aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/i3bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/i3bar.c')
-rw-r--r--swaybar/i3bar.c41
1 files changed, 36 insertions, 5 deletions
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index 141612a6..ae37eeb9 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>
@@ -31,7 +32,7 @@ static bool i3bar_parse_json(struct status_line *status, const char *text) {
31 status_error(status, "[failed to parse i3bar json]"); 32 status_error(status, "[failed to parse i3bar json]");
32 return false; 33 return false;
33 } 34 }
34 wlr_log(L_DEBUG, "Got i3bar json: '%s'", text); 35 wlr_log(WLR_DEBUG, "Got i3bar json: '%s'", text);
35 for (size_t i = 0; i < json_object_array_length(results); ++i) { 36 for (size_t i = 0; i < json_object_array_length(results); ++i) {
36 json_object *full_text, *short_text, *color, *min_width, *align, *urgent; 37 json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
37 json_object *name, *instance, *separator, *separator_block_width; 38 json_object *name, *instance, *separator, *separator_block_width;
@@ -191,11 +192,11 @@ bool i3bar_handle_readable(struct status_line *status) {
191 return redraw; 192 return redraw;
192} 193}
193 194
194void i3bar_block_send_click(struct status_line *status, 195enum hotspot_event_handling 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(L_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 HOTSPOT_PROCESS;
199 } 200 }
200 201
201 struct json_object *event_json = json_object_new_object(); 202 struct json_object *event_json = json_object_new_object();
@@ -214,4 +215,34 @@ void i3bar_block_send_click(struct status_line *status,
214 status_error(status, "[failed to write click event]"); 215 status_error(status, "[failed to write click event]");
215 } 216 }
216 json_object_put(event_json); 217 json_object_put(event_json);
218 return HOTSPOT_IGNORE;
219}
220
221enum x11_button wl_button_to_x11_button(uint32_t button) {
222 switch (button) {
223 case BTN_LEFT:
224 return LEFT;
225 case BTN_MIDDLE:
226 return MIDDLE;
227 case BTN_RIGHT:
228 return RIGHT;
229 case BTN_SIDE:
230 return BACK;
231 case BTN_EXTRA:
232 return FORWARD;
233 default:
234 return NONE;
235 }
236}
237
238enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
239 switch (axis) {
240 case WL_POINTER_AXIS_VERTICAL_SCROLL:
241 return wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
242 case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
243 return wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
244 default:
245 wlr_log(WLR_DEBUG, "Unexpected axis value on mouse scroll");
246 return NONE;
247 }
217} 248}