This commit is contained in:
Kenny Levinsen
2019-08-06 14:21:10 +02:00
parent 0896290411
commit ee4fe479d0
7 changed files with 76 additions and 43 deletions
+1 -1
View File
@@ -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};
+15 -5
View File
@@ -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()])
}
+2 -1
View File
@@ -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;
+48 -17
View File
@@ -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() {
+4 -2
View File
@@ -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,
+5 -12
View File
@@ -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;
+1 -5
View File
@@ -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();
}
_ => {}
},