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

Add command for setting mouse passthrough #2284

Merged
merged 1 commit into from
Sep 5, 2024
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
28 changes: 28 additions & 0 deletions runtime/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ pub enum Action {

/// Screenshot the viewport of the window.
Screenshot(Id, oneshot::Sender<Screenshot>),

/// Enables mouse passthrough for the given window.
///
/// This disables mouse events for the window and passes mouse events
/// through to whatever window is underneath.
EnableMousePassthrough(Id),

/// Disable mouse passthrough for the given window.
///
/// This enables mouse events for the window and stops mouse events
/// from being passed to whatever is underneath.
DisableMousePassthrough(Id),
}

/// Subscribes to the frames of the window of the running application.
Expand Down Expand Up @@ -406,3 +418,19 @@ pub fn screenshot(id: Id) -> Task<Screenshot> {
crate::Action::Window(Action::Screenshot(id, channel))
})
}

/// Enables mouse passthrough for the given window.
///
/// This disables mouse events for the window and passes mouse events
/// through to whatever window is underneath.
pub fn enable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::EnableMousePassthrough(id)))
}

/// Disable mouse passthrough for the given window.
///
/// This enables mouse events for the window and stops mouse events
/// from being passed to whatever is underneath.
pub fn disable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::DisableMousePassthrough(id)))
}
10 changes: 10 additions & 0 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,16 @@ fn run_action<P, C>(
));
}
}
window::Action::EnableMousePassthrough(id) => {
if let Some(window) = window_manager.get_mut(id) {
let _ = window.raw.set_cursor_hittest(false);
}
}
window::Action::DisableMousePassthrough(id) => {
if let Some(window) = window_manager.get_mut(id) {
let _ = window.raw.set_cursor_hittest(true);
}
}
},
Action::System(action) => match action {
system::Action::QueryInformation(_channel) => {
Expand Down
Loading