Skip to content

Commit e919a76

Browse files
feat(webview-window): add set_simple_fullscreen to WebviewWindow (#14619)
* feat(webview): add set_simple_fullscreen to WebviewWindow * add changes * Combine per platform fn to one --------- Co-authored-by: Tony <legendmastertony@gmail.com>
1 parent 0575dd2 commit e919a76

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'tauri': 'minor:feat'
3+
---
4+
5+
Add `set_simple_fullscreen` method to `WebviewWindow`.
6+
7+
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.

crates/tauri/src/webview/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,4 +2312,25 @@ mod tests {
23122312
crate::test_utils::assert_send::<super::Webview>();
23132313
crate::test_utils::assert_sync::<super::Webview>();
23142314
}
2315+
2316+
#[cfg(target_os = "macos")]
2317+
#[test]
2318+
fn test_webview_window_has_set_simple_fullscreen_method() {
2319+
use crate::test::{mock_builder, mock_context, noop_assets};
2320+
2321+
// Create a mock app with proper context
2322+
let app = mock_builder().build(mock_context(noop_assets())).unwrap();
2323+
2324+
// Get or create a webview window
2325+
let webview_window =
2326+
crate::WebviewWindowBuilder::new(&app, "test", crate::WebviewUrl::default())
2327+
.build()
2328+
.unwrap();
2329+
2330+
// This should compile if set_simple_fullscreen exists
2331+
let result = webview_window.set_simple_fullscreen(true);
2332+
2333+
// We expect this to work without panicking
2334+
assert!(result.is_ok(), "set_simple_fullscreen should succeed");
2335+
}
23152336
}

crates/tauri/src/webview/webview_window.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,20 @@ impl<R: Runtime> WebviewWindow<R> {
20572057
self.window.set_fullscreen(fullscreen)
20582058
}
20592059

2060+
/// Toggles a fullscreen mode that doesn't require a new macOS space.
2061+
/// Returns a boolean indicating whether the transition was successful (this won't work if the window was already in the native fullscreen).
2062+
///
2063+
/// This is how fullscreen used to work on macOS in versions before Lion.
2064+
/// And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
2065+
///
2066+
/// ## Platform-specific
2067+
///
2068+
/// - **macOS:** Uses native simple fullscreen mode.
2069+
/// - **Other platforms:** Falls back to [`Self::set_fullscreen`].
2070+
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
2071+
self.window.set_simple_fullscreen(enable)
2072+
}
2073+
20602074
/// Bring the window to front and focus.
20612075
pub fn set_focus(&self) -> crate::Result<()> {
20622076
self.window.set_focus()

crates/tauri/src/window/mod.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,25 +1968,27 @@ tauri::Builder::default()
19681968
.map_err(Into::into)
19691969
}
19701970

1971-
/// Toggles a fullscreen mode that doesn’t require a new macOS space. Returns a boolean indicating whether the transition was successful (this won’t work if the window was already in the native fullscreen).
1971+
/// Toggles a fullscreen mode that doesn't require a new macOS space.
1972+
/// Returns a boolean indicating whether the transition was successful (this won't work if the window was already in the native fullscreen).
19721973
///
1973-
/// This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
1974-
#[cfg(target_os = "macos")]
1975-
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
1976-
self
1977-
.window
1978-
.dispatcher
1979-
.set_simple_fullscreen(enable)
1980-
.map_err(Into::into)
1981-
}
1982-
1983-
/// On macOS, Toggles a fullscreen mode that doesn’t require a new macOS space. Returns a boolean indicating whether the transition was successful (this won’t work if the window was already in the native fullscreen).
1984-
/// This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
1974+
/// This is how fullscreen used to work on macOS in versions before Lion.
1975+
/// And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
19851976
///
1986-
/// On other platforms, this is the same as [`Window#method.set_fullscreen`].
1987-
#[cfg(not(target_os = "macos"))]
1988-
pub fn set_simple_fullscreen(&self, fullscreen: bool) -> crate::Result<()> {
1989-
self.set_fullscreen(fullscreen)
1977+
/// ## Platform-specific
1978+
///
1979+
/// - **macOS:** Uses native simple fullscreen mode.
1980+
/// - **Other platforms:** Falls back to [`Self::set_fullscreen`].
1981+
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
1982+
#[cfg(target_os = "macos")]
1983+
{
1984+
self
1985+
.window
1986+
.dispatcher
1987+
.set_simple_fullscreen(enable)
1988+
.map_err(Into::into)
1989+
}
1990+
#[cfg(not(target_os = "macos"))]
1991+
self.set_fullscreen(enable)
19901992
}
19911993

19921994
/// Bring the window to front and focus.

0 commit comments

Comments
 (0)