diff options
author | emersion <contact@emersion.fr> | 2018-07-18 00:16:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-18 00:16:15 +0100 |
commit | 48b911a4596f50b585a1073d32413236d9defb60 (patch) | |
tree | a225ff763a647e669cb8c7962b0bc333a8cf86a7 /swaybar | |
parent | Merge pull request #2289 from frsfnrrg/memory-fixes (diff) | |
parent | remove unnecessary parens (diff) | |
download | sway-48b911a4596f50b585a1073d32413236d9defb60.tar.gz sway-48b911a4596f50b585a1073d32413236d9defb60.tar.zst sway-48b911a4596f50b585a1073d32413236d9defb60.zip |
Merge pull request #2281 from pvsr/X11_click
Send clicks to swaybar blocks as X11 button ids
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/bar.c | 17 | ||||
-rw-r--r-- | swaybar/i3bar.c | 32 | ||||
-rw-r--r-- | swaybar/render.c | 4 |
3 files changed, 49 insertions, 4 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c index f03c5aea..94bc48bc 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -147,7 +147,7 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
147 | && x < hotspot->x + hotspot->width | 147 | && x < hotspot->x + hotspot->width |
148 | && y < hotspot->y + hotspot->height) { | 148 | && y < hotspot->y + hotspot->height) { |
149 | hotspot->callback(output, pointer->x, pointer->y, | 149 | hotspot->callback(output, pointer->x, pointer->y, |
150 | button, hotspot->data); | 150 | wl_button_to_x11_button(button), hotspot->data); |
151 | } | 151 | } |
152 | } | 152 | } |
153 | } | 153 | } |
@@ -155,11 +155,26 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, | |||
155 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, | 155 | static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, |
156 | uint32_t time, uint32_t axis, wl_fixed_t value) { | 156 | uint32_t time, uint32_t axis, wl_fixed_t value) { |
157 | struct swaybar *bar = data; | 157 | struct swaybar *bar = data; |
158 | struct swaybar_pointer *pointer = &bar->pointer; | ||
158 | struct swaybar_output *output = bar->pointer.current; | 159 | struct swaybar_output *output = bar->pointer.current; |
159 | if (!sway_assert(output, "axis with no active output")) { | 160 | if (!sway_assert(output, "axis with no active output")) { |
160 | return; | 161 | return; |
161 | } | 162 | } |
162 | 163 | ||
164 | struct swaybar_hotspot *hotspot; | ||
165 | wl_list_for_each(hotspot, &output->hotspots, link) { | ||
166 | double x = pointer->x * output->scale; | ||
167 | double y = pointer->y * output->scale; | ||
168 | if (x >= hotspot->x | ||
169 | && y >= hotspot->y | ||
170 | && x < hotspot->x + hotspot->width | ||
171 | && y < hotspot->y + hotspot->height) { | ||
172 | hotspot->callback(output, pointer->x, pointer->y, | ||
173 | wl_axis_to_x11_button(axis, value), hotspot->data); | ||
174 | return; | ||
175 | } | ||
176 | } | ||
177 | |||
163 | double amt = wl_fixed_to_double(value); | 178 | double amt = wl_fixed_to_double(value); |
164 | if (amt == 0.0) { | 179 | if (amt == 0.0) { |
165 | return; | 180 | return; |
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c index 26f073c8..78b183ad 100644 --- a/swaybar/i3bar.c +++ b/swaybar/i3bar.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <json-c/json.h> | 2 | #include <json-c/json.h> |
3 | #include <linux/input-event-codes.h> | ||
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | #include <unistd.h> | 6 | #include <unistd.h> |
@@ -192,7 +193,7 @@ bool i3bar_handle_readable(struct status_line *status) { | |||
192 | } | 193 | } |
193 | 194 | ||
194 | void i3bar_block_send_click(struct status_line *status, | 195 | void i3bar_block_send_click(struct status_line *status, |
195 | struct i3bar_block *block, int x, int y, uint32_t button) { | 196 | struct i3bar_block *block, int x, int y, enum x11_button button) { |
196 | wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); | 197 | wlr_log(WLR_DEBUG, "block %s clicked", block->name ? block->name : "(nil)"); |
197 | if (!block->name || !status->i3bar_state.click_events) { | 198 | if (!block->name || !status->i3bar_state.click_events) { |
198 | return; | 199 | return; |
@@ -215,3 +216,32 @@ void i3bar_block_send_click(struct status_line *status, | |||
215 | } | 216 | } |
216 | json_object_put(event_json); | 217 | json_object_put(event_json); |
217 | } | 218 | } |
219 | |||
220 | enum x11_button wl_button_to_x11_button(uint32_t button) { | ||
221 | switch (button) { | ||
222 | case BTN_LEFT: | ||
223 | return LEFT; | ||
224 | case BTN_MIDDLE: | ||
225 | return MIDDLE; | ||
226 | case BTN_RIGHT: | ||
227 | return RIGHT; | ||
228 | case BTN_SIDE: | ||
229 | return BACK; | ||
230 | case BTN_EXTRA: | ||
231 | return FORWARD; | ||
232 | default: | ||
233 | return NONE; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) { | ||
238 | switch (axis) { | ||
239 | case WL_POINTER_AXIS_VERTICAL_SCROLL: | ||
240 | return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN; | ||
241 | case WL_POINTER_AXIS_HORIZONTAL_SCROLL: | ||
242 | return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT; | ||
243 | default: | ||
244 | wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll"); | ||
245 | return NONE; | ||
246 | } | ||
247 | } | ||
diff --git a/swaybar/render.c b/swaybar/render.c index 909b56f4..d210e25a 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -109,7 +109,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, | |||
109 | } | 109 | } |
110 | 110 | ||
111 | static void block_hotspot_callback(struct swaybar_output *output, | 111 | static void block_hotspot_callback(struct swaybar_output *output, |
112 | int x, int y, uint32_t button, void *data) { | 112 | int x, int y, enum x11_button button, void *data) { |
113 | struct i3bar_block *block = data; | 113 | struct i3bar_block *block = data; |
114 | struct status_line *status = output->bar->status; | 114 | struct status_line *status = output->bar->status; |
115 | i3bar_block_send_click(status, block, x, y, button); | 115 | i3bar_block_send_click(status, block, x, y, button); |
@@ -349,7 +349,7 @@ static const char *strip_workspace_number(const char *ws_name) { | |||
349 | } | 349 | } |
350 | 350 | ||
351 | static void workspace_hotspot_callback(struct swaybar_output *output, | 351 | static void workspace_hotspot_callback(struct swaybar_output *output, |
352 | int x, int y, uint32_t button, void *data) { | 352 | int x, int y, enum x11_button button, void *data) { |
353 | ipc_send_workspace_command(output->bar, (const char *)data); | 353 | ipc_send_workspace_command(output->bar, (const char *)data); |
354 | } | 354 | } |
355 | 355 | ||