config: allow handling switch events
This commit is contained in:
parent
55d55bf161
commit
cf233abb5a
21 changed files with 443 additions and 27 deletions
|
|
@ -12,7 +12,7 @@ use {
|
|||
exec::Command,
|
||||
input::{
|
||||
acceleration::AccelProfile, capability::Capability, FocusFollowsMouseMode, InputDevice,
|
||||
Seat,
|
||||
Seat, SwitchEvent,
|
||||
},
|
||||
keyboard::{
|
||||
mods::{Modifiers, RELEASE},
|
||||
|
|
@ -95,6 +95,7 @@ pub(crate) struct Client {
|
|||
on_new_drm_device: RefCell<Option<Callback<DrmDevice>>>,
|
||||
on_del_drm_device: RefCell<Option<Callback<DrmDevice>>>,
|
||||
on_idle: RefCell<Option<Callback>>,
|
||||
on_switch_event: RefCell<HashMap<InputDevice, Callback<SwitchEvent>>>,
|
||||
bufs: RefCell<Vec<Vec<u8>>>,
|
||||
reload: Cell<bool>,
|
||||
read_interests: RefCell<HashMap<PollableId, Interest>>,
|
||||
|
|
@ -222,6 +223,7 @@ pub unsafe extern "C" fn init(
|
|||
on_new_drm_device: Default::default(),
|
||||
on_del_drm_device: Default::default(),
|
||||
on_idle: Default::default(),
|
||||
on_switch_event: Default::default(),
|
||||
bufs: Default::default(),
|
||||
reload: Cell::new(false),
|
||||
read_interests: Default::default(),
|
||||
|
|
@ -603,6 +605,16 @@ impl Client {
|
|||
*self.on_new_input_device.borrow_mut() = Some(cb(f));
|
||||
}
|
||||
|
||||
pub fn on_switch_event<F: FnMut(SwitchEvent) + 'static>(
|
||||
&self,
|
||||
input_device: InputDevice,
|
||||
f: F,
|
||||
) {
|
||||
self.on_switch_event
|
||||
.borrow_mut()
|
||||
.insert(input_device, cb(f));
|
||||
}
|
||||
|
||||
pub fn set_double_click_interval(&self, usec: u64) {
|
||||
self.send(&ClientMessage::SetDoubleClickIntervalUsec { usec });
|
||||
}
|
||||
|
|
@ -1258,7 +1270,9 @@ impl Client {
|
|||
run_cb("new input device", &handler, device);
|
||||
}
|
||||
}
|
||||
ServerMessage::DelInputDevice { .. } => {}
|
||||
ServerMessage::DelInputDevice { device } => {
|
||||
self.on_switch_event.borrow_mut().remove(&device);
|
||||
}
|
||||
ServerMessage::ConnectorConnect { device } => {
|
||||
let handler = self.on_connector_connected.borrow_mut().clone();
|
||||
if let Some(handler) = handler {
|
||||
|
|
@ -1332,6 +1346,17 @@ impl Client {
|
|||
}
|
||||
}
|
||||
}
|
||||
ServerMessage::SwitchEvent {
|
||||
seat,
|
||||
input_device,
|
||||
event,
|
||||
} => {
|
||||
let _ = seat;
|
||||
let cb = self.on_switch_event.borrow().get(&input_device).cloned();
|
||||
if let Some(cb) = cb {
|
||||
run_cb("switch event", &cb, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use {
|
|||
crate::{
|
||||
input::{
|
||||
acceleration::AccelProfile, capability::Capability, FocusFollowsMouseMode, InputDevice,
|
||||
Seat,
|
||||
Seat, SwitchEvent,
|
||||
},
|
||||
keyboard::{mods::Modifiers, syms::KeySym, Keymap},
|
||||
logging::LogLevel,
|
||||
|
|
@ -83,6 +83,11 @@ pub enum ServerMessage {
|
|||
effective_mods: Modifiers,
|
||||
sym: KeySym,
|
||||
},
|
||||
SwitchEvent {
|
||||
seat: Seat,
|
||||
input_device: InputDevice,
|
||||
event: SwitchEvent,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ impl InputDevice {
|
|||
pub fn devnode(self) -> String {
|
||||
get!(String::new()).input_device_devnode(self)
|
||||
}
|
||||
|
||||
/// Sets a callback that will be run if this device triggers a switch event.
|
||||
pub fn on_switch_event<F: FnMut(SwitchEvent) + 'static>(self, f: F) {
|
||||
get!().on_switch_event(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
/// A seat.
|
||||
|
|
@ -479,3 +484,26 @@ pub fn set_double_click_distance(distance: i32) {
|
|||
pub fn disable_default_seat() {
|
||||
get!().disable_default_seat();
|
||||
}
|
||||
|
||||
/// An event generated by a switch.
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum SwitchEvent {
|
||||
/// The lid of the device (usually a laptop) has been opened.
|
||||
///
|
||||
/// This is the default state.
|
||||
LidOpened,
|
||||
/// The lid of the device (usually a laptop) has been closed.
|
||||
///
|
||||
/// If the device is already in this state when the device is discovered, a synthetic
|
||||
/// event of this kind is generated.
|
||||
LidClosed,
|
||||
/// The device has been converted from tablet to laptop mode.
|
||||
///
|
||||
/// This is the default state.
|
||||
ConvertedToLaptop,
|
||||
/// The device has been converted from laptop to tablet mode.
|
||||
///
|
||||
/// If the device is already in this state when the device is discovered, a synthetic
|
||||
/// event of this kind is generated.
|
||||
ConvertedToTablet,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue