autocommit 2022-04-10 18:26:13 CEST
This commit is contained in:
parent
af152f7f3e
commit
6b3316e920
26 changed files with 514 additions and 82 deletions
|
|
@ -14,7 +14,7 @@ use {
|
|||
input::{acceleration::AccelProfile, capability::Capability, InputDevice, Seat},
|
||||
keyboard::keymap::Keymap,
|
||||
theme::Color,
|
||||
Axis, Command, Direction, LogLevel, ModifiedKeySym, Workspace,
|
||||
Axis, Command, Direction, LogLevel, ModifiedKeySym, Timer, Workspace,
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
|
|
@ -23,6 +23,7 @@ use {
|
|||
ptr,
|
||||
rc::Rc,
|
||||
slice,
|
||||
time::Duration,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -32,6 +33,7 @@ pub(crate) struct Client {
|
|||
srv_unref: unsafe extern "C" fn(data: *const u8),
|
||||
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
|
||||
key_handlers: RefCell<HashMap<(Seat, ModifiedKeySym), Rc<dyn Fn()>>>,
|
||||
timer_handlers: RefCell<HashMap<Timer, Rc<dyn Fn()>>>,
|
||||
response: RefCell<Vec<Response>>,
|
||||
on_new_seat: RefCell<Option<Rc<dyn Fn(Seat)>>>,
|
||||
on_new_input_device: RefCell<Option<Rc<dyn Fn(InputDevice)>>>,
|
||||
|
|
@ -113,6 +115,7 @@ pub unsafe extern "C" fn init(
|
|||
srv_unref,
|
||||
srv_handler,
|
||||
key_handlers: Default::default(),
|
||||
timer_handlers: Default::default(),
|
||||
response: Default::default(),
|
||||
on_new_seat: Default::default(),
|
||||
on_new_input_device: Default::default(),
|
||||
|
|
@ -222,6 +225,33 @@ impl Client {
|
|||
mono
|
||||
}
|
||||
|
||||
pub fn get_timer(&self, name: &str) -> Timer {
|
||||
let res = self.with_response(|| self.send(&ClientMessage::GetTimer { name }));
|
||||
get_response!(res, Timer(0), GetTimer, timer);
|
||||
timer
|
||||
}
|
||||
|
||||
pub fn remove_timer(&self, timer: Timer) {
|
||||
self.send(&ClientMessage::RemoveTimer { timer });
|
||||
}
|
||||
|
||||
pub fn program_timer(
|
||||
&self,
|
||||
timer: Timer,
|
||||
initial: Option<Duration>,
|
||||
periodic: Option<Duration>,
|
||||
) {
|
||||
self.send(&ClientMessage::ProgramTimer {
|
||||
timer,
|
||||
initial,
|
||||
periodic,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_timer_tick<F: Fn() + 'static>(&self, timer: Timer, f: F) {
|
||||
self.timer_handlers.borrow_mut().insert(timer, Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn get_workspace(&self, name: &str) -> Workspace {
|
||||
let res = self.with_response(|| self.send(&ClientMessage::GetWorkspace { name }));
|
||||
get_response!(res, Workspace(0), GetWorkspace, workspace);
|
||||
|
|
@ -288,6 +318,10 @@ impl Client {
|
|||
self.send(&ClientMessage::SetMono { seat, mono });
|
||||
}
|
||||
|
||||
pub fn set_status(&self, status: &str) {
|
||||
self.send(&ClientMessage::SetStatus { status });
|
||||
}
|
||||
|
||||
pub fn set_split(&self, seat: Seat, axis: Axis) {
|
||||
self.send(&ClientMessage::SetSplit { seat, axis });
|
||||
}
|
||||
|
|
@ -507,6 +541,12 @@ impl Client {
|
|||
}
|
||||
}
|
||||
ServerMessage::DelConnector { .. } => {}
|
||||
ServerMessage::TimerExpired { timer } => {
|
||||
let handler = self.timer_handlers.borrow_mut().get(&timer).cloned();
|
||||
if let Some(handler) = handler {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ use {
|
|||
input::{acceleration::AccelProfile, capability::Capability, InputDevice, Seat},
|
||||
keyboard::{keymap::Keymap, mods::Modifiers, syms::KeySym},
|
||||
theme::Color,
|
||||
Axis, Direction, LogLevel, Workspace,
|
||||
Axis, Direction, LogLevel, Timer, Workspace,
|
||||
},
|
||||
bincode::{BorrowDecode, Decode, Encode},
|
||||
std::time::Duration,
|
||||
};
|
||||
|
||||
#[derive(Encode, BorrowDecode, Debug)]
|
||||
|
|
@ -38,6 +39,9 @@ pub enum ServerMessage {
|
|||
mods: Modifiers,
|
||||
sym: KeySym,
|
||||
},
|
||||
TimerExpired {
|
||||
timer: Timer,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, BorrowDecode, Debug)]
|
||||
|
|
@ -77,6 +81,9 @@ pub enum ClientMessage<'a> {
|
|||
GetSplit {
|
||||
seat: Seat,
|
||||
},
|
||||
SetStatus {
|
||||
status: &'a str,
|
||||
},
|
||||
SetSplit {
|
||||
seat: Seat,
|
||||
axis: Axis,
|
||||
|
|
@ -203,6 +210,17 @@ pub enum ClientMessage<'a> {
|
|||
seat: Seat,
|
||||
workspace: Workspace,
|
||||
},
|
||||
GetTimer {
|
||||
name: &'a str,
|
||||
},
|
||||
RemoveTimer {
|
||||
timer: Timer,
|
||||
},
|
||||
ProgramTimer {
|
||||
timer: Timer,
|
||||
initial: Option<Duration>,
|
||||
periodic: Option<Duration>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
|
|
@ -242,6 +260,9 @@ pub enum Response {
|
|||
GetDeviceName {
|
||||
name: String,
|
||||
},
|
||||
GetTimer {
|
||||
timer: Timer,
|
||||
},
|
||||
GetWorkspace {
|
||||
workspace: Workspace,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use {
|
||||
crate::keyboard::{keymap::Keymap, ModifiedKeySym},
|
||||
bincode::{Decode, Encode},
|
||||
std::collections::HashMap,
|
||||
std::{collections::HashMap, time::Duration},
|
||||
};
|
||||
|
||||
#[macro_use]
|
||||
|
|
@ -12,6 +12,7 @@ pub mod drm;
|
|||
pub mod embedded;
|
||||
pub mod input;
|
||||
pub mod keyboard;
|
||||
pub mod status;
|
||||
pub mod theme;
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Debug)]
|
||||
|
|
@ -91,3 +92,28 @@ pub struct Workspace(pub u64);
|
|||
pub fn get_workspace(name: &str) -> Workspace {
|
||||
get!(Workspace(0)).get_workspace(name)
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct Timer(pub u64);
|
||||
|
||||
pub fn get_timer(name: &str) -> Timer {
|
||||
get!(Timer(0)).get_timer(name)
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
pub fn program(self, initial: Duration, periodic: Option<Duration>) {
|
||||
get!().program_timer(self, Some(initial), periodic);
|
||||
}
|
||||
|
||||
pub fn cancel(self) {
|
||||
get!().program_timer(self, None, None);
|
||||
}
|
||||
|
||||
pub fn remove(self) {
|
||||
get!().remove_timer(self);
|
||||
}
|
||||
|
||||
pub fn on_tick<F: Fn() + 'static>(self, f: F) {
|
||||
get!().on_timer_tick(self, f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
jay-config/src/status.rs
Normal file
3
jay-config/src/status.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub fn set_status(status: &str) {
|
||||
get!().set_status(status);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue