From 161db6f17d734ac9deb0a20e81b78d4b2a92ce68 Mon Sep 17 00:00:00 2001 From: Pallav Agarwal Date: Wed, 20 Dec 2017 17:49:38 +0530 Subject: [PATCH] Add relative coordinates in JSON for i3bar click events (fixes #2767) Add support for relative coordinates in i3bar click events Rename {x,y}_rel to relative_{x,y} Update i3bar-protocol doc to mention the added fields in click events --- docs/i3bar-protocol | 11 ++++++++++- i3bar/include/child.h | 2 +- i3bar/src/child.c | 14 +++++++++++++- i3bar/src/xcb.c | 3 ++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/i3bar-protocol b/docs/i3bar-protocol index b8c2b5ad..1a302587 100644 --- a/docs/i3bar-protocol +++ b/docs/i3bar-protocol @@ -236,6 +236,11 @@ x, y:: X11 root window coordinates where the click occurred button:: X11 button ID (for example 1 to 3 for left/middle/right mouse button) +relative_x, relative_y:: + Coordinates where the click occurred, with respect to the top left corner + of the block +width, height:: + Width and height (in px) of the block *Example*: ------------------------------------------ @@ -244,6 +249,10 @@ button:: "instance": "eth0", "button": 1, "x": 1320, - "y": 1400 + "y": 1400, + "relative_x": 12, + "relative_y": 8, + "width": 50, + "height": 22 } ------------------------------------------ diff --git a/i3bar/include/child.h b/i3bar/include/child.h index 0871c7f4..9479fac1 100644 --- a/i3bar/include/child.h +++ b/i3bar/include/child.h @@ -85,4 +85,4 @@ bool child_want_click_events(void); * Generates a click event, if enabled. * */ -void send_block_clicked(int button, const char *name, const char *instance, int x, int y); +void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height); diff --git a/i3bar/src/child.c b/i3bar/src/child.c index 170fcdef..1cd7d512 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -596,7 +596,7 @@ void child_click_events_key(const char *key) { * Generates a click event, if enabled. * */ -void send_block_clicked(int button, const char *name, const char *instance, int x, int y) { +void send_block_clicked(int button, const char *name, const char *instance, int x, int y, int x_rel, int y_rel, int width, int height) { if (!child.click_events) { return; } @@ -624,6 +624,18 @@ void send_block_clicked(int button, const char *name, const char *instance, int child_click_events_key("y"); yajl_gen_integer(gen, y); + child_click_events_key("relative_x"); + yajl_gen_integer(gen, x_rel); + + child_click_events_key("relative_y"); + yajl_gen_integer(gen, y_rel); + + child_click_events_key("width"); + yajl_gen_integer(gen, width); + + child_click_events_key("height"); + yajl_gen_integer(gen, height); + yajl_gen_map_close(gen); child_write_output(); } diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 77822544..542c86c3 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -523,7 +523,8 @@ void handle_button(xcb_button_press_event_t *event) { block_x += render->width + render->x_offset + render->x_append + get_sep_offset(block) + sep_offset_remainder; if (statusline_x <= block_x && statusline_x >= last_block_x) { - send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); + send_block_clicked(event->detail, block->name, block->instance, + event->root_x, event->root_y, statusline_x - last_block_x, event->event_y, block_x - last_block_x, bar_height); return; } -- 2.39.5