mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-31 12:20:09 +01:00
tools: keep a list of devices around for run-time changes
Hard-coded to 50 devices, because for a debugging tool that's plenty. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
1dfb248ab9
commit
3b0c97c78b
1 changed files with 36 additions and 0 deletions
|
|
@ -67,6 +67,8 @@ struct window {
|
|||
|
||||
/* l/m/r mouse buttons */
|
||||
int l, m, r;
|
||||
|
||||
struct libinput_device *devices[50];
|
||||
};
|
||||
|
||||
static int
|
||||
|
|
@ -211,11 +213,24 @@ window_init(struct window *w)
|
|||
gtk_widget_show_all(w->win);
|
||||
}
|
||||
|
||||
static void
|
||||
window_cleanup(struct window *w)
|
||||
{
|
||||
struct libinput_device **dev;
|
||||
ARRAY_FOR_EACH(w->devices, dev) {
|
||||
if (*dev)
|
||||
libinput_device_unref(*dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
handle_event_device_notify(struct libinput_event *ev)
|
||||
{
|
||||
struct libinput_device *dev = libinput_event_get_device(ev);
|
||||
struct libinput *li;
|
||||
struct window *w;
|
||||
const char *type;
|
||||
int i;
|
||||
|
||||
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED)
|
||||
type = "added";
|
||||
|
|
@ -232,6 +247,26 @@ handle_event_device_notify(struct libinput_event *ev)
|
|||
error("%s: Failed to enable tapping\n",
|
||||
libinput_device_get_sysname(dev));
|
||||
}
|
||||
|
||||
li = libinput_event_get_context(ev);
|
||||
w = libinput_get_user_data(li);
|
||||
|
||||
if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) {
|
||||
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
|
||||
if (w->devices[i] == NULL) {
|
||||
w->devices[i] = libinput_device_ref(dev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < ARRAY_LENGTH(w->devices); i++) {
|
||||
if (w->devices[i] == dev) {
|
||||
libinput_device_unref(w->devices[i]);
|
||||
w->devices[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -474,6 +509,7 @@ main(int argc, char *argv[])
|
|||
|
||||
gtk_main();
|
||||
|
||||
window_cleanup(&w);
|
||||
libinput_unref(li);
|
||||
udev_unref(udev);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue