From eb7537e53d5ebfd6369fa56c0714e927d94bcac0 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Thu, 13 Mar 2014 13:58:15 +0100 Subject: [PATCH] i3bar: Send mouse wheel events to child too Signed-off-by: Quentin Glidic --- i3bar/include/child.h | 6 ++++ i3bar/src/child.c | 8 +++++ i3bar/src/xcb.c | 75 ++++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/i3bar/include/child.h b/i3bar/include/child.h index 49329269..72272b24 100644 --- a/i3bar/include/child.h +++ b/i3bar/include/child.h @@ -73,6 +73,12 @@ void stop_child(void); */ void cont_child(void); +/* + * Whether or not the child want click events + * + */ +bool child_want_click_events(void); + /* * Generates a click event, if enabled. * diff --git a/i3bar/src/child.c b/i3bar/src/child.c index cfdf911c..53aef2fa 100644 --- a/i3bar/src/child.c +++ b/i3bar/src/child.c @@ -624,3 +624,11 @@ void cont_child(void) { killpg(child.pid, child.cont_signal); } } + +/* + * Whether or not the child want click events + * + */ +bool child_want_click_events(void) { + return child.click_events; +} diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 928771d8..5204d716 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -330,6 +330,39 @@ void handle_button(xcb_button_press_event_t *event) { DLOG("Got Button %d\n", event->detail); + if (child_want_click_events()) { + /* If the child asked for click events, + * check if a status block has been clicked. */ + + /* First calculate width of tray area */ + trayclient *trayclient; + int tray_width = 0; + TAILQ_FOREACH_REVERSE(trayclient, walk->trayclients, tc_head, tailq) { + if (!trayclient->mapped) + continue; + tray_width += (font.height + 2); + } + + int block_x = 0, last_block_x; + int offset = (walk->rect.w - (statusline_width + tray_width)) - 10; + + x = original_x - offset; + if (x >= 0) { + struct status_block *block; + + TAILQ_FOREACH(block, &statusline_head, blocks) { + last_block_x = block_x; + block_x += block->width + block->x_offset + block->x_append; + + if (x <= block_x && x >= last_block_x) { + send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); + return; + } + } + } + x = original_x; + } + switch (event->detail) { case 4: /* Mouse wheel up. We select the previous ws, if any. @@ -351,7 +384,7 @@ void handle_button(xcb_button_press_event_t *event) { cur_ws = TAILQ_NEXT(cur_ws, tailq); break; - default: + case 1: /* Check if this event regards a workspace button */ TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { DLOG("x = %d\n", x); @@ -360,43 +393,11 @@ void handle_button(xcb_button_press_event_t *event) { } x -= cur_ws->name_width + 11; } - if (cur_ws == NULL) { - /* No workspace button was pressed. - * Check if a status block has been clicked. - * This of course only has an effect, - * if the child reported bidirectional protocol usage. */ - - /* First calculate width of tray area */ - trayclient *trayclient; - int tray_width = 0; - TAILQ_FOREACH_REVERSE(trayclient, walk->trayclients, tc_head, tailq) { - if (!trayclient->mapped) - continue; - tray_width += (font.height + 2); - } - - int block_x = 0, last_block_x; - int offset = (walk->rect.w - (statusline_width + tray_width)) - 10; - - x = original_x - offset; - if (x < 0) - return; - - struct status_block *block; - - TAILQ_FOREACH(block, &statusline_head, blocks) { - last_block_x = block_x; - block_x += block->width + block->x_offset + block->x_append; - - if (x <= block_x && x >= last_block_x) { - send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); - return; - } - } - return; - } - if (event->detail != 1) + if (cur_ws == NULL) return; + break; + default: + return; } /* To properly handle workspace names with double quotes in them, we need -- 2.39.5