From 40aec97f799eb474114333b0e7e5eb5cce21c2e7 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Sun, 12 Jan 2025 23:10:21 +0100 Subject: [PATCH] Cargo format --- src/config.rs | 6 ++- src/state.rs | 105 +++++++++++++++++++++++++++------------- src/utils/desktop.rs | 4 +- src/utils/mod.rs | 2 +- src/utils/xdg.rs | 5 +- src/widgets/calendar.rs | 6 ++- src/widgets/launcher.rs | 4 +- src/widgets/layout.rs | 1 - 8 files changed, 89 insertions(+), 44 deletions(-) diff --git a/src/config.rs b/src/config.rs index 94ba503..62a6115 100644 --- a/src/config.rs +++ b/src/config.rs @@ -324,7 +324,11 @@ impl Widget { sections_x, sections_y, ))), - Widget::Launcher { font, font_size, launch_cmd } => v.push(Box::new(Interface::new( + Widget::Launcher { + font, + font_size, + launch_cmd, + } => v.push(Box::new(Interface::new( events.clone(), &mut fm, leak_or_default(font, "sans"), diff --git a/src/state.rs b/src/state.rs index 9751c88..17b5f03 100644 --- a/src/state.rs +++ b/src/state.rs @@ -8,8 +8,8 @@ use std::{ use wayland_client::{ protocol::{ - wl_buffer, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, wl_shm, - wl_shm_pool, wl_subcompositor, wl_subsurface, wl_surface, wl_callback, + wl_buffer, wl_callback, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, + wl_shm, wl_shm_pool, wl_subcompositor, wl_subsurface, wl_surface, }, Connection, Dispatch, QueueHandle, WEnum, }; @@ -61,7 +61,8 @@ pub struct Protocols { xdg_activation: Option, zwlr_layer_shell: Option, viewporter: Option, - wp_single_pixel_buffer_manager: Option, + wp_single_pixel_buffer_manager: + Option, } pub struct State { @@ -164,14 +165,22 @@ impl WidgetUpdater for State { impl State { pub fn check_registry(&mut self, qh: &QueueHandle) { - let wl_compositor = self.protocols.wl_compositor.as_ref().expect("wl_compositor missing"); + let wl_compositor = self + .protocols + .wl_compositor + .as_ref() + .expect("wl_compositor missing"); let main_surface = wl_compositor.create_surface(qh, ()); let bg_surface = wl_compositor.create_surface(qh, ()); self.main_surface.wl_surface = Some(main_surface.clone()); self.bg_surface.wl_surface = Some(bg_surface.clone()); self.activate(qh); - let wl_subcompositor = self.protocols.wl_subcompositor.as_ref().expect("wl_subcompositor missing"); + let wl_subcompositor = self + .protocols + .wl_subcompositor + .as_ref() + .expect("wl_subcompositor missing"); let subsurface = wl_subcompositor.get_subsurface(&bg_surface, &main_surface, qh, ()); subsurface.place_below(&main_surface); self.bg_surface.subsurface = Some(subsurface.clone()); @@ -179,7 +188,11 @@ impl State { match self.mode { OperationMode::XdgToplevel => { self.fonts.resolve(); - let xdg_wm_base = self.protocols.xdg_wm_base.as_ref().expect("xdg_wm_base missing"); + let xdg_wm_base = self + .protocols + .xdg_wm_base + .as_ref() + .expect("xdg_wm_base missing"); let xdg_surface = xdg_wm_base.get_xdg_surface(&main_surface, qh, ()); let toplevel = xdg_surface.get_toplevel(qh, ()); toplevel.set_title("wldash".into()); @@ -189,7 +202,11 @@ impl State { } OperationMode::LayerSurface(size) => { self.fonts.resolve(); - let layer_shell = self.protocols.zwlr_layer_shell.as_ref().expect("zwlr_layer_shell_v1 missing"); + let layer_shell = self + .protocols + .zwlr_layer_shell + .as_ref() + .expect("zwlr_layer_shell_v1 missing"); let layer_surface = layer_shell.get_layer_surface( &main_surface, None, @@ -208,32 +225,31 @@ impl State { zwlr_layer_surface_v1::Anchor::Left .union(zwlr_layer_surface_v1::Anchor::Bottom) .union(zwlr_layer_surface_v1::Anchor::Right) - .union(zwlr_layer_surface_v1::Anchor::Top) - ); - layer_surface.set_size( - max(size.0, min_size.width), - max(size.1, min_size.height), + .union(zwlr_layer_surface_v1::Anchor::Top), ); + layer_surface.set_size(max(size.0, min_size.width), max(size.1, min_size.height)); main_surface.commit(); self.main_surface.layer_surface = Some(layer_surface); } } - let viewporter = self.protocols.viewporter.as_ref().expect("wp_viewporter missing"); + let viewporter = self + .protocols + .viewporter + .as_ref() + .expect("wp_viewporter missing"); let viewport = viewporter.get_viewport(&bg_surface, qh, ()); self.bg_surface.viewport = Some(viewport); if let Some(background) = self.background { - let wp_single_pixel_buffer_manager = self.protocols.wp_single_pixel_buffer_manager.as_ref().expect("wp_single_pixel_buffer_manager_v1 missing"); - let buffer = wp_single_pixel_buffer_manager.create_u32_rgba_buffer( - 0, - 0, - 0, - background, - qh, - (), - ); + let wp_single_pixel_buffer_manager = self + .protocols + .wp_single_pixel_buffer_manager + .as_ref() + .expect("wp_single_pixel_buffer_manager_v1 missing"); + let buffer = + wp_single_pixel_buffer_manager.create_u32_rgba_buffer(0, 0, 0, background, qh, ()); bg_surface.attach(Some(&buffer), 0, 0); bg_surface.damage_buffer(0, 0, 1, 1); } @@ -259,8 +275,9 @@ impl Dispatch for State { Some(registry.bind::(name, 5, qh, ())); } "wl_subcompositor" => { - state.protocols.wl_subcompositor = - Some(registry.bind::(name, 1, qh, ())); + state.protocols.wl_subcompositor = Some( + registry.bind::(name, 1, qh, ()), + ); } "wl_shm" => { state.protocols.wl_shm = @@ -282,8 +299,14 @@ impl Dispatch for State { } "zwlr_layer_shell_v1" => { if let OperationMode::LayerSurface(_) = state.mode { - state.protocols.zwlr_layer_shell = Some(registry - .bind::(name, 4, qh, ())); + state.protocols.zwlr_layer_shell = Some( + registry.bind::( + name, + 4, + qh, + (), + ), + ); } } "wp_viewporter" => { @@ -309,10 +332,8 @@ impl Dispatch for State { _: &QueueHandle, ) { match event { - wl_callback::Event::Done { callback_data: _ } => { - state.ready = true - }, - _ => {}, + wl_callback::Event::Done { callback_data: _ } => state.ready = true, + _ => {} } } } @@ -463,8 +484,16 @@ impl Dispatch for State { state, ); - let surface = state.bg_surface.wl_surface.as_ref().expect("bg surface was not ready"); - let viewport = state.bg_surface.viewport.as_ref().expect("bg viewport was not ready"); + let surface = state + .bg_surface + .wl_surface + .as_ref() + .expect("bg surface was not ready"); + let viewport = state + .bg_surface + .viewport + .as_ref() + .expect("bg viewport was not ready"); viewport.set_destination(dim.0, dim.1); surface.commit(); } @@ -545,8 +574,16 @@ impl Dispatch for State { } if !state.configured || state.dimensions != (width, height) { - let surface = state.bg_surface.wl_surface.as_ref().expect("bg surface was not ready"); - let viewport = state.bg_surface.viewport.as_ref().expect("bg viewportw as not ready"); + let surface = state + .bg_surface + .wl_surface + .as_ref() + .expect("bg surface was not ready"); + let viewport = state + .bg_surface + .viewport + .as_ref() + .expect("bg viewportw as not ready"); viewport.set_destination(width, height); surface.commit(); diff --git a/src/utils/desktop.rs b/src/utils/desktop.rs index a63c58f..5074760 100644 --- a/src/utils/desktop.rs +++ b/src/utils/desktop.rs @@ -77,14 +77,14 @@ impl PartialEq for Desktop { pub fn load_desktop_cache() -> Result, Box> { match File::open(format!("{}/wldash/desktop.json", xdg::cache_folder())) { Ok(f) => simd_json::from_reader(f).map_err(|e| e.into()), - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), } } pub fn write_desktop_cache(v: &Vec) -> Result<(), Box> { match File::create(format!("{}/wldash/desktop.json", xdg::cache_folder())) { Ok(f) => simd_json::to_writer(f, v).map_err(|e| e.into()), - Err(e) => Err(e.into()) + Err(e) => Err(e.into()), } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index bb7cf87..9f478dc 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,3 @@ pub mod desktop; -pub mod xdg; mod inish; +pub mod xdg; diff --git a/src/utils/xdg.rs b/src/utils/xdg.rs index f5a2662..9146912 100644 --- a/src/utils/xdg.rs +++ b/src/utils/xdg.rs @@ -10,7 +10,6 @@ pub fn cache_folder() -> String { } } - pub fn config_folder() -> String { match env::var_os("XDG_CONFIG_HOME") { Some(s) => s.into_string().unwrap(), @@ -35,5 +34,7 @@ pub fn data_folders() -> Vec { }; // Eww. - std::iter::once(xdg_data_home.to_string()).chain(xdg_data_dirs.split(':').map(|x| x.to_string())).collect() + std::iter::once(xdg_data_home.to_string()) + .chain(xdg_data_dirs.split(':').map(|x| x.to_string())) + .collect() } diff --git a/src/widgets/calendar.rs b/src/widgets/calendar.rs index bfa3b77..ff3c30b 100644 --- a/src/widgets/calendar.rs +++ b/src/widgets/calendar.rs @@ -44,7 +44,11 @@ impl Calendar { fm.queue_font(font, size * DAY_FACTOR, "ADEFHIMNORSTUW"); fm.queue_font(font, size * YEAR_FACTOR, "0123456789"); fm.queue_font(font, size * DATE_FACTOR, "0123456789"); - fm.queue_font(month_font, size * MONTH_FACTOR, "ADFJMNOSabcehgilmnoprstuvy"); + fm.queue_font( + month_font, + size * MONTH_FACTOR, + "ADFJMNOSabcehgilmnoprstuvy", + ); Calendar { font, diff --git a/src/widgets/launcher.rs b/src/widgets/launcher.rs index a6be498..322d5e3 100644 --- a/src/widgets/launcher.rs +++ b/src/widgets/launcher.rs @@ -16,7 +16,7 @@ use crate::{ fonts::FontMap, keyboard::{keysyms, KeyEvent}, utils::{ - desktop::{load_desktop_files, load_desktop_cache, write_desktop_cache, Desktop}, + desktop::{load_desktop_cache, load_desktop_files, write_desktop_cache, Desktop}, xdg, }, widgets::{Geometry, Widget}, @@ -615,7 +615,7 @@ impl Interface { fm: &mut FontMap, font: &'static str, size: f32, - launch_cmd: Option + launch_cmd: Option, ) -> Interface { fm.queue_font( font, diff --git a/src/widgets/layout.rs b/src/widgets/layout.rs index 1009fad..21f6c18 100644 --- a/src/widgets/layout.rs +++ b/src/widgets/layout.rs @@ -281,4 +281,3 @@ impl Layout for Margin { } } } -