aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/meson.build3
-rw-r--r--common/pango.c67
-rw-r--r--include/pango.h16
-rw-r--r--include/sway/config.h7
-rw-r--r--include/swaybar/bar.h89
-rw-r--r--include/swaybar/config.h43
-rw-r--r--include/swaybar/event_loop.h4
-rw-r--r--include/swaybar/ipc.h22
-rw-r--r--include/swaybar/render.h22
-rw-r--r--meson.build3
-rw-r--r--swaybar/bar.c444
-rw-r--r--swaybar/config.c37
-rw-r--r--swaybar/event_loop.c10
-rw-r--r--swaybar/ipc.c410
-rw-r--r--swaybar/main.c33
-rw-r--r--swaybar/meson.build25
-rw-r--r--swaybar/render.c388
-rw-r--r--swaybar/status_line.c530
-rw-r--r--swaybar/tray/dbus.c197
-rw-r--r--swaybar/tray/icon.c400
-rw-r--r--swaybar/tray/sni.c481
-rw-r--r--swaybar/tray/sni_watcher.c497
-rw-r--r--swaybar/tray/tray.c398
23 files changed, 342 insertions, 3784 deletions
diff --git a/common/meson.build b/common/meson.build
index 01736ca6..4ad47077 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -1,5 +1,7 @@
deps = [
cairo,
+ pango,
+ pangocairo,
wlroots
]
@@ -14,6 +16,7 @@ lib_sway_common = static_library(
'ipc-client.c',
'log.c',
'list.c',
+ 'pango.c',
'readline.c',
'stringop.c',
'util.c'
diff --git a/common/pango.c b/common/pango.c
new file mode 100644
index 00000000..212d96cf
--- /dev/null
+++ b/common/pango.c
@@ -0,0 +1,67 @@
+#include <cairo/cairo.h>
+#include <pango/pangocairo.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
+ const char *text, int32_t scale, bool markup) {
+ PangoLayout *layout = pango_cairo_create_layout(cairo);
+ PangoAttrList *attrs;
+ if (markup) {
+ char *buf;
+ pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, NULL);
+ pango_layout_set_markup(layout, buf, -1);
+ free(buf);
+ } else {
+ attrs = pango_attr_list_new();
+ pango_layout_set_text(layout, text, -1);
+ }
+ pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
+ PangoFontDescription *desc = pango_font_description_from_string(font);
+ pango_layout_set_font_description(layout, desc);
+ pango_layout_set_single_paragraph_mode(layout, 1);
+ pango_layout_set_attributes(layout, attrs);
+ pango_attr_list_unref(attrs);
+ pango_font_description_free(desc);
+ return layout;
+}
+
+void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
+ int32_t scale, bool markup, const char *fmt, ...) {
+ char *buf = malloc(2048);
+
+ va_list args;
+ va_start(args, fmt);
+ if (vsnprintf(buf, 2048, fmt, args) >= 2048) {
+ strcpy(buf, "[buffer overflow]");
+ }
+ va_end(args);
+
+ PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
+ pango_cairo_update_layout(cairo, layout);
+ pango_layout_get_pixel_size(layout, width, height);
+ g_object_unref(layout);
+ free(buf);
+}
+
+void pango_printf(cairo_t *cairo, const char *font,
+ int32_t scale, bool markup, const char *fmt, ...) {
+ char *buf = malloc(2048);
+
+ va_list args;
+ va_start(args, fmt);
+ if (vsnprintf(buf, 2048, fmt, args) >= 2048) {
+ strcpy(buf, "[buffer overflow]");
+ }
+ va_end(args);
+
+ PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
+ pango_cairo_update_layout(cairo, layout);
+ pango_cairo_show_layout(cairo, layout);
+ g_object_unref(layout);
+ free(buf);
+}
diff --git a/include/pango.h b/include/pango.h
new file mode 100644
index 00000000..f6325f28
--- /dev/null
+++ b/include/pango.h
@@ -0,0 +1,16 @@
+#ifndef _SWAY_PANGO_H
+#define _SWAY_PANGO_H
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <cairo/cairo.h>
+#include <pango/pangocairo.h>
+
+PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
+ const char *text, int32_t scale, bool markup);
+void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
+ int32_t scale, bool markup, const char *fmt, ...);
+void pango_printf(cairo_t *cairo, const char *font,
+ int32_t scale, bool markup, const char *fmt, ...);
+
+#endif
diff --git a/include/sway/config.h b/include/sway/config.h
index 48a8b0ab..8c9e04de 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -1,17 +1,16 @@
#ifndef _SWAY_CONFIG_H
#define _SWAY_CONFIG_H
-
#define PID_WORKSPACE_TIMEOUT 60
-
#include <libinput.h>
#include <stdint.h>
#include <string.h>
+#include <time.h>
#include <wlr/types/wlr_box.h>
#include <xkbcommon/xkbcommon.h>
-#include <time.h>
#include "list.h"
#include "layout.h"
#include "container.h"
+#include "wlr-layer-shell-unstable-v1-protocol.h"
/**
* Describes a variable created via the `set` command.
@@ -152,7 +151,7 @@ struct bar_config {
char *id;
uint32_t modifier;
list_t *outputs;
- //enum desktop_shell_panel_position position; // TODO
+ char *position;
list_t *bindings;
char *status_command;
bool pango_markup;
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 50d36e76..3ae8c0b3 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -1,72 +1,45 @@
#ifndef _SWAYBAR_BAR_H
#define _SWAYBAR_BAR_H
-
-#include "client/registry.h"
-#include "client/window.h"
+#include <wayland-client.h>
+#include "pool-buffer.h"
#include "list.h"
-struct bar {
- struct config *config;
- struct status_line *status;
- list_t *outputs;
- struct output *focused_output;
+struct swaybar_config;
+struct swaybar_output;
+struct swaybar_workspace;
+
+struct swaybar {
+ struct wl_display *display;
+ struct wl_compositor *compositor;
+ struct zwlr_layer_shell_v1 *layer_shell;
+ struct wl_shm *shm;
- int ipc_event_socketfd;
- int ipc_socketfd;
- int status_read_fd;
- int status_write_fd;
- pid_t status_command_pid;
+ struct swaybar_config *config;
+ struct swaybar_output *focused_output;
+
+ struct wl_list outputs;
};
-struct output {
- struct window *window;
- struct registry *registry;
- list_t *workspaces;
-#ifdef ENABLE_TRAY
- list_t *items;
-#endif
+struct swaybar_output {
+ struct wl_list link;
+ struct swaybar *bar;
+ struct wl_output *output;
+ struct wl_surface *surface;
+ struct zwlr_layer_surface_v1 *layer_surface;
+
char *name;
int idx;
bool focused;
-};
-struct workspace {
- int num;
- char *name;
- bool focused;
- bool visible;
- bool urgent;
+ uint32_t width, height;
+ struct pool_buffer buffers[2];
+ struct pool_buffer *current_buffer;
};
-/** Global bar state */
-extern struct bar swaybar;
+void bar_setup(struct swaybar *bar,
+ const char *socket_path,
+ const char *bar_id);
+void bar_run(struct swaybar *bar);
+void bar_teardown(struct swaybar *bar);
-/** True if sway needs to render */
-extern bool dirty;
-
-/**
- * Setup bar.
- */
-void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id);
-
-/**
- * Create new output struct from name.
- */
-struct output *new_output(const char *name);
-
-/**
- * Bar mainloop.
- */
-void bar_run(struct bar *bar);
-
-/**
- * free workspace list.
- */
-void free_workspaces(list_t *workspaces);
-
-/**
- * Teardown bar.
- */
-void bar_teardown(struct bar *bar);
-
-#endif /* _SWAYBAR_BAR_H */
+#endif
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index 651f0ee3..1bfe4843 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -1,9 +1,7 @@
#ifndef _SWAYBAR_CONFIG_H
#define _SWAYBAR_CONFIG_H
-
-#include <stdint.h>
#include <stdbool.h>
-
+#include <stdint.h>
#include "list.h"
#include "util.h"
@@ -19,10 +17,10 @@ struct box_colors {
/**
* Swaybar config.
*/
-struct config {
+struct swaybar_config {
char *status_command;
bool pango_markup;
- uint32_t position;
+ uint32_t position; // zwlr_layer_surface_v1_anchor
char *font;
char *sep_symbol;
char *mode;
@@ -32,18 +30,6 @@ struct config {
bool workspace_buttons;
bool all_outputs;
list_t *outputs;
-
-#ifdef ENABLE_TRAY
- // Tray
- char *tray_output;
- char *icon_theme;
-
- uint32_t tray_padding;
- uint32_t activate_button;
- uint32_t context_button;
- uint32_t secondary_button;
-#endif
-
int height;
struct {
@@ -63,24 +49,7 @@ struct config {
} colors;
};
-/**
- * Parse position top|bottom|left|right.
- */
-uint32_t parse_position(const char *position);
-
-/**
- * Parse font.
- */
-char *parse_font(const char *font);
-
-/**
- * Initialize default sway config.
- */
-struct config *init_config();
-
-/**
- * Free config struct.
- */
-void free_config(struct config *config);
+struct swaybar_config *init_config();
+void free_config(struct swaybar_config *config);
-#endif /* _SWAYBAR_CONFIG_H */
+#endif
diff --git a/include/swaybar/event_loop.h b/include/swaybar/event_loop.h
index a0cde07f..99f6ed36 100644
--- a/include/swaybar/event_loop.h
+++ b/include/swaybar/event_loop.h
@@ -1,6 +1,5 @@
#ifndef _SWAYBAR_EVENT_LOOP_H
#define _SWAYBAR_EVENT_LOOP_H
-
#include <stdbool.h>
#include <time.h>
@@ -23,4 +22,5 @@ bool remove_timer(timer_t timer);
void event_loop_poll();
void init_event_loop();
-#endif /*_SWAYBAR_EVENT_LOOP_H */
+
+#endif
diff --git a/include/swaybar/ipc.h b/include/swaybar/ipc.h
index c11931d0..57a1b925 100644
--- a/include/swaybar/ipc.h
+++ b/include/swaybar/ipc.h
@@ -1,23 +1,9 @@
#ifndef _SWAYBAR_IPC_H
#define _SWAYBAR_IPC_H
+#include "swaybar/bar.h"
-#include "bar.h"
-
-/**
- * Initialize ipc connection to sway and get sway state, outputs, bar_config.
- */
-void ipc_bar_init(struct bar *bar, const char *bar_id);
-
-/**
- * Handle ipc event from sway.
- */
-bool handle_ipc_event(struct bar *bar);
-
-
-/**
- * Send workspace command to sway
- */
+void ipc_bar_init(struct swaybar *bar, const char *bar_id);
+bool handle_ipc_event(struct swaybar *bar);
void ipc_send_workspace_command(const char *workspace_name);
-#endif /* _SWAYBAR_IPC_H */
-
+#endif
diff --git a/include/swaybar/render.h b/include/swaybar/render.h
index 114f43f4..071e2298 100644
--- a/include/swaybar/render.h
+++ b/include/swaybar/render.h
@@ -1,22 +1,10 @@
#ifndef _SWAYBAR_RENDER_H
#define _SWAYBAR_RENDER_H
-#include "config.h"
-#include "bar.h"
+struct swaybar;
+struct swaybar_output;
+struct swaybar_config;
-/**
- * Render swaybar.
- */
-void render(struct output *output, struct config *config, struct status_line *line);
+void render_frame(struct swaybar *bar, struct swaybar_output *output);
-/**
- * Set window height and modify internal spacing accordingly.
- */
-void set_window_height(struct window *window, int height);
-
-/**
- * Compute the size of a workspace name
- */
-void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height);
-
-#endif /* _SWAYBAR_RENDER_H */
+#endif
diff --git a/meson.build b/meson.build
index b681f43a..49824b30 100644
--- a/meson.build
+++ b/meson.build
@@ -35,6 +35,7 @@ pixman = dependency('pixman-1')
libcap = dependency('libcap')
libinput = dependency('libinput')
math = cc.find_library('m')
+rt = cc.find_library('rt')
git = find_program('git', required: false)
a2x = find_program('a2x', required: false)
@@ -99,8 +100,10 @@ subdir('protocols')
subdir('common')
subdir('sway')
subdir('swaymsg')
+
subdir('client')
subdir('swaybg')
+subdir('swaybar')
config = configuration_data()
config.set('sysconfdir', join_paths(prefix, sysconfdir))
diff --git a/swaybar/bar.c b/swaybar/bar.c
index f12923a8..e1d594b4 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -1,390 +1,146 @@
#define _XOPEN_SOURCE 500
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <signal.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
#include <sys/wait.h>
-#include <signal.h>
-#include <poll.h>
-#ifdef __FreeBSD__
-#include <dev/evdev/input-event-codes.h>
-#else
-#include <linux/input-event-codes.h>
-#endif
-#ifdef ENABLE_TRAY
-#include <dbus/dbus.h>
-#include "swaybar/tray/sni_watcher.h"
-#include "swaybar/tray/tray.h"
-#include "swaybar/tray/sni.h"
-#endif
-#include "swaybar/ipc.h"
+#include <unistd.h>
+#include <wayland-client.h>
+#include <wlr/util/log.h>
#include "swaybar/render.h"
#include "swaybar/config.h"
-#include "swaybar/status_line.h"
#include "swaybar/event_loop.h"
#include "swaybar/bar.h"
-#include "ipc-client.h"
#include "list.h"
-#include "log.h"
+#include "pango.h"
+#include "pool-buffer.h"
+#include "wlr-layer-shell-unstable-v1-client-protocol.h"
-static void bar_init(struct bar *bar) {
+static void bar_init(struct swaybar *bar) {
bar->config = init_config();
- bar->status = init_status_line();
- bar->outputs = create_list();
+ wl_list_init(&bar->outputs);
}
-static void spawn_status_cmd_proc(struct bar *bar) {
- if (bar->config->status_command) {
- int pipe_read_fd[2];
- int pipe_write_fd[2];
-
- if (pipe(pipe_read_fd) != 0) {
- sway_log(L_ERROR, "Unable to create pipes for status_command fork");
- return;
- }
- if (pipe(pipe_write_fd) != 0) {
- sway_log(L_ERROR, "Unable to create pipe for status_command fork (write)");
- close(pipe_read_fd[0]);
- close(pipe_read_fd[1]);
- return;
- }
-
- bar->status_command_pid = fork();
- if (bar->status_command_pid == 0) {
- close(pipe_read_fd[0]);
- dup2(pipe_read_fd[1], STDOUT_FILENO);
- close(pipe_read_fd[1]);
-
- dup2(pipe_write_fd[0], STDIN_FILENO);
- close(pipe_write_fd[0]);
- close(pipe_write_fd[1]);
-
- char *const cmd[] = {
- "sh",
- "-c",
- bar->config->status_command,
- NULL,
- };
- execvp(cmd[0], cmd);
- return;
- }
-
- close(pipe_read_fd[1]);
- bar->status_read_fd = pipe_read_fd[0];
- fcntl(bar->status_read_fd, F_SETFL, O_NONBLOCK);
-
- close(pipe_write_fd[0]);
- bar->status_write_fd = pipe_write_fd[1];
- fcntl(bar->status_write_fd, F_SETFL, O_NONBLOCK);
- }
-}
-
-struct output *new_output(const char *name) {
- struct output *output = malloc(sizeof(struct output));
+struct swaybar_output *new_output(const char *name) {
+ struct swaybar_output *output = malloc(sizeof(struct swaybar_output));
output->name = strdup(name);
- output->window = NULL;
- output->registry = NULL;
- output->workspaces = create_list();
-#ifdef ENABLE_TRAY
- output->items = create_list();
-#endif
return output;
}
-static void mouse_button_notify(struct window *window, int x, int y,
- uint32_t button, uint32_t state_w) {
- sway_log(L_DEBUG, "Mouse button %d clicked at %d %d %d", button, x, y, state_w);
- if (!state_w) {
- return;
- }
-
- struct output *clicked_output = NULL;
- for (int i = 0; i < swaybar.outputs->length; i++) {
- struct output *output = swaybar.outputs->items[i];
- if (window == output->window) {
- clicked_output = output;
- break;
- }
- }
-
- if (!sway_assert(clicked_output != NULL, "Got pointer event for non-existing output")) {
- return;
- }
-
- double button_x = 0.5;
- for (int i = 0; i < clicked_output->workspaces->length; i++) {
- struct workspace *workspace = clicked_output->workspaces->items[i];
- int button_width, button_height;
-
- workspace_button_size(window, workspace->name, &button_width, &button_height);
-
- button_x += button_width;
- if (x <= button_x) {
- ipc_send_workspace_command(workspace->name);
- break;
- }
- }
-
- switch (button) {
- case BTN_LEFT:
- status_line_mouse_event(&swaybar, x, y, 1);
- break;
- case BTN_MIDDLE:
- status_line_mouse_event(&swaybar, x, y, 2);
- break;
- case BTN_RIGHT:
- status_line_mouse_event(&swaybar, x, y, 3);
- break;
- }
-
-#ifdef ENABLE_TRAY
- tray_mouse_event(clicked_output, x, y, button, state_w);
-#endif
-
+static void layer_surface_configure(void *data,
+ struct zwlr_layer_surface_v1 *surface,
+ uint32_t serial, uint32_t width, uint32_t height) {
+ struct swaybar_output *output = data;
+ output->width = width;
+ output->height = height;
+ zwlr_layer_surface_v1_ack_configure(surface, serial);
+ render_frame(output->bar, output);
}
-static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
- sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
-
- // If there are status blocks and click_events are enabled
- // check if the position is within the status area and if so
- // tell the status line to output the event and skip workspace
- // switching below.
- int num_blocks = swaybar.status->block_line->length;
- if (swaybar.status->click_events && num_blocks > 0) {
- struct status_block *first_block = swaybar.status->block_line->items[0];
- int x = window->pointer_input.last_x;
- int y = window->pointer_input.last_y;
- if (x > first_block->x) {
- if (direction == SCROLL_UP) {
- status_line_mouse_event(&swaybar, x, y, 4);
- } else {
- status_line_mouse_event(&swaybar, x, y, 5);
- }
- return;
- }
- }
+static void layer_surface_closed(void *_output,
+ struct zwlr_layer_surface_v1 *surface) {
+ // TODO: Deal with hotplugging
+ struct swaybar_output *output = output;
+ zwlr_layer_surface_v1_destroy(output->layer_surface);
+ wl_surface_destroy(output->surface);
+}
- if (!swaybar.config->wrap_scroll) {
- // Find output this window lives on
- int i;
- struct output *output = NULL;
- for (i = 0; i < swaybar.outputs->length; ++i) {
- output = swaybar.outputs->items[i];
- if (output->window == window) {
- break;
- }
- }
- if (!sway_assert(i != swaybar.outputs->length, "Unknown window in scroll event")) {
- return;
- }
- int focused = -1;
- for (i = 0; i < output->workspaces->length; ++i) {
- struct workspace *ws = output->workspaces->items[i];
- if (ws->focused) {
- focused = i;
- break;
- }
- }
- if (!sway_assert(focused != -1, "Scroll wheel event received on inactive output")) {
- return;
- }
- if ((focused == 0 && direction == SCROLL_UP) ||
- (focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
- // Do not wrap
- return;
- }
+struct zwlr_layer_surface_v1_listener layer_surface_listener = {
+ .configure = layer_surface_configure,
+ .closed = layer_surface_closed,
+};
+
+static void handle_global(void *data, struct wl_registry *registry,
+ uint32_t name, const char *interface, uint32_t version) {
+ struct swaybar *bar = data;
+ if (strcmp(interface, wl_compositor_interface.name) == 0) {
+ bar->compositor = wl_registry_bind(registry, name,
+ &wl_compositor_interface, 1);
+ } else if (strcmp(interface, wl_shm_interface.name) == 0) {
+ bar->shm = wl_registry_bind(registry, name,
+ &wl_shm_interface, 1);
+ } else if (strcmp(interface, wl_output_interface.name) == 0) {
+ static int idx = 0;
+ struct swaybar_output *output =
+ calloc(1, sizeof(struct swaybar_output));
+ output->bar = bar;
+ output->output = wl_registry_bind(registry, name,
+ &wl_output_interface, 1);
+ output->idx = idx++;
+ wl_list_insert(&bar->outputs, &output->link);
+ } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
+ bar->layer_shell = wl_registry_bind(
+ registry, name, &zwlr_layer_shell_v1_interface, 1);
}
+}
- const char *workspace_name = direction == SCROLL_UP ? "prev_on_output" : "next_on_output";
- ipc_send_workspace_command(workspace_name);
+static void handle_global_remove(void *data, struct wl_registry *registry,
+ uint32_t name) {
+ // who cares
}
-void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
- /* initialize bar with default values */
- bar_init(bar);
+static const struct wl_registry_listener registry_listener = {
+ .global = handle_global,
+ .global_remove = handle_global_remove,
+};
- /* Initialize event loop lists */
+void bar_setup(struct swaybar *bar,
+ const char *socket_path, const char *bar_id) {
+ bar_init(bar);
init_event_loop();
- /* 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, bar_id);
-
- int i;
- for (i = 0; i < bar->outputs->length; ++i) {
- struct output *bar_output = bar->outputs->items[i];
-
- bar_output->registry = registry_poll();
-
- if (!bar_output->registry->desktop_shell) {
- sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
- }
-
- struct output_state *output = bar_output->registry->outputs->items[bar_output->idx];
-
- bar_output->window = window_setup(bar_output->registry,
- output->width / output->scale, 30, output->scale, 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,
+ assert(bar->display = wl_display_connect(NULL));
+
+ struct wl_registry *registry = wl_display_get_registry(bar->display);
+ wl_registry_add_listener(registry, &registry_listener, bar);
+ wl_display_roundtrip(bar->display);
+ assert(bar->compositor && bar->layer_shell && bar->shm);
+
+ // TODO: we might not necessarily be meant to do all of the outputs
+ struct swaybar_output *output;
+ wl_list_for_each(output, &bar->outputs, link) {
+ assert(output->surface = wl_compositor_create_surface(bar->compositor));
+ output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
+ bar->layer_shell, output->surface, output->output,
+ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM, "panel");
+ assert(output->layer_surface);
+ zwlr_layer_surface_v1_add_listener(output->layer_surface,
+ &layer_surface_listener, output);
+ zwlr_layer_surface_v1_set_anchor(output->layer_surface,
bar->config->position);
-
- window_make_shell(bar_output->window);
-
- /* set font */
- bar_output->window->font = bar->config->font;
-
- /* set mouse event callbacks */
- bar_output->window->pointer_input.notify_button = mouse_button_notify;
- bar_output->window->pointer_input.notify_scroll = mouse_scroll_notify;
-
- /* set window height */
- set_window_height(bar_output->window, bar->config->height);
+ render_frame(bar, output);
}
- /* spawn status command */
- spawn_status_cmd_proc(bar);
-
-#ifdef ENABLE_TRAY
- init_tray(bar);
-#endif
}
-bool dirty = true;
-
-static void respond_ipc(int fd, short mask, void *_bar) {
- struct bar *bar = (struct bar *)_bar;
- sway_log(L_DEBUG, "Got IPC event.");
- dirty = handle_ipc_event(bar);
-}
-
-static void respond_command(int fd, short mask, void *_bar) {
- struct bar *bar = (struct bar *)_bar;
- dirty = handle_status_line(bar);
-}
-
-static void respond_output(int fd, short mask, void *_output) {
- struct output *output = (struct output *)_output;
- if (wl_display_dispatch(output->registry->display) == -1) {
- sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
+static void display_in(int fd, short mask, void *_bar) {
+ struct swaybar *bar = (struct swaybar *)_bar;
+ if (wl_display_dispatch(bar->display) == -1) {
+ wlr_log(L_ERROR, "failed to dispatch wl: %d", errno);
}
}
-void bar_run(struct bar *bar) {
- add_event(bar->ipc_event_socketfd, POLLIN, respond_ipc, bar);
- add_event(bar->status_read_fd, POLLIN, respond_command, bar);
-
- int i;
- for (i = 0; i < bar->outputs->length; ++i) {
- struct output *output = bar->outputs->items[i];
- add_event(wl_display_get_fd(output->registry->display),
- POLLIN, respond_output, output);
- }
-
+void bar_run(struct swaybar *bar) {
+ add_event(wl_display_get_fd(bar->display), POLLIN, display_in, bar);
while (1) {
- if (dirty) {
- 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);
- wl_display_flush(output->registry->display);
- }
- }
- }
-
- dirty = false;
-
event_loop_poll();
-#ifdef ENABLE_TRAY
- dispatch_dbus();
-#endif
}
}
-void free_workspaces(list_t *workspaces) {
- int i;
- for (i = 0; i < workspaces->length; ++i) {
- struct workspace *ws = workspaces->items[i];
- free(ws->name);
- free(ws);
+static void free_outputs(struct wl_list *list) {
+ struct swaybar_output *output, *tmp;
+ wl_list_for_each_safe(output, tmp, list, link) {
+ wl_list_remove(&output->link);
+ free(output->name);
+ free(output);
}
- list_free(workspaces);
}
-static void free_output(struct output *output) {
- window_teardown(output->window);
- if (output->registry) {
- registry_teardown(output->registry);
- }
-
- free(output->name);
-
- if (output->workspaces) {
- free_workspaces(output->workspaces);
- }
-
- 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
- int ret = kill(pid, SIGTERM);
- if (ret != 0) {
- sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid);
- } else {
- int status;
- waitpid(pid, &status, 0);
- }
- }
-}
-
-void bar_teardown(struct bar *bar) {
+void bar_teardown(struct swaybar *bar) {
+ free_outputs(&bar->outputs);
if (bar->config) {
free_config(bar->config);
}
-
- if (bar->outputs) {
- free_outputs(bar->outputs);
- }
-
- if (bar->status) {
- free_status_line(bar->status);
- }
-
- /* close sockets/pipes */
- if (bar->status_read_fd) {
- close(bar->status_read_fd);
- }
-
- if (bar->status_write_fd) {
- close(bar->status_write_fd);
- }
-
- if (bar->ipc_socketfd) {
- close(bar->ipc_socketfd);
- }
-
- if (bar->ipc_event_socketfd) {
- close(bar->ipc_event_socketfd);
- }
-
- /* terminate status command process */
- terminate_status_command(bar->status_command_pid);
}
diff --git a/swaybar/config.c b/swaybar/config.c
index 8fe552f2..0c2b57e0 100644
--- a/swaybar/config.c
+++ b/swaybar/config.c
@@ -1,21 +1,24 @@
#define _XOPEN_SOURCE 500
#include <stdlib.h>
#include <string.h>
-#include "wayland-desktop-shell-client-protocol.h"
-#include "log.h"
#include "swaybar/config.h"
+#include "wlr-layer-shell-unstable-v1-client-protocol.h"
uint32_t parse_position(const char *position) {
+ uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
+ uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
+ ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
if (strcmp("top", position) == 0) {
- return DESKTOP_SHELL_PANEL_POSITION_TOP;
+ return ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | horiz;
} else if (strcmp("bottom", position) == 0) {
- return DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
+ return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz;
} else if (strcmp("left", position) == 0) {
- return DESKTOP_SHELL_PANEL_POSITION_LEFT;
+ return ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | vert;
} else if (strcmp("right", position) == 0) {
- return DESKTOP_SHELL_PANEL_POSITION_RIGHT;
+ return ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | vert;
} else {
- return DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
+ return ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | horiz;
}
}
@@ -30,11 +33,11 @@ char *parse_font(const char *font) {
return new_font;
}
-struct config *init_config() {
- struct config *config = calloc(1, sizeof(struct config));
+struct swaybar_config *init_config() {
+ struct swaybar_config *config = calloc(1, sizeof(struct swaybar_config));
config->status_command = NULL;
config->pango_markup = false;
- config->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
+ config->position = parse_position("bottom");
config->font = strdup("monospace 10");
config->mode = NULL;
config->sep_symbol = NULL;
@@ -48,18 +51,6 @@ struct config *init_config() {
/* height */
config->height = 0;
-#ifdef ENABLE_TRAY
- config->tray_output = NULL;
- config->icon_theme = NULL;
- config->tray_padding = 2;
- /**
- * These constants are used by wayland and are defined in
- * linux/input-event-codes.h
- */
- config->activate_button = 0x110; /* BTN_LEFT */
- config->context_button = 0x111; /* BTN_RIGHT */
-#endif
-
/* colors */
config->colors.background = 0x000000FF;
config->colors.statusline = 0xFFFFFFFF;
@@ -88,7 +79,7 @@ struct config *init_config() {
return config;
}
-void free_config(struct config *config) {
+void free_config(struct swaybar_config *config) {
free(config->status_command);
free(config->font);
free(config->mode);
diff --git a/swaybar/event_loop.c b/swaybar/event_loop.c
index 0d1be1da..748372ed 100644
--- a/