The keyboard-state module crashes with SIGSEGV in libinput_device_ref
when a new input device appears in /dev/input/.
Three bugs fixed:
1. Missing NULL check: tryAddDevice() calls libinput_path_add_device()
which returns NULL on failure, then immediately passes the result to
libinput_device_ref() without checking. On laptops, virtual input
devices (power buttons, lid switch, etc.) appear and disappear in
/dev/input/ triggering the hotplug handler; if libinput can't open
one of these, the NULL return causes the segfault.
2. Missing cleanup on device removal: The IN_DELETE handler erased
devices from the map without calling libinput_path_remove_device(),
leaving dangling pointers in the libinput context.
3. Thread safety: libinput_devices_ was accessed from 3 threads
(main/GTK, libinput_thread_, hotplug_thread_) without any mutex.
Fixes#4851
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Use libinput event for keyboard state updates.
The state will update when CAPS_LOCK, NUM_LOCK or SCROLL_LOCK has been
released,
`interval` will have no effect after this change.