From dd89b5b1b3304497532bf7452572cfe9b7974dff Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 21 Jan 2025 01:19:30 +0000 Subject: [PATCH] [backend] option to ignore caps lock, fixes #41 No idea if this is a good approach[0], but it works for me. `/etc/xdg/swayosd/backend.toml` set to ``` [input] ignore_caps_lock_key = true ``` [0] I think in an ideal world we would ignore the capslock key and instead monitor the capslock status[1], but I have no idea how one would do that [1] I do actually like having a capslock status notifier - the reason I'm adding in support to ignore the capslock key is that I have the capslock key aliased to `escape`, so it no longer has anything to do with the capslock status --- src/config/backend.rs | 4 +++- src/input-backend/main.rs | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/config/backend.rs b/src/config/backend.rs index e2c9bbf..6896cb3 100644 --- a/src/config/backend.rs +++ b/src/config/backend.rs @@ -5,7 +5,9 @@ use std::path::PathBuf; #[derive(Deserialize, Default, Debug)] #[serde(deny_unknown_fields)] -pub struct InputBackendConfig {} +pub struct InputBackendConfig { + pub ignore_caps_lock_key: Option, +} #[derive(Deserialize, Default, Debug)] #[serde(deny_unknown_fields)] diff --git a/src/input-backend/main.rs b/src/input-backend/main.rs index ad280a7..67dfc1f 100644 --- a/src/input-backend/main.rs +++ b/src/input-backend/main.rs @@ -44,7 +44,7 @@ impl LibinputInterface for Interface { fn main() -> Result<(), zbus::Error> { // Parse Config - let _input_config = config::backend::read_backend_config() + let input_config = config::backend::read_backend_config() .expect("Failed to parse config file") .input; @@ -63,13 +63,17 @@ fn main() -> Result<(), zbus::Error> { let borrowed_fd = unsafe { BorrowedFd::borrow_raw(input.as_raw_fd()) }; let pollfd = PollFd::new(borrowed_fd, PollFlags::POLLIN); while poll(&mut [pollfd], None::).is_ok() { - event(&mut input, &iface_ref); + event(&input_config, &mut input, &iface_ref); } Ok(()) } -fn event(input: &mut Libinput, iface_ref: &InterfaceRef) { +fn event( + input_config: &config::backend::InputBackendConfig, + input: &mut Libinput, + iface_ref: &InterfaceRef, +) { input.dispatch().unwrap(); for event in input.into_iter() { if let Event::Keyboard(KeyboardEvent::Key(event)) = event { @@ -118,6 +122,13 @@ fn event(input: &mut Libinput, iface_ref: &InterfaceRef) { _ => continue, }; + // Special case because several people have the caps lock key + // bound to escape, so it doesn't affect the caps lock status + if ev_key == EV_KEY::KEY_CAPSLOCK && input_config.ignore_caps_lock_key.unwrap_or(false) + { + continue; + } + if let Some(path) = device.devnode() { if let Some(path) = path.to_str() { let event_info = EventInfo {