From 93125826c92a22f06c989ab0641e402f743afeaa Mon Sep 17 00:00:00 2001 From: Rentib Date: Thu, 19 Sep 2024 17:28:28 +0200 Subject: [PATCH] union Arg and spawn function --- config.def.h | 11 +++++++---- dam.c | 55 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/config.def.h b/config.def.h index 01575f7..b1ed9dc 100644 --- a/config.def.h +++ b/config.def.h @@ -11,12 +11,15 @@ static uint32_t colors[][3] = { /* tagging */ static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *termcmd[] = { "foot", NULL }; + /* button definitions */ /* click can be ClkTagBar, ClkLayout, ClkMode, ClkTitle, ClkStatus */ static const Button buttons[] = { /* click button function argument */ - { ClkTagBar, BTN_LEFT, view, 0 }, - { ClkTagBar, BTN_RIGHT, toggleview, 0 }, - { ClkTagBar, BTN_MIDDLE, toggletag, 0 }, - { ClkTitle, BTN_LEFT, zoom, 0 }, + { ClkTagBar, BTN_LEFT, view, {0} }, + { ClkTagBar, BTN_RIGHT, toggleview, {0} }, + { ClkTagBar, BTN_MIDDLE, toggletag, {0} }, + { ClkTitle, BTN_LEFT, zoom, {0} }, + { ClkStatus, BTN_MIDDLE, spawn , {.v = termcmd } }, }; diff --git a/dam.c b/dam.c index 1b9208e..ddb2ad9 100644 --- a/dam.c +++ b/dam.c @@ -45,17 +45,25 @@ typedef struct { struct wl_list link; } Bar; +typedef union { + int i; + unsigned int ui; + float f; + const void *v; +} Arg; + typedef struct { unsigned int click; unsigned int button; - void (*func)(uint32_t); - uint32_t arg; + void (*func)(const Arg *arg); + const Arg arg; } Button; -static void view(uint32_t arg); -static void toggleview(uint32_t arg); -static void toggletag(uint32_t arg); -static void zoom(uint32_t arg); +static void view(const Arg *arg); +static void toggleview(const Arg *arg); +static void toggletag(const Arg *arg); +static void zoom(const Arg *arg); +static void spawn(const Arg *arg); #include "config.h" @@ -126,42 +134,52 @@ parse_color(uint32_t *dest, const char *src) } void -view(uint32_t arg) +view(const Arg *arg) { char tagbuf[4]; zriver_control_v1_add_argument(control, "set-focused-tags"); - snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg); + snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui); zriver_control_v1_add_argument(control, tagbuf); zriver_control_v1_run_command(control, seat); } void -toggleview(uint32_t arg) +toggleview(const Arg *arg) { char tagbuf[4]; zriver_control_v1_add_argument(control, "toggle-focused-tags"); - snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg); + snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui); zriver_control_v1_add_argument(control, tagbuf); zriver_control_v1_run_command(control, seat); } void -toggletag(uint32_t arg) +toggletag(const Arg *arg) { char tagbuf[4]; zriver_control_v1_add_argument(control, "set-view-tags"); - snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg); + snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui); zriver_control_v1_add_argument(control, tagbuf); zriver_control_v1_run_command(control, seat); } static void -zoom(uint32_t arg) +zoom(const Arg *arg) { zriver_control_v1_add_argument(control, "zoom"); zriver_control_v1_run_command(control, seat); } +static void +spawn(const Arg *arg) +{ + char *const *i; + zriver_control_v1_add_argument(control, "spawn"); + for (i = (char *const *)arg->v; *i != NULL; i++) + zriver_control_v1_add_argument(control, *i); + zriver_control_v1_run_command(control, seat); +} + static void bar_deinit_surface(Bar *bar) { @@ -482,7 +500,8 @@ static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { int lw, mw = 0; - unsigned int i = 0, /* j = 0, */ x = 0, arg; + Arg arg = {0}; + unsigned int i = 0, /* j = 0, */ x = 0; unsigned int click; if (!pointer.button || !selbar) @@ -496,7 +515,7 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) if (i < LENGTH(tags)) { click = ClkTagBar; - arg = i; + arg.ui = 1 << i; } else if (pointer.x > x + lw && pointer.x < x + lw + mw) click = ClkMode; else if (pointer.x < x + lw) @@ -509,9 +528,9 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) for (i = 0; i < LENGTH(buttons); i++) { if (buttons[i].click == click && buttons[i].func && buttons[i].button == pointer.button) - buttons[i].func(click == ClkTagBar && !buttons[i].arg - ? arg - : buttons[i].arg); + buttons[i].func(click == ClkTagBar && !buttons[i].arg.i + ? &arg + : &buttons[i].arg); } }