From e2fa4ba49eee462da16b4917256506d7f4f46153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sun, 23 May 2021 21:03:14 +0200 Subject: [PATCH] [linuxinput] Handle all kinds of buttons (#10730) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously only the basic keyboard buttons where handled. Now all buttons known to Linux, or rather libevdev are reported. Reported-in: https://community.openhab.org/t/linuxinput-binding-and-mouse-capture/122612 Reported-in: https://github.com/t-8ch/binding-linuxinput/issues/5 Signed-off-by: Thomas Weißschuh --- .../binding/linuxinput/internal/evdev4j/EvdevDevice.java | 7 ++++++- .../linuxinput/internal/evdev4j/jnr/EvdevLibrary.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/EvdevDevice.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/EvdevDevice.java index f2ca21cf968..978aee31a93 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/EvdevDevice.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/EvdevDevice.java @@ -189,7 +189,7 @@ public class EvdevDevice implements Closeable { public Collection enumerateKeys() { int minKey = 0; - int maxKey = 255 - 1; + int maxKey = lib.event_type_get_max(EvdevLibrary.Type.KEY.intValue()); List result = new ArrayList<>(); for (int i = minKey; i <= maxKey; i++) { if (has(EvdevLibrary.Type.KEY, i)) { @@ -215,6 +215,11 @@ public class EvdevDevice implements Closeable { public String getName() { return lib.event_code_get_name(EvdevLibrary.Type.KEY.intValue(), code); } + + @Override + public String toString() { + return String.valueOf(code); + } } public static class InputEvent { diff --git a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/jnr/EvdevLibrary.java b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/jnr/EvdevLibrary.java index 2a26425e37c..7eca6b89bf1 100644 --- a/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/jnr/EvdevLibrary.java +++ b/bundles/org.openhab.binding.linuxinput/src/main/java/org/openhab/binding/linuxinput/internal/evdev4j/jnr/EvdevLibrary.java @@ -98,6 +98,8 @@ public interface EvdevLibrary { int enable_event_type(@In Handle handle, int type); + int event_type_get_max(int type); + int disable_event_type(@In Handle handle, int type); boolean has_event_code(@In Handle handle, int type, int code);