Waybar icon indicating copy to clipboard operation
Waybar copied to clipboard

Improve keyboard response time and enable hotplug support

Open asas1asas200 opened this issue 1 year ago • 3 comments

The keyboard-state module used the polling mechanism to get the keyboard status by the interval. But we more like to see the indicator update immediately, just like the pulseaudio module.

So, I use libinput keyboard event to listen to the specific key events update when it has been triggered. And the thread_ now is an event loop, so the interval value has no effect.

This patch is still in progress, such as the wiki page and the man page aren't finished yet.

I will also add the keyboard removal function in this patch because libinput can get the remove event. But a prerequisite for this is all the devices that needed be listened should be connected before launching waybar, or you need to restart waybar, see related issue #1584 .

I need some opinions about this change.

asas1asas200 avatar Aug 22 '22 13:08 asas1asas200

Have you considered using Gio classes instead of the raw OS facilities? E.g. Gio::FileMonitor or Glib event loop?

alebastr avatar Aug 23 '22 18:08 alebastr

Have you considered using Gio classes instead of the raw OS facilities? E.g. Gio::FileMonitor or Glib event loop?

I have tried the sample code below listening to the /dev/input: https://gist.github.com/simu/0ed1e9b12871e20cec48efe73eeeb8e1 The result is as follows:

monitoring /dev/input
/dev/input/event3 contents changed
/dev/input/event7 contents changed
/dev/input/event14 contents changed
/dev/input/event13 contents changed
/dev/input/event1 contents changed
/dev/input/event2 contents changed
/dev/input/event4 contents changed
/dev/input/event3 contents changed
/dev/input/event7 set of changes done

/dev/input/event14 set of changes done

/dev/input/event13 set of changes done

/dev/input/event1 set of changes done

/dev/input/event2 set of changes done

/dev/input/event4 set of changes done

/dev/input/event3 set of changes done

/dev/input/event3 contents changed
/dev/input/event7 contents changed
/dev/input/event14 contents changed
/dev/input/event13 contents changed
/dev/input/event1 contents changed
/dev/input/event2 contents changed
/dev/input/event4 contents changed
/dev/input/event3 contents changed
/dev/input/event7 contents changed
/dev/input/event14 contents changed
/dev/input/event13 contents changed
/dev/input/event1 contents changed
/dev/input/event2 contents changed
/dev/input/event4 contents changed
/dev/input/event3 contents changed
/dev/input/event7 contents changed
/dev/input/event14 contents changed
/dev/input/event13 contents changed

Even if I don't add or delete any device, it will get the unneeded events because the G_FILE_MONITOR_WATCH_MOVE attribute will lead to recording various events.

asas1asas200 avatar Aug 23 '22 19:08 asas1asas200

The current version has hotplug support and event-based keyboard lock status detection, problems in the first comment have been resolved. It can auto-detect new devices and won't crash when keyboards have been removed.

asas1asas200 avatar Aug 24 '22 11:08 asas1asas200

Thx! Can you also add the deprecated interval info into the github wiki?

Alexays avatar Oct 20 '22 08:10 Alexays