From 1f0223e9fd77d9e3d586f0e2420fc1b7a2949a85 Mon Sep 17 00:00:00 2001 From: James Ye Date: Fri, 20 Jan 2017 16:54:13 +1100 Subject: Add a "switch" interface for parts of the SW_* range This will allow switch devices known to libinput to be exposed. Currently, this is SW_LID. libinput also handles switch events internally, e.g. a laptop touchpad will be disabled autmoatically when the lid is closed. This is transparent to the caller, although the caller will also receive the event. See https://bugs.freedesktop.org/show_bug.cgi?id=86223 This features is intended to be the main driver for the interface. Co-Authored-By: Peter Hutterer Signed-off-by: James Ye Signed-off-by: Peter Hutterer --- tools/event-debug.c | 31 +++++++++++++++++++++++++++++++ tools/event-gui.c | 2 ++ 2 files changed, 33 insertions(+) (limited to 'tools') diff --git a/tools/event-debug.c b/tools/event-debug.c index a3e460a..779b54a 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -133,6 +133,9 @@ print_event_header(struct libinput_event *ev) case LIBINPUT_EVENT_TABLET_PAD_STRIP: type = "TABLET_PAD_STRIP"; break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + type = "SWITCH_TOGGLE"; + break; } prefix = (last_device != dev) ? '-' : ' '; @@ -194,6 +197,9 @@ print_device_notify(struct libinput_event *ev) if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) printf("P"); + if (libinput_device_has_capability(dev, + LIBINPUT_DEVICE_CAP_SWITCH)) + printf("S"); if (libinput_device_get_size(dev, &w, &h) == 0) printf(" size %.0fx%.0fmm", w, h); @@ -706,6 +712,28 @@ print_tablet_pad_strip_event(struct libinput_event *ev) mode); } +static void +print_switch_event(struct libinput_event *ev) +{ + struct libinput_event_switch *sw = libinput_event_get_switch_event(ev); + enum libinput_switch_state state; + const char *which; + + print_event_time(libinput_event_switch_get_time(sw)); + + switch (libinput_event_switch_get_switch(sw)) { + case LIBINPUT_SWITCH_LID: + which = "lid"; + break; + default: + abort(); + } + + state = libinput_event_switch_get_switch_state(sw); + + printf("switch %s state %d\n", which, state); +} + static int handle_and_print_events(struct libinput *li) { @@ -794,6 +822,9 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_TABLET_PAD_STRIP: print_tablet_pad_strip_event(ev); break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + print_switch_event(ev); + break; } libinput_event_destroy(ev); diff --git a/tools/event-gui.c b/tools/event-gui.c index e819901..155cc95 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -845,6 +845,8 @@ handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) case LIBINPUT_EVENT_TABLET_PAD_RING: case LIBINPUT_EVENT_TABLET_PAD_STRIP: break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + break; } libinput_event_destroy(ev); -- cgit v1.2.3