Skip to content

Commit 721bb44

Browse files
committed
Reset input smoothing on device hotplug
Previously, smoothing state persisted across device hotplug events, causing coordinate jumps when devices were reconnected. Changes: - Track device list changes (additions or removals) - Reset smooth_initialized flag when device list changes - Prevents coordinate jumps from stale smoothing state
1 parent 134607d commit 721bb44

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

backend/linux_input.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static void twin_linux_input_events(struct input_event *ev,
109109
twin_linux_input_t *tm)
110110
{
111111
/* TODO: twin_screen_dispatch() should be protect by mutex_lock, but the
112-
* counterpart piece of code with mutex is not yet sure */
112+
* counterpart piece of code with mutex is not yet sure.
113+
*/
113114

114115
twin_event_t tev;
115116

@@ -350,15 +351,29 @@ static void twin_linux_edev_open(struct pollfd *pfds, twin_linux_input_t *tm)
350351
}
351352

352353
/* Close disconnected devices */
354+
bool device_list_changed = false;
353355
for (size_t i = 0; i < tm->evdev_cnt; i++) {
354-
if (tm->evdevs[i].fd > 0)
356+
if (tm->evdevs[i].fd > 0) {
355357
close(tm->evdevs[i].fd);
358+
device_list_changed = true;
359+
}
356360
}
357361

362+
/* Check if new devices were added */
363+
if (new_evdev_cnt != tm->evdev_cnt)
364+
device_list_changed = true;
365+
358366
/* Overwrite the evdev list */
359367
memcpy(tm->evdevs, evdevs, sizeof(tm->evdevs));
360368
tm->evdev_cnt = new_evdev_cnt;
361369

370+
#if TWIN_INPUT_SMOOTH_WEIGHT > 0
371+
/* Reset smoothing state on device reconnection to prevent coordinate jumps
372+
*/
373+
if (device_list_changed && tm->smooth_initialized)
374+
tm->smooth_initialized = false;
375+
#endif
376+
362377
/* Initialize evdev poll file descriptors */
363378
for (size_t i = tm->udev_cnt; i < tm->evdev_cnt + tm->udev_cnt; i++) {
364379
pfds[i].fd = tm->evdevs[i - 1].fd;

0 commit comments

Comments
 (0)