From b9e55419719a541287dda3f1c791ead565108ab2 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Sat, 20 Sep 2025 12:17:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=F0=9F=93=8E-fixes,=20typo=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dash-frontend/src/lib.rs | 2 +- wgui/src/components/button.rs | 8 +- wgui/src/components/checkbox.rs | 8 +- wgui/src/event.rs | 2 +- wgui/src/globals.rs | 6 +- wgui/src/layout.rs | 6 +- wgui/src/lib.rs | 3 +- wgui/src/parser/mod.rs | 67 +++++----- wgui/src/widget/label.rs | 4 +- wgui/src/widget/mod.rs | 91 ++++++------- wlx-capture/src/lib.rs | 1 + wlx-capture/src/pipewire.rs | 39 +++--- wlx-capture/src/wayland.rs | 12 +- wlx-capture/src/wlr_dmabuf.rs | 28 ++-- wlx-capture/src/xshm.rs | 12 +- wlx-overlay-s/src/backend/common.rs | 12 +- wlx-overlay-s/src/backend/input.rs | 81 ++++++------ wlx-overlay-s/src/backend/openvr/manifest.rs | 18 +-- wlx-overlay-s/src/backend/openvr/mod.rs | 24 ++-- wlx-overlay-s/src/backend/openxr/blocker.rs | 9 +- wlx-overlay-s/src/backend/openxr/input.rs | 44 +++---- wlx-overlay-s/src/backend/openxr/mod.rs | 44 +++---- wlx-overlay-s/src/backend/openxr/swapchain.rs | 4 +- wlx-overlay-s/src/backend/overlay.rs | 9 +- wlx-overlay-s/src/backend/wayvr/client.rs | 39 +++--- wlx-overlay-s/src/backend/wayvr/display.rs | 41 +++--- wlx-overlay-s/src/backend/wayvr/mod.rs | 44 +++---- wlx-overlay-s/src/backend/wayvr/process.rs | 16 +-- wlx-overlay-s/src/backend/wayvr/server_ipc.rs | 20 +-- wlx-overlay-s/src/config_wayvr.rs | 16 +-- wlx-overlay-s/src/gui/panel/button.rs | 44 ++++--- wlx-overlay-s/src/gui/panel/helper.rs | 8 +- wlx-overlay-s/src/gui/panel/label.rs | 120 +++++++++--------- wlx-overlay-s/src/main.rs | 28 ++-- wlx-overlay-s/src/overlays/keyboard/mod.rs | 8 +- wlx-overlay-s/src/overlays/screen/pw.rs | 8 +- wlx-overlay-s/src/overlays/screen/wl.rs | 16 +-- wlx-overlay-s/src/overlays/screen/x11.rs | 14 +- wlx-overlay-s/src/overlays/wayvr.rs | 8 +- wlx-overlay-s/src/subsystem/hid/mod.rs | 22 ++-- wlx-overlay-s/src/subsystem/hid/wayland.rs | 6 +- 41 files changed, 494 insertions(+), 498 deletions(-) diff --git a/dash-frontend/src/lib.rs b/dash-frontend/src/lib.rs index f829d2b..c9736e0 100644 --- a/dash-frontend/src/lib.rs +++ b/dash-frontend/src/lib.rs @@ -116,7 +116,7 @@ impl Frontend { }; // fixme: timer events instead of this thing - if self.ticks % 1000 == 0 { + if self.ticks.is_multiple_of(1000) { self.update_time(&mut common); } diff --git a/wgui/src/components/button.rs b/wgui/src/components/button.rs index dc0b12e..64d90f6 100644 --- a/wgui/src/components/button.rs +++ b/wgui/src/components/button.rs @@ -216,10 +216,10 @@ fn register_event_mouse_release( if state.down { state.down = false; - if state.hovered { - if let Some(on_click) = &state.on_click { - on_click(common, ButtonClickEvent {})?; - } + if state.hovered + && let Some(on_click) = &state.on_click + { + on_click(common, ButtonClickEvent {})?; } } diff --git a/wgui/src/components/checkbox.rs b/wgui/src/components/checkbox.rs index e094642..f7bf828 100644 --- a/wgui/src/components/checkbox.rs +++ b/wgui/src/components/checkbox.rs @@ -229,10 +229,10 @@ fn register_event_mouse_release( state.checked = !state.checked; set_box_checked(&common.state.widgets, &data, state.checked); - if state.hovered { - if let Some(on_toggle) = &state.on_toggle { - on_toggle(common, CheckboxToggleEvent { checked: state.checked })?; - } + if state.hovered + && let Some(on_toggle) = &state.on_toggle + { + on_toggle(common, CheckboxToggleEvent { checked: state.checked })?; } } diff --git a/wgui/src/event.rs b/wgui/src/event.rs index ea99de9..c7ba4ca 100644 --- a/wgui/src/event.rs +++ b/wgui/src/event.rs @@ -129,7 +129,7 @@ pub struct CallbackDataCommon<'a> { } impl CallbackDataCommon<'_> { - pub fn i18n(&self) -> RefMut { + pub fn i18n(&self) -> RefMut<'_, I18n> { self.state.globals.i18n() } diff --git a/wgui/src/globals.rs b/wgui/src/globals.rs index dee5980..86b8c2d 100644 --- a/wgui/src/globals.rs +++ b/wgui/src/globals.rs @@ -33,15 +33,15 @@ impl WguiGlobals { Ok(Self(Rc::new(RefCell::new(Globals { assets, i18n, defaults })))) } - pub fn get(&self) -> RefMut { + pub fn get(&self) -> RefMut<'_, Globals> { self.0.borrow_mut() } - pub fn i18n(&self) -> RefMut { + pub fn i18n(&self) -> RefMut<'_, I18n> { RefMut::map(self.0.borrow_mut(), |x| &mut x.i18n) } - pub fn assets(&self) -> RefMut> { + pub fn assets(&self) -> RefMut<'_, Box> { RefMut::map(self.0.borrow_mut(), |x| &mut x.assets) } } diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs index b9abc6e..288567f 100644 --- a/wgui/src/layout.rs +++ b/wgui/src/layout.rs @@ -29,11 +29,11 @@ impl Widget { Self(Rc::new(RefCell::new(widget_state))) } - pub fn get_as_mut(&self) -> Option> { + pub fn get_as_mut(&self) -> Option> { RefMut::filter_map(self.0.borrow_mut(), |w| w.obj.get_as_mut::()).ok() } - pub fn state(&self) -> RefMut { + pub fn state(&self) -> RefMut<'_, WidgetState> { self.0.borrow_mut() } } @@ -51,7 +51,7 @@ impl WidgetMap { Self(HopSlotMap::with_key()) } - pub fn get_as(&self, handle: WidgetID) -> Option> { + pub fn get_as(&self, handle: WidgetID) -> Option> { self.0.get(handle)?.get_as_mut::() } diff --git a/wgui/src/lib.rs b/wgui/src/lib.rs index 8e4ad16..57131e0 100644 --- a/wgui/src/lib.rs +++ b/wgui/src/lib.rs @@ -14,7 +14,8 @@ clippy::implicit_hasher, clippy::option_if_let_else, clippy::significant_drop_tightening, - clippy::float_cmp + clippy::float_cmp, + clippy::needless_pass_by_ref_mut )] pub mod animation; diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index 7f1b080..0c774ba 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -208,20 +208,19 @@ pub fn parse_color_hex(html_hex: &str) -> Option { 1., )); } - } else if html_hex.len() == 9 { - if let (Ok(r), Ok(g), Ok(b), Ok(a)) = ( + } else if html_hex.len() == 9 + && let (Ok(r), Ok(g), Ok(b), Ok(a)) = ( u8::from_str_radix(&html_hex[1..3], 16), u8::from_str_radix(&html_hex[3..5], 16), u8::from_str_radix(&html_hex[5..7], 16), u8::from_str_radix(&html_hex[7..9], 16), ) { - return Some(drawing::Color::new( - f32::from(r) / 255., - f32::from(g) / 255., - f32::from(b) / 255., - f32::from(a) / 255., - )); - } + return Some(drawing::Color::new( + f32::from(r) / 255., + f32::from(g) / 255., + f32::from(b) / 255., + f32::from(a) / 255., + )); } log::warn!("failed to parse color \"{html_hex}\""); None @@ -670,32 +669,32 @@ fn parse_child<'a, U1, U2>( } // check for custom attributes (if the callback is set) - if let Some(widget_id) = new_widget_id { - if let Some(on_custom_attribs) = &ctx.doc_params.extra.on_custom_attribs { - let mut pairs = SmallVec::<[CustomAttribPair; 4]>::new(); + if let Some(widget_id) = new_widget_id + && let Some(on_custom_attribs) = &ctx.doc_params.extra.on_custom_attribs + { + let mut pairs = SmallVec::<[CustomAttribPair; 4]>::new(); - for attrib in child_node.attributes() { - let attr_name = attrib.name(); - if !attr_name.starts_with('_') || attr_name.is_empty() { - continue; - } - - let attr_without_prefix = &attr_name[1..]; // safe - - pairs.push(CustomAttribPair { - attrib: attr_without_prefix, - value: attrib.value(), - }); + for attrib in child_node.attributes() { + let attr_name = attrib.name(); + if !attr_name.starts_with('_') || attr_name.is_empty() { + continue; } - if !pairs.is_empty() { - on_custom_attribs(CustomAttribsInfo { - widgets: &ctx.layout.state.widgets, - parent_id, - widget_id, - pairs: &pairs, - }); - } + let attr_without_prefix = &attr_name[1..]; // safe + + pairs.push(CustomAttribPair { + attrib: attr_without_prefix, + value: attrib.value(), + }); + } + + if !pairs.is_empty() { + on_custom_attribs(CustomAttribsInfo { + widgets: &ctx.layout.state.widgets, + parent_id, + widget_id, + pairs: &pairs, + }); } } @@ -752,7 +751,7 @@ impl CustomAttribsInfo<'_> { self.widgets.get(self.widget_id) } - pub fn get_widget_as(&self) -> Option> { + pub fn get_widget_as(&self) -> Option> { self.widgets.get(self.widget_id)?.get_as_mut::() } @@ -797,7 +796,7 @@ pub struct CustomAttribsInfoOwned { impl CustomAttribsInfoOwned { pub fn get_value(&self, attrib_name: &str) -> Option<&str> { // O(n) search, these pairs won't be problematically big anyways - for pair in self.pairs.iter() { + for pair in &self.pairs { if pair.attrib == attrib_name { return Some(pair.value.as_str()); } diff --git a/wgui/src/widget/label.rs b/wgui/src/widget/label.rs index f67ae47..c18092f 100644 --- a/wgui/src/widget/label.rs +++ b/wgui/src/widget/label.rs @@ -10,7 +10,7 @@ use crate::{ globals::Globals, i18n::{I18n, Translation}, layout::WidgetID, - renderer_vk::text::{TextStyle, FONT_SYSTEM}, + renderer_vk::text::{FONT_SYSTEM, TextStyle}, }; use super::{WidgetObj, WidgetState}; @@ -86,7 +86,7 @@ impl WidgetLabel { fn update_attrs(&mut self) { let attrs = Attrs::from(&self.params.style); - for line in self.buffer.borrow_mut().lines.iter_mut() { + for line in &mut self.buffer.borrow_mut().lines { line.set_attrs_list(AttrsList::new(&attrs)); } } diff --git a/wgui/src/widget/mod.rs b/wgui/src/widget/mod.rs index 74a6a78..5ebaf8e 100644 --- a/wgui/src/widget/mod.rs +++ b/wgui/src/widget/mod.rs @@ -331,41 +331,42 @@ impl WidgetState { match &event { Event::MouseDown(e) => { - if hovered && self.data.set_device_pressed(e.device, true) { - if let Some(listeners) = &listeners { - call_event!( - self, - listeners, - widget_id, - node_id, - params, - MousePress, - user_data, - CallbackMetadata::MouseButton(event::MouseButton { - index: e.index, - pos: e.pos - }) - ); - } + if hovered + && self.data.set_device_pressed(e.device, true) + && let Some(listeners) = &listeners + { + call_event!( + self, + listeners, + widget_id, + node_id, + params, + MousePress, + user_data, + CallbackMetadata::MouseButton(event::MouseButton { + index: e.index, + pos: e.pos + }) + ); } } Event::MouseUp(e) => { - if self.data.set_device_pressed(e.device, false) { - if let Some(listeners) = listeners { - call_event!( - self, - listeners, - widget_id, - node_id, - params, - MouseRelease, - user_data, - CallbackMetadata::MouseButton(event::MouseButton { - index: e.index, - pos: e.pos, - }) - ); - } + if self.data.set_device_pressed(e.device, false) + && let Some(listeners) = listeners + { + call_event!( + self, + listeners, + widget_id, + node_id, + params, + MouseRelease, + user_data, + CallbackMetadata::MouseButton(event::MouseButton { + index: e.index, + pos: e.pos, + }) + ); } } Event::MouseMotion(e) => { @@ -416,19 +417,19 @@ impl WidgetState { } } Event::MouseLeave(e) => { - if self.data.set_device_hovered(e.device, false) { - if let Some(listeners) = &listeners { - call_event!( - self, - listeners, - widget_id, - node_id, - params, - MouseLeave, - user_data, - CallbackMetadata::None - ); - } + if self.data.set_device_hovered(e.device, false) + && let Some(listeners) = &listeners + { + call_event!( + self, + listeners, + widget_id, + node_id, + params, + MouseLeave, + user_data, + CallbackMetadata::None + ); } } Event::InternalStateChange(e) => { diff --git a/wlx-capture/src/lib.rs b/wlx-capture/src/lib.rs index 357fe78..26c8162 100644 --- a/wlx-capture/src/lib.rs +++ b/wlx-capture/src/lib.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(clippy::expect_fun_call)] use frame::{DrmFormat, WlxFrame}; diff --git a/wlx-capture/src/pipewire.rs b/wlx-capture/src/pipewire.rs index 1052a46..78a9124 100644 --- a/wlx-capture/src/pipewire.rs +++ b/wlx-capture/src/pipewire.rs @@ -1,13 +1,13 @@ use std::any::Any; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; use std::sync::mpsc; -use std::sync::Arc; use std::thread::JoinHandle; use ashpd::desktop::{ - screencast::{CursorMode, Screencast, SourceType}, PersistMode, + screencast::{CursorMode, Screencast, SourceType}, }; pub use ashpd::Error as AshpdError; @@ -17,35 +17,35 @@ use pw::spa; use pw::properties::properties; use pw::stream::{Stream, StreamFlags}; -use pw::{context::Context, main_loop::MainLoop, Error}; +use pw::{Error, context::Context, main_loop::MainLoop}; use spa::buffer::DataType; use spa::buffer::MetaData; use spa::buffer::MetaType; +use spa::param::ParamType; use spa::param::video::VideoFormat; use spa::param::video::VideoInfoRaw; -use spa::param::ParamType; -use spa::pod::serialize::GenError; use spa::pod::ChoiceValue; use spa::pod::Pod; +use spa::pod::serialize::GenError; use spa::pod::{Object, Property, PropertyFlags, Value}; use spa::utils::Choice; use spa::utils::ChoiceEnum; use spa::utils::ChoiceFlags; +use crate::WlxCapture; +use crate::frame::DRM_FORMAT_ABGR8888; +use crate::frame::DRM_FORMAT_ABGR2101010; +use crate::frame::DRM_FORMAT_ARGB8888; +use crate::frame::DRM_FORMAT_XBGR8888; +use crate::frame::DRM_FORMAT_XBGR2101010; +use crate::frame::DRM_FORMAT_XRGB8888; use crate::frame::DrmFormat; use crate::frame::FourCC; use crate::frame::FrameFormat; use crate::frame::MouseMeta; use crate::frame::Transform; use crate::frame::WlxFrame; -use crate::frame::DRM_FORMAT_ABGR2101010; -use crate::frame::DRM_FORMAT_ABGR8888; -use crate::frame::DRM_FORMAT_ARGB8888; -use crate::frame::DRM_FORMAT_XBGR2101010; -use crate::frame::DRM_FORMAT_XBGR8888; -use crate::frame::DRM_FORMAT_XRGB8888; use crate::frame::{DmabufFrame, FramePlane, MemFdFrame, MemPtrFrame}; -use crate::WlxCapture; pub struct PipewireStream { pub node_id: u32, @@ -76,7 +76,7 @@ pub async fn pipewire_select_screen( log::debug!("Available cursor modes: {cursor_modes:#x}"); - // propery will be same system-wide, so race condition not a concern + // properly will be same system-wide, so race condition not a concern CURSOR_MODES.store(cursor_modes, Ordering::Relaxed); } @@ -369,13 +369,12 @@ where } if let Some(mut buffer) = maybe_buffer { - if let MetaData::Header(header) = buffer.find_meta_data(MetaType::Header) { - if header.flags & spa::sys::SPA_META_HEADER_FLAG_CORRUPTED != 0 { - log::warn!("{}: PipeWire buffer is corrupt.", &name); - return; - } + if let MetaData::Header(header) = buffer.find_meta_data(MetaType::Header) + && header.flags & spa::sys::SPA_META_HEADER_FLAG_CORRUPTED != 0 + { + log::warn!("{}: PipeWire buffer is corrupt.", &name); + return; } - if let MetaData::VideoTransform(transform) = buffer.find_meta_data(MetaType::VideoTransform) { @@ -497,7 +496,7 @@ where .collect(); format_params.push(obj_to_bytes(get_format_params(None)).unwrap()); // safe unwrap: known - // good values + // good values let mut params: Vec<&Pod> = format_params .iter() diff --git a/wlx-capture/src/wayland.rs b/wlx-capture/src/wayland.rs index cb366ba..c1afccf 100644 --- a/wlx-capture/src/wayland.rs +++ b/wlx-capture/src/wayland.rs @@ -19,15 +19,15 @@ use smithay_client_toolkit::reexports::{ pub use wayland_client; use wayland_client::{ + Connection, Dispatch, EventQueue, Proxy, QueueHandle, backend::WaylandError, - globals::{registry_queue_init, GlobalList, GlobalListContents}, + globals::{GlobalList, GlobalListContents, registry_queue_init}, protocol::{ wl_output::{self, Transform, WlOutput}, wl_registry::{self, WlRegistry}, wl_seat::WlSeat, wl_shm::WlShm, }, - Connection, Dispatch, EventQueue, Proxy, QueueHandle, }; use crate::frame; @@ -179,10 +179,10 @@ impl WlxClient { } }, Err(err) => { - if let WaylandError::Io(ref e) = err { - if e.kind() == std::io::ErrorKind::WouldBlock { - return; - } + if let WaylandError::Io(ref e) = err + && e.kind() == std::io::ErrorKind::WouldBlock + { + return; } log::warn!("Error while reading from event queue: {err:?}"); } diff --git a/wlx-capture/src/wlr_dmabuf.rs b/wlx-capture/src/wlr_dmabuf.rs index 8e23836..1725ff7 100644 --- a/wlx-capture/src/wlr_dmabuf.rs +++ b/wlx-capture/src/wlr_dmabuf.rs @@ -10,9 +10,9 @@ use smithay_client_toolkit::reexports::protocols_wlr::export_dmabuf::v1::client: use wayland_client::{Connection, QueueHandle, Dispatch, Proxy}; use crate::{ + WlxCapture, frame::{DmabufFrame, DrmFormat, FramePlane, WlxFrame}, wayland::WlxClient, - WlxCapture, }; use log::{debug, warn}; @@ -84,20 +84,20 @@ where true } fn receive(&mut self) -> Option { - if let Some(data) = self.data.as_ref() { - if let Some(WlxFrame::Dmabuf(last)) = data.receiver.try_iter().last() { - // this is the only protocol that requires us to manually close the FD - while self.fds.len() > 6 * last.num_planes { - // safe unwrap - let _ = unsafe { OwnedFd::from_raw_fd(self.fds.pop_back().unwrap()) }; - } - for p in 0..last.num_planes { - if let Some(fd) = last.planes[p].fd { - self.fds.push_front(fd); - } - } - return (data.receive_callback)(&data.user_data, WlxFrame::Dmabuf(last)); + if let Some(data) = self.data.as_ref() + && let Some(WlxFrame::Dmabuf(last)) = data.receiver.try_iter().last() + { + // this is the only protocol that requires us to manually close the FD + while self.fds.len() > 6 * last.num_planes { + // safe unwrap + let _ = unsafe { OwnedFd::from_raw_fd(self.fds.pop_back().unwrap()) }; } + for p in 0..last.num_planes { + if let Some(fd) = last.planes[p].fd { + self.fds.push_front(fd); + } + } + return (data.receive_callback)(&data.user_data, WlxFrame::Dmabuf(last)); } None } diff --git a/wlx-capture/src/xshm.rs b/wlx-capture/src/xshm.rs index a197e4f..3f0b05f 100644 --- a/wlx-capture/src/xshm.rs +++ b/wlx-capture/src/xshm.rs @@ -3,16 +3,16 @@ use std::{ env, error::Error, sync::{ - mpsc::{self}, Arc, + mpsc::{self}, }, }; use rxscreen::monitor::Monitor; use crate::{ - frame::{DrmFormat, FrameFormat, MemPtrFrame, MouseMeta, WlxFrame, DRM_FORMAT_XRGB8888}, WlxCapture, + frame::{DRM_FORMAT_XRGB8888, DrmFormat, FrameFormat, MemPtrFrame, MouseMeta, WlxFrame}, }; pub struct XshmScreen { @@ -169,10 +169,10 @@ where self.request_new_frame(); } fn request_new_frame(&mut self) { - if let Some(sender) = &self.sender { - if let Err(e) = sender.send(()) { - log::debug!("Failed to send frame request: {}", e); - } + if let Some(sender) = &self.sender + && let Err(e) = sender.send(()) + { + log::debug!("Failed to send frame request: {}", e); } } } diff --git a/wlx-overlay-s/src/backend/common.rs b/wlx-overlay-s/src/backend/common.rs index 646f48f..2af9f92 100644 --- a/wlx-overlay-s/src/backend/common.rs +++ b/wlx-overlay-s/src/backend/common.rs @@ -12,9 +12,9 @@ use crate::{ config::AStrSetExt, overlays::{ anchor::create_anchor, - keyboard::{builder::create_keyboard, KEYBOARD_NAME}, + keyboard::{KEYBOARD_NAME, builder::create_keyboard}, screen::create_screens, - watch::{create_watch, WATCH_NAME}, + watch::{WATCH_NAME, create_watch}, }, state::AppState, }; @@ -57,10 +57,10 @@ where } else { match create_screens(app) { Ok((data, keymap)) => { - if show_screens.is_empty() { - if let Some((_, s, _)) = data.screens.first() { - show_screens.arc_set(s.name.clone()); - } + if show_screens.is_empty() + && let Some((_, s, _)) = data.screens.first() + { + show_screens.arc_set(s.name.clone()); } for (meta, mut state, backend) in data.screens { if show_screens.arc_get(state.name.as_ref()) { diff --git a/wlx-overlay-s/src/backend/input.rs b/wlx-overlay-s/src/backend/input.rs index 25fef65..5f44fc6 100644 --- a/wlx-overlay-s/src/backend/input.rs +++ b/wlx-overlay-s/src/backend/input.rs @@ -115,10 +115,10 @@ impl InputState { session.config.alt_click_up.iter() }; - if let Some(program) = args.next() { - if let Ok(child) = Command::new(program).args(args).spawn() { - self.processes.push(child); - } + if let Some(program) = args.next() + && let Ok(child) = Command::new(program).args(args).spawn() + { + self.processes.push(child); } } } @@ -283,11 +283,11 @@ pub enum PointerMode { } fn update_focus(focus: &mut KeyboardFocus, state: &OverlayState) { - if let Some(f) = &state.keyboard_focus { - if *focus != *f { - log::info!("Setting keyboard focus to {:?}", *f); - *focus = *f; - } + if let Some(f) = &state.keyboard_focus + && *focus != *f + { + log::info!("Setting keyboard focus to {:?}", *f); + *focus = *f; } } @@ -337,32 +337,31 @@ where pointer = &mut app.input_state.pointers[idx]; pointer.interaction.hovered_id = None; } - if !pointer.now.click && pointer.before.click { - if let Some(clicked_id) = pointer.interaction.clicked_id.take() { - if let Some(clicked) = overlays.mut_by_id(clicked_id) { - let hit = PointerHit { - pointer: pointer.idx, - overlay: clicked_id, - mode: pointer.interaction.mode, - ..Default::default() - }; - clicked.backend.on_pointer(app, &hit, false); - } - } + if !pointer.now.click + && pointer.before.click + && let Some(clicked_id) = pointer.interaction.clicked_id.take() + && let Some(clicked) = overlays.mut_by_id(clicked_id) + { + let hit = PointerHit { + pointer: pointer.idx, + overlay: clicked_id, + mode: pointer.interaction.mode, + ..Default::default() + }; + clicked.backend.on_pointer(app, &hit, false); } return (0.0, None); // no hit }; - if let Some(hovered_id) = pointer.interaction.hovered_id { - if hovered_id != hit.overlay { - if let Some(old_hovered) = overlays.mut_by_id(hovered_id) { - if Some(pointer.idx) == old_hovered.primary_pointer { - old_hovered.primary_pointer = None; - } - old_hovered.backend.on_left(app, idx); - pointer = &mut app.input_state.pointers[idx]; - } + if let Some(hovered_id) = pointer.interaction.hovered_id + && hovered_id != hit.overlay + && let Some(old_hovered) = overlays.mut_by_id(hovered_id) + { + if Some(pointer.idx) == old_hovered.primary_pointer { + old_hovered.primary_pointer = None; } + old_hovered.backend.on_left(app, idx); + pointer = &mut app.input_state.pointers[idx]; } let Some(hovered) = overlays.mut_by_id(hit.overlay) else { log::warn!("Hit overlay {} does not exist", hit.overlay.0); @@ -589,17 +588,17 @@ impl Pointer { pointer = &mut app.input_state.pointers[idx]; if save_success { - if let Some(grab_data) = pointer.interaction.grabbed.as_ref() { - if overlay.state.curvature != grab_data.old_curvature { - if let Some(val) = overlay.state.curvature { - app.session - .config - .curve_values - .arc_set(overlay.state.name.clone(), val); - } else { - let ref_name = overlay.state.name.as_ref(); - app.session.config.curve_values.arc_rm(ref_name); - } + if let Some(grab_data) = pointer.interaction.grabbed.as_ref() + && overlay.state.curvature != grab_data.old_curvature + { + if let Some(val) = overlay.state.curvature { + app.session + .config + .curve_values + .arc_set(overlay.state.name.clone(), val); + } else { + let ref_name = overlay.state.name.as_ref(); + app.session.config.curve_values.arc_rm(ref_name); } } app.session.config.transform_values.arc_set( diff --git a/wlx-overlay-s/src/backend/openvr/manifest.rs b/wlx-overlay-s/src/backend/openvr/manifest.rs index b96b6ff..1769dda 100644 --- a/wlx-overlay-s/src/backend/openvr/manifest.rs +++ b/wlx-overlay-s/src/backend/openvr/manifest.rs @@ -21,15 +21,15 @@ pub(super) fn install_manifest(app_mgr: &mut ApplicationsManager) -> anyhow::Res .ok_or_else(|| anyhow::anyhow!("Invalid executable path"))?, }; - if app_mgr.is_application_installed(APP_KEY) == Ok(true) { - if let Ok(mut file) = File::open(&manifest_path) { - let mut buf = String::new(); - if file.read_to_string(&mut buf).is_ok() { - let manifest: json::JsonValue = json::parse(&buf)?; - if manifest["applications"][0]["binary_path_linux"] == executable_path { - log::info!("Manifest already up to date"); - return Ok(()); - } + if app_mgr.is_application_installed(APP_KEY) == Ok(true) + && let Ok(mut file) = File::open(&manifest_path) + { + let mut buf = String::new(); + if file.read_to_string(&mut buf).is_ok() { + let manifest: json::JsonValue = json::parse(&buf)?; + if manifest["applications"][0]["binary_path_linux"] == executable_path { + log::info!("Manifest already up to date"); + return Ok(()); } } } diff --git a/wlx-overlay-s/src/backend/openvr/mod.rs b/wlx-overlay-s/src/backend/openvr/mod.rs index cc01872..5a1adc9 100644 --- a/wlx-overlay-s/src/backend/openvr/mod.rs +++ b/wlx-overlay-s/src/backend/openvr/mod.rs @@ -2,18 +2,18 @@ use std::{ collections::VecDeque, ops::Add, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering}, }, time::{Duration, Instant}, }; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use ovr_overlay::{ - sys::{ETrackedDeviceProperty, EVRApplicationType, EVREventType}, TrackedDeviceIndex, + sys::{ETrackedDeviceProperty, EVRApplicationType, EVREventType}, }; -use vulkano::{device::physical::PhysicalDevice, Handle, VulkanObject}; +use vulkano::{Handle, VulkanObject, device::physical::PhysicalDevice}; use crate::{ backend::{ @@ -21,7 +21,7 @@ use crate::{ input::interact, openvr::{ helpers::adjust_gain, - input::{set_action_manifest, OpenVrInputSource}, + input::{OpenVrInputSource, set_action_manifest}, lines::LinePool, manifest::{install_manifest, uninstall_manifest}, overlay::OpenVrOverlayData, @@ -29,10 +29,10 @@ use crate::{ overlay::{OverlayData, ShouldRender}, task::{SystemTask, TaskType}, }, - graphics::{init_openvr_graphics, CommandBuffers}, + graphics::{CommandBuffers, init_openvr_graphics}, overlays::{ toast::{Toast, ToastTopic}, - watch::{watch_fade, WATCH_NAME}, + watch::{WATCH_NAME, watch_fade}, }, state::AppState, subsystem::notifications::NotificationManager, @@ -229,11 +229,11 @@ pub fn openvr_run( }); } TaskType::DropOverlay(sel) => { - if let Some(o) = overlays.mut_by_selector(&sel) { - if o.state.birthframe < cur_frame { - o.destroy(&mut overlay_mgr); - overlays.remove_by_selector(&sel); - } + if let Some(o) = overlays.mut_by_selector(&sel) + && o.state.birthframe < cur_frame + { + o.destroy(&mut overlay_mgr); + overlays.remove_by_selector(&sel); } } TaskType::System(task) => match task { diff --git a/wlx-overlay-s/src/backend/openxr/blocker.rs b/wlx-overlay-s/src/backend/openxr/blocker.rs index 8631b2d..596241d 100644 --- a/wlx-overlay-s/src/backend/openxr/blocker.rs +++ b/wlx-overlay-s/src/backend/openxr/blocker.rs @@ -61,10 +61,11 @@ fn set_clients_io_active(monado: &mut Monado, active: bool) { } }; - if name != "wlx-overlay-s" && state.contains(ClientState::ClientSessionVisible) { - if let Err(e) = client.set_io_active(active) { - warn!("Failed to set io active for client: {e}"); - } + if name != "wlx-overlay-s" + && state.contains(ClientState::ClientSessionVisible) + && let Err(e) = client.set_io_active(active) + { + warn!("Failed to set io active for client: {e}"); } } } diff --git a/wlx-overlay-s/src/backend/openxr/input.rs b/wlx-overlay-s/src/backend/openxr/input.rs index 947f345..ad27bbc 100644 --- a/wlx-overlay-s/src/backend/openxr/input.rs +++ b/wlx-overlay-s/src/backend/openxr/input.rs @@ -4,7 +4,7 @@ use std::{ time::{Duration, Instant}, }; -use glam::{bool, Affine3A, Quat, Vec3}; +use glam::{Affine3A, Quat, Vec3, bool}; use libmonado as mnd; use openxr::{self as xr, Quaternionf, Vector2f, Vector3f}; use serde::{Deserialize, Serialize}; @@ -15,7 +15,7 @@ use crate::{ state::{AppSession, AppState}, }; -use super::{helpers::posef_to_transform, XrState}; +use super::{XrState, helpers::posef_to_transform}; static CLICK_TIMES: [Duration; 3] = [ Duration::ZERO, @@ -229,21 +229,21 @@ impl OpenXrInputSource { role: TrackedDeviceRole, app: &mut AppState, ) { - if let Ok(status) = device.battery_status() { - if status.present { - app.input_state.devices.push(TrackedDevice { - soc: Some(status.charge), - charging: status.charging, - role, - }); - log::debug!( - "Device {} role {:#?}: {:.0}% (charging {})", - device.index, - role, - status.charge * 100.0f32, - status.charging - ); - } + if let Ok(status) = device.battery_status() + && status.present + { + app.input_state.devices.push(TrackedDevice { + soc: Some(status.charge), + charging: status.charging, + role, + }); + log::debug!( + "Device {} role {:#?}: {:.0}% (charging {})", + device.index, + role, + status.charge * 100.0f32, + status.charging + ); } } @@ -268,11 +268,11 @@ impl OpenXrInputSource { let mut seen = Vec::::with_capacity(32); for (mnd_role, wlx_role) in roles { let device = monado.device_from_role(mnd_role); - if let Ok(mut device) = device { - if !seen.contains(&device.index) { - seen.push(device.index); - Self::update_device_battery_status(&mut device, wlx_role, app); - } + if let Ok(mut device) = device + && !seen.contains(&device.index) + { + seen.push(device.index); + Self::update_device_battery_status(&mut device, wlx_role, app); } } if let Ok(devices) = monado.devices() { diff --git a/wlx-overlay-s/src/backend/openxr/mod.rs b/wlx-overlay-s/src/backend/openxr/mod.rs index 8b67bab..0a65289 100644 --- a/wlx-overlay-s/src/backend/openxr/mod.rs +++ b/wlx-overlay-s/src/backend/openxr/mod.rs @@ -2,8 +2,8 @@ use std::{ collections::VecDeque, ops::Add, sync::{ - atomic::{AtomicBool, AtomicUsize, Ordering}, Arc, + atomic::{AtomicBool, AtomicUsize, Ordering}, }, time::{Duration, Instant}, }; @@ -23,10 +23,10 @@ use crate::{ overlay::{OverlayData, ShouldRender}, task::{SystemTask, TaskType}, }, - graphics::{init_openxr_graphics, CommandBuffers}, + graphics::{CommandBuffers, init_openxr_graphics}, overlays::{ toast::{Toast, ToastTopic}, - watch::{watch_fade, WATCH_NAME}, + watch::{WATCH_NAME, watch_fade}, }, state::AppState, subsystem::notifications::NotificationManager, @@ -228,11 +228,11 @@ pub fn openxr_run( } } - if next_device_update <= Instant::now() { - if let Some(monado) = &mut monado { - OpenXrInputSource::update_devices(&mut app, monado); - next_device_update = Instant::now() + Duration::from_secs(30); - } + if next_device_update <= Instant::now() + && let Some(monado) = &mut monado + { + OpenXrInputSource::update_devices(&mut app, monado); + next_device_update = Instant::now() + Duration::from_secs(30); } if !session_running { @@ -375,10 +375,8 @@ pub fn openxr_run( // Begin rendering let mut buffers = CommandBuffers::default(); - if !main_session_visible { - if let Some(skybox) = skybox.as_mut() { - skybox.render(&xr_state, &app, &mut buffers)?; - } + if !main_session_visible && let Some(skybox) = skybox.as_mut() { + skybox.render(&xr_state, &app, &mut buffers)?; } for o in overlays.iter_mut() { @@ -427,11 +425,9 @@ pub fn openxr_run( // Layer composition let mut layers = vec![]; - if !main_session_visible { - if let Some(skybox) = skybox.as_mut() { - for (idx, layer) in skybox.present(&xr_state, &app)?.into_iter().enumerate() { - layers.push(((idx as f32).mul_add(-50.0, 200.0), layer)); - } + if !main_session_visible && let Some(skybox) = skybox.as_mut() { + for (idx, layer) in skybox.present(&xr_state, &app)?.into_iter().enumerate() { + layers.push(((idx as f32).mul_add(-50.0, 200.0), layer)); } } @@ -514,13 +510,13 @@ pub fn openxr_run( }); } TaskType::DropOverlay(sel) => { - if let Some(o) = overlays.mut_by_selector(&sel) { - if o.state.birthframe < cur_frame { - log::debug!("{}: destroy", o.state.name); - if let Some(o) = overlays.remove_by_selector(&sel) { - // set for deletion after all images are done showing - delete_queue.push((o, cur_frame + 5)); - } + if let Some(o) = overlays.mut_by_selector(&sel) + && o.state.birthframe < cur_frame + { + log::debug!("{}: destroy", o.state.name); + if let Some(o) = overlays.remove_by_selector(&sel) { + // set for deletion after all images are done showing + delete_queue.push((o, cur_frame + 5)); } } } diff --git a/wlx-overlay-s/src/backend/openxr/swapchain.rs b/wlx-overlay-s/src/backend/openxr/swapchain.rs index 0b59819..3e11ba9 100644 --- a/wlx-overlay-s/src/backend/openxr/swapchain.rs +++ b/wlx-overlay-s/src/backend/openxr/swapchain.rs @@ -5,8 +5,8 @@ use openxr as xr; use smallvec::SmallVec; use vulkano::{ - image::{sys::RawImage, view::ImageView, ImageCreateInfo, ImageUsage}, Handle, + image::{ImageCreateInfo, ImageUsage, sys::RawImage, view::ImageView}, }; use wgui::gfx::WGfx; @@ -109,7 +109,7 @@ impl WlxSwapchain { Ok(()) } - pub(super) fn get_subimage(&self) -> xr::SwapchainSubImage { + pub(super) fn get_subimage(&self) -> xr::SwapchainSubImage<'_, xr::Vulkan> { debug_assert!(self.ever_acquired, "swapchain was never acquired!"); xr::SwapchainSubImage::new() .swapchain(&self.swapchain) diff --git a/wlx-overlay-s/src/backend/overlay.rs b/wlx-overlay-s/src/backend/overlay.rs index f099a29..c7ed994 100644 --- a/wlx-overlay-s/src/backend/overlay.rs +++ b/wlx-overlay-s/src/backend/overlay.rs @@ -247,18 +247,17 @@ where self.state.positioning, Positioning::Floating | Positioning::Anchored ) { - let hard_reset; - if let Some(transform) = app + let hard_reset = if let Some(transform) = app .session .config .transform_values .arc_get(self.state.name.as_ref()) { self.state.saved_transform = Some(*transform); - hard_reset = false; + false } else { - hard_reset = true; - } + true + }; self.state.reset(app, hard_reset); } self.backend.init(app) diff --git a/wlx-overlay-s/src/backend/wayvr/client.rs b/wlx-overlay-s/src/backend/wayvr/client.rs index 1ebeb83..d21079d 100644 --- a/wlx-overlay-s/src/backend/wayvr/client.rs +++ b/wlx-overlay-s/src/backend/wayvr/client.rs @@ -10,8 +10,9 @@ use smithay::{ use crate::backend::wayvr::{ExternalProcessRequest, WayVRTask}; use super::{ + ProcessWayVREnv, comp::{self, ClientState}, - display, process, ProcessWayVREnv, + display, process, }; pub struct WayVRClient { @@ -118,20 +119,20 @@ impl WayVRCompositor { // Find suitable auth key from the process list for p in processes.vec.iter().flatten() { - if let process::Process::Managed(process) = &p.obj { - if let Some(auth_key) = &process_env.display_auth { - // Find process with matching auth key - if process.auth_key.as_str() == auth_key { - // Check if display handle is valid - if displays.get(&process.display_handle).is_some() { - // Add client - self.add_client(WayVRClient { - client, - display_handle: process.display_handle, - pid: creds.pid as u32, - }); - return Ok(()); - } + if let process::Process::Managed(process) = &p.obj + && let Some(auth_key) = &process_env.display_auth + { + // Find process with matching auth key + if process.auth_key.as_str() == auth_key { + // Check if display handle is valid + if displays.get(&process.display_handle).is_some() { + // Add client + self.add_client(WayVRClient { + client, + display_handle: process.display_handle, + pid: creds.pid as u32, + }); + return Ok(()); } } } @@ -160,10 +161,10 @@ impl WayVRCompositor { displays: &mut display::DisplayVec, processes: &mut process::ProcessVec, ) -> anyhow::Result<()> { - if let Some(stream) = self.listener.accept()? { - if let Err(e) = self.accept_connection(stream, displays, processes) { - log::error!("Failed to accept connection: {e}"); - } + if let Some(stream) = self.listener.accept()? + && let Err(e) = self.accept_connection(stream, displays, processes) + { + log::error!("Failed to accept connection: {e}"); } Ok(()) diff --git a/wlx-overlay-s/src/backend/wayvr/display.rs b/wlx-overlay-s/src/backend/wayvr/display.rs index 8deffae..29777f2 100644 --- a/wlx-overlay-s/src/backend/wayvr/display.rs +++ b/wlx-overlay-s/src/backend/wayvr/display.rs @@ -2,13 +2,13 @@ use std::{cell::RefCell, rc::Rc, sync::Arc}; use smithay::{ backend::renderer::{ - element::{ - surface::{render_elements_from_surface_tree, WaylandSurfaceRenderElement}, - Kind, - }, - gles::{ffi, GlesRenderer, GlesTexture}, - utils::draw_render_elements, Bind, Color32F, Frame, Renderer, + element::{ + Kind, + surface::{WaylandSurfaceRenderElement, render_elements_from_surface_tree}, + }, + gles::{GlesRenderer, GlesTexture, ffi}, + utils::draw_render_elements, }, input, utils::{Logical, Point, Rectangle, Size, Transform}, @@ -22,8 +22,8 @@ use crate::{ }; use super::{ - client::WayVRCompositor, comp::send_frames_surface_tree, egl_data, event_queue::SyncEventQueue, - process, smithay_wrapper, time, window, BlitMethod, WayVRSignal, + BlitMethod, WayVRSignal, client::WayVRCompositor, comp::send_frames_surface_tree, egl_data, + event_queue::SyncEventQueue, process, smithay_wrapper, time, window, }; fn generate_auth_key() -> String { @@ -136,7 +136,9 @@ impl Display { BlitMethod::Dmabuf => match params.egl_data.create_dmabuf_data(&egl_image) { Ok(dmabuf_data) => egl_data::RenderData::Dmabuf(dmabuf_data), Err(e) => { - log::error!("create_dmabuf_data failed: {e:?}. Using software blitting (This will be slow!)"); + log::error!( + "create_dmabuf_data failed: {e:?}. Using software blitting (This will be slow!)" + ); egl_data::RenderData::Software(None) } }, @@ -271,13 +273,12 @@ impl Display { if self.visible { if !self.displayed_windows.is_empty() { self.no_windows_since = None; - } else if let Some(auto_hide_delay) = config.auto_hide_delay { - if let Some(s) = self.no_windows_since { - if s + u64::from(auto_hide_delay) < get_millis() { - // Auto-hide after specific time - signals.send(WayVRSignal::DisplayVisibility(*handle, false)); - } - } + } else if let Some(auto_hide_delay) = config.auto_hide_delay + && let Some(s) = self.no_windows_since + && s + u64::from(auto_hide_delay) < get_millis() + { + // Auto-hide after specific time + signals.send(WayVRSignal::DisplayVisibility(*handle, false)); } } @@ -577,10 +578,10 @@ impl Display { Ok(child) => Ok(SpawnProcessResult { auth_key, child }), Err(e) => { anyhow::bail!( - "Failed to launch process with path \"{}\": {}. Make sure your exec path exists.", - exec_path, - e - ); + "Failed to launch process with path \"{}\": {}. Make sure your exec path exists.", + exec_path, + e + ); } } } diff --git a/wlx-overlay-s/src/backend/wayvr/mod.rs b/wlx-overlay-s/src/backend/wayvr/mod.rs index 051eff6..25ceb3f 100644 --- a/wlx-overlay-s/src/backend/wayvr/mod.rs +++ b/wlx-overlay-s/src/backend/wayvr/mod.rs @@ -436,7 +436,7 @@ impl WayVR { .manager .tick_wayland(&mut self.state.displays, &mut self.state.processes)?; - if self.state.ticks % 200 == 0 { + if self.state.ticks.is_multiple_of(200) { self.state.manager.cleanup_clients(); } @@ -460,10 +460,10 @@ impl WayVR { #[allow(dead_code)] pub fn get_primary_display(displays: &DisplayVec) -> Option { for (idx, cell) in displays.vec.iter().enumerate() { - if let Some(cell) = cell { - if cell.obj.primary { - return Some(DisplayVec::get_handle(cell, idx)); - } + if let Some(cell) = cell + && cell.obj.primary + { + return Some(DisplayVec::get_handle(cell, idx)); } } None @@ -474,10 +474,10 @@ impl WayVR { name: &str, ) -> Option { for (idx, cell) in displays.vec.iter().enumerate() { - if let Some(cell) = cell { - if cell.obj.name == name { - return Some(DisplayVec::get_handle(cell, idx)); - } + if let Some(cell) = cell + && cell.obj.name == name + { + return Some(DisplayVec::get_handle(cell, idx)); } } None @@ -519,10 +519,10 @@ impl WayVRState { let changed = self.cur_modifiers ^ modifiers; for i in 0..8 { let m = 1 << i; - if changed & m != 0 { - if let Some(vk) = MODS_TO_KEYS.get(m).into_iter().flatten().next() { - self.send_key(*vk as u32, modifiers & m != 0); - } + if changed & m != 0 + && let Some(vk) = MODS_TO_KEYS.get(m).into_iter().flatten().next() + { + self.send_key(*vk as u32, modifiers & m != 0); } } self.cur_modifiers = modifiers; @@ -652,16 +652,16 @@ impl WayVRState { _env: &[(&str, &str)], ) -> Option { for (idx, cell) in self.processes.vec.iter().enumerate() { - if let Some(cell) = &cell { - if let process::Process::Managed(process) = &cell.obj { - if process.display_handle != display_handle - || process.exec_path != exec_path - || process.args != args - { - continue; - } - return Some(process::ProcessVec::get_handle(cell, idx)); + if let Some(cell) = &cell + && let process::Process::Managed(process) = &cell.obj + { + if process.display_handle != display_handle + || process.exec_path != exec_path + || process.args != args + { + continue; } + return Some(process::ProcessVec::get_handle(cell, idx)); } } diff --git a/wlx-overlay-s/src/backend/wayvr/process.rs b/wlx-overlay-s/src/backend/wayvr/process.rs index f0392da..1d5dded 100644 --- a/wlx-overlay-s/src/backend/wayvr/process.rs +++ b/wlx-overlay-s/src/backend/wayvr/process.rs @@ -97,10 +97,10 @@ fn get_process_env_value(pid: i32, key: &str) -> anyhow::Result> let lines: Vec<&str> = env_data.split('\0').filter(|s| !s.is_empty()).collect(); for line in lines { - if let Some(cell) = line.split_once('=') { - if cell.0 == key { - return Ok(Some(String::from(cell.1))); - } + if let Some(cell) = line.split_once('=') + && cell.0 == key + { + return Ok(Some(String::from(cell.1))); } } @@ -199,10 +199,10 @@ pub fn find_by_pid(processes: &ProcessVec, pid: u32) -> Option { let Some(cell) = cell else { continue; }; - if let Process::Managed(wayvr_process) = &cell.obj { - if wayvr_process.auth_key == value { - return Some(ProcessVec::get_handle(cell, idx)); - } + if let Process::Managed(wayvr_process) = &cell.obj + && wayvr_process.auth_key == value + { + return Some(ProcessVec::get_handle(cell, idx)); } } } diff --git a/wlx-overlay-s/src/backend/wayvr/server_ipc.rs b/wlx-overlay-s/src/backend/wayvr/server_ipc.rs index e5e28aa..e4b69df 100644 --- a/wlx-overlay-s/src/backend/wayvr/server_ipc.rs +++ b/wlx-overlay-s/src/backend/wayvr/server_ipc.rs @@ -329,9 +329,7 @@ impl Connection { handle: packet_server::WvrWindowHandle, visible: bool, ) { - let mut to_resize = None; - - if let Some(window) = params + let to_resize = if let Some(window) = params .state .wm .borrow_mut() @@ -339,14 +337,16 @@ impl Connection { .get_mut(&window::WindowHandle::from_packet(handle)) { window.visible = visible; - to_resize = Some(window.display_handle); - } + Some(window.display_handle) + } else { + None + }; - if let Some(to_resize) = to_resize { - if let Some(display) = params.state.displays.get_mut(&to_resize) { - display.reposition_windows(); - display.trigger_rerender(); - } + if let Some(to_resize) = to_resize + && let Some(display) = params.state.displays.get_mut(&to_resize) + { + display.reposition_windows(); + display.trigger_rerender(); } } diff --git a/wlx-overlay-s/src/config_wayvr.rs b/wlx-overlay-s/src/config_wayvr.rs index a113375..c92741f 100644 --- a/wlx-overlay-s/src/config_wayvr.rs +++ b/wlx-overlay-s/src/config_wayvr.rs @@ -18,7 +18,7 @@ use crate::{ }, config::load_config_with_conf_d, config_io, - overlays::wayvr::{executable_exists_in_path, WayVRData}, + overlays::wayvr::{WayVRData, executable_exists_in_path}, }; // Flat version of RelativeTo @@ -211,13 +211,13 @@ impl WayVRConfig { for (catalog_name, catalog) in &self.catalogs { for app in &catalog.apps { - if let Some(b) = app.shown_at_start { - if b { - tasks.enqueue(TaskType::WayVR(WayVRAction::AppClick { - catalog_name: Arc::from(catalog_name.as_str()), - app_name: Arc::from(app.name.as_str()), - })); - } + if let Some(b) = app.shown_at_start + && b + { + tasks.enqueue(TaskType::WayVR(WayVRAction::AppClick { + catalog_name: Arc::from(catalog_name.as_str()), + app_name: Arc::from(app.name.as_str()), + })); } } } diff --git a/wlx-overlay-s/src/gui/panel/button.rs b/wlx-overlay-s/src/gui/panel/button.rs index aa0b893..6e9a2ae 100644 --- a/wlx-overlay-s/src/gui/panel/button.rs +++ b/wlx-overlay-s/src/gui/panel/button.rs @@ -11,7 +11,7 @@ use wgui::{ use crate::{ backend::{common::OverlaySelector, overlay::OverlayID, task::TaskType, wayvr::WayVRAction}, - config::{save_layout, AStrSetExt}, + config::{AStrSetExt, save_layout}, state::AppState, }; @@ -21,14 +21,14 @@ pub(super) fn setup_custom_button( attribs: &CustomAttribsInfoOwned, listeners: &mut EventListenerCollection, listener_handles: &mut ListenerHandleVec, - app: &AppState, + _app: &AppState, ) { const EVENTS: [(&str, EventListenerKind); 2] = [ ("press", EventListenerKind::MousePress), ("release", EventListenerKind::MouseRelease), ]; - for (name, kind) in EVENTS.iter() { + for (name, kind) in &EVENTS { let Some(action) = attribs.get_value(name) else { continue; }; @@ -47,14 +47,14 @@ pub(super) fn setup_custom_button( }), "::OverlayToggle" => { let Some(selector) = args.next() else { - log::warn!("Missing argument for {}", command); + log::warn!("Missing argument for {command}"); continue; }; - let selector = selector - .parse::() - .map(|id| OverlaySelector::Id(OverlayID { 0: id })) - .unwrap_or_else(|_| OverlaySelector::Name(selector.into())); + let selector = selector.parse::().map_or_else( + |_| OverlaySelector::Name(selector.into()), + |id| OverlaySelector::Id(OverlayID(id)), + ); Box::new(move |_common, _data, app, _| { app.tasks.enqueue(TaskType::Overlay( @@ -90,7 +90,11 @@ pub(super) fn setup_custom_button( } "::WatchHide" => todo!(), "::WatchSwapHand" => todo!(), + // TODO + #[allow(clippy::match_same_arms)] "::EditToggle" => return, + // TODO + #[allow(clippy::match_same_arms)] "::OscSend" => return, // shell _ => todo!(), @@ -110,18 +114,20 @@ struct ShellButtonState { carry_over: RefCell>, } +// TODO +#[allow(clippy::missing_const_for_fn)] fn shell_on_action( - state: &ShellButtonState, - common: &mut event::CallbackDataCommon, - data: &mut event::CallbackData, + _state: &ShellButtonState, + _common: &mut event::CallbackDataCommon, + _data: &mut event::CallbackData, ) { - let mut mut_state = state.mut_state.borrow_mut(); + //let mut mut_state = state.mut_state.borrow_mut(); } fn shell_on_tick( state: &ShellButtonState, - common: &mut event::CallbackDataCommon, - data: &mut event::CallbackData, + _common: &mut event::CallbackDataCommon, + _data: &mut event::CallbackData, ) { let mut mut_state = state.mut_state.borrow_mut(); @@ -129,8 +135,8 @@ fn shell_on_tick( match child.try_wait() { // not exited yet Ok(None) => { - if let Some(text) = mut_state.reader.as_mut().and_then(|r| { - read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut()) + if let Some(_text) = mut_state.reader.as_mut().and_then(|r| { + read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut()) }) { //TODO update label } @@ -138,8 +144,8 @@ fn shell_on_tick( } // exited successfully Ok(Some(code)) if code.success() => { - if let Some(text) = mut_state.reader.as_mut().and_then(|r| { - read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut()) + if let Some(_text) = mut_state.reader.as_mut().and_then(|r| { + read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut()) }) { //TODO update label } @@ -148,7 +154,7 @@ fn shell_on_tick( // exited with failure Ok(Some(code)) => { mut_state.child = None; - log::warn!("Label process exited with code {}", code); + log::warn!("Label process exited with code {code}"); } // lost Err(_) => { diff --git a/wlx-overlay-s/src/gui/panel/helper.rs b/wlx-overlay-s/src/gui/panel/helper.rs index f348ee1..f7c9390 100644 --- a/wlx-overlay-s/src/gui/panel/helper.rs +++ b/wlx-overlay-s/src/gui/panel/helper.rs @@ -11,7 +11,7 @@ static ENV_VAR_REGEX: LazyLock = LazyLock::new(|| { pub(super) fn expand_env_vars(template: &str) -> String { ENV_VAR_REGEX .replace_all(template, |caps: ®ex::Captures| { - let var_name = caps.get(1).or(caps.get(2)).unwrap().as_str(); + let var_name = caps.get(1).or_else(|| caps.get(2)).unwrap().as_str(); std::env::var(var_name) .inspect_err(|e| log::warn!("Unable to substitute env var {var_name}: {e:?}")) .unwrap_or_default() @@ -45,9 +45,5 @@ where carry_over.replace(cur); - if prev.len() > 0 { - Some(prev) - } else { - None - } + if prev.is_empty() { None } else { Some(prev) } } diff --git a/wlx-overlay-s/src/gui/panel/label.rs b/wlx-overlay-s/src/gui/panel/label.rs index d516a46..846b555 100644 --- a/wlx-overlay-s/src/gui/panel/label.rs +++ b/wlx-overlay-s/src/gui/panel/label.rs @@ -15,7 +15,7 @@ use wgui::{ event::{self, EventCallback, EventListenerCollection, ListenerHandleVec}, i18n::Translation, layout::Layout, - parser::{parse_color_hex, CustomAttribsInfoOwned}, + parser::{CustomAttribsInfoOwned, parse_color_hex}, widget::label::WidgetLabel, }; @@ -23,6 +23,7 @@ use crate::state::AppState; use super::helper::{expand_env_vars, read_label_from_pipe}; +#[allow(clippy::too_many_lines)] pub(super) fn setup_custom_label( layout: &mut Layout, attribs: &CustomAttribsInfoOwned, @@ -85,15 +86,15 @@ pub(super) fn setup_custom_label( let state = BatteryLabelState { low_color: attribs .get_value("low_color") - .and_then(|s| parse_color_hex(s)) + .and_then(parse_color_hex) .unwrap_or(BAT_LOW), normal_color: attribs .get_value("normal_color") - .and_then(|s| parse_color_hex(s)) + .and_then(parse_color_hex) .unwrap_or(BAT_NORMAL), charging_color: attribs .get_value("charging_color") - .and_then(|s| parse_color_hex(s)) + .and_then(parse_color_hex) .unwrap_or(BAT_CHARGING), low_threshold: attribs .get_value("low_threshold") @@ -122,10 +123,7 @@ pub(super) fn setup_custom_label( tz_name.split('/').next_back().map(|x| x.replace('_', " ")) }); - let pretty_tz = match maybe_pretty_tz.as_ref() { - Some(x) => x.as_str(), - None => "Local", - }; + let pretty_tz = maybe_pretty_tz.as_ref().map_or("Local", |x| x.as_str()); let mut i18n = layout.state.globals.i18n(); layout @@ -133,7 +131,7 @@ pub(super) fn setup_custom_label( .widgets .get_as::(attribs.widget_id) .unwrap() - .set_text_simple(&mut *i18n, Translation::from_raw_text(&pretty_tz)); + .set_text_simple(&mut i18n, Translation::from_raw_text(pretty_tz)); // does not need to be dynamic return; @@ -202,6 +200,7 @@ struct ShellLabelState { carry_over: RefCell>, } +#[allow(clippy::redundant_else)] fn shell_on_tick( state: &ShellLabelState, common: &mut event::CallbackDataCommon, @@ -214,7 +213,7 @@ fn shell_on_tick( // not exited yet Ok(None) => { if let Some(text) = mut_state.reader.as_mut().and_then(|r| { - read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut()) + read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut()) }) { let label = data.obj.get_as_mut::().unwrap(); label.set_text(common, Translation::from_raw_text(&text)); @@ -225,7 +224,7 @@ fn shell_on_tick( // exited successfully Ok(Some(code)) if code.success() => { if let Some(text) = mut_state.reader.as_mut().and_then(|r| { - read_label_from_pipe("child process", r, &mut *state.carry_over.borrow_mut()) + read_label_from_pipe("child process", r, &mut state.carry_over.borrow_mut()) }) { let label = data.obj.get_as_mut::().unwrap(); label.set_text(common, Translation::from_raw_text(&text)); @@ -237,7 +236,7 @@ fn shell_on_tick( Ok(Some(code)) => { mut_state.child = None; mut_state.next_try = Instant::now() + Duration::from_secs(15); - log::warn!("Label process exited with code {}", code); + log::warn!("Label process exited with code {code}"); return; } // lost @@ -248,10 +247,8 @@ fn shell_on_tick( return; } } - } else { - if mut_state.next_try > Instant::now() { - return; - } + } else if mut_state.next_try > Instant::now() { + return; } match Command::new("sh") @@ -266,7 +263,7 @@ fn shell_on_tick( mut_state.reader = Some(io::BufReader::new(stdout)); } Err(e) => { - log::warn!("Failed to run shell script '{}': {e:?}", &state.exec) + log::warn!("Failed to run shell script '{}': {e:?}", &state.exec); } } } @@ -300,7 +297,7 @@ impl FifoLabelState { if let Err(e) = fs::remove_file(&self.path) { anyhow::bail!("Unable to remove existing FIFO at {}: {e:?}", &self.path); - }; + } Ok(()) } @@ -321,39 +318,38 @@ fn pipe_on_tick( ) { let mut mut_state = state.mut_state.borrow_mut(); - let reader = match mut_state.reader.as_mut() { - Some(f) => f, - None => { - if mut_state.next_try > Instant::now() { - return; - } - - if let Err(e) = state.try_remove_fifo() { - mut_state.next_try = Instant::now() + Duration::from_secs(15); - log::warn!("Requested FIFO path is taken: {e:?}"); - return; - } - - if let Err(e) = create_fifo(&state.path, 0o777) { - mut_state.next_try = Instant::now() + Duration::from_secs(15); - log::warn!("Failed to create FIFO: {e:?}"); - return; - } - - mut_state.reader = fs::File::open(&state.path) - .inspect_err(|e| { - log::warn!("Failed to open FIFO: {e:?}"); - mut_state.next_try = Instant::now() + Duration::from_secs(15); - }) - .map(|f| io::BufReader::new(f)) - .ok(); - - mut_state.reader.as_mut().unwrap() + let reader = if let Some(f) = mut_state.reader.as_mut() { + f + } else { + if mut_state.next_try > Instant::now() { + return; } + + if let Err(e) = state.try_remove_fifo() { + mut_state.next_try = Instant::now() + Duration::from_secs(15); + log::warn!("Requested FIFO path is taken: {e:?}"); + return; + } + + if let Err(e) = create_fifo(&state.path, 0o777) { + mut_state.next_try = Instant::now() + Duration::from_secs(15); + log::warn!("Failed to create FIFO: {e:?}"); + return; + } + + mut_state.reader = fs::File::open(&state.path) + .inspect_err(|e| { + log::warn!("Failed to open FIFO: {e:?}"); + mut_state.next_try = Instant::now() + Duration::from_secs(15); + }) + .map(io::BufReader::new) + .ok(); + + mut_state.reader.as_mut().unwrap() }; if let Some(text) = - read_label_from_pipe(&state.path, reader, &mut *state.carry_over.borrow_mut()) + read_label_from_pipe(&state.path, reader, &mut state.carry_over.borrow_mut()) { let label = data.obj.get_as_mut::().unwrap(); label.set_text(common, Translation::from_raw_text(&text)); @@ -385,21 +381,21 @@ fn battery_on_tick( let label = data.obj.get_as_mut::().unwrap(); - if let Some(device) = device { - if let Some(soc) = device.soc { - let soc = (soc * 100.).min(99.) as u32; - let text = format!("{}{}", tags[device.role as usize], soc); - let color = if device.charging { - state.charging_color - } else if soc < state.low_threshold { - state.low_color - } else { - state.normal_color - }; - label.set_color(common, color, false); - label.set_text(common, Translation::from_raw_text(&text)); - return; - } + if let Some(device) = device + && let Some(soc) = device.soc + { + let soc = (soc * 100.).min(99.) as u32; + let text = format!("{}{}", tags[device.role as usize], soc); + let color = if device.charging { + state.charging_color + } else if soc < state.low_threshold { + state.low_color + } else { + state.normal_color + }; + label.set_color(common, color, false); + label.set_text(common, Translation::from_raw_text(&text)); + return; } label.set_text(common, Translation::default()); } diff --git a/wlx-overlay-s/src/main.rs b/wlx-overlay-s/src/main.rs index 4248973..8355c92 100644 --- a/wlx-overlay-s/src/main.rs +++ b/wlx-overlay-s/src/main.rs @@ -269,20 +269,20 @@ fn ensure_single_instance(replace: bool) -> bool { if path.exists() { // load contents - if let Ok(pid_str) = std::fs::read_to_string(&path) { - if let Ok(pid) = pid_str.trim().parse::() { - let mut system = sysinfo::System::new(); - system.refresh_processes( - sysinfo::ProcessesToUpdate::Some(&[Pid::from_u32(pid)]), - false, - ); - if let Some(proc) = system.process(sysinfo::Pid::from_u32(pid)) { - if replace { - proc.kill_with(sysinfo::Signal::Term); - proc.wait(); - } else { - return false; - } + if let Ok(pid_str) = std::fs::read_to_string(&path) + && let Ok(pid) = pid_str.trim().parse::() + { + let mut system = sysinfo::System::new(); + system.refresh_processes( + sysinfo::ProcessesToUpdate::Some(&[Pid::from_u32(pid)]), + false, + ); + if let Some(proc) = system.process(sysinfo::Pid::from_u32(pid)) { + if replace { + proc.kill_with(sysinfo::Signal::Term); + proc.wait(); + } else { + return false; } } } diff --git a/wlx-overlay-s/src/overlays/keyboard/mod.rs b/wlx-overlay-s/src/overlays/keyboard/mod.rs index 5393a28..908edf1 100644 --- a/wlx-overlay-s/src/overlays/keyboard/mod.rs +++ b/wlx-overlay-s/src/overlays/keyboard/mod.rs @@ -204,10 +204,10 @@ fn handle_release(app: &mut AppState, key: &KeyState, keyboard: &mut KeyboardSta .processes .retain_mut(|child| !matches!(child.try_wait(), Ok(Some(_)))); - if let Some(program) = release_program { - if let Ok(child) = Command::new(program).args(release_args).spawn() { - keyboard.processes.push(child); - } + if let Some(program) = release_program + && let Ok(child) = Command::new(program).args(release_args).spawn() + { + keyboard.processes.push(child); } true } diff --git a/wlx-overlay-s/src/overlays/screen/pw.rs b/wlx-overlay-s/src/overlays/screen/pw.rs index acca283..34a3d0a 100644 --- a/wlx-overlay-s/src/overlays/screen/pw.rs +++ b/wlx-overlay-s/src/overlays/screen/pw.rs @@ -83,10 +83,10 @@ pub(super) fn select_pw_screen( task::Poll::Pending => { if Instant::now() >= print_at { log::info!("{instructions}"); - if let Ok(sender) = DbusNotificationSender::new() { - if let Ok(id) = sender.notify_send(instructions, "", 2, 0, 0, true) { - notify = Some((sender, id)); - } + if let Ok(sender) = DbusNotificationSender::new() + && let Ok(id) = sender.notify_send(instructions, "", 2, 0, 0, true) + { + notify = Some((sender, id)); } break; } diff --git a/wlx-overlay-s/src/overlays/screen/wl.rs b/wlx-overlay-s/src/overlays/screen/wl.rs index 24b4765..2afe01b 100644 --- a/wlx-overlay-s/src/overlays/screen/wl.rs +++ b/wlx-overlay-s/src/overlays/screen/wl.rs @@ -1,9 +1,9 @@ use glam::vec2; use wlx_capture::{ + WlxCapture, wayland::{WlxClient, WlxOutput}, wlr_dmabuf::WlrDmabufCapture, wlr_screencopy::WlrScreencopyCapture, - WlxCapture, }; use crate::{ @@ -13,10 +13,10 @@ use crate::{ }; use super::{ - backend::ScreenBackend, - capture::{new_wlx_capture, MainThreadWlxCapture}, - pw::{load_pw_token_config, save_pw_token_config}, ScreenCreateData, + backend::ScreenBackend, + capture::{MainThreadWlxCapture, new_wlx_capture}, + pw::{load_pw_token_config, save_pw_token_config}, }; impl ScreenBackend { @@ -76,10 +76,10 @@ pub fn create_screen_renderer_wl( Ok((renderer, restore_token)) => { capture = Some(renderer); - if let Some(token) = restore_token { - if pw_token_store.arc_set(display_name.into(), token.clone()) { - log::info!("Adding Pipewire token {token}"); - } + if let Some(token) = restore_token + && pw_token_store.arc_set(display_name.into(), token.clone()) + { + log::info!("Adding Pipewire token {token}"); } } Err(e) => { diff --git a/wlx-overlay-s/src/overlays/screen/x11.rs b/wlx-overlay-s/src/overlays/screen/x11.rs index d04261e..9c00fe7 100644 --- a/wlx-overlay-s/src/overlays/screen/x11.rs +++ b/wlx-overlay-s/src/overlays/screen/x11.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use glam::vec2; use wlx_capture::{ + WlxCapture, frame::Transform, xshm::{XshmCapture, XshmScreen}, - WlxCapture, }; use crate::{ @@ -13,9 +13,9 @@ use crate::{ }; use super::{ - backend::ScreenBackend, - capture::{new_wlx_capture, MainThreadWlxCapture}, ScreenCreateData, + backend::ScreenBackend, + capture::{MainThreadWlxCapture, new_wlx_capture}, }; #[cfg(feature = "pipewire")] @@ -62,10 +62,10 @@ pub fn create_screens_x11pw(app: &mut AppState) -> anyhow::Result String { let mut state = xkb::State::new(&self.keymap); - if modifier > 0 { - if let Some(mod_key) = MODS_TO_KEYS.get(modifier) { - state.update_key( - xkb::Keycode::from(mod_key[0] as u32), - xkb::KeyDirection::Down, - ); - } + if modifier > 0 + && let Some(mod_key) = MODS_TO_KEYS.get(modifier) + { + state.update_key( + xkb::Keycode::from(mod_key[0] as u32), + xkb::KeyDirection::Down, + ); } state.key_get_utf8(xkb::Keycode::from(key as u32)) } diff --git a/wlx-overlay-s/src/subsystem/hid/wayland.rs b/wlx-overlay-s/src/subsystem/hid/wayland.rs index 5cfe895..c374c01 100644 --- a/wlx-overlay-s/src/subsystem/hid/wayland.rs +++ b/wlx-overlay-s/src/subsystem/hid/wayland.rs @@ -1,11 +1,11 @@ use wlx_capture::wayland::wayland_client::{ - globals::{registry_queue_init, GlobalListContents}, + Connection, Dispatch, Proxy, QueueHandle, + globals::{GlobalListContents, registry_queue_init}, protocol::{ wl_keyboard::{self, WlKeyboard}, wl_registry::WlRegistry, wl_seat::{self, Capability, WlSeat}, }, - Connection, Dispatch, Proxy, QueueHandle, }; use xkbcommon::xkb; @@ -32,7 +32,7 @@ pub fn get_keymap_wl() -> anyhow::Result { let qh = queue.handle(); let seat: WlSeat = globals .bind(&qh, 4..=9, ()) - .expect(WlSeat::interface().name); + .unwrap_or_else(|_| panic!("{}", WlSeat::interface().name)); let mut me = WlKeymapHandler { seat,