diff --git a/build/build.rs b/build/build.rs index 15e63f5a..3e432be7 100644 --- a/build/build.rs +++ b/build/build.rs @@ -1,3 +1,16 @@ +#![allow( + clippy::len_zero, + clippy::needless_lifetimes, + clippy::enum_variant_names, + clippy::useless_format, + clippy::redundant_clone, + clippy::collapsible_if, + clippy::unnecessary_to_owned, + clippy::match_like_matches_macro, + clippy::too_many_arguments, + clippy::iter_skip_next, +)] + extern crate core; use std::fs::{File, OpenOptions}; diff --git a/build/enums.rs b/build/enums.rs index f4317cd1..f7517361 100644 --- a/build/enums.rs +++ b/build/enums.rs @@ -149,7 +149,7 @@ fn write_egl_procs(f: &mut W) -> anyhow::Result<()> { writeln!(f)?; writeln!(f, "#[derive(Copy, Clone, Debug)]")?; writeln!(f, "pub struct ExtProc {{")?; - for (name, _, _) in map.iter().copied() { + for (name, _, _) in map.iter() { writeln!(f, " {}: *mut u8,", name)?; } writeln!(f, "}}")?; diff --git a/build/wire_dbus.rs b/build/wire_dbus.rs index f2185f95..9b9d34fa 100644 --- a/build/wire_dbus.rs +++ b/build/wire_dbus.rs @@ -432,15 +432,15 @@ fn write_type2(f: &mut W, lt: &str, ty: &Type) -> Result<()> { Type::Fd => "Rc", Type::Array(e) => { write!(f, "Cow<{}, [", lt)?; - write_type2(f, lt, &e)?; + write_type2(f, lt, e)?; write!(f, "]>")?; return Ok(()); } Type::DictEntry(k, v) => { write!(f, "DictEntry<")?; - write_type2(f, lt, &k)?; + write_type2(f, lt, k)?; write!(f, ", ")?; - write_type2(f, lt, &v)?; + write_type2(f, lt, v)?; write!(f, ">")?; return Ok(()); } @@ -450,7 +450,7 @@ fn write_type2(f: &mut W, lt: &str, ty: &Type) -> Result<()> { if idx > 0 { write!(f, ", ")?; } - write_type2(f, lt, &fs)?; + write_type2(f, lt, fs)?; } write!(f, ")")?; return Ok(()); @@ -671,7 +671,7 @@ fn write_element(f: &mut W, element: Element, indent: &str) -> Result< { let indent = format!("{} ", indent); for component in &element.components { - write_component(f, &element, &component, &indent)?; + write_component(f, &element, component, &indent)?; } write_module(f, element, &indent)?; } diff --git a/build/wire_xcon.rs b/build/wire_xcon.rs index bb566c94..2ddb968b 100644 --- a/build/wire_xcon.rs +++ b/build/wire_xcon.rs @@ -362,9 +362,7 @@ impl<'a> Parser<'a> { } Ok(Type::String(len)) })(); - let ty = - ty.with_context(|| format!("While parsing string starting in line {}", line))?; - ty + ty.with_context(|| format!("While parsing string starting in line {}", line))? } b"list" => { let (line, body) = self.expect_tree(TreeDelim::Paren)?; @@ -381,9 +379,7 @@ impl<'a> Parser<'a> { } Ok(Type::List(Box::new(ty), len)) })(); - let ty = - ty.with_context(|| format!("While parsing list starting in line {}", line))?; - ty + ty.with_context(|| format!("While parsing list starting in line {}", line))? } b"bitmask" => { let (line, body) = self.expect_tree(TreeDelim::Paren)?; @@ -397,9 +393,7 @@ impl<'a> Parser<'a> { } Ok(Type::Bitmask(name.to_owned(), len)) })(); - let ty = - ty.with_context(|| format!("While parsing bitmask starting in line {}", line))?; - ty + ty.with_context(|| format!("While parsing bitmask starting in line {}", line))? } b"enum" => { let (line, body) = self.expect_tree(TreeDelim::Paren)?; @@ -413,9 +407,7 @@ impl<'a> Parser<'a> { } Ok(Type::Enum(Box::new(ty), len)) })(); - let ty = - ty.with_context(|| format!("While parsing enum starting in line {}", line))?; - ty + ty.with_context(|| format!("While parsing enum starting in line {}", line))? } _ => Type::Named(ty.to_owned()), }; diff --git a/default-config/src/lib.rs b/default-config/src/lib.rs index 429ab199..d7541e0a 100644 --- a/default-config/src/lib.rs +++ b/default-config/src/lib.rs @@ -76,7 +76,7 @@ fn configure_seat(s: Seat) { s.bind(MOD | SYM_p, || Command::new("xeyes").spawn()); - s.bind(MOD | SYM_q, || quit()); + s.bind(MOD | SYM_q, quit); s.bind(CTRL | ALT | SYM_F1, || switch_to_vt(1)); s.bind(CTRL | ALT | SYM_F2, || switch_to_vt(2)); diff --git a/jay-config/src/_private/client.rs b/jay-config/src/_private/client.rs index 423a3551..dc32b97d 100644 --- a/jay-config/src/_private/client.rs +++ b/jay-config/src/_private/client.rs @@ -1,3 +1,5 @@ +#![allow(clippy::declare_interior_mutable_const, clippy::type_complexity)] + use crate::_private::ipc::{ClientMessage, InitMessage, Response, ServerMessage}; use crate::_private::{bincode_ops, logging, Config, ConfigEntry, ConfigEntryGen, VERSION}; use crate::keyboard::keymap::Keymap; diff --git a/src/backends/metal/video.rs b/src/backends/metal/video.rs index 7ad7591b..5e7eea46 100644 --- a/src/backends/metal/video.rs +++ b/src/backends/metal/video.rs @@ -228,7 +228,7 @@ fn create_connector( master: dev.master.clone(), output_id: state.output_ids.next(), crtcs, - mode: CloneCell::new(info.modes.first().cloned().map(|m| Rc::new(m))), + mode: CloneCell::new(info.modes.first().cloned().map(Rc::new)), modes: info.modes, buffers: Default::default(), next_buffer: Default::default(), @@ -749,7 +749,7 @@ impl MetalBackend { let bo = dev.dev.gbm.create_bo( width, height, - &format, + format, GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT, ); let bo = match bo { @@ -929,7 +929,7 @@ pub struct RenderBuffer { } fn modes_equal(a: &DrmModeInfo, b: &DrmModeInfo) -> bool { - true && a.clock == b.clock + a.clock == b.clock && a.hdisplay == b.hdisplay && a.hsync_start == b.hsync_start && a.hsync_end == b.hsync_end diff --git a/src/backends/x.rs b/src/backends/x.rs index 89ddb173..abb743ae 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -329,7 +329,7 @@ impl XBackendData { modifier: INVALID_MODIFIER, }; let mut images = [None, None]; - for i in 0..2 { + for image in &mut images { let bo = self .gbm .create_bo(width, height, &format, GBM_BO_USE_RENDERING)?; @@ -358,7 +358,7 @@ impl XBackendData { } pfb.pixmap }; - images[i] = Some(XImage { + *image = Some(XImage { pixmap: Cell::new(pixmap), fb: CloneCell::new(fb), idle: Cell::new(true), diff --git a/src/client.rs b/src/client.rs index ae7fdc45..f49ba466 100644 --- a/src/client.rs +++ b/src/client.rs @@ -367,12 +367,10 @@ impl Client { pub fn lookup(&self, id: Id) -> Result, ClientError> { match Id::lookup(self, id) { Some(t) => Ok(t), - _ => { - return Err(ClientError::LookupError(LookupError { - interface: Id::INTERFACE, - id: id.into(), - })) - } + _ => Err(ClientError::LookupError(LookupError { + interface: Id::INTERFACE, + id: id.into(), + })), } } } diff --git a/src/config/handler.rs b/src/config/handler.rs index 43650879..7476cdbd 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -210,7 +210,7 @@ impl ConfigProxyHandler { let seat = self.get_seat(seat)?; self.send(&ServerMessage::Response { response: Response::GetMono { - mono: seat.get_mono().unwrap_or(false).into(), + mono: seat.get_mono().unwrap_or(false), }, }); Ok(()) diff --git a/src/dbus.rs b/src/dbus.rs index 1936fcc9..c1f10bc6 100644 --- a/src/dbus.rs +++ b/src/dbus.rs @@ -200,8 +200,8 @@ const NO_AUTO_START: u8 = 0x2; #[allow(dead_code)] const ALLOW_INTERACTIVE_AUTHORIZATION: u8 = 0x4; -pub const BUS_DEST: &'static str = "org.freedesktop.DBus"; -pub const BUS_PATH: &'static str = "/org/freedesktop/dbus"; +pub const BUS_DEST: &str = "org.freedesktop.DBus"; +pub const BUS_PATH: &str = "/org/freedesktop/dbus"; #[derive(Default, Debug)] struct Headers<'a> { diff --git a/src/dbus/formatter.rs b/src/dbus/formatter.rs index 2e192d8e..2119b9f3 100644 --- a/src/dbus/formatter.rs +++ b/src/dbus/formatter.rs @@ -60,7 +60,7 @@ impl<'a> Formatter<'a> { pub fn write_variant(&mut self, variant: &Variant) { let pos = self.buf.len(); self.buf.push(0); - variant.write_signature(&mut self.buf); + variant.write_signature(self.buf); self.buf.push(0); self.buf[pos] = (self.buf.len() - pos - 2) as u8; self.write_variant_body(variant); diff --git a/src/dbus/incoming.rs b/src/dbus/incoming.rs index 490f221b..855edae5 100644 --- a/src/dbus/incoming.rs +++ b/src/dbus/incoming.rs @@ -68,6 +68,7 @@ impl Incoming { self.incoming .fill_msg_buf(remaining as usize, msg_buf) .await?; + #[allow(clippy::drop_ref)] drop(msg_buf); let msg_buf = unsafe { msg_buf_data.get().deref().deref() }; let headers = &msg_buf[FIXED_HEADER_SIZE..FIXED_HEADER_SIZE + headers_len as usize]; @@ -78,7 +79,7 @@ impl Incoming { } let fds: Vec<_> = self.incoming.fds.drain(..unix_fds).collect(); let mut parser = Parser { - buf: &msg_buf, + buf: msg_buf, pos: FIXED_HEADER_SIZE + dyn_header_len as usize, fds: &fds, }; diff --git a/src/dbus/socket.rs b/src/dbus/socket.rs index 9189858a..197928c7 100644 --- a/src/dbus/socket.rs +++ b/src/dbus/socket.rs @@ -354,7 +354,7 @@ where struct AsyncReplyHandler>(Rc>); impl> AsyncReplyHandler { - fn complete(self: Box, res: Result, DbusError>) { + fn complete(self, res: Result, DbusError>) { self.0.data.set(Some(res)); if let Some(waker) = self.0.waker.take() { waker.wake(); diff --git a/src/drm/drm.rs b/src/drm/drm.rs index 110f6f16..52db595c 100644 --- a/src/drm/drm.rs +++ b/src/drm/drm.rs @@ -284,7 +284,7 @@ impl DrmMaster { master: self.clone(), fb, }), - Err(e) => return Err(DrmError::AddFb(e)), + Err(e) => Err(DrmError::AddFb(e)), } } @@ -544,11 +544,11 @@ pub struct DrmModeInfo { impl DrmModeInfo { pub fn create_blob(&self, master: &Rc) -> Result { - let raw = self.into_raw(); + let raw = self.to_raw(); master.create_blob(&raw) } - pub fn into_raw(&self) -> drm_mode_modeinfo { + pub fn to_raw(&self) -> drm_mode_modeinfo { let mut name = [0u8; DRM_DISPLAY_MODE_LEN]; let len = name.len().min(self.name.len()); name[..len].copy_from_slice(&self.name.as_bytes()[..len]); diff --git a/src/drm/drm/sys.rs b/src/drm/drm/sys.rs index c0b266d7..89aa9057 100644 --- a/src/drm/drm/sys.rs +++ b/src/drm/drm/sys.rs @@ -87,7 +87,7 @@ pub fn get_minor_type(min: u64) -> Result { } } -const DRM_DIR_NAME: &'static str = "/dev/dri"; +const DRM_DIR_NAME: &str = "/dev/dri"; fn device_dir(maj: u64, min: u64) -> Ustring { uapi::format_ustr!("/sys/dev/char/{maj}:{min}/device/drm") @@ -264,11 +264,11 @@ pub fn mode_getproperty( prop.count_values = 0; let mut props = Vec::::with_capacity(prop.count_enum_blobs as usize); + prop.enum_blob_ptr = props.as_mut_ptr() as _; + get(&mut prop)?; unsafe { props.set_len(prop.count_enum_blobs as usize); } - prop.enum_blob_ptr = props.as_mut_ptr() as _; - get(&mut prop)?; let mut values = Vec::with_capacity(props.len()); for v in props { values.push(DrmPropertyEnumValue { diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index c3d2e32f..7d51cfb7 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -52,6 +52,7 @@ use std::ops::{Deref, DerefMut}; use std::rc::Rc; use thiserror::Error; use uapi::{c, Errno, OwnedFd}; +use crate::utils::rc_eq::rc_eq; const POINTER: u32 = 1; const KEYBOARD: u32 = 2; @@ -193,7 +194,7 @@ impl WlSeatGlobal { for seat in client.values() { let kbs = seat.keyboards.lock(); for kb in kbs.values() { - let fd = match seat.keymap_fd(&keymap) { + let fd = match seat.keymap_fd(keymap) { Ok(fd) => fd, Err(e) => { log::error!("Could not creat a file descriptor to transfer the keymap to client {}: {}", id, ErrorFmt(e)); @@ -344,7 +345,7 @@ impl WlSeatGlobal { pub fn set_cursor(&self, cursor: Option>) { if let Some(old) = self.cursor.get() { if let Some(new) = cursor.as_ref() { - if Rc::ptr_eq(&old, new) { + if rc_eq(&old, new) { return; } } diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index ef85e109..f5ec3753 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -236,7 +236,7 @@ impl WlSeatGlobal { client: &Rc, ) { match field.get() { - Some(sel) => ipc::offer_source_to::(&sel, &client), + Some(sel) => ipc::offer_source_to::(&sel, client), None => T::for_each_device(self, client.id, |dd| { T::send_selection(dd, ObjectId::NONE.into()); }), @@ -441,7 +441,7 @@ impl WlSeatGlobal { pub fn focus_surface(&self, surface: &WlSurface) { let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect(); let serial = self.serial.fetch_add(1); - self.surface_kb_event(0, &surface, |k| { + self.surface_kb_event(0, surface, |k| { k.send_enter(serial, surface.id, &pressed_keys) }); let ModifierState { @@ -452,7 +452,7 @@ impl WlSeatGlobal { .. } = self.kb_state.borrow().mods(); let serial = self.serial.fetch_add(1); - self.surface_kb_event(0, &surface, |k| { + self.surface_kb_event(0, surface, |k| { k.send_modifiers(serial, mods_depressed, mods_latched, mods_locked, group) }); diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index de3354fe..baef9db6 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -275,7 +275,7 @@ impl PointerOwner for GrabPointerOwner { icon.dnd_icons.insert(seat.id(), seat.clone()); } if let Some(new) = &src { - ipc::attach_seat::(&new, seat, ipc::Role::Dnd)?; + ipc::attach_seat::(new, seat, ipc::Role::Dnd)?; } *seat.dropped_dnd.borrow_mut() = None; let pointer_owner = Rc::new(DndPointerOwner { diff --git a/src/ifs/wl_surface/wl_subsurface.rs b/src/ifs/wl_surface/wl_subsurface.rs index aaaeec9f..db6b1754 100644 --- a/src/ifs/wl_surface/wl_subsurface.rs +++ b/src/ifs/wl_surface/wl_subsurface.rs @@ -126,7 +126,7 @@ impl WlSubsurface { self.sync_ancestor.set(sync_ancestor); self.depth.set(depth); self.surface.ext.set(self.clone()); - update_children_attach(&self, sync_ancestor, depth)?; + update_children_attach(self, sync_ancestor, depth)?; Ok(()) } diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index 42054466..4743b44d 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -530,7 +530,7 @@ impl XdgSurfaceExt for XdgToplevel { if let Some(workspace) = self.xdg.workspace.get() { let output = workspace.output.get(); let bindings = output.global.bindings.borrow_mut(); - for binding in bindings.get(&self.xdg.surface.client.id) { + if let Some(binding) = bindings.get(&self.xdg.surface.client.id) { for binding in binding.values() { self.xdg.surface.send_enter(binding.id); } diff --git a/src/logind.rs b/src/logind.rs index ab3ecc84..dbe9298b 100644 --- a/src/logind.rs +++ b/src/logind.rs @@ -115,7 +115,7 @@ impl Session { .handle_signal::( Some(LOGIND_NAME), Some(&self.session_path), - move |v| f(v), + f, ) } diff --git a/src/main.rs b/src/main.rs index 985a4b3c..78436544 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,23 @@ clippy::needless_lifetimes, clippy::enum_variant_names, clippy::useless_format, - clippy::redundant_clone + clippy::redundant_clone, + clippy::collapsible_if, + clippy::match_like_matches_macro, + clippy::collapsible_else_if, + clippy::identity_op, + clippy::module_inception, + clippy::single_char_pattern, + clippy::too_many_arguments, + clippy::from_over_into, + clippy::single_match, + clippy::upper_case_acronyms, + clippy::manual_map, + clippy::type_complexity, + clippy::option_map_unit_fn, + clippy::wrong_self_convention, + clippy::single_char_add_str, + clippy::ptr_eq, )] use crate::cli::{Cli, Cmd}; diff --git a/src/pango.rs b/src/pango.rs index b1773ab1..0e0523bf 100644 --- a/src/pango.rs +++ b/src/pango.rs @@ -214,7 +214,7 @@ impl PangoCairoContext { } Ok(PangoLayout { c: self.clone(), - l: l, + l, }) } } diff --git a/src/render/egl.rs b/src/render/egl.rs index 45e47314..1fdcce80 100644 --- a/src/render/egl.rs +++ b/src/render/egl.rs @@ -28,9 +28,9 @@ pub mod display; pub mod image; pub mod sys; -pub(super) static PROCS: Lazy = Lazy::new(|| ExtProc::load()); +pub(super) static PROCS: Lazy = Lazy::new(ExtProc::load); -pub(super) static EXTS: Lazy = Lazy::new(|| get_client_ext()); +pub(super) static EXTS: Lazy = Lazy::new(get_client_ext); pub fn init() -> Result<(), RenderError> { if !EXTS.contains(ClientExt::EXT_PLATFORM_BASE) { diff --git a/src/render/proc.rs b/src/render/proc.rs index 7fefdc56..ea6ece7f 100644 --- a/src/render/proc.rs +++ b/src/render/proc.rs @@ -1,3 +1,3 @@ -#![allow(non_snake_case, dead_code)] +#![allow(non_snake_case, dead_code, clippy::unused_unit)] include!(concat!(env!("OUT_DIR"), "/egl_procs.rs")); diff --git a/src/render/renderer/renderer.rs b/src/render/renderer/renderer.rs index bbeba440..9affabad 100644 --- a/src/render/renderer/renderer.rs +++ b/src/render/renderer/renderer.rs @@ -19,6 +19,7 @@ use crate::theme::Color; use crate::tree::{ContainerNode, FloatNode, Node, OutputNode, WorkspaceNode}; use std::ops::Deref; use std::rc::Rc; +use crate::utils::rc_eq::rc_eq; pub struct Renderer<'a> { pub(super) ctx: &'a Rc, @@ -201,7 +202,7 @@ impl Renderer<'_> { } pub fn render_texture(&mut self, texture: &Texture, x: i32, y: i32, format: &Format) { - assert!(Rc::ptr_eq(&self.ctx.ctx, &texture.ctx.ctx)); + assert!(rc_eq(&self.ctx.ctx, &texture.ctx.ctx)); unsafe { glActiveTexture(GL_TEXTURE0); diff --git a/src/theme.rs b/src/theme.rs index 2521f931..0a9df6fb 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -18,7 +18,7 @@ impl Color { } fn to_f32(c: u8) -> f32 { - c as f32 / 255 as f32 + c as f32 / 255f32 } impl Color { diff --git a/src/tree/container.rs b/src/tree/container.rs index 9b5c28cc..1751f439 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -21,6 +21,7 @@ use std::fmt::{Debug, Formatter}; use std::mem; use std::ops::{Deref, DerefMut, Sub}; use std::rc::Rc; +use crate::utils::rc_eq::rc_eq; #[allow(dead_code)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -197,14 +198,12 @@ impl ContainerNode { pub fn prepend_child(self: &Rc, new: Rc) { if let Some(child) = self.children.first() { self.add_child_before_(&child, new); - return; } } pub fn append_child(self: &Rc, new: Rc) { if let Some(child) = self.children.last() { self.add_child_after_(&child, new); - return; } } @@ -271,7 +270,7 @@ impl ContainerNode { let new_child_factor = 1.0 / num_children as f64; let mut sum_factors = 0.0; for child in self.children.iter() { - let factor = if Rc::ptr_eq(&child.node, &new) { + let factor = if rc_eq(&child.node, &new) { new_child_factor } else { child.factor.get() * (1.0 - new_child_factor) @@ -588,7 +587,7 @@ impl ContainerNode { } if let Some(ctx) = &ctx { let title = c.title.borrow_mut(); - match text::render(&ctx, width, th, &font, &title, Color::GREY) { + match text::render(ctx, width, th, &font, &title, Color::GREY) { Ok(t) => rd.titles.push(ContainerTitle { x: pos, y: 0, @@ -626,7 +625,7 @@ impl ContainerNode { rd.underline_rects.push(rect); if let Some(ctx) = &ctx { let title = c.title.borrow_mut(); - match text::render(&ctx, body.width(), th, &font, &title, Color::GREY) { + match text::render(ctx, body.width(), th, &font, &title, Color::GREY) { Ok(t) => rd.titles.push(ContainerTitle { x: body.x1(), y: body.y1() - th - 1, diff --git a/src/utils.rs b/src/utils.rs index b4a5bd2c..e5859ddc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -25,3 +25,4 @@ pub mod trim; pub mod vasprintf; pub mod vec_ext; pub mod vecstorage; +pub mod rc_eq; diff --git a/src/utils/buffd/buf_out.rs b/src/utils/buffd/buf_out.rs index 9ccf2b5a..1c0b17ec 100644 --- a/src/utils/buffd/buf_out.rs +++ b/src/utils/buffd/buf_out.rs @@ -65,7 +65,7 @@ impl OutBufferSwapchain { pub fn commit(&mut self) { if self.cur.write_pos > 0 { - let new = self.free.pop().unwrap_or_else(|| Default::default()); + let new = self.free.pop().unwrap_or_default(); let old = mem::replace(&mut self.cur, new); self.pending.push_back(old); } diff --git a/src/utils/linkedlist.rs b/src/utils/linkedlist.rs index 0d7cb664..64398ec3 100644 --- a/src/utils/linkedlist.rs +++ b/src/utils/linkedlist.rs @@ -224,7 +224,7 @@ impl NodeRef { { unsafe { let data = self.data.as_ref(); - let other = peer(&data).get(); + let other = peer(data).get(); if other.as_ref().data.is_some() { other.as_ref().rc.fetch_add(1); Some(NodeRef { data: other }) diff --git a/src/utils/oserror.rs b/src/utils/oserror.rs index 8d8a6fce..67781b17 100644 --- a/src/utils/oserror.rs +++ b/src/utils/oserror.rs @@ -5,7 +5,7 @@ use uapi::c::c_int; use uapi::{c, Errno}; static ERRORS: Lazy<&'static [Option<&'static str>]> = Lazy::new(|| { - static MSGS: &'static [(c::c_int, &'static str)] = &[ + static MSGS: &[(c::c_int, &str)] = &[ (c::EWOULDBLOCK, "Operation would block"), (c::ENOTSUP, "Not supported"), (c::EHWPOISON, "Memory page has hardware error"), diff --git a/src/utils/rc_eq.rs b/src/utils/rc_eq.rs new file mode 100644 index 00000000..725b3a3d --- /dev/null +++ b/src/utils/rc_eq.rs @@ -0,0 +1,5 @@ +use std::rc::Rc; + +pub fn rc_eq(a: &Rc, b: &Rc) -> bool { + Rc::as_ptr(a) as *const u8 == Rc::as_ptr(b) as *const u8 +} diff --git a/src/wire_xcon.rs b/src/wire_xcon.rs index 974b25d9..fa185cee 100644 --- a/src/wire_xcon.rs +++ b/src/wire_xcon.rs @@ -1,4 +1,4 @@ -#![allow(unused_imports, unused_variables, dead_code, unused_assignments)] +#![allow(unused_imports, unused_variables, dead_code, unused_assignments, clippy::eval_order_dependence, clippy::double_parens, clippy::unnecessary_cast)] use crate::xcon::{Formatter, Message, Parser, Request, XEvent, XconError}; use bstr::BStr; diff --git a/src/xcon.rs b/src/xcon.rs index c1d3ab98..3033f173 100644 --- a/src/xcon.rs +++ b/src/xcon.rs @@ -257,7 +257,7 @@ struct AsyncReplyHandler> { } impl> AsyncReplyHandler { - fn done(self: Box, res: Result, XconError>) { + fn done(self, res: Result, XconError>) { if let Some(slot) = self.slot.upgrade() { slot.data.set(Some(res)); if let Some(waker) = slot.waker.take() { diff --git a/src/xcon/parser.rs b/src/xcon/parser.rs index 78588b09..5f03a98a 100644 --- a/src/xcon/parser.rs +++ b/src/xcon/parser.rs @@ -61,7 +61,7 @@ impl<'a> Parser<'a> { Ok(self.fds[self.fds_pos - 1].clone()) } - pub fn read_pod<'b, T: Pod>(&mut self) -> Result { + pub fn read_pod(&mut self) -> Result { match uapi::pod_read_init(&self.buf[self.pos..]) { Ok(v) => { self.pos += mem::size_of::(); diff --git a/src/xwayland.rs b/src/xwayland.rs index 6a05ec31..9b5703fb 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -24,19 +24,19 @@ use uapi::{c, pipe2, Errno, OwnedFd}; #[derive(Debug, Error)] enum XWaylandError { #[error("Could not create a wayland socket")] - SocketFailed(#[source] crate::utils::oserror::OsError), + SocketFailed(#[source] OsError), #[error("/tmp/.X11-unix does not exist")] MissingSocketDir, #[error("Could not stat /tmp/.X11-unix")] - StatSocketDir(#[source] crate::utils::oserror::OsError), + StatSocketDir(#[source] OsError), #[error("/tmp/.X11-unix is not a directory")] NotASocketDir, #[error("/tmp/.X11-unix is writable")] SocketDirNotWritable, #[error("Could not write to the lock file")] - WriteLockFile(#[source] std::io::Error), + WriteLockFile(#[source] OsError), #[error("Could not open the lock file for reading")] - ReadLockFile(#[source] std::io::Error), + ReadLockFile(#[source] OsError), #[error("The lock file does not contain a PID")] NotALockFile(#[source] ParseIntError), #[error("The socket is already in use")] @@ -183,17 +183,18 @@ async fn run( pub fn build_args(fds: &[OwnedFd]) -> (String, Vec) { let prog = "Xwayland".to_string(); - let mut args = vec![]; - args.push("-terminate".to_string()); - args.push("-rootless".to_string()); - args.push("-verbose".to_string()); - args.push(10.to_string()); - args.push("-displayfd".to_string()); - args.push(fds[0].raw().to_string()); - args.push("-listenfd".to_string()); - args.push(fds[1].raw().to_string()); - args.push("-wm".to_string()); - args.push(fds[2].raw().to_string()); + let args = vec![ + "-terminate".to_string(), + "-rootless".to_string(), + "-verbose".to_string(), + 10.to_string(), + "-displayfd".to_string(), + fds[0].raw().to_string(), + "-listenfd".to_string(), + fds[1].raw().to_string(), + "-wm".to_string(), + fds[2].raw().to_string(), + ]; (prog, args) } diff --git a/src/xwayland/xwm.rs b/src/xwayland/xwm.rs index a64c9dab..f26b077b 100644 --- a/src/xwayland/xwm.rs +++ b/src/xwayland/xwm.rs @@ -326,8 +326,8 @@ impl Wm { c, atoms, never_focus, - root: root, - xwin: xwin, + root, + xwin, client, windows: Default::default(), windows_by_surface_id: Default::default(), @@ -687,7 +687,7 @@ impl Wm { { data.info.icccm_hints.input.set(1); } - self.compute_input_model(&data); + self.compute_input_model(data); } async fn load_window_wm_normal_hints(&self, data: &Rc) { @@ -838,7 +838,7 @@ impl Wm { } data.info .never_focus - .set(buf.iter().any(|t| self.never_focus.contains(&t))); + .set(buf.iter().any(|t| self.never_focus.contains(t))); data.info.window_types.clear(); data.info .window_types @@ -852,7 +852,7 @@ impl Wm { log::error!("The xwindow has already been constructed"); return; } - let window = Rc::new(Xwindow::new(&data, &surface, &self.queue)); + let window = Rc::new(Xwindow::new(data, &surface, &self.queue)); if let Err(e) = window.install() { log::error!( "Could not attach the xwindow to the surface: {}", @@ -912,7 +912,7 @@ impl Wm { async fn handle_event(&mut self, event: &Event) { match event.ext() { Some(_) => {} - _ => self.handle_core_event(&event).await, + _ => self.handle_core_event(event).await, } } @@ -1489,8 +1489,7 @@ impl Wm { } fn update_wants_floating(&self, data: &Rc) { - let res = false - || data.info.modal.get() + let res = data.info.modal.get() || data .info .window_types