cargo fmt
This commit is contained in:
+55
-12
@@ -6,10 +6,11 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::{
|
||||
event::Events,
|
||||
fonts::{FontMap, find_font},
|
||||
fonts::{find_font, FontMap},
|
||||
widgets::{
|
||||
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,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -81,7 +82,7 @@ pub struct Config {
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Config {
|
||||
Config{
|
||||
Config {
|
||||
font_paths: None,
|
||||
widget: Default::default(),
|
||||
mode: Default::default(),
|
||||
@@ -98,12 +99,31 @@ impl Config {
|
||||
|
||||
let mut bars = Vec::new();
|
||||
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 {
|
||||
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 {
|
||||
margins: (20, 20, 20, 20),
|
||||
@@ -143,7 +163,7 @@ impl Config {
|
||||
("monospace".to_string(), monospace),
|
||||
]);
|
||||
|
||||
Config{
|
||||
Config {
|
||||
font_paths: Some(map),
|
||||
widget: widget,
|
||||
mode: OperationMode::LayerSurface((1024, 768)),
|
||||
@@ -158,12 +178,31 @@ impl Config {
|
||||
|
||||
let mut bars = Vec::new();
|
||||
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 {
|
||||
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![
|
||||
Widget::HorizontalLayout(vec![
|
||||
@@ -201,10 +240,14 @@ impl Config {
|
||||
("monospace".to_string(), monospace),
|
||||
]);
|
||||
|
||||
Config{
|
||||
Config {
|
||||
font_paths: Some(map),
|
||||
widget: widget,
|
||||
mode: if clay { OperationMode::XdgToplevel } else { OperationMode::LayerSurface((1024, 768)) },
|
||||
mode: if clay {
|
||||
OperationMode::XdgToplevel
|
||||
} else {
|
||||
OperationMode::LayerSurface((1024, 768))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -21,12 +21,12 @@ use wayland_client::{protocol::wl_keyboard, WEnum};
|
||||
use xkbcommon::xkb;
|
||||
|
||||
pub mod keysyms;
|
||||
mod state;
|
||||
mod repeat;
|
||||
mod state;
|
||||
|
||||
pub use self::repeat::{KeyRepeatSource, RepeatMessage};
|
||||
use self::state::KbState;
|
||||
pub use self::state::ModifiersState;
|
||||
pub use self::repeat::{KeyRepeatSource, RepeatMessage};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KeyEvent {
|
||||
@@ -76,11 +76,7 @@ impl Keyboard {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn key(
|
||||
&mut self,
|
||||
key: u32,
|
||||
key_state: WEnum<wl_keyboard::KeyState>,
|
||||
) -> KeyEvent {
|
||||
pub fn key(&mut self, key: u32, key_state: WEnum<wl_keyboard::KeyState>) -> KeyEvent {
|
||||
if let Some(state) = &mut self.state {
|
||||
let (sym, utf8, repeats) = {
|
||||
// Get the values to generate a key event
|
||||
|
||||
+32
-39
@@ -5,9 +5,7 @@ use calloop::{
|
||||
timer::{TimeoutAction, Timer},
|
||||
EventSource, Poll, PostAction, Readiness, Token, TokenFactory,
|
||||
};
|
||||
use wayland_client::{
|
||||
protocol::wl_keyboard, WEnum,
|
||||
};
|
||||
use wayland_client::{protocol::wl_keyboard, WEnum};
|
||||
|
||||
use super::KeyEvent;
|
||||
|
||||
@@ -15,7 +13,7 @@ use super::KeyEvent;
|
||||
pub enum RepeatMessage {
|
||||
StopRepeat,
|
||||
KeyEvent(KeyEvent),
|
||||
RepeatInfo((u32, u32))
|
||||
RepeatInfo((u32, u32)),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -30,7 +28,7 @@ pub struct KeyRepeatSource {
|
||||
|
||||
impl KeyRepeatSource {
|
||||
pub fn new(ch: channel::Channel<RepeatMessage>) -> KeyRepeatSource {
|
||||
KeyRepeatSource{
|
||||
KeyRepeatSource {
|
||||
channel: ch,
|
||||
timer: Timer::immediate(),
|
||||
delay: Duration::ZERO,
|
||||
@@ -71,44 +69,40 @@ impl EventSource for KeyRepeatSource {
|
||||
// Check if the key repeat should stop
|
||||
let channel_pa = self
|
||||
.channel
|
||||
.process_events(readiness, token, |event, _| {
|
||||
match event {
|
||||
channel::Event::Msg(message) => {
|
||||
match message {
|
||||
RepeatMessage::StopRepeat => {
|
||||
.process_events(readiness, token, |event, _| match event {
|
||||
channel::Event::Msg(message) => match message {
|
||||
RepeatMessage::StopRepeat => {
|
||||
key.take();
|
||||
}
|
||||
RepeatMessage::KeyEvent(event) => match event.state {
|
||||
WEnum::Value(wl_keyboard::KeyState::Pressed) => {
|
||||
key.replace(event);
|
||||
reregister = true;
|
||||
|
||||
next_deadline = std::time::Instant::now() + *delay;
|
||||
timer.set_deadline(next_deadline);
|
||||
}
|
||||
WEnum::Value(wl_keyboard::KeyState::Released) => match key {
|
||||
Some(k) if k.keysym == event.keysym => {
|
||||
key.take();
|
||||
}
|
||||
RepeatMessage::KeyEvent(event) => match event.state {
|
||||
WEnum::Value(wl_keyboard::KeyState::Pressed) => {
|
||||
key.replace(event);
|
||||
reregister = true;
|
||||
|
||||
next_deadline = std::time::Instant::now() + *delay;
|
||||
timer.set_deadline(next_deadline);
|
||||
}
|
||||
WEnum::Value(wl_keyboard::KeyState::Released) => match key {
|
||||
Some(k) if k.keysym == event.keysym => {
|
||||
key.take();
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
RepeatMessage::RepeatInfo((new_rate, new_delay)) => {
|
||||
*rate = Duration::from_micros(1_000_000 / new_rate as u64);
|
||||
*delay = Duration::from_millis(new_delay as u64);
|
||||
*disabled = false;
|
||||
if key.is_some() {
|
||||
next_deadline = std::time::Instant::now() + *delay;
|
||||
timer.set_deadline(next_deadline);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
RepeatMessage::RepeatInfo((new_rate, new_delay)) => {
|
||||
*rate = Duration::from_micros(1_000_000 / new_rate as u64);
|
||||
*delay = Duration::from_millis(new_delay as u64);
|
||||
*disabled = false;
|
||||
if key.is_some() {
|
||||
next_deadline = std::time::Instant::now() + *delay;
|
||||
timer.set_deadline(next_deadline);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
channel::Event::Closed => {
|
||||
removed = true;
|
||||
}
|
||||
channel::Event::Closed => {
|
||||
removed = true;
|
||||
}
|
||||
})
|
||||
.map_err(|err| calloop::Error::OtherError(Box::new(err)))?;
|
||||
@@ -166,4 +160,3 @@ impl EventSource for KeyRepeatSource {
|
||||
self.timer.unregister(poll)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -23,9 +23,9 @@ use buffer::BufferView;
|
||||
use config::Config;
|
||||
use event::{Event, Events};
|
||||
use fonts::{FontMap, MaybeFontMap};
|
||||
use keyboard::{KeyRepeatSource, RepeatMessage};
|
||||
use state::State;
|
||||
use widgets::{Geometry, Widget};
|
||||
use keyboard::{KeyRepeatSource, RepeatMessage};
|
||||
|
||||
use std::{env, rc::Rc, thread};
|
||||
|
||||
@@ -50,7 +50,7 @@ fn main() {
|
||||
Err(_) => panic!("uh"),
|
||||
}
|
||||
std::process::exit(0);
|
||||
},
|
||||
}
|
||||
Some(_) => panic!("unknown argument"),
|
||||
None => break,
|
||||
}
|
||||
@@ -140,7 +140,9 @@ fn main() {
|
||||
|
||||
let layout = Rc::new(config.widget.construct_layout(&mut 0));
|
||||
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()
|
||||
.name("fontloader".to_string())
|
||||
|
||||
+14
-5
@@ -29,8 +29,8 @@ use wayland_protocols::{
|
||||
use wayland_protocols_wlr::layer_shell::v1::client::{zwlr_layer_shell_v1, zwlr_layer_surface_v1};
|
||||
|
||||
use crate::{
|
||||
config::OperationMode,
|
||||
buffer::BufferManager,
|
||||
config::OperationMode,
|
||||
event::{Event, Events, PointerButton, PointerEvent},
|
||||
fonts::{FontMap, MaybeFontMap},
|
||||
keyboard::{Keyboard, RepeatMessage},
|
||||
@@ -560,8 +560,11 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
match event {
|
||||
wl_keyboard::Event::Leave { .. }=> {
|
||||
state.keyrepeat_sender.send(RepeatMessage::StopRepeat).unwrap();
|
||||
wl_keyboard::Event::Leave { .. } => {
|
||||
state
|
||||
.keyrepeat_sender
|
||||
.send(RepeatMessage::StopRepeat)
|
||||
.unwrap();
|
||||
}
|
||||
wl_keyboard::Event::Key {
|
||||
key,
|
||||
@@ -580,7 +583,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
||||
}
|
||||
if repeats {
|
||||
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;
|
||||
@@ -601,7 +607,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
||||
state.keyboard.keymap(format, fd, size);
|
||||
}
|
||||
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();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
time::Duration,
|
||||
error::Error,
|
||||
};
|
||||
|
||||
use dbus::blocking::{
|
||||
@@ -55,8 +55,7 @@ fn get_battery_state() -> Result<UpowerBatteryState, Box<dyn Error>> {
|
||||
device_path,
|
||||
Duration::from_millis(500),
|
||||
);
|
||||
let state: u32 = proxy
|
||||
.get("org.freedesktop.UPower.Device", "State")?;
|
||||
let state: u32 = proxy.get("org.freedesktop.UPower.Device", "State")?;
|
||||
Ok(UpowerBatteryState::from_dbus(state as u64))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user