spkp

Stacking wayland compositor
git clone git://git.z3bra.org/sp:kp.git
Log | Files | Refs

commit d9297195a41fb19b58a494f2a74b2fa0247ee43c
parent 309db35851509a986a45ced6182bb73f2ff18af5
Author: Willy Goiffon <dev@z3bra.org>
Date:   Tue, 10 Nov 2020 10:50:15 +0100

Move keybindings configuration to config.h

Diffstat:
Mcompositor.c | 56++++++++++++++++++++++++++++++++++++++++++++++----------
Mconfig.def.h | 4++++
2 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -26,7 +26,6 @@ #include "xdg-shell-protocol.h" #include "arg.h" -#include "config.h" enum { NORMAL, @@ -106,6 +105,21 @@ struct keyboard { struct wl_list link; }; +/* Optional argument to pass down to a keybinding function */ +union keyarg { + int i; + float f; + const void *v; +}; + +/* Keybindig to function association, see config.h */ +struct key { + uint32_t mod; + uint32_t key; + void (*func)(struct state *, union keyarg *); + union keyarg arg; +}; + /* Rendering data, used to render window's surfaces */ struct rdata { struct wlr_output *output; @@ -147,6 +161,11 @@ static int keybinding(struct state *, uint32_t, uint32_t); static struct window *underneath(struct state *, double, double); static struct wlr_surface *topsurface(struct window *, double, double, double *, double *); +/* keybinding functions, see config.h */ +static void kb_terminate(struct state *, union keyarg *); + +#include "config.h" + void usage(char *pgm) { @@ -759,13 +778,14 @@ focus(struct window *window, struct wlr_surface *surface) int keybinding(struct state *server, uint32_t mod, uint32_t key) { - switch (key) { - case XKB_KEY_Escape: - if (mod & WLR_MODIFIER_LOGO) { - wl_display_terminate(server->dpy); - return 1; /* NOTREACHED */ - } - break; + ssize_t i, nkey; + + nkey = sizeof(keys)/sizeof(*keys); + + for (i=0; i<nkey; i++) { + if (keys[i].mod == mod \ + && keys[i].key == key) + keys[i].func(server, NULL); } return 0; @@ -802,17 +822,33 @@ underneath(struct state *server, double x, double y) return NULL; } +/* + * Return the topmost wlr_surface at the given position. + * The x, y coordinates relative to that surface are also returned if + * a pointer to sx, sy is given. + * This function is mostly used to relay pointer events to and underlying + * surface. + */ struct wlr_surface * -topsurface(struct window *window, double x, double y, double *rx, double *ry) +topsurface(struct window *window, double x, double y, double *sx, double *sy) { struct wlr_surface *surface; surface = wlr_xdg_surface_surface_at(window->surface, - x - window->x, y - window->y, rx, ry); + x - window->x, y - window->y, sx, sy); return surface; } +/* + * Keybind: Terminate the wayland compositor + */ +void kb_terminate(struct state *server, union keyarg *arg) +{ + (void)arg; + wl_display_terminate(server->dpy); +} + int main(int argc, char *argv[]) { diff --git a/config.def.h b/config.def.h @@ -1 +1,5 @@ float background[4] = { 1.0, 0.6, 0.6, 0.3 }; + +struct key keys[] = { + { WLR_MODIFIER_LOGO, XKB_KEY_Escape, kb_terminate, {0} }, +};