From 8877674f4321ceba5832f35b47911d8929c71147 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 8 Jan 2020 11:31:56 +0100 Subject: [PATCH] cargo fmt --- src/config.rs | 6 +++++- src/desktop.rs | 12 ++++++++--- src/main.rs | 37 ++++++++++++++++++++++++-------- src/widget.rs | 2 +- src/widgets/audio/alsa_sound.rs | 2 +- src/widgets/audio/pulse_sound.rs | 2 +- src/widgets/backlight.rs | 2 +- src/widgets/bar_widget.rs | 2 +- src/widgets/battery.rs | 34 ++++++++++++++++++----------- src/widgets/calendar.rs | 2 +- src/widgets/clock.rs | 2 +- src/widgets/date.rs | 2 +- src/widgets/launcher.rs | 16 ++++++++------ 13 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5d7c0df..7f217cc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -123,7 +123,11 @@ impl Widget { Err(_) => None, } } - Widget::Backlight { device, font_size, length } => { + Widget::Backlight { + device, + font_size, + length, + } => { let d = if device == "" { "intel_backlight" } else { diff --git a/src/desktop.rs b/src/desktop.rs index 359e5c6..f89de29 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -37,9 +37,15 @@ impl Desktop { hidden: desktop.get("Hidden").unwrap_or(&"".to_string()) == "true", exec: desktop.get("Exec").map(|x| x.to_string()), url: desktop.get("URL").map(|x| x.to_string()), - keywords: desktop.get("Keywords").map(|x| - x.split(";").map(|y| y.trim().to_string()).filter(|z| z != "").collect() - ).unwrap_or(vec![]), + keywords: desktop + .get("Keywords") + .map(|x| { + x.split(";") + .map(|y| y.trim().to_string()) + .filter(|z| z != "") + .collect() + }) + .unwrap_or(vec![]), }), None => Err(Box::new(io_error::new( ErrorKind::NotFound, diff --git a/src/main.rs b/src/main.rs index 04c1e9d..4af1560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,10 @@ use std::os::unix::io::AsRawFd; use std::os::unix::net::{UnixListener, UnixStream}; use std::sync::mpsc::channel; -use timerfd::{TimerFd, TimerState, SetTimeFlags}; +use chrono::{Duration, Local}; use nix::poll::{poll, PollFd, PollFlags}; use os_pipe::pipe; -use chrono::{Local, Duration}; +use timerfd::{SetTimeFlags, TimerFd, TimerState}; mod app; mod buffer; @@ -198,7 +198,7 @@ fn main() { app.cmd_queue().lock().unwrap().push_back(Cmd::Draw); let mut visible = !daemon; - let mut wait_ctx = WaitContext{ + let mut wait_ctx = WaitContext { fds: Vec::new(), target_time: None, }; @@ -275,13 +275,20 @@ fn main() { } else { Duration::seconds(0) }; - timer.set_state(TimerState::Oneshot(sleep.to_std().unwrap()), SetTimeFlags::Default); + timer.set_state( + TimerState::Oneshot(sleep.to_std().unwrap()), + SetTimeFlags::Default, + ); wait_ctx.fds.push(tm_fd); } poll(&mut wait_ctx.fds, -1).unwrap(); - if wait_ctx.fds[0].revents().unwrap().contains(PollFlags::POLLIN) { + if wait_ctx.fds[0] + .revents() + .unwrap() + .contains(PollFlags::POLLIN) + { if let Some(guard) = app.event_queue().prepare_read() { if let Err(e) = guard.read_events() { if e.kind() != ::std::io::ErrorKind::WouldBlock { @@ -298,12 +305,20 @@ fn main() { .expect("Failed to dispatch all messages."); } - if wait_ctx.fds[1].revents().unwrap().contains(PollFlags::POLLIN) { + if wait_ctx.fds[1] + .revents() + .unwrap() + .contains(PollFlags::POLLIN) + { let mut v = [0x00]; rx_pipe.read_exact(&mut v).unwrap(); } - if wait_ctx.fds[2].revents().unwrap().contains(PollFlags::POLLIN) { + if wait_ctx.fds[2] + .revents() + .unwrap() + .contains(PollFlags::POLLIN) + { if let Ok((stream, _)) = listener.accept() { let client_queue = q.clone(); let mut client_pipe = ipc_pipe.try_clone().unwrap(); @@ -331,8 +346,12 @@ fn main() { } } - if wait_ctx.target_time.is_some() && - wait_ctx.fds[wait_ctx.fds.len()-1].revents().unwrap().contains(PollFlags::POLLIN) { + if wait_ctx.target_time.is_some() + && wait_ctx.fds[wait_ctx.fds.len() - 1] + .revents() + .unwrap() + .contains(PollFlags::POLLIN) + { timer.read(); q.lock().unwrap().push_back(Cmd::Draw); } diff --git a/src/widget.rs b/src/widget.rs index 8d18feb..c4dd7b5 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1,7 +1,7 @@ -use nix::poll::{PollFd}; use crate::buffer::Buffer; use crate::color::Color; use chrono::{DateTime, Local}; +use nix::poll::PollFd; pub use smithay_client_toolkit::keyboard::{KeyState, ModifiersState}; pub struct DrawContext<'a> { diff --git a/src/widgets/audio/alsa_sound.rs b/src/widgets/audio/alsa_sound.rs index 4079143..fb1ec09 100644 --- a/src/widgets/audio/alsa_sound.rs +++ b/src/widgets/audio/alsa_sound.rs @@ -1,6 +1,6 @@ use crate::color::Color; -use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use crate::widget::WaitContext; +use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use alsa::mixer::{Mixer, Selem, SelemChannelId, SelemId}; diff --git a/src/widgets/audio/pulse_sound.rs b/src/widgets/audio/pulse_sound.rs index b8f8a79..9d95a49 100644 --- a/src/widgets/audio/pulse_sound.rs +++ b/src/widgets/audio/pulse_sound.rs @@ -1,7 +1,7 @@ use crate::cmd::Cmd; use crate::color::Color; -use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use crate::widget::WaitContext; +use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use std::cell::RefCell; use std::collections::HashMap; diff --git a/src/widgets/backlight.rs b/src/widgets/backlight.rs index 5acfa55..f64ee0b 100644 --- a/src/widgets/backlight.rs +++ b/src/widgets/backlight.rs @@ -1,6 +1,6 @@ use crate::color::Color; -use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use crate::widget::WaitContext; +use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use std::fs::OpenOptions; use std::io::{Error, ErrorKind}; diff --git a/src/widgets/bar_widget.rs b/src/widgets/bar_widget.rs index 46cd15b..e0a1a94 100644 --- a/src/widgets/bar_widget.rs +++ b/src/widgets/bar_widget.rs @@ -1,6 +1,6 @@ use crate::color::Color; use crate::draw::{draw_bar, draw_box, Font, ROBOTO_REGULAR}; -use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget, WaitContext}; +use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget}; use std::sync::{Arc, Mutex}; diff --git a/src/widgets/battery.rs b/src/widgets/battery.rs index 421263d..5efd792 100644 --- a/src/widgets/battery.rs +++ b/src/widgets/battery.rs @@ -1,7 +1,7 @@ use crate::cmd::Cmd; use crate::color::Color; -use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use crate::widget::WaitContext; +use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl}; use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex}; @@ -44,7 +44,7 @@ struct DbusConnection(dbus::Connection); impl std::convert::AsRef for DbusConnection { fn as_ref(&self) -> &dbus::Connection { - return &self.0 + return &self.0; } } @@ -70,12 +70,14 @@ enum UpowerBatteryState { } impl UpowerBattery { - pub fn from_device(dirty: Arc>, sender: Sender, device: &str) -> Result { - let con = dbus::Connection::get_private(dbus::BusType::System) - .map_err(|_| ::std::io::Error::new( - ::std::io::ErrorKind::Other, - "unable to open dbus", - ))?; + pub fn from_device( + dirty: Arc>, + sender: Sender, + device: &str, + ) -> Result { + let con = dbus::Connection::get_private(dbus::BusType::System).map_err(|_| { + ::std::io::Error::new(::std::io::ErrorKind::Other, "unable to open dbus") + })?; let device_path = format!("/org/freedesktop/UPower/devices/battery_{}", device); let rule = format!( @@ -85,11 +87,12 @@ impl UpowerBattery { member='PropertiesChanged'", &device_path ); - con.add_match(&rule) - .map_err(|_| ::std::io::Error::new( + con.add_match(&rule).map_err(|_| { + ::std::io::Error::new( ::std::io::ErrorKind::Other, "unable to add match rule to dbus connection", - ))?; + ) + })?; let upower_type: dbus::arg::Variant = match get_upower_property(&con, &device_path, "Type")?.get1() { Some(v) => v, @@ -173,7 +176,11 @@ impl UpowerBattery { impl BarWidgetImpl for UpowerBattery { fn wait(&mut self, ctx: &mut WaitContext) { - for _ in self.con.as_ref().watch_handle(self.watch.fd(), dbus::WatchEvent::Readable as u32) { + for _ in self + .con + .as_ref() + .watch_handle(self.watch.fd(), dbus::WatchEvent::Readable as u32) + { let capacity = get_upower_property(self.con.as_ref(), &self.device_path, "Percentage") .unwrap() .get1::>() @@ -199,7 +206,8 @@ impl BarWidgetImpl for UpowerBattery { self.sender.send(Cmd::Draw).unwrap(); } - ctx.fds.push(PollFd::new(self.watch.fd(), PollFlags::POLLIN)); + ctx.fds + .push(PollFd::new(self.watch.fd(), PollFlags::POLLIN)); } fn name(&self) -> &str { "battery" diff --git a/src/widgets/calendar.rs b/src/widgets/calendar.rs index 16ee667..dbbf85f 100644 --- a/src/widgets/calendar.rs +++ b/src/widgets/calendar.rs @@ -1,7 +1,7 @@ use crate::buffer::Buffer; use crate::color::Color; use crate::draw::{Font, DEJAVUSANS_MONO, ROBOTO_REGULAR}; -use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget, WaitContext}; +use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget}; use chrono::{Date, Datelike, Local}; diff --git a/src/widgets/clock.rs b/src/widgets/clock.rs index b925ea4..f503ae4 100644 --- a/src/widgets/clock.rs +++ b/src/widgets/clock.rs @@ -1,6 +1,6 @@ use crate::color::Color; use crate::draw::{Font, ROBOTO_REGULAR}; -use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget, WaitContext}; +use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget}; use chrono::{DateTime, Datelike, Duration, Local, Timelike}; diff --git a/src/widgets/date.rs b/src/widgets/date.rs index 38cb500..1264653 100644 --- a/src/widgets/date.rs +++ b/src/widgets/date.rs @@ -1,6 +1,6 @@ use crate::color::Color; use crate::draw::{Font, ROBOTO_REGULAR}; -use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget, WaitContext}; +use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget}; use chrono::{DateTime, Datelike, Local}; diff --git a/src/widgets/launcher.rs b/src/widgets/launcher.rs index ce52af1..bfb84e1 100644 --- a/src/widgets/launcher.rs +++ b/src/widgets/launcher.rs @@ -3,13 +3,13 @@ use crate::cmd::Cmd; use crate::color::Color; use crate::desktop::{load_desktop_files, Desktop}; use crate::draw::{Font, ROBOTO_REGULAR}; -use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, Widget, WaitContext}; +use crate::widget::{DrawContext, DrawReport, KeyState, ModifiersState, WaitContext, Widget}; use std::cell::RefCell; use std::cmp::Ordering; +use std::collections::HashMap; use std::process::Command; use std::sync::mpsc::Sender; -use std::collections::HashMap; use fuzzy_matcher::skim::{fuzzy_indices, fuzzy_match}; use smithay_client_toolkit::keyboard::keysyms; @@ -82,7 +82,7 @@ impl Launcher { let size = if idx == self.offset && self.input.len() > 0 { let (_, indices) = fuzzy_indices(&m.name.to_lowercase(), &self.input.to_lowercase()) - .unwrap_or((0, vec![])); + .unwrap_or((0, vec![])); let mut colors = Vec::with_capacity(m.name.len()); for pos in 0..m.name.len() { if indices.contains(&pos) { @@ -211,7 +211,7 @@ impl Matcher { // Skip over new matches for the same program that are worse // than the one we already have. if ma_old > &ma { - return + return; } } @@ -220,9 +220,11 @@ impl Matcher { } fn matches(&self) -> Vec { - let mut m = self.matches.iter() - .map(|(key, ma)| (ma.clone(), key.clone())) - .collect::>(); + let mut m = self + .matches + .iter() + .map(|(key, ma)| (ma.clone(), key.clone())) + .collect::>(); m.sort_by(|(ma1, d1), (ma2, d2)| { if ma1 > ma2 {