From 9219d32d6afe57f3aab06f0db6b0a75fbf6b5132 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Mon, 23 Jun 2025 10:31:28 +0200 Subject: [PATCH 1/2] Supporting media keys (wayland + Windows) for now. --- src/linux/wayland/keycodes.rs | 19 +++++++++++++++++-- src/rdev.rs | 9 +++++++++ src/windows/keycodes.rs | 8 +++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/linux/wayland/keycodes.rs b/src/linux/wayland/keycodes.rs index 5a813b3..59a939d 100644 --- a/src/linux/wayland/keycodes.rs +++ b/src/linux/wayland/keycodes.rs @@ -153,7 +153,15 @@ decl_keycodes!( Kp7, 71, Kp8, 72, Kp9, 73, - KpDelete, 83 + KpDelete, 83, + VolumeMute, 113, + VolumeDown, 114, + VolumeUp, 115, + NextTrack, 163, + PlayPause, 164, + PreviousTrack, 165, + PlayCd, 200, + Function, 464 ); #[rustfmt::skip] @@ -259,7 +267,14 @@ decl_keycodes_uinput!( Key::Delete , UKey::Delete, Key::Pause , UKey::Pause, Key::MetaLeft , UKey::LeftMeta, - Key::PrintScreen , UKey::Print + Key::PrintScreen , UKey::Print, + Key::PlayPause, UKey::PlayPause, + Key::PlayCd, UKey::PlayCD, + Key::VolumeMute, UKey::Mute, + Key::VolumeDown, UKey::VolumeDown, + Key::VolumeUp, UKey::VolumeUp, + Key::NextTrack, UKey::NextSong, + Key::PreviousTrack, UKey::PreviousSong //Key::IntlBackslash , UKey::Backslash ); diff --git a/src/rdev.rs b/src/rdev.rs index cfc71f9..5009995 100644 --- a/src/rdev.rs +++ b/src/rdev.rs @@ -220,6 +220,15 @@ pub enum Key { Kp9, KpDelete, Function, + VolumeUp, + VolumeDown, + VolumeMute, + BrightnessUp, + BrightnessDown, + PreviousTrack, + PlayPause, + PlayCd, + NextTrack, Unknown(u32), } diff --git a/src/windows/keycodes.rs b/src/windows/keycodes.rs index 6d1a13f..caa0b3a 100644 --- a/src/windows/keycodes.rs +++ b/src/windows/keycodes.rs @@ -145,7 +145,13 @@ decl_keycodes! { Kp7, 103, Kp8, 104, Kp9, 105, - KpDelete, 110 + KpDelete, 110, + VolumeMute, 173, + VolumeDown, 174, + VolumeUp, 175, + NextTrack, 176, + PreviousTrack, 177, + PlayPause, 179 } #[cfg(test)] From 00627bf3b20737ba5f4cce9f352160e86a8a9d0c Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Mon, 23 Jun 2025 10:39:11 +0200 Subject: [PATCH 2/2] Clippy on Linux. --- src/linux/wayland/grab.rs | 5 +---- src/linux/wayland/listen.rs | 1 + src/linux/wayland/xkb_keycodes.rs | 2 +- src/linux/x11/grab.rs | 5 +---- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/linux/wayland/grab.rs b/src/linux/wayland/grab.rs index 361400b..abcd4ee 100644 --- a/src/linux/wayland/grab.rs +++ b/src/linux/wayland/grab.rs @@ -581,10 +581,7 @@ fn setup_inotify(epoll_fd: RawFd, devices: &[Device]) -> io::Result { //Ensure there is space for inotify at last epoll index. if devices.len() as u64 >= INOTIFY_DATA { eprintln!("number of devices: {}", devices.len()); - return Err(io::Error::new( - io::ErrorKind::Other, - "too many device files!", - )); + return Err(io::Error::other("too many device files!")); } // Set up inotify to listen for new devices being plugged in let inotify = inotify_devices()?; diff --git a/src/linux/wayland/listen.rs b/src/linux/wayland/listen.rs index 66086f3..761e161 100644 --- a/src/linux/wayland/listen.rs +++ b/src/linux/wayland/listen.rs @@ -73,6 +73,7 @@ fn convert(keyboard: &mut Keyboard, libevent: LibEvent) -> Option { impl LibinputInterface for Interface { fn open_restricted(&mut self, path: &Path, flags: i32) -> Result { + #[allow(clippy::bad_bit_mask)] OpenOptions::new() .custom_flags(flags) .read((flags & O_RDONLY != 0) | (flags & O_RDWR != 0)) diff --git a/src/linux/wayland/xkb_keycodes.rs b/src/linux/wayland/xkb_keycodes.rs index 3f59a54..8c64f03 100644 --- a/src/linux/wayland/xkb_keycodes.rs +++ b/src/linux/wayland/xkb_keycodes.rs @@ -3,5 +3,5 @@ use std::os::raw::c_uint; // Maps our internal keycodes to XKB keycodes pub fn internal_to_xkb_keycode(internal_code: c_uint) -> u32 { // XKB keycodes start at 8, so we need to offset them - internal_code as u32 + 8 + internal_code + 8 } diff --git a/src/linux/x11/grab.rs b/src/linux/x11/grab.rs index fd49934..d59144c 100644 --- a/src/linux/x11/grab.rs +++ b/src/linux/x11/grab.rs @@ -516,10 +516,7 @@ fn setup_inotify(epoll_fd: RawFd, devices: &[Device]) -> io::Result { //Ensure there is space for inotify at last epoll index. if devices.len() as u64 >= INOTIFY_DATA { eprintln!("number of devices: {}", devices.len()); - return Err(io::Error::new( - io::ErrorKind::Other, - "too many device files!", - )); + return Err(io::Error::other("too many device files!")); } // Set up inotify to listen for new devices being plugged in let inotify = inotify_devices()?;