diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 55a13a0f..6a8c2948 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -162,7 +162,7 @@ impl WindowBuilderExtMacOS for WindowBuilder { #[inline] fn with_resize_increments(mut self, increments: LogicalSize) -> WindowBuilder { - self.platform_specific.resize_increments = Some(increments.into()); + self.platform_specific.resize_increments = Some(increments); self } diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index d421f1a2..d1d9524c 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -60,8 +60,11 @@ pub trait EventHandler: Debug { fn handle_user_events(&mut self, control_flow: &mut ControlFlow); } +pub(crate) type Callback = + RefCell, &RootWindowTarget, &mut ControlFlow)>; + struct EventLoopHandler { - callback: Weak, &RootWindowTarget, &mut ControlFlow)>>, + callback: Weak>, window_target: Rc>, } @@ -142,7 +145,7 @@ impl Handler { self.pending_events.lock().unwrap() } - fn redraw<'a>(&'a self) -> MutexGuard<'a, Vec> { + fn redraw(&self) -> MutexGuard<'_, Vec> { self.pending_redraw.lock().unwrap() } @@ -186,11 +189,11 @@ impl Handler { } fn take_events(&self) -> VecDeque { - mem::replace(&mut *self.events(), Default::default()) + mem::take(&mut *self.events()) } fn should_redraw(&self) -> Vec { - mem::replace(&mut *self.redraw(), Default::default()) + mem::take(&mut *self.redraw()) } fn get_in_callback(&self) -> bool { @@ -264,10 +267,7 @@ pub static INTERRUPT_EVENT_LOOP_EXIT: AtomicBool = AtomicBool::new(false); pub enum AppState {} impl AppState { - pub fn set_callback( - callback: Weak, &RootWindowTarget, &mut ControlFlow)>>, - window_target: Rc>, - ) { + pub fn set_callback(callback: Weak>, window_target: Rc>) { *HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler { callback, window_target, diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 4b3d641a..54181d36 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -25,7 +25,7 @@ use crate::{ platform_impl::platform::{ app::APP_CLASS, app_delegate::APP_DELEGATE_CLASS, - app_state::AppState, + app_state::{AppState, Callback}, monitor::{self, MonitorHandle}, observer::*, util::IdRef, @@ -111,7 +111,7 @@ pub struct EventLoop { /// Every other reference should be a Weak reference which is only upgraded /// into a strong reference in order to call the callback but then the /// strong reference should be dropped as soon as possible. - _callback: Option, &RootWindowTarget, &mut ControlFlow)>>>, + _callback: Option>>, } impl EventLoop { diff --git a/src/platform_impl/macos/ffi.rs b/src/platform_impl/macos/ffi.rs index c887cd53..8296bef2 100644 --- a/src/platform_impl/macos/ffi.rs +++ b/src/platform_impl/macos/ffi.rs @@ -15,7 +15,6 @@ use core_graphics::{ base::CGError, display::{CGDirectDisplayID, CGDisplayConfigRef}, }; -use objc; pub const NSNotFound: NSInteger = NSInteger::max_value(); @@ -108,6 +107,7 @@ pub const kCGNumberOfWindowLevelKeys: NSInteger = 20; #[derive(Debug, Clone, Copy)] #[repr(isize)] +#[allow(clippy::enum_variant_names)] pub enum NSWindowLevel { NSNormalWindowLevel = kCGBaseWindowLevelKey as _, NSFloatingWindowLevel = kCGFloatingWindowLevelKey as _, diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index cf16f97d..08dba6c9 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -121,7 +121,7 @@ impl Eq for MonitorHandle {} impl PartialOrd for MonitorHandle { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(&other)) + Some(self.cmp(other)) } } diff --git a/src/platform_impl/macos/util/cursor.rs b/src/platform_impl/macos/util/cursor.rs index 5c4d1537..48921ad2 100644 --- a/src/platform_impl/macos/util/cursor.rs +++ b/src/platform_impl/macos/util/cursor.rs @@ -104,7 +104,7 @@ impl Cursor { // Note that loading `busybutclickable` with this code won't animate the frames; // instead you'll just get them all in a column. pub unsafe fn load_webkit_cursor(cursor_name: &str) -> id { - static CURSOR_ROOT: &'static str = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors"; + static CURSOR_ROOT: &str = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors"; let cursor_root = NSString::alloc(nil).init_str(CURSOR_ROOT); let cursor_name = NSString::alloc(nil).init_str(cursor_name); let cursor_pdf = NSString::alloc(nil).init_str("cursor.pdf"); diff --git a/src/platform_impl/macos/util/mod.rs b/src/platform_impl/macos/util/mod.rs index 6f50cbfa..b64155d9 100644 --- a/src/platform_impl/macos/util/mod.rs +++ b/src/platform_impl/macos/util/mod.rs @@ -68,7 +68,7 @@ impl Drop for IdRef { impl Deref for IdRef { type Target = id; - fn deref<'a>(&'a self) -> &'a id { + fn deref(&self) -> &id { &self.0 } } @@ -113,7 +113,7 @@ pub unsafe fn app_name() -> Option { } } -pub unsafe fn superclass<'a>(this: &'a Object) -> &'a Class { +pub unsafe fn superclass(this: &Object) -> &Class { let superclass: *const Class = msg_send![this, superclass]; &*superclass } diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 55271f79..20f18b64 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -260,7 +260,7 @@ lazy_static! { decl.add_ivar::<*mut c_void>("winitState"); decl.add_ivar::("markedText"); let protocol = Protocol::get("NSTextInputClient").unwrap(); - decl.add_protocol(&protocol); + decl.add_protocol(protocol); ViewClass(decl.register()) }; } @@ -589,7 +589,7 @@ fn get_characters(event: id, ignore_modifiers: bool) -> String { // As defined in: https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT fn is_corporate_character(c: char) -> bool { - match c { + matches!(c, '\u{F700}'..='\u{F747}' | '\u{F802}'..='\u{F84F}' | '\u{F850}' @@ -597,9 +597,8 @@ fn is_corporate_character(c: char) -> bool { | '\u{F85D}' | '\u{F85F}' | '\u{F860}'..='\u{F86B}' - | '\u{F870}'..='\u{F8FF}' => true, - _ => false, - } + | '\u{F870}'..='\u{F8FF}' + ) } // Retrieves a layout-independent keycode given an event. @@ -607,7 +606,7 @@ fn retrieve_keycode(event: id) -> Option { #[inline] fn get_code(ev: id, raw: bool) -> Option { let characters = get_characters(ev, raw); - characters.chars().next().and_then(|c| char_to_keycode(c)) + characters.chars().next().and_then(char_to_keycode) } // Cmd switches Roman letters for Dvorak-QWERTY layout, so we try modified characters first. diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index f123b093..57578535 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -127,7 +127,7 @@ fn create_window( video_mode: VideoMode { ref monitor, .. }, })) => { let monitor_screen = monitor.ns_screen(); - Some(monitor_screen.unwrap_or(appkit::NSScreen::mainScreen(nil))) + Some(monitor_screen.unwrap_or_else(|| appkit::NSScreen::mainScreen(nil))) } Some(Fullscreen::Borderless(None)) => Some(appkit::NSScreen::mainScreen(nil)), None => None, @@ -158,13 +158,10 @@ fn create_window( } }; - let mut masks = if !attrs.decorations && !screen.is_some() { + let mut masks = if (!attrs.decorations && screen.is_none()) || pl_attrs.titlebar_hidden { // Resizable UnownedWindow without a titlebar or borders // if decorations is set to false, ignore pl_attrs - NSWindowStyleMask::NSBorderlessWindowMask - | NSWindowStyleMask::NSResizableWindowMask - | NSWindowStyleMask::NSMiniaturizableWindowMask - } else if pl_attrs.titlebar_hidden { + // // if the titlebar is hidden, ignore other pl_attrs NSWindowStyleMask::NSBorderlessWindowMask | NSWindowStyleMask::NSResizableWindowMask @@ -192,7 +189,8 @@ fn create_window( appkit::NSBackingStoreBuffered, NO, )); - let res = ns_window.non_nil().map(|ns_window| { + + ns_window.non_nil().map(|ns_window| { let title = util::ns_string_id_ref(&attrs.title); ns_window.setReleasedWhenClosed_(NO); ns_window.setTitle_(*title); @@ -241,8 +239,7 @@ fn create_window( ns_window.center(); } ns_window - }); - res + }) }) } @@ -362,14 +359,14 @@ impl UnownedWindow { ns_window.setBackgroundColor_(NSColor::clearColor(nil)); } - win_attribs.min_inner_size.map(|dim| { + if let Some(dim) = win_attribs.min_inner_size { let logical_dim = dim.to_logical(scale_factor); - set_min_inner_size(*ns_window, logical_dim) - }); - win_attribs.max_inner_size.map(|dim| { + set_min_inner_size(*ns_window, logical_dim); + } + if let Some(dim) = win_attribs.max_inner_size { let logical_dim = dim.to_logical(scale_factor); - set_max_inner_size(*ns_window, logical_dim) - }); + set_max_inner_size(*ns_window, logical_dim); + } use cocoa::foundation::NSArray; // register for drag and drop operations. diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 2c0d962b..fc9be0fc 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -55,7 +55,7 @@ impl WindowDelegateState { let mut delegate_state = WindowDelegateState { ns_window: window.ns_window.clone(), ns_view: window.ns_view.clone(), - window: Arc::downgrade(&window), + window: Arc::downgrade(window), initial_fullscreen, previous_position: None, previous_scale_factor: scale_factor, @@ -86,7 +86,7 @@ impl WindowDelegateState { pub fn emit_static_scale_factor_changed_event(&mut self) { let scale_factor = self.get_scale_factor(); if scale_factor == self.previous_scale_factor { - return (); + return; }; self.previous_scale_factor = scale_factor;