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

Accepts first mouse #2457

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, fixed ALT+Space shortcut to open window menu.
- On Wayland, fixed `Ime::Preedit` not being sent on IME reset.
- Fixed unbound version specified for `raw-window-handle` leading to compilation failures.
- On MacOS, made `accepts_first_mouse` configurable.

# 0.27.2 (2022-8-12)

Expand Down
1 change: 1 addition & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ If your PR makes notable changes to Winit's features, please update this section
* Hidden titlebar
* Hidden titlebar buttons
* Full-size content view
* Accepts first mouse

### Unix
* Window urgency
Expand Down
8 changes: 8 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub trait WindowBuilderExtMacOS {
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
fn with_has_shadow(self, has_shadow: bool) -> WindowBuilder;
/// Window accepts click-through mouse events.
fn with_accepts_first_mouse(self, accepts_first_mouse: bool) -> WindowBuilder;
}

impl WindowBuilderExtMacOS for WindowBuilder {
Expand Down Expand Up @@ -164,6 +166,12 @@ impl WindowBuilderExtMacOS for WindowBuilder {
self.platform_specific.has_shadow = has_shadow;
self
}

#[inline]
fn with_accepts_first_mouse(mut self, accepts_first_mouse: bool) -> WindowBuilder {
self.platform_specific.accepts_first_mouse = accepts_first_mouse;
self
}
}

pub trait EventLoopBuilderExtMacOS {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ declare_class!(
#[sel(acceptsFirstMouse:)]
fn accepts_first_mouse(&self, _event: &NSEvent) -> bool {
trace_scope!("acceptsFirstMouse:");
true
self.window().accepts_first_mouse()
}
}
);
Expand Down
10 changes: 10 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub fullsize_content_view: bool,
pub disallow_hidpi: bool,
pub has_shadow: bool,
pub accepts_first_mouse: bool,
}

impl Default for PlatformSpecificWindowBuilderAttributes {
Expand All @@ -93,6 +94,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
fullsize_content_view: false,
disallow_hidpi: false,
has_shadow: true,
accepts_first_mouse: true,
}
}
}
Expand Down Expand Up @@ -149,6 +151,7 @@ pub struct SharedState {
/// bar in exclusive fullscreen but want to restore the original options when
/// transitioning back to borderless fullscreen.
save_presentation_opts: Option<NSApplicationPresentationOptions>,
accepts_first_mouse: bool,
madsmtm marked this conversation as resolved.
Show resolved Hide resolved
}

impl SharedState {
Expand Down Expand Up @@ -287,6 +290,7 @@ impl WinitWindow {
let state = SharedState {
resizable: attrs.resizable,
maximized: attrs.maximized,
accepts_first_mouse: pl_attrs.accepts_first_mouse,
..Default::default()
};
Ivar::write(
Expand Down Expand Up @@ -1106,6 +1110,12 @@ impl WinitWindow {
util::set_style_mask_sync(self, current_style_mask & (!mask));
}
}

#[inline]
pub fn accepts_first_mouse(&self) -> bool {
let shared_state_lock = self.shared_state.lock().unwrap();
shared_state_lock.accepts_first_mouse
}
}

impl WindowExtMacOS for WinitWindow {
Expand Down