diff --git a/.changes/webview-set-simple-fullscreen.md b/.changes/webview-set-simple-fullscreen.md new file mode 100644 index 000000000000..ba0cdf8bf2b7 --- /dev/null +++ b/.changes/webview-set-simple-fullscreen.md @@ -0,0 +1,7 @@ +--- +'tauri': 'minor:feat' +--- + +Add `set_simple_fullscreen` method to `WebviewWindow`. + +This method was already available on the `Window` type and is now also available on `WebviewWindow` for consistency. On macOS, it toggles fullscreen mode without creating a new macOS Space. On other platforms, it falls back to regular fullscreen. diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 9c4a6e0ea79c..f4ec884feffc 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -2312,4 +2312,25 @@ mod tests { crate::test_utils::assert_send::(); crate::test_utils::assert_sync::(); } + + #[cfg(target_os = "macos")] + #[test] + fn test_webview_window_has_set_simple_fullscreen_method() { + use crate::test::{mock_builder, mock_context, noop_assets}; + + // Create a mock app with proper context + let app = mock_builder().build(mock_context(noop_assets())).unwrap(); + + // Get or create a webview window + let webview_window = + crate::WebviewWindowBuilder::new(&app, "test", crate::WebviewUrl::default()) + .build() + .unwrap(); + + // This should compile if set_simple_fullscreen exists + let result = webview_window.set_simple_fullscreen(true); + + // We expect this to work without panicking + assert!(result.is_ok(), "set_simple_fullscreen should succeed"); + } } diff --git a/crates/tauri/src/webview/webview_window.rs b/crates/tauri/src/webview/webview_window.rs index 24232993a7d5..3b8e9da6c3a2 100644 --- a/crates/tauri/src/webview/webview_window.rs +++ b/crates/tauri/src/webview/webview_window.rs @@ -2057,6 +2057,33 @@ impl WebviewWindow { self.window.set_fullscreen(fullscreen) } + /// Toggles a fullscreen mode that doesn't require a new macOS space. + /// + /// This is how fullscreen used to work on macOS in versions before Lion. + /// It allows the user to have a fullscreen window without using another space + /// or taking control over the entire monitor. + /// + /// ## Platform-specific + /// + /// - **macOS:** Uses native simple fullscreen mode. + /// - **Other platforms:** Falls back to [`Self::set_fullscreen`]. + #[cfg(target_os = "macos")] + pub fn set_simple_fullscreen(&self, fullscreen: bool) -> crate::Result<()> { + self.window.set_simple_fullscreen(fullscreen) + } + + /// Toggles a fullscreen mode that doesn't require a new macOS space. + /// + /// On non-macOS platforms, this method falls back to regular fullscreen behavior. + /// + /// ## Platform-specific + /// + /// - **Other platforms:** Falls back to [`Self::set_fullscreen`]. + #[cfg(not(target_os = "macos"))] + pub fn set_simple_fullscreen(&self, fullscreen: bool) -> crate::Result<()> { + self.set_fullscreen(fullscreen) + } + /// Bring the window to front and focus. pub fn set_focus(&self) -> crate::Result<()> { self.window.set_focus()