mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Clippy fixes macos platform (#2133)
This commit is contained in:
parent
cf4660841a
commit
001fb7ef60
|
@ -162,7 +162,7 @@ impl WindowBuilderExtMacOS for WindowBuilder {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_resize_increments(mut self, increments: LogicalSize<f64>) -> WindowBuilder {
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,11 @@ pub trait EventHandler: Debug {
|
||||||
fn handle_user_events(&mut self, control_flow: &mut ControlFlow);
|
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> {
|
struct EventLoopHandler<T: 'static> {
|
||||||
callback: Weak<RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>>,
|
callback: Weak<Callback<T>>,
|
||||||
window_target: Rc<RootWindowTarget<T>>,
|
window_target: Rc<RootWindowTarget<T>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +145,7 @@ impl Handler {
|
||||||
self.pending_events.lock().unwrap()
|
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()
|
self.pending_redraw.lock().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,11 +189,11 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_events(&self) -> VecDeque<EventWrapper> {
|
fn take_events(&self) -> VecDeque<EventWrapper> {
|
||||||
mem::replace(&mut *self.events(), Default::default())
|
mem::take(&mut *self.events())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_redraw(&self) -> Vec<WindowId> {
|
fn should_redraw(&self) -> Vec<WindowId> {
|
||||||
mem::replace(&mut *self.redraw(), Default::default())
|
mem::take(&mut *self.redraw())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_in_callback(&self) -> bool {
|
fn get_in_callback(&self) -> bool {
|
||||||
|
@ -264,10 +267,7 @@ pub static INTERRUPT_EVENT_LOOP_EXIT: AtomicBool = AtomicBool::new(false);
|
||||||
pub enum AppState {}
|
pub enum AppState {}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn set_callback<T>(
|
pub fn set_callback<T>(callback: Weak<Callback<T>>, window_target: Rc<RootWindowTarget<T>>) {
|
||||||
callback: Weak<RefCell<dyn FnMut(Event<'_, T>, &RootWindowTarget<T>, &mut ControlFlow)>>,
|
|
||||||
window_target: Rc<RootWindowTarget<T>>,
|
|
||||||
) {
|
|
||||||
*HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler {
|
*HANDLER.callback.lock().unwrap() = Some(Box::new(EventLoopHandler {
|
||||||
callback,
|
callback,
|
||||||
window_target,
|
window_target,
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
||||||
platform_impl::platform::{
|
platform_impl::platform::{
|
||||||
app::APP_CLASS,
|
app::APP_CLASS,
|
||||||
app_delegate::APP_DELEGATE_CLASS,
|
app_delegate::APP_DELEGATE_CLASS,
|
||||||
app_state::AppState,
|
app_state::{AppState, Callback},
|
||||||
monitor::{self, MonitorHandle},
|
monitor::{self, MonitorHandle},
|
||||||
observer::*,
|
observer::*,
|
||||||
util::IdRef,
|
util::IdRef,
|
||||||
|
@ -111,7 +111,7 @@ pub struct EventLoop<T: 'static> {
|
||||||
/// Every other reference should be a Weak reference which is only upgraded
|
/// 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
|
/// into a strong reference in order to call the callback but then the
|
||||||
/// strong reference should be dropped as soon as possible.
|
/// 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> {
|
impl<T> EventLoop<T> {
|
||||||
|
|
|
@ -15,7 +15,6 @@ use core_graphics::{
|
||||||
base::CGError,
|
base::CGError,
|
||||||
display::{CGDirectDisplayID, CGDisplayConfigRef},
|
display::{CGDirectDisplayID, CGDisplayConfigRef},
|
||||||
};
|
};
|
||||||
use objc;
|
|
||||||
|
|
||||||
pub const NSNotFound: NSInteger = NSInteger::max_value();
|
pub const NSNotFound: NSInteger = NSInteger::max_value();
|
||||||
|
|
||||||
|
@ -108,6 +107,7 @@ pub const kCGNumberOfWindowLevelKeys: NSInteger = 20;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(isize)]
|
#[repr(isize)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
pub enum NSWindowLevel {
|
pub enum NSWindowLevel {
|
||||||
NSNormalWindowLevel = kCGBaseWindowLevelKey as _,
|
NSNormalWindowLevel = kCGBaseWindowLevelKey as _,
|
||||||
NSFloatingWindowLevel = kCGFloatingWindowLevelKey as _,
|
NSFloatingWindowLevel = kCGFloatingWindowLevelKey as _,
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl Eq for MonitorHandle {}
|
||||||
|
|
||||||
impl PartialOrd for MonitorHandle {
|
impl PartialOrd for MonitorHandle {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||||
Some(self.cmp(&other))
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ impl Cursor {
|
||||||
// Note that loading `busybutclickable` with this code won't animate the frames;
|
// Note that loading `busybutclickable` with this code won't animate the frames;
|
||||||
// instead you'll just get them all in a column.
|
// instead you'll just get them all in a column.
|
||||||
pub unsafe fn load_webkit_cursor(cursor_name: &str) -> id {
|
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_root = NSString::alloc(nil).init_str(CURSOR_ROOT);
|
||||||
let cursor_name = NSString::alloc(nil).init_str(cursor_name);
|
let cursor_name = NSString::alloc(nil).init_str(cursor_name);
|
||||||
let cursor_pdf = NSString::alloc(nil).init_str("cursor.pdf");
|
let cursor_pdf = NSString::alloc(nil).init_str("cursor.pdf");
|
||||||
|
|
|
@ -68,7 +68,7 @@ impl Drop for IdRef {
|
||||||
|
|
||||||
impl Deref for IdRef {
|
impl Deref for IdRef {
|
||||||
type Target = id;
|
type Target = id;
|
||||||
fn deref<'a>(&'a self) -> &'a id {
|
fn deref(&self) -> &id {
|
||||||
&self.0
|
&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];
|
let superclass: *const Class = msg_send![this, superclass];
|
||||||
&*superclass
|
&*superclass
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ lazy_static! {
|
||||||
decl.add_ivar::<*mut c_void>("winitState");
|
decl.add_ivar::<*mut c_void>("winitState");
|
||||||
decl.add_ivar::<id>("markedText");
|
decl.add_ivar::<id>("markedText");
|
||||||
let protocol = Protocol::get("NSTextInputClient").unwrap();
|
let protocol = Protocol::get("NSTextInputClient").unwrap();
|
||||||
decl.add_protocol(&protocol);
|
decl.add_protocol(protocol);
|
||||||
ViewClass(decl.register())
|
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
|
// As defined in: https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT
|
||||||
fn is_corporate_character(c: char) -> bool {
|
fn is_corporate_character(c: char) -> bool {
|
||||||
match c {
|
matches!(c,
|
||||||
'\u{F700}'..='\u{F747}'
|
'\u{F700}'..='\u{F747}'
|
||||||
| '\u{F802}'..='\u{F84F}'
|
| '\u{F802}'..='\u{F84F}'
|
||||||
| '\u{F850}'
|
| '\u{F850}'
|
||||||
|
@ -597,9 +597,8 @@ fn is_corporate_character(c: char) -> bool {
|
||||||
| '\u{F85D}'
|
| '\u{F85D}'
|
||||||
| '\u{F85F}'
|
| '\u{F85F}'
|
||||||
| '\u{F860}'..='\u{F86B}'
|
| '\u{F860}'..='\u{F86B}'
|
||||||
| '\u{F870}'..='\u{F8FF}' => true,
|
| '\u{F870}'..='\u{F8FF}'
|
||||||
_ => false,
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves a layout-independent keycode given an event.
|
// Retrieves a layout-independent keycode given an event.
|
||||||
|
@ -607,7 +606,7 @@ fn retrieve_keycode(event: id) -> Option<VirtualKeyCode> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_code(ev: id, raw: bool) -> Option<VirtualKeyCode> {
|
fn get_code(ev: id, raw: bool) -> Option<VirtualKeyCode> {
|
||||||
let characters = get_characters(ev, raw);
|
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.
|
// Cmd switches Roman letters for Dvorak-QWERTY layout, so we try modified characters first.
|
||||||
|
|
|
@ -127,7 +127,7 @@ fn create_window(
|
||||||
video_mode: VideoMode { ref monitor, .. },
|
video_mode: VideoMode { ref monitor, .. },
|
||||||
})) => {
|
})) => {
|
||||||
let monitor_screen = monitor.ns_screen();
|
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)),
|
Some(Fullscreen::Borderless(None)) => Some(appkit::NSScreen::mainScreen(nil)),
|
||||||
None => None,
|
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
|
// Resizable UnownedWindow without a titlebar or borders
|
||||||
// if decorations is set to false, ignore pl_attrs
|
// 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
|
// if the titlebar is hidden, ignore other pl_attrs
|
||||||
NSWindowStyleMask::NSBorderlessWindowMask
|
NSWindowStyleMask::NSBorderlessWindowMask
|
||||||
| NSWindowStyleMask::NSResizableWindowMask
|
| NSWindowStyleMask::NSResizableWindowMask
|
||||||
|
@ -192,7 +189,8 @@ fn create_window(
|
||||||
appkit::NSBackingStoreBuffered,
|
appkit::NSBackingStoreBuffered,
|
||||||
NO,
|
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);
|
let title = util::ns_string_id_ref(&attrs.title);
|
||||||
ns_window.setReleasedWhenClosed_(NO);
|
ns_window.setReleasedWhenClosed_(NO);
|
||||||
ns_window.setTitle_(*title);
|
ns_window.setTitle_(*title);
|
||||||
|
@ -241,8 +239,7 @@ fn create_window(
|
||||||
ns_window.center();
|
ns_window.center();
|
||||||
}
|
}
|
||||||
ns_window
|
ns_window
|
||||||
});
|
})
|
||||||
res
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,14 +359,14 @@ impl UnownedWindow {
|
||||||
ns_window.setBackgroundColor_(NSColor::clearColor(nil));
|
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);
|
let logical_dim = dim.to_logical(scale_factor);
|
||||||
set_min_inner_size(*ns_window, logical_dim)
|
set_min_inner_size(*ns_window, logical_dim);
|
||||||
});
|
}
|
||||||
win_attribs.max_inner_size.map(|dim| {
|
if let Some(dim) = win_attribs.max_inner_size {
|
||||||
let logical_dim = dim.to_logical(scale_factor);
|
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;
|
use cocoa::foundation::NSArray;
|
||||||
// register for drag and drop operations.
|
// register for drag and drop operations.
|
||||||
|
|
|
@ -55,7 +55,7 @@ impl WindowDelegateState {
|
||||||
let mut delegate_state = WindowDelegateState {
|
let mut delegate_state = WindowDelegateState {
|
||||||
ns_window: window.ns_window.clone(),
|
ns_window: window.ns_window.clone(),
|
||||||
ns_view: window.ns_view.clone(),
|
ns_view: window.ns_view.clone(),
|
||||||
window: Arc::downgrade(&window),
|
window: Arc::downgrade(window),
|
||||||
initial_fullscreen,
|
initial_fullscreen,
|
||||||
previous_position: None,
|
previous_position: None,
|
||||||
previous_scale_factor: scale_factor,
|
previous_scale_factor: scale_factor,
|
||||||
|
@ -86,7 +86,7 @@ impl WindowDelegateState {
|
||||||
pub fn emit_static_scale_factor_changed_event(&mut self) {
|
pub fn emit_static_scale_factor_changed_event(&mut self) {
|
||||||
let scale_factor = self.get_scale_factor();
|
let scale_factor = self.get_scale_factor();
|
||||||
if scale_factor == self.previous_scale_factor {
|
if scale_factor == self.previous_scale_factor {
|
||||||
return ();
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.previous_scale_factor = scale_factor;
|
self.previous_scale_factor = scale_factor;
|
||||||
|
|
Loading…
Reference in a new issue