aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/i3bar.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-10 12:43:10 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-10 12:43:10 -0500
commit3d6440ec26f2b39c54fd03aa3a3c822a8a2bbc72 (patch)
tree05e5dddd092b3d3ba16166a3784a49923e9f3de2 /swaybar/i3bar.c
parentMerge pull request #3400 from ianyfan/config-brace (diff)
downloadsway-3d6440ec26f2b39c54fd03aa3a3c822a8a2bbc72.tar.gz
sway-3d6440ec26f2b39c54fd03aa3a3c822a8a2bbc72.tar.zst
sway-3d6440ec26f2b39c54fd03aa3a3c822a8a2bbc72.zip
bar_cmd_bind: utilize mouse button helpers
This modifies `bar_cmd_bindsym` to use `get_mouse_bindsym` for parsing mouse buttons. This also introduces `cmd_bar_bindcode`, which will use `get_mouse_bindcode` for parsing mouse buttons. Like sway bindings, the two commands are encapsulated in a single file with shared code. This also modifies swaybar to operate off of event codes rather than x11 button numbers, which allows for any mouse button to be used. This introduces two new IPC properties: - For `get_bar_config`, `event_code` has been added to the `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`. - Likewise for `click_events`, `event` has been added and will include the event code for the button clicked. If the event code can be mapped to a x11 button, `button` will still be the x11 button number. Otherwise, `button` will be `0`.
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r--swaybar/i3bar.c31
1 files changed, 29 insertions, 2 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));