Clippy fixes macos platform (#2133)

This commit is contained in:
Lucas Kent 2022-01-16 11:14:59 +11:00 committed by GitHub
parent cf4660841a
commit 001fb7ef60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 39 deletions

View file

@ -162,7 +162,7 @@ impl WindowBuilderExtMacOS for WindowBuilder {
#[inline]
fn with_resize_increments(mut self, increments: LogicalSize<f64>) -> WindowBuilder {
self.platform_specific.resize_increments = Some(increments.into());
self.platform_specific.resize_increments = Some(increments);
self
}

View file

@ -60,8 +60,11 @@ pub trait EventHandler: Debug {
fn handle_user_events(&mut self, control_flow: &mut ControlFlow);
}
pub(crate) type Callback<T> =
RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>;
struct EventLoopHandler<T: 'static> {
callback: Weak<RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>>,
callback: Weak<Callback<T>>,
window_target: Rc<RootWindowTarget<T>>,
}
@ -142,7 +145,7 @@ impl Handler {
self.pending_events.lock().unwrap()
}
fn redraw<'a>(&'a self) -> MutexGuard<'a, Vec<WindowId>> {
fn redraw(&self) -> MutexGuard<'_, Vec<WindowId>> {
self.pending_redraw.lock().unwrap()
}
@ -186,11 +189,11 @@ impl Handler {
}
fn take_events(&self) -> VecDeque<EventWrapper> {
mem::replace(&mut *self.events(), Default::default())
mem::take(&mut *self.events())
}
fn should_redraw(&self) -> Vec<WindowId> {
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<T>(
callback: Weak<RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>>,
window_target: Rc<RootWindowTarget<T>>,
) {
pub fn set_callback<T>(callback: Weak<Callback<T>>, window_target: Rc<RootWindowTarget<T>>) {
*HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler {
callback,
window_target,

View file

@ -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<T: 'static> {
/// 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<Rc<RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>>>,
_callback: Option<Rc<Callback<T>>>,
}
impl<T> EventLoop<T> {

View file

@ -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 _,

View file

@ -121,7 +121,7 @@ impl Eq for MonitorHandle {}
impl PartialOrd for MonitorHandle {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(&other))
Some(self.cmp(other))
}
}

View file

@ -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");

View file

@ -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<id> {
}
}
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
}

View file

@ -260,7 +260,7 @@ lazy_static! {
decl.add_ivar::<*mut c_void>("winitState");
decl.add_ivar::<id>("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<VirtualKeyCode> {
#[inline]
fn get_code(ev: id, raw: bool) -> Option<VirtualKeyCode> {
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.

View file

@ -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.

View file

@ -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;