diff --git a/example/pointer.c b/example/pointer.c index c2fb6ee55..9a2f33d76 100644 --- a/example/pointer.c +++ b/example/pointer.c @@ -47,15 +47,6 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_end(sample->renderer); } -static void handle_keyboard_key(struct keyboard_state *kbstate, - xkb_keysym_t sym, enum wlr_key_state key_state) { - if (sym == XKB_KEY_Escape) { - kbstate->compositor->exit = true; - } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); - } -} - static void handle_pointer_motion(struct pointer_state *pstate, double d_x, double d_y) { struct sample_state *state = pstate->compositor->data; @@ -117,7 +108,6 @@ int main(int argc, char *argv[]) { compositor.data = &state; compositor.output_add_cb = handle_output_add; compositor.output_frame_cb = handle_output_frame; - compositor.keyboard_key_cb = handle_keyboard_key; compositor.pointer_motion_cb = handle_pointer_motion; compositor.pointer_button_cb = handle_pointer_button; compositor.pointer_axis_cb = handle_pointer_axis; diff --git a/example/rotation.c b/example/rotation.c index b795b438a..7eed1c2e5 100644 --- a/example/rotation.c +++ b/example/rotation.c @@ -107,9 +107,6 @@ static void handle_keyboard_key(struct keyboard_state *kbstate, // Also, key repeat if (key_state == WLR_KEY_PRESSED) { switch (sym) { - case XKB_KEY_Escape: - kbstate->compositor->exit = true; - break; case XKB_KEY_Left: update_velocities(kbstate->compositor, -16, 0); break; @@ -123,10 +120,6 @@ static void handle_keyboard_key(struct keyboard_state *kbstate, update_velocities(kbstate->compositor, 0, 16); break; } - - if (sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); - } } } diff --git a/example/shared.c b/example/shared.c index b9689f1cc..c4ec4ffed 100644 --- a/example/shared.c +++ b/example/shared.c @@ -42,6 +42,11 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { if (kbstate->compositor->keyboard_key_cb) { kbstate->compositor->keyboard_key_cb(kbstate, sym, key_state); } + if (sym == XKB_KEY_Escape) { + wl_display_terminate(kbstate->compositor->display); + } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { + wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); + } } xkb_state_update_key(kbstate->xkb_state, keycode, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); @@ -470,10 +475,7 @@ void compositor_init(struct compositor_state *state) { } void compositor_run(struct compositor_state *state) { - while (!state->exit) { - wl_event_loop_dispatch(state->event_loop, 0); - } - + wl_display_run(state->display); wlr_backend_destroy(state->backend); wlr_session_finish(state->session); wl_display_destroy(state->display); diff --git a/example/simple.c b/example/simple.c index cb3a194c9..8a01fab81 100644 --- a/example/simple.c +++ b/example/simple.c @@ -38,15 +38,6 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) { glClear(GL_COLOR_BUFFER_BIT); } -static void handle_keyboard_key(struct keyboard_state *kbstate, - xkb_keysym_t sym, enum wlr_key_state key_state) { - if (sym == XKB_KEY_Escape) { - kbstate->compositor->exit = true; - } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); - } -} - int main() { struct sample_state state = { .color = { 1.0, 0.0, 0.0 }, @@ -55,7 +46,6 @@ int main() { struct compositor_state compositor = { 0, .data = &state, .output_frame_cb = handle_output_frame, - .keyboard_key_cb = handle_keyboard_key, }; compositor_init(&compositor); compositor_run(&compositor); diff --git a/example/tablet.c b/example/tablet.c index 998efc0cc..69c530a63 100644 --- a/example/tablet.c +++ b/example/tablet.c @@ -76,15 +76,6 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_end(sample->renderer); } -static void handle_keyboard_key(struct keyboard_state *kbstate, - xkb_keysym_t sym, enum wlr_key_state key_state) { - if (sym == XKB_KEY_Escape) { - kbstate->compositor->exit = true; - } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); - } -} - static void handle_tool_axis(struct tablet_tool_state *tstate, struct wlr_event_tablet_tool_axis *event) { struct sample_state *sample = tstate->compositor->data; @@ -152,7 +143,6 @@ int main(int argc, char *argv[]) { struct compositor_state compositor = { 0, .data = &state, .output_frame_cb = handle_output_frame, - .keyboard_key_cb = handle_keyboard_key, .tool_axis_cb = handle_tool_axis, .tool_proximity_cb = handle_tool_proximity, .tool_button_cb = handle_tool_button, diff --git a/example/touch.c b/example/touch.c index d2280385d..4b4782f1d 100644 --- a/example/touch.c +++ b/example/touch.c @@ -54,15 +54,6 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_renderer_end(sample->renderer); } -static void handle_keyboard_key(struct keyboard_state *kbstate, - xkb_keysym_t sym, enum wlr_key_state key_state) { - if (sym == XKB_KEY_Escape) { - kbstate->compositor->exit = true; - } else if (key_state == WLR_KEY_PRESSED && sym >= XKB_KEY_F1 && sym <= XKB_KEY_F12) { - wlr_session_change_vt(kbstate->compositor->session, sym - XKB_KEY_F1 + 1); - } -} - static void handle_touch_down(struct touch_state *tstate, int32_t slot, double x, double y, double width, double height) { struct sample_state *sample = tstate->compositor->data; @@ -104,7 +95,6 @@ int main(int argc, char *argv[]) { struct compositor_state compositor = { 0, .data = &state, .output_frame_cb = handle_output_frame, - .keyboard_key_cb = handle_keyboard_key, .touch_down_cb = handle_touch_down, .touch_up_cb = handle_touch_up, .touch_motion_cb = handle_touch_motion,