From ee4fe479d06b1e671c4ab1d862fe8f10f2affac6 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Tue, 6 Aug 2019 14:21:10 +0200 Subject: [PATCH] rustfmt --- src/backlight.rs | 2 +- src/battery.rs | 20 +++++++++++---- src/clock.rs | 3 ++- src/draw.rs | 65 +++++++++++++++++++++++++++++++++++------------- src/launcher.rs | 6 +++-- src/main.rs | 17 ++++--------- src/sound.rs | 6 +---- 7 files changed, 76 insertions(+), 43 deletions(-) diff --git a/src/backlight.rs b/src/backlight.rs index e60835d..450eb4c 100644 --- a/src/backlight.rs +++ b/src/backlight.rs @@ -3,11 +3,11 @@ use crate::color::Color; use crate::draw::{draw_bar, draw_box, Font, ROBOTO_REGULAR}; use crate::module::{Input, ModuleImpl}; +use std::cell::RefCell; use std::fs::OpenOptions; use std::io::{Error, ErrorKind}; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; -use std::cell::RefCell; use chrono::{DateTime, Local}; diff --git a/src/battery.rs b/src/battery.rs index 544a3c6..806c5f2 100644 --- a/src/battery.rs +++ b/src/battery.rs @@ -3,10 +3,10 @@ use crate::color::Color; use crate::draw::{draw_bar, draw_box, Font, ROBOTO_REGULAR}; use crate::module::{Input, ModuleImpl}; +use std::cell::RefCell; use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex}; use std::thread; -use std::cell::RefCell; use chrono::{DateTime, Local}; use dbus; @@ -192,9 +192,15 @@ impl ModuleImpl for UpowerBattery { buf.memset(bg); let text_color = Color::new(1.0, 1.0, 1.0, 1.0); let bar_color = match self.inner.lock().unwrap().state { - UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => Color::new(1.0, 1.0, 1.0, 1.0), - UpowerBatteryState::Charging | UpowerBatteryState::Full => Color::new(0.5, 1.0, 0.5, 1.0), - UpowerBatteryState::NotCharging | UpowerBatteryState::Empty => Color::new(1.0, 0.5, 0.5, 1.0), + UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => { + Color::new(1.0, 1.0, 1.0, 1.0) + } + UpowerBatteryState::Charging | UpowerBatteryState::Full => { + Color::new(0.5, 1.0, 0.5, 1.0) + } + UpowerBatteryState::NotCharging | UpowerBatteryState::Empty => { + Color::new(1.0, 0.5, 0.5, 1.0) + } }; let inner = self.inner.lock().unwrap(); @@ -212,7 +218,11 @@ impl ModuleImpl for UpowerBattery { (inner.capacity as f32) / 100.0, )?; - draw_box(&mut buf.subdimensions((128, 0, 432, 24))?, &bar_color, (432, 24))?; + draw_box( + &mut buf.subdimensions((128, 0, 432, 24))?, + &bar_color, + (432, 24), + )?; Ok(vec![buf.get_signed_bounds()]) } diff --git a/src/clock.rs b/src/clock.rs index 52ecf51..0c59984 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -77,7 +77,8 @@ impl ModuleImpl for Clock { if time.date() != self.cur_time.date() || time.hour() != self.cur_time.hour() || time.minute() != self.cur_time.minute() - || force || self.first_draw + || force + || self.first_draw { self.cur_time = time.clone(); self.first_draw = false; diff --git a/src/draw.rs b/src/draw.rs index 02aa74f..4dd4203 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -3,15 +3,20 @@ use crate::color::Color; use std::collections::HashMap; -use rusttype::{point, Font as RustFont, Scale}; use lazy_static::lazy_static; +use rusttype::{point, Font as RustFont, Scale}; -pub static DEJAVUSANS_MONO_FONT_DATA: &'static [u8] = include_bytes!("../fonts/dejavu/DejaVuSansMono.ttf"); +pub static DEJAVUSANS_MONO_FONT_DATA: &'static [u8] = + include_bytes!("../fonts/dejavu/DejaVuSansMono.ttf"); pub static ROBOTO_REGULAR_FONT_DATA: &'static [u8] = include_bytes!("../fonts/Roboto-Regular.ttf"); lazy_static! { - pub static ref DEJAVUSANS_MONO: RustFont<'static> = RustFont::from_bytes(DEJAVUSANS_MONO_FONT_DATA as &[u8]).expect("error constructing DejaVuSansMono"); - pub static ref ROBOTO_REGULAR: RustFont<'static> = RustFont::from_bytes(ROBOTO_REGULAR_FONT_DATA as &[u8]).expect("error constructing Roboto-Regular"); + pub static ref DEJAVUSANS_MONO: RustFont<'static> = + RustFont::from_bytes(DEJAVUSANS_MONO_FONT_DATA as &[u8]) + .expect("error constructing DejaVuSansMono"); + pub static ref ROBOTO_REGULAR: RustFont<'static> = + RustFont::from_bytes(ROBOTO_REGULAR_FONT_DATA as &[u8]) + .expect("error constructing Roboto-Regular"); } struct CachedGlyph { @@ -29,25 +34,27 @@ impl CachedGlyph { .scaled(scale) .positioned(point(0.0, v_metrics.ascent)); - if let Some(bounding_box) = glyph.pixel_bounding_box() { let origin = (bounding_box.min.x, bounding_box.min.y); - let dimensions = ((bounding_box.max.x - bounding_box.min.x) as u32, (bounding_box.max.y - bounding_box.min.y) as u32); + let dimensions = ( + (bounding_box.max.x - bounding_box.min.x) as u32, + (bounding_box.max.y - bounding_box.min.y) as u32, + ); let mut render = vec![0.0; (dimensions.0 * dimensions.1) as usize]; glyph.draw(|x, y, o| { let pos = x + (y * dimensions.0); render[pos as usize] = o; }); - CachedGlyph{ + CachedGlyph { origin: origin, dimensions: dimensions, render: render, } } else { - CachedGlyph{ - origin: (0,0), - dimensions: ((size/4.0) as u32, 0), + CachedGlyph { + origin: (0, 0), + dimensions: ((size / 4.0) as u32, 0), render: Vec::new(), } } @@ -57,16 +64,21 @@ impl CachedGlyph { let mut x = 0; let mut y = 0; for v in &self.render { - let _ = buf.put(((x + pos.0 + self.origin.0) as u32, (y + pos.1 + self.origin.1) as u32), &bg.blend(&c, *v)); + let _ = buf.put( + ( + (x + pos.0 + self.origin.0) as u32, + (y + pos.1 + self.origin.1) as u32, + ), + &bg.blend(&c, *v), + ); - if x == self.dimensions.0 as i32 -1 { + if x == self.dimensions.0 as i32 - 1 { y += 1; x = 0; } else { x += 1; } } - } } @@ -78,14 +90,20 @@ pub struct Font { impl Font { pub fn new(font: &'static RustFont, size: f32) -> Font { - Font{ + Font { glyphs: HashMap::new(), font: font, size: size, } } - pub fn draw_text(&mut self, buf: &mut Buffer, bg: &Color, c: &Color, s: &str) -> Result<(u32, u32), ::std::io::Error> { + pub fn draw_text( + &mut self, + buf: &mut Buffer, + bg: &Color, + c: &Color, + s: &str, + ) -> Result<(u32, u32), ::std::io::Error> { let mut x_off = 0; let mut off = 0; for ch in s.chars() { @@ -110,7 +128,14 @@ impl Font { Ok((x_off as u32, self.size as u32)) } - pub fn draw_text_fixed_width(&mut self, buf: &mut Buffer, bg: &Color, c: &Color, distances: &[u32], s: &str) -> Result<(u32, u32), ::std::io::Error> { + pub fn draw_text_fixed_width( + &mut self, + buf: &mut Buffer, + bg: &Color, + c: &Color, + distances: &[u32], + s: &str, + ) -> Result<(u32, u32), ::std::io::Error> { let mut x_off = 0; let mut off = 0; for ch in s.chars() { @@ -135,7 +160,13 @@ impl Font { Ok((x_off as u32, self.size as u32)) } - pub fn draw_text_individual_colors(&mut self, buf: &mut Buffer, bg: &Color, color: &[Color], s: &str) -> Result<(u32, u32), ::std::io::Error> { + pub fn draw_text_individual_colors( + &mut self, + buf: &mut Buffer, + bg: &Color, + color: &[Color], + s: &str, + ) -> Result<(u32, u32), ::std::io::Error> { let mut x_off = 0; let mut off = 0; for ch in s.chars() { diff --git a/src/launcher.rs b/src/launcher.rs index 94180d6..d4c790b 100644 --- a/src/launcher.rs +++ b/src/launcher.rs @@ -3,9 +3,9 @@ use crate::color::Color; use crate::draw::{Font, ROBOTO_REGULAR}; use crate::module::{Input, ModuleImpl}; +use std::cell::RefCell; use std::cmp::Ordering; use std::io::Read; -use std::cell::RefCell; use atty::Stream; use chrono::{DateTime, Local}; @@ -94,7 +94,9 @@ impl ModuleImpl for Launcher { colors.push(Color::new(0.75, 0.75, 0.75, 1.0)); } } - self.font.borrow_mut().draw_text_individual_colors(&mut b, bg, &colors, &m)? + self.font + .borrow_mut() + .draw_text_individual_colors(&mut b, bg, &colors, &m)? } else { self.font.borrow_mut().draw_text( &mut b, diff --git a/src/main.rs b/src/main.rs index 8c11d64..98e47e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,7 +180,6 @@ impl App { mod_tx.send(modules).unwrap(); }); - let cmd_queue = Arc::new(Mutex::new(VecDeque::new())); let (display, mut event_queue) = Display::connect_to_env().unwrap(); @@ -299,7 +298,9 @@ impl App { move |layer| { layer.implement_closure( move |evt, layer| match evt { - zwlr_layer_surface_v1::Event::Configure { serial, .. } => layer.ack_configure(serial), + zwlr_layer_surface_v1::Event::Configure { serial, .. } => { + layer.ack_configure(serial) + } _ => unreachable!(), }, (), @@ -356,20 +357,12 @@ impl App { } => { pos = (surface_x as u32, surface_y as u32); } - wl_pointer::Event::Axis { - axis, - value, - .. - } => { + wl_pointer::Event::Axis { axis, value, .. } => { if axis == wl_pointer::Axis::VerticalScroll { vert_scroll += value; } } - wl_pointer::Event::Button { - button, - state, - .. - } => match state { + wl_pointer::Event::Button { button, state, .. } => match state { wl_pointer::ButtonState::Released => { btn = button; btn_clicked = true; diff --git a/src/sound.rs b/src/sound.rs index ca73f5e..a6be51f 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -481,11 +481,7 @@ impl ModuleImpl for PulseAudio { } Input::Click { pos: _pos, button } => match button { 273 => { - self.device - .lock() - .unwrap() - .toggle() - .unwrap(); + self.device.lock().unwrap().toggle().unwrap(); } _ => {} },