mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Accepts first mouse (#2457)
* MacOS: set value for `accepts_first_mouse` * Update CHANGELOG and FEATURES * Field doesn't need to be public * Convert `bool` to `BOOL` * Fix formatting * Move flag from window state to view instance * Feedback from PR * Fix changelog location
This commit is contained in:
parent
58f2455aa9
commit
48b843e42d
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On MacOS, made `accepts_first_mouse` configurable.
|
||||||
- Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`.
|
- Migrated `WindowBuilderExtUnix::with_resize_increments` to `WindowBuilder`.
|
||||||
- Added `Window::resize_increments`/`Window::set_resize_increments` to update resize increments at runtime for X11/macOS.
|
- Added `Window::resize_increments`/`Window::set_resize_increments` to update resize increments at runtime for X11/macOS.
|
||||||
- macOS/iOS: Use `objc2` instead of `objc` internally.
|
- macOS/iOS: Use `objc2` instead of `objc` internally.
|
||||||
|
|
|
@ -129,6 +129,7 @@ If your PR makes notable changes to Winit's features, please update this section
|
||||||
* Hidden titlebar
|
* Hidden titlebar
|
||||||
* Hidden titlebar buttons
|
* Hidden titlebar buttons
|
||||||
* Full-size content view
|
* Full-size content view
|
||||||
|
* Accepts first mouse
|
||||||
|
|
||||||
### Unix
|
### Unix
|
||||||
* Window urgency
|
* Window urgency
|
||||||
|
|
|
@ -111,6 +111,8 @@ pub trait WindowBuilderExtMacOS {
|
||||||
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
|
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
|
||||||
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
|
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
|
||||||
fn with_has_shadow(self, has_shadow: 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 {
|
impl WindowBuilderExtMacOS for WindowBuilder {
|
||||||
|
@ -164,6 +166,12 @@ impl WindowBuilderExtMacOS for WindowBuilder {
|
||||||
self.platform_specific.has_shadow = has_shadow;
|
self.platform_specific.has_shadow = has_shadow;
|
||||||
self
|
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 {
|
pub trait EventLoopBuilderExtMacOS {
|
||||||
|
|
|
@ -136,6 +136,7 @@ declare_class!(
|
||||||
_ns_window: IvarDrop<Id<WinitWindow, Shared>>,
|
_ns_window: IvarDrop<Id<WinitWindow, Shared>>,
|
||||||
pub(super) state: IvarDrop<Box<ViewState>>,
|
pub(super) state: IvarDrop<Box<ViewState>>,
|
||||||
marked_text: IvarDrop<Id<NSMutableAttributedString, Owned>>,
|
marked_text: IvarDrop<Id<NSMutableAttributedString, Owned>>,
|
||||||
|
accepts_first_mouse: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl ClassType for WinitView {
|
unsafe impl ClassType for WinitView {
|
||||||
|
@ -144,8 +145,12 @@ declare_class!(
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl WinitView {
|
unsafe impl WinitView {
|
||||||
#[sel(initWithId:)]
|
#[sel(initWithId:acceptsFirstMouse:)]
|
||||||
fn init_with_id(&mut self, window: *mut WinitWindow) -> Option<&mut Self> {
|
fn init_with_id(
|
||||||
|
&mut self,
|
||||||
|
window: *mut WinitWindow,
|
||||||
|
accepts_first_mouse: bool,
|
||||||
|
) -> Option<&mut Self> {
|
||||||
let this: Option<&mut Self> = unsafe { msg_send![super(self), init] };
|
let this: Option<&mut Self> = unsafe { msg_send![super(self), init] };
|
||||||
this.map(|this| {
|
this.map(|this| {
|
||||||
let state = ViewState {
|
let state = ViewState {
|
||||||
|
@ -165,6 +170,7 @@ declare_class!(
|
||||||
);
|
);
|
||||||
Ivar::write(&mut this.state, Box::new(state));
|
Ivar::write(&mut this.state, Box::new(state));
|
||||||
Ivar::write(&mut this.marked_text, NSMutableAttributedString::new());
|
Ivar::write(&mut this.marked_text, NSMutableAttributedString::new());
|
||||||
|
Ivar::write(&mut this.accepts_first_mouse, accepts_first_mouse);
|
||||||
|
|
||||||
this.setPostsFrameChangedNotifications(true);
|
this.setPostsFrameChangedNotifications(true);
|
||||||
|
|
||||||
|
@ -911,14 +917,20 @@ declare_class!(
|
||||||
#[sel(acceptsFirstMouse:)]
|
#[sel(acceptsFirstMouse:)]
|
||||||
fn accepts_first_mouse(&self, _event: &NSEvent) -> bool {
|
fn accepts_first_mouse(&self, _event: &NSEvent) -> bool {
|
||||||
trace_scope!("acceptsFirstMouse:");
|
trace_scope!("acceptsFirstMouse:");
|
||||||
true
|
*self.accepts_first_mouse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
impl WinitView {
|
impl WinitView {
|
||||||
pub(super) fn new(window: &WinitWindow) -> Id<Self, Shared> {
|
pub(super) fn new(window: &WinitWindow, accepts_first_mouse: bool) -> Id<Self, Shared> {
|
||||||
unsafe { msg_send_id![msg_send_id![Self::class(), alloc], initWithId: window] }
|
unsafe {
|
||||||
|
msg_send_id![
|
||||||
|
msg_send_id![Self::class(), alloc],
|
||||||
|
initWithId: window,
|
||||||
|
acceptsFirstMouse: accepts_first_mouse,
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window(&self) -> Id<WinitWindow, Shared> {
|
fn window(&self) -> Id<WinitWindow, Shared> {
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
pub fullsize_content_view: bool,
|
pub fullsize_content_view: bool,
|
||||||
pub disallow_hidpi: bool,
|
pub disallow_hidpi: bool,
|
||||||
pub has_shadow: bool,
|
pub has_shadow: bool,
|
||||||
|
pub accepts_first_mouse: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||||
|
@ -93,6 +94,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||||
fullsize_content_view: false,
|
fullsize_content_view: false,
|
||||||
disallow_hidpi: false,
|
disallow_hidpi: false,
|
||||||
has_shadow: true,
|
has_shadow: true,
|
||||||
|
accepts_first_mouse: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -354,7 +356,7 @@ impl WinitWindow {
|
||||||
})
|
})
|
||||||
.ok_or_else(|| os_error!(OsError::CreationError("Couldn't create `NSWindow`")))?;
|
.ok_or_else(|| os_error!(OsError::CreationError("Couldn't create `NSWindow`")))?;
|
||||||
|
|
||||||
let view = WinitView::new(&this);
|
let view = WinitView::new(&this, pl_attrs.accepts_first_mouse);
|
||||||
|
|
||||||
// The default value of `setWantsBestResolutionOpenGLSurface:` was `false` until
|
// The default value of `setWantsBestResolutionOpenGLSurface:` was `false` until
|
||||||
// macos 10.14 and `true` after 10.15, we should set it to `YES` or `NO` to avoid
|
// macos 10.14 and `true` after 10.15, we should set it to `YES` or `NO` to avoid
|
||||||
|
|
Loading…
Reference in a new issue