Skip to content

Commit be2e6b8

Browse files
add Window.is_always_on_top() and WebviewWindow.is_always_on_top() (#12944)
* add `Window.is_always_on_top()` and `WebviewWindow.is_always_on_top()` * add api * fmt --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent b9ee806 commit be2e6b8

File tree

12 files changed

+98
-2
lines changed

12 files changed

+98
-2
lines changed

.changes/add-is-always-on-top.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
tauri: 'minor:feat'
3+
tauri-runtime: 'minor:feat'
4+
tauri-runtime-wry: 'minor:feat'
5+
---
6+
7+
add `Window.is_always_on_top()` and `WebviewWindow.is_always_on_top()`

.changes/is-always-on-top-api.md

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#isAlwaysOnTop` and `WebviewWindow#isAlwaysOnTop` methods.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ pub enum WindowMessage {
12291229
RawWindowHandle(Sender<std::result::Result<SendRawWindowHandle, raw_window_handle::HandleError>>),
12301230
Theme(Sender<Theme>),
12311231
IsEnabled(Sender<bool>),
1232+
IsAlwaysOnTop(Sender<bool>),
12321233
// Setters
12331234
Center,
12341235
RequestUserAttention(Option<UserAttentionTypeWrapper>),
@@ -1801,6 +1802,10 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
18011802
window_getter!(self, WindowMessage::IsEnabled)
18021803
}
18031804

1805+
fn is_always_on_top(&self) -> Result<bool> {
1806+
window_getter!(self, WindowMessage::IsAlwaysOnTop)
1807+
}
1808+
18041809
#[cfg(any(
18051810
target_os = "linux",
18061811
target_os = "dragonfly",
@@ -3014,7 +3019,7 @@ fn handle_user_message<T: UserEvent>(
30143019
tx.send(map_theme(&window.theme())).unwrap();
30153020
}
30163021
WindowMessage::IsEnabled(tx) => tx.send(window.is_enabled()).unwrap(),
3017-
3022+
WindowMessage::IsAlwaysOnTop(tx) => tx.send(window.is_always_on_top()).unwrap(),
30183023
// Setters
30193024
WindowMessage::Center => window.center(),
30203025
WindowMessage::RequestUserAttention(request_type) => {

crates/tauri-runtime/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,13 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
612612
/// Whether the window is enabled or disable.
613613
fn is_enabled(&self) -> Result<bool>;
614614

615+
/// Gets the window alwaysOnTop flag state.
616+
///
617+
/// ## Platform-specific
618+
///
619+
/// - **iOS / Android:** Unsupported.
620+
fn is_always_on_top(&self) -> Result<bool>;
621+
615622
/// Gets the window's current title.
616623
fn title(&self) -> Result<String>;
617624

crates/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
6565
("available_monitors", true),
6666
("cursor_position", true),
6767
("theme", true),
68+
("is_always_on_top", true),
6869
// setters
6970
("center", false),
7071
("request_user_attention", false),

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Default permissions for the plugin.
2626
- `allow-available-monitors`
2727
- `allow-cursor-position`
2828
- `allow-theme`
29+
- `allow-is-always-on-top`
2930
- `allow-internal-toggle-maximize`
3031

3132
## Permission Table
@@ -352,6 +353,32 @@ Denies the internal_toggle_maximize command without any pre-configured scope.
352353
<tr>
353354
<td>
354355

356+
`core:window:allow-is-always-on-top`
357+
358+
</td>
359+
<td>
360+
361+
Enables the is_always_on_top command without any pre-configured scope.
362+
363+
</td>
364+
</tr>
365+
366+
<tr>
367+
<td>
368+
369+
`core:window:deny-is-always-on-top`
370+
371+
</td>
372+
<td>
373+
374+
Denies the is_always_on_top command without any pre-configured scope.
375+
376+
</td>
377+
</tr>
378+
379+
<tr>
380+
<td>
381+
355382
`core:window:allow-is-closable`
356383

357384
</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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,10 @@ impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {
10161016
Ok(true)
10171017
}
10181018

1019+
fn is_always_on_top(&self) -> Result<bool> {
1020+
Ok(false)
1021+
}
1022+
10191023
fn set_background_color(&self, color: Option<tauri_utils::config::Color>) -> Result<()> {
10201024
Ok(())
10211025
}

crates/tauri/src/webview/webview_window.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,15 @@ impl<R: Runtime> WebviewWindow<R> {
13201320
self.webview.window().is_enabled()
13211321
}
13221322

1323+
/// Determines if this window should always be on top of other windows.
1324+
///
1325+
/// ## Platform-specific
1326+
///
1327+
/// - **iOS / Android:** Unsupported.
1328+
pub fn is_always_on_top(&self) -> crate::Result<bool> {
1329+
self.webview.window().is_always_on_top()
1330+
}
1331+
13231332
/// Gets the window's native maximize button state
13241333
///
13251334
/// ## Platform-specific

crates/tauri/src/window/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,19 @@ impl<R: Runtime> Window<R> {
13971397
self.window.dispatcher.is_enabled().map_err(Into::into)
13981398
}
13991399

1400+
/// Determines if this window should always be on top of other windows.
1401+
///
1402+
/// ## Platform-specific
1403+
///
1404+
/// - **iOS / Android:** Unsupported.
1405+
pub fn is_always_on_top(&self) -> crate::Result<bool> {
1406+
self
1407+
.window
1408+
.dispatcher
1409+
.is_always_on_top()
1410+
.map_err(Into::into)
1411+
}
1412+
14001413
/// Gets the window's native maximize button state
14011414
///
14021415
/// ## Platform-specific

0 commit comments

Comments
 (0)