From da5fa932e59e47a286ae53d96e82eee6d72811bc Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 29 Aug 2022 14:36:04 +0200 Subject: [PATCH] Make `winit` work with `objc2` --- src/platform_impl/ios/app_state.rs | 4 +- src/platform_impl/ios/ffi.rs | 72 ++++++++---- src/platform_impl/ios/view.rs | 47 ++++---- src/platform_impl/macos/app.rs | 5 +- src/platform_impl/macos/app_delegate.rs | 8 +- src/platform_impl/macos/app_state.rs | 2 +- src/platform_impl/macos/event_loop.rs | 4 +- src/platform_impl/macos/ffi.rs | 25 ----- src/platform_impl/macos/menu.rs | 2 +- src/platform_impl/macos/mod.rs | 2 +- src/platform_impl/macos/util/async.rs | 2 +- src/platform_impl/macos/util/cursor.rs | 2 +- src/platform_impl/macos/util/mod.rs | 4 +- src/platform_impl/macos/view.rs | 125 ++++++++------------- src/platform_impl/macos/window.rs | 16 +-- src/platform_impl/macos/window_delegate.rs | 45 ++++---- 16 files changed, 158 insertions(+), 207 deletions(-) diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 0586084476d..8b5be97822c 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -9,7 +9,7 @@ use std::{ time::Instant, }; -use objc::runtime::{BOOL, YES}; +use objc::runtime::{Object, BOOL, YES}; use once_cell::sync::Lazy; use crate::{ @@ -582,7 +582,7 @@ pub unsafe fn did_finish_launching() { let _: () = msg_send![window, setScreen: screen]; let _: () = msg_send![screen, release]; let controller: id = msg_send![window, rootViewController]; - let _: () = msg_send![window, setRootViewController:ptr::null::<()>()]; + let _: () = msg_send![window, setRootViewController:ptr::null::()]; let _: () = msg_send![window, setRootViewController: controller]; let _: () = msg_send![window, makeKeyAndVisible]; } diff --git a/src/platform_impl/ios/ffi.rs b/src/platform_impl/ios/ffi.rs index a81f0ccab76..515e32dcf04 100644 --- a/src/platform_impl/ios/ffi.rs +++ b/src/platform_impl/ios/ffi.rs @@ -28,6 +28,17 @@ pub struct NSOperatingSystemVersion { pub patch: NSInteger, } +unsafe impl Encode for NSOperatingSystemVersion { + const ENCODING: Encoding = Encoding::Struct( + "NSOperatingSystemVersion", + &[ + NSInteger::ENCODING, + NSInteger::ENCODING, + NSInteger::ENCODING, + ], + ); +} + #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct CGPoint { @@ -35,6 +46,10 @@ pub struct CGPoint { pub y: CGFloat, } +unsafe impl Encode for CGPoint { + const ENCODING: Encoding = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct CGSize { @@ -51,6 +66,10 @@ impl CGSize { } } +unsafe impl Encode for CGSize { + const ENCODING: Encoding = Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + #[repr(C)] #[derive(Debug, Clone, Copy, PartialEq)] pub struct CGRect { @@ -65,18 +84,9 @@ impl CGRect { } unsafe impl Encode for CGRect { - fn encode() -> Encoding { - unsafe { - if cfg!(target_pointer_width = "32") { - Encoding::from_str("{CGRect={CGPoint=ff}{CGSize=ff}}") - } else if cfg!(target_pointer_width = "64") { - Encoding::from_str("{CGRect={CGPoint=dd}{CGSize=dd}}") - } else { - unimplemented!() - } - } - } + const ENCODING: Encoding = Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); } + #[derive(Debug)] #[allow(dead_code)] #[repr(isize)] @@ -88,6 +98,10 @@ pub enum UITouchPhase { Cancelled, } +unsafe impl Encode for UITouchPhase { + const ENCODING: Encoding = NSInteger::ENCODING; +} + #[derive(Debug, PartialEq, Eq)] #[allow(dead_code)] #[repr(isize)] @@ -97,6 +111,10 @@ pub enum UIForceTouchCapability { Available, } +unsafe impl Encode for UIForceTouchCapability { + const ENCODING: Encoding = NSInteger::ENCODING; +} + #[derive(Debug, PartialEq, Eq)] #[allow(dead_code)] #[repr(isize)] @@ -106,6 +124,10 @@ pub enum UITouchType { Pencil, } +unsafe impl Encode for UITouchType { + const ENCODING: Encoding = NSInteger::ENCODING; +} + #[repr(C)] #[derive(Debug, Clone)] pub struct UIEdgeInsets { @@ -115,14 +137,24 @@ pub struct UIEdgeInsets { pub right: CGFloat, } +unsafe impl Encode for UIEdgeInsets { + const ENCODING: Encoding = Encoding::Struct( + "UIEdgeInsets", + &[ + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + ], + ); +} + #[repr(transparent)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct UIUserInterfaceIdiom(NSInteger); unsafe impl Encode for UIUserInterfaceIdiom { - fn encode() -> Encoding { - NSInteger::encode() - } + const ENCODING: Encoding = NSInteger::ENCODING; } impl UIUserInterfaceIdiom { @@ -162,9 +194,7 @@ impl From for Idiom { pub struct UIInterfaceOrientationMask(NSUInteger); unsafe impl Encode for UIInterfaceOrientationMask { - fn encode() -> Encoding { - NSUInteger::encode() - } + const ENCODING: Encoding = NSUInteger::ENCODING; } impl UIInterfaceOrientationMask { @@ -213,9 +243,7 @@ impl UIInterfaceOrientationMask { pub struct UIRectEdge(NSUInteger); unsafe impl Encode for UIRectEdge { - fn encode() -> Encoding { - NSUInteger::encode() - } + const ENCODING: Encoding = NSUInteger::ENCODING; } impl From for UIRectEdge { @@ -241,9 +269,7 @@ impl From for ScreenEdge { pub struct UIScreenOverscanCompensation(NSInteger); unsafe impl Encode for UIScreenOverscanCompensation { - fn encode() -> Encoding { - NSInteger::encode() - } + const ENCODING: Encoding = NSInteger::ENCODING; } #[allow(dead_code)] diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 727b7152693..c4d475609a4 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -70,11 +70,11 @@ macro_rules! add_property { } $decl.add_method( sel!($setter_name:), - setter as extern "C" fn(&mut Object, Sel, $t), + setter as extern "C" fn(_, _, _), ); $decl.add_method( sel!($getter_name), - $getter_name as extern "C" fn(&Object, Sel) -> $t, + $getter_name as extern "C" fn(_, _) -> _, ); } }; @@ -156,11 +156,12 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { untrusted_scale_factor: CGFloat, ) { unsafe { - let superclass: &'static Class = msg_send![object, superclass]; + let superclass: &'static Class = msg_send![&*object, superclass]; let _: () = msg_send![ - super(object, superclass), + super(&mut *object, superclass), setContentScaleFactor: untrusted_scale_factor ]; + let object = &*object; // Immutable for rest of method let window: id = msg_send![object, window]; // `window` is null when `setContentScaleFactor` is invoked prior to `[UIWindow @@ -283,34 +284,28 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { let mut decl = ClassDecl::new(&format!("WinitUIView{}", ID), root_view_class) .expect("Failed to declare class `WinitUIView`"); ID += 1; - decl.add_method( - sel!(drawRect:), - draw_rect as extern "C" fn(&Object, Sel, CGRect), - ); - decl.add_method( - sel!(layoutSubviews), - layout_subviews as extern "C" fn(&Object, Sel), - ); + decl.add_method(sel!(drawRect:), draw_rect as extern "C" fn(_, _, _)); + decl.add_method(sel!(layoutSubviews), layout_subviews as extern "C" fn(_, _)); decl.add_method( sel!(setContentScaleFactor:), - set_content_scale_factor as extern "C" fn(&mut Object, Sel, CGFloat), + set_content_scale_factor as extern "C" fn(_, _, _), ); decl.add_method( sel!(touchesBegan:withEvent:), - handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id), + handle_touches as extern "C" fn(_, _, _, _), ); decl.add_method( sel!(touchesMoved:withEvent:), - handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id), + handle_touches as extern "C" fn(_, _, _, _), ); decl.add_method( sel!(touchesEnded:withEvent:), - handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id), + handle_touches as extern "C" fn(_, _, _, _), ); decl.add_method( sel!(touchesCancelled:withEvent:), - handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id), + handle_touches as extern "C" fn(_, _, _, _), ); decl.register() @@ -333,7 +328,7 @@ unsafe fn get_view_controller_class() -> &'static Class { .expect("Failed to declare class `WinitUIViewController`"); decl.add_method( sel!(shouldAutorotate), - should_autorotate as extern "C" fn(&Object, Sel) -> BOOL, + should_autorotate as extern "C" fn(_, _) -> _, ); add_property! { decl, @@ -416,11 +411,11 @@ unsafe fn get_window_class() -> &'static Class { .expect("Failed to declare class `WinitUIWindow`"); decl.add_method( sel!(becomeKeyWindow), - become_key_window as extern "C" fn(&Object, Sel), + become_key_window as extern "C" fn(_, _), ); decl.add_method( sel!(resignKeyWindow), - resign_key_window as extern "C" fn(&Object, Sel), + resign_key_window as extern "C" fn(_, _), ); CLASS = Some(decl.register()); @@ -594,29 +589,29 @@ pub fn create_delegate_class() { unsafe { decl.add_method( sel!(application:didFinishLaunchingWithOptions:), - did_finish_launching as extern "C" fn(&mut Object, Sel, id, id) -> BOOL, + did_finish_launching as extern "C" fn(_, _, _, _) -> _, ); decl.add_method( sel!(applicationDidBecomeActive:), - did_become_active as extern "C" fn(&Object, Sel, id), + did_become_active as extern "C" fn(_, _, _), ); decl.add_method( sel!(applicationWillResignActive:), - will_resign_active as extern "C" fn(&Object, Sel, id), + will_resign_active as extern "C" fn(_, _, _), ); decl.add_method( sel!(applicationWillEnterForeground:), - will_enter_foreground as extern "C" fn(&Object, Sel, id), + will_enter_foreground as extern "C" fn(_, _, _), ); decl.add_method( sel!(applicationDidEnterBackground:), - did_enter_background as extern "C" fn(&Object, Sel, id), + did_enter_background as extern "C" fn(_, _, _), ); decl.add_method( sel!(applicationWillTerminate:), - will_terminate as extern "C" fn(&Object, Sel, id), + will_terminate as extern "C" fn(_, _, _), ); decl.register(); diff --git a/src/platform_impl/macos/app.rs b/src/platform_impl/macos/app.rs index a4a6ef0b4d9..129c34a638a 100644 --- a/src/platform_impl/macos/app.rs +++ b/src/platform_impl/macos/app.rs @@ -21,10 +21,7 @@ pub static APP_CLASS: Lazy = Lazy::new(|| unsafe { let superclass = class!(NSApplication); let mut decl = ClassDecl::new("WinitApp", superclass).unwrap(); - decl.add_method( - sel!(sendEvent:), - send_event as extern "C" fn(&Object, Sel, id), - ); + decl.add_method(sel!(sendEvent:), send_event as extern "C" fn(_, _, _)); AppClass(decl.register()) }); diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index fc5ae7e4070..3a9954afcbd 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -27,16 +27,16 @@ pub static APP_DELEGATE_CLASS: Lazy = Lazy::new(|| unsafe { let superclass = class!(NSResponder); let mut decl = ClassDecl::new("WinitAppDelegate", superclass).unwrap(); - decl.add_class_method(sel!(new), new as extern "C" fn(&Class, Sel) -> id); - decl.add_method(sel!(dealloc), dealloc as extern "C" fn(&Object, Sel)); + decl.add_class_method(sel!(new), new as extern "C" fn(_, _) -> _); + decl.add_method(sel!(dealloc), dealloc as extern "C" fn(_, _)); decl.add_method( sel!(applicationDidFinishLaunching:), - did_finish_launching as extern "C" fn(&Object, Sel, id), + did_finish_launching as extern "C" fn(_, _, _), ); decl.add_method( sel!(applicationWillTerminate:), - will_terminate as extern "C" fn(&Object, Sel, id), + will_terminate as extern "C" fn(_, _, _), ); decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME); diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 711c99b1581..b655ed1454d 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -403,7 +403,7 @@ impl AppState { unsafe { let app: id = NSApp(); - autoreleasepool(|| { + autoreleasepool(|_| { let _: () = msg_send![app, stop: nil]; // To stop event loop immediately, we need to post some event here. post_dummy_event(app); diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index ea0315139c2..6075fd53294 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -161,7 +161,7 @@ impl EventLoop { aux_state.activation_policy = attributes.activation_policy; aux_state.default_menu = attributes.default_menu; - autoreleasepool(|| { + autoreleasepool(|_| { let _: () = msg_send![app, setDelegate:*delegate]; }); @@ -209,7 +209,7 @@ impl EventLoop { self._callback = Some(Rc::clone(&callback)); - let exit_code = autoreleasepool(|| unsafe { + let exit_code = autoreleasepool(|_| unsafe { let app = NSApp(); assert_ne!(app, nil); diff --git a/src/platform_impl/macos/ffi.rs b/src/platform_impl/macos/ffi.rs index 0a23e60d41c..5c6fbc797c1 100644 --- a/src/platform_impl/macos/ffi.rs +++ b/src/platform_impl/macos/ffi.rs @@ -18,31 +18,6 @@ use core_graphics::{ pub const NSNotFound: NSInteger = NSInteger::max_value(); -#[repr(C)] -pub struct NSRange { - pub location: NSUInteger, - pub length: NSUInteger, -} - -impl NSRange { - #[inline] - pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange { - NSRange { location, length } - } -} - -unsafe impl objc::Encode for NSRange { - fn encode() -> objc::Encoding { - let encoding = format!( - // TODO: Verify that this is correct - "{{NSRange={}{}}}", - NSUInteger::encode().as_str(), - NSUInteger::encode().as_str(), - ); - unsafe { objc::Encoding::from_str(&encoding) } - } -} - pub trait NSMutableAttributedString: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSMutableAttributedString), alloc] diff --git a/src/platform_impl/macos/menu.rs b/src/platform_impl/macos/menu.rs index 089874efc5e..a791869277e 100644 --- a/src/platform_impl/macos/menu.rs +++ b/src/platform_impl/macos/menu.rs @@ -13,7 +13,7 @@ struct KeyEquivalent<'a> { } pub fn initialize() { - autoreleasepool(|| unsafe { + autoreleasepool(|_| unsafe { let menubar = IdRef::new(NSMenu::new(nil)); let app_menu_item = IdRef::new(NSMenuItem::new(nil)); menubar.addItem_(*app_menu_item); diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index 4608e2fa42b..902565cc4b9 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -75,7 +75,7 @@ impl Window { attributes: WindowAttributes, pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { - let (window, _delegate) = autoreleasepool(|| UnownedWindow::new(attributes, pl_attribs))?; + let (window, _delegate) = autoreleasepool(|_| UnownedWindow::new(attributes, pl_attribs))?; Ok(Window { window, _delegate }) } } diff --git a/src/platform_impl/macos/util/async.rs b/src/platform_impl/macos/util/async.rs index bf7e33ea727..84f35f1f597 100644 --- a/src/platform_impl/macos/util/async.rs +++ b/src/platform_impl/macos/util/async.rs @@ -229,7 +229,7 @@ pub unsafe fn set_title_async(ns_window: id, title: String) { pub unsafe fn close_async(ns_window: IdRef) { let ns_window = MainThreadSafe(ns_window); Queue::main().exec_async(move || { - autoreleasepool(move || { + autoreleasepool(move |_| { ns_window.close(); }); }); diff --git a/src/platform_impl/macos/util/cursor.rs b/src/platform_impl/macos/util/cursor.rs index 48921ad2f5c..1e1574ce8e3 100644 --- a/src/platform_impl/macos/util/cursor.rs +++ b/src/platform_impl/macos/util/cursor.rs @@ -148,7 +148,7 @@ pub unsafe fn invisible_cursor() -> id { if *cursor_obj.borrow() == nil { // Create a cursor from `CURSOR_BYTES` let cursor_data: id = msg_send![class!(NSData), - dataWithBytesNoCopy:CURSOR_BYTES as *const [u8] + dataWithBytesNoCopy:CURSOR_BYTES.as_ptr() length:CURSOR_BYTES.len() freeWhenDone:NO ]; diff --git a/src/platform_impl/macos/util/mod.rs b/src/platform_impl/macos/util/mod.rs index 859bdb9c9d1..53217d8ca7a 100644 --- a/src/platform_impl/macos/util/mod.rs +++ b/src/platform_impl/macos/util/mod.rs @@ -9,7 +9,7 @@ use std::os::raw::c_uchar; use cocoa::{ appkit::{CGFloat, NSApp, NSWindowStyleMask}, base::{id, nil}, - foundation::{NSPoint, NSRect, NSString, NSUInteger}, + foundation::{NSPoint, NSRange, NSRect, NSString, NSUInteger}, }; use core_graphics::display::CGDisplay; use objc::runtime::{Class, Object, BOOL, NO}; @@ -28,7 +28,7 @@ where bitset & flag == flag } -pub const EMPTY_RANGE: ffi::NSRange = ffi::NSRange { +pub const EMPTY_RANGE: NSRange = NSRange { location: ffi::NSNotFound as NSUInteger, length: 0, }; diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 16bc457ecc6..44f9067159d 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -12,7 +12,7 @@ use std::{ use cocoa::{ appkit::{NSApp, NSEvent, NSEventModifierFlags, NSEventPhase, NSView, NSWindow}, base::{id, nil}, - foundation::{NSInteger, NSPoint, NSRect, NSSize, NSString, NSUInteger}, + foundation::{NSInteger, NSPoint, NSRange, NSRect, NSSize, NSString, NSUInteger}, }; use objc::{ declare::ClassDecl, @@ -165,169 +165,134 @@ unsafe impl Sync for ViewClass {} static VIEW_CLASS: Lazy = Lazy::new(|| unsafe { let superclass = class!(NSView); let mut decl = ClassDecl::new("WinitView", superclass).unwrap(); - decl.add_method(sel!(dealloc), dealloc as extern "C" fn(&Object, Sel)); + decl.add_method(sel!(dealloc), dealloc as extern "C" fn(_, _)); decl.add_method( sel!(initWithWinit:), - init_with_winit as extern "C" fn(&Object, Sel, *mut c_void) -> id, + init_with_winit as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(viewDidMoveToWindow), - view_did_move_to_window as extern "C" fn(&Object, Sel), - ); - decl.add_method( - sel!(drawRect:), - draw_rect as extern "C" fn(&Object, Sel, NSRect), + view_did_move_to_window as extern "C" fn(_, _), ); + decl.add_method(sel!(drawRect:), draw_rect as extern "C" fn(_, _, _)); decl.add_method( sel!(acceptsFirstResponder), - accepts_first_responder as extern "C" fn(&Object, Sel) -> BOOL, - ); - decl.add_method( - sel!(touchBar), - touch_bar as extern "C" fn(&Object, Sel) -> BOOL, + accepts_first_responder as extern "C" fn(_, _) -> _, ); + decl.add_method(sel!(touchBar), touch_bar as extern "C" fn(_, _) -> _); decl.add_method( sel!(resetCursorRects), - reset_cursor_rects as extern "C" fn(&Object, Sel), + reset_cursor_rects as extern "C" fn(_, _), ); // ------------------------------------------------------------------ // NSTextInputClient decl.add_method( sel!(hasMarkedText), - has_marked_text as extern "C" fn(&Object, Sel) -> BOOL, - ); - decl.add_method( - sel!(markedRange), - marked_range as extern "C" fn(&Object, Sel) -> NSRange, + has_marked_text as extern "C" fn(_, _) -> _, ); + decl.add_method(sel!(markedRange), marked_range as extern "C" fn(_, _) -> _); decl.add_method( sel!(selectedRange), - selected_range as extern "C" fn(&Object, Sel) -> NSRange, + selected_range as extern "C" fn(_, _) -> _, ); decl.add_method( sel!(setMarkedText:selectedRange:replacementRange:), - set_marked_text as extern "C" fn(&mut Object, Sel, id, NSRange, NSRange), + set_marked_text as extern "C" fn(_, _, _, _, _), ); - decl.add_method(sel!(unmarkText), unmark_text as extern "C" fn(&Object, Sel)); + decl.add_method(sel!(unmarkText), unmark_text as extern "C" fn(_, _)); decl.add_method( sel!(validAttributesForMarkedText), - valid_attributes_for_marked_text as extern "C" fn(&Object, Sel) -> id, + valid_attributes_for_marked_text as extern "C" fn(_, _) -> _, ); decl.add_method( sel!(attributedSubstringForProposedRange:actualRange:), - attributed_substring_for_proposed_range - as extern "C" fn(&Object, Sel, NSRange, *mut c_void) -> id, + attributed_substring_for_proposed_range as extern "C" fn(_, _, _, _) -> _, ); decl.add_method( sel!(insertText:replacementRange:), - insert_text as extern "C" fn(&Object, Sel, id, NSRange), + insert_text as extern "C" fn(_, _, _, _), ); decl.add_method( sel!(characterIndexForPoint:), - character_index_for_point as extern "C" fn(&Object, Sel, NSPoint) -> NSUInteger, + character_index_for_point as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(firstRectForCharacterRange:actualRange:), - first_rect_for_character_range - as extern "C" fn(&Object, Sel, NSRange, *mut c_void) -> NSRect, + first_rect_for_character_range as extern "C" fn(_, _, _, _) -> _, ); decl.add_method( sel!(doCommandBySelector:), - do_command_by_selector as extern "C" fn(&Object, Sel, Sel), + do_command_by_selector as extern "C" fn(_, _, _), ); // ------------------------------------------------------------------ - decl.add_method(sel!(keyDown:), key_down as extern "C" fn(&Object, Sel, id)); - decl.add_method(sel!(keyUp:), key_up as extern "C" fn(&Object, Sel, id)); - decl.add_method( - sel!(flagsChanged:), - flags_changed as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(insertTab:), - insert_tab as extern "C" fn(&Object, Sel, id), - ); + decl.add_method(sel!(keyDown:), key_down as extern "C" fn(_, _, _)); + decl.add_method(sel!(keyUp:), key_up as extern "C" fn(_, _, _)); + decl.add_method(sel!(flagsChanged:), flags_changed as extern "C" fn(_, _, _)); + decl.add_method(sel!(insertTab:), insert_tab as extern "C" fn(_, _, _)); decl.add_method( sel!(insertBackTab:), - insert_back_tab as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(mouseDown:), - mouse_down as extern "C" fn(&Object, Sel, id), + insert_back_tab as extern "C" fn(_, _, _), ); - decl.add_method(sel!(mouseUp:), mouse_up as extern "C" fn(&Object, Sel, id)); + decl.add_method(sel!(mouseDown:), mouse_down as extern "C" fn(_, _, _)); + decl.add_method(sel!(mouseUp:), mouse_up as extern "C" fn(_, _, _)); decl.add_method( sel!(rightMouseDown:), - right_mouse_down as extern "C" fn(&Object, Sel, id), + right_mouse_down as extern "C" fn(_, _, _), ); decl.add_method( sel!(rightMouseUp:), - right_mouse_up as extern "C" fn(&Object, Sel, id), + right_mouse_up as extern "C" fn(_, _, _), ); decl.add_method( sel!(otherMouseDown:), - other_mouse_down as extern "C" fn(&Object, Sel, id), + other_mouse_down as extern "C" fn(_, _, _), ); decl.add_method( sel!(otherMouseUp:), - other_mouse_up as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(mouseMoved:), - mouse_moved as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(mouseDragged:), - mouse_dragged as extern "C" fn(&Object, Sel, id), + other_mouse_up as extern "C" fn(_, _, _), ); + decl.add_method(sel!(mouseMoved:), mouse_moved as extern "C" fn(_, _, _)); + decl.add_method(sel!(mouseDragged:), mouse_dragged as extern "C" fn(_, _, _)); decl.add_method( sel!(rightMouseDragged:), - right_mouse_dragged as extern "C" fn(&Object, Sel, id), + right_mouse_dragged as extern "C" fn(_, _, _), ); decl.add_method( sel!(otherMouseDragged:), - other_mouse_dragged as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(mouseEntered:), - mouse_entered as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(mouseExited:), - mouse_exited as extern "C" fn(&Object, Sel, id), - ); - decl.add_method( - sel!(scrollWheel:), - scroll_wheel as extern "C" fn(&Object, Sel, id), + other_mouse_dragged as extern "C" fn(_, _, _), ); + decl.add_method(sel!(mouseEntered:), mouse_entered as extern "C" fn(_, _, _)); + decl.add_method(sel!(mouseExited:), mouse_exited as extern "C" fn(_, _, _)); + decl.add_method(sel!(scrollWheel:), scroll_wheel as extern "C" fn(_, _, _)); decl.add_method( sel!(magnifyWithEvent:), - magnify_with_event as extern "C" fn(&Object, Sel, id), + magnify_with_event as extern "C" fn(_, _, _), ); decl.add_method( sel!(rotateWithEvent:), - rotate_with_event as extern "C" fn(&Object, Sel, id), + rotate_with_event as extern "C" fn(_, _, _), ); decl.add_method( sel!(pressureChangeWithEvent:), - pressure_change_with_event as extern "C" fn(&Object, Sel, id), + pressure_change_with_event as extern "C" fn(_, _, _), ); decl.add_method( sel!(_wantsKeyDownForEvent:), - wants_key_down_for_event as extern "C" fn(&Object, Sel, id) -> BOOL, + wants_key_down_for_event as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(cancelOperation:), - cancel_operation as extern "C" fn(&Object, Sel, id), + cancel_operation as extern "C" fn(_, _, _), ); decl.add_method( sel!(frameDidChange:), - frame_did_change as extern "C" fn(&Object, Sel, id), + frame_did_change as extern "C" fn(_, _, _), ); decl.add_method( sel!(acceptsFirstMouse:), - accepts_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL, + accepts_first_mouse as extern "C" fn(_, _, _) -> _, ); decl.add_ivar::<*mut c_void>("winitState"); decl.add_ivar::("markedText"); @@ -364,7 +329,7 @@ extern "C" fn init_with_winit(this: &Object, _sel: Sel, state: *mut c_void) -> i notification_center, addObserver: this selector: sel!(frameDidChange:) - name: frame_did_change_notification_name + name: *frame_did_change_notification_name object: this ]; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index f804a275f21..4a63f9e2e0d 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -141,7 +141,7 @@ fn create_window( attrs: &WindowAttributes, pl_attrs: &PlatformSpecificWindowBuilderAttributes, ) -> Option { - autoreleasepool(|| unsafe { + autoreleasepool(|_| unsafe { let screen = match attrs.fullscreen { Some(Fullscreen::Borderless(Some(RootMonitorHandle { inner: ref monitor }))) | Some(Fullscreen::Exclusive(RootVideoMode { @@ -239,10 +239,7 @@ fn create_window( } if attrs.always_on_top { - let _: () = msg_send![ - *ns_window, - setLevel: ffi::NSWindowLevel::NSFloatingWindowLevel - ]; + let _: () = msg_send![*ns_window, setLevel: ffi::kCGFloatingWindowLevelKey]; } if let Some(increments) = pl_attrs.resize_increments { @@ -284,11 +281,11 @@ static WINDOW_CLASS: Lazy = Lazy::new(|| unsafe { decl.add_method( sel!(canBecomeMainWindow), - can_become_main_window as extern "C" fn(&Object, Sel) -> BOOL, + can_become_main_window as extern "C" fn(_, _) -> _, ); decl.add_method( sel!(canBecomeKeyWindow), - can_become_key_window as extern "C" fn(&Object, Sel) -> BOOL, + can_become_key_window as extern "C" fn(_, _) -> _, ); WindowClass(decl.register()) }); @@ -998,10 +995,7 @@ impl UnownedWindow { // Restore the normal window level following the Borderless fullscreen // `CGShieldingWindowLevel() + 1` hack. - let _: () = msg_send![ - *self.ns_window, - setLevel: ffi::NSWindowLevel::NSNormalWindowLevel - ]; + let _: () = msg_send![*self.ns_window, setLevel: ffi::kCGBaseWindowLevelKey]; }, _ => {} }; diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 001c89fdd3e..0dc5e8575e6 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -139,90 +139,89 @@ static WINDOW_DELEGATE_CLASS: Lazy = Lazy::new(|| unsafe { let superclass = class!(NSResponder); let mut decl = ClassDecl::new("WinitWindowDelegate", superclass).unwrap(); - decl.add_method(sel!(dealloc), dealloc as extern "C" fn(&Object, Sel)); + decl.add_method(sel!(dealloc), dealloc as extern "C" fn(_, _)); decl.add_method( sel!(initWithWinit:), - init_with_winit as extern "C" fn(&Object, Sel, *mut c_void) -> id, + init_with_winit as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(windowShouldClose:), - window_should_close as extern "C" fn(&Object, Sel, id) -> BOOL, + window_should_close as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(windowWillClose:), - window_will_close as extern "C" fn(&Object, Sel, id), + window_will_close as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidResize:), - window_did_resize as extern "C" fn(&Object, Sel, id), + window_did_resize as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidMove:), - window_did_move as extern "C" fn(&Object, Sel, id), + window_did_move as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidChangeBackingProperties:), - window_did_change_backing_properties as extern "C" fn(&Object, Sel, id), + window_did_change_backing_properties as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidBecomeKey:), - window_did_become_key as extern "C" fn(&Object, Sel, id), + window_did_become_key as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidResignKey:), - window_did_resign_key as extern "C" fn(&Object, Sel, id), + window_did_resign_key as extern "C" fn(_, _, _), ); decl.add_method( sel!(draggingEntered:), - dragging_entered as extern "C" fn(&Object, Sel, id) -> BOOL, + dragging_entered as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(prepareForDragOperation:), - prepare_for_drag_operation as extern "C" fn(&Object, Sel, id) -> BOOL, + prepare_for_drag_operation as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(performDragOperation:), - perform_drag_operation as extern "C" fn(&Object, Sel, id) -> BOOL, + perform_drag_operation as extern "C" fn(_, _, _) -> _, ); decl.add_method( sel!(concludeDragOperation:), - conclude_drag_operation as extern "C" fn(&Object, Sel, id), + conclude_drag_operation as extern "C" fn(_, _, _), ); decl.add_method( sel!(draggingExited:), - dragging_exited as extern "C" fn(&Object, Sel, id), + dragging_exited as extern "C" fn(_, _, _), ); decl.add_method( sel!(window:willUseFullScreenPresentationOptions:), - window_will_use_fullscreen_presentation_options - as extern "C" fn(&Object, Sel, id, NSUInteger) -> NSUInteger, + window_will_use_fullscreen_presentation_options as extern "C" fn(_, _, _, _) -> _, ); decl.add_method( sel!(windowDidEnterFullScreen:), - window_did_enter_fullscreen as extern "C" fn(&Object, Sel, id), + window_did_enter_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowWillEnterFullScreen:), - window_will_enter_fullscreen as extern "C" fn(&Object, Sel, id), + window_will_enter_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidExitFullScreen:), - window_did_exit_fullscreen as extern "C" fn(&Object, Sel, id), + window_did_exit_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowWillExitFullScreen:), - window_will_exit_fullscreen as extern "C" fn(&Object, Sel, id), + window_will_exit_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidFailToEnterFullScreen:), - window_did_fail_to_enter_fullscreen as extern "C" fn(&Object, Sel, id), + window_did_fail_to_enter_fullscreen as extern "C" fn(_, _, _), ); decl.add_method( sel!(windowDidChangeOcclusionState:), - window_did_change_occlusion_state as extern "C" fn(&Object, Sel, id), + window_did_change_occlusion_state as extern "C" fn(_, _, _), ); decl.add_ivar::<*mut c_void>("winitState"); @@ -268,7 +267,7 @@ extern "C" fn window_will_close(this: &Object, _: Sel, _: id) { trace_scope!("windowWillClose:"); with_state(this, |state| unsafe { // `setDelegate:` retains the previous value and then autoreleases it - autoreleasepool(|| { + autoreleasepool(|_| { // Since El Capitan, we need to be careful that delegate methods can't // be called after the window closes. let _: () = msg_send![*state.ns_window, setDelegate: nil];