diff --git a/Cargo.toml b/Cargo.toml index a08d914..6a5e589 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ironbar" version = "0.16.1" -edition = "2021" +edition = "2024" license = "MIT" description = "Customisable GTK Layer Shell wlroots/sway bar" repository = "https://github.com/jakestanger/ironbar" diff --git a/build.rs b/build.rs index a23d3b3..c8d82da 100644 --- a/build.rs +++ b/build.rs @@ -22,8 +22,8 @@ mod ipc { use clap::Command; use clap::CommandFactory; -use clap_complete::generate_to; use clap_complete::Shell::{Bash, Fish, Zsh}; +use clap_complete::generate_to; use cli::Args; use std::fs; use std::path::PathBuf; diff --git a/src/bar.rs b/src/bar.rs index 73feba2..8ec6ae2 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -1,7 +1,7 @@ +use crate::Ironbar; use crate::config::{BarConfig, BarPosition, MarginConfig, ModuleConfig}; use crate::modules::{BarModuleFactory, ModuleInfo, ModuleLocation}; use crate::popup::Popup; -use crate::Ironbar; use color_eyre::Result; use glib::Propagation; use gtk::gdk::Monitor; diff --git a/src/clients/clipboard.rs b/src/clients/clipboard.rs index 1752486..7444119 100644 --- a/src/clients/clipboard.rs +++ b/src/clients/clipboard.rs @@ -1,7 +1,7 @@ use super::wayland::{self, ClipboardItem}; use crate::{arc_mut, lock, register_client, spawn, try_send}; -use indexmap::map::Iter; use indexmap::IndexMap; +use indexmap::map::Iter; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; use tracing::{debug, trace}; diff --git a/src/clients/compositor/hyprland.rs b/src/clients/compositor/hyprland.rs index 990efe4..ec612b0 100644 --- a/src/clients/compositor/hyprland.rs +++ b/src/clients/compositor/hyprland.rs @@ -10,7 +10,7 @@ use hyprland::dispatch::{Dispatch, DispatchType, WorkspaceIdentifierWithSpecial} use hyprland::event_listener::EventListener; use hyprland::prelude::*; use hyprland::shared::{HyprDataVec, WorkspaceType}; -use tokio::sync::broadcast::{channel, Receiver, Sender}; +use tokio::sync::broadcast::{Receiver, Sender, channel}; use tracing::{debug, error, info}; #[derive(Debug)] @@ -250,7 +250,7 @@ impl Client { // // Here we are trying to recover `layout_name` from `keyboard_name` - let layout = layout_event.keyboard_name.as_str().split(",").nth(1); + let layout = layout_event.keyboard_name.as_str().split(',').nth(1); let Some(layout) = layout else { error!( "Failed to get layout from string: {}. The failed logic is a workaround for a bug in `hyprland 0.4.0-alpha.3`", layout_event.keyboard_name); diff --git a/src/clients/compositor/mod.rs b/src/clients/compositor/mod.rs index 4222beb..db45052 100644 --- a/src/clients/compositor/mod.rs +++ b/src/clients/compositor/mod.rs @@ -1,3 +1,4 @@ +use crate::clients::ClientResult; use crate::register_fallible_client; use cfg_if::cfg_if; use color_eyre::{Help, Report, Result}; @@ -67,7 +68,7 @@ impl Compositor { pub fn create_keyboard_layout_client( clients: &mut super::Clients, - ) -> Result> { + ) -> ClientResult { let current = Self::get_current(); debug!("Getting keyboard_layout client for: {current}"); match current { @@ -76,9 +77,7 @@ impl Compositor { .sway() .map(|client| client as Arc), #[cfg(feature = "keyboard+hyprland")] - Self::Hyprland => clients - .hyprland() - .map(|client| client as Arc), + Self::Hyprland => Ok(clients.hyprland()), Self::Niri | Self::Unsupported => Err(Report::msg("Unsupported compositor").note( "Currently keyboard layout functionality are only supported by Sway and Hyprland", )), @@ -98,9 +97,7 @@ impl Compositor { .sway() .map(|client| client as Arc), #[cfg(feature = "workspaces+hyprland")] - Self::Hyprland => clients - .hyprland() - .map(|client| client as Arc), + Self::Hyprland => Ok(clients.hyprland()), #[cfg(feature = "workspaces+niri")] Self::Niri => Ok(Arc::new(niri::Client::new())), Self::Unsupported => Err(Report::msg("Unsupported compositor") diff --git a/src/clients/compositor/niri/connection.rs b/src/clients/compositor/niri/connection.rs index 4806661..9c588f2 100644 --- a/src/clients/compositor/niri/connection.rs +++ b/src/clients/compositor/niri/connection.rs @@ -3,7 +3,7 @@ /// to reduce compile times. use crate::clients::compositor::Workspace as IronWorkspace; use crate::{await_sync, clients::compositor::Visibility}; -use color_eyre::eyre::{eyre, Result}; +use color_eyre::eyre::{Result, eyre}; use core::str; use serde::{Deserialize, Serialize}; use std::{env, path::Path}; diff --git a/src/clients/compositor/sway.rs b/src/clients/compositor/sway.rs index 5bc9864..d39f650 100644 --- a/src/clients/compositor/sway.rs +++ b/src/clients/compositor/sway.rs @@ -6,7 +6,7 @@ use crate::clients::sway::Client; use crate::{await_sync, error, send, spawn}; use color_eyre::Report; use swayipc_async::{InputChange, InputEvent, Node, WorkspaceChange, WorkspaceEvent}; -use tokio::sync::broadcast::{channel, Receiver}; +use tokio::sync::broadcast::{Receiver, channel}; impl WorkspaceClient for Client { fn focus(&self, id: i64) { diff --git a/src/clients/libinput.rs b/src/clients/libinput.rs index 6de1b8b..c823989 100644 --- a/src/clients/libinput.rs +++ b/src/clients/libinput.rs @@ -1,7 +1,7 @@ use crate::{arc_rw, read_lock, send, spawn, spawn_blocking, write_lock}; use color_eyre::{Report, Result}; -use evdev_rs::enums::{int_to_ev_key, EventCode, EV_KEY, EV_LED}; use evdev_rs::DeviceWrapper; +use evdev_rs::enums::{EV_KEY, EV_LED, EventCode, int_to_ev_key}; use input::event::keyboard::{KeyState, KeyboardEventTrait}; use input::event::{DeviceEvent, EventTrait, KeyboardEvent}; use input::{DeviceCapability, Libinput, LibinputInterface}; diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 418faf3..6410e80 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,4 +1,4 @@ -use crate::{await_sync, Ironbar}; +use crate::{Ironbar, await_sync}; use color_eyre::Result; use std::collections::HashMap; use std::path::Path; @@ -129,16 +129,14 @@ impl Clients { } #[cfg(feature = "hyprland")] - pub fn hyprland(&mut self) -> ClientResult { - let client = if let Some(client) = &self.hyprland { + pub fn hyprland(&mut self) -> Arc { + if let Some(client) = &self.hyprland { client.clone() } else { let client = Arc::new(compositor::hyprland::Client::new()); self.hyprland.replace(client.clone()); client - }; - - Ok(client) + } } #[cfg(feature = "cairo")] diff --git a/src/clients/music/mpd.rs b/src/clients/music/mpd.rs index f1239c9..9d1157d 100644 --- a/src/clients/music/mpd.rs +++ b/src/clients/music/mpd.rs @@ -1,14 +1,14 @@ use super::{ - MusicClient, PlayerState, PlayerUpdate, ProgressTick, Status, Track, TICK_INTERVAL_MS, + MusicClient, PlayerState, PlayerUpdate, ProgressTick, Status, TICK_INTERVAL_MS, Track, }; -use crate::{await_sync, send, spawn, Ironbar}; +use crate::{Ironbar, await_sync, send, spawn}; use color_eyre::Report; use color_eyre::Result; use mpd_client::client::{ConnectionEvent, Subsystem}; use mpd_client::commands::{self, SeekMode}; use mpd_client::responses::{PlayState, Song}; use mpd_client::tag::Tag; -use mpd_utils::{mpd_client, PersistentClient}; +use mpd_utils::{PersistentClient, mpd_client}; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Duration; diff --git a/src/clients/music/mpris.rs b/src/clients/music/mpris.rs index 95e63f2..946b6fb 100644 --- a/src/clients/music/mpris.rs +++ b/src/clients/music/mpris.rs @@ -1,4 +1,4 @@ -use super::{MusicClient, PlayerState, PlayerUpdate, Status, Track, TICK_INTERVAL_MS}; +use super::{MusicClient, PlayerState, PlayerUpdate, Status, TICK_INTERVAL_MS, Track}; use crate::clients::music::ProgressTick; use crate::{arc_mut, lock, send, spawn_blocking}; use color_eyre::Result; diff --git a/src/clients/networkmanager.rs b/src/clients/networkmanager.rs index 333ab4e..02ce6b5 100644 --- a/src/clients/networkmanager.rs +++ b/src/clients/networkmanager.rs @@ -7,10 +7,10 @@ use tracing::error; use zbus::export::ordered_stream::OrderedStreamExt; use zbus::fdo::PropertiesProxy; use zbus::{ + Connection, names::InterfaceName, proxy, zvariant::{ObjectPath, Str}, - Connection, }; const DBUS_BUS: &str = "org.freedesktop.NetworkManager"; diff --git a/src/clients/sysinfo.rs b/src/clients/sysinfo.rs index 847d2a8..ac5cce5 100644 --- a/src/clients/sysinfo.rs +++ b/src/clients/sysinfo.rs @@ -394,7 +394,7 @@ impl Client { } /// Gets system uptime formatted as `HH:mm`. - pub fn uptime(&self) -> String { + pub fn uptime() -> String { let uptime = System::uptime(); let hours = uptime / 3600; format!("{:0>2}:{:0>2}", hours, (uptime % 3600) / 60) @@ -513,7 +513,7 @@ impl Namespace for Client { TokenType::LoadAverage1 => get(self.load_average_1()), TokenType::LoadAverage5 => get(self.load_average_5()), TokenType::LoadAverage15 => get(self.load_average_15()), - TokenType::Uptime => Some(self.uptime()), + TokenType::Uptime => Some(Client::uptime()), } } diff --git a/src/clients/upower/dbus.rs b/src/clients/upower/dbus.rs index 3c265fd..c3733d6 100644 --- a/src/clients/upower/dbus.rs +++ b/src/clients/upower/dbus.rs @@ -1,5 +1,5 @@ /// Originally taken from `upower-dbus` crate -/// https://github.com/pop-os/upower-dbus/blob/main/LICENSE +/// // Copyright 2021 System76 // SPDX-License-Identifier: MPL-2.0 use zbus::proxy; diff --git a/src/clients/volume/mod.rs b/src/clients/volume/mod.rs index 3db503f..86b1e18 100644 --- a/src/clients/volume/mod.rs +++ b/src/clients/volume/mod.rs @@ -1,7 +1,7 @@ mod sink; mod sink_input; -use crate::{arc_mut, lock, register_client, send, spawn_blocking, APP_ID}; +use crate::{APP_ID, arc_mut, lock, register_client, send, spawn_blocking}; use libpulse_binding::callbacks::ListResult; use libpulse_binding::context::introspect::{Introspector, ServerInfo}; use libpulse_binding::context::subscribe::{Facility, InterestMaskSet, Operation}; diff --git a/src/clients/volume/sink.rs b/src/clients/volume/sink.rs index d08b99e..6750387 100644 --- a/src/clients/volume/sink.rs +++ b/src/clients/volume/sink.rs @@ -1,11 +1,11 @@ -use super::{percent_to_volume, volume_to_percent, ArcMutVec, Client, ConnectionState, Event}; +use super::{ArcMutVec, Client, ConnectionState, Event, percent_to_volume, volume_to_percent}; use crate::{lock, send}; use libpulse_binding::callbacks::ListResult; +use libpulse_binding::context::Context; use libpulse_binding::context::introspect::SinkInfo; use libpulse_binding::context::subscribe::Operation; -use libpulse_binding::context::Context; use libpulse_binding::def::SinkState; -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use tokio::sync::broadcast; use tracing::{debug, error}; diff --git a/src/clients/volume/sink_input.rs b/src/clients/volume/sink_input.rs index 102aed2..14142f0 100644 --- a/src/clients/volume/sink_input.rs +++ b/src/clients/volume/sink_input.rs @@ -1,10 +1,10 @@ -use super::{percent_to_volume, volume_to_percent, ArcMutVec, Client, ConnectionState, Event}; +use super::{ArcMutVec, Client, ConnectionState, Event, percent_to_volume, volume_to_percent}; use crate::{lock, send}; use libpulse_binding::callbacks::ListResult; +use libpulse_binding::context::Context; use libpulse_binding::context::introspect::SinkInputInfo; use libpulse_binding::context::subscribe::Operation; -use libpulse_binding::context::Context; -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use tokio::sync::broadcast; use tracing::{debug, error}; diff --git a/src/clients/wayland/mod.rs b/src/clients/wayland/mod.rs index c338075..abeeac8 100644 --- a/src/clients/wayland/mod.rs +++ b/src/clients/wayland/mod.rs @@ -2,7 +2,7 @@ mod macros; mod wl_output; mod wl_seat; -use crate::error::{ExitCode, ERR_CHANNEL_RECV}; +use crate::error::{ERR_CHANNEL_RECV, ExitCode}; use crate::{arc_mut, lock, register_client, send, spawn, spawn_blocking}; use std::process::exit; use std::sync::{Arc, Mutex}; @@ -11,8 +11,8 @@ use calloop_channel::Event::Msg; use cfg_if::cfg_if; use color_eyre::Report; use smithay_client_toolkit::output::OutputState; -use smithay_client_toolkit::reexports::calloop::channel as calloop_channel; use smithay_client_toolkit::reexports::calloop::EventLoop; +use smithay_client_toolkit::reexports::calloop::channel as calloop_channel; use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource; use smithay_client_toolkit::registry::{ProvidesRegistryState, RegistryState}; use smithay_client_toolkit::seat::SeatState; diff --git a/src/clients/wayland/wlr_data_control/device.rs b/src/clients/wayland/wlr_data_control/device.rs index 08e90c8..01279cc 100644 --- a/src/clients/wayland/wlr_data_control/device.rs +++ b/src/clients/wayland/wlr_data_control/device.rs @@ -6,7 +6,7 @@ use crate::error::ERR_WAYLAND_DATA; use crate::lock; use std::sync::{Arc, Mutex}; use tracing::warn; -use wayland_client::{event_created_child, Connection, Dispatch, Proxy, QueueHandle}; +use wayland_client::{Connection, Dispatch, Proxy, QueueHandle, event_created_child}; use wayland_protocols_wlr::data_control::v1::client::{ zwlr_data_control_device_v1::{Event, ZwlrDataControlDeviceV1}, zwlr_data_control_offer_v1::ZwlrDataControlOfferV1, @@ -37,7 +37,9 @@ pub trait DataControlDeviceDataExt: Send + Sync { fn selection_mime_types(&self) -> Vec { let inner = self.data_control_device_data(); - lock!(lock!(inner.inner).selection_offer) + let offer = &lock!(inner.inner).selection_offer; + + lock!(offer) .as_ref() .map(|offer| { let data = offer @@ -51,14 +53,14 @@ pub trait DataControlDeviceDataExt: Send + Sync { /// Get the active selection offer if it exists. fn selection_offer(&self) -> Option { let inner = self.data_control_device_data(); - lock!(lock!(inner.inner).selection_offer) - .as_ref() - .and_then(|offer| { - let data = offer - .data::() - .expect(ERR_WAYLAND_DATA); - data.as_selection_offer() - }) + let offer = &lock!(inner.inner).selection_offer; + + lock!(offer).as_ref().and_then(|offer| { + let data = offer + .data::() + .expect(ERR_WAYLAND_DATA); + data.as_selection_offer() + }) } } @@ -159,7 +161,9 @@ where } } Event::Finished => { - warn!("Data control offer is no longer valid, but has not been dropped by client. This could cause clipboard issues."); + warn!( + "Data control offer is no longer valid, but has not been dropped by client. This could cause clipboard issues." + ); } _ => {} } diff --git a/src/clients/wayland/wlr_data_control/mod.rs b/src/clients/wayland/wlr_data_control/mod.rs index 1891155..71f42e8 100644 --- a/src/clients/wayland/wlr_data_control/mod.rs +++ b/src/clients/wayland/wlr_data_control/mod.rs @@ -7,10 +7,10 @@ use self::device::{DataControlDeviceDataExt, DataControlDeviceHandler}; use self::offer::{DataControlDeviceOffer, DataControlOfferHandler}; use self::source::DataControlSourceHandler; use super::{Client, Environment, Event, Request, Response}; -use crate::{lock, spawn, try_send, Ironbar}; +use crate::{Ironbar, lock, spawn, try_send}; use device::DataControlDevice; use glib::Bytes; -use nix::fcntl::{fcntl, F_GETPIPE_SZ, F_SETPIPE_SZ}; +use nix::fcntl::{F_GETPIPE_SZ, F_SETPIPE_SZ, fcntl}; use nix::sys::epoll::{Epoll, EpollCreateFlags, EpollEvent, EpollFlags, EpollTimeout}; use smithay_client_toolkit::data_device_manager::WritePipe; use std::cmp::min; diff --git a/src/clients/wayland/wlr_foreign_toplevel/handle.rs b/src/clients/wayland/wlr_foreign_toplevel/handle.rs index 779d2ae..41f86fd 100644 --- a/src/clients/wayland/wlr_foreign_toplevel/handle.rs +++ b/src/clients/wayland/wlr_foreign_toplevel/handle.rs @@ -1,5 +1,5 @@ use super::manager::ToplevelManagerState; -use crate::{lock, Ironbar}; +use crate::{Ironbar, lock}; use std::collections::HashSet; use std::sync::{Arc, Mutex}; use tracing::trace; diff --git a/src/clients/wayland/wlr_foreign_toplevel/manager.rs b/src/clients/wayland/wlr_foreign_toplevel/manager.rs index 416d0ac..e2c34fa 100644 --- a/src/clients/wayland/wlr_foreign_toplevel/manager.rs +++ b/src/clients/wayland/wlr_foreign_toplevel/manager.rs @@ -4,7 +4,7 @@ use smithay_client_toolkit::globals::{GlobalData, ProvidesBoundGlobal}; use std::marker::PhantomData; use tracing::{debug, warn}; use wayland_client::globals::{BindError, GlobalList}; -use wayland_client::{event_created_child, Connection, Dispatch, QueueHandle}; +use wayland_client::{Connection, Dispatch, QueueHandle, event_created_child}; use wayland_protocols_wlr::foreign_toplevel::v1::client::{ zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, zwlr_foreign_toplevel_manager_v1::{Event, ZwlrForeignToplevelManagerV1}, @@ -67,7 +67,9 @@ where state.toplevel(conn, qhandle); } Event::Finished => { - warn!("Foreign toplevel manager is no longer valid, but has not been dropped by client. This could cause window tracking issues."); + warn!( + "Foreign toplevel manager is no longer valid, but has not been dropped by client. This could cause window tracking issues." + ); } _ => {} } diff --git a/src/config/common.rs b/src/config/common.rs index 855a3dc..33e2d42 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -1,4 +1,4 @@ -use crate::dynamic_value::{dynamic_string, DynamicBool}; +use crate::dynamic_value::{DynamicBool, dynamic_string}; use crate::script::{Script, ScriptInput}; use glib::Propagation; use gtk::gdk::ScrollDirection; diff --git a/src/config/impl.rs b/src/config/impl.rs index cab524f..696db62 100644 --- a/src/config/impl.rs +++ b/src/config/impl.rs @@ -52,9 +52,9 @@ where } #[cfg(feature = "schema")] -pub fn schema_layer(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { +pub fn schema_layer(generator: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema { use schemars::JsonSchema; - let mut schema: schemars::schema::SchemaObject = ::json_schema(gen).into(); + let mut schema: schemars::schema::SchemaObject = ::json_schema(generator).into(); schema.enum_values = Some(vec![ "background".into(), "bottom".into(), diff --git a/src/desktop_file.rs b/src/desktop_file.rs index 375b198..558743e 100644 --- a/src/desktop_file.rs +++ b/src/desktop_file.rs @@ -31,7 +31,7 @@ fn find_application_dirs() -> Vec { let xdg_dirs = env::var_os("XDG_DATA_DIRS"); if let Some(xdg_dirs) = xdg_dirs { - for mut xdg_dir in env::split_paths(&xdg_dirs).map(PathBuf::from) { + for mut xdg_dir in env::split_paths(&xdg_dirs) { xdg_dir.push("applications"); dirs.push(xdg_dir); } diff --git a/src/dynamic_value/dynamic_bool.rs b/src/dynamic_value/dynamic_bool.rs index 4b69cc3..5833fbe 100644 --- a/src/dynamic_value/dynamic_bool.rs +++ b/src/dynamic_value/dynamic_bool.rs @@ -1,7 +1,7 @@ use crate::script::Script; -use crate::{glib_recv_mpsc, spawn, try_send}; #[cfg(feature = "ipc")] -use crate::{send_async, Ironbar}; +use crate::{Ironbar, send_async}; +use crate::{glib_recv_mpsc, spawn, try_send}; use cfg_if::cfg_if; use serde::Deserialize; use tokio::sync::mpsc; diff --git a/src/dynamic_value/dynamic_string.rs b/src/dynamic_value/dynamic_string.rs index a33f89c..057da5e 100644 --- a/src/dynamic_value/dynamic_string.rs +++ b/src/dynamic_value/dynamic_string.rs @@ -1,6 +1,6 @@ -use crate::script::{OutputStream, Script}; #[cfg(feature = "ipc")] use crate::Ironbar; +use crate::script::{OutputStream, Script}; use crate::{arc_mut, glib_recv_mpsc, lock, spawn, try_send}; use tokio::sync::mpsc; diff --git a/src/gtk_helpers.rs b/src/gtk_helpers.rs index c4bc58e..9c68541 100644 --- a/src/gtk_helpers.rs +++ b/src/gtk_helpers.rs @@ -1,5 +1,5 @@ use crate::config::TruncateMode; -use glib::{markup_escape_text, IsA}; +use glib::{IsA, markup_escape_text}; use gtk::pango::EllipsizeMode; use gtk::prelude::*; use gtk::{Label, Orientation, Widget}; diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs index 9f58a6b..695200d 100644 --- a/src/ipc/mod.rs +++ b/src/ipc/mod.rs @@ -23,7 +23,9 @@ impl Ipc { .join("ironbar-ipc.sock"); if format!("{}", ipc_socket_file.display()).len() > 100 { - warn!("The IPC socket file's absolute path exceeds 100 bytes, the socket may fail to create."); + warn!( + "The IPC socket file's absolute path exceeds 100 bytes, the socket may fail to create." + ); } Self { diff --git a/src/ipc/server/bar.rs b/src/ipc/server/bar.rs index d5c42c5..3f4b2f3 100644 --- a/src/ipc/server/bar.rs +++ b/src/ipc/server/bar.rs @@ -1,11 +1,11 @@ use super::Response; +use crate::Ironbar; use crate::bar::Bar; use crate::ipc::{BarCommand, BarCommandType}; use crate::modules::PopupButton; -use crate::Ironbar; use std::rc::Rc; -pub fn handle_command(command: BarCommand, ironbar: &Rc) -> Response { +pub fn handle_command(command: &BarCommand, ironbar: &Rc) -> Response { use BarCommandType::*; let bars = ironbar.bars_by_name(&command.name); diff --git a/src/ipc/server/ironvar.rs b/src/ipc/server/ironvar.rs index 2689c53..4b82e7c 100644 --- a/src/ipc/server/ironvar.rs +++ b/src/ipc/server/ironvar.rs @@ -1,7 +1,6 @@ -use crate::ipc::commands::IronvarCommand; -use crate::ipc::Response; -use crate::ironvar::{Namespace, WritableNamespace}; use crate::Ironbar; +use crate::ipc::{IronvarCommand, Response}; +use crate::ironvar::{Namespace, WritableNamespace}; use std::sync::Arc; pub fn handle_command(command: IronvarCommand) -> Response { diff --git a/src/ipc/server/mod.rs b/src/ipc/server/mod.rs index 463e8fa..e6592e2 100644 --- a/src/ipc/server/mod.rs +++ b/src/ipc/server/mod.rs @@ -6,8 +6,8 @@ use std::path::Path; use std::rc::Rc; use color_eyre::{Report, Result}; -use gtk::prelude::*; use gtk::Application; +use gtk::prelude::*; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::{UnixListener, UnixStream}; use tokio::sync::mpsc::{self, Receiver, Sender}; @@ -15,7 +15,7 @@ use tracing::{debug, error, info, warn}; use crate::ipc::{Command, Response}; use crate::style::load_css; -use crate::{glib_recv_mpsc, send_async, spawn, try_send, Ironbar}; +use crate::{Ironbar, glib_recv_mpsc, send_async, spawn, try_send}; use super::Ipc; @@ -150,7 +150,7 @@ impl Ipc { } } Command::Var(cmd) => ironvar::handle_command(cmd), - Command::Bar(cmd) => bar::handle_command(cmd, ironbar), + Command::Bar(cmd) => bar::handle_command(&cmd, ironbar), } } diff --git a/src/logging.rs b/src/logging.rs index 6ba97c7..e048e62 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -9,7 +9,7 @@ use tracing_appender::rolling::Rotation; use tracing_error::ErrorLayer; use tracing_subscriber::fmt::{Layer, MakeWriter}; use tracing_subscriber::prelude::*; -use tracing_subscriber::{fmt, EnvFilter}; +use tracing_subscriber::{EnvFilter, fmt}; struct MakeFileWriter { file_writer: NonBlocking, @@ -32,7 +32,11 @@ impl<'a> MakeWriter<'a> for MakeFileWriter { pub fn install_logging() -> Result { // Disable backtraces by default if env::var("RUST_LIB_BACKTRACE").is_err() { - env::set_var("RUST_LIB_BACKTRACE", "0"); + // as this is the very first thing we do (before runtimes are set up) + // we can be sure that it only runs in a single-thread context + unsafe { + env::set_var("RUST_LIB_BACKTRACE", "0"); + } } // keep guard in scope diff --git a/src/main.rs b/src/main.rs index 6456a05..abed965 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,26 +7,26 @@ use std::path::PathBuf; use std::process::exit; use std::rc::Rc; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::{mpsc, Arc, Mutex, OnceLock}; +use std::sync::{Arc, Mutex, OnceLock, mpsc}; use cfg_if::cfg_if; #[cfg(feature = "cli")] use clap::Parser; -use color_eyre::eyre::Result; use color_eyre::Report; +use color_eyre::eyre::Result; use dirs::config_dir; +use gtk::Application; use gtk::gdk::Display; use gtk::prelude::*; -use gtk::Application; use smithay_client_toolkit::output::OutputInfo; use tokio::runtime::Runtime; -use tokio::task::{block_in_place, JoinHandle}; +use tokio::task::{JoinHandle, block_in_place}; use tracing::{debug, error, info, warn}; use universal_config::ConfigLoader; -use crate::bar::{create_bar, Bar}; -use crate::clients::wayland::OutputEventType; +use crate::bar::{Bar, create_bar}; use crate::clients::Clients; +use crate::clients::wayland::OutputEventType; use crate::config::{Config, MonitorConfig}; use crate::error::ExitCode; #[cfg(feature = "ipc")] diff --git a/src/modules/cairo.rs b/src/modules/cairo.rs index b5c144f..7b88989 100644 --- a/src/modules/cairo.rs +++ b/src/modules/cairo.rs @@ -2,13 +2,13 @@ use crate::config::CommonConfig; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{glib_recv, module_impl, spawn, try_send}; use cairo::{Format, ImageSurface}; -use glib::translate::IntoGlibPtr; use glib::Propagation; -use gtk::prelude::*; +use glib::translate::IntoGlibPtr; use gtk::DrawingArea; +use gtk::prelude::*; use mlua::{Error, Function, LightUserData}; use notify::event::ModifyKind; -use notify::{recommended_watcher, Event, EventKind, RecursiveMode, Watcher}; +use notify::{Event, EventKind, RecursiveMode, Watcher, recommended_watcher}; use serde::Deserialize; use std::fs; use std::path::PathBuf; diff --git a/src/modules/custom/image.rs b/src/modules/custom/image.rs index fe46b5d..96d6ae4 100644 --- a/src/modules/custom/image.rs +++ b/src/modules/custom/image.rs @@ -1,5 +1,5 @@ -use gtk::prelude::*; use gtk::Image; +use gtk::prelude::*; use serde::Deserialize; use crate::build; diff --git a/src/modules/custom/label.rs b/src/modules/custom/label.rs index 26a1ad5..4e35ad9 100644 --- a/src/modules/custom/label.rs +++ b/src/modules/custom/label.rs @@ -1,5 +1,5 @@ -use gtk::prelude::*; use gtk::Label; +use gtk::prelude::*; use serde::Deserialize; use super::{CustomWidget, CustomWidgetContext}; diff --git a/src/modules/custom/mod.rs b/src/modules/custom/mod.rs index 9ef32eb..2a7c926 100644 --- a/src/modules/custom/mod.rs +++ b/src/modules/custom/mod.rs @@ -5,16 +5,16 @@ mod label; mod progress; mod slider; +use self::r#box::BoxWidget; use self::image::ImageWidget; use self::label::LabelWidget; -use self::r#box::BoxWidget; use self::slider::SliderWidget; use crate::config::{CommonConfig, ModuleConfig}; use crate::modules::custom::button::ButtonWidget; use crate::modules::custom::progress::ProgressWidget; use crate::modules::{ - wrap_widget, AnyModuleFactory, BarModuleFactory, Module, ModuleInfo, ModuleParts, ModulePopup, - ModuleUpdateEvent, PopupButton, PopupModuleFactory, WidgetContext, + AnyModuleFactory, BarModuleFactory, Module, ModuleInfo, ModuleParts, ModulePopup, + ModuleUpdateEvent, PopupButton, PopupModuleFactory, WidgetContext, wrap_widget, }; use crate::script::Script; use crate::{module_impl, send_async, spawn}; diff --git a/src/modules/custom/progress.rs b/src/modules/custom/progress.rs index 1d9f40e..98c6dea 100644 --- a/src/modules/custom/progress.rs +++ b/src/modules/custom/progress.rs @@ -1,5 +1,5 @@ -use gtk::prelude::*; use gtk::ProgressBar; +use gtk::prelude::*; use serde::Deserialize; use tokio::sync::mpsc; use tracing::error; diff --git a/src/modules/custom/slider.rs b/src/modules/custom/slider.rs index bc5ea7f..2c6d2c0 100644 --- a/src/modules/custom/slider.rs +++ b/src/modules/custom/slider.rs @@ -2,8 +2,8 @@ use glib::Propagation; use std::cell::Cell; use std::ops::Neg; -use gtk::prelude::*; use gtk::Scale; +use gtk::prelude::*; use serde::Deserialize; use tokio::sync::mpsc; use tracing::error; diff --git a/src/modules/focused.rs b/src/modules/focused.rs index 87fc81d..9d48571 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -6,8 +6,8 @@ use crate::image::ImageProvider; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{glib_recv, module_impl, send_async, spawn, try_send}; use color_eyre::Result; -use gtk::prelude::*; use gtk::Label; +use gtk::prelude::*; use serde::Deserialize; use tokio::sync::mpsc; use tracing::debug; diff --git a/src/modules/keyboard.rs b/src/modules/keyboard.rs index 8900e67..afb22b1 100644 --- a/src/modules/keyboard.rs +++ b/src/modules/keyboard.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use color_eyre::eyre::Report; use color_eyre::Result; -use gtk::{prelude::*, Button}; +use color_eyre::eyre::Report; +use gtk::{Button, prelude::*}; use serde::Deserialize; use tokio::sync::mpsc; use tracing::{debug, trace}; @@ -217,7 +217,9 @@ impl Module for KeyboardModule { module_update!(tx, KeyboardUpdate::Layout(payload)); } Err(tokio::sync::broadcast::error::RecvError::Lagged(count)) => { - tracing::warn!("Channel lagged behind by {count}, this may result in unexpected or broken behaviour"); + tracing::warn!( + "Channel lagged behind by {count}, this may result in unexpected or broken behaviour" + ); } Err(err) => { tracing::error!("{err:?}"); diff --git a/src/modules/launcher/item.rs b/src/modules/launcher/item.rs index 0bcd265..3b894bd 100644 --- a/src/modules/launcher/item.rs +++ b/src/modules/launcher/item.rs @@ -3,8 +3,8 @@ use crate::clients::wayland::ToplevelInfo; use crate::config::{BarPosition, TruncateMode}; use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::image::ImageProvider; -use crate::modules::launcher::{ItemEvent, LauncherUpdate}; use crate::modules::ModuleUpdateEvent; +use crate::modules::launcher::{ItemEvent, LauncherUpdate}; use crate::{read_lock, try_send}; use glib::Propagation; use gtk::gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}; diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 12d35f8..e23a406 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -221,7 +221,7 @@ impl Module for LauncherModule { let icon_override = info .icon_overrides .get(app_id) - .map_or_else(String::new, |v| v.to_string()); + .map_or_else(String::new, ToString::to_string); ( app_id.to_string(), @@ -250,19 +250,16 @@ impl Module for LauncherModule { for info in handles { let mut items = lock!(items); let item = items.get_mut(&info.app_id); - match item { - Some(item) => { - item.merge_toplevel(info.clone()); - } - None => { - let mut item = Item::from(info.clone()); + if let Some(item) = item { + item.merge_toplevel(info.clone()); + } else { + let mut item = Item::from(info.clone()); - if let Some(icon) = icon_overrides.get(&info.app_id) { - item.icon_override = icon.clone(); - } - - items.insert(info.app_id.clone(), item); + if let Some(icon) = icon_overrides.get(&info.app_id) { + item.icon_override.clone_from(icon); } + + items.insert(info.app_id.clone(), item); } } @@ -294,7 +291,7 @@ impl Module for LauncherModule { let mut item: Item = info.into(); if let Some(icon) = icon_overrides.get(&app_id) { - item.icon_override = icon.clone(); + item.icon_override.clone_from(icon); } items.insert(app_id.clone(), item.clone()); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index e1b8335..d7f25e2 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -15,7 +15,7 @@ use crate::clients::{ClientResult, ProvidesClient, ProvidesFallibleClient}; use crate::config::{BarPosition, CommonConfig, TransitionType}; use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry}; use crate::popup::Popup; -use crate::{glib_recv_mpsc, send, Ironbar}; +use crate::{Ironbar, glib_recv_mpsc, send}; #[cfg(feature = "cairo")] pub mod cairo; diff --git a/src/modules/music/mod.rs b/src/modules/music/mod.rs index dc2796b..2c1f6db 100644 --- a/src/modules/music/mod.rs +++ b/src/modules/music/mod.rs @@ -1,7 +1,7 @@ use std::cell::RefMut; use std::path::PathBuf; -use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; use color_eyre::Result; @@ -12,12 +12,12 @@ use regex::Regex; use tokio::sync::{broadcast, mpsc}; use tracing::error; +use crate::clients::Clients; use crate::clients::music::{ self, MusicClient, PlayerState, PlayerUpdate, ProgressTick, Status, Track, }; -use crate::clients::Clients; use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; -use crate::image::{new_icon_button, IconLabel, ImageProvider}; +use crate::image::{IconLabel, ImageProvider, new_icon_button}; use crate::modules::PopupButton; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext, diff --git a/src/modules/script.rs b/src/modules/script.rs index b2ec0ca..e1e7c28 100644 --- a/src/modules/script.rs +++ b/src/modules/script.rs @@ -4,8 +4,8 @@ use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetC use crate::script::{OutputStream, Script, ScriptMode}; use crate::{glib_recv, module_impl, spawn, try_send}; use color_eyre::{Help, Report, Result}; -use gtk::prelude::*; use gtk::Label; +use gtk::prelude::*; use serde::Deserialize; use tokio::sync::mpsc; use tracing::error; diff --git a/src/modules/sway/mode.rs b/src/modules/sway/mode.rs index b9bcbaa..ba573e2 100644 --- a/src/modules/sway/mode.rs +++ b/src/modules/sway/mode.rs @@ -3,8 +3,8 @@ use crate::gtk_helpers::IronbarLabelExt; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{await_sync, glib_recv, module_impl, try_send}; use color_eyre::{Report, Result}; -use gtk::prelude::*; use gtk::Label; +use gtk::prelude::*; use serde::Deserialize; use swayipc_async::ModeEvent; use tokio::sync::mpsc; diff --git a/src/modules/sysinfo/mod.rs b/src/modules/sysinfo/mod.rs index fbab5b0..ffb888b 100644 --- a/src/modules/sysinfo/mod.rs +++ b/src/modules/sysinfo/mod.rs @@ -9,8 +9,8 @@ use crate::modules::sysinfo::token::Part; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{clients, glib_recv, module_impl, send_async, spawn, try_send}; use color_eyre::Result; -use gtk::prelude::*; use gtk::Label; +use gtk::prelude::*; use serde::Deserialize; use std::time::Duration; use tokio::sync::mpsc; diff --git a/src/modules/sysinfo/renderer.rs b/src/modules/sysinfo/renderer.rs index 050fac6..6219104 100644 --- a/src/modules/sysinfo/renderer.rs +++ b/src/modules/sysinfo/renderer.rs @@ -1,5 +1,5 @@ -use super::token::{Alignment, Part, Token}; use super::Interval; +use super::token::{Alignment, Part, Token}; use crate::clients; use crate::clients::sysinfo::{TokenType, Value, ValueSet}; @@ -85,7 +85,7 @@ impl Token { TokenType::LoadAverage15 => get(client.load_average_15()), // String tokens - TokenType::Uptime => TokenValue::String(client.uptime()), + TokenType::Uptime => TokenValue::String(clients::sysinfo::Client::uptime()), } } } diff --git a/src/modules/tray/mod.rs b/src/modules/tray/mod.rs index ca76289..0589bb2 100644 --- a/src/modules/tray/mod.rs +++ b/src/modules/tray/mod.rs @@ -65,7 +65,10 @@ impl Module for TrayModule { let client = context.try_client::()?; let mut tray_rx = client.subscribe(); - let initial_items = lock!(client.items()).clone(); + let initial_items = { + let items = client.items(); + lock!(items).clone() + }; // listen to tray updates spawn(async move { diff --git a/src/modules/upower.rs b/src/modules/upower.rs index 478af03..2b27b85 100644 --- a/src/modules/upower.rs +++ b/src/modules/upower.rs @@ -1,6 +1,6 @@ use color_eyre::Result; use futures_lite::stream::StreamExt; -use gtk::{prelude::*, Button}; +use gtk::{Button, prelude::*}; use gtk::{Label, Orientation}; use serde::Deserialize; use tokio::sync::{broadcast, mpsc}; diff --git a/src/modules/workspaces/button.rs b/src/modules/workspaces/button.rs index 94fba39..419feb0 100644 --- a/src/modules/workspaces/button.rs +++ b/src/modules/workspaces/button.rs @@ -3,8 +3,8 @@ use crate::gtk_helpers::IronbarGtkExt; use crate::image::new_icon_button; use crate::modules::workspaces::WorkspaceItemContext; use crate::try_send; -use gtk::prelude::*; use gtk::Button as GtkButton; +use gtk::prelude::*; #[derive(Debug, Clone)] pub struct Button { diff --git a/src/modules/workspaces/mod.rs b/src/modules/workspaces/mod.rs index 9f1b14a..854f7c7 100644 --- a/src/modules/workspaces/mod.rs +++ b/src/modules/workspaces/mod.rs @@ -10,8 +10,8 @@ use crate::modules::workspaces::open_state::OpenState; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{glib_recv, module_impl, send_async, spawn}; use color_eyre::{Report, Result}; -use gtk::prelude::*; use gtk::IconTheme; +use gtk::prelude::*; use serde::Deserialize; use std::cmp::Ordering; use std::collections::HashMap; diff --git a/src/popup.rs b/src/popup.rs index 63ad5a8..1dc972e 100644 --- a/src/popup.rs +++ b/src/popup.rs @@ -7,7 +7,7 @@ use crate::clients::wayland::{OutputEvent, OutputEventType}; use crate::config::BarPosition; use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry}; use crate::modules::{ModuleInfo, ModulePopupParts, PopupButton}; -use crate::{glib_recv, rc_mut, Ironbar}; +use crate::{Ironbar, glib_recv, rc_mut}; use gtk::prelude::*; use gtk::{ApplicationWindow, Button, Orientation}; use gtk_layer_shell::LayerShell; diff --git a/src/style.rs b/src/style.rs index 2bf8ed9..b529413 100644 --- a/src/style.rs +++ b/src/style.rs @@ -2,9 +2,9 @@ use crate::{glib_recv_mpsc, spawn, try_send}; use color_eyre::{Help, Report}; use gtk::ffi::GTK_STYLE_PROVIDER_PRIORITY_USER; use gtk::prelude::*; -use gtk::{gdk, gio, Application, CssProvider, StyleContext}; +use gtk::{Application, CssProvider, StyleContext, gdk, gio}; use notify::event::ModifyKind; -use notify::{recommended_watcher, Event, EventKind, RecursiveMode, Result, Watcher}; +use notify::{Event, EventKind, RecursiveMode, Result, Watcher, recommended_watcher}; use std::env; use std::path::PathBuf; use std::time::Duration;