|
@@ -23,8 +23,8 @@ use crate::{
|
|
|
sealed::{ManagerBase, RuntimeOrDispatch},
|
|
|
utils::config::Config,
|
|
|
utils::{assets::Assets, resources::resource_relpath, Env},
|
|
|
- Context, EventLoopMessage, Invoke, InvokeError, InvokeResponse, Manager, Runtime, Scopes,
|
|
|
- StateManager, Theme, Window,
|
|
|
+ Context, DeviceEventFilter, EventLoopMessage, Invoke, InvokeError, InvokeResponse, Manager,
|
|
|
+ Runtime, Scopes, StateManager, Theme, Window,
|
|
|
};
|
|
|
|
|
|
#[cfg(shell_scope)]
|
|
@@ -805,6 +805,35 @@ impl<R: Runtime> App<R> {
|
|
|
.set_activation_policy(activation_policy);
|
|
|
}
|
|
|
|
|
|
+ /// Change the device event filter mode.
|
|
|
+ ///
|
|
|
+ /// Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, [`tao`]
|
|
|
+ /// will ignore them by default for unfocused windows on Windows. This method allows changing
|
|
|
+ /// the filter to explicitly capture them again.
|
|
|
+ ///
|
|
|
+ /// ## Platform-specific
|
|
|
+ ///
|
|
|
+ /// - ** Linux / macOS / iOS / Android**: Unsupported.
|
|
|
+ ///
|
|
|
+ /// # Examples
|
|
|
+ /// ```,no_run
|
|
|
+ /// let mut app = tauri::Builder::default()
|
|
|
+ /// // on an actual app, remove the string argument
|
|
|
+ /// .build(tauri::generate_context!("test/fixture/src-tauri/tauri.conf.json"))
|
|
|
+ /// .expect("error while building tauri application");
|
|
|
+ /// app.set_device_event_filter(tauri::DeviceEventFilter::Always);
|
|
|
+ /// app.run(|_app_handle, _event| {});
|
|
|
+ /// ```
|
|
|
+ ///
|
|
|
+ /// [`tao`]: https://crates.io/crates/tao
|
|
|
+ pub fn set_device_event_filter(&mut self, filter: DeviceEventFilter) {
|
|
|
+ self
|
|
|
+ .runtime
|
|
|
+ .as_mut()
|
|
|
+ .unwrap()
|
|
|
+ .set_device_event_filter(filter);
|
|
|
+ }
|
|
|
+
|
|
|
/// Gets the argument matches of the CLI definition configured in `tauri.conf.json`.
|
|
|
///
|
|
|
/// # Examples
|
|
@@ -1008,6 +1037,9 @@ pub struct Builder<R: Runtime> {
|
|
|
/// The updater configuration.
|
|
|
#[cfg(updater)]
|
|
|
updater_settings: UpdaterSettings,
|
|
|
+
|
|
|
+ /// The device event filter.
|
|
|
+ device_event_filter: DeviceEventFilter,
|
|
|
}
|
|
|
|
|
|
impl<R: Runtime> Builder<R> {
|
|
@@ -1036,6 +1068,7 @@ impl<R: Runtime> Builder<R> {
|
|
|
system_tray_event_listeners: Vec::new(),
|
|
|
#[cfg(updater)]
|
|
|
updater_settings: Default::default(),
|
|
|
+ device_event_filter: Default::default(),
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1486,6 +1519,28 @@ impl<R: Runtime> Builder<R> {
|
|
|
self
|
|
|
}
|
|
|
|
|
|
+ /// Change the device event filter mode.
|
|
|
+ ///
|
|
|
+ /// Since the DeviceEvent capture can lead to high CPU usage for unfocused windows, [`tao`]
|
|
|
+ /// will ignore them by default for unfocused windows on Windows. This method allows changing
|
|
|
+ /// the filter to explicitly capture them again.
|
|
|
+ ///
|
|
|
+ /// ## Platform-specific
|
|
|
+ ///
|
|
|
+ /// - ** Linux / macOS / iOS / Android**: Unsupported.
|
|
|
+ ///
|
|
|
+ /// # Examples
|
|
|
+ /// ```,no_run
|
|
|
+ /// tauri::Builder::default()
|
|
|
+ /// .device_event_filter(tauri::DeviceEventFilter::Always);
|
|
|
+ /// ```
|
|
|
+ ///
|
|
|
+ /// [`tao`]: https://crates.io/crates/tao
|
|
|
+ pub fn device_event_filter(mut self, filter: DeviceEventFilter) -> Self {
|
|
|
+ self.device_event_filter = filter;
|
|
|
+ self
|
|
|
+ }
|
|
|
+
|
|
|
/// Builds the application.
|
|
|
#[allow(clippy::type_complexity)]
|
|
|
pub fn build<A: Assets>(mut self, context: Context<A>) -> crate::Result<App<R>> {
|
|
@@ -1531,13 +1586,15 @@ impl<R: Runtime> Builder<R> {
|
|
|
}
|
|
|
|
|
|
#[cfg(any(windows, target_os = "linux"))]
|
|
|
- let runtime = if self.runtime_any_thread {
|
|
|
+ let mut runtime = if self.runtime_any_thread {
|
|
|
R::new_any_thread()?
|
|
|
} else {
|
|
|
R::new()?
|
|
|
};
|
|
|
#[cfg(not(any(windows, target_os = "linux")))]
|
|
|
- let runtime = R::new()?;
|
|
|
+ let mut runtime = R::new()?;
|
|
|
+
|
|
|
+ runtime.set_device_event_filter(self.device_event_filter);
|
|
|
|
|
|
let runtime_handle = runtime.handle();
|
|
|
|