From 0f17521cc3b21c8ba3690283ec8621e8ebdc6fbd Mon Sep 17 00:00:00 2001 From: WSH032 <614337162@qq.com> Date: Fri, 15 Aug 2025 16:19:30 +0800 Subject: [PATCH 1/3] feat(tauri): impl `App::set_device_event_filter` for `AppHandle` also --- .../impl-set_device_event_filter-for-apphandle.md | 7 +++++++ crates/tauri-runtime-wry/src/lib.rs | 11 +++++++++++ crates/tauri-runtime/src/lib.rs | 9 +++++++++ crates/tauri/src/app.rs | 11 +++++++++++ crates/tauri/src/test/mock_runtime.rs | 4 ++++ 5 files changed, 42 insertions(+) create mode 100644 .changes/impl-set_device_event_filter-for-apphandle.md diff --git a/.changes/impl-set_device_event_filter-for-apphandle.md b/.changes/impl-set_device_event_filter-for-apphandle.md new file mode 100644 index 000000000000..b22818599552 --- /dev/null +++ b/.changes/impl-set_device_event_filter-for-apphandle.md @@ -0,0 +1,7 @@ +--- +"tauri-runtime-wry": minor +"tauri-runtime": minor +"tauri": minor +--- + +Implement `App::set_device_event_filter` for `AppHandle` also. diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 0708d28c08db..d39daafd9212 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -1430,6 +1430,7 @@ pub enum WebviewMessage { pub enum EventLoopWindowTargetMessage { CursorPosition(Sender>>), SetTheme(Option), + SetDeviceEventFilter(DeviceEventFilter), } pub type CreateWindowClosure = @@ -2637,6 +2638,13 @@ impl RuntimeHandle for WryHandle { ) } + fn set_device_event_filter(&self, filter: DeviceEventFilter) { + let _ = send_user_message( + &self.context, + Message::EventLoopWindowTarget(EventLoopWindowTargetMessage::SetDeviceEventFilter(filter)), + ); + } + #[cfg(target_os = "android")] fn find_class<'a>( &self, @@ -3892,6 +3900,9 @@ fn handle_user_message( EventLoopWindowTargetMessage::SetTheme(theme) => { event_loop.set_theme(to_tao_theme(theme)); } + EventLoopWindowTargetMessage::SetDeviceEventFilter(filter) => { + event_loop.set_device_event_filter(DeviceEventFilterWrapper::from(filter).0); + } }, } } diff --git a/crates/tauri-runtime/src/lib.rs b/crates/tauri-runtime/src/lib.rs index f8b97cffddfc..051a82d69723 100644 --- a/crates/tauri-runtime/src/lib.rs +++ b/crates/tauri-runtime/src/lib.rs @@ -329,6 +329,15 @@ pub trait RuntimeHandle: Debug + Clone + Send + Sync + Sized + 'st #[cfg_attr(docsrs, doc(cfg(target_os = "macos")))] fn hide(&self) -> Result<()>; + /// Change the device event filter mode. + /// + /// See [Runtime::set_device_event_filter] for details. + /// + /// ## Platform-specific + /// + /// See [Runtime::set_device_event_filter] for details. + fn set_device_event_filter(&self, filter: DeviceEventFilter); + /// Finds an Android class in the project scope. #[cfg(target_os = "android")] fn find_class<'a>( diff --git a/crates/tauri/src/app.rs b/crates/tauri/src/app.rs index 16c1b0d981a8..9faa6b9ceb9c 100644 --- a/crates/tauri/src/app.rs +++ b/crates/tauri/src/app.rs @@ -623,6 +623,17 @@ impl AppHandle { .set_dock_visibility(visible) .map_err(Into::into) } + + /// Change the device event filter mode. + /// + /// See [App::set_device_event_filter] for details. + /// + /// ## Platform-specific + /// + /// See [App::set_device_event_filter] for details. + pub fn set_device_event_filter(&self, filter: DeviceEventFilter) { + self.runtime_handle.set_device_event_filter(filter); + } } impl Manager for AppHandle { diff --git a/crates/tauri/src/test/mock_runtime.rs b/crates/tauri/src/test/mock_runtime.rs index 297de2acfa9a..8662d6d1ae56 100644 --- a/crates/tauri/src/test/mock_runtime.rs +++ b/crates/tauri/src/test/mock_runtime.rs @@ -270,6 +270,10 @@ impl RuntimeHandle for MockRuntimeHandle { Ok(()) } + fn set_device_event_filter(&self, _: DeviceEventFilter) { + // no-op + } + #[cfg(target_os = "android")] fn find_class<'a>( &self, From 3f754ddf47ae2740042040b3ce904b57d514122d Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 16 Aug 2025 14:55:28 -0300 Subject: [PATCH 2/3] Update .changes/impl-set_device_event_filter-for-apphandle.md --- .changes/impl-set_device_event_filter-for-apphandle.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.changes/impl-set_device_event_filter-for-apphandle.md b/.changes/impl-set_device_event_filter-for-apphandle.md index b22818599552..dc340e9d5bac 100644 --- a/.changes/impl-set_device_event_filter-for-apphandle.md +++ b/.changes/impl-set_device_event_filter-for-apphandle.md @@ -1,7 +1,6 @@ --- -"tauri-runtime-wry": minor -"tauri-runtime": minor -"tauri": minor ---- +"tauri-runtime-wry": minor:feat +"tauri-runtime": minor:feat +"tauri": minor:feat Implement `App::set_device_event_filter` for `AppHandle` also. From 15bc3b913b91bf98802941f6fdbd2c95fb710918 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 16 Aug 2025 14:55:41 -0300 Subject: [PATCH 3/3] Update .changes/impl-set_device_event_filter-for-apphandle.md --- .changes/impl-set_device_event_filter-for-apphandle.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changes/impl-set_device_event_filter-for-apphandle.md b/.changes/impl-set_device_event_filter-for-apphandle.md index dc340e9d5bac..834b3d6c8414 100644 --- a/.changes/impl-set_device_event_filter-for-apphandle.md +++ b/.changes/impl-set_device_event_filter-for-apphandle.md @@ -2,5 +2,6 @@ "tauri-runtime-wry": minor:feat "tauri-runtime": minor:feat "tauri": minor:feat +--- Implement `App::set_device_event_filter` for `AppHandle` also.