Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] option to ignore caps lock, fixes #41 #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/config/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
}

#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
Expand Down
17 changes: 14 additions & 3 deletions src/input-backend/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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::<u8>).is_ok() {
event(&mut input, &iface_ref);
event(&input_config, &mut input, &iface_ref);
}

Ok(())
}

fn event(input: &mut Libinput, iface_ref: &InterfaceRef<DbusServer>) {
fn event(
input_config: &config::backend::InputBackendConfig,
input: &mut Libinput,
iface_ref: &InterfaceRef<DbusServer>,
) {
input.dispatch().unwrap();
for event in input.into_iter() {
if let Event::Keyboard(KeyboardEvent::Key(event)) = event {
Expand Down Expand Up @@ -118,6 +122,13 @@ fn event(input: &mut Libinput, iface_ref: &InterfaceRef<DbusServer>) {
_ => 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 {
Expand Down
Loading