i3bar: Send mouse wheel events to child too
Patch status: merged
Patch by Quentin Glidic
Long description:
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
To apply this patch, use:
curl http://cr.i3wm.org/patch/483/raw.patch | git am
b/i3bar/include/child.h
16 |
@@ -74,6 +74,12 @@ void stop_child(void); |
17 |
void cont_child(void); |
18 |
|
19 |
/* |
20 |
+ * Whether or not the child want click events |
21 |
+ * |
22 |
+ */ |
23 |
+bool child_want_click_events(void); |
24 |
+ |
25 |
+/* |
26 |
* Generates a click event, if enabled. |
27 |
* |
28 |
*/ |
b/i3bar/src/child.c
33 |
@@ -624,3 +624,11 @@ void cont_child(void) { |
34 |
killpg(child.pid, child.cont_signal); |
35 |
} |
36 |
} |
37 |
+ |
38 |
+/* |
39 |
+ * Whether or not the child want click events |
40 |
+ * |
41 |
+ */ |
42 |
+bool child_want_click_events(void) { |
43 |
+ return child.click_events; |
44 |
+} |
b/i3bar/src/xcb.c
49 |
@@ -330,6 +330,39 @@ void handle_button(xcb_button_press_event_t *event) { |
50 |
|
51 |
DLOG("Got Button %d\n", event->detail); |
52 |
|
53 |
+ if (child_want_click_events()) { |
54 |
+ /* If the child asked for click events, |
55 |
+ * check if a status block has been clicked. */ |
56 |
+ |
57 |
+ /* First calculate width of tray area */ |
58 |
+ trayclient *trayclient; |
59 |
+ int tray_width = 0; |
60 |
+ TAILQ_FOREACH_REVERSE(trayclient, walk->trayclients, tc_head, tailq) { |
61 |
+ if (!trayclient->mapped) |
62 |
+ continue; |
63 |
+ tray_width += (font.height + 2); |
64 |
+ } |
65 |
+ |
66 |
+ int block_x = 0, last_block_x; |
67 |
+ int offset = (walk->rect.w - (statusline_width + tray_width)) - 10; |
68 |
+ |
69 |
+ x = original_x - offset; |
70 |
+ if (x >= 0) { |
71 |
+ struct status_block *block; |
72 |
+ |
73 |
+ TAILQ_FOREACH(block, &statusline_head, blocks) { |
74 |
+ last_block_x = block_x; |
75 |
+ block_x += block->width + block->x_offset + block->x_append; |
76 |
+ |
77 |
+ if (x <= block_x && x >= last_block_x) { |
78 |
+ send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); |
79 |
+ return; |
80 |
+ } |
81 |
+ } |
82 |
+ } |
83 |
+ x = original_x; |
84 |
+ } |
85 |
+ |
86 |
switch (event->detail) { |
87 |
case 4: |
88 |
/* Mouse wheel up. We select the previous ws, if any. |
89 |
@@ -351,7 +384,7 @@ void handle_button(xcb_button_press_event_t *event) { |
90 |
|
91 |
cur_ws = TAILQ_NEXT(cur_ws, tailq); |
92 |
break; |
93 |
- default: |
94 |
+ case 1: |
95 |
/* Check if this event regards a workspace button */ |
96 |
TAILQ_FOREACH(cur_ws, walk->workspaces, tailq) { |
97 |
DLOG("x = %d\n", x); |
98 |
@@ -360,43 +393,11 @@ void handle_button(xcb_button_press_event_t *event) { |
99 |
} |
100 |
x -= cur_ws->name_width + 11; |
101 |
} |
102 |
- if (cur_ws == NULL) { |
103 |
- /* No workspace button was pressed. |
104 |
- * Check if a status block has been clicked. |
105 |
- * This of course only has an effect, |
106 |
- * if the child reported bidirectional protocol usage. */ |
107 |
- |
108 |
- /* First calculate width of tray area */ |
109 |
- trayclient *trayclient; |
110 |
- int tray_width = 0; |
111 |
- TAILQ_FOREACH_REVERSE(trayclient, walk->trayclients, tc_head, tailq) { |
112 |
- if (!trayclient->mapped) |
113 |
- continue; |
114 |
- tray_width += (font.height + 2); |
115 |
- } |
116 |
- |
117 |
- int block_x = 0, last_block_x; |
118 |
- int offset = (walk->rect.w - (statusline_width + tray_width)) - 10; |
119 |
- |
120 |
- x = original_x - offset; |
121 |
- if (x < 0) |
122 |
- return; |
123 |
- |
124 |
- struct status_block *block; |
125 |
- |
126 |
- TAILQ_FOREACH(block, &statusline_head, blocks) { |
127 |
- last_block_x = block_x; |
128 |
- block_x += block->width + block->x_offset + block->x_append; |
129 |
- |
130 |
- if (x <= block_x && x >= last_block_x) { |
131 |
- send_block_clicked(event->detail, block->name, block->instance, event->root_x, event->root_y); |
132 |
- return; |
133 |
- } |
134 |
- } |
135 |
- return; |
136 |
- } |
137 |
- if (event->detail != 1) |
138 |
+ if (cur_ws == NULL) |
139 |
return; |
140 |
+ break; |
141 |
+ default: |
142 |
+ return; |
143 |
} |
144 |
|
145 |
/* To properly handle workspace names with double quotes in them, we need |