feat(core): add window accept_first_mouse option, closes #5347 (#5374)

This commit is contained in:
Lucas Fernandes Nogueira 2022-10-17 11:07:45 -03:00 committed by GitHub
parent b8bf8e0fac
commit 95f467add5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 11 deletions

View File

@ -0,0 +1,5 @@
---
"api": minor
---
Added the `acceptFirstMouse` window option.

View File

@ -0,0 +1,6 @@
---
"tauri": minor
"tauri-runtime-wry": minor
---
Add `accept_first_mouse` option for macOS windows.

View File

@ -2950,7 +2950,8 @@ fn create_webview<T: UserEvent>(
.map_err(|e| Error::CreateWebview(Box::new(e)))?
.with_url(&url)
.unwrap() // safe to unwrap because we validate the URL beforehand
.with_transparent(is_window_transparent);
.with_transparent(is_window_transparent)
.with_accept_first_mouse(webview_attributes.accept_first_mouse);
if webview_attributes.file_drop_handler_enabled {
webview_builder = webview_builder
.with_file_drop_handler(create_file_drop_handler(window_event_listeners.clone()));

View File

@ -27,6 +27,7 @@ pub struct WebviewAttributes {
pub data_directory: Option<PathBuf>,
pub file_drop_handler_enabled: bool,
pub clipboard: bool,
pub accept_first_mouse: bool,
}
impl WebviewAttributes {
@ -39,6 +40,7 @@ impl WebviewAttributes {
data_directory: None,
file_drop_handler_enabled: true,
clipboard: false,
accept_first_mouse: false,
}
}
@ -79,6 +81,13 @@ impl WebviewAttributes {
self.clipboard = true;
self
}
/// Sets whether clicking an inactive window also clicks through to the webview.
#[must_use]
pub fn accept_first_mouse(mut self, accept: bool) -> Self {
self.accept_first_mouse = accept;
self
}
}
/// Do **NOT** implement this trait except for use in a custom [`Runtime`](crate::Runtime).

View File

@ -870,6 +870,9 @@ pub struct WindowConfig {
/// If `true`, sets the window title to be hidden on macOS.
#[serde(default, alias = "hidden-title")]
pub hidden_title: bool,
/// Whether clicking an inactive window also clicks through to the webview.
#[serde(default, alias = "accept-first-mouse")]
pub accept_first_mouse: bool,
}
impl Default for WindowConfig {
@ -901,6 +904,7 @@ impl Default for WindowConfig {
theme: None,
title_bar_style: Default::default(),
hidden_title: false,
accept_first_mouse: false,
}
}
}
@ -3032,6 +3036,7 @@ mod build {
let theme = opt_lit(self.theme.as_ref());
let title_bar_style = &self.title_bar_style;
let hidden_title = self.hidden_title;
let accept_first_mouse = self.accept_first_mouse;
literal_struct!(
tokens,
@ -3061,7 +3066,8 @@ mod build {
skip_taskbar,
theme,
title_bar_style,
hidden_title
hidden_title,
accept_first_mouse
);
}
}

File diff suppressed because one or more lines are too long

View File

@ -1484,14 +1484,13 @@ impl<R: Runtime> Builder<R> {
for config in manager.config().tauri.windows.clone() {
let url = config.url.clone();
let label = config.label.clone();
let file_drop_enabled = config.file_drop_enabled;
let user_agent = config.user_agent.clone();
let mut webview_attributes = WebviewAttributes::new(url);
if let Some(ua) = user_agent {
let mut webview_attributes =
WebviewAttributes::new(url).accept_first_mouse(config.accept_first_mouse);
if let Some(ua) = &config.user_agent {
webview_attributes = webview_attributes.user_agent(&ua.to_string());
}
if !file_drop_enabled {
if !config.file_drop_enabled {
webview_attributes = webview_attributes.disable_file_drop_handler();
}

View File

@ -535,6 +535,13 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
self.webview_attributes.clipboard = true;
self
}
/// Sets whether clicking an inactive window also clicks through to the webview.
#[must_use]
pub fn accept_first_mouse(mut self, accept: bool) -> Self {
self.webview_attributes.accept_first_mouse = accept;
self
}
}
// TODO: expand these docs since this is a pretty important type

View File

@ -2042,6 +2042,10 @@ interface WindowOptions {
* If `true`, sets the window title to be hidden on macOS.
*/
hiddenTitle?: boolean
/**
* Whether clicking an inactive window also clicks through to the webview.
*/
acceptFirstMouse?: boolean
/**
* The user agent for the webview.
*/

View File

@ -670,6 +670,11 @@
"description": "If `true`, sets the window title to be hidden on macOS.",
"default": false,
"type": "boolean"
},
"acceptFirstMouse": {
"description": "Whether clicking an inactive window also clicks through to the webview.",
"default": false,
"type": "boolean"
}
},
"additionalProperties": false