chore(rustfmt): use nightly (#2325)

Stable rustfmt lacks a lot of features resulting in worse formatted
code, thus use nightly formatter.
This commit is contained in:
Kirill Chibisov 2024-04-26 19:11:44 +04:00 committed by GitHub
parent 7006c7ceca
commit 7b0c7b6cb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
154 changed files with 3439 additions and 5891 deletions

View file

@ -448,7 +448,7 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
Some(Fullscreen::Borderless(Some(monitor)))
| Some(Fullscreen::Exclusive(VideoModeHandle { monitor, .. })) => {
monitor.ns_screen(mtm).or_else(|| NSScreen::mainScreen(mtm))
}
},
Some(Fullscreen::Borderless(None)) => NSScreen::mainScreen(mtm),
None => None,
};
@ -462,7 +462,7 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
Some(size) => {
let size = size.to_logical(scale_factor);
NSSize::new(size.width, size.height)
}
},
None => NSSize::new(800.0, 600.0),
};
let position = match attrs.position {
@ -472,12 +472,12 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option<Id<Wini
NSPoint::new(position.x, position.y),
size,
))
}
},
// This value is ignored by calling win.center() below
None => NSPoint::new(0.0, 0.0),
};
NSRect::new(position, size)
}
},
};
let mut masks = if (!attrs.decorations && screen.is_none())
@ -631,30 +631,27 @@ impl WindowDelegate {
let parent_view: Id<NSView> =
unsafe { Id::retain(handle.ns_view.as_ptr().cast()) }.unwrap();
let parent = parent_view.window().ok_or_else(|| {
os_error!(OsError::CreationError(
"parent view should be installed in a window"
))
os_error!(OsError::CreationError("parent view should be installed in a window"))
})?;
// SAFETY: We know that there are no parent -> child -> parent cycles since the only place in `winit`
// where we allow making a window a child window is right here, just after it's been created.
// SAFETY: We know that there are no parent -> child -> parent cycles since the only
// place in `winit` where we allow making a window a child window is
// right here, just after it's been created.
unsafe {
parent.addChildWindow_ordered(&window, NSWindowOrderingMode::NSWindowAbove)
};
}
},
Some(raw) => panic!("invalid raw window handle {raw:?} on macOS"),
None => (),
}
let resize_increments = match attrs
.resize_increments
.map(|i| i.to_logical(window.backingScaleFactor() as _))
{
Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => {
NSSize::new(width, height)
}
_ => NSSize::new(1., 1.),
};
let resize_increments =
match attrs.resize_increments.map(|i| i.to_logical(window.backingScaleFactor() as _)) {
Some(LogicalSize { width, height }) if width >= 1. && height >= 1. => {
NSSize::new(width, height)
},
_ => NSSize::new(1., 1.),
};
let scale_factor = window.backingScaleFactor() as _;
@ -771,10 +768,7 @@ impl WindowDelegate {
};
self.ivars().previous_scale_factor.set(scale_factor);
let content_size = self
.window()
.contentRectForFrameRect(self.window().frame())
.size;
let content_size = self.window().contentRectForFrameRect(self.window().frame()).size;
let content_size = LogicalSize::new(content_size.width, content_size.height);
let app_delegate = ApplicationDelegate::get(MainThreadMarker::from(self));
@ -885,26 +879,20 @@ impl WindowDelegate {
pub fn request_inner_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
let scale_factor = self.scale_factor();
let size = size.to_logical(scale_factor);
self.window()
.setContentSize(NSSize::new(size.width, size.height));
self.window().setContentSize(NSSize::new(size.width, size.height));
None
}
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
let dimensions = dimensions.unwrap_or(Size::Logical(LogicalSize {
width: 0.0,
height: 0.0,
}));
let dimensions =
dimensions.unwrap_or(Size::Logical(LogicalSize { width: 0.0, height: 0.0 }));
let min_size = dimensions.to_logical::<CGFloat>(self.scale_factor());
let min_size = NSSize::new(min_size.width, min_size.height);
unsafe { self.window().setContentMinSize(min_size) };
// If necessary, resize the window to match constraint
let mut current_size = self
.window()
.contentRectForFrameRect(self.window().frame())
.size;
let mut current_size = self.window().contentRectForFrameRect(self.window().frame()).size;
if current_size.width < min_size.width {
current_size.width = min_size.width;
}
@ -926,10 +914,7 @@ impl WindowDelegate {
unsafe { self.window().setContentMaxSize(max_size) };
// If necessary, resize the window to match constraint
let mut current_size = self
.window()
.contentRectForFrameRect(self.window().frame())
.size;
let mut current_size = self.window().contentRectForFrameRect(self.window().frame()).size;
if max_size.width < current_size.width {
current_size.width = max_size.width;
}
@ -1013,9 +998,7 @@ impl WindowDelegate {
// We edit the button directly instead of using `NSResizableWindowMask`,
// since that mask also affect the resizability of the window (which is
// controllable by other means in `winit`).
if let Some(button) = self
.window()
.standardWindowButton(NSWindowButton::NSWindowZoomButton)
if let Some(button) = self.window().standardWindowButton(NSWindowButton::NSWindowZoomButton)
{
button.setEnabled(buttons.contains(WindowButtons::MAXIMIZE));
}
@ -1064,7 +1047,7 @@ impl WindowDelegate {
CursorGrabMode::None => true,
CursorGrabMode::Confined => {
return Err(ExternalError::NotSupported(NotSupportedError::new()))
}
},
};
// TODO: Do this for real https://stackoverflow.com/a/40922095/5435443
@ -1107,9 +1090,7 @@ impl WindowDelegate {
#[inline]
pub fn drag_window(&self) -> Result<(), ExternalError> {
let mtm = MainThreadMarker::from(self);
let event = NSApplication::sharedApplication(mtm)
.currentEvent()
.unwrap();
let event = NSApplication::sharedApplication(mtm).currentEvent().unwrap();
self.window().performWindowDragWithEvent(&event);
Ok(())
}
@ -1151,12 +1132,8 @@ impl WindowDelegate {
}
fn saved_style(&self) -> NSWindowStyleMask {
let base_mask = self
.ivars()
.saved_style
.take()
.unwrap_or_else(|| self.window().styleMask())
.0;
let base_mask =
self.ivars().saved_style.take().unwrap_or_else(|| self.window().styleMask()).0;
NSWindowStyleMask(if self.ivars().resizable.get() {
base_mask | NSWindowStyleMask::Resizable.0
} else {
@ -1225,10 +1202,7 @@ impl WindowDelegate {
let screen = NSScreen::mainScreen(mtm).expect("no screen found");
screen.visibleFrame()
} else {
self.ivars()
.standard_frame
.get()
.unwrap_or(DEFAULT_STANDARD_FRAME)
self.ivars().standard_frame.get().unwrap_or(DEFAULT_STANDARD_FRAME)
};
self.window().setFrame_display(new_rect, false);
}
@ -1275,7 +1249,7 @@ impl WindowDelegate {
} else {
return;
}
}
},
Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
}
.ns_screen(mtm)
@ -1305,9 +1279,7 @@ impl WindowDelegate {
let mut fade_token = ffi::kCGDisplayFadeReservationInvalidToken;
if matches!(old_fullscreen, Some(Fullscreen::Borderless(_))) {
self.ivars()
.save_presentation_opts
.replace(Some(app.presentationOptions()));
self.ivars().save_presentation_opts.replace(Some(app.presentationOptions()));
}
unsafe {
@ -1380,11 +1352,11 @@ impl WindowDelegate {
self.ivars().saved_style.set(Some(curr_mask));
}
toggle_fullscreen(self.window());
}
},
(Some(Fullscreen::Borderless(_)), None) => {
// State is restored by `window_did_exit_fullscreen`
toggle_fullscreen(self.window());
}
},
(Some(Fullscreen::Exclusive(ref video_mode)), None) => {
unsafe {
ffi::CGRestorePermanentDisplayConfiguration();
@ -1394,7 +1366,7 @@ impl WindowDelegate {
);
};
toggle_fullscreen(self.window());
}
},
(Some(Fullscreen::Borderless(_)), Some(Fullscreen::Exclusive(_))) => {
// If we're already in fullscreen mode, calling
// `CGDisplayCapture` will place the shielding window on top of
@ -1404,9 +1376,7 @@ impl WindowDelegate {
// of the menu bar, and this looks broken, so we must make sure
// that the menu bar is disabled. This is done in the window
// delegate in `window:willUseFullScreenPresentationOptions:`.
self.ivars()
.save_presentation_opts
.set(Some(app.presentationOptions()));
self.ivars().save_presentation_opts.set(Some(app.presentationOptions()));
let presentation_options = NSApplicationPresentationOptions(
NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0
@ -1417,7 +1387,7 @@ impl WindowDelegate {
let window_level = unsafe { ffi::CGShieldingWindowLevel() } as NSWindowLevel + 1;
self.window().setLevel(window_level);
}
},
(Some(Fullscreen::Exclusive(ref video_mode)), Some(Fullscreen::Borderless(_))) => {
let presentation_options = self.ivars().save_presentation_opts.get().unwrap_or(
NSApplicationPresentationOptions(NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0
@ -1436,10 +1406,9 @@ impl WindowDelegate {
// Restore the normal window level following the Borderless fullscreen
// `CGShieldingWindowLevel() + 1` hack.
self.window()
.setLevel(ffi::kCGNormalWindowLevel as NSWindowLevel);
}
_ => {}
self.window().setLevel(ffi::kCGNormalWindowLevel as NSWindowLevel);
},
_ => {},
};
}
@ -1628,9 +1597,7 @@ impl WindowDelegate {
pub fn set_theme(&self, theme: Option<Theme>) {
let mtm = MainThreadMarker::from(self);
set_ns_theme(theme, mtm);
self.ivars()
.current_theme
.set(theme.or_else(|| Some(get_ns_theme(mtm))));
self.ivars().current_theme.set(theme.or_else(|| Some(get_ns_theme(mtm))));
}
#[inline]
@ -1676,15 +1643,11 @@ impl WindowExtMacOS for WindowDelegate {
if fullscreen {
// Remember the original window's settings
// Exclude title bar
self.ivars().standard_frame.set(Some(
self.window().contentRectForFrameRect(self.window().frame()),
));
self.ivars()
.saved_style
.set(Some(self.window().styleMask()));
self.ivars()
.save_presentation_opts
.set(Some(app.presentationOptions()));
.standard_frame
.set(Some(self.window().contentRectForFrameRect(self.window().frame())));
self.ivars().saved_style.set(Some(self.window().styleMask()));
self.ivars().save_presentation_opts.set(Some(app.presentationOptions()));
// Tell our window's state that we're in fullscreen
self.ivars().is_simple_fullscreen.set(true);
@ -1700,10 +1663,7 @@ impl WindowExtMacOS for WindowDelegate {
self.toggle_style_mask(NSWindowStyleMask::Titled, false);
// Set the window frame to the screen frame size
let screen = self
.window()
.screen()
.expect("expected screen to be available");
let screen = self.window().screen().expect("expected screen to be available");
self.window().setFrame_display(screen.frame(), true);
// Fullscreen windows can't be resized, minimized, or moved
@ -1718,11 +1678,7 @@ impl WindowExtMacOS for WindowDelegate {
self.ivars().is_simple_fullscreen.set(false);
let save_presentation_opts = self.ivars().save_presentation_opts.get();
let frame = self
.ivars()
.standard_frame
.get()
.unwrap_or(DEFAULT_STANDARD_FRAME);
let frame = self.ivars().standard_frame.get().unwrap_or(DEFAULT_STANDARD_FRAME);
if let Some(presentation_opts) = save_presentation_opts {
app.setPresentationOptions(presentation_opts);
@ -1747,8 +1703,7 @@ impl WindowExtMacOS for WindowDelegate {
#[inline]
fn set_tabbing_identifier(&self, identifier: &str) {
self.window()
.setTabbingIdentifier(&NSString::from_str(identifier))
self.window().setTabbingIdentifier(&NSString::from_str(identifier))
}
#[inline]
@ -1779,9 +1734,7 @@ impl WindowExtMacOS for WindowDelegate {
#[inline]
fn num_tabs(&self) -> usize {
unsafe { self.window().tabbedWindows() }
.map(|windows| windows.len())
.unwrap_or(1)
unsafe { self.window().tabbedWindows() }.map(|windows| windows.len()).unwrap_or(1)
}
fn is_document_edited(&self) -> bool {