fallback: fix lid switch event listener being initialized twice

Once the lid is closed, the keyboard event listener is set up to open the lid
for us on keyboard events. With the right sequence, we can trigger the
listener to be added to the list multiple times, triggering an assert in the
list test code (or an infinite loop in the 1.8 branch).

Conditions:
* SW_LID value 1 - sets up the keyboard listener
* keyboard event - sets lid_is_closed to false
* SW_LID value 0 - is ignored because we're already open
* SW_LID value 1 - sets up the keyboard listener again

https://bugs.freedesktop.org/show_bug.cgi?id=103298

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 41a70bbe92)
This commit is contained in:
Peter Hutterer 2017-10-27 15:03:52 +10:00
parent 368e6fa8d3
commit 9f1e8a032c
2 changed files with 23 additions and 22 deletions

View file

@ -105,6 +105,8 @@ lid_switch_toggle_keyboard_listener(struct lid_switch_dispatch *dispatch,
if (!dispatch->keyboard.keyboard)
return;
libinput_device_remove_event_listener(&dispatch->keyboard.listener);
if (is_closed) {
libinput_device_add_event_listener(
&dispatch->keyboard.keyboard->base,
@ -112,10 +114,7 @@ lid_switch_toggle_keyboard_listener(struct lid_switch_dispatch *dispatch,
lid_switch_keyboard_event,
dispatch);
} else {
libinput_device_remove_event_listener(
&dispatch->keyboard.listener);
libinput_device_init_event_listener(
&dispatch->keyboard.listener);
libinput_device_init_event_listener(&dispatch->keyboard.listener);
}
}
@ -131,11 +130,12 @@ lid_switch_process_switch(struct lid_switch_dispatch *dispatch,
case SW_LID:
is_closed = !!e->value;
if (dispatch->lid_is_closed == is_closed)
return;
lid_switch_toggle_keyboard_listener(dispatch,
is_closed);
if (dispatch->lid_is_closed == is_closed)
return;
dispatch->lid_is_closed = is_closed;
lid_switch_notify_toggle(dispatch, device, time);

View file

@ -426,6 +426,7 @@ START_TEST(lid_open_on_key)
keyboard = litest_add_device(li, LITEST_KEYBOARD);
for (int i = 0; i < 3; i++) {
litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON);
litest_drain_events(li);
@ -439,13 +440,13 @@ START_TEST(lid_open_on_key)
litest_is_switch_event(event,
LIBINPUT_SWITCH_LID,
LIBINPUT_SWITCH_STATE_OFF);
libinput_event_destroy(event);
litest_assert_only_typed_events(li, LIBINPUT_EVENT_KEYBOARD_KEY);
litest_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF);
litest_assert_empty_queue(li);
libinput_event_destroy(event);
}
litest_delete_device(keyboard);
}
END_TEST