Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: disable mouse event when building windows on Linux, closes #5913 #6025

Merged
merged 10 commits into from
Jan 16, 2023
6 changes: 6 additions & 0 deletions .changes/linux-mouse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-runtime-wry": patch
---

On Linux, disable mouse event when creating windows with `with_config`.

12 changes: 12 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ impl WindowBuilder for WindowBuilderWrapper {
");
}

#[cfg(target_os = "linux")]
{
// Mouse event is disabled on Linux since sudden event bursts could block event loop.
window = window.mouse_event(false);
}

if let (Some(min_width), Some(min_height)) = (config.min_width, config.min_height) {
window = window.min_inner_size(min_width, min_height);
}
Expand Down Expand Up @@ -950,6 +956,12 @@ impl WindowBuilder for WindowBuilderWrapper {
fn get_menu(&self) -> Option<&Menu> {
self.menu.as_ref()
}

#[cfg(target_os = "linux")]
fn mouse_event(mut self, enable: bool) -> Self {
self.inner = self.inner.with_cursor_moved_event(enable);
self
}
}

pub struct FileDropEventWrapper(WryFileDropEvent);
Expand Down
5 changes: 5 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ pub trait WindowBuilder: WindowBuilderBase {

/// Gets the window menu.
fn get_menu(&self) -> Option<&Menu>;

/// Disables mouse events on Linux.
#[cfg(target_os = "linux")]
#[must_use]
fn mouse_event(self, enable: bool) -> Self;
}

/// IPC handler.
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/test/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ impl WindowBuilder for MockWindowBuilder {
fn get_menu(&self) -> Option<&Menu> {
None
}

#[cfg(target_os = "linux")]
fn mouse_event(self, enable: bool) -> Self {
self
}
}

impl<T: UserEvent> Dispatch<T> for MockDispatcher {
Expand Down