config: allow handling switch events
This commit is contained in:
parent
55d55bf161
commit
cf233abb5a
21 changed files with 443 additions and 27 deletions
|
|
@ -8,7 +8,7 @@ use {
|
|||
libinput::consts::DeviceCapability,
|
||||
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
|
||||
},
|
||||
jay_config::video::GfxApi,
|
||||
jay_config::{input::SwitchEvent, video::GfxApi},
|
||||
std::{
|
||||
any::Any,
|
||||
error::Error,
|
||||
|
|
@ -312,6 +312,11 @@ pub enum InputEvent {
|
|||
time_usec: u64,
|
||||
cancelled: bool,
|
||||
},
|
||||
|
||||
SwitchEvent {
|
||||
time_usec: u64,
|
||||
event: SwitchEvent,
|
||||
},
|
||||
}
|
||||
|
||||
pub enum DrmEvent {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,14 @@ use {
|
|||
consts::{
|
||||
LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_KEY_STATE_PRESSED,
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
||||
LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF, LIBINPUT_SWITCH_STATE_ON,
|
||||
LIBINPUT_SWITCH_TABLET_MODE,
|
||||
},
|
||||
event::LibInputEvent,
|
||||
},
|
||||
utils::{bitflags::BitflagsExt, errorfmt::ErrorFmt},
|
||||
},
|
||||
jay_config::input::SwitchEvent,
|
||||
std::rc::Rc,
|
||||
uapi::c,
|
||||
};
|
||||
|
|
@ -99,6 +102,7 @@ impl MetalBackend {
|
|||
c::LIBINPUT_EVENT_GESTURE_PINCH_END => self.handle_gesture_pinch_end(event),
|
||||
c::LIBINPUT_EVENT_GESTURE_HOLD_BEGIN => self.handle_gesture_hold_begin(event),
|
||||
c::LIBINPUT_EVENT_GESTURE_HOLD_END => self.handle_gesture_hold_end(event),
|
||||
c::LIBINPUT_EVENT_SWITCH_TOGGLE => self.handle_switch_toggle(event),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -297,4 +301,23 @@ impl MetalBackend {
|
|||
cancelled: event.cancelled(),
|
||||
});
|
||||
}
|
||||
|
||||
fn handle_switch_toggle(self: &Rc<Self>, event: LibInputEvent) {
|
||||
let (event, dev) = unpack!(self, event, switch_event);
|
||||
let switch_event = match (event.switch(), event.switch_state()) {
|
||||
(LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_OFF) => SwitchEvent::LidOpened,
|
||||
(LIBINPUT_SWITCH_LID, LIBINPUT_SWITCH_STATE_ON) => SwitchEvent::LidClosed,
|
||||
(LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_OFF) => {
|
||||
SwitchEvent::ConvertedToLaptop
|
||||
}
|
||||
(LIBINPUT_SWITCH_TABLET_MODE, LIBINPUT_SWITCH_STATE_ON) => {
|
||||
SwitchEvent::ConvertedToTablet
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
dev.event(InputEvent::SwitchEvent {
|
||||
time_usec: event.time_usec(),
|
||||
event: switch_event,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use {
|
|||
jay_seat_events::{
|
||||
Axis120, AxisFrame, AxisInverted, AxisPx, AxisSource, AxisStop, Button, HoldBegin,
|
||||
HoldEnd, Key, Modifiers, PinchBegin, PinchEnd, PinchUpdate, PointerAbs, PointerRel,
|
||||
SwipeBegin, SwipeEnd, SwipeUpdate,
|
||||
SwipeBegin, SwipeEnd, SwipeUpdate, SwitchEvent,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -324,6 +324,26 @@ async fn run(seat_test: Rc<SeatTest>) {
|
|||
println!();
|
||||
}
|
||||
});
|
||||
let st = seat_test.clone();
|
||||
SwitchEvent::handle(tc, se, (), move |_, ev| {
|
||||
let event = match ev.event {
|
||||
0 => "lid opened",
|
||||
1 => "lid closed",
|
||||
2 => "converted to laptop",
|
||||
3 => "converted to tablet",
|
||||
_ => "unknown event",
|
||||
};
|
||||
if all || ev.seat == seat {
|
||||
if all {
|
||||
print!("Seat: {}, ", st.name(ev.seat));
|
||||
}
|
||||
println!(
|
||||
"Time: {:.4}, Device: {}, {event}",
|
||||
time(ev.time_usec),
|
||||
ev.input_device
|
||||
);
|
||||
}
|
||||
});
|
||||
pending::<()>().await;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use {
|
|||
ipc::{InitMessage, ServerFeature, ServerMessage, V1InitMessage},
|
||||
ConfigEntry, VERSION,
|
||||
},
|
||||
input::{InputDevice, Seat},
|
||||
input::{InputDevice, Seat, SwitchEvent},
|
||||
keyboard::{mods::Modifiers, syms::KeySym},
|
||||
video::{Connector, DrmDevice},
|
||||
},
|
||||
|
|
@ -144,6 +144,14 @@ impl ConfigProxy {
|
|||
pub fn idle(&self) {
|
||||
self.send(&ServerMessage::Idle);
|
||||
}
|
||||
|
||||
pub fn switch_event(&self, seat: SeatId, input_device: InputDeviceId, event: SwitchEvent) {
|
||||
self.send(&ServerMessage::SwitchEvent {
|
||||
seat: Seat(seat.raw() as _),
|
||||
input_device: InputDevice(input_device.raw() as _),
|
||||
event,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ConfigProxy {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
backend::KeyState,
|
||||
backend::{InputDeviceId, KeyState},
|
||||
client::Client,
|
||||
fixed::Fixed,
|
||||
ifs::wl_seat::{wl_pointer::PendingScroll, SeatId},
|
||||
|
|
@ -220,6 +220,22 @@ impl JaySeatEvents {
|
|||
cancelled: cancelled as _,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn send_switch_event(
|
||||
&self,
|
||||
seat: SeatId,
|
||||
input_device: InputDeviceId,
|
||||
time_usec: u64,
|
||||
event: jay_config::input::SwitchEvent,
|
||||
) {
|
||||
self.client.event(SwitchEvent {
|
||||
self_id: self.id,
|
||||
seat: seat.raw(),
|
||||
time_usec,
|
||||
input_device: input_device.raw(),
|
||||
event: event as _,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl JaySeatEventsRequestHandler for JaySeatEvents {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
backend::{ConnectorId, InputEvent, KeyState, AXIS_120},
|
||||
backend::{ConnectorId, InputDeviceId, InputEvent, KeyState, AXIS_120},
|
||||
client::ClientId,
|
||||
config::InvokedShortcut,
|
||||
fixed::Fixed,
|
||||
|
|
@ -37,9 +37,12 @@ use {
|
|||
xkbcommon::{KeyboardState, XkbState, XKB_KEY_DOWN, XKB_KEY_UP},
|
||||
},
|
||||
isnt::std_1::primitive::{IsntSlice2Ext, IsntSliceExt},
|
||||
jay_config::keyboard::{
|
||||
mods::{Modifiers, CAPS, NUM, RELEASE},
|
||||
syms::{KeySym, SYM_Escape},
|
||||
jay_config::{
|
||||
input::SwitchEvent,
|
||||
keyboard::{
|
||||
mods::{Modifiers, CAPS, NUM, RELEASE},
|
||||
syms::{KeySym, SYM_Escape},
|
||||
},
|
||||
},
|
||||
smallvec::SmallVec,
|
||||
std::{cell::RefCell, collections::hash_map::Entry, rc::Rc},
|
||||
|
|
@ -200,7 +203,8 @@ impl WlSeatGlobal {
|
|||
| InputEvent::PinchUpdate { time_usec, .. }
|
||||
| InputEvent::PinchEnd { time_usec, .. }
|
||||
| InputEvent::HoldBegin { time_usec, .. }
|
||||
| InputEvent::HoldEnd { time_usec, .. } => {
|
||||
| InputEvent::HoldEnd { time_usec, .. }
|
||||
| InputEvent::SwitchEvent { time_usec, .. } => {
|
||||
self.last_input_usec.set(time_usec);
|
||||
if self.idle_notifications.is_not_empty() {
|
||||
for (_, notification) in self.idle_notifications.lock().drain() {
|
||||
|
|
@ -299,6 +303,9 @@ impl WlSeatGlobal {
|
|||
time_usec,
|
||||
cancelled,
|
||||
} => self.hold_end(time_usec, cancelled),
|
||||
InputEvent::SwitchEvent { time_usec, event } => {
|
||||
self.switch_event(dev.device.id(), time_usec, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -504,6 +511,15 @@ impl WlSeatGlobal {
|
|||
self.gesture_owner.hold_end(self, time_usec, cancelled)
|
||||
}
|
||||
|
||||
fn switch_event(self: &Rc<Self>, dev: InputDeviceId, time_usec: u64, event: SwitchEvent) {
|
||||
self.state.for_each_seat_tester(|t| {
|
||||
t.send_switch_event(self.id, dev, time_usec, event);
|
||||
});
|
||||
if let Some(config) = self.state.config.get() {
|
||||
config.switch_event(self.id, dev, event);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn key_event<F>(
|
||||
self: &Rc<Self>,
|
||||
time_usec: u64,
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
|||
ServerMessage::DevicesEnumerated => {}
|
||||
ServerMessage::InterestReady { .. } => {}
|
||||
ServerMessage::Features { .. } => {}
|
||||
ServerMessage::SwitchEvent { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use {
|
||||
crate::libinput::{
|
||||
consts::{ButtonState, EventType, KeyState, PointerAxis},
|
||||
consts::{ButtonState, EventType, KeyState, PointerAxis, Switch, SwitchState},
|
||||
device::LibInputDevice,
|
||||
sys::{
|
||||
libinput_event, libinput_event_destroy, libinput_event_gesture,
|
||||
|
|
@ -10,14 +10,17 @@ use {
|
|||
libinput_event_gesture_get_finger_count, libinput_event_gesture_get_scale,
|
||||
libinput_event_gesture_get_time_usec, libinput_event_get_device,
|
||||
libinput_event_get_gesture_event, libinput_event_get_keyboard_event,
|
||||
libinput_event_get_pointer_event, libinput_event_get_type, libinput_event_keyboard,
|
||||
libinput_event_keyboard_get_key, libinput_event_keyboard_get_key_state,
|
||||
libinput_event_keyboard_get_time_usec, libinput_event_pointer,
|
||||
libinput_event_pointer_get_button, libinput_event_pointer_get_button_state,
|
||||
libinput_event_pointer_get_dx, libinput_event_pointer_get_dx_unaccelerated,
|
||||
libinput_event_pointer_get_dy, libinput_event_pointer_get_dy_unaccelerated,
|
||||
libinput_event_pointer_get_scroll_value, libinput_event_pointer_get_scroll_value_v120,
|
||||
libinput_event_pointer_get_time_usec, libinput_event_pointer_has_axis,
|
||||
libinput_event_get_pointer_event, libinput_event_get_switch_event,
|
||||
libinput_event_get_type, libinput_event_keyboard, libinput_event_keyboard_get_key,
|
||||
libinput_event_keyboard_get_key_state, libinput_event_keyboard_get_time_usec,
|
||||
libinput_event_pointer, libinput_event_pointer_get_button,
|
||||
libinput_event_pointer_get_button_state, libinput_event_pointer_get_dx,
|
||||
libinput_event_pointer_get_dx_unaccelerated, libinput_event_pointer_get_dy,
|
||||
libinput_event_pointer_get_dy_unaccelerated, libinput_event_pointer_get_scroll_value,
|
||||
libinput_event_pointer_get_scroll_value_v120, libinput_event_pointer_get_time_usec,
|
||||
libinput_event_pointer_has_axis, libinput_event_switch,
|
||||
libinput_event_switch_get_switch, libinput_event_switch_get_switch_state,
|
||||
libinput_event_switch_get_time_usec,
|
||||
},
|
||||
},
|
||||
std::marker::PhantomData,
|
||||
|
|
@ -43,6 +46,11 @@ pub struct LibInputEventGesture<'a> {
|
|||
pub(super) _phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
pub struct LibInputEventSwitch<'a> {
|
||||
pub(super) event: *mut libinput_event_switch,
|
||||
pub(super) _phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
impl<'a> Drop for LibInputEvent<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
|
@ -98,6 +106,18 @@ impl<'a> LibInputEvent<'a> {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn switch_event(&self) -> Option<LibInputEventSwitch> {
|
||||
let res = unsafe { libinput_event_get_switch_event(self.event) };
|
||||
if res.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(LibInputEventSwitch {
|
||||
event: res,
|
||||
_phantom: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LibInputEventKeyboard<'a> {
|
||||
|
|
@ -194,3 +214,17 @@ impl<'a> LibInputEventGesture<'a> {
|
|||
unsafe { libinput_event_gesture_get_angle_delta(self.event) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LibInputEventSwitch<'a> {
|
||||
pub fn time_usec(&self) -> u64 {
|
||||
unsafe { libinput_event_switch_get_time_usec(self.event) }
|
||||
}
|
||||
|
||||
pub fn switch(&self) -> Switch {
|
||||
unsafe { Switch(libinput_event_switch_get_switch(self.event)) }
|
||||
}
|
||||
|
||||
pub fn switch_state(&self) -> SwitchState {
|
||||
unsafe { SwitchState(libinput_event_switch_get_switch_state(self.event)) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ pub struct libinput_event_keyboard(u8);
|
|||
pub struct libinput_event_pointer(u8);
|
||||
#[repr(transparent)]
|
||||
pub struct libinput_event_gesture(u8);
|
||||
#[repr(transparent)]
|
||||
pub struct libinput_event_switch(u8);
|
||||
|
||||
#[link(name = "input")]
|
||||
extern "C" {
|
||||
|
|
@ -155,6 +157,15 @@ extern "C" {
|
|||
pub fn libinput_event_gesture_get_dy_unaccelerated(event: *mut libinput_event_gesture) -> f64;
|
||||
pub fn libinput_event_gesture_get_scale(event: *mut libinput_event_gesture) -> f64;
|
||||
pub fn libinput_event_gesture_get_angle_delta(event: *mut libinput_event_gesture) -> f64;
|
||||
|
||||
pub fn libinput_event_get_switch_event(
|
||||
event: *mut libinput_event,
|
||||
) -> *mut libinput_event_switch;
|
||||
pub fn libinput_event_switch_get_switch(event: *mut libinput_event_switch) -> libinput_switch;
|
||||
pub fn libinput_event_switch_get_switch_state(
|
||||
event: *mut libinput_event_switch,
|
||||
) -> libinput_switch_state;
|
||||
pub fn libinput_event_switch_get_time_usec(event: *mut libinput_event_switch) -> u64;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue