nixos-config/packages/evdev-proxy/add-evdev-selector.patch

102 lines
2.9 KiB
Diff

diff --git a/config.toml b/config.toml
index ba11ce4..3021e89 100644
--- a/config.toml
+++ b/config.toml
@@ -27,6 +27,8 @@ log_level = "INFO"
# on it's usb vendor:model identificator and device
# class (Mouse/Keyboard), useful for wireless devices
# with single receiver (e.g. Logitech Unifying Receiver)
+# * EVDEVClass -- Simple selector based on the PHYS udev attribute. Mainly
+# useful for use with key-mapper
#
# Example devices:
#[[device]]
diff --git a/src/config.rs b/src/config.rs
index 06ae8f5..10d7721 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -35,6 +35,9 @@ pub enum DeviceSelector {
model: u16,
class: USBHIDClass,
},
+ EVDEVClass{
+ phys: String,
+ },
}
pub fn read_config<P: AsRef<Path> + Debug + ToString>(path: P) -> Result<SelfConfig, ConfigError> {
diff --git a/src/main.rs b/src/main.rs
index 19055c7..b5c46ec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,7 +21,10 @@ fn selector_by_config(s: &config::DeviceSelector) -> Box<dyn udevdetect::DevFilt
},
config::DeviceSelector::USBIDClass{vendor, model, class} => {
Box::new(udevdetect::USBIDClassFilter::new(*vendor, *model, *class))
- }
+ },
+ config::DeviceSelector::EVDEVClass{phys} => {
+ Box::new(udevdetect::EVDEVFilter::new(String::from(phys)))
+ },
}
}
diff --git a/src/udevdetect/filter_evdev.rs b/src/udevdetect/filter_evdev.rs
new file mode 100644
index 0000000..51dc81e
--- /dev/null
+++ b/src/udevdetect/filter_evdev.rs
@@ -0,0 +1,34 @@
+use udev::{Device, Event};
+
+use crate::udevdetect::{DevFilter, get_device_property};
+
+#[derive(Debug)]
+pub struct EVDEVFilter {
+ phys: String,
+}
+impl EVDEVFilter {
+ pub fn new(phys: String) -> Self {
+ let f = EVDEVFilter {
+ phys: phys,
+ };
+ debug!("New EVDEV Filter for: {:?}", f.phys);
+ f
+ }
+}
+impl DevFilter for EVDEVFilter {
+ fn match_event(&self, e: &Event) -> bool {
+ return self.match_device(&e.device());
+ }
+
+ fn match_device(&self, e: &Device) -> bool {
+ match e.parent() {
+ Some(parent) => {
+ if get_device_property(&parent, "PHYS") != self.phys {
+ return false
+ }
+ true
+ },
+ None => false
+ }
+ }
+}
diff --git a/src/udevdetect/mod.rs b/src/udevdetect/mod.rs
index c2009a9..e9ed274 100644
--- a/src/udevdetect/mod.rs
+++ b/src/udevdetect/mod.rs
@@ -9,11 +9,13 @@ pub use self::filter::DevFilter;
pub use self::filter_usbid::USBIDFilter;
pub use self::filter_usbidclass::USBIDClassFilter;
pub use self::filter_usbidclass::USBHIDClass;
+pub use self::filter_evdev::EVDEVFilter;
mod listener;
mod filter;
mod filter_usbid;
mod filter_usbidclass;
+mod filter_evdev;
fn get_event_property<'a>(ev: &'a Event, key: &'a str) -> &'a str {
ev.property_value(key).unwrap_or(OsStr::new("")).to_str().unwrap_or("")