mirror of https://github.com/wayvr-org/wayvr.git
refactor KeyCombo
This commit is contained in:
parent
cf6bfe855e
commit
ca550f356b
|
|
@ -30,14 +30,14 @@ const POLL_TIMEOUT_MS: i32 = 20;
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum KeyCombo {
|
||||
Super1,
|
||||
Super2,
|
||||
Super3,
|
||||
Super4,
|
||||
SuperTab,
|
||||
AltF4,
|
||||
Set1,
|
||||
Set2,
|
||||
Set3,
|
||||
Set4,
|
||||
SwitchApp,
|
||||
CloseApp,
|
||||
/// Always consumed by InputCapture internally
|
||||
CtrlAltDel,
|
||||
EmergencyRelease,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -553,7 +553,7 @@ fn process_libinput_event(
|
|||
if !grabbed {
|
||||
// while ungrabbed, SuperTab will arm an automatic grab
|
||||
if allow_deferred_grab
|
||||
&& key_combo_is_pressed(KeyCombo::SuperTab, &state.pressed_keys)
|
||||
&& key_combo_is_pressed(KeyCombo::SwitchApp, &state.pressed_keys)
|
||||
{
|
||||
*pending_grab = true;
|
||||
}
|
||||
|
|
@ -561,19 +561,19 @@ fn process_libinput_event(
|
|||
return ProcessResult::Continue;
|
||||
}
|
||||
|
||||
if pressed && key_combo_is_pressed(KeyCombo::CtrlAltDel, &state.pressed_keys) {
|
||||
if pressed && key_combo_is_pressed(KeyCombo::EmergencyRelease, &state.pressed_keys) {
|
||||
log::info!("Ctrl+Alt+Del pressed, ungrabbing all input devices");
|
||||
return ProcessResult::EmergencyUngrab;
|
||||
}
|
||||
|
||||
// while grabbed, these combos get emitted as normal
|
||||
for combo in [
|
||||
KeyCombo::SuperTab,
|
||||
KeyCombo::AltF4,
|
||||
KeyCombo::Super1,
|
||||
KeyCombo::Super2,
|
||||
KeyCombo::Super3,
|
||||
KeyCombo::Super4,
|
||||
KeyCombo::SwitchApp,
|
||||
KeyCombo::CloseApp,
|
||||
KeyCombo::Set1,
|
||||
KeyCombo::Set2,
|
||||
KeyCombo::Set3,
|
||||
KeyCombo::Set4,
|
||||
] {
|
||||
let combo_pressed = key_combo_is_pressed(combo, &state.pressed_keys);
|
||||
let was_pressed = state.active_combos.contains(&combo);
|
||||
|
|
@ -873,20 +873,20 @@ fn key_combo_is_pressed(combo: KeyCombo, pressed: &HashSet<u16>) -> bool {
|
|||
let alt =
|
||||
pressed.contains(&KeyCode::KEY_LEFTALT.0) || pressed.contains(&KeyCode::KEY_RIGHTALT.0);
|
||||
|
||||
let ctrl =
|
||||
pressed.contains(&KeyCode::KEY_LEFTCTRL.0) || pressed.contains(&KeyCode::KEY_RIGHTCTRL.0);
|
||||
// let ctrl =
|
||||
// pressed.contains(&KeyCode::KEY_LEFTCTRL.0) || pressed.contains(&KeyCode::KEY_RIGHTCTRL.0);
|
||||
|
||||
let meta =
|
||||
pressed.contains(&KeyCode::KEY_LEFTMETA.0) || pressed.contains(&KeyCode::KEY_RIGHTMETA.0);
|
||||
|
||||
match combo {
|
||||
KeyCombo::AltF4 => alt && pressed.contains(&KeyCode::KEY_F4.0),
|
||||
KeyCombo::CtrlAltDel => ctrl && alt && pressed.contains(&KeyCode::KEY_DELETE.0),
|
||||
KeyCombo::SuperTab => meta && pressed.contains(&KeyCode::KEY_TAB.0),
|
||||
KeyCombo::Super1 => meta && pressed.contains(&KeyCode::KEY_1.0),
|
||||
KeyCombo::Super2 => meta && pressed.contains(&KeyCode::KEY_2.0),
|
||||
KeyCombo::Super3 => meta && pressed.contains(&KeyCode::KEY_3.0),
|
||||
KeyCombo::Super4 => meta && pressed.contains(&KeyCode::KEY_4.0),
|
||||
KeyCombo::CloseApp => alt && pressed.contains(&KeyCode::KEY_F4.0),
|
||||
KeyCombo::EmergencyRelease => meta && pressed.contains(&KeyCode::KEY_BACKSPACE.0),
|
||||
KeyCombo::SwitchApp => meta && pressed.contains(&KeyCode::KEY_X.0),
|
||||
KeyCombo::Set1 => meta && pressed.contains(&KeyCode::KEY_1.0),
|
||||
KeyCombo::Set2 => meta && pressed.contains(&KeyCode::KEY_2.0),
|
||||
KeyCombo::Set3 => meta && pressed.contains(&KeyCode::KEY_3.0),
|
||||
KeyCombo::Set4 => meta && pressed.contains(&KeyCode::KEY_4.0),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -847,13 +847,13 @@ impl WvrServerState {
|
|||
self.wm.keyboard_focus = None;
|
||||
}
|
||||
input_capture::CapturedEvent::KeyCombo { combo, pressed } => match combo {
|
||||
input_capture::KeyCombo::AltF4 if pressed => {
|
||||
input_capture::KeyCombo::CloseApp if pressed => {
|
||||
if let Some(hover) = self.wm.mouse.as_mut() {
|
||||
let window_handle = hover.hover_window;
|
||||
self.close_window(window_handle);
|
||||
}
|
||||
}
|
||||
input_capture::KeyCombo::SuperTab => {
|
||||
input_capture::KeyCombo::SwitchApp => {
|
||||
if pressed {
|
||||
input_state.picking_focus = super::input::FocusPickState::Aiming;
|
||||
} else {
|
||||
|
|
@ -870,16 +870,16 @@ impl WvrServerState {
|
|||
);
|
||||
}
|
||||
}
|
||||
input_capture::KeyCombo::Super1 if pressed => {
|
||||
input_capture::KeyCombo::Set1 if pressed => {
|
||||
tasks.enqueue(TaskType::Overlay(OverlayTask::ToggleSet(0)))
|
||||
}
|
||||
input_capture::KeyCombo::Super2 if pressed => {
|
||||
input_capture::KeyCombo::Set2 if pressed => {
|
||||
tasks.enqueue(TaskType::Overlay(OverlayTask::ToggleSet(1)))
|
||||
}
|
||||
input_capture::KeyCombo::Super3 if pressed => {
|
||||
input_capture::KeyCombo::Set3 if pressed => {
|
||||
tasks.enqueue(TaskType::Overlay(OverlayTask::ToggleSet(2)))
|
||||
}
|
||||
input_capture::KeyCombo::Super4 if pressed => {
|
||||
input_capture::KeyCombo::Set4 if pressed => {
|
||||
tasks.enqueue(TaskType::Overlay(OverlayTask::ToggleSet(3)))
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
Loading…
Reference in New Issue