1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 10:41:03 +02:00

refactor: fix new clippy warnings

This commit is contained in:
Jake Stanger 2023-06-29 16:57:47 +01:00
parent 27f920d012
commit cc181a8b6d
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
13 changed files with 42 additions and 43 deletions

View file

@ -207,7 +207,7 @@ fn add_modules(
}}; }};
} }
for config in modules.into_iter() { for config in modules {
let id = get_unique_usize(); let id = get_unique_usize();
match config { match config {
#[cfg(feature = "clipboard")] #[cfg(feature = "clipboard")]

View file

@ -38,7 +38,8 @@ impl ClipboardClient {
spawn(async move { spawn(async move {
let (mut rx, item) = { let (mut rx, item) = {
let wl = wayland::get_client().await; let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_clipboard() wl.subscribe_clipboard()
}; };
@ -111,7 +112,7 @@ impl ClipboardClient {
rx rx
} }
pub async fn copy(&self, id: usize) { pub fn copy(&self, id: usize) {
debug!("Copying item with id {id}"); debug!("Copying item with id {id}");
let item = { let item = {
@ -120,7 +121,8 @@ impl ClipboardClient {
}; };
if let Some(item) = item { if let Some(item) = item {
let wl = wayland::get_client().await; let wl = wayland::get_client();
let wl = lock!(wl);
wl.copy_to_clipboard(item); wl.copy_to_clipboard(item);
} }

View file

@ -31,7 +31,7 @@ impl TrayEventReceiver {
let (b_tx, b_rx) = broadcast::channel(16); let (b_tx, b_rx) = broadcast::channel(16);
let tray = StatusNotifierWatcher::new(rx).await?; let tray = StatusNotifierWatcher::new(rx).await?;
let mut host = tray.create_notifier_host(&id).await?; let mut host = Box::pin(tray.create_notifier_host(&id)).await?;
let tray = Arc::new(Mutex::new(BTreeMap::new())); let tray = Arc::new(Mutex::new(BTreeMap::new()));
@ -106,7 +106,7 @@ lazy_static! {
let value = loop { let value = loop {
retries += 1; retries += 1;
let tray = TrayEventReceiver::new().await; let tray = Box::pin(TrayEventReceiver::new()).await;
match tray { match tray {
Ok(tray) => break Some(tray), Ok(tray) => break Some(tray),

View file

@ -6,7 +6,7 @@ use zbus::fdo::PropertiesProxy;
lazy_static! { lazy_static! {
static ref DISPLAY_PROXY: AsyncOnce<Arc<PropertiesProxy<'static>>> = AsyncOnce::new(async { static ref DISPLAY_PROXY: AsyncOnce<Arc<PropertiesProxy<'static>>> = AsyncOnce::new(async {
let dbus = zbus::Connection::system() let dbus = Box::pin(zbus::Connection::system())
.await .await
.expect("failed to create connection to system bus"); .expect("failed to create connection to system bus");

View file

@ -71,7 +71,7 @@ pub struct WaylandClient {
} }
impl WaylandClient { impl WaylandClient {
pub(super) async fn new() -> Self { pub(super) fn new() -> Self {
let (toplevel_tx, toplevel_rx) = broadcast::channel(32); let (toplevel_tx, toplevel_rx) = broadcast::channel(32);
let (toplevel_init_tx, toplevel_init_rx) = mpsc::channel(); let (toplevel_init_tx, toplevel_init_rx) = mpsc::channel();

View file

@ -1,6 +1,6 @@
/// It is necessary to store macros in a separate file due to a compilation error. /// It is necessary to store macros in a separate file due to a compilation error.
/// I believe this stems from the feature flags. /// I believe this stems from the feature flags.
/// Related issue: https://github.com/rust-lang/rust/issues/81066 /// Related issue: <https://github.com/rust-lang/rust/issues/81066>
// --- Data Control Device --- \\ // --- Data Control Device --- \\

View file

@ -7,7 +7,6 @@ mod wlr_foreign_toplevel;
use self::wlr_foreign_toplevel::manager::ToplevelManagerState; use self::wlr_foreign_toplevel::manager::ToplevelManagerState;
use crate::{delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager}; use crate::{delegate_foreign_toplevel_handle, delegate_foreign_toplevel_manager};
use async_once::AsyncOnce;
use cfg_if::cfg_if; use cfg_if::cfg_if;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use smithay_client_toolkit::output::OutputState; use smithay_client_toolkit::output::OutputState;
@ -18,6 +17,7 @@ use smithay_client_toolkit::{
delegate_output, delegate_registry, delegate_seat, registry_handlers, delegate_output, delegate_registry, delegate_seat, registry_handlers,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use tokio::sync::broadcast; use tokio::sync::broadcast;
use wayland_client::protocol::wl_seat::WlSeat; use wayland_client::protocol::wl_seat::WlSeat;
@ -33,7 +33,6 @@ cfg_if! {
use self::wlr_data_control::manager::DataControlDeviceManagerState; use self::wlr_data_control::manager::DataControlDeviceManagerState;
use self::wlr_data_control::source::CopyPasteSource; use self::wlr_data_control::source::CopyPasteSource;
use self::wlr_data_control::SelectionOfferItem; use self::wlr_data_control::SelectionOfferItem;
use std::sync::{Arc, Mutex};
pub use wlr_data_control::{ClipboardItem, ClipboardValue}; pub use wlr_data_control::{ClipboardItem, ClipboardValue};
@ -106,10 +105,9 @@ impl ProvidesRegistryState for Environment {
} }
lazy_static! { lazy_static! {
static ref CLIENT: AsyncOnce<WaylandClient> = static ref CLIENT: Arc<Mutex<WaylandClient>> = Arc::new(Mutex::new(WaylandClient::new()));
AsyncOnce::new(async { WaylandClient::new().await });
} }
pub async fn get_client() -> &'static WaylandClient { pub fn get_client() -> Arc<Mutex<WaylandClient>> {
CLIENT.get().await CLIENT.clone()
} }

View file

@ -291,14 +291,14 @@ impl DataControlSourceHandler for Environment {
let mut events = (0..16).map(|_| EpollEvent::empty()).collect::<Vec<_>>(); let mut events = (0..16).map(|_| EpollEvent::empty()).collect::<Vec<_>>();
let mut epoll_event = EpollEvent::new(EpollFlags::EPOLLOUT, 0); let mut epoll_event = EpollEvent::new(EpollFlags::EPOLLOUT, 0);
let epoll_fd = epoll_create().unwrap(); let epoll_fd = epoll_create().expect("to get valid file descriptor");
epoll_ctl( epoll_ctl(
epoll_fd, epoll_fd,
EpollOp::EpollCtlAdd, EpollOp::EpollCtlAdd,
fd.as_raw_fd(), fd.as_raw_fd(),
&mut epoll_event, &mut epoll_event,
) )
.unwrap(); .expect("to send valid epoll operation");
while !bytes.is_empty() { while !bytes.is_empty() {
let chunk = &bytes[..min(pipe_size as usize, bytes.len())]; let chunk = &bytes[..min(pipe_size as usize, bytes.len())];

View file

@ -151,9 +151,8 @@ where
lock!(data.inner).current_info = Some(pending_info); lock!(data.inner).current_info = Some(pending_info);
} }
if !lock!(data.inner).initial_done { if lock!(data.inner).initial_done {
lock!(data.inner).initial_done = true; state.update_handle(
state.new_handle(
conn, conn,
qh, qh,
ToplevelHandle { ToplevelHandle {
@ -161,7 +160,8 @@ where
}, },
); );
} else { } else {
state.update_handle( lock!(data.inner).initial_done = true;
state.new_handle(
conn, conn,
qh, qh,
ToplevelHandle { ToplevelHandle {

View file

@ -46,7 +46,7 @@ use tokio::runtime::Handle;
use tokio::task::{block_in_place, spawn_blocking}; use tokio::task::{block_in_place, spawn_blocking};
use crate::error::ExitCode; use crate::error::ExitCode;
use clients::wayland::{self, WaylandClient}; use clients::wayland;
use tracing::{debug, error, info}; use tracing::{debug, error, info};
use universal_config::ConfigLoader; use universal_config::ConfigLoader;
@ -59,9 +59,9 @@ async fn main() {
cfg_if! { cfg_if! {
if #[cfg(feature = "cli")] { if #[cfg(feature = "cli")] {
run_with_args().await run_with_args().await;
} else { } else {
start_ironbar().await start_ironbar().await;
} }
} }
} }
@ -78,16 +78,14 @@ async fn run_with_args() {
Err(err) => error!("{err:?}"), Err(err) => error!("{err:?}"),
}; };
} }
None => start_ironbar().await, None => start_ironbar(),
} }
} }
async fn start_ironbar() { fn start_ironbar() {
info!("Ironbar version {}", VERSION); info!("Ironbar version {}", VERSION);
info!("Starting application"); info!("Starting application");
let wayland_client = wayland::get_client().await;
let app = Application::builder().application_id(GTK_APP_ID).build(); let app = Application::builder().application_id(GTK_APP_ID).build();
let running = Rc::new(Cell::new(false)); let running = Rc::new(Cell::new(false));
@ -141,7 +139,7 @@ async fn start_ironbar() {
} }
} }
if let Err(err) = create_bars(app, &display, wayland_client, &config) { if let Err(err) = create_bars(app, &display, &config) {
error!("{:?}", err); error!("{:?}", err);
exit(ExitCode::CreateBars as i32); exit(ExitCode::CreateBars as i32);
} }
@ -189,13 +187,9 @@ async fn start_ironbar() {
} }
/// Creates each of the bars across each of the (configured) outputs. /// Creates each of the bars across each of the (configured) outputs.
fn create_bars( fn create_bars(app: &Application, display: &Display, config: &Config) -> Result<()> {
app: &Application, let wl = wayland::get_client();
display: &Display, let outputs = lock!(wl).get_outputs();
wl: &WaylandClient,
config: &Config,
) -> Result<()> {
let outputs = wl.get_outputs();
debug!("Received {} outputs from Wayland", outputs.len()); debug!("Received {} outputs from Wayland", outputs.len());
debug!("Outputs: {:?}", outputs); debug!("Outputs: {:?}", outputs);

View file

@ -111,7 +111,7 @@ impl Module<Button> for ClipboardModule {
while let Some(event) = rx.recv().await { while let Some(event) = rx.recv().await {
let client = clipboard::get_client(); let client = clipboard::get_client();
match event { match event {
UIEvent::Copy(id) => client.copy(id).await, UIEvent::Copy(id) => client.copy(id),
UIEvent::Remove(id) => client.remove(id), UIEvent::Remove(id) => client.remove(id),
} }
} }

View file

@ -3,7 +3,7 @@ use crate::config::{CommonConfig, TruncateMode};
use crate::gtk_helpers::add_class; use crate::gtk_helpers::add_class;
use crate::image::ImageProvider; use crate::image::ImageProvider;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{send_async, try_send}; use crate::{lock, send_async, try_send};
use color_eyre::Result; use color_eyre::Result;
use glib::Continue; use glib::Continue;
use gtk::prelude::*; use gtk::prelude::*;
@ -52,7 +52,8 @@ impl Module<gtk::Box> for FocusedModule {
) -> Result<()> { ) -> Result<()> {
spawn(async move { spawn(async move {
let (mut wlrx, handles) = { let (mut wlrx, handles) = {
let wl = wayland::get_client().await; let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_toplevels() wl.subscribe_toplevels()
}; };

View file

@ -117,7 +117,8 @@ impl Module<gtk::Box> for LauncherModule {
let tx = tx2; let tx = tx2;
let (mut wlrx, handles) = { let (mut wlrx, handles) = {
let wl = wayland::get_client().await; let wl = wayland::get_client();
let wl = lock!(wl);
wl.subscribe_toplevels() wl.subscribe_toplevels()
}; };
@ -270,7 +271,7 @@ impl Module<gtk::Box> for LauncherModule {
} else { } else {
send_async!(tx, ModuleUpdateEvent::ClosePopup); send_async!(tx, ModuleUpdateEvent::ClosePopup);
let wl = wayland::get_client().await; let wl = wayland::get_client();
let items = lock!(items); let items = lock!(items);
let id = match event { let id = match event {
@ -291,13 +292,16 @@ impl Module<gtk::Box> for LauncherModule {
{ {
debug!("Focusing window {id}: {}", window.name); debug!("Focusing window {id}: {}", window.name);
let seat = wl.get_seats().pop().expect("Failed to get Wayland seat"); let seat = lock!(wl)
.get_seats()
.pop()
.expect("Failed to get Wayland seat");
window.focus(&seat); window.focus(&seat);
} }
} }
// roundtrip to immediately send activate event // roundtrip to immediately send activate event
wl.roundtrip(); lock!(wl).roundtrip();
} }
} }
}); });