From 22d6bcacbb2001eb292ebd8c5d021447700f9512 Mon Sep 17 00:00:00 2001 From: Sean Wang <126865849+WSH032@users.noreply.github.com> Date: Sun, 17 Aug 2025 02:30:46 +0800 Subject: [PATCH] feat(tauri): impl `App::set_device_event_filter` for `AppHandle` also (#14008) * feat(tauri): impl `App::set_device_event_filter` for `AppHandle` also * Update .changes/impl-set_device_event_filter-for-apphandle.md * Update .changes/impl-set_device_event_filter-for-apphandle.md --------- Co-authored-by: Lucas Fernandes Nogueira --- .../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 000000000..834b3d6c8 --- /dev/null +++ b/.changes/impl-set_device_event_filter-for-apphandle.md @@ -0,0 +1,7 @@ +--- +"tauri-runtime-wry": minor:feat +"tauri-runtime": minor:feat +"tauri": minor:feat +--- + +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 f3873174e..6fc0c2ee9 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -1434,6 +1434,7 @@ pub enum WebviewMessage { pub enum EventLoopWindowTargetMessage { CursorPosition(Sender>>), SetTheme(Option), + SetDeviceEventFilter(DeviceEventFilter), } pub type CreateWindowClosure = @@ -2641,6 +2642,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, @@ -3901,6 +3909,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 f8b97cffd..051a82d69 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 16c1b0d98..9faa6b9ce 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 297de2acf..8662d6d1a 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,