Skip to content
Open
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
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 @@ -1381,6 +1381,7 @@ pub enum WindowMessage {
SetSizeConstraints(WindowSizeConstraints),
SetPosition(Position),
SetFullscreen(bool),
SetFullscreenOnMonitor(PhysicalPosition<f64>),
#[cfg(target_os = "macos")]
SetSimpleFullscreen(bool),
SetFocus,
Expand Down Expand Up @@ -2246,6 +2247,16 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
)
}

fn set_fullscreen_on_monitor(&self, position: PhysicalPosition<f64>) -> Result<()> {
send_user_message(
&self.context,
Message::Window(
self.window_id,
WindowMessage::SetFullscreenOnMonitor(position),
),
)
}

fn set_fullscreen(&self, fullscreen: bool) -> Result<()> {
send_user_message(
&self.context,
Expand Down Expand Up @@ -3419,6 +3430,11 @@ fn handle_user_message<T: UserEvent>(
window.set_fullscreen(None)
}
}
WindowMessage::SetFullscreenOnMonitor(position) => {
if let Some(monitor) = window.monitor_from_point(position.x, position.y) {
window.set_fullscreen(Some(Fullscreen::Borderless(Some(monitor))))
}
}

#[cfg(target_os = "macos")]
WindowMessage::SetSimpleFullscreen(enable) => {
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 @@ -878,6 +878,9 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
/// Updates the window fullscreen state.
fn set_fullscreen(&self, fullscreen: bool) -> Result<()>;

/// Sets the window as fullscreen, on the monitor that contains the specified position.
fn set_fullscreen_on_monitor(&self, position: PhysicalPosition<f64>) -> Result<()>;

#[cfg(target_os = "macos")]
fn set_simple_fullscreen(&self, enable: bool) -> 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_fullscreen_on_monitor", false),
("set_simple_fullscreen", false),
("set_focus", false),
("set_focusable", 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 @@ -1317,6 +1317,32 @@ Denies the set_fullscreen command without any pre-configured scope.
<tr>
<td>

`core:window:allow-set-fullscreen-on-monitor`

</td>
<td>

Enables the set_fullscreen_on_monitor command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:window:deny-set-fullscreen-on-monitor`

</td>
<td>

Denies the set_fullscreen_on_monitor command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`core:window:allow-set-icon`

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

fn set_fullscreen_on_monitor(&self, position: PhysicalPosition<f64>) -> Result<()> {
Ok(())
}

#[cfg(target_os = "macos")]
fn set_simple_fullscreen(&self, enable: bool) -> Result<()> {
Ok(())
Expand Down
9 changes: 9 additions & 0 deletions crates/tauri/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1968,6 +1968,15 @@ tauri::Builder::default()
.map_err(Into::into)
}

/// Sets the window as fullscreen, on the monitor that contains the specified position.
pub fn set_fullscreen_on_monitor(&self, position: PhysicalPosition<f64>) -> crate::Result<()> {
self
.window
.dispatcher
.set_fullscreen_on_monitor(position)
.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).
///
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_fullscreen_on_monitor, PhysicalPosition<f64>);
setter!(set_simple_fullscreen, bool);
setter!(set_focus);
setter!(set_focusable, bool);
Expand Down Expand Up @@ -303,6 +304,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
desktop_commands::set_size_constraints,
desktop_commands::set_position,
desktop_commands::set_fullscreen,
desktop_commands::set_fullscreen_on_monitor,
desktop_commands::set_simple_fullscreen,
desktop_commands::set_focus,
desktop_commands::set_focusable,
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-fullscreen-on-monitor",
"core:window:allow-set-simple-fullscreen",
"core:window:allow-set-focus",
"core:window:allow-set-focusable",
Expand Down
44 changes: 43 additions & 1 deletion examples/api/src/views/Window.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
PhysicalPosition,
Effect,
EffectState,
ProgressBarStatus
ProgressBarStatus,
availableMonitors,
currentMonitor,
} from '@tauri-apps/api/window'
import { WebviewWindow } from '@tauri-apps/api/webviewWindow'

Expand All @@ -20,6 +22,14 @@
[webview.label]: webview
})

let monitor = $state("")
let selectedMonitor = $state("")
let monitorMap = $state({})

availableMonitors().then((response) => {
monitorMap = Object.fromEntries(response.map((m) => [m.name, m]))
})

let focusable = $state(true)

const cursorIconOptions = [
Expand Down Expand Up @@ -222,6 +232,11 @@
x = outerPosition.x
y = outerPosition.y
})
currentMonitor().then((response) => {
if (response) {
monitor = response.name
}
})
}

async function addWindowEventListeners(window) {
Expand Down Expand Up @@ -501,6 +516,27 @@
>
Set focusable to {!focusable}
</button>

<div class="gap-2">
<form
class="flex"
onsubmit={(ev) => {
if (selectedMonitor) {
webviewMap[selectedWebview].setFullscreenOnMonitor(monitorMap[selectedMonitor].position)
.then((r) => {fullscreen = true})
}
ev.preventDefault()
}}
>
<button class="btn" type="submit">Set Fullscreen on Monitor</button>
<select class="input" style="padding-top: 0;padding-bottom: 0;" bind:value={selectedMonitor}>
<option value="" disabled selected>Choose a monitor...</option>
{#each Object.keys(monitorMap) as label}
<option value={label}>{label}</option>
{/each}
</select>
</form>
</div>
</div>
<div class="grid cols-[repeat(auto-fill,minmax(180px,1fr))]">
<label>
Expand Down Expand Up @@ -681,6 +717,12 @@
<span>x: {outerPosition.toLogical(scaleFactor).x.toFixed(3)}</span>
<span>y: {outerPosition.toLogical(scaleFactor).y.toFixed(3)}</span>
</div>
<div>
<div class="text-accent dark:text-darkAccent font-700 m-block-1">
Current Monitor
</div>
<span>{monitor}</span>
</div>
</div>
<div class="grid gap-2">
<h4 class="my-2">Cursor</h4>
Expand Down
7 changes: 7 additions & 0 deletions packages/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,13 @@ class Window {
})
}

async setFullscreenOnMonitor(position: PhysicalPosition): Promise<void> {
return invoke('plugin:window|set_fullscreen_on_monitor', {
label: this.label,
value: position
})
}

/**
* 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.
Expand Down