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
154 changed files with 3439 additions and 5891 deletions

View File

@@ -5,13 +5,11 @@ use std::sync::{Arc, Mutex};
use sctk::reexports::client::protocol::wl_display::WlDisplay;
use sctk::reexports::client::protocol::wl_surface::WlSurface;
use sctk::reexports::client::Proxy;
use sctk::reexports::client::QueueHandle;
use sctk::reexports::client::{Proxy, QueueHandle};
use sctk::compositor::{CompositorState, Region, SurfaceData};
use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1;
use sctk::shell::xdg::window::Window as SctkWindow;
use sctk::shell::xdg::window::WindowDecorations;
use sctk::shell::xdg::window::{Window as SctkWindow, WindowDecorations};
use sctk::shell::WaylandSurface;
use tracing::warn;
@@ -90,15 +88,11 @@ impl Window {
let surface = state.compositor_state.create_surface(&queue_handle);
let compositor = state.compositor_state.clone();
let xdg_activation = state
.xdg_activation
.as_ref()
.map(|activation_state| activation_state.global().clone());
let xdg_activation =
state.xdg_activation.as_ref().map(|activation_state| activation_state.global().clone());
let display = event_loop_window_target.connection.display();
let size: Size = attributes
.inner_size
.unwrap_or(LogicalSize::new(800., 600.).into());
let size: Size = attributes.inner_size.unwrap_or(LogicalSize::new(800., 600.).into());
// We prefer server side decorations, however to not have decorations we ask for client
// side decorations instead.
@@ -109,9 +103,7 @@ impl Window {
};
let window =
state
.xdg_shell
.create_window(surface.clone(), default_decorations, &queue_handle);
state.xdg_shell.create_window(surface.clone(), default_decorations, &queue_handle);
let mut window_state = WindowState::new(
event_loop_window_target.connection.clone(),
@@ -152,7 +144,7 @@ impl Window {
match attributes.fullscreen.map(Into::into) {
Some(Fullscreen::Exclusive(_)) => {
warn!("`Fullscreen::Exclusive` is ignored on Wayland");
}
},
#[cfg_attr(not(x11_platform), allow(clippy::bind_instead_of_map))]
Some(Fullscreen::Borderless(monitor)) => {
let output = monitor.and_then(|monitor| match monitor {
@@ -162,7 +154,7 @@ impl Window {
});
window.set_fullscreen(output.as_ref())
}
},
_ if attributes.maximized => window.set_maximized(),
_ => (),
};
@@ -173,10 +165,9 @@ impl Window {
}
// Activate the window when the token is passed.
if let (Some(xdg_activation), Some(token)) = (
xdg_activation.as_ref(),
attributes.platform_specific.activation_token,
) {
if let (Some(xdg_activation), Some(token)) =
(xdg_activation.as_ref(), attributes.platform_specific.activation_token)
{
xdg_activation.activate(token._token, &surface);
}
@@ -186,20 +177,14 @@ impl Window {
// Add the window and window requests into the state.
let window_state = Arc::new(Mutex::new(window_state));
let window_id = super::make_wid(&surface);
state
.windows
.get_mut()
.insert(window_id, window_state.clone());
state.windows.get_mut().insert(window_id, window_state.clone());
let window_requests = WindowRequests {
redraw_requested: AtomicBool::new(true),
closed: AtomicBool::new(false),
};
let window_requests = Arc::new(window_requests);
state
.window_requests
.get_mut()
.insert(window_id, window_requests.clone());
state.window_requests.get_mut().insert(window_id, window_requests.clone());
// Setup the event sync to insert `WindowEvents` right from the window.
let window_events_sink = state.window_events_sink.clone();
@@ -209,17 +194,13 @@ impl Window {
// Do a roundtrip.
event_queue.roundtrip(&mut state).map_err(|error| {
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(
error
))))
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(error))))
})?;
// XXX Wait for the initial configure to arrive.
while !window_state.lock().unwrap().is_configured() {
event_queue.blocking_dispatch(&mut state).map_err(|error| {
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(
error
))))
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(error))))
})?;
}
@@ -329,10 +310,7 @@ impl Window {
pub fn set_min_inner_size(&self, min_size: Option<Size>) {
let scale_factor = self.scale_factor();
let min_size = min_size.map(|size| size.to_logical(scale_factor));
self.window_state
.lock()
.unwrap()
.set_min_inner_size(min_size);
self.window_state.lock().unwrap().set_min_inner_size(min_size);
// NOTE: Requires commit to be applied.
self.request_redraw();
}
@@ -342,10 +320,7 @@ impl Window {
pub fn set_max_inner_size(&self, max_size: Option<Size>) {
let scale_factor = self.scale_factor();
let max_size = max_size.map(|size| size.to_logical(scale_factor));
self.window_state
.lock()
.unwrap()
.set_max_inner_size(max_size);
self.window_state.lock().unwrap().set_max_inner_size(max_size);
// NOTE: Requires commit to be applied.
self.request_redraw();
}
@@ -362,10 +337,7 @@ impl Window {
#[inline]
pub fn set_transparent(&self, transparent: bool) {
self.window_state
.lock()
.unwrap()
.set_transparent(transparent);
self.window_state.lock().unwrap().set_transparent(transparent);
}
#[inline]
@@ -388,10 +360,7 @@ impl Window {
#[inline]
pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> {
self.window_state
.lock()
.unwrap()
.drag_resize_window(direction)
self.window_state.lock().unwrap().drag_resize_window(direction)
}
#[inline]
@@ -499,7 +468,7 @@ impl Window {
match fullscreen {
Some(Fullscreen::Exclusive(_)) => {
warn!("`Fullscreen::Exclusive` is ignored on Wayland");
}
},
#[cfg_attr(not(x11_platform), allow(clippy::bind_instead_of_map))]
Some(Fullscreen::Borderless(monitor)) => {
let output = monitor.and_then(|monitor| match monitor {
@@ -509,7 +478,7 @@ impl Window {
});
self.window.set_fullscreen(output.as_ref())
}
},
None => self.window.unset_fullscreen(),
}
}
@@ -526,10 +495,7 @@ impl Window {
#[inline]
pub fn set_cursor_visible(&self, visible: bool) {
self.window_state
.lock()
.unwrap()
.set_cursor_visible(visible);
self.window_state.lock().unwrap().set_cursor_visible(visible);
}
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
@@ -538,7 +504,7 @@ impl Window {
None => {
warn!("`request_user_attention` isn't supported");
return;
}
},
};
// Urgency is only removed by the compositor and there's no need to raise urgency when it
@@ -630,10 +596,7 @@ impl Window {
if window_state.ime_allowed() != allowed && window_state.set_ime_allowed(allowed) {
let event = WindowEvent::Ime(if allowed { Ime::Enabled } else { Ime::Disabled });
self.window_events_sink
.lock()
.unwrap()
.push_window_event(event, self.window_id);
self.window_events_sink.lock().unwrap().push_window_event(event, self.window_id);
self.event_loop_awakener.ping();
}
}

View File

@@ -226,13 +226,10 @@ impl WindowState {
&self,
callback: F,
) {
self.pointers
.iter()
.filter_map(Weak::upgrade)
.for_each(|pointer| {
let data = pointer.pointer().winit_data();
callback(pointer.as_ref(), data);
})
self.pointers.iter().filter_map(Weak::upgrade).for_each(|pointer| {
let data = pointer.pointer().winit_data();
callback(pointer.as_ref(), data);
})
}
/// Get the current state of the frame callback.
@@ -257,7 +254,7 @@ impl WindowState {
FrameCallbackState::None | FrameCallbackState::Received => {
self.frame_callback_state = FrameCallbackState::Requested;
surface.frame(&self.queue_handle, surface.clone());
}
},
FrameCallbackState::Requested => (),
}
}
@@ -297,11 +294,11 @@ impl WindowState {
// Hide the frame if we were asked to not decorate.
frame.set_hidden(!self.decorate);
self.frame = Some(frame);
}
},
Err(err) => {
warn!("Failed to create client side decorations frame: {err}");
self.csd_fails = true;
}
},
}
} else if configure.decoration_mode == DecorationMode::Server {
// Drop the frame for server side decorations to save resources.
@@ -320,8 +317,8 @@ impl WindowState {
let width = width.map(|w| w.get()).unwrap_or(1);
let height = height.map(|h| h.get()).unwrap_or(1);
((width, height).into(), false)
}
(_, _) if stateless => (self.stateless_size, true),
},
(..) if stateless => (self.stateless_size, true),
_ => (self.size, true),
}
} else {
@@ -335,10 +332,8 @@ impl WindowState {
// Apply configure bounds only when compositor let the user decide what size to pick.
if constrain {
let bounds = self.inner_size_bounds(&configure);
new_size.width = bounds
.0
.map(|bound_w| new_size.width.min(bound_w.get()))
.unwrap_or(new_size.width);
new_size.width =
bounds.0.map(|bound_w| new_size.width.min(bound_w.get())).unwrap_or(new_size.width);
new_size.height = bounds
.1
.map(|bound_h| new_size.height.min(bound_h.get()))
@@ -346,10 +341,7 @@ impl WindowState {
}
let new_state = configure.state;
let old_state = self
.last_configure
.as_ref()
.map(|configure| configure.state);
let old_state = self.last_configure.as_ref().map(|configure| configure.state);
let state_change_requires_resize = old_state
.map(|old_state| {
@@ -387,10 +379,7 @@ impl WindowState {
configure_bounds.0.unwrap_or(NonZeroU32::new(1).unwrap()),
configure_bounds.1.unwrap_or(NonZeroU32::new(1).unwrap()),
);
(
configure_bounds.0.and(width),
configure_bounds.1.and(height),
)
(configure_bounds.0.and(width), configure_bounds.1.and(height))
} else {
configure_bounds
}
@@ -460,7 +449,7 @@ impl WindowState {
_ => return None,
};
self.window.resize(seat, serial, edge);
}
},
FrameAction::ShowMenu(x, y) => self.window.show_window_menu(seat, serial, (x, y)),
_ => (),
};
@@ -643,12 +632,7 @@ impl WindowState {
/// Try to resize the window when the user can do so.
pub fn request_inner_size(&mut self, inner_size: Size) -> PhysicalSize<u32> {
if self
.last_configure
.as_ref()
.map(Self::is_stateless)
.unwrap_or(true)
{
if self.last_configure.as_ref().map(Self::is_stateless).unwrap_or(true) {
self.resize(inner_size.to_logical(self.scale_factor()))
}
@@ -674,10 +658,7 @@ impl WindowState {
);
}
(
frame.location(),
frame.add_borders(self.size.width, self.size.height).into(),
)
(frame.location(), frame.add_borders(self.size.width, self.size.height).into())
} else {
((0, 0), self.size)
};
@@ -724,16 +705,12 @@ impl WindowState {
/// Set the custom cursor icon.
pub(crate) fn set_custom_cursor(&mut self, cursor: RootCustomCursor) {
let cursor = match cursor {
RootCustomCursor {
inner: PlatformCustomCursor::Wayland(cursor),
} => cursor.0,
RootCustomCursor { inner: PlatformCustomCursor::Wayland(cursor) } => cursor.0,
#[cfg(x11_platform)]
RootCustomCursor {
inner: PlatformCustomCursor::X(_),
} => {
RootCustomCursor { inner: PlatformCustomCursor::X(_) } => {
tracing::error!("passed a X11 cursor to Wayland backend");
return;
}
},
};
let cursor = {
@@ -752,11 +729,7 @@ impl WindowState {
self.apply_on_pointer(|pointer, _| {
let surface = pointer.surface();
let scale = surface
.data::<SurfaceData>()
.unwrap()
.surface_data()
.scale_factor();
let scale = surface.data::<SurfaceData>().unwrap().surface_data().scale_factor();
surface.set_buffer_scale(scale);
surface.attach(Some(cursor.buffer.wl_buffer()), 0, 0);
@@ -864,7 +837,7 @@ impl WindowState {
}),
CursorGrabMode::Locked => {
self.apply_on_pointer(|_, data| data.unlock_pointer());
}
},
}
let surface = self.window.wl_surface();
@@ -879,7 +852,7 @@ impl WindowState {
}),
CursorGrabMode::None => {
// Current lock/confine was already removed.
}
},
}
Ok(())
@@ -902,11 +875,9 @@ impl WindowState {
// Position can be set only for locked cursor.
if self.cursor_grab_mode.current_grab_mode != CursorGrabMode::Locked {
return Err(ExternalError::Os(os_error!(
crate::platform_impl::OsError::Misc(
"cursor position can be set only for locked cursor."
)
)));
return Err(ExternalError::Os(os_error!(crate::platform_impl::OsError::Misc(
"cursor position can be set only for locked cursor."
))));
}
self.apply_on_pointer(|_, data| {
@@ -929,9 +900,7 @@ impl WindowState {
for pointer in self.pointers.iter().filter_map(|pointer| pointer.upgrade()) {
let latest_enter_serial = pointer.pointer().winit_data().latest_enter_serial();
pointer
.pointer()
.set_cursor(latest_enter_serial, None, 0, 0);
pointer.pointer().set_cursor(latest_enter_serial, None, 0, 0);
}
}
}
@@ -945,19 +914,12 @@ impl WindowState {
self.decorate = decorate;
match self
.last_configure
.as_ref()
.map(|configure| configure.decoration_mode)
{
match self.last_configure.as_ref().map(|configure| configure.decoration_mode) {
Some(DecorationMode::Server) if !self.decorate => {
// To disable decorations we should request client and hide the frame.
self.window
.request_decoration_mode(Some(DecorationMode::Client))
}
_ if self.decorate => self
.window
.request_decoration_mode(Some(DecorationMode::Server)),
self.window.request_decoration_mode(Some(DecorationMode::Client))
},
_ if self.decorate => self.window.request_decoration_mode(Some(DecorationMode::Server)),
_ => (),
}
@@ -1054,10 +1016,7 @@ impl WindowState {
info!("Blur manager unavailable, unable to change blur")
}
} else if !blurred && self.blur.is_some() {
self.blur_manager
.as_ref()
.unwrap()
.unset(self.window.wl_surface());
self.blur_manager.as_ref().unwrap().unset(self.window.wl_surface());
self.blur.take().unwrap().release();
}
}
@@ -1146,10 +1105,7 @@ struct GrabState {
impl GrabState {
fn new() -> Self {
Self {
user_grab_mode: CursorGrabMode::None,
current_grab_mode: CursorGrabMode::None,
}
Self { user_grab_mode: CursorGrabMode::None, current_grab_mode: CursorGrabMode::None }
}
}