diff options
author | Benjamin Tissoires <benjamin.tissoires@gmail.com> | 2017-05-19 12:55:54 +0200 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-05-23 15:10:10 +1000 |
commit | 28fcd2c6d41e972f606c60f56c6f0a94d73455ae (patch) | |
tree | 4536835f51a06d9613b2e51af54e8214de12eb68 /src | |
parent | 1671c7f4adcf0873c55b21dc3e0578e91c360837 (diff) |
lid: track the notifier initial state internally, but not externally
What we do not want is libinput to believe the LID is closed while
it's not. But the internal notifier state need to be in sync with the evdev
node, or it's going to be a pain setting the keyboard listener.
But since we don't know if the state is reliable, we track the internal state
separately from the external state so that we can set up the keyboard listener
when the lid is closed, without having libinput actually send lid closed
events for unreliable devices.
https://bugs.freedesktop.org/show_bug.cgi?id=101099
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/evdev-lid.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/src/evdev-lid.c b/src/evdev-lid.c index 8090780..010cb42 100644 --- a/src/evdev-lid.c +++ b/src/evdev-lid.c @@ -34,6 +34,7 @@ struct lid_switch_dispatch { enum switch_reliability reliability; bool lid_is_closed; + bool lid_is_closed_client_state; struct { struct evdev_device *keyboard; @@ -50,6 +51,20 @@ lid_dispatch(struct evdev_dispatch *dispatch) } static void +lid_switch_notify_toggle(struct lid_switch_dispatch *dispatch, + struct evdev_device *device, + uint64_t time) +{ + if (dispatch->lid_is_closed ^ dispatch->lid_is_closed_client_state) { + switch_notify_toggle(&device->base, + time, + LIBINPUT_SWITCH_LID, + dispatch->lid_is_closed); + dispatch->lid_is_closed_client_state = dispatch->lid_is_closed; + } +} + +static void lid_switch_keyboard_event(uint64_t time, struct libinput_event *event, void *data) @@ -79,10 +94,7 @@ lid_switch_keyboard_event(uint64_t time, * the key event. */ dispatch->lid_is_closed = false; - switch_notify_toggle(&dispatch->device->base, - time, - LIBINPUT_SWITCH_LID, - dispatch->lid_is_closed); + lid_switch_notify_toggle(dispatch, dispatch->device, time); } static void @@ -120,16 +132,12 @@ lid_switch_process_switch(struct lid_switch_dispatch *dispatch, if (dispatch->lid_is_closed == is_closed) return; - lid_switch_toggle_keyboard_listener(dispatch, is_closed); dispatch->lid_is_closed = is_closed; - switch_notify_toggle(&device->base, - time, - LIBINPUT_SWITCH_LID, - dispatch->lid_is_closed); + lid_switch_notify_toggle(dispatch, device, time); break; } } @@ -249,10 +257,12 @@ lid_switch_sync_initial_state(struct evdev_device *device, { struct lid_switch_dispatch *dispatch = lid_dispatch(device->dispatch); struct libevdev *evdev = device->evdev; - bool is_closed = false; dispatch->reliability = evdev_read_switch_reliability_prop(device); + dispatch->lid_is_closed = libevdev_get_event_value(evdev, EV_SW, SW_LID); + dispatch->lid_is_closed_client_state = false; + /* For the initial state sync, we depend on whether the lid switch * is reliable. If we know it's reliable, we sync as expected. * If we're not sure, we ignore the initial state and only sync on @@ -260,24 +270,11 @@ lid_switch_sync_initial_state(struct evdev_device *device, * that always have the switch in 'on' state thus don't mess up our * touchpad. */ - switch(dispatch->reliability) { - case RELIABILITY_UNKNOWN: - case RELIABILITY_WRITE_OPEN: - is_closed = false; - break; - case RELIABILITY_RELIABLE: - is_closed = libevdev_get_event_value(evdev, EV_SW, SW_LID); - break; - } - - dispatch->lid_is_closed = is_closed; - if (dispatch->lid_is_closed) { + if (dispatch->lid_is_closed && + dispatch->reliability == RELIABILITY_RELIABLE) { uint64_t time; time = libinput_now(evdev_libinput_context(device)); - switch_notify_toggle(&device->base, - time, - LIBINPUT_SWITCH_LID, - LIBINPUT_SWITCH_STATE_ON); + lid_switch_notify_toggle(dispatch, device, time); } } |