From 3aea01f9051c6f8dc9c2cb22e5e6569d54184c6a Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sat, 6 Feb 2016 13:36:15 -0500 Subject: [PATCH 1/3] Refactor: move variable to where used. Code is clearer if the definition is placed where needed. --- src/logkeys.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/logkeys.cc b/src/logkeys.cc index 61c7eb2..97df312 100644 --- a/src/logkeys.cc +++ b/src/logkeys.cc @@ -46,7 +46,6 @@ #endif #define COMMAND_STR_DUMPKEYS ( EXE_DUMPKEYS " -n | " EXE_GREP " '^\\([[:space:]]shift[[:space:]]\\)*\\([[:space:]]altgr[[:space:]]\\)*keycode'" ) -#define COMMAND_STR_DEVICES ( EXE_GREP " -E 'Handlers|EV=' /proc/bus/input/devices | " EXE_GREP " -B1 'EV=120013' | " EXE_GREP " -Eo 'event[0-9]+' ") #define COMMAND_STR_GET_PID ( (std::string(EXE_PS " ax | " EXE_GREP " '") + program_invocation_name + "' | " EXE_GREP " -v grep").c_str() ) #define INPUT_EVENT_PATH "/dev/input/" // standard path @@ -331,7 +330,11 @@ void determine_input_device() setegid(65534); seteuid(65534); // extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.) - std::stringstream output(execute(COMMAND_STR_DEVICES)); + // The compiler automatically concatenates these adjacent strings to a single string. + const char* cmd = EXE_GREP " -E 'Handlers|EV=' /proc/bus/input/devices | " + EXE_GREP " -B1 'EV=120013' | " + EXE_GREP " -Eo 'event[0-9]+' "; + std::stringstream output(execute(cmd)); std::vector results; std::string line; From 892f04f1d02eb38b2b53b6452b1d7d1bb76fc54e Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sat, 6 Feb 2016 13:39:59 -0500 Subject: [PATCH 2/3] Recognize Logitech K7570 keyboard. The usual keyboard event bitmask is 120013, but Logitech and some other keyboards have 12001F. Using both F and f as grep case-insensitivity flag may vary across systems. --- src/logkeys.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logkeys.cc b/src/logkeys.cc index 97df312..6fa12c0 100644 --- a/src/logkeys.cc +++ b/src/logkeys.cc @@ -332,7 +332,7 @@ void determine_input_device() // extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.) // The compiler automatically concatenates these adjacent strings to a single string. const char* cmd = EXE_GREP " -E 'Handlers|EV=' /proc/bus/input/devices | " - EXE_GREP " -B1 'EV=120013' | " + EXE_GREP " -B1 'EV=12001[3Ff]' | " EXE_GREP " -Eo 'event[0-9]+' "; std::stringstream output(execute(cmd)); From 5560126a74704d0a704df312f488da011c9bb79b Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Sat, 6 Feb 2016 13:57:06 -0500 Subject: [PATCH 3/3] Recognize other Logitech keyboard. Device name 'Eee PC WMI hotkeys' has EV=100013. Tweaked regex to handle. --- src/logkeys.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logkeys.cc b/src/logkeys.cc index 6fa12c0..c683fd3 100644 --- a/src/logkeys.cc +++ b/src/logkeys.cc @@ -332,7 +332,7 @@ void determine_input_device() // extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.) // The compiler automatically concatenates these adjacent strings to a single string. const char* cmd = EXE_GREP " -E 'Handlers|EV=' /proc/bus/input/devices | " - EXE_GREP " -B1 'EV=12001[3Ff]' | " + EXE_GREP " -B1 'EV=1[02]001[3Ff]' | " EXE_GREP " -Eo 'event[0-9]+' "; std::stringstream output(execute(cmd));