From 6140326f85857e3a13745584cf4df7a0ddf352db Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Wed, 9 Jan 2019 10:10:55 +0100 Subject: [PATCH] Basic exiting and TTY switching --- src/input/input_manager.rs | 8 ++++++++ src/input/keyboard.rs | 31 +++++++++++++++++++++++++++++++ src/input/mod.rs | 5 +++++ src/main.rs | 8 ++++---- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/input/input_manager.rs create mode 100644 src/input/keyboard.rs create mode 100644 src/input/mod.rs diff --git a/src/input/input_manager.rs b/src/input/input_manager.rs new file mode 100644 index 0000000..40eff9a --- /dev/null +++ b/src/input/input_manager.rs @@ -0,0 +1,8 @@ +use crate::input::Keyboard; + +use wlroots::input; + +pub fn input_manager() -> input::manager::Builder { + input::manager::Builder::default() + .keyboard_added(|_compositor_handle, _keyboard_handle| Some(Box::new(Keyboard))) +} diff --git a/src/input/keyboard.rs b/src/input/keyboard.rs new file mode 100644 index 0000000..3a59a58 --- /dev/null +++ b/src/input/keyboard.rs @@ -0,0 +1,31 @@ +use wlroots::{ + compositor, + input::{self, keyboard}, + xkbcommon::xkb::keysyms, +}; + +pub struct Keyboard; + +impl input::keyboard::Handler for Keyboard { + fn on_key( + &mut self, + compositor_handle: compositor::Handle, + _keyboard_handle: keyboard::Handle, + key_event: &keyboard::event::Key, + ) { + for key in key_event.pressed_keys() { + match key { + keysyms::KEY_Escape => compositor::terminate(), + keysyms::KEY_XF86Switch_VT_1 ..= keysyms::KEY_XF86Switch_VT_12 => { + compositor_handle.run(|compositor| { + let backend = compositor.backend_mut(); + if let Some(mut session) = backend.get_session() { + session.change_vt(key - keysyms::KEY_XF86Switch_VT_1 + 1); + } + }).unwrap(); + } + _ => {} + } + } + } +} diff --git a/src/input/mod.rs b/src/input/mod.rs new file mode 100644 index 0000000..c52eb78 --- /dev/null +++ b/src/input/mod.rs @@ -0,0 +1,5 @@ +mod input_manager; +mod keyboard; + +pub use self::input_manager::*; +pub use self::keyboard::*; diff --git a/src/main.rs b/src/main.rs index 2200dc2..ecf62c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod input; + use log::info; use wlroots::{ @@ -14,10 +16,7 @@ fn main() { fn init_logs() { init_logging(WLR_INFO, None); - env_logger::Builder::from_env( - env_logger::Env::default() - .filter("KIWMI_LOG") - ).init(); + env_logger::Builder::from_env(env_logger::Env::default().filter("KIWMI_LOG")).init(); info!("Logger initialized!"); } @@ -26,5 +25,6 @@ fn build_compositor() -> compositor::Compositor { compositor::Builder::new() .gles2(true) .data_device(true) + .input_manager(input::input_manager()) .build_auto(()) }