mirror of
https://github.com/pinnacle-comp/pinnacle.git
synced 2024-12-27 21:58:18 +01:00
Add vt switching
This commit is contained in:
parent
a76512c0aa
commit
7123ecf8ba
2 changed files with 129 additions and 21 deletions
|
@ -122,7 +122,7 @@ struct UdevOutputId {
|
|||
}
|
||||
|
||||
pub struct UdevData {
|
||||
session: LibSeatSession,
|
||||
pub session: LibSeatSession,
|
||||
display_handle: DisplayHandle,
|
||||
dmabuf_state: Option<(DmabufState, DmabufGlobal)>,
|
||||
primary_gpu: DrmNode,
|
||||
|
|
148
src/input.rs
148
src/input.rs
|
@ -8,10 +8,10 @@ use crate::{
|
|||
window::WindowElement,
|
||||
};
|
||||
use smithay::{
|
||||
backend::input::{
|
||||
backend::{input::{
|
||||
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
|
||||
KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent,
|
||||
},
|
||||
}, session::Session},
|
||||
desktop::{layer_map_for_output, space::SpaceElement},
|
||||
input::{
|
||||
keyboard::{keysyms, FilterResult},
|
||||
|
@ -304,6 +304,26 @@ impl<B: Backend> State<B> {
|
|||
.axis(self, frame);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
impl State<WinitData> {
|
||||
pub fn process_input_event<B: InputBackend>(&mut self, event: InputEvent<B>) {
|
||||
match event {
|
||||
// TODO: rest of input events
|
||||
|
||||
// InputEvent::DeviceAdded { device } => todo!(),
|
||||
// InputEvent::DeviceRemoved { device } => todo!(),
|
||||
InputEvent::Keyboard { event } => self.keyboard::<B>(event),
|
||||
// InputEvent::PointerMotion { event } => {}
|
||||
InputEvent::PointerMotionAbsolute { event } => self.pointer_motion_absolute::<B>(event),
|
||||
InputEvent::PointerButton { event } => self.pointer_button::<B>(event),
|
||||
InputEvent::PointerAxis { event } => self.pointer_axis::<B>(event),
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let time = event.time_msec();
|
||||
|
@ -351,6 +371,13 @@ impl<B: Backend> State<B> {
|
|||
&& keysym.modified_sym() == keysyms::KEY_Escape
|
||||
{
|
||||
return FilterResult::Intercept(CallbackId(999999));
|
||||
} else if modifiers.ctrl && modifiers.alt {
|
||||
if let mut vt @ keysyms::KEY_XF86Switch_VT_1..=keysyms::KEY_XF86Switch_VT_12 =
|
||||
keysym.modified_sym() {
|
||||
vt = vt - keysyms::KEY_XF86Switch_VT_1 + 1;
|
||||
tracing::info!("Switching to vt {vt}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,24 +414,6 @@ impl<B: Backend> State<B> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State<WinitData> {
|
||||
pub fn process_input_event<B: InputBackend>(&mut self, event: InputEvent<B>) {
|
||||
match event {
|
||||
// TODO: rest of input events
|
||||
|
||||
// InputEvent::DeviceAdded { device } => todo!(),
|
||||
// InputEvent::DeviceRemoved { device } => todo!(),
|
||||
InputEvent::Keyboard { event } => self.keyboard::<B>(event),
|
||||
// InputEvent::PointerMotion { event } => {}
|
||||
InputEvent::PointerMotionAbsolute { event } => self.pointer_motion_absolute::<B>(event),
|
||||
InputEvent::PointerButton { event } => self.pointer_button::<B>(event),
|
||||
InputEvent::PointerAxis { event } => self.pointer_axis::<B>(event),
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn pointer_motion_absolute<I: InputBackend>(&mut self, event: I::PointerMotionAbsoluteEvent) {
|
||||
let Some(output) = self.space.outputs().next() else { return; };
|
||||
|
@ -470,6 +479,105 @@ impl State<UdevData> {
|
|||
}
|
||||
}
|
||||
|
||||
fn keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let time = event.time_msec();
|
||||
let press_state = event.state();
|
||||
let mut move_mode = false;
|
||||
let action = self
|
||||
.seat
|
||||
.get_keyboard()
|
||||
.expect("Seat has no keyboard") // FIXME: handle err
|
||||
.input(
|
||||
self,
|
||||
event.key_code(),
|
||||
press_state,
|
||||
serial,
|
||||
time,
|
||||
|state, modifiers, keysym| {
|
||||
if press_state == KeyState::Pressed {
|
||||
let mut modifier_mask = Vec::<Modifier>::new();
|
||||
if modifiers.alt {
|
||||
modifier_mask.push(Modifier::Alt);
|
||||
}
|
||||
if modifiers.shift {
|
||||
modifier_mask.push(Modifier::Shift);
|
||||
}
|
||||
if modifiers.ctrl {
|
||||
modifier_mask.push(Modifier::Ctrl);
|
||||
}
|
||||
if modifiers.logo {
|
||||
modifier_mask.push(Modifier::Super);
|
||||
}
|
||||
let raw_sym = if keysym.raw_syms().len() == 1 {
|
||||
keysym.raw_syms()[0]
|
||||
} else {
|
||||
keysyms::KEY_NoSymbol
|
||||
};
|
||||
if let Some(callback_id) = state
|
||||
.input_state
|
||||
.keybinds
|
||||
.get(&(modifier_mask.into(), raw_sym))
|
||||
{
|
||||
return FilterResult::Intercept(*callback_id);
|
||||
} else if modifiers.ctrl
|
||||
&& modifiers.shift
|
||||
&& modifiers.alt
|
||||
&& keysym.modified_sym() == keysyms::KEY_Escape
|
||||
{
|
||||
return FilterResult::Intercept(CallbackId(999999));
|
||||
} else if modifiers.ctrl && modifiers.alt {
|
||||
if let mut vt @ keysyms::KEY_XF86Switch_VT_1..=keysyms::KEY_XF86Switch_VT_12 =
|
||||
keysym.modified_sym() {
|
||||
vt = vt - keysyms::KEY_XF86Switch_VT_1 + 1;
|
||||
return FilterResult::Intercept(CallbackId(1000000 + vt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if keysym.modified_sym() == keysyms::KEY_Control_L {
|
||||
match press_state {
|
||||
KeyState::Pressed => {
|
||||
move_mode = true;
|
||||
}
|
||||
KeyState::Released => {
|
||||
move_mode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
FilterResult::Forward
|
||||
},
|
||||
);
|
||||
|
||||
self.move_mode = move_mode;
|
||||
|
||||
if let Some(callback_id) = action {
|
||||
if callback_id.0 == 999999 {
|
||||
self.loop_signal.stop();
|
||||
return;
|
||||
}
|
||||
if callback_id.0 > 1000000 {
|
||||
let vt = callback_id.0 - 1000000;
|
||||
tracing::info!("Switching to vt {vt}");
|
||||
if let Err(err) = self.backend_data.session.change_vt(vt as i32) {
|
||||
tracing::error!("Failed to switch to vt {vt}: {err}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(stream) = self.api_state.stream.as_ref() {
|
||||
if let Err(err) = crate::api::send_to_client(
|
||||
&mut stream.lock().expect("Could not lock stream mutex"),
|
||||
&OutgoingMsg::CallCallback {
|
||||
callback_id,
|
||||
args: None,
|
||||
},
|
||||
) {
|
||||
tracing::warn!("error sending msg to client: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) {
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
self.pointer_location += event.delta();
|
||||
|
|
Loading…
Reference in a new issue