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
5 changed files with 30 additions and 6 deletions
|
|
@ -136,6 +136,7 @@ declare_class!(
|
|||
_ns_window: IvarDrop<Id<WinitWindow, Shared>>,
|
||||
pub(super) state: IvarDrop<Box<ViewState>>,
|
||||
marked_text: IvarDrop<Id<NSMutableAttributedString, Owned>>,
|
||||
accepts_first_mouse: bool,
|
||||
}
|
||||
|
||||
unsafe impl ClassType for WinitView {
|
||||
|
|
@ -144,8 +145,12 @@ declare_class!(
|
|||
}
|
||||
|
||||
unsafe impl WinitView {
|
||||
#[sel(initWithId:)]
|
||||
fn init_with_id(&mut self, window: *mut WinitWindow) -> Option<&mut Self> {
|
||||
#[sel(initWithId:acceptsFirstMouse:)]
|
||||
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] };
|
||||
this.map(|this| {
|
||||
let state = ViewState {
|
||||
|
|
@ -165,6 +170,7 @@ declare_class!(
|
|||
);
|
||||
Ivar::write(&mut this.state, Box::new(state));
|
||||
Ivar::write(&mut this.marked_text, NSMutableAttributedString::new());
|
||||
Ivar::write(&mut this.accepts_first_mouse, accepts_first_mouse);
|
||||
|
||||
this.setPostsFrameChangedNotifications(true);
|
||||
|
||||
|
|
@ -911,14 +917,20 @@ declare_class!(
|
|||
#[sel(acceptsFirstMouse:)]
|
||||
fn accepts_first_mouse(&self, _event: &NSEvent) -> bool {
|
||||
trace_scope!("acceptsFirstMouse:");
|
||||
true
|
||||
*self.accepts_first_mouse
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
impl WinitView {
|
||||
pub(super) fn new(window: &WinitWindow) -> Id<Self, Shared> {
|
||||
unsafe { msg_send_id![msg_send_id![Self::class(), alloc], initWithId: window] }
|
||||
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,
|
||||
acceptsFirstMouse: accepts_first_mouse,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn window(&self) -> Id<WinitWindow, Shared> {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -93,6 +94,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
|||
fullsize_content_view: false,
|
||||
disallow_hidpi: false,
|
||||
has_shadow: true,
|
||||
accepts_first_mouse: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -354,7 +356,7 @@ impl WinitWindow {
|
|||
})
|
||||
.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
|
||||
// macos 10.14 and `true` after 10.15, we should set it to `YES` or `NO` to avoid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue