aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-07-23 20:27:56 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-07-23 20:31:11 -0400
commitf4b882475eee7a81c206c7825616cc4656b2f60b (patch)
tree38e6ebf81b235424f105dcbcbb194e5e9eac70c0 /swaybar
parentImplement pid->workspace tracking (diff)
parentMerge pull request #2342 from RyanDwyer/update-cursor (diff)
downloadsway-f4b882475eee7a81c206c7825616cc4656b2f60b.tar.gz
sway-f4b882475eee7a81c206c7825616cc4656b2f60b.tar.zst
sway-f4b882475eee7a81c206c7825616cc4656b2f60b.zip
Merge branch 'master' into pid-workspaces
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c25
-rw-r--r--swaybar/i3bar.c41
-rw-r--r--swaybar/ipc.c16
-rw-r--r--swaybar/main.c8
-rw-r--r--swaybar/render.c24
-rw-r--r--swaybar/status_line.c6
6 files changed, 95 insertions, 25 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 5b8028e5..62a7727e 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -46,7 +46,7 @@ static void swaybar_output_free(struct swaybar_output *output) {
46 if (!output) { 46 if (!output) {
47 return; 47 return;
48 } 48 }
49 wlr_log(L_DEBUG, "Removing output %s", output->name); 49 wlr_log(WLR_DEBUG, "Removing output %s", output->name);
50 zwlr_layer_surface_v1_destroy(output->layer_surface); 50 zwlr_layer_surface_v1_destroy(output->layer_surface);
51 wl_surface_destroy(output->surface); 51 wl_surface_destroy(output->surface);
52 wl_output_destroy(output->output); 52 wl_output_destroy(output->output);
@@ -146,8 +146,10 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
146 && y >= hotspot->y 146 && y >= hotspot->y
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 if (HOTSPOT_IGNORE == hotspot->callback(output, pointer->x, pointer->y,
150 button, hotspot->data); 150 wl_button_to_x11_button(button), hotspot->data)) {
151 return;
152 }
151 } 153 }
152 } 154 }
153} 155}
@@ -155,11 +157,28 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer,
155static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, 157static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer,
156 uint32_t time, uint32_t axis, wl_fixed_t value) { 158 uint32_t time, uint32_t axis, wl_fixed_t value) {
157 struct swaybar *bar = data; 159 struct swaybar *bar = data;
160 struct swaybar_pointer *pointer = &bar->pointer;
158 struct swaybar_output *output = bar->pointer.current; 161 struct swaybar_output *output = bar->pointer.current;
159 if (!sway_assert(output, "axis with no active output")) { 162 if (!sway_assert(output, "axis with no active output")) {
160 return; 163 return;
161 } 164 }
162 165
166 struct swaybar_hotspot *hotspot;
167 wl_list_for_each(hotspot, &output->hotspots, link) {
168 double x = pointer->x * output->scale;
169 double y = pointer->y * output->scale;
170 if (x >= hotspot->x
171 && y >= hotspot->y
172 && x < hotspot->x + hotspot->width
173 && y < hotspot->y + hotspot->height) {
174 if (HOTSPOT_IGNORE == hotspot->callback(
175 output, pointer->x, pointer->y,
176 wl_axis_to_x11_button(axis, value), hotspot->data)) {
177 return;
178 }
179 }
180 }
181
163 double amt = wl_fixed_to_double(value); 182 double amt = wl_fixed_to_double(value);
164 if (amt == 0.0) { 183 if (amt == 0.0) {
165 return; 184 return;
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}
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 959fa095..c2d05920 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -115,6 +115,18 @@ static void ipc_parse_colors(
115 config->colors.inactive_workspace.text = parse_color( 115 config->colors.inactive_workspace.text = parse_color(
116 json_object_get_string(inactive_workspace_text)); 116 json_object_get_string(inactive_workspace_text));
117 } 117 }
118 if (urgent_workspace_border) {
119 config->colors.urgent_workspace.border = parse_color(
120 json_object_get_string(urgent_workspace_border));
121 }
122 if (urgent_workspace_bg) {
123 config->colors.urgent_workspace.background = parse_color(
124 json_object_get_string(urgent_workspace_bg));
125 }
126 if (urgent_workspace_text) {
127 config->colors.urgent_workspace.text = parse_color(
128 json_object_get_string(urgent_workspace_text));
129 }
118 if (binding_mode_border) { 130 if (binding_mode_border) {
119 config->colors.binding_mode.border = parse_color( 131 config->colors.binding_mode.border = parse_color(
120 json_object_get_string(binding_mode_border)); 132 json_object_get_string(binding_mode_border));
@@ -327,7 +339,7 @@ bool handle_ipc_readable(struct swaybar *bar) {
327 json_object *result = json_tokener_parse(resp->payload); 339 json_object *result = json_tokener_parse(resp->payload);
328 if (!result) { 340 if (!result) {
329 free_ipc_response(resp); 341 free_ipc_response(resp);
330 wlr_log(L_ERROR, "failed to parse payload as json"); 342 wlr_log(WLR_ERROR, "failed to parse payload as json");
331 return false; 343 return false;
332 } 344 }
333 json_object *json_change, *json_pango_markup; 345 json_object *json_change, *json_pango_markup;
@@ -340,7 +352,7 @@ bool handle_ipc_readable(struct swaybar *bar) {
340 bar->config->mode = strdup(change); 352 bar->config->mode = strdup(change);
341 } 353 }
342 } else { 354 } else {
343 wlr_log(L_ERROR, "failed to parse response"); 355 wlr_log(WLR_ERROR, "failed to parse response");
344 json_object_put(result); 356 json_object_put(result);
345 free_ipc_response(resp); 357 free_ipc_response(resp);
346 return false; 358 return false;
diff --git a/swaybar/main.c b/swaybar/main.c
index c897e1c9..60e4b37c 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -75,13 +75,13 @@ int main(int argc, char **argv) {
75 } 75 }
76 76
77 if (debug) { 77 if (debug) {
78 wlr_log_init(L_DEBUG, NULL); 78 wlr_log_init(WLR_DEBUG, NULL);
79 } else { 79 } else {
80 wlr_log_init(L_ERROR, NULL); 80 wlr_log_init(WLR_ERROR, NULL);
81 } 81 }
82 82
83 if (!bar_id) { 83 if (!bar_id) {
84 wlr_log(L_ERROR, "No bar_id passed. " 84 wlr_log(WLR_ERROR, "No bar_id passed. "
85 "Provide --bar_id or let sway start swaybar"); 85 "Provide --bar_id or let sway start swaybar");
86 return 1; 86 return 1;
87 } 87 }
@@ -89,7 +89,7 @@ int main(int argc, char **argv) {
89 if (!socket_path) { 89 if (!socket_path) {
90 socket_path = get_socketpath(); 90 socket_path = get_socketpath();
91 if (!socket_path) { 91 if (!socket_path) {
92 wlr_log(L_ERROR, "Unable to retrieve socket path"); 92 wlr_log(WLR_ERROR, "Unable to retrieve socket path");
93 return 1; 93 return 1;
94 } 94 }
95 } 95 }
diff --git a/swaybar/render.c b/swaybar/render.c
index 327a6f5f..6f370077 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -108,11 +108,11 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color,
108 } 108 }
109} 109}
110 110
111static void block_hotspot_callback(struct swaybar_output *output, 111static enum hotspot_event_handling 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 return i3bar_block_send_click(status, block, x, y, button);
116} 116}
117 117
118static uint32_t render_status_block(cairo_t *cairo, 118static uint32_t render_status_block(cairo_t *cairo,
@@ -298,7 +298,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
298 298
299 int text_width, text_height; 299 int text_width, text_height;
300 get_text_size(cairo, config->font, &text_width, &text_height, 300 get_text_size(cairo, config->font, &text_width, &text_height,
301 output->scale, config->pango_markup, "%s", mode); 301 output->scale, config->mode_pango_markup,
302 "%s", mode);
302 303
303 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 304 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
304 int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; 305 int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale;
@@ -329,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
329 double text_y = height / 2.0 - text_height / 2.0; 330 double text_y = height / 2.0 - text_height / 2.0;
330 cairo_set_source_u32(cairo, config->colors.binding_mode.text); 331 cairo_set_source_u32(cairo, config->colors.binding_mode.text);
331 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); 332 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
332 pango_printf(cairo, config->font, output->scale, config->pango_markup, 333 pango_printf(cairo, config->font, output->scale, config->mode_pango_markup,
333 "%s", mode); 334 "%s", mode);
334 return surface_height; 335 return surface_height;
335} 336}
@@ -347,9 +348,13 @@ static const char *strip_workspace_number(const char *ws_name) {
347 return ws_name; 348 return ws_name;
348} 349}
349 350
350static void workspace_hotspot_callback(struct swaybar_output *output, 351static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output,
351 int x, int y, uint32_t button, void *data) { 352 int x, int y, enum x11_button button, void *data) {
353 if (button != LEFT) {
354 return HOTSPOT_PROCESS;
355 }
352 ipc_send_workspace_command(output->bar, (const char *)data); 356 ipc_send_workspace_command(output->bar, (const char *)data);
357 return HOTSPOT_IGNORE;
353} 358}
354 359
355static uint32_t render_workspace_button(cairo_t *cairo, 360static uint32_t render_workspace_button(cairo_t *cairo,
@@ -496,12 +501,15 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
496 // different height than what we asked for 501 // different height than what we asked for
497 wl_surface_commit(output->surface); 502 wl_surface_commit(output->surface);
498 wl_display_roundtrip(bar->display); 503 wl_display_roundtrip(bar->display);
499 } else { 504 } else if (height > 0) {
500 // Replay recording into shm and send it off 505 // Replay recording into shm and send it off
501 output->current_buffer = get_next_buffer(bar->shm, 506 output->current_buffer = get_next_buffer(bar->shm,
502 output->buffers, 507 output->buffers,
503 output->width * output->scale, 508 output->width * output->scale,
504 output->height * output->scale); 509 output->height * output->scale);
510 if (!output->current_buffer) {
511 return;
512 }
505 cairo_t *shm = output->current_buffer->cairo; 513 cairo_t *shm = output->current_buffer->cairo;
506 514
507 cairo_save(shm); 515 cairo_save(shm);
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index e0e7414a..bc47580b 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -49,14 +49,14 @@ bool status_handle_readable(struct status_line *status) {
49 json_object *version; 49 json_object *version;
50 if (json_object_object_get_ex(proto, "version", &version) 50 if (json_object_object_get_ex(proto, "version", &version)
51 && json_object_get_int(version) == 1) { 51 && json_object_get_int(version) == 1) {
52 wlr_log(L_DEBUG, "Switched to i3bar protocol."); 52 wlr_log(WLR_DEBUG, "Switched to i3bar protocol.");
53 status->protocol = PROTOCOL_I3BAR; 53 status->protocol = PROTOCOL_I3BAR;
54 } 54 }
55 json_object *click_events; 55 json_object *click_events;
56 if (json_object_object_get_ex( 56 if (json_object_object_get_ex(
57 proto, "click_events", &click_events) 57 proto, "click_events", &click_events)
58 && json_object_get_boolean(click_events)) { 58 && json_object_get_boolean(click_events)) {
59 wlr_log(L_DEBUG, "Enabled click events."); 59 wlr_log(WLR_DEBUG, "Enabled click events.");
60 status->i3bar_state.click_events = true; 60 status->i3bar_state.click_events = true;
61 const char *events_array = "[\n"; 61 const char *events_array = "[\n";
62 ssize_t len = strlen(events_array); 62 ssize_t len = strlen(events_array);
@@ -91,7 +91,7 @@ struct status_line *status_line_init(char *cmd) {
91 int pipe_read_fd[2]; 91 int pipe_read_fd[2];
92 int pipe_write_fd[2]; 92 int pipe_write_fd[2];
93 if (pipe(pipe_read_fd) != 0 || pipe(pipe_write_fd) != 0) { 93 if (pipe(pipe_read_fd) != 0 || pipe(pipe_write_fd) != 0) {
94 wlr_log(L_ERROR, "Unable to create pipes for status_command fork"); 94 wlr_log(WLR_ERROR, "Unable to create pipes for status_command fork");
95 exit(1); 95 exit(1);
96 } 96 }
97 97