aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c55
1 files changed, 31 insertions, 24 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index ab307fd4..388c24c4 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -16,12 +16,13 @@
16#else 16#else
17#include <linux/input-event-codes.h> 17#include <linux/input-event-codes.h>
18#endif 18#endif
19#include "swaybar/render.h" 19#include "swaybar/bar.h"
20#include "swaybar/config.h" 20#include "swaybar/config.h"
21#include "swaybar/event_loop.h" 21#include "swaybar/event_loop.h"
22#include "swaybar/status_line.h" 22#include "swaybar/i3bar.h"
23#include "swaybar/bar.h"
24#include "swaybar/ipc.h" 23#include "swaybar/ipc.h"
24#include "swaybar/status_line.h"
25#include "swaybar/render.h"
25#include "ipc-client.h" 26#include "ipc-client.h"
26#include "list.h" 27#include "list.h"
27#include "log.h" 28#include "log.h"
@@ -71,6 +72,16 @@ static void swaybar_output_free(struct swaybar_output *output) {
71 free(output); 72 free(output);
72} 73}
73 74
75static void set_output_dirty(struct swaybar_output *output) {
76 if (output->frame_scheduled) {
77 output->dirty = true;
78 return;
79 }
80 if (output->surface) {
81 render_frame(output);
82 }
83}
84
74static void layer_surface_configure(void *data, 85static void layer_surface_configure(void *data,
75 struct zwlr_layer_surface_v1 *surface, 86 struct zwlr_layer_surface_v1 *surface,
76 uint32_t serial, uint32_t width, uint32_t height) { 87 uint32_t serial, uint32_t width, uint32_t height) {
@@ -78,7 +89,7 @@ static void layer_surface_configure(void *data,
78 output->width = width; 89 output->width = width;
79 output->height = height; 90 output->height = height;
80 zwlr_layer_surface_v1_ack_configure(surface, serial); 91 zwlr_layer_surface_v1_ack_configure(surface, serial);
81 render_frame(output->bar, output); 92 set_output_dirty(output);
82} 93}
83 94
84static void layer_surface_closed(void *_output, 95static void layer_surface_closed(void *_output,
@@ -324,27 +335,22 @@ static void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
324 const char *make, const char *model, int32_t transform) { 335 const char *make, const char *model, int32_t transform) {
325 struct swaybar_output *output = data; 336 struct swaybar_output *output = data;
326 output->subpixel = subpixel; 337 output->subpixel = subpixel;
327 if (output->surface) {
328 render_frame(output->bar, output);
329 }
330} 338}
331 339
332static void output_mode(void *data, struct wl_output *output, uint32_t flags, 340static void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
333 int32_t width, int32_t height, int32_t refresh) { 341 int32_t width, int32_t height, int32_t refresh) {
334 // Who cares 342 // Who cares
335} 343}
336 344
337static void output_done(void *data, struct wl_output *output) { 345static void output_done(void *data, struct wl_output *wl_output) {
338 // Who cares 346 struct swaybar_output *output = data;
347 set_output_dirty(output);
339} 348}
340 349
341static void output_scale(void *data, struct wl_output *wl_output, 350static void output_scale(void *data, struct wl_output *wl_output,
342 int32_t factor) { 351 int32_t factor) {
343 struct swaybar_output *output = data; 352 struct swaybar_output *output = data;
344 output->scale = factor; 353 output->scale = factor;
345 if (output->surface) {
346 render_frame(output->bar, output);
347 }
348} 354}
349 355
350struct wl_output_listener output_listener = { 356struct wl_output_listener output_listener = {
@@ -380,7 +386,7 @@ static void xdg_output_handle_done(void *data,
380 wl_list_insert(&bar->outputs, &output->link); 386 wl_list_insert(&bar->outputs, &output->link);
381 387
382 add_layer_surface(output); 388 add_layer_surface(output);
383 render_frame(bar, output); 389 set_output_dirty(output);
384 } 390 }
385} 391}
386 392
@@ -469,23 +475,23 @@ static const struct wl_registry_listener registry_listener = {
469 .global_remove = handle_global_remove, 475 .global_remove = handle_global_remove,
470}; 476};
471 477
472static void render_all_frames(struct swaybar *bar) { 478static void set_bar_dirty(struct swaybar *bar) {
473 struct swaybar_output *output; 479 struct swaybar_output *output;
474 wl_list_for_each(output, &bar->outputs, link) { 480 wl_list_for_each(output, &bar->outputs, link) {
475 if (output->surface != NULL) { 481 set_output_dirty(output);
476 render_frame(bar, output);
477 }
478 } 482 }
479} 483}
480 484
481void bar_setup(struct swaybar *bar, 485bool bar_setup(struct swaybar *bar,
482 const char *socket_path, const char *bar_id) { 486 const char *socket_path, const char *bar_id) {
483 bar_init(bar); 487 bar_init(bar);
484 init_event_loop(); 488 init_event_loop();
485 489
486 bar->ipc_socketfd = ipc_open_socket(socket_path); 490 bar->ipc_socketfd = ipc_open_socket(socket_path);
487 bar->ipc_event_socketfd = ipc_open_socket(socket_path); 491 bar->ipc_event_socketfd = ipc_open_socket(socket_path);
488 ipc_initialize(bar, bar_id); 492 if (!ipc_initialize(bar, bar_id)) {
493 return false;
494 }
489 if (bar->config->status_command) { 495 if (bar->config->status_command) {
490 bar->status = status_line_init(bar->config->status_command); 496 bar->status = status_line_init(bar->config->status_command);
491 } 497 }
@@ -525,7 +531,8 @@ void bar_setup(struct swaybar *bar,
525 assert(pointer->cursor_surface); 531 assert(pointer->cursor_surface);
526 532
527 ipc_get_workspaces(bar); 533 ipc_get_workspaces(bar);
528 render_all_frames(bar); 534 set_bar_dirty(bar);
535 return true;
529} 536}
530 537
531static void display_in(int fd, short mask, void *data) { 538static void display_in(int fd, short mask, void *data) {
@@ -539,7 +546,7 @@ static void display_in(int fd, short mask, void *data) {
539static void ipc_in(int fd, short mask, void *data) { 546static void ipc_in(int fd, short mask, void *data) {
540 struct swaybar *bar = data; 547 struct swaybar *bar = data;
541 if (handle_ipc_readable(bar)) { 548 if (handle_ipc_readable(bar)) {
542 render_all_frames(bar); 549 set_bar_dirty(bar);
543 } 550 }
544} 551}
545 552
@@ -547,10 +554,10 @@ static void status_in(int fd, short mask, void *data) {
547 struct swaybar *bar = data; 554 struct swaybar *bar = data;
548 if (mask & (POLLHUP | POLLERR)) { 555 if (mask & (POLLHUP | POLLERR)) {
549 status_error(bar->status, "[error reading from status command]"); 556 status_error(bar->status, "[error reading from status command]");
550 render_all_frames(bar); 557 set_bar_dirty(bar);
551 remove_event(fd); 558 remove_event(fd);
552 } else if (status_handle_readable(bar->status)) { 559 } else if (status_handle_readable(bar->status)) {
553 render_all_frames(bar); 560 set_bar_dirty(bar);
554 } 561 }
555} 562}
556 563