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

@ -1,13 +1,12 @@
use std::{
ffi::CString,
hash::{Hash, Hasher},
iter, slice,
sync::Arc,
};
use std::ffi::CString;
use std::hash::{Hash, Hasher};
use std::sync::Arc;
use std::{iter, slice};
use x11rb::connection::Connection;
use crate::{platform_impl::PlatformCustomCursorSource, window::CursorIcon};
use crate::platform_impl::PlatformCustomCursorSource;
use crate::window::CursorIcon;
use super::super::ActiveEventLoop;
use super::*;
@ -21,13 +20,11 @@ impl XConnection {
.entry(cursor)
.or_insert_with(|| self.get_cursor(cursor));
self.update_cursor(window, cursor)
.expect("Failed to set cursor");
self.update_cursor(window, cursor).expect("Failed to set cursor");
}
pub(crate) fn set_custom_cursor(&self, window: xproto::Window, cursor: &CustomCursor) {
self.update_cursor(window, cursor.inner.cursor)
.expect("Failed to set cursor");
self.update_cursor(window, cursor.inner.cursor).expect("Failed to set cursor");
}
fn create_empty_cursor(&self) -> ffi::Cursor {
@ -151,12 +148,7 @@ impl CustomCursor {
let cursor =
(event_loop.xconn.xcursor.XcursorImageLoadCursor)(event_loop.xconn.display, ximage);
(event_loop.xconn.xcursor.XcursorImageDestroy)(ximage);
Self {
inner: Arc::new(CustomCursorInner {
xconn: event_loop.xconn.clone(),
cursor,
}),
}
Self { inner: Arc::new(CustomCursorInner { xconn: event_loop.xconn.clone(), cursor }) }
}
}
}

View file

