From d35d122eb1f2ff2f4e69ccfc9b82630bb3a0616a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 22 May 2017 16:00:20 +1000 Subject: lid: force the lid to open when the keyboard device is removed On unreliable tablets (Surface3), always force the lid switch to open when the paired keyboard is removed. This way the lid can't be stuck in a closed state when there's nothing attached that can actually trigger that state. https://bugs.freedesktop.org/show_bug.cgi?id=101100 Signed-off-by: Peter Hutterer --- src/evdev-lid.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/evdev-lid.c b/src/evdev-lid.c index fe98e6e..1edb12b 100644 --- a/src/evdev-lid.c +++ b/src/evdev-lid.c @@ -64,6 +64,23 @@ lid_switch_notify_toggle(struct lid_switch_dispatch *dispatch, } } +static void +lid_switch_update_kernel_state(struct lid_switch_dispatch *dispatch, + uint64_t time) +{ + int fd; + const struct input_event ev[2] = { + {{ 0, 0 }, EV_SW, SW_LID, 0 }, + {{ 0, 0 }, EV_SYN, SYN_REPORT, 0 }, + }; + + if (dispatch->reliability != RELIABILITY_WRITE_OPEN) + return; + + fd = libevdev_get_fd(dispatch->device->evdev); + (void)write(fd, ev, sizeof(ev)); +} + static void lid_switch_keyboard_event(uint64_t time, struct libinput_event *event, @@ -77,17 +94,7 @@ lid_switch_keyboard_event(uint64_t time, if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY) return; - if (dispatch->reliability == RELIABILITY_WRITE_OPEN) { - int fd = libevdev_get_fd(dispatch->device->evdev); - struct input_event ev[2] = { - {{ 0, 0 }, EV_SW, SW_LID, 0 }, - {{ 0, 0 }, EV_SYN, SYN_REPORT, 0 }, - }; - - (void)write(fd, ev, sizeof(ev)); - /* In case write() fails, we sync the lid state manually - * regardless. */ - } + lid_switch_update_kernel_state(dispatch, time); /* Posting the event here means we preempt the keyboard events that * caused us to wake up, so the lid event is always passed on before @@ -246,11 +253,16 @@ lid_switch_interface_device_removed(struct evdev_device *device, struct lid_switch_dispatch *dispatch = lid_dispatch(device->dispatch); if (removed_device == dispatch->keyboard.keyboard) { + uint64_t time; + libinput_device_remove_event_listener( &dispatch->keyboard.listener); libinput_device_init_event_listener( &dispatch->keyboard.listener); dispatch->keyboard.keyboard = NULL; + + time = libinput_now(evdev_libinput_context(device)); + lid_switch_update_kernel_state(dispatch, time); } } -- cgit v1.2.3