Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/set-simple-fullscreen-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/api": minor:feat
---

Added `Window::setSimpleFullscreen`.
7 changes: 7 additions & 0 deletions .changes/set-simple-fullscreen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-runtime": minor:feat
"tauri-runtime-wry": minor:feat
"tauri": minor:feat
---

Added `Window::set_simple_fullscreen`.
16 changes: 16 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,8 @@ pub enum WindowMessage {
SetSizeConstraints(WindowSizeConstraints),
SetPosition(Position),
SetFullscreen(bool),
#[cfg(target_os = "macos")]
SetSimpleFullscreen(bool),
SetFocus,
SetIcon(TaoWindowIcon),
SetSkipTaskbar(bool),
Expand Down Expand Up @@ -2190,6 +2192,14 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
)
}

#[cfg(target_os = "macos")]
fn set_simple_fullscreen(&self, enable: bool) -> Result<()> {
send_user_message(
&self.context,
Message::Window(self.window_id, WindowMessage::SetSimpleFullscreen(enable)),
)
}

fn set_focus(&self) -> Result<()> {
send_user_message(
&self.context,
Expand Down Expand Up @@ -3322,6 +3332,12 @@ fn handle_user_message<T: UserEvent>(
window.set_fullscreen(None)
}
}

#[cfg(target_os = "macos")]
WindowMessage::SetSimpleFullscreen(enable) => {
window.set_simple_fullscreen(enable);
}

WindowMessage::SetFocus => {
window.set_focus();
}
Expand Down
3 changes: 3 additions & 0 deletions crates/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
/// Updates the window fullscreen state.
fn set_fullscreen(&self, fullscreen: bool) -> Result<()>;

#[cfg(target_os = "macos")]
fn set_simple_fullscreen(&self, enable: bool) -> Result<()>;

/// Bring the window to front and focus.
fn set_focus(&self) -> Result<()>;

Expand Down
1 change: 1 addition & 0 deletions crates/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
("set_max_size", false),
("set_position", false),
("set_fullscreen", false),
("set_simple_fullscreen", false),
("set_focus", false),
("set_skip_taskbar", false),
("set_cursor_grab", false),
Expand Down
26 changes: 26 additions & 0 deletions crates/tauri/permissions/window/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,32 @@ Denies the set_shadow command without any pre-configured scope.
<tr>
<td>

`core:window:allow-set-simple-fullscreen`

</td>
<td>

Enables the set_simple_fullscreen command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:window:deny-set-simple-fullscreen`

</td>
<td>

Denies the set_simple_fullscreen command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:window:allow-set-size`

</td>
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions crates/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,11 @@ impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
Ok(())
}

#[cfg(target_os = "macos")]
fn set_simple_fullscreen(&self, enable: bool) -> Result<()> {
Ok(())
}

fn set_focus(&self) -> Result<()> {
Ok(())
}
Expand Down
21 changes: 21 additions & 0 deletions crates/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,27 @@ tauri::Builder::default()
.map_err(Into::into)
}

/// 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).
///
/// 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.
#[cfg(target_os = "macos")]
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
self
.window
.dispatcher
.set_simple_fullscreen(enable)
.map_err(Into::into)
}

/// 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).
/// 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.
///
/// On other platforms, this is the same as [`Window#method.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.dispatcher.set_focus().map_err(Into::into)
Expand Down
2 changes: 2 additions & 0 deletions crates/tauri/src/window/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ mod desktop_commands {
setter!(set_max_size, Option<Size>);
setter!(set_position, Position);
setter!(set_fullscreen, bool);
setter!(set_simple_fullscreen, bool);
setter!(set_focus);
setter!(set_skip_taskbar, bool);
setter!(set_cursor_grab, bool);
Expand Down Expand Up @@ -301,6 +302,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::set_size_constraints,
desktop_commands::set_position,
desktop_commands::set_fullscreen,
desktop_commands::set_simple_fullscreen,
desktop_commands::set_focus,
desktop_commands::set_enabled,
desktop_commands::set_skip_taskbar,
Expand Down
1 change: 1 addition & 0 deletions examples/api/src-tauri/capabilities/run-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"core:window:allow-set-max-size",
"core:window:allow-set-position",
"core:window:allow-set-fullscreen",
"core:window:allow-set-simple-fullscreen",
"core:window:allow-set-focus",
"core:window:allow-set-skip-taskbar",
"core:window:allow-set-cursor-grab",
Expand Down
8 changes: 8 additions & 0 deletions examples/api/src/views/Window.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
let alwaysOnBottom = $state(false)
let contentProtected = $state(false)
let fullscreen = $state(false)
let simpleFullscreen = $state(false)
let width = $state(null)
let height = $state(null)
let minWidth = $state(null)
Expand Down Expand Up @@ -337,6 +338,9 @@
$effect(() => {
webviewMap[selectedWebview]?.setFullscreen(fullscreen)
})
$effect(() => {
webviewMap[selectedWebview]?.setSimpleFullscreen(simpleFullscreen)
})

$effect(() => {
minWidth && minHeight
Expand Down Expand Up @@ -532,6 +536,10 @@
<input type="checkbox" class="checkbox" bind:checked={fullscreen} />
Fullscreen
</label>
<label>
<input type="checkbox" class="checkbox" bind:checked={simpleFullscreen} />
Simple fullscreen
</label>
</div>
<div class="flex flex-wrap children:flex-basis-30 gap-2">
<div class="grid gap-1 children:grid">
Expand Down
16 changes: 16 additions & 0 deletions packages/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,22 @@ class Window {
})
}

/**
* 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).
* 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.
*
* On other platforms, this is the same as {@link Window.setFullscreen}.
*
* @param fullscreen Whether the window should go to simple fullscreen or not.
* @returns A promise indicating the success or failure of the operation.
*/
async setSimpleFullscreen(fullscreen: boolean): Promise<void> {
return invoke('plugin:window|set_simple_fullscreen', {
label: this.label,
value: fullscreen
})
}

/**
* Bring the window to front and focus.
* @example
Expand Down
Loading