From 9f2ddc48efd6bb48546576dca7e9b5f20cc7d174 Mon Sep 17 00:00:00 2001 From: Keith Bowes Date: Wed, 19 Feb 2020 22:48:30 -0500 Subject: [PATCH] Some more keyboard support: no keyboard capability with no keyboards, ctrl+esc and alt+tab for more Openbox-esque behavior --- include/waybox/xdg_shell.h | 1 + waybox/main.c | 4 ++-- waybox/seat.c | 36 ++++++++++++++++++------------------ waybox/xdg_shell.c | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/include/waybox/xdg_shell.h b/include/waybox/xdg_shell.h index a53c413..b6660b0 100644 --- a/include/waybox/xdg_shell.h +++ b/include/waybox/xdg_shell.h @@ -1,3 +1,4 @@ #include "waybox/server.h" void init_xdg_shell(struct wb_server *server); +void focus_view(struct wb_view *view, struct wlr_surface *surface); diff --git a/waybox/main.c b/waybox/main.c index cb47e1f..3df99de 100644 --- a/waybox/main.c +++ b/waybox/main.c @@ -6,13 +6,13 @@ #include "waybox/server.h" -struct wl_display* display = NULL; +//struct wl_display* display = NULL; int main(int argc, char **argv){ struct wb_server server = {0}; // Global display - display = server.wl_display; + //display = server.wl_display; if (init_wb(&server) == false) { printf("Failed to create backend\n"); diff --git a/waybox/seat.c b/waybox/seat.c index 91e0e26..58a96a0 100644 --- a/waybox/seat.c +++ b/waybox/seat.c @@ -1,9 +1,8 @@ -#include - #include "waybox/seat.h" +#include "waybox/xdg_shell.h" /* Stolen from wltiny. Customizations will come later. */ -static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym) { +static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32_t modifiers) { /* * Here we handle compositor keybindings. This is when the compositor is * processing keys, rather than passing them on to the client for its own @@ -11,29 +10,25 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym) { * * This function assumes Alt is held down. */ - switch (sym) { - case XKB_KEY_Escape: + + if (modifiers & WLR_MODIFIER_CTRL && sym == XKB_KEY_Escape) { wl_display_terminate(server->wl_display); - break; - case XKB_KEY_F1: -#if 0 + } + else if (modifiers & WLR_MODIFIER_ALT && sym == XKB_KEY_Tab) { /* Cycle to the next view */ if (wl_list_length(&server->views) < 2) { - break; + return false; } - struct tinywl_view *current_view = wl_container_of( + struct wb_view *current_view = wl_container_of( server->views.next, current_view, link); - struct tinywl_view *next_view = wl_container_of( + struct wb_view *next_view = wl_container_of( current_view->link.next, next_view, link); focus_view(next_view, next_view->xdg_surface->surface); /* Move the previous view to the end of the list */ wl_list_remove(¤t_view->link); wl_list_insert(server->views.prev, ¤t_view->link); -#endif - break; - default: - return false; } + else return false; return true; } @@ -73,11 +68,11 @@ static void keyboard_handle_key( bool handled = false; uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard); - if ((modifiers & WLR_MODIFIER_ALT) && event->state == WLR_KEY_PRESSED) { + if (event->state == WLR_KEY_PRESSED) { /* If alt is held down and this button was _pressed_, we attempt to * process it as a compositor keybinding. */ for (int i = 0; i < nsyms; i++) { - handled = handle_keybinding(server, syms[i]); + handled = handle_keybinding(server, syms[i], modifiers); } } @@ -133,6 +128,12 @@ static void new_input_notify(struct wl_listener *listener, void *data) { default: break; } + + uint32_t caps = WL_SEAT_CAPABILITY_POINTER; + if (!wl_list_empty(&server->seat->keyboards)) { + caps |= WL_SEAT_CAPABILITY_KEYBOARD; + } + wlr_seat_set_capabilities(server->seat->seat, caps); } struct wb_seat * wb_seat_create(struct wb_server * server) { @@ -142,7 +143,6 @@ struct wb_seat * wb_seat_create(struct wb_server * server) { server->new_input.notify = new_input_notify; wl_signal_add(&server->backend->events.new_input, &server->new_input); seat->seat = wlr_seat_create(server->wl_display, "seat0"); - wlr_seat_set_capabilities(seat->seat, WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD); return seat; } diff --git a/waybox/xdg_shell.c b/waybox/xdg_shell.c index c9a89fb..026a22a 100644 --- a/waybox/xdg_shell.c +++ b/waybox/xdg_shell.c @@ -1,6 +1,6 @@ #include "waybox/xdg_shell.h" -static void focus_view(struct wb_view *view, struct wlr_surface *surface) { +void focus_view(struct wb_view *view, struct wlr_surface *surface) { /* Note: this function only deals with keyboard focus. */ if (view == NULL) { return;