mirror of
https://github.com/kolunmi/dwlb.git
synced 2025-09-07 11:54:45 +00:00
support mouse wheel up and down for actions
This commit is contained in:
parent
d2150540f5
commit
d4c747faec
@ -43,6 +43,8 @@ The `-status` and `-title` commands are used to write status text. The text may
|
|||||||
| `^lm(SHELLCOMMAND)` | Begins or terminates left mouse button region with action `SHELLCOMMAND`. |
|
| `^lm(SHELLCOMMAND)` | Begins or terminates left mouse button region with action `SHELLCOMMAND`. |
|
||||||
| `^mm(SHELLCOMMAND)` | Begins or terminates middle mouse button region with action `SHELLCOMMAND`. |
|
| `^mm(SHELLCOMMAND)` | Begins or terminates middle mouse button region with action `SHELLCOMMAND`. |
|
||||||
| `^rm(SHELLCOMMAND)` | Begins or terminates right mouse button region with action `SHELLCOMMAND`. |
|
| `^rm(SHELLCOMMAND)` | Begins or terminates right mouse button region with action `SHELLCOMMAND`. |
|
||||||
|
| `^us(SHELLCOMMAND)` | Begins or terminates mouse scroll up region with action `SHELLCOMMAND`. |
|
||||||
|
| `^ds(SHELLCOMMAND)` | Begins or terminates mouse scroll down region with action `SHELLCOMMAND`. |
|
||||||
|
|
||||||
In this example, clicking the text highlighted in red will spawn the [foot](https://codeberg.org/dnkl/foot) terminal.
|
In this example, clicking the text highlighted in red will spawn the [foot](https://codeberg.org/dnkl/foot) terminal.
|
||||||
```bash
|
```bash
|
||||||
|
51
dwlb.c
51
dwlb.c
@ -115,6 +115,8 @@
|
|||||||
|
|
||||||
#define TEXT_MAX 2048
|
#define TEXT_MAX 2048
|
||||||
|
|
||||||
|
enum { WheelUp, WheelDown };
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pixman_color_t color;
|
pixman_color_t color;
|
||||||
bool bg;
|
bool bg;
|
||||||
@ -657,7 +659,7 @@ pointer_frame(void *data, struct wl_pointer *pointer)
|
|||||||
}
|
}
|
||||||
x += TEXT_WIDTH(tags[i], seat->bar->width - x, seat->bar->textpadding) / buffer_scale;
|
x += TEXT_WIDTH(tags[i], seat->bar->width - x, seat->bar->textpadding) / buffer_scale;
|
||||||
} while (seat->pointer_x >= x && ++i < tags_l);
|
} while (seat->pointer_x >= x && ++i < tags_l);
|
||||||
|
|
||||||
if (i < tags_l) {
|
if (i < tags_l) {
|
||||||
/* Clicked on tags */
|
/* Clicked on tags */
|
||||||
if (ipc) {
|
if (ipc) {
|
||||||
@ -699,6 +701,7 @@ pointer_frame(void *data, struct wl_pointer *pointer)
|
|||||||
} else {
|
} else {
|
||||||
/* Clicked on status */
|
/* Clicked on status */
|
||||||
for (i = 0; i < seat->bar->status.buttons_l; i++) {
|
for (i = 0; i < seat->bar->status.buttons_l; i++) {
|
||||||
|
|
||||||
if (seat->pointer_button == seat->bar->status.buttons[i].btn
|
if (seat->pointer_button == seat->bar->status.buttons[i].btn
|
||||||
&& seat->pointer_x >= status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x1 / buffer_scale
|
&& seat->pointer_x >= status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x1 / buffer_scale
|
||||||
&& seat->pointer_x < status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x2 / buffer_scale) {
|
&& seat->pointer_x < status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x2 / buffer_scale) {
|
||||||
@ -722,6 +725,25 @@ static void
|
|||||||
pointer_axis_discrete(void *data, struct wl_pointer *pointer,
|
pointer_axis_discrete(void *data, struct wl_pointer *pointer,
|
||||||
uint32_t axis, int32_t discrete)
|
uint32_t axis, int32_t discrete)
|
||||||
{
|
{
|
||||||
|
uint32_t i;
|
||||||
|
uint32_t btn = discrete < 0 ? WheelUp : WheelDown;
|
||||||
|
Seat *seat = (Seat *)data;
|
||||||
|
|
||||||
|
if (!seat->bar)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint32_t status_x = seat->bar->width / buffer_scale - TEXT_WIDTH(seat->bar->status.text, seat->bar->width, seat->bar->textpadding) / buffer_scale;
|
||||||
|
if (seat->pointer_x > status_x) {
|
||||||
|
/* Clicked on status */
|
||||||
|
for (i = 0; i < seat->bar->status.buttons_l; i++) {
|
||||||
|
if (btn == seat->bar->status.buttons[i].btn
|
||||||
|
&& seat->pointer_x >= status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x1 / buffer_scale
|
||||||
|
&& seat->pointer_x < status_x + seat->bar->textpadding + seat->bar->status.buttons[i].x2 / buffer_scale) {
|
||||||
|
shell_command(seat->bar->status.buttons[i].command);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1259,6 +1281,8 @@ parse_into_customtext(CustomText *ct, char *text)
|
|||||||
Button *left_button = NULL;
|
Button *left_button = NULL;
|
||||||
Button *middle_button = NULL;
|
Button *middle_button = NULL;
|
||||||
Button *right_button = NULL;
|
Button *right_button = NULL;
|
||||||
|
Button *scrollup_button = NULL;
|
||||||
|
Button *scrolldown_button = NULL;
|
||||||
|
|
||||||
for (char *p = text; *p && str_pos < sizeof(ct->text) - 1; p++) {
|
for (char *p = text; *p && str_pos < sizeof(ct->text) - 1; p++) {
|
||||||
if (state == UTF8_ACCEPT && *p == '^') {
|
if (state == UTF8_ACCEPT && *p == '^') {
|
||||||
@ -1318,6 +1342,26 @@ parse_into_customtext(CustomText *ct, char *text)
|
|||||||
snprintf(right_button->command, sizeof right_button->command, "%s", arg);
|
snprintf(right_button->command, sizeof right_button->command, "%s", arg);
|
||||||
right_button->x1 = x;
|
right_button->x1 = x;
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(p, "us")) {
|
||||||
|
if (scrollup_button) {
|
||||||
|
scrollup_button->x2 = x;
|
||||||
|
scrollup_button = NULL;
|
||||||
|
} else if (*arg) {
|
||||||
|
ARRAY_APPEND(ct->buttons, ct->buttons_l, ct->buttons_c, scrollup_button);
|
||||||
|
scrollup_button->btn = WheelUp;
|
||||||
|
snprintf(scrollup_button->command, sizeof scrollup_button->command, "%s", arg);
|
||||||
|
scrollup_button->x1 = x;
|
||||||
|
}
|
||||||
|
} else if (!strcmp(p, "ds")) {
|
||||||
|
if (scrolldown_button) {
|
||||||
|
scrolldown_button->x2 = x;
|
||||||
|
scrolldown_button = NULL;
|
||||||
|
} else if (*arg) {
|
||||||
|
ARRAY_APPEND(ct->buttons, ct->buttons_l, ct->buttons_c, scrolldown_button);
|
||||||
|
scrolldown_button->btn = WheelDown;
|
||||||
|
snprintf(scrolldown_button->command, sizeof scrolldown_button->command, "%s", arg);
|
||||||
|
scrolldown_button->x1 = x;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*--arg = '(';
|
*--arg = '(';
|
||||||
@ -1351,6 +1395,11 @@ parse_into_customtext(CustomText *ct, char *text)
|
|||||||
middle_button->x2 = x;
|
middle_button->x2 = x;
|
||||||
if (right_button)
|
if (right_button)
|
||||||
right_button->x2 = x;
|
right_button->x2 = x;
|
||||||
|
if (scrollup_button)
|
||||||
|
scrollup_button->x2 = x;
|
||||||
|
if (scrolldown_button)
|
||||||
|
scrolldown_button->x2 = x;
|
||||||
|
|
||||||
|
|
||||||
ct->text[str_pos] = '\0';
|
ct->text[str_pos] = '\0';
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user