Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/impl-set_device_event_filter-for-apphandle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-runtime-wry": minor:feat
"tauri-runtime": minor:feat
"tauri": minor:feat
Comment thread
lucasfernog marked this conversation as resolved.
---

Implement `App::set_device_event_filter` for `AppHandle` also.
11 changes: 11 additions & 0 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@ pub enum WebviewMessage {
pub enum EventLoopWindowTargetMessage {
CursorPosition(Sender<Result<PhysicalPosition<f64>>>),
SetTheme(Option<Theme>),
SetDeviceEventFilter(DeviceEventFilter),
}

pub type CreateWindowClosure<T> =
Expand Down Expand Up @@ -2637,6 +2638,13 @@ impl<T: UserEvent> RuntimeHandle<T> for WryHandle<T> {
)
}

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,
Expand Down Expand Up @@ -3892,6 +3900,9 @@ fn handle_user_message<T: UserEvent>(
EventLoopWindowTargetMessage::SetTheme(theme) => {
event_loop.set_theme(to_tao_theme(theme));
}
EventLoopWindowTargetMessage::SetDeviceEventFilter(filter) => {
event_loop.set_device_event_filter(DeviceEventFilterWrapper::from(filter).0);
}
},
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,15 @@ pub trait RuntimeHandle<T: UserEvent>: 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>(
Expand Down
11 changes: 11 additions & 0 deletions crates/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,17 @@ impl<R: Runtime> AppHandle<R> {
.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<R: Runtime> Manager<R> for AppHandle<R> {
Expand Down
4 changes: 4 additions & 0 deletions crates/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ impl<T: UserEvent> RuntimeHandle<T> for MockRuntimeHandle {
Ok(())
}

fn set_device_event_filter(&self, _: DeviceEventFilter) {
// no-op
}

#[cfg(target_os = "android")]
fn find_class<'a>(
&self,
Expand Down
Loading