cargo fmt

This commit is contained in:
Kenny Levinsen
2023-02-13 18:49:44 +01:00
parent 8826cab89d
commit 022f6a719a
6 changed files with 111 additions and 69 deletions
+52 -9
View File
@@ -6,10 +6,11 @@ use std::sync::{Arc, Mutex};
use crate::{ use crate::{
event::Events, event::Events,
fonts::{FontMap, find_font}, fonts::{find_font, FontMap},
widgets::{ widgets::{
Backlight, Battery, Calendar, Clock, Date, HorizontalLayout, IndexedLayout, Interface, Backlight, Battery, Calendar, Clock, Date, HorizontalLayout, IndexedLayout, Interface,
InvertedHorizontalLayout, Layout, Line, Margin, PulseAudio, VerticalLayout, Widget as RealWidget, InvertedHorizontalLayout, Layout, Line, Margin, PulseAudio, VerticalLayout,
Widget as RealWidget,
}, },
}; };
@@ -98,12 +99,31 @@ impl Config {
let mut bars = Vec::new(); let mut bars = Vec::new();
if has_battery { if has_battery {
bars.push(Widget::Margin{ margins: (0, 0, 0, 8), widget: Box::new(Widget::Battery { font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (0, 0, 0, 8),
widget: Box::new(Widget::Battery {
font: None,
font_size: 24.,
}),
});
} }
if has_backlight { if has_backlight {
bars.push(Widget::Margin{ margins: (0, 0, 0, 8), widget: Box::new(Widget::Backlight { device: Some("intel_backlight".to_string()), font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (0, 0, 0, 8),
widget: Box::new(Widget::Backlight {
device: Some("intel_backlight".to_string()),
font: None,
font_size: 24.,
}),
});
} }
bars.push(Widget::Margin{ margins: (0, 0, 0, 8), widget: Box::new(Widget::PulseAudio { font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (0, 0, 0, 8),
widget: Box::new(Widget::PulseAudio {
font: None,
font_size: 24.,
}),
});
let widget = Widget::Margin { let widget = Widget::Margin {
margins: (20, 20, 20, 20), margins: (20, 20, 20, 20),
@@ -158,12 +178,31 @@ impl Config {
let mut bars = Vec::new(); let mut bars = Vec::new();
if has_battery { if has_battery {
bars.push(Widget::Margin{ margins: (16, 8, 8, 0), widget: Box::new(Widget::Battery { font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (16, 8, 8, 0),
widget: Box::new(Widget::Battery {
font: None,
font_size: 24.,
}),
});
} }
if has_backlight { if has_backlight {
bars.push(Widget::Margin{ margins: (16, 8, 8, 0), widget: Box::new(Widget::Backlight { device: Some("intel_backlight".to_string()), font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (16, 8, 8, 0),
widget: Box::new(Widget::Backlight {
device: Some("intel_backlight".to_string()),
font: None,
font_size: 24.,
}),
});
} }
bars.push(Widget::Margin{ margins: (16, 8, 8, 0), widget: Box::new(Widget::PulseAudio { font: None, font_size: 24. })}); bars.push(Widget::Margin {
margins: (16, 8, 8, 0),
widget: Box::new(Widget::PulseAudio {
font: None,
font_size: 24.,
}),
});
let widget = Widget::VerticalLayout(vec![ let widget = Widget::VerticalLayout(vec![
Widget::HorizontalLayout(vec![ Widget::HorizontalLayout(vec![
@@ -204,7 +243,11 @@ impl Config {
Config { Config {
font_paths: Some(map), font_paths: Some(map),
widget: widget, widget: widget,
mode: if clay { OperationMode::XdgToplevel } else { OperationMode::LayerSurface((1024, 768)) }, mode: if clay {
OperationMode::XdgToplevel
} else {
OperationMode::LayerSurface((1024, 768))
},
} }
} }
} }
+3 -7
View File
@@ -21,12 +21,12 @@ use wayland_client::{protocol::wl_keyboard, WEnum};
use xkbcommon::xkb; use xkbcommon::xkb;
pub mod keysyms; pub mod keysyms;
mod state;
mod repeat; mod repeat;
mod state;
pub use self::repeat::{KeyRepeatSource, RepeatMessage};
use self::state::KbState; use self::state::KbState;
pub use self::state::ModifiersState; pub use self::state::ModifiersState;
pub use self::repeat::{KeyRepeatSource, RepeatMessage};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KeyEvent { pub struct KeyEvent {
@@ -76,11 +76,7 @@ impl Keyboard {
} }
} }
pub fn key( pub fn key(&mut self, key: u32, key_state: WEnum<wl_keyboard::KeyState>) -> KeyEvent {
&mut self,
key: u32,
key_state: WEnum<wl_keyboard::KeyState>,
) -> KeyEvent {
if let Some(state) = &mut self.state { if let Some(state) = &mut self.state {
let (sym, utf8, repeats) = { let (sym, utf8, repeats) = {
// Get the values to generate a key event // Get the values to generate a key event
+6 -13
View File
@@ -5,9 +5,7 @@ use calloop::{
timer::{TimeoutAction, Timer}, timer::{TimeoutAction, Timer},
EventSource, Poll, PostAction, Readiness, Token, TokenFactory, EventSource, Poll, PostAction, Readiness, Token, TokenFactory,
}; };
use wayland_client::{ use wayland_client::{protocol::wl_keyboard, WEnum};
protocol::wl_keyboard, WEnum,
};
use super::KeyEvent; use super::KeyEvent;
@@ -15,7 +13,7 @@ use super::KeyEvent;
pub enum RepeatMessage { pub enum RepeatMessage {
StopRepeat, StopRepeat,
KeyEvent(KeyEvent), KeyEvent(KeyEvent),
RepeatInfo((u32, u32)) RepeatInfo((u32, u32)),
} }
#[derive(Debug)] #[derive(Debug)]
@@ -71,10 +69,8 @@ impl EventSource for KeyRepeatSource {
// Check if the key repeat should stop // Check if the key repeat should stop
let channel_pa = self let channel_pa = self
.channel .channel
.process_events(readiness, token, |event, _| { .process_events(readiness, token, |event, _| match event {
match event { channel::Event::Msg(message) => match message {
channel::Event::Msg(message) => {
match message {
RepeatMessage::StopRepeat => { RepeatMessage::StopRepeat => {
key.take(); key.take();
} }
@@ -93,7 +89,7 @@ impl EventSource for KeyRepeatSource {
_ => (), _ => (),
}, },
_ => (), _ => (),
} },
RepeatMessage::RepeatInfo((new_rate, new_delay)) => { RepeatMessage::RepeatInfo((new_rate, new_delay)) => {
*rate = Duration::from_micros(1_000_000 / new_rate as u64); *rate = Duration::from_micros(1_000_000 / new_rate as u64);
*delay = Duration::from_millis(new_delay as u64); *delay = Duration::from_millis(new_delay as u64);
@@ -103,13 +99,11 @@ impl EventSource for KeyRepeatSource {
timer.set_deadline(next_deadline); timer.set_deadline(next_deadline);
} }
} }
} },
}
channel::Event::Closed => { channel::Event::Closed => {
removed = true; removed = true;
} }
}
}) })
.map_err(|err| calloop::Error::OtherError(Box::new(err)))?; .map_err(|err| calloop::Error::OtherError(Box::new(err)))?;
@@ -166,4 +160,3 @@ impl EventSource for KeyRepeatSource {
self.timer.unregister(poll) self.timer.unregister(poll)
} }
} }
+5 -3
View File
@@ -23,9 +23,9 @@ use buffer::BufferView;
use config::Config; use config::Config;
use event::{Event, Events}; use event::{Event, Events};
use fonts::{FontMap, MaybeFontMap}; use fonts::{FontMap, MaybeFontMap};
use keyboard::{KeyRepeatSource, RepeatMessage};
use state::State; use state::State;
use widgets::{Geometry, Widget}; use widgets::{Geometry, Widget};
use keyboard::{KeyRepeatSource, RepeatMessage};
use std::{env, rc::Rc, thread}; use std::{env, rc::Rc, thread};
@@ -50,7 +50,7 @@ fn main() {
Err(_) => panic!("uh"), Err(_) => panic!("uh"),
} }
std::process::exit(0); std::process::exit(0);
}, }
Some(_) => panic!("unknown argument"), Some(_) => panic!("unknown argument"),
None => break, None => break,
} }
@@ -140,7 +140,9 @@ fn main() {
let layout = Rc::new(config.widget.construct_layout(&mut 0)); let layout = Rc::new(config.widget.construct_layout(&mut 0));
let mut widgets: Vec<Box<dyn Widget>> = Vec::new(); let mut widgets: Vec<Box<dyn Widget>> = Vec::new();
config.widget.construct_widgets(&mut widgets, &mut fm, &events); config
.widget
.construct_widgets(&mut widgets, &mut fm, &events);
let font_thread = thread::Builder::new() let font_thread = thread::Builder::new()
.name("fontloader".to_string()) .name("fontloader".to_string())
+13 -4
View File
@@ -29,8 +29,8 @@ use wayland_protocols::{
use wayland_protocols_wlr::layer_shell::v1::client::{zwlr_layer_shell_v1, zwlr_layer_surface_v1}; use wayland_protocols_wlr::layer_shell::v1::client::{zwlr_layer_shell_v1, zwlr_layer_surface_v1};
use crate::{ use crate::{
config::OperationMode,
buffer::BufferManager, buffer::BufferManager,
config::OperationMode,
event::{Event, Events, PointerButton, PointerEvent}, event::{Event, Events, PointerButton, PointerEvent},
fonts::{FontMap, MaybeFontMap}, fonts::{FontMap, MaybeFontMap},
keyboard::{Keyboard, RepeatMessage}, keyboard::{Keyboard, RepeatMessage},
@@ -561,7 +561,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
) { ) {
match event { match event {
wl_keyboard::Event::Leave { .. } => { wl_keyboard::Event::Leave { .. } => {
state.keyrepeat_sender.send(RepeatMessage::StopRepeat).unwrap(); state
.keyrepeat_sender
.send(RepeatMessage::StopRepeat)
.unwrap();
} }
wl_keyboard::Event::Key { wl_keyboard::Event::Key {
key, key,
@@ -580,7 +583,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
} }
if repeats { if repeats {
if let Event::KeyEvent(k) = ev { if let Event::KeyEvent(k) = ev {
state.keyrepeat_sender.send(RepeatMessage::KeyEvent(k)).unwrap(); state
.keyrepeat_sender
.send(RepeatMessage::KeyEvent(k))
.unwrap();
} }
} }
state.dirty = true; state.dirty = true;
@@ -601,7 +607,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
state.keyboard.keymap(format, fd, size); state.keyboard.keymap(format, fd, size);
} }
wl_keyboard::Event::RepeatInfo { rate, delay } => { wl_keyboard::Event::RepeatInfo { rate, delay } => {
state.keyrepeat_sender.send(RepeatMessage::RepeatInfo((rate as u32, delay as u32))).unwrap(); state
.keyrepeat_sender
.send(RepeatMessage::RepeatInfo((rate as u32, delay as u32)))
.unwrap();
} }
_ => (), _ => (),
} }
+2 -3
View File
@@ -1,8 +1,8 @@
use std::{ use std::{
error::Error,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
thread, thread,
time::Duration, time::Duration,
error::Error,
}; };
use dbus::blocking::{ use dbus::blocking::{
@@ -55,8 +55,7 @@ fn get_battery_state() -> Result<UpowerBatteryState, Box<dyn Error>> {
device_path, device_path,
Duration::from_millis(500), Duration::from_millis(500),
); );
let state: u32 = proxy let state: u32 = proxy.get("org.freedesktop.UPower.Device", "State")?;
.get("org.freedesktop.UPower.Device", "State")?;
Ok(UpowerBatteryState::from_dbus(state as u64)) Ok(UpowerBatteryState::from_dbus(state as u64))
} }