From 63b4bf500020cf35cebfdce2d73f8e359ff495c2 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 9 Jul 2018 22:54:30 +0100 Subject: Update for swaywm/wlroots#1126 --- swaybar/i3bar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'swaybar/i3bar.c') diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 141612a6..26f073c8 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -31,7 +31,7 @@ static bool i3bar_parse_json(struct status_line *status, const char *text) { status_error(status, "[failed to parse i3bar json]"); return false; } - wlr_log(L_DEBUG, "Got i3bar json: '%s'", text); + wlr_log(WLR_DEBUG, "Got i3bar json: '%s'", text); for (size_t i = 0; i < json_object_array_length(results); ++i) { json_object *full_text, *short_text, *color, *min_width, *align, *urgent; json_object *name, *instance, *separator, *separator_block_width; @@ -193,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) { void i3bar_block_send_click(struct status_line *status, struct i3bar_block *block, int x, int y, uint32_t button) { - wlr_log(L_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); + wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); if (!block->name || !status->i3bar_state.click_events) { return; } -- cgit v1.2.3 From 79a998849b8cedc9fccddfb31e4d1c99d1c17ff7 Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Sun, 15 Jul 2018 20:16:37 -0400 Subject: make hotspot callback take an x11 button id --- include/swaybar/bar.h | 15 ++++++++++++++- include/swaybar/status_line.h | 4 +++- swaybar/bar.c | 2 +- swaybar/i3bar.c | 32 +++++++++++++++++++++++++++++++- swaybar/render.c | 4 ++-- 5 files changed, 51 insertions(+), 6 deletions(-) (limited to 'swaybar/i3bar.c') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index af478f33..f1ff25b2 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -16,11 +16,24 @@ struct swaybar_pointer { int x, y; }; +enum x11_button { + NONE, + LEFT, + MIDDLE, + RIGHT, + SCROLL_UP, + SCROLL_DOWN, + SCROLL_LEFT, + SCROLL_RIGHT, + BACK, + FORWARD, +}; + struct swaybar_hotspot { struct wl_list link; int x, y, width, height; void (*callback)(struct swaybar_output *output, - int x, int y, uint32_t button, void *data); + int x, int y, enum x11_button button, void *data); void (*destroy)(void *data); void *data; }; diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index bf12a842..2eaf8140 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h @@ -72,7 +72,9 @@ bool status_handle_readable(struct status_line *status); void status_line_free(struct status_line *status); bool i3bar_handle_readable(struct status_line *status); void i3bar_block_send_click(struct status_line *status, - struct i3bar_block *block, int x, int y, uint32_t button); + struct i3bar_block *block, int x, int y, enum x11_button button); void i3bar_block_free(struct i3bar_block *block); +enum x11_button wl_button_to_x11_button(uint32_t button); +enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value); #endif diff --git a/swaybar/bar.c b/swaybar/bar.c index f03c5aea..1186d1e5 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -147,7 +147,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, && x < hotspot->x + hotspot->width && y < hotspot->y + hotspot->height) { hotspot->callback(output, pointer->x, pointer->y, - button, hotspot->data); + wl_button_to_x11_button(button), hotspot->data); } } } diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 26f073c8..a615fb27 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -1,5 +1,6 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include #include @@ -192,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) { } void i3bar_block_send_click(struct status_line *status, - struct i3bar_block *block, int x, int y, uint32_t button) { + struct i3bar_block *block, int x, int y, enum x11_button button) { wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); if (!block->name || !status->i3bar_state.click_events) { return; @@ -215,3 +216,32 @@ void i3bar_block_send_click(struct status_line *status, } json_object_put(event_json); } + +enum x11_button wl_button_to_x11_button(uint32_t button) { + switch (button) { + case (BTN_LEFT): + return LEFT; + case (BTN_MIDDLE): + return MIDDLE; + case (BTN_RIGHT): + return RIGHT; + case (BTN_SIDE): + return BACK; + case (BTN_EXTRA): + return FORWARD; + default: + return NONE; + } +} + +enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) { + switch (axis) { + case WL_POINTER_AXIS_VERTICAL_SCROLL: + return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN; + case WL_POINTER_AXIS_HORIZONTAL_SCROLL: + return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT; + default: + wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll"); + return NONE; + } +} diff --git a/swaybar/render.c b/swaybar/render.c index 909b56f4..d210e25a 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -109,7 +109,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, } static void block_hotspot_callback(struct swaybar_output *output, - int x, int y, uint32_t button, void *data) { + int x, int y, enum x11_button button, void *data) { struct i3bar_block *block = data; struct status_line *status = output->bar->status; i3bar_block_send_click(status, block, x, y, button); @@ -349,7 +349,7 @@ static const char *strip_workspace_number(const char *ws_name) { } static void workspace_hotspot_callback(struct swaybar_output *output, - int x, int y, uint32_t button, void *data) { + int x, int y, enum x11_button button, void *data) { ipc_send_workspace_command(output->bar, (const char *)data); } -- cgit v1.2.3 From e43c20134ab48ab36391443860cbdf4ac67d8348 Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Tue, 17 Jul 2018 19:00:38 -0400 Subject: remove unnecessary parens --- swaybar/i3bar.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'swaybar/i3bar.c') diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index a615fb27..78b183ad 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -219,15 +219,15 @@ void i3bar_block_send_click(struct status_line *status, enum x11_button wl_button_to_x11_button(uint32_t button) { switch (button) { - case (BTN_LEFT): + case BTN_LEFT: return LEFT; - case (BTN_MIDDLE): + case BTN_MIDDLE: return MIDDLE; - case (BTN_RIGHT): + case BTN_RIGHT: return RIGHT; - case (BTN_SIDE): + case BTN_SIDE: return BACK; - case (BTN_EXTRA): + case BTN_EXTRA: return FORWARD; default: return NONE; -- cgit v1.2.3 From bfcfabee2b7e6bd820929a3cb86c4981a6385ac7 Mon Sep 17 00:00:00 2001 From: minus Date: Thu, 19 Jul 2018 21:15:01 +0200 Subject: swaybar: Fix scroll handling on workspace buttons As well as ignoring scroll events on status elements when click_events is enabled. Previously, using the scroll wheel on a workspace button would switch to that workspace instead of scrolling through them. Clicks and scrolling on status elements would always be processed by swaybar, too. So in case you were using scrolling as volume control on a status item, swaybar would additionally scroll through your workspaces. --- include/swaybar/bar.h | 7 ++++++- include/swaybar/status_line.h | 2 +- swaybar/bar.c | 14 +++++++++----- swaybar/i3bar.c | 5 +++-- swaybar/render.c | 10 +++++++--- 5 files changed, 26 insertions(+), 12 deletions(-) (limited to 'swaybar/i3bar.c') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index f1ff25b2..1cecea71 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -29,10 +29,15 @@ enum x11_button { FORWARD, }; +enum hotspot_event_handling { + HOTSPOT_IGNORE, + HOTSPOT_PROCESS, +}; + struct swaybar_hotspot { struct wl_list link; int x, y, width, height; - void (*callback)(struct swaybar_output *output, + enum hotspot_event_handling (*callback)(struct swaybar_output *output, int x, int y, enum x11_button button, void *data); void (*destroy)(void *data); void *data; diff --git a/include/swaybar/status_line.h b/include/swaybar/status_line.h index 2eaf8140..de9b98d7 100644 --- a/include/swaybar/status_line.h +++ b/include/swaybar/status_line.h @@ -71,7 +71,7 @@ void status_error(struct status_line *status, const char *text); bool status_handle_readable(struct status_line *status); void status_line_free(struct status_line *status); bool i3bar_handle_readable(struct status_line *status); -void i3bar_block_send_click(struct status_line *status, +enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, struct i3bar_block *block, int x, int y, enum x11_button button); void i3bar_block_free(struct i3bar_block *block); enum x11_button wl_button_to_x11_button(uint32_t button); diff --git a/swaybar/bar.c b/swaybar/bar.c index 94bc48bc..62a7727e 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -146,8 +146,10 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, && y >= hotspot->y && x < hotspot->x + hotspot->width && y < hotspot->y + hotspot->height) { - hotspot->callback(output, pointer->x, pointer->y, - wl_button_to_x11_button(button), hotspot->data); + if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y, + wl_button_to_x11_button(button), hotspot->data)) { + return; + } } } } @@ -169,9 +171,11 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, && y >= hotspot->y && x < hotspot->x + hotspot->width && y < hotspot->y + hotspot->height) { - hotspot->callback(output, pointer->x, pointer->y, - wl_axis_to_x11_button(axis, value), hotspot->data); - return; + if (HOTSPOT_IGNORE == hotspot->callback( + output, pointer->x, pointer->y, + wl_axis_to_x11_button(axis, value), hotspot->data)) { + return; + } } } diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 78b183ad..ae37eeb9 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c @@ -192,11 +192,11 @@ bool i3bar_handle_readable(struct status_line *status) { return redraw; } -void i3bar_block_send_click(struct status_line *status, +enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, struct i3bar_block *block, int x, int y, enum x11_button button) { wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); if (!block->name || !status->i3bar_state.click_events) { - return; + return HOTSPOT_PROCESS; } struct json_object *event_json = json_object_new_object(); @@ -215,6 +215,7 @@ void i3bar_block_send_click(struct status_line *status, status_error(status, "[failed to write click event]"); } json_object_put(event_json); + return HOTSPOT_IGNORE; } enum x11_button wl_button_to_x11_button(uint32_t button) { diff --git a/swaybar/render.c b/swaybar/render.c index d210e25a..6f370077 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -108,11 +108,11 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, } } -static void block_hotspot_callback(struct swaybar_output *output, +static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output, int x, int y, enum x11_button button, void *data) { struct i3bar_block *block = data; struct status_line *status = output->bar->status; - i3bar_block_send_click(status, block, x, y, button); + return i3bar_block_send_click(status, block, x, y, button); } static uint32_t render_status_block(cairo_t *cairo, @@ -348,9 +348,13 @@ static const char *strip_workspace_number(const char *ws_name) { return ws_name; } -static void workspace_hotspot_callback(struct swaybar_output *output, +static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, int x, int y, enum x11_button button, void *data) { + if (button != LEFT) { + return HOTSPOT_PROCESS; + } ipc_send_workspace_command(output->bar, (const char *)data); + return HOTSPOT_IGNORE; } static uint32_t render_workspace_button(cairo_t *cairo, -- cgit v1.2.3