Skip to content

Commit 68874c6

Browse files
feat(core): webview window focusable property, closes #11130 (#13564)
* Adds the ability to set the focused property from tauri.conf.json -- windows * add set_focusable, pin tao * fmt --------- Co-authored-by: Lucas Nogueira <[email protected]>
1 parent dfadcb7 commit 68874c6

File tree

20 files changed

+177
-7
lines changed

20 files changed

+177
-7
lines changed

.changes/focusable.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": minor:feat
3+
"tauri-runtime": minor:feat
4+
"tauri-runtime-wry": minor:feat
5+
"@tauri-apps/api": minor:feat
6+
---
7+
8+
Add window focusable attribute and set_focusable API.

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri-cli/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@
366366
"default": true,
367367
"type": "boolean"
368368
},
369+
"focusable": {
370+
"description": "Whether the window will be focusable or not.",
371+
"default": true,
372+
"type": "boolean"
373+
},
369374
"transparent": {
370375
"description": "Whether the window is transparent or not.\n\n Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.\n WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.",
371376
"default": false,

crates/tauri-cli/tauri.config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@
347347
"default": true,
348348
"type": "boolean"
349349
},
350+
"focusable": {
351+
"description": "Whether the window will be focusable or not.",
352+
"default": true,
353+
"type": "boolean"
354+
},
350355
"transparent": {
351356
"description": "Whether the window is transparent or not.\n\n Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.\n WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.",
352357
"default": false,

crates/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ wry = { version = "0.53.1", default-features = false, features = [
2323
"os-webview",
2424
"linux-body",
2525
] }
26-
tao = { version = "0.34", default-features = false, features = ["rwh_06"] }
26+
tao = { version = "0.34.1", default-features = false, features = ["rwh_06"] }
2727
tauri-runtime = { version = "2.7.1", path = "../tauri-runtime" }
2828
tauri-utils = { version = "2.6.0", path = "../tauri-utils" }
2929
raw-window-handle = "0.6"

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ impl WindowBuilder for WindowBuilderWrapper {
870870
.title(config.title.to_string())
871871
.inner_size(config.width, config.height)
872872
.focused(config.focus)
873+
.focusable(config.focusable)
873874
.visible(config.visible)
874875
.resizable(config.resizable)
875876
.fullscreen(config.fullscreen)
@@ -1035,6 +1036,11 @@ impl WindowBuilder for WindowBuilderWrapper {
10351036
self
10361037
}
10371038

1039+
fn focusable(mut self, focusable: bool) -> Self {
1040+
self.inner = self.inner.with_focusable(focusable);
1041+
self
1042+
}
1043+
10381044
fn maximized(mut self, maximized: bool) -> Self {
10391045
self.inner = self.inner.with_maximized(maximized);
10401046
self
@@ -1355,6 +1361,7 @@ pub enum WindowMessage {
13551361
#[cfg(target_os = "macos")]
13561362
SetSimpleFullscreen(bool),
13571363
SetFocus,
1364+
SetFocusable(bool),
13581365
SetIcon(TaoWindowIcon),
13591366
SetSkipTaskbar(bool),
13601367
SetCursorGrab(bool),
@@ -2238,6 +2245,13 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
22382245
)
22392246
}
22402247

2248+
fn set_focusable(&self, focusable: bool) -> Result<()> {
2249+
send_user_message(
2250+
&self.context,
2251+
Message::Window(self.window_id, WindowMessage::SetFocusable(focusable)),
2252+
)
2253+
}
2254+
22412255
fn set_icon(&self, icon: Icon) -> Result<()> {
22422256
send_user_message(
22432257
&self.context,
@@ -3379,6 +3393,9 @@ fn handle_user_message<T: UserEvent>(
33793393
WindowMessage::SetFocus => {
33803394
window.set_focus();
33813395
}
3396+
WindowMessage::SetFocusable(focusable) => {
3397+
window.set_focusable(focusable);
3398+
}
33823399
WindowMessage::SetIcon(icon) => {
33833400
window.set_window_icon(Some(icon));
33843401
}

crates/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ pub trait WindowDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 's
872872
/// Bring the window to front and focus.
873873
fn set_focus(&self) -> Result<()>;
874874

875+
/// Sets whether the window can be focused.
876+
fn set_focusable(&self, focusable: bool) -> Result<()>;
877+
875878
/// Updates the window icon.
876879
fn set_icon(&self, icon: Icon) -> Result<()>;
877880

crates/tauri-runtime/src/window.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ pub trait WindowBuilder: WindowBuilderBase {
329329
#[must_use]
330330
fn focused(self, focused: bool) -> Self;
331331

332+
/// Whether the window will be focusable or not.
333+
#[must_use]
334+
fn focusable(self, focusable: bool) -> Self;
335+
332336
/// Whether the window should be maximized upon creation.
333337
#[must_use]
334338
fn maximized(self, maximized: bool) -> Self;

crates/tauri-schema-generator/schemas/config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@
366366
"default": true,
367367
"type": "boolean"
368368
},
369+
"focusable": {
370+
"description": "Whether the window will be focusable or not.",
371+
"default": true,
372+
"type": "boolean"
373+
},
369374
"transparent": {
370375
"description": "Whether the window is transparent or not.\n\n Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.\n WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.",
371376
"default": false,

crates/tauri-utils/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,9 @@ pub struct WindowConfig {
16411641
/// Whether the window will be initially focused or not.
16421642
#[serde(default = "default_true")]
16431643
pub focus: bool,
1644+
/// Whether the window will be focusable or not.
1645+
#[serde(default = "default_true")]
1646+
pub focusable: bool,
16441647
/// Whether the window is transparent or not.
16451648
///
16461649
/// Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri > macOSPrivateApi`.
@@ -1866,6 +1869,7 @@ impl Default for WindowConfig {
18661869
title: default_title(),
18671870
fullscreen: false,
18681871
focus: false,
1872+
focusable: true,
18691873
transparent: false,
18701874
maximized: false,
18711875
visible: true,
@@ -3319,6 +3323,7 @@ mod build {
33193323
let proxy_url = opt_lit(self.proxy_url.as_ref().map(url_lit).as_ref());
33203324
let fullscreen = self.fullscreen;
33213325
let focus = self.focus;
3326+
let focusable = self.focusable;
33223327
let transparent = self.transparent;
33233328
let maximized = self.maximized;
33243329
let visible = self.visible;
@@ -3376,6 +3381,7 @@ mod build {
33763381
proxy_url,
33773382
fullscreen,
33783383
focus,
3384+
focusable,
33793385
transparent,
33803386
maximized,
33813387
visible,

0 commit comments

Comments
 (0)