configurable buttons like in dwm

This commit is contained in:
Rentib 2024-09-19 16:58:48 +02:00
parent 3454f67c49
commit edaecf4a18
2 changed files with 63 additions and 28 deletions

View file

@ -10,3 +10,13 @@ static uint32_t colors[][3] = {
/* tagging */
static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
/* 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 },
};

81
dam.c
View file

@ -52,6 +52,11 @@ typedef struct {
uint32_t 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);
#include "config.h"
static struct wl_display *display;
@ -120,6 +125,43 @@ parse_color(uint32_t *dest, const char *src)
*dest = (*dest << 8) | 0xFF;
}
void
view(uint32_t arg)
{
char tagbuf[4];
zriver_control_v1_add_argument(control, "set-focused-tags");
snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg);
zriver_control_v1_add_argument(control, tagbuf);
zriver_control_v1_run_command(control, seat);
}
void
toggleview(uint32_t arg)
{
char tagbuf[4];
zriver_control_v1_add_argument(control, "toggle-focused-tags");
snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg);
zriver_control_v1_add_argument(control, tagbuf);
zriver_control_v1_run_command(control, seat);
}
void
toggletag(uint32_t arg)
{
char tagbuf[4];
zriver_control_v1_add_argument(control, "set-view-tags");
snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << arg);
zriver_control_v1_add_argument(control, tagbuf);
zriver_control_v1_run_command(control, seat);
}
static void
zoom(uint32_t arg)
{
zriver_control_v1_add_argument(control, "zoom");
zriver_control_v1_run_command(control, seat);
}
static void
bar_deinit_surface(Bar *bar)
{
@ -440,9 +482,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;
unsigned int i = 0, /* j = 0, */ x = 0, arg;
unsigned int click;
char tagbuf[4];
if (!pointer.button || !selbar)
return;
@ -453,9 +494,10 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
x += TEXTW(selbar, tags[i]);
while (pointer.x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags))
if (i < LENGTH(tags)) {
click = ClkTagBar;
else if (pointer.x > x + lw && pointer.x < x + lw + mw)
arg = i;
} else if (pointer.x > x + lw && pointer.x < x + lw + mw)
click = ClkMode;
else if (pointer.x < x + lw)
click = ClkLayout;
@ -464,30 +506,13 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
else
click = ClkTitle;
switch (click) {
case ClkTagBar:
zriver_control_v1_add_argument(control,
pointer.button == BTN_LEFT ? "set-focused-tags" :
pointer.button == BTN_MIDDLE ? "toggle-focused-tags" :
"set-view-tags");
snprintf(tagbuf, sizeof(tagbuf), "%d", 1 << i);
zriver_control_v1_add_argument(control, tagbuf);
zriver_control_v1_run_command(control, seat);
break;
case ClkLayout:
/* TODO: cannot disable rivertile; change layout to 'floating' */
break;
case ClkMode:
/* TODO: river has no method of getting a list of modes */
break;
case ClkTitle:
zriver_control_v1_add_argument(control, "zoom");
zriver_control_v1_run_command(control, seat);
break;
case ClkStatus:
/* dwm spawns termcmd */
break;
}
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);
}
}
static void