aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 231c1ad7..5b1213a8 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 1#include <assert.h>
3#include <errno.h> 2#include <errno.h>
4#include <fcntl.h> 3#include <fcntl.h>
@@ -51,10 +50,6 @@ static void swaybar_output_free(struct swaybar_output *output) {
51 if (output->surface != NULL) { 50 if (output->surface != NULL) {
52 wl_surface_destroy(output->surface); 51 wl_surface_destroy(output->surface);
53 } 52 }
54 if (output->input_region != NULL) {
55 wl_region_destroy(output->input_region);
56 }
57 zxdg_output_v1_destroy(output->xdg_output);
58 wl_output_destroy(output->output); 53 wl_output_destroy(output->output);
59 destroy_buffer(&output->buffers[0]); 54 destroy_buffer(&output->buffers[0]);
60 destroy_buffer(&output->buffers[1]); 55 destroy_buffer(&output->buffers[1]);
@@ -90,7 +85,7 @@ static void layer_surface_closed(void *_output,
90 swaybar_output_free(output); 85 swaybar_output_free(output);
91} 86}
92 87
93struct zwlr_layer_surface_v1_listener layer_surface_listener = { 88static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
94 .configure = layer_surface_configure, 89 .configure = layer_surface_configure,
95 .closed = layer_surface_closed, 90 .closed = layer_surface_closed,
96}; 91};
@@ -114,10 +109,9 @@ static void add_layer_surface(struct swaybar_output *output) {
114 109
115 if (overlay) { 110 if (overlay) {
116 // Empty input region 111 // Empty input region
117 output->input_region = wl_compositor_create_region(bar->compositor); 112 struct wl_region *region = wl_compositor_create_region(bar->compositor);
118 assert(output->input_region); 113 wl_surface_set_input_region(output->surface, region);
119 114 wl_region_destroy(region);
120 wl_surface_set_input_region(output->surface, output->input_region);
121 } 115 }
122 116
123 zwlr_layer_surface_v1_set_anchor(output->layer_surface, config->position); 117 zwlr_layer_surface_v1_set_anchor(output->layer_surface, config->position);
@@ -172,7 +166,7 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
172 if (bar->status) { 166 if (bar->status) {
173 sway_log(SWAY_DEBUG, "Sending %s signal to status command", 167 sway_log(SWAY_DEBUG, "Sending %s signal to status command",
174 visible ? "cont" : "stop"); 168 visible ? "cont" : "stop");
175 kill(bar->status->pid, visible ? 169 kill(-bar->status->pid, visible ?
176 bar->status->cont_signal : bar->status->stop_signal); 170 bar->status->cont_signal : bar->status->stop_signal);
177 } 171 }
178 } 172 }
@@ -230,7 +224,7 @@ static void output_scale(void *data, struct wl_output *wl_output,
230 } 224 }
231} 225}
232 226
233struct wl_output_listener output_listener = { 227static const struct wl_output_listener output_listener = {
234 .geometry = output_geometry, 228 .geometry = output_geometry,
235 .mode = output_mode, 229 .mode = output_mode,
236 .done = output_done, 230 .done = output_done,
@@ -307,7 +301,7 @@ static void xdg_output_handle_description(void *data,
307 } 301 }
308} 302}
309 303
310struct zxdg_output_v1_listener xdg_output_listener = { 304static const struct zxdg_output_v1_listener xdg_output_listener = {
311 .logical_position = xdg_output_handle_logical_position, 305 .logical_position = xdg_output_handle_logical_position,
312 .logical_size = xdg_output_handle_logical_size, 306 .logical_size = xdg_output_handle_logical_size,
313 .done = xdg_output_handle_done, 307 .done = xdg_output_handle_done,
@@ -367,6 +361,9 @@ static void handle_global(void *data, struct wl_registry *registry,
367 } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) { 361 } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0) {
368 bar->xdg_output_manager = wl_registry_bind(registry, name, 362 bar->xdg_output_manager = wl_registry_bind(registry, name,
369 &zxdg_output_manager_v1_interface, 2); 363 &zxdg_output_manager_v1_interface, 2);
364 } else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
365 bar->cursor_shape_manager = wl_registry_bind(registry, name,
366 &wp_cursor_shape_manager_v1_interface, 1);
370 } 367 }
371} 368}
372 369
@@ -430,15 +427,17 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
430 // Second roundtrip for xdg-output 427 // Second roundtrip for xdg-output
431 wl_display_roundtrip(bar->display); 428 wl_display_roundtrip(bar->display);
432 429
433 struct swaybar_seat *seat; 430 if (!bar->cursor_shape_manager) {
434 wl_list_for_each(seat, &bar->seats, link) { 431 struct swaybar_seat *seat;
435 struct swaybar_pointer *pointer = &seat->pointer; 432 wl_list_for_each(seat, &bar->seats, link) {
436 if (!pointer) { 433 struct swaybar_pointer *pointer = &seat->pointer;
437 continue; 434 if (!pointer) {
435 continue;
436 }
437 pointer->cursor_surface =
438 wl_compositor_create_surface(bar->compositor);
439 assert(pointer->cursor_surface);
438 } 440 }
439 pointer->cursor_surface =
440 wl_compositor_create_surface(bar->compositor);
441 assert(pointer->cursor_surface);
442 } 441 }
443 442
444 if (bar->config->status_command) { 443 if (bar->config->status_command) {
@@ -461,13 +460,28 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
461 460
462static void display_in(int fd, short mask, void *data) { 461static void display_in(int fd, short mask, void *data) {
463 struct swaybar *bar = data; 462 struct swaybar *bar = data;
463 if (mask & (POLLHUP | POLLERR)) {
464 if (mask & POLLERR) {
465 sway_log(SWAY_ERROR, "Wayland display poll error");
466 }
467 bar->running = false;
468 return;
469 }
464 if (wl_display_dispatch(bar->display) == -1) { 470 if (wl_display_dispatch(bar->display) == -1) {
471 sway_log(SWAY_ERROR, "wl_display_dispatch failed");
465 bar->running = false; 472 bar->running = false;
466 } 473 }
467} 474}
468 475
469static void ipc_in(int fd, short mask, void *data) { 476static void ipc_in(int fd, short mask, void *data) {
470 struct swaybar *bar = data; 477 struct swaybar *bar = data;
478 if (mask & (POLLHUP | POLLERR)) {
479 if (mask & POLLERR) {
480 sway_log(SWAY_ERROR, "IPC poll error");
481 }
482 bar->running = false;
483 return;
484 }
471 if (handle_ipc_readable(bar)) { 485 if (handle_ipc_readable(bar)) {
472 set_bar_dirty(bar); 486 set_bar_dirty(bar);
473 } 487 }