فهرست منبع

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

Lucas Fernandes Nogueira 2 سال پیش
والد
کامیت
95f467add5

+ 5 - 0
.changes/accept-first-mouse-api.md

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

+ 6 - 0
.changes/accept-first-mouse.md

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

+ 2 - 1
core/tauri-runtime-wry/src/lib.rs

@@ -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()));

+ 9 - 0
core/tauri-runtime/src/webview.rs

@@ -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).

+ 7 - 1
core/tauri-utils/src/config.rs

@@ -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
       );
     }
   }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
core/tauri/scripts/bundle.global.js


+ 4 - 5
core/tauri/src/app.rs

@@ -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();
       }
 

+ 7 - 0
core/tauri/src/window.rs

@@ -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

+ 4 - 0
tooling/api/src/window.ts

@@ -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.
    */

+ 5 - 0
tooling/cli/schema.json

@@ -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

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است