aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-15 21:25:28 -0500
committerLibravatar emersion <contact@emersion.fr>2019-01-16 11:12:45 +0100
commit02bbefda20b9a4f86e740d33bbaa21c661bb2fac (patch)
tree1b753e414749374be1e144a326a744c4b6812480 /swaybar
parentlayer_shell: do not SIGABRT sway on zero outputs (diff)
downloadsway-02bbefda20b9a4f86e740d33bbaa21c661bb2fac.tar.gz
sway-02bbefda20b9a4f86e740d33bbaa21c661bb2fac.tar.zst
sway-02bbefda20b9a4f86e740d33bbaa21c661bb2fac.zip
bar_cmd_tray_bind: Use mouse button helpers
This modifies `bar_cmd_tray_bindsym` to use `get_mouse_bindsym` for parsing mouse buttons. This also introduces `bar_cmd_tray_bindcode`, which will use `get_mouse_bindcode` for parsing mouse buttons. Like with sway bindings, the two commands are encapsulated in a single file to maximize shared code. This also modifies tray bindings to work off of events codes rather than x11 buttons, which allows for any mouse buttons to be used. For `get_bar_config`, `event_code` has been added to the `tray_bindings` section and will include to event code for the button. If the event code can be mapped to a x11 button, `input_code` will still be the x11 button number. Otherwise, `input_code` will be `0`.
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/config.c20
-rw-r--r--swaybar/i3bar.c25
-rw-r--r--swaybar/input.c25
-rw-r--r--swaybar/ipc.c12
-rw-r--r--swaybar/tray/item.c15
5 files changed, 61 insertions, 36 deletions
diff --git a/swaybar/config.c b/swaybar/config.c
index d4cc9b1a..0071c7f9 100644
--- a/swaybar/config.c
+++ b/swaybar/config.c
@@ -78,6 +78,7 @@ struct swaybar_config *init_config(void) {
78 78
79#if HAVE_TRAY 79#if HAVE_TRAY
80 config->tray_padding = 2; 80 config->tray_padding = 2;
81 wl_list_init(&config->tray_bindings);
81#endif 82#endif
82 83
83 return config; 84 return config;
@@ -91,6 +92,16 @@ static void free_binding(struct swaybar_binding *binding) {
91 free(binding); 92 free(binding);
92} 93}
93 94
95#if HAVE_TRAY
96static void free_tray_binding(struct tray_binding *binding) {
97 if (!binding) {
98 return;
99 }
100 free(binding->command);
101 free(binding);
102}
103#endif
104
94void free_config(struct swaybar_config *config) { 105void free_config(struct swaybar_config *config) {
95 free(config->status_command); 106 free(config->status_command);
96 free(config->font); 107 free(config->font);
@@ -111,9 +122,14 @@ void free_config(struct swaybar_config *config) {
111 } 122 }
112#if HAVE_TRAY 123#if HAVE_TRAY
113 list_free_items_and_destroy(config->tray_outputs); 124 list_free_items_and_destroy(config->tray_outputs);
114 for (int i = 0; i < 10; ++i) { 125
115 free(config->tray_bindings[i]); 126 struct tray_binding *tray_bind = NULL, *tmp_tray_bind = NULL;
127 wl_list_for_each_safe(tray_bind, tmp_tray_bind, &config->tray_bindings,
128 link) {
129 wl_list_remove(&tray_bind->link);
130 free_tray_binding(tray_bind);
116 } 131 }
132
117 free(config->icon_theme); 133 free(config->icon_theme);
118#endif 134#endif
119 free(config); 135 free(config);
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 116c8f6e..8bca1bf9 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -259,31 +259,6 @@ 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
287enum hotspot_event_handling i3bar_block_send_click(struct status_line *status, 262enum hotspot_event_handling i3bar_block_send_click(struct status_line *status,
288 struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h, 263 struct i3bar_block *block, int x, int y, int rx, int ry, int w, int h,
289 uint32_t button) { 264 uint32_t button) {
diff --git a/swaybar/input.c b/swaybar/input.c
index bdd55e58..998b186f 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -22,6 +22,31 @@ void free_hotspots(struct wl_list *list) {
22 } 22 }
23} 23}
24 24
25uint32_t event_to_x11_button(uint32_t event) {
26 switch (event) {
27 case BTN_LEFT:
28 return 1;
29 case BTN_MIDDLE:
30 return 2;
31 case BTN_RIGHT:
32 return 3;
33 case SWAY_SCROLL_UP:
34 return 4;
35 case SWAY_SCROLL_DOWN:
36 return 5;
37 case SWAY_SCROLL_LEFT:
38 return 6;
39 case SWAY_SCROLL_RIGHT:
40 return 7;
41 case BTN_SIDE:
42 return 8;
43 case BTN_EXTRA:
44 return 9;
45 default:
46 return 0;
47 }
48}
49
25static uint32_t wl_axis_to_button(uint32_t axis, wl_fixed_t value) { 50static uint32_t wl_axis_to_button(uint32_t axis, wl_fixed_t value) {
26 bool negative = wl_fixed_to_double(value) < 0; 51 bool negative = wl_fixed_to_double(value) < 0;
27 switch (axis) { 52 switch (axis) {
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 097f9161..0dc39439 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -313,11 +313,13 @@ static bool ipc_parse_config(
313 int length = json_object_array_length(tray_bindings); 313 int length = json_object_array_length(tray_bindings);
314 for (int i = 0; i < length; ++i) { 314 for (int i = 0; i < length; ++i) {
315 json_object *bind = json_object_array_get_idx(tray_bindings, i); 315 json_object *bind = json_object_array_get_idx(tray_bindings, i);
316 json_object *button, *command; 316 struct tray_binding *binding =
317 json_object_object_get_ex(bind, "input_code", &button); 317 calloc(1, sizeof(struct tray_binding));
318 json_object_object_get_ex(bind, "command", &command); 318 binding->button = json_object_get_int(
319 config->tray_bindings[json_object_get_int(button)] = 319 json_object_object_get(bind, "event_code"));
320 strdup(json_object_get_string(command)); 320 binding->command = strdup(json_object_get_string(
321 json_object_object_get(bind, "command")));
322 wl_list_insert(&config->tray_bindings, &binding->link);
321 } 323 }
322 } 324 }
323 325
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c
index 0833dcb9..9056331e 100644
--- a/swaybar/tray/item.c
+++ b/swaybar/tray/item.c
@@ -301,8 +301,15 @@ void destroy_sni(struct swaybar_sni *sni) {
301} 301}
302 302
303static void handle_click(struct swaybar_sni *sni, int x, int y, 303static void handle_click(struct swaybar_sni *sni, int x, int y,
304 enum x11_button button, int delta) { 304 uint32_t button, int delta) {
305 const char *method = sni->tray->bar->config->tray_bindings[button]; 305 const char *method = NULL;
306 struct tray_binding *binding = NULL;
307 wl_list_for_each(binding, &sni->tray->bar->config->tray_bindings, link) {
308 if (binding->button == button) {
309 method = binding->command;
310 break;
311 }
312 }
306 if (!method) { 313 if (!method) {
307 static const char *default_bindings[10] = { 314 static const char *default_bindings[10] = {
308 "nop", 315 "nop",
@@ -316,7 +323,7 @@ static void handle_click(struct swaybar_sni *sni, int x, int y,
316 "nop", 323 "nop",
317 "nop" 324 "nop"
318 }; 325 };
319 method = default_bindings[button]; 326 method = default_bindings[event_to_x11_button(button)];
320 } 327 }
321 if (strcmp(method, "nop") == 0) { 328 if (strcmp(method, "nop") == 0) {
322 return; 329 return;
@@ -345,7 +352,7 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
345 352
346static enum hotspot_event_handling icon_hotspot_callback( 353static enum hotspot_event_handling icon_hotspot_callback(
347 struct swaybar_output *output, struct swaybar_hotspot *hotspot, 354 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
348 int x, int y, enum x11_button button, void *data) { 355 int x, int y, uint32_t button, void *data) {
349 wlr_log(WLR_DEBUG, "Clicked on %s", (char *)data); 356 wlr_log(WLR_DEBUG, "Clicked on %s", (char *)data);
350 357
351 struct swaybar_tray *tray = output->bar->tray; 358 struct swaybar_tray *tray = output->bar->tray;