Skip to content

Commit 5110a76

Browse files
feat(window): add macOS window::set_simple_fullscreen (closes #13670) (#13830)
* add implementation of set_simple_fullscreen * add simple fullscreen API for macos * register desktop command * format * fix errors * chore: format * change implementation * add api * fix tests --------- Co-authored-by: Lucas Nogueira <[email protected]>
1 parent a9ec128 commit 5110a76

File tree

13 files changed

+112
-1
lines changed

13 files changed

+112
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/api": minor:feat
3+
---
4+
5+
Added `Window::setSimpleFullscreen`.

.changes/set-simple-fullscreen.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-runtime": minor:feat
3+
"tauri-runtime-wry": minor:feat
4+
"tauri": minor:feat
5+
---
6+
7+
Added `Window::set_simple_fullscreen`.

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,8 @@ pub enum WindowMessage {
13481348
SetSizeConstraints(WindowSizeConstraints),
13491349
SetPosition(Position),
13501350
SetFullscreen(bool),
1351+
#[cfg(target_os = "macos")]
1352+
SetSimpleFullscreen(bool),
13511353
SetFocus,
13521354
SetIcon(TaoWindowIcon),
13531355
SetSkipTaskbar(bool),
@@ -2190,6 +2192,14 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
21902192
)
21912193
}
21922194

2195+
#[cfg(target_os = "macos")]
2196+
fn set_simple_fullscreen(&self, enable: bool) -> Result<()> {
2197+
send_user_message(
2198+
&self.context,
2199+
Message::Window(self.window_id, WindowMessage::SetSimpleFullscreen(enable)),
2200+
)
2201+
}
2202+
21932203
fn set_focus(&self) -> Result<()> {
21942204
send_user_message(
21952205
&self.context,
@@ -3322,6 +3332,12 @@ fn handle_user_message<T: UserEvent>(
33223332
window.set_fullscreen(None)
33233333
}
33243334
}
3335+
3336+
#[cfg(target_os = "macos")]
3337+
WindowMessage::SetSimpleFullscreen(enable) => {
3338+
window.set_simple_fullscreen(enable);
3339+
}
3340+
33253341
WindowMessage::SetFocus => {
33263342
window.set_focus();
33273343
}

crates/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
844844
/// Updates the window fullscreen state.
845845
fn set_fullscreen(&self, fullscreen: bool) -> Result<()>;
846846

847+
#[cfg(target_os = "macos")]
848+
fn set_simple_fullscreen(&self, enable: bool) -> Result<()>;
849+
847850
/// Bring the window to front and focus.
848851
fn set_focus(&self) -> Result<()>;
849852

crates/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
9999
("set_max_size", false),
100100
("set_position", false),
101101
("set_fullscreen", false),
102+
("set_simple_fullscreen", false),
102103
("set_focus", false),
103104
("set_skip_taskbar", false),
104105
("set_cursor_grab", false),

crates/tauri/permissions/window/autogenerated/reference.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,32 @@ Denies the set_shadow command without any pre-configured scope.
15771577
<tr>
15781578
<td>
15791579

1580+
`core:window:allow-set-simple-fullscreen`
1581+
1582+
</td>
1583+
<td>
1584+
1585+
Enables the set_simple_fullscreen command without any pre-configured scope.
1586+
1587+
</td>
1588+
</tr>
1589+
1590+
<tr>
1591+
<td>
1592+
1593+
`core:window:deny-set-simple-fullscreen`
1594+
1595+
</td>
1596+
<td>
1597+
1598+
Denies the set_simple_fullscreen command without any pre-configured scope.
1599+
1600+
</td>
1601+
</tr>
1602+
1603+
<tr>
1604+
<td>
1605+
15801606
`core:window:allow-set-size`
15811607

15821608
</td>

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/test/mock_runtime.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,11 @@ impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
981981
Ok(())
982982
}
983983

984+
#[cfg(target_os = "macos")]
985+
fn set_simple_fullscreen(&self, enable: bool) -> Result<()> {
986+
Ok(())
987+
}
988+
984989
fn set_focus(&self) -> Result<()> {
985990
Ok(())
986991
}

crates/tauri/src/window/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,27 @@ tauri::Builder::default()
19611961
.map_err(Into::into)
19621962
}
19631963

1964+
/// 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).
1965+
///
1966+
/// 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.
1967+
#[cfg(target_os = "macos")]
1968+
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
1969+
self
1970+
.window
1971+
.dispatcher
1972+
.set_simple_fullscreen(enable)
1973+
.map_err(Into::into)
1974+
}
1975+
1976+
/// 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).
1977+
/// 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.
1978+
///
1979+
/// On other platforms, this is the same as [`Window#method.set_fullscreen`].
1980+
#[cfg(not(target_os = "macos"))]
1981+
pub fn set_simple_fullscreen(&self, fullscreen: bool) -> crate::Result<()> {
1982+
self.set_fullscreen(fullscreen)
1983+
}
1984+
19641985
/// Bring the window to front and focus.
19651986
pub fn set_focus(&self) -> crate::Result<()> {
19661987
self.window.dispatcher.set_focus().map_err(Into::into)

crates/tauri/src/window/plugin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ mod desktop_commands {
128128
setter!(set_max_size, Option<Size>);
129129
setter!(set_position, Position);
130130
setter!(set_fullscreen, bool);
131+
setter!(set_simple_fullscreen, bool);
131132
setter!(set_focus);
132133
setter!(set_skip_taskbar, bool);
133134
setter!(set_cursor_grab, bool);
@@ -301,6 +302,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
301302
desktop_commands::set_size_constraints,
302303
desktop_commands::set_position,
303304
desktop_commands::set_fullscreen,
305+
desktop_commands::set_simple_fullscreen,
304306
desktop_commands::set_focus,
305307
desktop_commands::set_enabled,
306308
desktop_commands::set_skip_taskbar,

0 commit comments

Comments
 (0)