@ -15,12 +15,7 @@ impl AaRect {
pub fn new((x, y): (i32, i32), (width, height): (u32, u32)) -> Self {
let (x, y) = (x as i64, y as i64);
let (width, height) = (width as i64, height as i64);
AaRect {
x,
y,
width,
height,
}
AaRect { x, y, width, height }
}
pub fn contains_point(&self, x: i64, y: i64) -> bool {
@ -50,12 +45,7 @@ pub struct FrameExtents {
impl FrameExtents {
pub fn new(left: u32, right: u32, top: u32, bottom: u32) -> Self {
FrameExtents {
left,
right,
top,
bottom,
}
FrameExtents { left, right, top, bottom }
}
pub fn from_border(border: u32) -> Self {
@ -80,10 +70,7 @@ impl FrameExtentsHeuristic {
pub fn inner_pos_to_outer(&self, x: i32, y: i32) -> (i32, i32) {
use self::FrameExtentsHeuristicPath::*;
if self.heuristic_path != UnsupportedBordered {
(
x - self.frame_extents.left as i32,
y - self.frame_extents.top as i32,
)
(x - self.frame_extents.left as i32, y - self.frame_extents.top as i32)
} else {
(x, y)
}
@ -92,14 +79,10 @@ impl FrameExtentsHeuristic {
pub fn inner_size_to_outer(&self, width: u32, height: u32) -> (u32, u32) {
(
width.saturating_add(
self.frame_extents
.left
.saturating_add(self.frame_extents.right) as _,
self.frame_extents.left.saturating_add(self.frame_extents.right) as _
),
height.saturating_add(
self.frame_extents
.top
.saturating_add(self.frame_extents.bottom) as _,
self.frame_extents.top.saturating_add(self.frame_extents.bottom) as _
),
)
}
@ -112,10 +95,7 @@ impl XConnection {
window: xproto::Window,
root: xproto::Window,
) -> Result<xproto::TranslateCoordinatesReply, X11Error> {
self.xcb_connection()
.translate_coordinates(window, root, 0, 0)?
.reply()
.map_err(Into::into)
self.xcb_connection().translate_coordinates(window, root, 0, 0)?.reply().map_err(Into::into)
}
// This is adequate for inner_size
@ -123,10 +103,7 @@ impl XConnection {
&self,
window: xproto::Window,
) -> Result<xproto::GetGeometryReply, X11Error> {
self.xcb_connection()
.get_geometry(window)?
.reply()
.map_err(Into::into)
self.xcb_connection().get_geometry(window)?.reply().map_err(Into::into)
}
fn get_frame_extents(&self, window: xproto::Window) -> Option<FrameExtents> {
@ -141,11 +118,7 @@ impl XConnection {
// support this. As this is part of EWMH (Extended Window Manager Hints), it's likely to
// be unsupported by many smaller WMs.
let extents: Option<Vec<u32>> = self
.get_property(
window,
extents_atom,
xproto::Atom::from(xproto::AtomEnum::CARDINAL),
)
.get_property(window, extents_atom, xproto::Atom::from(xproto::AtomEnum::CARDINAL))
.ok();
extents.and_then(|extents| {
@ -171,11 +144,7 @@ impl XConnection {
}
let client_list: Option<Vec<xproto::Window>> = self
.get_property(
root,
client_list_atom,
xproto::Atom::from(xproto::AtomEnum::WINDOW),
)
.get_property(root, client_list_atom, xproto::Atom::from(xproto::AtomEnum::WINDOW))
.ok();
client_list.map(|client_list| client_list.contains(&(window as xproto::Window)))
@ -221,14 +190,9 @@ impl XConnection {
};
let (width, height, border) = {
let inner_geometry = self
.get_geometry(window)
.expect("Failed to get inner window geometry");
(
inner_geometry.width,
inner_geometry.height,
inner_geometry.border_width,
)
let inner_geometry =
self.get_geometry(window).expect("Failed to get inner window geometry");
(inner_geometry.width, inner_geometry.height, inner_geometry.border_width)
};
// The first condition is only false for un-nested windows, but isn't always false for
@ -253,39 +217,29 @@ impl XConnection {
// known discrepancies:
// * Mutter/Muffin/Budgie gives decorated windows a margin of 9px (only 7px on top) in
// addition to a 1px semi-transparent border. The margin can be easily observed by
// using a screenshot tool to get a screenshot of a selected window, and is
// presumably used for drawing drop shadows. Getting window geometry information
// via hierarchy-climbing results in this margin being included in both the
// position and outer size, so a window positioned at (0, 0) would be reported as
// having a position (-10, -8).
// * Compiz has a drop shadow margin just like Mutter/Muffin/Budgie, though it's 10px
// on all sides, and there's no additional border.
// * Enlightenment otherwise gets a y position equivalent to inner_y_rel_root.
// Without decorations, there's no difference. This is presumably related to
// Enlightenment's fairly unique concept of window position; it interprets
// positions given to XMoveWindow as a client area position rather than a position
// of the overall window.
// using a screenshot tool to get a screenshot of a selected window, and is presumably
// used for drawing drop shadows. Getting window geometry information via
// hierarchy-climbing results in this margin being included in both the position and
// outer size, so a window positioned at (0, 0) would be reported as having a position
// (-10, -8).
// * Compiz has a drop shadow margin just like Mutter/Muffin/Budgie, though it's 10px on
// all sides, and there's no additional border.
// * Enlightenment otherwise gets a y position equivalent to inner_y_rel_root. Without
// decorations, there's no difference. This is presumably related to Enlightenment's
// fairly unique concept of window position; it interprets positions given to
// XMoveWindow as a client area position rather than a position of the overall window.
FrameExtentsHeuristic {
frame_extents,
heuristic_path: Supported,
}
FrameExtentsHeuristic { frame_extents, heuristic_path: Supported }
} else if nested {
// If the position value we have is for a nested window used as the client area, we'll
// just climb up the hierarchy and get the geometry of the outermost window we're
// nested in.
let outer_window = self
.climb_hierarchy(window, root)
.expect("Failed to climb window hierarchy");
let outer_window =
self.climb_hierarchy(window, root).expect("Failed to climb window hierarchy");
let (outer_y, outer_width, outer_height) = {
let outer_geometry = self
.get_geometry(outer_window)
.expect("Failed to get outer window geometry");
(
outer_geometry.y,
outer_geometry.width,
outer_geometry.height,
)
let outer_geometry =
self.get_geometry(outer_window).expect("Failed to get outer window geometry");
(outer_geometry.y, outer_geometry.width, outer_geometry.height)
};
// Since we have the geometry of the outermost window and the geometry of the client
@ -300,18 +254,12 @@ impl XConnection {
let bottom = diff_y.saturating_sub(offset_y);
let frame_extents = FrameExtents::new(left, right, top, bottom);
FrameExtentsHeuristic {
frame_extents,
heuristic_path: UnsupportedNested,
}
FrameExtentsHeuristic { frame_extents, heuristic_path: UnsupportedNested }
} else {
// This is the case for xmonad and dwm, AKA the only WMs tested that supplied a
// border value. This is convenient, since we can use it to get an accurate frame.
let frame_extents = FrameExtents::from_border(border.into());
FrameExtentsHeuristic {
frame_extents,
heuristic_path: UnsupportedBordered,
}
FrameExtentsHeuristic { frame_extents, heuristic_path: UnsupportedBordered }
}
}
}

View file

@ -76,13 +76,7 @@ mod mwm {
impl MotifHints {
pub fn new() -> MotifHints {
MotifHints {
hints: MwmHints {
flags: 0,
functions: 0,
decorations: 0,
input_mode: 0,
status: 0,
},
hints: MwmHints { flags: 0, functions: 0, decorations: 0, input_mode: 0, status: 0 },
}
}

View file

@ -1,8 +1,6 @@
use std::{slice, str};
use x11rb::protocol::{
xinput::{self, ConnectionExt as _},
xkb,
};
use x11rb::protocol::xinput::{self, ConnectionExt as _};
use x11rb::protocol::xkb;
use super::*;
@ -22,13 +20,10 @@ impl XConnection {
mask: xinput::XIEventMask,
) -> Result<VoidCookie<'_>, X11Error> {
self.xcb_connection()
.xinput_xi_select_events(
window,
&[xinput::EventMask {
deviceid: device_id,
mask: vec![mask],
}],
)
.xinput_xi_select_events(window, &[xinput::EventMask {
deviceid: device_id,
mask: vec![mask],
}])
.map_err(Into::into)
}

View file

@ -1,4 +1,5 @@
use std::{iter::Enumerate, slice::Iter};
use std::iter::Enumerate;
use std::slice::Iter;
use super::*;
@ -14,17 +15,13 @@ pub struct KeymapIter<'a> {
impl Keymap {
pub fn iter(&self) -> KeymapIter<'_> {
KeymapIter {
iter: self.keys.iter().enumerate(),
index: 0,
item: None,
}
KeymapIter { iter: self.keys.iter().enumerate(), index: 0, item: None }
}
}
impl<'a> IntoIterator for &'a Keymap {
type Item = ffi::KeyCode;
type IntoIter = KeymapIter<'a>;
type Item = ffi::KeyCode;
fn into_iter(self) -> Self::IntoIter {
self.iter()

View file

@ -1,11 +1,9 @@
// Welcome to the util module, where we try to keep you from shooting yourself in the foot.
// *results may vary
use std::{
mem::{self, MaybeUninit},
ops::BitAnd,
os::raw::*,
};
use std::mem::{self, MaybeUninit};
use std::ops::BitAnd;
use std::os::raw::*;
mod client_msg;
pub mod cookie;
@ -22,12 +20,17 @@ mod window_property;
mod wm;
mod xmodmap;
pub use self::{
cursor::*, geometry::*, hint::*, input::*, mouse::*, window_property::*, wm::*,
xmodmap::ModifierKeymap,
};
pub use self::cursor::*;
pub use self::geometry::*;
pub use self::hint::*;
pub use self::input::*;
pub use self::mouse::*;
pub use self::window_property::*;
pub use self::wm::*;
pub use self::xmodmap::ModifierKeymap;
use super::{atoms::*, ffi, VoidCookie, X11Error, XConnection, XError};
use super::atoms::*;
use super::{ffi, VoidCookie, X11Error, XConnection, XError};
use x11rb::protocol::xproto::{self, ConnectionExt as _};
pub fn maybe_change<T: PartialEq>(field: &mut Option<T>, value: T) -> bool {
@ -54,12 +57,13 @@ impl XConnection {
// 1. `XPending`, `XNextEvent`, and `XWindowEvent` flush "as needed"
// 2. `XFlush` explicitly flushes
// 3. `XSync` flushes and blocks until all requests are responded to
// 4. Calls that have a return dependent on a response (i.e. `XGetWindowProperty`) sync internally.
// When in doubt, check the X11 source; if a function calls `_XReply`, it flushes and waits.
// 4. Calls that have a return dependent on a response (i.e. `XGetWindowProperty`) sync
// internally. When in doubt, check the X11 source; if a function calls `_XReply`, it flushes
// and waits.
// All util functions that abstract an async function will return a `Flusher`.
pub fn flush_requests(&self) -> Result<(), XError> {
unsafe { (self.xlib.XFlush)(self.display) };
//println!("XFlush");
// println!("XFlush");
// This isn't necessarily a useful time to check for errors (since our request hasn't
// necessarily been processed yet)
self.check_errors()
@ -67,7 +71,7 @@ impl XConnection {
pub fn sync_with_server(&self) -> Result<(), XError> {
unsafe { (self.xlib.XSync)(self.display, ffi::False) };
//println!("XSync");
// println!("XSync");
self.check_errors()
}
}

View file

@ -8,10 +8,7 @@ pub struct Delta<T> {
impl<T: Default> Default for Delta<T> {
fn default() -> Self {
Self {
x: Default::default(),
y: Default::default(),
}
Self { x: Default::default(), y: Default::default() }
}
}

View file

@ -1,8 +1,9 @@
use std::{env, str, str::FromStr};
use std::str::FromStr;
use std::{env, str};
use super::*;
use crate::platform_impl::platform::x11::monitor;
use crate::{dpi::validate_scale_factor, platform_impl::platform::x11::VideoModeHandle};
use crate::dpi::validate_scale_factor;
use crate::platform_impl::platform::x11::{monitor, VideoModeHandle};
use tracing::warn;
use x11rb::protocol::randr::{self, ConnectionExt as _};
@ -42,16 +43,14 @@ impl XConnection {
if let Some(xsettings_screen) = self.xsettings_screen() {
match self.xsettings_dpi(xsettings_screen) {
Ok(Some(dpi)) => return Some(dpi),
Ok(None) => {}
Ok(None) => {},
Err(err) => {
tracing::warn!("failed to fetch XSettings: {err}");
}
},
}
}
self.database()
.get_string("Xft.dpi", "")
.and_then(|s| f64::from_str(s).ok())
self.database().get_string("Xft.dpi", "").and_then(|s| f64::from_str(s).ok())
}
pub fn get_output_info(
@ -69,7 +68,7 @@ impl XConnection {
Err(err) => {
warn!("Failed to get output info: {:?}", err);
return None;
}
},
};
let bit_depth = self.default_root().root_depth;
@ -100,14 +99,15 @@ impl XConnection {
Err(err) => {
warn!("Failed to get output name: {:?}", err);
return None;
}
},
};
// Override DPI if `WINIT_X11_SCALE_FACTOR` variable is set
let deprecated_dpi_override = env::var("WINIT_HIDPI_FACTOR").ok();
if deprecated_dpi_override.is_some() {
warn!(
"The WINIT_HIDPI_FACTOR environment variable is deprecated; use WINIT_X11_SCALE_FACTOR"
)
"The WINIT_HIDPI_FACTOR environment variable is deprecated; use \
WINIT_X11_SCALE_FACTOR"
)
}
let dpi_env = env::var("WINIT_X11_SCALE_FACTOR").ok().map_or_else(
|| EnvVarDPI::NotSet,
@ -120,7 +120,8 @@ impl XConnection {
EnvVarDPI::NotSet
} else {
panic!(
"`WINIT_X11_SCALE_FACTOR` invalid; DPI factors must be either normal floats greater than 0, or `randr`. Got `{var}`"
"`WINIT_X11_SCALE_FACTOR` invalid; DPI factors must be either normal \
floats greater than 0, or `randr`. Got `{var}`"
);
}
},
@ -134,11 +135,12 @@ impl XConnection {
EnvVarDPI::Scale(dpi_override) => {
if !validate_scale_factor(dpi_override) {
panic!(
"`WINIT_X11_SCALE_FACTOR` invalid; DPI factors must be either normal floats greater than 0, or `randr`. Got `{dpi_override}`",
"`WINIT_X11_SCALE_FACTOR` invalid; DPI factors must be either normal \
floats greater than 0, or `randr`. Got `{dpi_override}`",
);
}
dpi_override
}
},
EnvVarDPI::NotSet => {
if let Some(dpi) = self.get_xft_dpi() {
dpi / 96.
@ -148,7 +150,7 @@ impl XConnection {
(output_info.mm_width as _, output_info.mm_height as _),
)
}
}
},
};
Some((name, scale_factor, modes))
@ -159,10 +161,8 @@ impl XConnection {
crtc_id: randr::Crtc,
mode_id: randr::Mode,
) -> Result<(), X11Error> {
let crtc = self
.xcb_connection()
.randr_get_crtc_info(crtc_id, x11rb::CURRENT_TIME)?
.reply()?;
let crtc =
self.xcb_connection().randr_get_crtc_info(crtc_id, x11rb::CURRENT_TIME)?.reply()?;
self.xcb_connection()
.randr_set_crtc_config(
@ -181,10 +181,6 @@ impl XConnection {
}
pub fn get_crtc_mode(&self, crtc_id: randr::Crtc) -> Result<randr::Mode, X11Error> {
Ok(self
.xcb_connection()
.randr_get_crtc_info(crtc_id, x11rb::CURRENT_TIME)?
.reply()?
.mode)
Ok(self.xcb_connection().randr_get_crtc_info(crtc_id, x11rb::CURRENT_TIME)?.reply()?.mode)
}
}

View file

@ -87,10 +87,7 @@ impl XConnection {
property,
property_type,
(mem::size_of::<T>() * 8) as u8,
new_value
.len()
.try_into()
.expect("too many items for property"),
new_value.len().try_into().expect("too many items for property"),
bytemuck::cast_slice::<T, u8>(new_value),
)
.map_err(Into::into)

View file

@ -38,12 +38,8 @@ impl XConnection {
fn get_supported_hints(&self, root: xproto::Window) -> Vec<xproto::Atom> {
let atoms = self.atoms();
let supported_atom = atoms[_NET_SUPPORTED];
self.get_property(
root,
supported_atom,
xproto::Atom::from(xproto::AtomEnum::ATOM),
)
.unwrap_or_else(|_| Vec::with_capacity(0))
self.get_property(root, supported_atom, xproto::Atom::from(xproto::AtomEnum::ATOM))
.unwrap_or_else(|_| Vec::with_capacity(0))
}
#[allow(clippy::useless_conversion)]
@ -57,22 +53,22 @@ impl XConnection {
// inavailability of time machines, we'll just try to get _NET_SUPPORTING_WM_CHECK
// regardless of whether or not the WM claims to support it.
//
// Blackbox 0.70 also incorrectly reports not supporting this, though that appears to be fixed
// in 0.72.
/*if !supported_hints.contains(&check_atom) {
return None;
}*/
// Blackbox 0.70 also incorrectly reports not supporting this, though that appears to be
// fixed in 0.72.
// if !supported_hints.contains(&check_atom) {
// return None;
// }
// IceWM (1.3.x and earlier) doesn't report supporting _NET_WM_NAME, but will nonetheless
// provide us with a value for it. Note that the unofficial 1.4 fork of IceWM works fine.
/*if !supported_hints.contains(&wm_name_atom) {
return None;
}*/
// if !supported_hints.contains(&wm_name_atom) {
// return None;
// }
// Of the WMs tested, only xmonad and dwm fail to provide a WM name.
// Querying this property on the root window will give us the ID of a child window created by
// the WM.
// Querying this property on the root window will give us the ID of a child window created
// by the WM.
let root_window_wm_check = {
let result = self.get_property::<xproto::Window>(
root,