use flexible command arg in buttons
This commit is contained in:
parent
a76f1dc808
commit
a8275b4713
2 changed files with 25 additions and 54 deletions
|
@ -26,9 +26,9 @@ static const char *termcmd[] = { "foot", NULL };
|
||||||
/* click can be ClkTagBar, ClkLayout, ClkMode, ClkTitle, ClkStatus */
|
/* click can be ClkTagBar, ClkLayout, ClkMode, ClkTitle, ClkStatus */
|
||||||
static const Button buttons[] = {
|
static const Button buttons[] = {
|
||||||
/* click button function argument */
|
/* click button function argument */
|
||||||
{ ClkTagBar, BTN_LEFT, view, {0} },
|
{ ClkTagBar, BTN_LEFT, cmd, {.s = "set-focused-tags"} },
|
||||||
{ ClkTagBar, BTN_RIGHT, toggleview, {0} },
|
{ ClkTagBar, BTN_RIGHT, cmd, {.s = "toggle-focused-tags"} },
|
||||||
{ ClkTagBar, BTN_MIDDLE, toggletag, {0} },
|
{ ClkTagBar, BTN_MIDDLE, cmd, {.s = "set-view-tags"} },
|
||||||
{ ClkTitle, BTN_LEFT, zoom, {0} },
|
{ ClkTitle, BTN_LEFT, cmd, {.s = "zoom"} },
|
||||||
{ ClkStatus, BTN_MIDDLE, spawn, {.v = termcmd } },
|
{ ClkStatus, BTN_MIDDLE, spawn, {.v = termcmd } },
|
||||||
};
|
};
|
||||||
|
|
67
dam.c
67
dam.c
|
@ -45,10 +45,9 @@ typedef struct {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
} Bar;
|
} Bar;
|
||||||
|
|
||||||
typedef union {
|
typedef struct {
|
||||||
int i;
|
|
||||||
unsigned int ui;
|
unsigned int ui;
|
||||||
float f;
|
char *s;
|
||||||
const void *v;
|
const void *v;
|
||||||
} Arg;
|
} Arg;
|
||||||
|
|
||||||
|
@ -59,10 +58,7 @@ typedef struct {
|
||||||
const Arg arg;
|
const Arg arg;
|
||||||
} Button;
|
} Button;
|
||||||
|
|
||||||
static void view(const Arg *arg);
|
static void cmd(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);
|
static void spawn(const Arg *arg);
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -133,40 +129,15 @@ parse_color(uint32_t *dest, const char *src)
|
||||||
*dest = (*dest << 8) | 0xFF;
|
*dest = (*dest << 8) | 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
view(const Arg *arg)
|
|
||||||
{
|
|
||||||
char tagbuf[4];
|
|
||||||
zriver_control_v1_add_argument(control, "set-focused-tags");
|
|
||||||
snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui);
|
|
||||||
zriver_control_v1_add_argument(control, tagbuf);
|
|
||||||
zriver_control_v1_run_command(control, seat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
toggleview(const Arg *arg)
|
|
||||||
{
|
|
||||||
char tagbuf[4];
|
|
||||||
zriver_control_v1_add_argument(control, "toggle-focused-tags");
|
|
||||||
snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui);
|
|
||||||
zriver_control_v1_add_argument(control, tagbuf);
|
|
||||||
zriver_control_v1_run_command(control, seat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
toggletag(const Arg *arg)
|
|
||||||
{
|
|
||||||
char tagbuf[4];
|
|
||||||
zriver_control_v1_add_argument(control, "set-view-tags");
|
|
||||||
snprintf(tagbuf, sizeof(tagbuf), "%d", arg->ui);
|
|
||||||
zriver_control_v1_add_argument(control, tagbuf);
|
|
||||||
zriver_control_v1_run_command(control, seat);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zoom(const Arg *arg)
|
cmd(const Arg *arg)
|
||||||
{
|
{
|
||||||
zriver_control_v1_add_argument(control, "zoom");
|
char argbuf[4];
|
||||||
|
zriver_control_v1_add_argument(control, arg->s);
|
||||||
|
if (arg->ui) {
|
||||||
|
snprintf(argbuf, sizeof(argbuf), "%d", arg->ui);
|
||||||
|
zriver_control_v1_add_argument(control, argbuf);
|
||||||
|
}
|
||||||
zriver_control_v1_run_command(control, seat);
|
zriver_control_v1_run_command(control, seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,8 +480,8 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
|
||||||
{
|
{
|
||||||
int lw, mw = 0;
|
int lw, mw = 0;
|
||||||
Arg arg = {0};
|
Arg arg = {0};
|
||||||
unsigned int i = 0, /* j = 0, */ x = 0;
|
unsigned int i = 0, x = 0;
|
||||||
unsigned int click;
|
unsigned int tag, click;
|
||||||
|
|
||||||
if (!pointer.button || !selbar)
|
if (!pointer.button || !selbar)
|
||||||
return;
|
return;
|
||||||
|
@ -523,7 +494,7 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
|
||||||
|
|
||||||
if (i < LENGTH(tags)) {
|
if (i < LENGTH(tags)) {
|
||||||
click = ClkTagBar;
|
click = ClkTagBar;
|
||||||
arg.ui = 1 << i;
|
tag = 1 << i;
|
||||||
} else if (pointer.x > x + lw && pointer.x < x + lw + mw)
|
} else if (pointer.x > x + lw && pointer.x < x + lw + mw)
|
||||||
click = ClkMode;
|
click = ClkMode;
|
||||||
else if (pointer.x < x + lw)
|
else if (pointer.x < x + lw)
|
||||||
|
@ -533,12 +504,12 @@ pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
|
||||||
else
|
else
|
||||||
click = ClkTitle;
|
click = ClkTitle;
|
||||||
|
|
||||||
for (i = 0; i < LENGTH(buttons); i++) {
|
for (i = 0; i < LENGTH(buttons); i++)
|
||||||
if (buttons[i].click == click && buttons[i].func
|
if (buttons[i].click == click && buttons[i].func && buttons[i].button == pointer.button) {
|
||||||
&& buttons[i].button == pointer.button)
|
arg = buttons[i].arg;
|
||||||
buttons[i].func(click == ClkTagBar && !buttons[i].arg.i
|
if (click == ClkTagBar && !arg.ui)
|
||||||
? &arg
|
arg.ui = tag;
|
||||||
: &buttons[i].arg);
|
buttons[i].func(&arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue