feat(keybaord): enable hotplug support

Use inotify listening devices path changes to implement hotplug support.
The new hotplug thread is also an event loop, so the interval value has
no effect.
The evdev is now open on demand.

Fix libinput_interface object life-time.
This commit is contained in:
asas1asas200
2022-08-23 23:18:40 +08:00
parent 061f4550f4
commit dcd75b3b40
2 changed files with 108 additions and 77 deletions

View File

@ -23,7 +23,7 @@ class KeyboardState : public AModule {
auto update() -> void;
private:
auto findKeyboards() -> void;
auto tryAddDevice(const std::string&) -> void;
Gtk::Box box_;
Gtk::Label numlock_label_;
@ -36,13 +36,12 @@ class KeyboardState : public AModule {
const std::chrono::seconds interval_;
std::string icon_locked_;
std::string icon_unlocked_;
std::string devices_path_;
int fd_;
libevdev* dev_;
struct libinput* libinput_;
std::unordered_map<std::string, struct libinput_device*> libinput_devices_;
util::SleeperThread thread_;
util::SleeperThread libinput_thread_, hotplug_thread_;
};
} // namespace waybar::modules