Skip to content

Commit 75b94d0

Browse files
authored
[backend] option to ignore caps lock, fixes #41 (#123)
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
1 parent b4b7679 commit 75b94d0

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/config/backend.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use std::path::PathBuf;
55

66
#[derive(Deserialize, Default, Debug)]
77
#[serde(deny_unknown_fields)]
8-
pub struct InputBackendConfig {}
8+
pub struct InputBackendConfig {
9+
pub ignore_caps_lock_key: Option<bool>,
10+
}
911

1012
#[derive(Deserialize, Default, Debug)]
1113
#[serde(deny_unknown_fields)]

src/input-backend/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl LibinputInterface for Interface {
4444

4545
fn main() -> Result<(), zbus::Error> {
4646
// Parse Config
47-
let _input_config = config::backend::read_backend_config()
47+
let input_config = config::backend::read_backend_config()
4848
.expect("Failed to parse config file")
4949
.input;
5050

@@ -63,13 +63,17 @@ fn main() -> Result<(), zbus::Error> {
6363
let borrowed_fd = unsafe { BorrowedFd::borrow_raw(input.as_raw_fd()) };
6464
let pollfd = PollFd::new(borrowed_fd, PollFlags::POLLIN);
6565
while poll(&mut [pollfd], None::<u8>).is_ok() {
66-
event(&mut input, &iface_ref);
66+
event(&input_config, &mut input, &iface_ref);
6767
}
6868

6969
Ok(())
7070
}
7171

72-
fn event(input: &mut Libinput, iface_ref: &InterfaceRef<DbusServer>) {
72+
fn event(
73+
input_config: &config::backend::InputBackendConfig,
74+
input: &mut Libinput,
75+
iface_ref: &InterfaceRef<DbusServer>,
76+
) {
7377
input.dispatch().unwrap();
7478
for event in input.into_iter() {
7579
if let Event::Keyboard(KeyboardEvent::Key(event)) = event {
@@ -118,6 +122,13 @@ fn event(input: &mut Libinput, iface_ref: &InterfaceRef<DbusServer>) {
118122
_ => continue,
119123
};
120124

125+
// Special case because several people have the caps lock key
126+
// bound to escape, so it doesn't affect the caps lock status
127+
if ev_key == EV_KEY::KEY_CAPSLOCK && input_config.ignore_caps_lock_key.unwrap_or(false)
128+
{
129+
continue;
130+
}
131+
121132
if let Some(path) = device.devnode() {
122133
if let Some(path) = path.to_str() {
123134
let event_info = EventInfo {

0 commit comments

Comments
 (0)