Cargo format

This commit is contained in:
Kenny Levinsen
2025-02-27 14:48:41 +01:00
parent 9031361dd1
commit 40aec97f79
8 changed files with 89 additions and 44 deletions
+5 -1
View File
@@ -324,7 +324,11 @@ impl Widget {
sections_x, sections_x,
sections_y, 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(), events.clone(),
&mut fm, &mut fm,
leak_or_default(font, "sans"), leak_or_default(font, "sans"),
+71 -34
View File
@@ -8,8 +8,8 @@ use std::{
use wayland_client::{ use wayland_client::{
protocol::{ protocol::{
wl_buffer, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, wl_shm, wl_buffer, wl_callback, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat,
wl_shm_pool, wl_subcompositor, wl_subsurface, wl_surface, wl_callback, wl_shm, wl_shm_pool, wl_subcompositor, wl_subsurface, wl_surface,
}, },
Connection, Dispatch, QueueHandle, WEnum, Connection, Dispatch, QueueHandle, WEnum,
}; };
@@ -61,7 +61,8 @@ pub struct Protocols {
xdg_activation: Option<xdg_activation_v1::XdgActivationV1>, xdg_activation: Option<xdg_activation_v1::XdgActivationV1>,
zwlr_layer_shell: Option<zwlr_layer_shell_v1::ZwlrLayerShellV1>, zwlr_layer_shell: Option<zwlr_layer_shell_v1::ZwlrLayerShellV1>,
viewporter: Option<wp_viewporter::WpViewporter>, viewporter: Option<wp_viewporter::WpViewporter>,
wp_single_pixel_buffer_manager: Option<wp_single_pixel_buffer_manager_v1::WpSinglePixelBufferManagerV1>, wp_single_pixel_buffer_manager:
Option<wp_single_pixel_buffer_manager_v1::WpSinglePixelBufferManagerV1>,
} }
pub struct State { pub struct State {
@@ -164,14 +165,22 @@ impl WidgetUpdater for State {
impl State { impl State {
pub fn check_registry(&mut self, qh: &QueueHandle<Self>) { pub fn check_registry(&mut self, qh: &QueueHandle<Self>) {
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 main_surface = wl_compositor.create_surface(qh, ());
let bg_surface = wl_compositor.create_surface(qh, ()); let bg_surface = wl_compositor.create_surface(qh, ());
self.main_surface.wl_surface = Some(main_surface.clone()); self.main_surface.wl_surface = Some(main_surface.clone());
self.bg_surface.wl_surface = Some(bg_surface.clone()); self.bg_surface.wl_surface = Some(bg_surface.clone());
self.activate(qh); 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, ()); let subsurface = wl_subcompositor.get_subsurface(&bg_surface, &main_surface, qh, ());
subsurface.place_below(&main_surface); subsurface.place_below(&main_surface);
self.bg_surface.subsurface = Some(subsurface.clone()); self.bg_surface.subsurface = Some(subsurface.clone());
@@ -179,7 +188,11 @@ impl State {
match self.mode { match self.mode {
OperationMode::XdgToplevel => { OperationMode::XdgToplevel => {
self.fonts.resolve(); 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 xdg_surface = xdg_wm_base.get_xdg_surface(&main_surface, qh, ());
let toplevel = xdg_surface.get_toplevel(qh, ()); let toplevel = xdg_surface.get_toplevel(qh, ());
toplevel.set_title("wldash".into()); toplevel.set_title("wldash".into());
@@ -189,7 +202,11 @@ impl State {
} }
OperationMode::LayerSurface(size) => { OperationMode::LayerSurface(size) => {
self.fonts.resolve(); 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( let layer_surface = layer_shell.get_layer_surface(
&main_surface, &main_surface,
None, None,
@@ -208,32 +225,31 @@ impl State {
zwlr_layer_surface_v1::Anchor::Left zwlr_layer_surface_v1::Anchor::Left
.union(zwlr_layer_surface_v1::Anchor::Bottom) .union(zwlr_layer_surface_v1::Anchor::Bottom)
.union(zwlr_layer_surface_v1::Anchor::Right) .union(zwlr_layer_surface_v1::Anchor::Right)
.union(zwlr_layer_surface_v1::Anchor::Top) .union(zwlr_layer_surface_v1::Anchor::Top),
);
layer_surface.set_size(
max(size.0, min_size.width),
max(size.1, min_size.height),
); );
layer_surface.set_size(max(size.0, min_size.width), max(size.1, min_size.height));
main_surface.commit(); main_surface.commit();
self.main_surface.layer_surface = Some(layer_surface); 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, ()); let viewport = viewporter.get_viewport(&bg_surface, qh, ());
self.bg_surface.viewport = Some(viewport); self.bg_surface.viewport = Some(viewport);
if let Some(background) = self.background { 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 wp_single_pixel_buffer_manager = self
let buffer = wp_single_pixel_buffer_manager.create_u32_rgba_buffer( .protocols
0, .wp_single_pixel_buffer_manager
0, .as_ref()
0, .expect("wp_single_pixel_buffer_manager_v1 missing");
background, let buffer =
qh, wp_single_pixel_buffer_manager.create_u32_rgba_buffer(0, 0, 0, background, qh, ());
(),
);
bg_surface.attach(Some(&buffer), 0, 0); bg_surface.attach(Some(&buffer), 0, 0);
bg_surface.damage_buffer(0, 0, 1, 1); bg_surface.damage_buffer(0, 0, 1, 1);
} }
@@ -259,8 +275,9 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
Some(registry.bind::<wl_compositor::WlCompositor, _, _>(name, 5, qh, ())); Some(registry.bind::<wl_compositor::WlCompositor, _, _>(name, 5, qh, ()));
} }
"wl_subcompositor" => { "wl_subcompositor" => {
state.protocols.wl_subcompositor = state.protocols.wl_subcompositor = Some(
Some(registry.bind::<wl_subcompositor::WlSubcompositor, _, _>(name, 1, qh, ())); registry.bind::<wl_subcompositor::WlSubcompositor, _, _>(name, 1, qh, ()),
);
} }
"wl_shm" => { "wl_shm" => {
state.protocols.wl_shm = state.protocols.wl_shm =
@@ -282,8 +299,14 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
} }
"zwlr_layer_shell_v1" => { "zwlr_layer_shell_v1" => {
if let OperationMode::LayerSurface(_) = state.mode { if let OperationMode::LayerSurface(_) = state.mode {
state.protocols.zwlr_layer_shell = Some(registry state.protocols.zwlr_layer_shell = Some(
.bind::<zwlr_layer_shell_v1::ZwlrLayerShellV1, _, _>(name, 4, qh, ())); registry.bind::<zwlr_layer_shell_v1::ZwlrLayerShellV1, _, _>(
name,
4,
qh,
(),
),
);
} }
} }
"wp_viewporter" => { "wp_viewporter" => {
@@ -309,10 +332,8 @@ impl Dispatch<wl_callback::WlCallback, ()> for State {
_: &QueueHandle<Self>, _: &QueueHandle<Self>,
) { ) {
match event { match event {
wl_callback::Event::Done { callback_data: _ } => { wl_callback::Event::Done { callback_data: _ } => state.ready = true,
state.ready = true _ => {}
},
_ => {},
} }
} }
} }
@@ -463,8 +484,16 @@ impl Dispatch<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, ()> for State {
state, state,
); );
let surface = state.bg_surface.wl_surface.as_ref().expect("bg surface was not ready"); let surface = state
let viewport = state.bg_surface.viewport.as_ref().expect("bg viewport was not ready"); .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); viewport.set_destination(dim.0, dim.1);
surface.commit(); surface.commit();
} }
@@ -545,8 +574,16 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
} }
if !state.configured || state.dimensions != (width, height) { if !state.configured || state.dimensions != (width, height) {
let surface = state.bg_surface.wl_surface.as_ref().expect("bg surface was not ready"); let surface = state
let viewport = state.bg_surface.viewport.as_ref().expect("bg viewportw as not ready"); .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); viewport.set_destination(width, height);
surface.commit(); surface.commit();
+2 -2
View File
@@ -77,14 +77,14 @@ impl PartialEq for Desktop {
pub fn load_desktop_cache() -> Result<Vec<Desktop>, Box<dyn Error>> { pub fn load_desktop_cache() -> Result<Vec<Desktop>, Box<dyn Error>> {
match File::open(format!("{}/wldash/desktop.json", xdg::cache_folder())) { match File::open(format!("{}/wldash/desktop.json", xdg::cache_folder())) {
Ok(f) => simd_json::from_reader(f).map_err(|e| e.into()), 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<Desktop>) -> Result<(), Box<dyn Error>> { pub fn write_desktop_cache(v: &Vec<Desktop>) -> Result<(), Box<dyn Error>> {
match File::create(format!("{}/wldash/desktop.json", xdg::cache_folder())) { match File::create(format!("{}/wldash/desktop.json", xdg::cache_folder())) {
Ok(f) => simd_json::to_writer(f, v).map_err(|e| e.into()), Ok(f) => simd_json::to_writer(f, v).map_err(|e| e.into()),
Err(e) => Err(e.into()) Err(e) => Err(e.into()),
} }
} }
+1 -1
View File
@@ -1,3 +1,3 @@
pub mod desktop; pub mod desktop;
pub mod xdg;
mod inish; mod inish;
pub mod xdg;
+3 -2
View File
@@ -10,7 +10,6 @@ pub fn cache_folder() -> String {
} }
} }
pub fn config_folder() -> String { pub fn config_folder() -> String {
match env::var_os("XDG_CONFIG_HOME") { match env::var_os("XDG_CONFIG_HOME") {
Some(s) => s.into_string().unwrap(), Some(s) => s.into_string().unwrap(),
@@ -35,5 +34,7 @@ pub fn data_folders() -> Vec<String> {
}; };
// Eww. // 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()
} }
+5 -1
View File
@@ -44,7 +44,11 @@ impl Calendar {
fm.queue_font(font, size * DAY_FACTOR, "ADEFHIMNORSTUW"); fm.queue_font(font, size * DAY_FACTOR, "ADEFHIMNORSTUW");
fm.queue_font(font, size * YEAR_FACTOR, "0123456789"); fm.queue_font(font, size * YEAR_FACTOR, "0123456789");
fm.queue_font(font, size * DATE_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 { Calendar {
font, font,
+2 -2
View File
@@ -16,7 +16,7 @@ use crate::{
fonts::FontMap, fonts::FontMap,
keyboard::{keysyms, KeyEvent}, keyboard::{keysyms, KeyEvent},
utils::{ utils::{
desktop::{load_desktop_files, load_desktop_cache, write_desktop_cache, Desktop}, desktop::{load_desktop_cache, load_desktop_files, write_desktop_cache, Desktop},
xdg, xdg,
}, },
widgets::{Geometry, Widget}, widgets::{Geometry, Widget},
@@ -615,7 +615,7 @@ impl Interface {
fm: &mut FontMap, fm: &mut FontMap,
font: &'static str, font: &'static str,
size: f32, size: f32,
launch_cmd: Option<String> launch_cmd: Option<String>,
) -> Interface { ) -> Interface {
fm.queue_font( fm.queue_font(
font, font,
-1
View File
@@ -281,4 +281,3 @@ impl Layout for Margin {
} }
} }
} }