cargo fmt
This commit is contained in:
+55
-12
@@ -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,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config{
|
Config {
|
||||||
font_paths: None,
|
font_paths: None,
|
||||||
widget: Default::default(),
|
widget: Default::default(),
|
||||||
mode: Default::default(),
|
mode: Default::default(),
|
||||||
@@ -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),
|
||||||
@@ -143,7 +163,7 @@ impl Config {
|
|||||||
("monospace".to_string(), monospace),
|
("monospace".to_string(), monospace),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Config{
|
Config {
|
||||||
font_paths: Some(map),
|
font_paths: Some(map),
|
||||||
widget: widget,
|
widget: widget,
|
||||||
mode: OperationMode::LayerSurface((1024, 768)),
|
mode: OperationMode::LayerSurface((1024, 768)),
|
||||||
@@ -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![
|
||||||
@@ -201,10 +240,14 @@ impl Config {
|
|||||||
("monospace".to_string(), monospace),
|
("monospace".to_string(), monospace),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
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
@@ -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
|
||||||
|
|||||||
+32
-39
@@ -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)]
|
||||||
@@ -30,7 +28,7 @@ pub struct KeyRepeatSource {
|
|||||||
|
|
||||||
impl KeyRepeatSource {
|
impl KeyRepeatSource {
|
||||||
pub fn new(ch: channel::Channel<RepeatMessage>) -> KeyRepeatSource {
|
pub fn new(ch: channel::Channel<RepeatMessage>) -> KeyRepeatSource {
|
||||||
KeyRepeatSource{
|
KeyRepeatSource {
|
||||||
channel: ch,
|
channel: ch,
|
||||||
timer: Timer::immediate(),
|
timer: Timer::immediate(),
|
||||||
delay: Duration::ZERO,
|
delay: Duration::ZERO,
|
||||||
@@ -71,44 +69,40 @@ 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) => {
|
RepeatMessage::StopRepeat => {
|
||||||
match message {
|
key.take();
|
||||||
RepeatMessage::StopRepeat => {
|
}
|
||||||
|
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();
|
key.take();
|
||||||
}
|
}
|
||||||
RepeatMessage::KeyEvent(event) => match event.state {
|
_ => (),
|
||||||
WEnum::Value(wl_keyboard::KeyState::Pressed) => {
|
},
|
||||||
key.replace(event);
|
_ => (),
|
||||||
reregister = true;
|
},
|
||||||
|
RepeatMessage::RepeatInfo((new_rate, new_delay)) => {
|
||||||
next_deadline = std::time::Instant::now() + *delay;
|
*rate = Duration::from_micros(1_000_000 / new_rate as u64);
|
||||||
timer.set_deadline(next_deadline);
|
*delay = Duration::from_millis(new_delay as u64);
|
||||||
}
|
*disabled = false;
|
||||||
WEnum::Value(wl_keyboard::KeyState::Released) => match key {
|
if key.is_some() {
|
||||||
Some(k) if k.keysym == event.keysym => {
|
next_deadline = std::time::Instant::now() + *delay;
|
||||||
key.take();
|
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 => {
|
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
@@ -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())
|
||||||
|
|||||||
+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 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},
|
||||||
@@ -560,8 +560,11 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
|||||||
_: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
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();
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user