Skip to content

Commit 95f467a

Browse files
authored
feat(core): add window accept_first_mouse option, closes #5347 (#5374)
1 parent b8bf8e0 commit 95f467a

File tree

10 files changed

+53
-11
lines changed

10 files changed

+53
-11
lines changed

.changes/accept-first-mouse-api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": minor
3+
---
4+
5+
Added the `acceptFirstMouse` window option.

.changes/accept-first-mouse.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": minor
3+
"tauri-runtime-wry": minor
4+
---
5+
6+
Add `accept_first_mouse` option for macOS windows.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,8 @@ fn create_webview<T: UserEvent>(
29502950
.map_err(|e| Error::CreateWebview(Box::new(e)))?
29512951
.with_url(&url)
29522952
.unwrap() // safe to unwrap because we validate the URL beforehand
2953-
.with_transparent(is_window_transparent);
2953+
.with_transparent(is_window_transparent)
2954+
.with_accept_first_mouse(webview_attributes.accept_first_mouse);
29542955
if webview_attributes.file_drop_handler_enabled {
29552956
webview_builder = webview_builder
29562957
.with_file_drop_handler(create_file_drop_handler(window_event_listeners.clone()));

core/tauri-runtime/src/webview.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct WebviewAttributes {
2727
pub data_directory: Option<PathBuf>,
2828
pub file_drop_handler_enabled: bool,
2929
pub clipboard: bool,
30+
pub accept_first_mouse: bool,
3031
}
3132

3233
impl WebviewAttributes {
@@ -39,6 +40,7 @@ impl WebviewAttributes {
3940
data_directory: None,
4041
file_drop_handler_enabled: true,
4142
clipboard: false,
43+
accept_first_mouse: false,
4244
}
4345
}
4446

@@ -79,6 +81,13 @@ impl WebviewAttributes {
7981
self.clipboard = true;
8082
self
8183
}
84+
85+
/// Sets whether clicking an inactive window also clicks through to the webview.
86+
#[must_use]
87+
pub fn accept_first_mouse(mut self, accept: bool) -> Self {
88+
self.accept_first_mouse = accept;
89+
self
90+
}
8291
}
8392

8493
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

core/tauri-utils/src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,9 @@ pub struct WindowConfig {
870870
/// If `true`, sets the window title to be hidden on macOS.
871871
#[serde(default, alias = "hidden-title")]
872872
pub hidden_title: bool,
873+
/// Whether clicking an inactive window also clicks through to the webview.
874+
#[serde(default, alias = "accept-first-mouse")]
875+
pub accept_first_mouse: bool,
873876
}
874877

875878
impl Default for WindowConfig {
@@ -901,6 +904,7 @@ impl Default for WindowConfig {
901904
theme: None,
902905
title_bar_style: Default::default(),
903906
hidden_title: false,
907+
accept_first_mouse: false,
904908
}
905909
}
906910
}
@@ -3032,6 +3036,7 @@ mod build {
30323036
let theme = opt_lit(self.theme.as_ref());
30333037
let title_bar_style = &self.title_bar_style;
30343038
let hidden_title = self.hidden_title;
3039+
let accept_first_mouse = self.accept_first_mouse;
30353040

30363041
literal_struct!(
30373042
tokens,
@@ -3061,7 +3066,8 @@ mod build {
30613066
skip_taskbar,
30623067
theme,
30633068
title_bar_style,
3064-
hidden_title
3069+
hidden_title,
3070+
accept_first_mouse
30653071
);
30663072
}
30673073
}

core/tauri/scripts/bundle.global.js

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

core/tauri/src/app.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,14 +1484,13 @@ impl<R: Runtime> Builder<R> {
14841484
for config in manager.config().tauri.windows.clone() {
14851485
let url = config.url.clone();
14861486
let label = config.label.clone();
1487-
let file_drop_enabled = config.file_drop_enabled;
1488-
let user_agent = config.user_agent.clone();
14891487

1490-
let mut webview_attributes = WebviewAttributes::new(url);
1491-
if let Some(ua) = user_agent {
1488+
let mut webview_attributes =
1489+
WebviewAttributes::new(url).accept_first_mouse(config.accept_first_mouse);
1490+
if let Some(ua) = &config.user_agent {
14921491
webview_attributes = webview_attributes.user_agent(&ua.to_string());
14931492
}
1494-
if !file_drop_enabled {
1493+
if !config.file_drop_enabled {
14951494
webview_attributes = webview_attributes.disable_file_drop_handler();
14961495
}
14971496

core/tauri/src/window.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,13 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
535535
self.webview_attributes.clipboard = true;
536536
self
537537
}
538+
539+
/// Sets whether clicking an inactive window also clicks through to the webview.
540+
#[must_use]
541+
pub fn accept_first_mouse(mut self, accept: bool) -> Self {
542+
self.webview_attributes.accept_first_mouse = accept;
543+
self
544+
}
538545
}
539546

540547
// TODO: expand these docs since this is a pretty important type

tooling/api/src/window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,10 @@ interface WindowOptions {
20422042
* If `true`, sets the window title to be hidden on macOS.
20432043
*/
20442044
hiddenTitle?: boolean
2045+
/**
2046+
* Whether clicking an inactive window also clicks through to the webview.
2047+
*/
2048+
acceptFirstMouse?: boolean
20452049
/**
20462050
* The user agent for the webview.
20472051
*/

tooling/cli/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,11 @@
670670
"description": "If `true`, sets the window title to be hidden on macOS.",
671671
"default": false,
672672
"type": "boolean"
673+
},
674+
"acceptFirstMouse": {
675+
"description": "Whether clicking an inactive window also clicks through to the webview.",
676+
"default": false,
677+
"type": "boolean"
673678
}
674679
},
675680
"additionalProperties": false

0 commit comments

Comments
 (0)