From 0ff1afd6628d9a4fcc6fad3d70b86d62b59c18b1 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 9 Feb 2022 14:25:42 +0100 Subject: [PATCH] input: Add some basic keyboard control --- src/input/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 2a8f7065..ed0a07d5 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::state::Common; -#[cfg(feature = "debug")] use smithay::{backend::input::KeyState, wayland::seat::keysyms}; use smithay::{ backend::input::{Device, DeviceCapability, InputBackend, InputEvent}, @@ -208,11 +207,50 @@ impl Common { serial, time, |modifiers, handle| { - // here we can handle global shortcuts and the like - if userdata.get::().unwrap().filter(&handle) { + if state == KeyState::Released && userdata.get::().unwrap().filter(&handle) { return FilterResult::Intercept(()); } + // here we can handle global shortcuts and the like + if modifiers.logo + && handle.raw_syms().contains(&keysyms::KEY_Return) + && state == KeyState::Pressed + { + if let Err(err) = std::process::Command::new("gnome-terminal") + .env("WAYLAND_DISPLAY", &self.socket) + .spawn() + { + slog_scope::warn!("Failed to spawn terminal: {}", err); + } + userdata.get::().unwrap().add(&handle); + return FilterResult::Intercept(()); + } + + if modifiers.logo + && handle.raw_syms().iter().any(|sym| *sym >= keysyms::KEY_0 && *sym <= keysyms::KEY_9) + && state == KeyState::Pressed + { + let current_output = active_output(seat, &self); + let key_num = handle.raw_syms() + .iter() + .find(|sym| **sym >= keysyms::KEY_0 && **sym <= keysyms::KEY_9) + .unwrap() - keysyms::KEY_0; + let workspace = match key_num { + 0 => 9, + x => x - 1, + }; + self.spaces.activate(¤t_output, workspace as usize); + userdata.get::().unwrap().add(&handle); + return FilterResult::Intercept(()); + } + + if modifiers.logo && modifiers.shift + && handle.raw_syms().contains(&keysyms::KEY_Escape) + && state == KeyState::Pressed + { + self.should_stop = true; + } + #[cfg(feature = "debug")] { self.egui.modifiers = modifiers.clone(); @@ -247,7 +285,6 @@ impl Common { } } - let _ = (modifiers, handle); FilterResult::Forward }, );