diff --git a/src/evdev-lid.c b/src/evdev-lid.c index e410ecad..b12ca0af 100644 --- a/src/evdev-lid.c +++ b/src/evdev-lid.c @@ -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); diff --git a/test/test-lid.c b/test/test-lid.c index 338c5447..d12f9b93 100644 --- a/test/test-lid.c +++ b/test/test-lid.c @@ -426,26 +426,27 @@ START_TEST(lid_open_on_key) keyboard = litest_add_device(li, LITEST_KEYBOARD); - litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); - litest_drain_events(li); + for (int i = 0; i < 3; i++) { + litest_lid_action(sw, LIBINPUT_SWITCH_STATE_ON); + litest_drain_events(li); - litest_event(keyboard, EV_KEY, KEY_A, 1); - litest_event(keyboard, EV_SYN, SYN_REPORT, 0); - litest_event(keyboard, EV_KEY, KEY_A, 0); - litest_event(keyboard, EV_SYN, SYN_REPORT, 0); - libinput_dispatch(li); + litest_event(keyboard, EV_KEY, KEY_A, 1); + litest_event(keyboard, EV_SYN, SYN_REPORT, 0); + litest_event(keyboard, EV_KEY, KEY_A, 0); + litest_event(keyboard, EV_SYN, SYN_REPORT, 0); + libinput_dispatch(li); - event = libinput_get_event(li); - litest_is_switch_event(event, - LIBINPUT_SWITCH_LID, - LIBINPUT_SWITCH_STATE_OFF); + event = libinput_get_event(li); + 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_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_lid_action(sw, LIBINPUT_SWITCH_STATE_OFF); + litest_assert_empty_queue(li); + } litest_delete_device(keyboard); } END_TEST