summaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/i3bar.c31
-rw-r--r--swaybar/input.c36
-rw-r--r--swaybar/ipc.c2
-rw-r--r--swaybar/render.c19
4 files changed, 50 insertions, 38 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 54607a3a..116c8f6e 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -259,9 +259,34 @@ bool i3bar_handle_readable(struct status_line *status) {
259 } 259 }
260} 260}
261 261
262static uint32_t event_to_x11_button(uint32_t event) {
263 switch (event) {
264 case BTN_LEFT:
265 return 1;
266 case BTN_MIDDLE:
267 return 2;
268 case BTN_RIGHT:
269 return 3;
270 case SWAY_SCROLL_UP:
271 return 4;
272 case SWAY_SCROLL_DOWN:
273 return 5;
274 case SWAY_SCROLL_LEFT:
275 return 6;
276 case SWAY_SCROLL_RIGHT:
277 return 7;
278 case BTN_SIDE:
279 return 8;
280 case BTN_EXTRA:
281 return 9;
282 default:
283 return 0;
284 }
285}
286
262enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, 287enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
263 struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, 288 struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
264 enum x11_button button) { 289 uint32_t button) {
265 wlr_log(WLR_DEBUG, "block %s clicked", block->name); 290 wlr_log(WLR_DEBUG, "block %s clicked", block->name);
266 if (!block->name || !status->click_events) { 291 if (!block->name || !status->click_events) {
267 return HOTSPOT_PROCESS; 292 return HOTSPOT_PROCESS;
@@ -275,7 +300,9 @@ enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
275 json_object_new_string(block->instance)); 300 json_object_new_string(block->instance));
276 } 301 }
277 302
278 json_object_object_add(event_json, "button", json_object_new_int(button)); 303 json_object_object_add(event_json, "button",
304 json_object_new_int(event_to_x11_button(button)));
305 json_object_object_add(event_json, "event", json_object_new_int(button));
279 json_object_object_add(event_json, "x", json_object_new_int(x)); 306 json_object_object_add(event_json, "x", json_object_new_int(x));
280 json_object_object_add(event_json, "y", json_object_new_int(y)); 307 json_object_object_add(event_json, "y", json_object_new_int(y));
281 json_object_object_add(event_json, "relative_x", json_object_new_int(rx)); 308 json_object_object_add(event_json, "relative_x", json_object_new_int(rx));
diff --git a/swaybar/input.c b/swaybar/input.c
index 620da977..bdd55e58 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -22,32 +22,16 @@ void free_hotspots(struct wl_list *list) {
22 } 22 }
23} 23}
24 24
25static enum x11_button wl_button_to_x11_button(uint32_t button) { 25static uint32_t wl_axis_to_button(uint32_t axis, wl_fixed_t value) {
26 switch (button) { 26 bool negative = wl_fixed_to_double(value) < 0;
27 case BTN_LEFT:
28 return LEFT;
29 case BTN_MIDDLE:
30 return MIDDLE;
31 case BTN_RIGHT:
32 return RIGHT;
33 case BTN_SIDE:
34 return BACK;
35 case BTN_EXTRA:
36 return FORWARD;
37 default:
38 return NONE;
39 }
40}
41
42static enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
43 switch (axis) { 27 switch (axis) {
44 case WL_POINTER_AXIS_VERTICAL_SCROLL: 28 case WL_POINTER_AXIS_VERTICAL_SCROLL:
45 return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN; 29 return negative ? SWAY_SCROLL_UP : SWAY_SCROLL_DOWN;
46 case WL_POINTER_AXIS_HORIZONTAL_SCROLL: 30 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
47 return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT; 31 return negative ? SWAY_SCROLL_LEFT : SWAY_SCROLL_RIGHT;
48 default: 32 default:
49 wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll"); 33 wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll");
50 return NONE; 34 return 0;
51 } 35 }
52} 36}
53 37
@@ -102,12 +86,12 @@ static void wl_pointer_motion(void *data, struct wl_pointer *wl_pointer,
102 bar->pointer.y = wl_fixed_to_int(surface_y); 86 bar->pointer.y = wl_fixed_to_int(surface_y);
103} 87}
104 88
105static bool check_bindings(struct swaybar *bar, uint32_t x11_button, 89static bool check_bindings(struct swaybar *bar, uint32_t button,
106 uint32_t state) { 90 uint32_t state) {
107 bool released = state == WL_POINTER_BUTTON_STATE_RELEASED; 91 bool released = state == WL_POINTER_BUTTON_STATE_RELEASED;
108 for (int i = 0; i < bar->config->bindings->length; i++) { 92 for (int i = 0; i < bar->config->bindings->length; i++) {
109 struct swaybar_binding *binding = bar->config->bindings->items[i]; 93 struct swaybar_binding *binding = bar->config->bindings->items[i];
110 if (binding->button == x11_button && binding->release == released) { 94 if (binding->button == button && binding->release == released) {
111 ipc_execute_binding(bar, binding); 95 ipc_execute_binding(bar, binding);
112 return true; 96 return true;
113 } 97 }
@@ -124,7 +108,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
124 return; 108 return;
125 } 109 }
126 110
127 if (check_bindings(bar, wl_button_to_x11_button(button), state)) { 111 if (check_bindings(bar, button, state)) {
128 return; 112 return;
129 } 113 }
130 114
@@ -140,7 +124,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
140 && x < hotspot->x + hotspot->width 124 && x < hotspot->x + hotspot->width
141 && y < hotspot->y + hotspot->height) { 125 && y < hotspot->y + hotspot->height) {
142 if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot, 126 if (HOTSPOT_IGNORE == hotspot->callback(output, hotspot,
143 pointer->x, pointer->y, wl_button_to_x11_button(button), hotspot->data)) { 127 pointer->x, pointer->y, button, hotspot->data)) {
144 return; 128 return;
145 } 129 }
146 } 130 }
@@ -158,7 +142,7 @@ static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
158 142
159 // If there is a button press binding, execute it, skip default behavior, 143 // If there is a button press binding, execute it, skip default behavior,
160 // and check button release bindings 144 // and check button release bindings
161 enum x11_button button = wl_axis_to_x11_button(axis, value); 145 uint32_t button = wl_axis_to_button(axis, value);
162 if (check_bindings(bar, button, WL_POINTER_BUTTON_STATE_PRESSED)) { 146 if (check_bindings(bar, button, WL_POINTER_BUTTON_STATE_PRESSED)) {
163 check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED); 147 check_bindings(bar, button, WL_POINTER_BUTTON_STATE_RELEASED);
164 return; 148 return;
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 8e7a542e..ba53d95d 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -237,7 +237,7 @@ static bool ipc_parse_config(
237 struct swaybar_binding *binding = 237 struct swaybar_binding *binding =
238 calloc(1, sizeof(struct swaybar_binding)); 238 calloc(1, sizeof(struct swaybar_binding));
239 binding->button = json_object_get_int( 239 binding->button = json_object_get_int(
240 json_object_object_get(bindobj, "input_code")); 240 json_object_object_get(bindobj, "event_code"));
241 binding->command = strdup(json_object_get_string( 241 binding->command = strdup(json_object_get_string(
242 json_object_object_get(bindobj, "command"))); 242 json_object_object_get(bindobj, "command")));
243 binding->release = json_object_get_boolean( 243 binding->release = json_object_get_boolean(
diff --git a/swaybar/render.c b/swaybar/render.c
index 7cbcea07..670e8e74 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -1,5 +1,6 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 2#include <assert.h>
3#include <linux/input-event-codes.h>
3#include <limits.h> 4#include <limits.h>
4#include <stdlib.h> 5#include <stdlib.h>
5#include <stdint.h> 6#include <stdint.h>
@@ -126,13 +127,13 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
126 } 127 }
127} 128}
128 129
129static enum hotspot_event_handling block_hotspot_callback(struct swaybar_output *output, 130static enum hotspot_event_handling block_hotspot_callback(
130 struct swaybar_hotspot *hotspot, 131 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
131 int x, int y, enum x11_button button, void *data) { 132 int x, int y, uint32_t button, void *data) {
132 struct i3bar_block *block = data; 133 struct i3bar_block *block = data;
133 struct status_line *status = output->bar->status; 134 struct status_line *status = output->bar->status;
134 return i3bar_block_send_click(status, block, x, y, x - hotspot->x, y - hotspot->y, 135 return i3bar_block_send_click(status, block, x, y, x - hotspot->x,
135 hotspot->width, hotspot->height, button); 136 y - hotspot->y, hotspot->width, hotspot->height, button);
136} 137}
137 138
138static void i3bar_block_unref_callback(void *data) { 139static void i3bar_block_unref_callback(void *data) {
@@ -360,10 +361,10 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
360 return output->height; 361 return output->height;
361} 362}
362 363
363static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, 364static enum hotspot_event_handling workspace_hotspot_callback(
364 struct swaybar_hotspot *hotspot, 365 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
365 int x, int y, enum x11_button button, void *data) { 366 int x, int y, uint32_t button, void *data) {
366 if (button != LEFT) { 367 if (button != BTN_LEFT) {
367 return HOTSPOT_PROCESS; 368 return HOTSPOT_PROCESS;
368 } 369 }
369 ipc_send_workspace_command(output->bar, (const char *)data); 370 ipc_send_workspace_command(output->bar, (const char *)data);