alexmohr / keyboard-backlight

Controls the keyboard backlight of notebooks to conserve power by turning keyboard backlight off when not in use
MIT License
14 stars 3 forks source link

Mouse detection bug #20

Open skiv71 opened 1 year ago

skiv71 commented 1 year ago

Hi, great application!

I've noticed a bug when deploying this application in fydeos, but on reviewing the source, I see a possible bug in the -M choices 0,1,2.

I've not seen this issue on fedora, ubuntu etc and even brunch, but I think it must be down to the driver being used.

Basically, in 0 (default) the code was missing my: -

/dev/input/by-id/pci-0000:00:15.0-platform-i2c_designware.0-event-mouse -> ../event9

I think it relates to https://github.com/alexmohr/keyboard-backlight/blob/master/kbd_backlight.cpp#L473

I was able to workaround by specifying -m 1 (internal only), but really, option 0 should pick this up.

alexmohr commented 1 year ago

you can try the following patch

diff --git a/kbd_backlight.cpp b/kbd_backlight.cpp
index a964be4..602cf0c 100644
--- a/kbd_backlight.cpp
+++ b/kbd_backlight.cpp
@@ -476,7 +476,7 @@ int main(int argc, char **argv) {
                          "/dev/input/",
                          std::regex(".*mice.*"),
                          inputDevices);
-     break;
+     [[fallthrough]];
    case INTERNAL:
      get_devices_in_path(ignoredDevices,
                          "/dev/input/by-path",
skiv71 commented 1 year ago

Sorry, I'm not actually sure how to apply this. I added the fallthrough manually and compiled, but it did not work as hoped.

Did I miss something?

alexmohr commented 1 year ago

Did you also remove the break?

skiv71 commented 1 year ago

Ah no, which looking at it now, is the same change I was gonna hack myself to fix it. Good ol' switch statements.

I'll try it soon, but I'm sure it'll work

skiv71 commented 1 year ago

Yea, that works fine

skiv71 commented 1 year ago

Hi Alex, wonder if you can please assist me again? I'm trying to get this working on chrome os flex... and I can for keyboard detection... but the OS doesn't implement the /dev/input/by-path directory.

I have found the event file (/dev/input/event5) and I've found the device in /sys/class/input/input6, but I'm not sure how to modify the search to get it to read the events?

I've tried /dev/input with regex .event5 but it doesn't work :(

alexmohr commented 1 year ago

in this line https://github.com/alexmohr/keyboard-backlight/blob/master/kbd_backlight.cpp#L477 replace std::regex(".*mice.*"), with std::regex("event5") This should detect mouse events in /dev/input/event5 If you need more than 1 event file you can detect multiple files by adding multiple regex conditions std::regex("event[5,10,1]") to detect events inevent5,event10andevent1` Mouse detection mode must be set to 'all'

alexmohr commented 1 year ago

I'm not sure if this is what you've done already. If it is make sure event5 is actually the correct event file. Do you get any errors? If not please enable debug output by running cmake -DDEBUG_LEVEL=-g3 -DCMAKE_BUILD_TYPE=Debug Then start the application in foreground mode (-f) and post the output here

skiv71 commented 1 year ago

Hey... thanks for reply. I actually tried that last night, with no joy.

I know event5 is the right device file as if I cat it, touchpad input fills the screen.

I'll build it again now with debug and get back to you... thanks

skiv71 commented 1 year ago

Ok, this is what I have... I used options -f -m 0

/home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:454: Parsing options... /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:465: Using backlight device: /sys/class/leds/tpacpi::kbd_backlight/brightness /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:467: Getting keyboards... /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sleep button" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="lid switch" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="power button" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:178: Detected keyboard: n: name="at translated set 2 keyboard" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:194: Added keyboard /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="syna8017:00 06cb:ceb2 mouse" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="syna8017:00 06cb:ceb2 touchpad" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="video bus" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="intel hid events" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="thinkpad extra buttons" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="tpps/2 elan trackpoint" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sof-hda-dsp mic" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sof-hda-dsp headphone" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sof-hda-dsp hdmi/dp,pcm=3" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sof-hda-dsp hdmi/dp,pcm=4" /home/chronos/user/Downloads/keyboard-backlight-master/kbd_backlight.cpp:180: Ignoring non keyboard device: n: name="sof-hda-dsp hdmi/dp,pcm=5"

alexmohr commented 1 year ago

Hmm I don't have any idea why it fails. I created a chrome-os-flex-debug with more logs. If you can repeat the test with this branch we might get an idea why it fails