From 20743f91eb970fe76f67c3f4844b2205a8e5b1cd Mon Sep 17 00:00:00 2001 From: Aleksander Date: Tue, 12 May 2026 21:59:54 +0200 Subject: [PATCH] clippy --- dash-frontend/src/tab/apps.rs | 11 ------ dash-frontend/src/tab/monado.rs | 12 +++---- dash-frontend/src/tab/settings/mod.rs | 2 +- .../src/util/networking/http_client.rs | 13 ++++--- dash-frontend/src/util/networking/mod.rs | 4 +-- .../src/util/networking/skymap_catalog.rs | 12 ++----- dash-frontend/src/util/popup_manager.rs | 23 +++++------- dash-frontend/src/util/wgui_simple.rs | 6 ++-- dash-frontend/src/views/download_file.rs | 2 +- dash-frontend/src/views/game_launcher.rs | 8 ++--- dash-frontend/src/views/game_list.rs | 4 +-- .../src/views/remote_skymap_downloader.rs | 9 ++--- dash-frontend/src/views/remote_skymap_list.rs | 35 ++++++------------ dash-frontend/src/views/skymap_list.rs | 12 +++---- dash-frontend/src/views/skymap_list_cell.rs | 4 +-- wayvr/src/backend/openxr/playspace.rs | 2 +- wayvr/src/backend/openxr/skybox.rs | 4 +-- wayvr/src/config.rs | 2 +- wayvr/src/gui/panel/mod.rs | 6 ++-- wayvr/src/ipc/ipc_server.rs | 10 +++--- wayvr/src/overlays/dashboard.rs | 2 +- wayvr/src/state.rs | 1 - wayvr/src/subsystem/hid/mod.rs | 15 ++++---- wgui/src/components/color_selector.rs | 17 ++++----- wgui/src/components/slider.rs | 36 +++++++++---------- wgui/src/drawing.rs | 1 + wgui/src/layout.rs | 4 +-- wgui/src/parser/component_slider.rs | 2 +- wgui/src/parser/mod.rs | 6 ++-- wgui/src/widget/mod.rs | 26 ++++++-------- 30 files changed, 126 insertions(+), 165 deletions(-) diff --git a/dash-frontend/src/tab/apps.rs b/dash-frontend/src/tab/apps.rs index cf093f84..a55cf356 100644 --- a/dash-frontend/src/tab/apps.rs +++ b/dash-frontend/src/tab/apps.rs @@ -11,7 +11,6 @@ use wgui::{ globals::WguiGlobals, layout::{WidgetID, WidgetPair}, parser::{Fetchable, ParseDocumentParams, ParserState}, - task::Tasks, }; use wlx_common::desktop_finder::DesktopEntry; @@ -22,9 +21,6 @@ use crate::{ views::{self}, }; -#[derive(Clone)] -enum Task {} - struct State { view_launcher: PopupHolder, } @@ -35,7 +31,6 @@ pub struct TabApps { state: Rc>, app_list: AppList, - tasks: Tasks, marker: PhantomData, } @@ -47,10 +42,6 @@ impl Tab for TabApps { fn update(&mut self, frontend: &mut Frontend, _time_ms: u32, data: &mut T) -> anyhow::Result<()> { let state = self.state.borrow_mut(); - for task in self.tasks.drain() { - match task {} - } - self.app_list.tick(frontend, &self.state, &mut self.parser_state)?; state @@ -96,7 +87,6 @@ fn doc_params(globals: WguiGlobals) -> ParseDocumentParams<'static> { impl TabApps { pub fn new(frontend: &mut Frontend, parent_id: WidgetID, data: &mut T) -> anyhow::Result { let globals = frontend.layout.state.globals.clone(); - let tasks = Tasks::new(); let state = Rc::new(RefCell::new(State { view_launcher: Default::default(), })); @@ -127,7 +117,6 @@ impl TabApps { app_list, parser_state, state, - tasks, marker: PhantomData, }) } diff --git a/dash-frontend/src/tab/monado.rs b/dash-frontend/src/tab/monado.rs index a9c5332e..e850bc58 100644 --- a/dash-frontend/src/tab/monado.rs +++ b/dash-frontend/src/tab/monado.rs @@ -333,12 +333,12 @@ impl SubtabGeneralSettings { } }) } - slider_keying_curve.on_value_changed(get_slider_callback(&tasks)); - slider_keying_despill.on_value_changed(get_slider_callback(&tasks)); - slider_keying_hue_range.on_value_changed(get_slider_callback(&tasks)); - slider_keying_saturation_range.on_value_changed(get_slider_callback(&tasks)); - slider_keying_value_range.on_value_changed(get_slider_callback(&tasks)); - cs_keying.on_changed(get_color_selector_callback(&tasks)); + slider_keying_curve.on_value_changed(get_slider_callback(tasks)); + slider_keying_despill.on_value_changed(get_slider_callback(tasks)); + slider_keying_hue_range.on_value_changed(get_slider_callback(tasks)); + slider_keying_saturation_range.on_value_changed(get_slider_callback(tasks)); + slider_keying_value_range.on_value_changed(get_slider_callback(tasks)); + cs_keying.on_changed(get_color_selector_callback(tasks)); } Ok(Self { diff --git a/dash-frontend/src/tab/settings/mod.rs b/dash-frontend/src/tab/settings/mod.rs index 50930517..d0fdaad7 100644 --- a/dash-frontend/src/tab/settings/mod.rs +++ b/dash-frontend/src/tab/settings/mod.rs @@ -220,7 +220,7 @@ impl Tab for TabSettings { let mut common = frontend.layout.common(); let mut label = self .state - .fetch_widget_as::(&common.state, &format!("{id}_value"))?; + .fetch_widget_as::(common.state, &format!("{id}_value"))?; let translation = Translation { text: text.into(), diff --git a/dash-frontend/src/util/networking/http_client.rs b/dash-frontend/src/util/networking/http_client.rs index 812620c3..8500dc92 100644 --- a/dash-frontend/src/util/networking/http_client.rs +++ b/dash-frontend/src/util/networking/http_client.rs @@ -19,7 +19,7 @@ pub struct HttpClientResponse { } impl HttpClientResponse { - pub fn as_json(self) -> anyhow::Result + pub fn into_json(self) -> anyhow::Result where T: for<'a> serde::Deserialize<'a>, { @@ -66,12 +66,11 @@ pub async fn get(params: GetParams<'_>) -> anyhow::Result { let (parts, body) = resp.into_parts(); // that's a pretty interesting way to get file size :] - if let Some(val) = parts.headers.get("Content-Length") { - if let Ok(str) = val.to_str() { - if let Ok(s) = str.parse() { - file_size = s; - } - } + if let Some(val) = parts.headers.get("Content-Length") + && let Ok(str) = val.to_str() + && let Ok(s) = str.parse() + { + file_size = s; } let mut on_progress = params.on_progress; diff --git a/dash-frontend/src/util/networking/mod.rs b/dash-frontend/src/util/networking/mod.rs index b6c625a8..3c83a713 100644 --- a/dash-frontend/src/util/networking/mod.rs +++ b/dash-frontend/src/util/networking/mod.rs @@ -2,5 +2,5 @@ pub mod http_client; pub mod image_fetch; pub mod skymap_catalog; -// pub const WAYVR_ROOT_URL: &'static str = "https://wayvr.org"; -pub const WAYVR_SKYMAPS_ROOT: &'static str = "https://wayvr.org/skymaps"; +// pub const WAYVR_ROOT_URL: &str = "https://wayvr.org"; +pub const WAYVR_SKYMAPS_ROOT: &str = "https://wayvr.org/skymaps"; diff --git a/dash-frontend/src/util/networking/skymap_catalog.rs b/dash-frontend/src/util/networking/skymap_catalog.rs index d7d21ca2..02af4612 100644 --- a/dash-frontend/src/util/networking/skymap_catalog.rs +++ b/dash-frontend/src/util/networking/skymap_catalog.rs @@ -67,10 +67,7 @@ impl SkymapCatalogEntryFiles { // example result: "https://wayvr.org/skymaps/files/my_skymap_8k.dds" pub fn get_url_from_res(&self, res: SkymapResolution) -> Option { - let Some(filename) = self.get_filename_from_res(res) else { - return None; - }; - + let filename = self.get_filename_from_res(res)?; Some(format!("{}/files/{}", WAYVR_SKYMAPS_ROOT, filename)) } @@ -102,10 +99,7 @@ pub struct SkymapCatalogEntry { impl SkymapCatalogEntry { pub fn get_destination_path(&self, resolution: SkymapResolution) -> Option { - let Some(filename) = self.files.get_filename_from_res(resolution) else { - return None; - }; - + let filename = self.files.get_filename_from_res(resolution)?; Some(config_io::get_skymaps_root().join(filename)) } @@ -170,7 +164,7 @@ pub async fn request_catalog(executor: &AsyncExecutor) -> anyhow::Result()?; + let catalog = res.into_json::()?; catalog.validate()?; Ok(catalog) diff --git a/dash-frontend/src/util/popup_manager.rs b/dash-frontend/src/util/popup_manager.rs index fa7b7cfd..e7c62151 100644 --- a/dash-frontend/src/util/popup_manager.rs +++ b/dash-frontend/src/util/popup_manager.rs @@ -135,11 +135,7 @@ impl PopupHolder { F: FnOnce(&mut ViewType) -> R, { let mut state = self.state.borrow_mut(); - if let Some(view) = state.view.as_mut() { - Some(f(view)) - } else { - None - } + state.view.as_mut().map(f) } // Same as with_view, but the closure expects a simple anyhow::Result<()> type @@ -190,20 +186,18 @@ pub struct PopupContentFuncData<'a> { } type PopupClosedCallback = Box; +type OnContentCallback = Box anyhow::Result>; // we need to implement Clone here, but the underlying function can be called only once. // on_content will be cleared after the first call #[derive(Clone)] pub struct MountPopupOnceParams { title: Translation, - on_content: Rc anyhow::Result>>>>, + on_content: Rc>>, } impl MountPopupOnceParams { - pub fn new( - title: Translation, - on_content: Box anyhow::Result>, - ) -> Self { + pub fn new(title: Translation, on_content: OnContentCallback) -> Self { Self { title, on_content: Rc::new(RefCell::new(Some(on_content))), @@ -313,15 +307,14 @@ impl PopupManager { but_back.on_click({ let popup_handle = Rc::downgrade(&popup_handle.state); Rc::new(move |_common, _evt| { - if let Some(popup_handle) = popup_handle.upgrade() { - if let Some(closed_callback) = { + if let Some(popup_handle) = popup_handle.upgrade() + && let Some(closed_callback) = { let mut state = popup_handle.borrow_mut(); state.mounted_popup = None; // will call Drop state.closed_callback.take() } { - log::debug!("closed_callback called"); - closed_callback(); - } + log::debug!("closed_callback called"); + closed_callback(); } Ok(()) }) diff --git a/dash-frontend/src/util/wgui_simple.rs b/dash-frontend/src/util/wgui_simple.rs index af4d393c..8fe9a1c3 100644 --- a/dash-frontend/src/util/wgui_simple.rs +++ b/dash-frontend/src/util/wgui_simple.rs @@ -97,9 +97,9 @@ pub fn create_icon(layout: &mut Layout, id_parent: WidgetID, size: Vec2, path: A id_parent, widget_sprite, taffy::Style { - min_size: size.clone(), - max_size: size.clone(), - size: size.clone(), + min_size: size, + max_size: size, + size, ..Default::default() }, )?; diff --git a/dash-frontend/src/views/download_file.rs b/dash-frontend/src/views/download_file.rs index 30b299ff..439f7b94 100644 --- a/dash-frontend/src/views/download_file.rs +++ b/dash-frontend/src/views/download_file.rs @@ -158,7 +158,7 @@ impl View { wgui_simple::create_loading(wgui_simple::CreateLoadingParams { parent_id: id_loading_parent, - layout: layout, + layout, with_text: false, })?; diff --git a/dash-frontend/src/views/game_launcher.rs b/dash-frontend/src/views/game_launcher.rs index 17722bc1..f16ca69b 100644 --- a/dash-frontend/src/views/game_launcher.rs +++ b/dash-frontend/src/views/game_launcher.rs @@ -59,12 +59,12 @@ impl ViewTrait for View { } for task in tasks { match task { - Task::FillAppDetails(details) => self.action_fill_app_details(&mut par.layout, details)?, + Task::FillAppDetails(details) => self.action_fill_app_details(par.layout, details)?, Task::Launch => self.action_launch(), Task::SetCoverArt(cover_art) => { let _ = self .view_cover - .set_cover_art(&mut self.game_cover_view_common, &mut par.layout, &cover_art); + .set_cover_art(&mut self.game_cover_view_common, par.layout, &cover_art); } } } @@ -145,8 +145,8 @@ impl View { ) -> anyhow::Result<()> { { let mut c = layout.common(); - let label_author = self.state.fetch_widget(&c.state, "label_author")?.widget; - let label_description = self.state.fetch_widget(&c.state, "label_description")?.widget; + let label_author = self.state.fetch_widget(c.state, "label_author")?.widget; + let label_description = self.state.fetch_widget(c.state, "label_description")?.widget; if let Some(developer) = details.developers.pop() { label_author diff --git a/dash-frontend/src/views/game_list.rs b/dash-frontend/src/views/game_list.rs index ab7e6448..1097f5f2 100644 --- a/dash-frontend/src/views/game_list.rs +++ b/dash-frontend/src/views/game_list.rs @@ -78,9 +78,9 @@ impl ViewTrait for View { for task in tasks { match task { Task::LoadManifests => self.load_manifests(), - Task::FillPage(page_idx) => self.fill_page(&mut par.layout, &mut par.executor, page_idx)?, + Task::FillPage(page_idx) => self.fill_page(par.layout, par.executor, page_idx)?, Task::AppManifestClicked(manifest) => self.action_app_manifest_clicked(manifest)?, - Task::SetCoverArt(app_id, cover_art) => self.set_cover_art(&mut par.layout, app_id, cover_art), + Task::SetCoverArt(app_id, cover_art) => self.set_cover_art(par.layout, app_id, cover_art), Task::PrevPage => self.page_prev(), Task::NextPage => self.page_next(), } diff --git a/dash-frontend/src/views/remote_skymap_downloader.rs b/dash-frontend/src/views/remote_skymap_downloader.rs index 4a2aa537..5dbaa9cf 100644 --- a/dash-frontend/src/views/remote_skymap_downloader.rs +++ b/dash-frontend/src/views/remote_skymap_downloader.rs @@ -144,7 +144,7 @@ impl View { pub fn new(par: Params) -> anyhow::Result { let tasks = Tasks::::new(); - let parser_state = wgui::parser::parse_from_assets(&doc_params(&par.globals), par.layout, par.parent_id)?; + let parser_state = wgui::parser::parse_from_assets(&doc_params(par.globals), par.layout, par.parent_id)?; let id_resolution_buttons = parser_state.get_widget_id("resolution_buttons")?; let str_version = par.globals.i18n().translate("VERSION"); @@ -249,9 +249,9 @@ impl View { } fn show_dialog_box_action(&mut self, resolution: SkymapResolution) -> anyhow::Result<()> { - const ACTION_REMOVE: &'static str = "remove"; - const ACTION_DOWNLOAD_AGAIN: &'static str = "download_again"; - const ACTION_APPLY: &'static str = "apply"; + const ACTION_REMOVE: &str = "remove"; + const ACTION_DOWNLOAD_AGAIN: &str = "download_again"; + const ACTION_APPLY: &str = "apply"; let tasks = self.tasks.clone(); @@ -362,6 +362,7 @@ impl View { } } +#[allow(clippy::too_many_arguments)] pub fn mount_popup( frontend_tasks: FrontendTasks, executor: AsyncExecutor, diff --git a/dash-frontend/src/views/remote_skymap_list.rs b/dash-frontend/src/views/remote_skymap_list.rs index 76c171dc..0ba02497 100644 --- a/dash-frontend/src/views/remote_skymap_list.rs +++ b/dash-frontend/src/views/remote_skymap_list.rs @@ -34,18 +34,12 @@ pub struct Params<'a> { pub on_updated_library: Rc, } +type SetSkymapPreview = (Uuid, Option<(CustomGlyphData, Rc>)>); + #[derive(Clone)] enum Task { SetSkymapCatalog(Rc>), - SetSkymapPreview( - ( - SkymapUuid, - Option<( - CustomGlyphData, /* ready-to-use preview image data */ - Rc>, /* compressed preview image data (should weigh about 10-15 KiB) */ - )>, - ), - ), + SetSkymapPreview(SetSkymapPreview), ShowRemoteSkymapDownloader(SkymapUuid), RefreshCells, } @@ -70,9 +64,7 @@ pub struct View { } fn get_entry_by_uuid(catalog: &SkymapCatalog, skymap_uuid: Uuid) -> Option<&SkymapCatalogEntry> { - let Some(entry) = catalog.entries.iter().find(|entry| entry.uuid == skymap_uuid) else { - return None; - }; + let entry = catalog.entries.iter().find(|entry| entry.uuid == skymap_uuid)?; Some(entry) } @@ -176,7 +168,7 @@ impl View { }; for cell in &mut self.mounted_cells { - if let Some(entry) = get_entry_by_uuid(&catalog, cell.skymap_uuid) { + if let Some(entry) = get_entry_by_uuid(catalog, cell.skymap_uuid) { cell.view.refresh_resolution_pips(layout, entry)?; } } @@ -195,7 +187,7 @@ impl View { extra: Default::default(), }; - let parser_state = wgui::parser::parse_from_assets(&doc_params, layout, self.id_parent)?; + let parser_state = wgui::parser::parse_from_assets(doc_params, layout, self.id_parent)?; let id_list = parser_state.fetch_widget(&layout.state, "list")?.id; @@ -207,11 +199,11 @@ impl View { self.tasks.clone(), ); - let skymap_uuid = entry.uuid.clone(); + let skymap_uuid = entry.uuid; self.mounted_cells.push(MountedCell { preview_image_compressed: None, - skymap_uuid: entry.uuid.clone(), + skymap_uuid: entry.uuid, view: views::skymap_list_cell::View::new(views::skymap_list_cell::Params { id_parent: id_list, layout, @@ -240,7 +232,7 @@ impl View { return Ok(()); }; - let Some(entry) = get_entry_by_uuid(&catalog, uuid) else { + let Some(entry) = get_entry_by_uuid(catalog, uuid) else { return Ok(()); }; @@ -273,13 +265,8 @@ impl View { skymap_uuid: SkymapUuid, ) -> Option<(CustomGlyphData, Rc> /* preview_image_compressed */)> { if let Some(cell) = &self.mounted_cells.iter().find(|mc| mc.skymap_uuid == skymap_uuid) { - let Some(image) = cell.view.get_image() else { - return None; - }; - - let Some(preview_image_compressed) = cell.preview_image_compressed.clone() else { - return None; - }; + let image = cell.view.get_image()?; + let preview_image_compressed = cell.preview_image_compressed.clone()?; return Some((image, preview_image_compressed)); } None diff --git a/dash-frontend/src/views/skymap_list.rs b/dash-frontend/src/views/skymap_list.rs index cf97aa2d..48999bca 100644 --- a/dash-frontend/src/views/skymap_list.rs +++ b/dash-frontend/src/views/skymap_list.rs @@ -66,10 +66,10 @@ impl ViewTrait for View { for task in tasks { match task { Task::DownloadSkymaps => { - self.download_skymaps(&par.executor)?; + self.download_skymaps(par.executor)?; } Task::Refresh => { - self.refresh(&mut par.layout)?; + self.refresh(par.layout)?; } Task::ShowSkymapResolutionSelector(entry) => { self.show_skymap_resolution_selector(entry); @@ -236,10 +236,10 @@ impl View { })?; // load preview image - if let Ok(data) = std::fs::read(skymaps_root.join(&entry.files.preview)) { - if let Ok(glyph_data) = CustomGlyphData::from_bytes_raster(&self.globals, &entry.files.preview, &data) { - view.set_image(layout, Some(glyph_data))?; - } + if let Ok(data) = std::fs::read(skymaps_root.join(&entry.files.preview)) + && let Ok(glyph_data) = CustomGlyphData::from_bytes_raster(&self.globals, &entry.files.preview, &data) + { + view.set_image(layout, Some(glyph_data))?; } self.cells.push(Cell { view }); diff --git a/dash-frontend/src/views/skymap_list_cell.rs b/dash-frontend/src/views/skymap_list_cell.rs index f0267ce5..fa8375de 100644 --- a/dash-frontend/src/views/skymap_list_cell.rs +++ b/dash-frontend/src/views/skymap_list_cell.rs @@ -146,7 +146,7 @@ impl View { } pub fn refresh_resolution_pips(&mut self, layout: &mut Layout, entry: &SkymapCatalogEntry) -> anyhow::Result<()> { - populate_res_pips(layout, self.id_resolution_pips, &mut self.parser_state, &entry)?; + populate_res_pips(layout, self.id_resolution_pips, &mut self.parser_state, entry)?; Ok(()) } @@ -163,6 +163,6 @@ impl View { } pub fn get_image(&self) -> Option { - return self.image.clone(); + self.image.clone() } } diff --git a/wayvr/src/backend/openxr/playspace.rs b/wayvr/src/backend/openxr/playspace.rs index 0bc370b8..0f6d95b5 100644 --- a/wayvr/src/backend/openxr/playspace.rs +++ b/wayvr/src/backend/openxr/playspace.rs @@ -30,7 +30,7 @@ impl PlayspaceMover { Err(MndResult::ErrorInvalidVersion) ) { anyhow::bail!("Space offsets not supported."); - }; + } Ok(Self { drag: None, diff --git a/wayvr/src/backend/openxr/skybox.rs b/wayvr/src/backend/openxr/skybox.rs index 2d0215e2..21d2e9d5 100644 --- a/wayvr/src/backend/openxr/skybox.rs +++ b/wayvr/src/backend/openxr/skybox.rs @@ -23,6 +23,7 @@ use super::{ swapchain::{WlxSwapchain, create_swapchain}, }; +#[allow(clippy::struct_field_names)] pub(super) struct Skybox { view: Option>, sky: Option, @@ -126,8 +127,7 @@ impl Skybox { let extent = self .view .as_ref() - .map(|v| v.extent_u32arr()) - .unwrap_or([4096, 4096]); + .map_or([4096, 4096], ExtentExt::extent_u32arr); let mut swapchain = create_swapchain(xr, app.gfx.clone(), extent, 1, opts)?; let tgt = swapchain diff --git a/wayvr/src/config.rs b/wayvr/src/config.rs index eed2709c..a42526db 100644 --- a/wayvr/src/config.rs +++ b/wayvr/src/config.rs @@ -48,7 +48,7 @@ where panic!("No usable config found."); } -const SUPPORTED_EXTESIONS: [&'static str; 4] = ["yaml", "yml", "json", "json5"]; +const SUPPORTED_EXTESIONS: [&str; 4] = ["yaml", "yml", "json", "json5"]; fn is_supported_config_file(path: &Path) -> bool { if path.is_dir() { diff --git a/wayvr/src/gui/panel/mod.rs b/wayvr/src/gui/panel/mod.rs index c135e58a..7726ffcc 100644 --- a/wayvr/src/gui/panel/mod.rs +++ b/wayvr/src/gui/panel/mod.rs @@ -498,7 +498,7 @@ pub fn apply_custom_command( ModifyPanelCommand::SetText(text) => { if let Ok(mut label) = panel .parser_state - .fetch_widget_as::(&com.state, element) + .fetch_widget_as::(com.state, element) { label.set_text(&mut com, Translation::from_raw_text(text)); } else if let Ok(button) = panel @@ -511,7 +511,7 @@ pub fn apply_custom_command( } } ModifyPanelCommand::SetImage(path) => { - if let Ok(pair) = panel.parser_state.fetch_widget(&com.state, element) { + if let Ok(pair) = panel.parser_state.fetch_widget(com.state, element) { let data = CustomGlyphData::from_assets( &app.wgui_globals, wgui::assets::AssetPath::File(path), @@ -533,7 +533,7 @@ pub fn apply_custom_command( let color = parse_color_hex(color) .context("Invalid color format, must be a html hex color!")?; - if let Ok(pair) = panel.parser_state.fetch_widget(&com.state, element) { + if let Ok(pair) = panel.parser_state.fetch_widget(com.state, element) { if let Some(mut rect) = pair.widget.get_as::() { rect.set_color(&mut com, color); } else if let Some(mut label) = pair.widget.get_as::() { diff --git a/wayvr/src/ipc/ipc_server.rs b/wayvr/src/ipc/ipc_server.rs index 8a33c87f..7dead59d 100644 --- a/wayvr/src/ipc/ipc_server.rs +++ b/wayvr/src/ipc/ipc_server.rs @@ -49,19 +49,19 @@ fn read_check(expected_size: u32, res: std::io::Result) -> anyhow::Result anyhow::bail!("End of stream"); } if count as u32 == expected_size { - return Ok(true); // read succeeded + Ok(true) // read succeeded } else { log::error!("count {count} is not {expected_size}"); - return Ok(false); + Ok(false) } } Err(e) => match e.kind() { std::io::ErrorKind::WouldBlock => { // no incoming data (this socket is non-blocking), try again later - return Ok(false); + Ok(false) } _ => { - anyhow::bail!("Connection error: {:?}", e); + anyhow::bail!("Connection error: {e:?}"); } }, } @@ -500,7 +500,7 @@ impl Connection { } } Err(e) => { - log::debug!("Disconnecting client: {:?}", e); + log::debug!("Disconnecting client: {e:?}"); self.alive = false; break; } diff --git a/wayvr/src/overlays/dashboard.rs b/wayvr/src/overlays/dashboard.rs index a3eaf6b0..d1a3f038 100644 --- a/wayvr/src/overlays/dashboard.rs +++ b/wayvr/src/overlays/dashboard.rs @@ -74,7 +74,7 @@ impl DashFrontend { let mut interface = DashInterfaceLive::new(); if app.session.no_autostart { - log::info!("Not starting apps due to --no-autostart") + log::info!("Not starting apps due to --no-autostart"); } else { for p in app.session.config.autostart_apps.clone() { let _ = interface.process_launch(app, false, p); diff --git a/wayvr/src/state.rs b/wayvr/src/state.rs index 478fb261..49a5f3f1 100644 --- a/wayvr/src/state.rs +++ b/wayvr/src/state.rs @@ -154,7 +154,6 @@ impl AppState { desktop_finder.refresh(); let lang_provider = WayVRLangProvider::from_config(&session.config); - let executor = Rc::new(smol::LocalExecutor::new()); let mut app_state = Self { session, diff --git a/wayvr/src/subsystem/hid/mod.rs b/wayvr/src/subsystem/hid/mod.rs index b3d5e611..5a8ee423 100644 --- a/wayvr/src/subsystem/hid/mod.rs +++ b/wayvr/src/subsystem/hid/mod.rs @@ -25,6 +25,14 @@ mod x11; pub static USE_UINPUT: AtomicBool = AtomicBool::new(true); pub(super) fn initialize() -> Result { + const CHECK_UINPUT_MESSAGE: &str = + "Could not create uinput provider. Keyboard/Mouse input will not work! + +Check if the uinput kernel module is loaded: lsmod | grep uinput + - If not loaded, follow your distro's instructions to load the uinput kernel module. + +Check if you're in input group, run: id -nG"; + if !USE_UINPUT.load(std::sync::atomic::Ordering::Relaxed) { const UINPUT_DISABLED: &str = "Uinput disabled by user."; log::info!("{UINPUT_DISABLED}"); @@ -40,13 +48,6 @@ pub(super) fn initialize() -> Result { log::info!("Initialized uinput."); return Ok(uinput); } - const CHECK_UINPUT_MESSAGE: &str = - "Could not create uinput provider. Keyboard/Mouse input will not work! - -Check if the uinput kernel module is loaded: lsmod | grep uinput - - If not loaded, follow your distro's instructions to load the uinput kernel module. - -Check if you're in input group, run: id -nG"; let mut full_uinput_error = String::from(CHECK_UINPUT_MESSAGE); if let Ok(user) = std::env::var("USER") { let check_group_message = format!( diff --git a/wgui/src/components/color_selector.rs b/wgui/src/components/color_selector.rs index 16631c58..a7ef1b4d 100644 --- a/wgui/src/components/color_selector.rs +++ b/wgui/src/components/color_selector.rs @@ -46,6 +46,7 @@ struct PopupState { id_rect_color: WidgetID, } +#[allow(clippy::struct_field_names)] struct State { color: drawing::Color, self_ref: Weak, @@ -83,16 +84,16 @@ impl ComponentTrait for ComponentColorSelector { fn refresh(&self, data: &mut RefreshData) { let mut state = self.state.borrow_mut(); - if let Some(wants_open) = state.wants_open.take() { - if let Err(e) = self.open(data.layout, &mut state, wants_open.position) { - log::error!("{:?}", e); - debug_assert!(false); - } + if let Some(wants_open) = state.wants_open.take() + && let Err(e) = self.open(data.layout, &mut state, wants_open.position) + { + log::error!("{e:?}"); + debug_assert!(false); } self.data.button.set_text( &mut data.layout.common(), - Translation::from_raw_text_string(format!("{}", state.color.to_hex_rgb())), + Translation::from_raw_text_string(state.color.to_hex_rgb()), ); self.data.button.set_color(&mut data.layout.common(), state.color); @@ -111,7 +112,7 @@ fn set_color_internal(state: &mut State, common: &mut CallbackDataCommon, color: } if let Some(on_changed) = &state.on_changed { - on_changed(common, ColorSelectorChangedEvent { color }) + on_changed(common, ColorSelectorChangedEvent { color }); } state.color = color; @@ -148,7 +149,7 @@ impl ComponentColorSelector { let id_content = self.window.get_content().id; let parser_state = parser::parse_from_assets( - &mut ParseDocumentParams { + &ParseDocumentParams { globals: layout.state.globals.clone(), path: AssetPath::WguiInternal("wgui/color_selector.xml"), extra: Default::default(), diff --git a/wgui/src/components/slider.rs b/wgui/src/components/slider.rs index fa61b8bf..e1774baa 100644 --- a/wgui/src/components/slider.rs +++ b/wgui/src/components/slider.rs @@ -40,7 +40,7 @@ pub struct Limits { } impl Value { - pub fn get(&self) -> f32 { + pub const fn get(&self) -> f32 { self.0 } @@ -113,6 +113,7 @@ impl TooltipTrait for State { } } +#[allow(clippy::struct_field_names)] struct SliderHandleData { id_handle_rect: WidgetID, // Rectangle id_text: Option, // Text @@ -146,7 +147,7 @@ impl ComponentTrait for ComponentSlider { let value1 = state.value1.get(); state.set_value(&mut common, &self.data, ValueIndex::Primary, value1); - if let Some(value2) = state.value2.as_ref().map(|v| v.get()) { + if let Some(value2) = state.value2.as_ref().map(Value::get) { state.set_value(&mut common, &self.data, ValueIndex::Secondary, value2); } } @@ -169,7 +170,7 @@ impl ComponentSlider { let state = self.state.borrow(); match index { ValueIndex::Primary => Some(state.value1.get()), - ValueIndex::Secondary => state.value2.as_ref().map(|v| v.get()), + ValueIndex::Secondary => state.value2.as_ref().map(Value::get), } } @@ -231,7 +232,7 @@ const HANDLE_WIDTH: f32 = 32.0; const HANDLE_HEIGHT: f32 = 24.0; impl State { - fn get_hovered_index(&self) -> Option { + const fn get_hovered_index(&self) -> Option { if self.hovered1 { Some(ValueIndex::Primary) } else if self.hovered2 { @@ -336,10 +337,10 @@ impl State { on_value_changed( common, SliderValueChangedEvent { - index: index, + index, value: value.get(), }, - ) + ); } } } @@ -447,17 +448,13 @@ fn update_handle_hovers( let hovered1_prev = state.hovered1; let hovered2_prev = state.hovered2; - if !state.hovered_body { - state.hovered1 = false; - state.hovered2 = false; - } else { + if state.hovered_body { let dist1 = get_handle_dist(common, &data.handle1, mouse_pos); let dist2 = data .handle2 .as_ref() - .map(|h| get_handle_dist(common, h, mouse_pos)) - .unwrap_or(std::f32::MAX); + .map_or(f32::MAX, |h| get_handle_dist(common, h, mouse_pos)); state.hovered1 = dist1 <= MAX_HOVER_DIST; state.hovered2 = dist2 <= MAX_HOVER_DIST; @@ -470,6 +467,9 @@ fn update_handle_hovers( state.hovered1 = false; } } + } else { + state.hovered1 = false; + state.hovered2 = false; } // hover state changed, run animations @@ -516,12 +516,12 @@ fn register_event_mouse_motion( update_handle_hovers(common, &data, &mut state, anim_mult, pos_relative); - if let Some(dragged_by) = &state.dragged_by { - if dragged_by.device == pos.device { - let index = dragged_by.index; - state.update_value_to_mouse(event_data, &data, common, index); - return Ok(EventResult::Consumed); - } + if let Some(dragged_by) = &state.dragged_by + && dragged_by.device == pos.device + { + let index = dragged_by.index; + state.update_value_to_mouse(event_data, &data, common, index); + return Ok(EventResult::Consumed); } Ok(EventResult::Pass) diff --git a/wgui/src/drawing.rs b/wgui/src/drawing.rs index ef8fa550..7acc52e9 100644 --- a/wgui/src/drawing.rs +++ b/wgui/src/drawing.rs @@ -207,6 +207,7 @@ pub struct HsvColor { pub a: f32, } +#[allow(clippy::many_single_char_names)] impl HsvColor { pub const fn new(h: f32, s: f32, v: f32, a: f32) -> Self { Self { h, s, v, a } diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs index 0ff8f588..2e202007 100644 --- a/wgui/src/layout.rs +++ b/wgui/src/layout.rs @@ -229,7 +229,7 @@ fn add_child_internal( } impl Layout { - pub fn common(&mut self) -> CallbackDataCommon<'_> { + pub const fn common(&mut self) -> CallbackDataCommon<'_> { CallbackDataCommon { alterables: &mut self.alterables, state: &self.state, @@ -480,7 +480,7 @@ impl Layout { Ok(()) } - fn get_event_params<'a>( + const fn get_event_params<'a>( &'a self, l: &'a taffy::Layout, node_id: taffy::NodeId, diff --git a/wgui/src/parser/component_slider.rs b/wgui/src/parser/component_slider.rs index d38a738a..f14d21a6 100644 --- a/wgui/src/parser/component_slider.rs +++ b/wgui/src/parser/component_slider.rs @@ -69,7 +69,7 @@ pub fn parse_component_slider( step, }, value1: slider::Value(initial_value1), - value2: initial_value2.map(|v| slider::Value(v)), + value2: initial_value2.map(slider::Value), show_value: show_value != 0, tooltip: tooltip.get_info(), }, diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index e8bac585..1020ba47 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -225,7 +225,7 @@ impl ParserState { /// but it keeps components data in this `ParserState` object for you. /// The result can be safely dropped, all required event listeners and components /// will be kept intact in this `ParserState`. - /// Resulting ParserData::components Vec will be left empty (they are moved into this `ParserState::data`) + /// Resulting `ParserData::components` Vec will be left empty (they are moved into this `ParserState::data`) pub fn realize_template( &mut self, doc_params: &ParseDocumentParams, @@ -245,7 +245,7 @@ impl ParserState { /// Semi-internal - This function is suitable in cases if you don't want to pollute /// the main parser state state with dynamic IDs (this won't propagate components!) /// Use `realize_template` (or in some rare cases: `instantiate_template`) instead unless you want to handle `components` results yourself. - /// Make sure not to drop resulting ParserData if you want to have your listener handles valid + /// Make sure not to drop resulting `ParserData` if you want to have your listener handles valid /// (they are contained in components). Use `realize_template` instead if you don't want to think about it. pub fn parse_template_only( &self, @@ -282,7 +282,7 @@ impl ParserState { /// Parse named