aboutsummaryrefslogtreecommitdiff
path: root/swaybar/bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c82
1 files changed, 51 insertions, 31 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index d80c9af3..6d2872c3 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
@@ -17,11 +18,7 @@
static void bar_init(struct bar *bar) {
bar->config = init_config();
bar->status = init_status_line();
- bar->output = malloc(sizeof(struct output));
- bar->output->window = NULL;
- bar->output->registry = NULL;
- bar->output->workspaces = create_list();
- bar->output->name = NULL;
+ bar->outputs = create_list();
}
static void spawn_status_cmd_proc(struct bar *bar) {
@@ -49,38 +46,50 @@ static void spawn_status_cmd_proc(struct bar *bar) {
}
}
+struct output *new_output(const char *name) {
+ struct output *output = malloc(sizeof(struct output));
+ output->name = strdup(name);
+ output->window = NULL;
+ output->registry = NULL;
+ output->workspaces = create_list();
+ return output;
+}
-void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id, int desired_output) {
+void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
/* initialize bar with default values */
bar_init(bar);
- bar->output->registry = registry_poll();
-
- if (!bar->output->registry->desktop_shell) {
- sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
- }
-
/* connect to sway ipc */
bar->ipc_socketfd = ipc_open_socket(socket_path);
bar->ipc_event_socketfd = ipc_open_socket(socket_path);
- ipc_bar_init(bar, desired_output, bar_id);
+ ipc_bar_init(bar, bar_id);
- struct output_state *output = bar->output->registry->outputs->items[desired_output];
+ int i;
+ for (i = 0; i < bar->outputs->length; ++i) {
+ struct output *bar_output = bar->outputs->items[i];
- bar->output->window = window_setup(bar->output->registry, output->width, 30, false);
- if (!bar->output->window) {
- sway_abort("Failed to create window.");
- }
- desktop_shell_set_panel(bar->output->registry->desktop_shell, output->output, bar->output->window->surface);
- desktop_shell_set_panel_position(bar->output->registry->desktop_shell, bar->config->position);
+ bar_output->registry = registry_poll();
- /* set font */
- bar->output->window->font = bar->config->font;
+ if (!bar_output->registry->desktop_shell) {
+ sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
+ }
- /* set window height */
- set_window_height(bar->output->window, bar->config->height);
+ struct output_state *output = bar_output->registry->outputs->items[bar_output->idx];
+ bar_output->window = window_setup(bar_output->registry, output->width, 30, false);
+ if (!bar_output->window) {
+ sway_abort("Failed to create window.");
+ }
+ desktop_shell_set_panel(bar_output->registry->desktop_shell, output->output, bar_output->window->surface);
+ desktop_shell_set_panel_position(bar_output->registry->desktop_shell, bar->config->position);
+
+ /* set font */
+ bar_output->window->font = bar->config->font;
+
+ /* set window height */
+ set_window_height(bar_output->window, bar->config->height);
+ }
/* spawn status command */
spawn_status_cmd_proc(bar);
}
@@ -92,12 +101,15 @@ void bar_run(struct bar *bar) {
while (1) {
if (dirty) {
- struct output *output = bar->output;
- if (window_prerender(output->window) && output->window->cairo) {
- render(output, bar->config, bar->status);
- window_render(output->window);
- if (wl_display_dispatch(output->registry->display) == -1) {
- break;
+ int i;
+ for (i = 0; i < bar->outputs->length; ++i) {
+ struct output *output = bar->outputs->items[i];
+ if (window_prerender(output->window) && output->window->cairo) {
+ render(output, bar->config, bar->status);
+ window_render(output->window);
+ if (wl_display_dispatch(output->registry->display) == -1) {
+ break;
+ }
}
}
}
@@ -149,6 +161,14 @@ static void free_output(struct output *output) {
free(output);
}
+static void free_outputs(list_t *outputs) {
+ int i;
+ for (i = 0; i < outputs->length; ++i) {
+ free_output(outputs->items[i]);
+ }
+ list_free(outputs);
+}
+
static void terminate_status_command(pid_t pid) {
if (pid) {
// terminate status_command process
@@ -164,7 +184,7 @@ static void terminate_status_command(pid_t pid) {
void bar_teardown(struct bar *bar) {
free_config(bar->config);
- free_output(bar->output);
+ free_outputs(bar->outputs);
free_status_line(bar->status);
/* close sockets/pipes */