aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/swaybar/bar.h8
-rw-r--r--include/swaybar/tray/tray.h28
-rw-r--r--meson.build1
-rw-r--r--meson_options.txt1
-rw-r--r--swaybar/bar.c15
-rw-r--r--swaybar/meson.build40
-rw-r--r--swaybar/render.c9
-rw-r--r--swaybar/tray/tray.c21
8 files changed, 110 insertions, 13 deletions
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 57c5114e..ef27012d 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -1,6 +1,7 @@
#ifndef _SWAYBAR_BAR_H
#define _SWAYBAR_BAR_H
#include <wayland-client.h>
+#include "config.h"
#include "input.h"
#include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@@ -8,6 +9,9 @@
struct swaybar_config;
struct swaybar_output;
+#if HAVE_TRAY
+struct swaybar_tray;
+#endif
struct swaybar_workspace;
struct loop;
@@ -38,6 +42,10 @@ struct swaybar {
int ipc_socketfd;
struct wl_list outputs; // swaybar_output::link
+
+#if HAVE_TRAY
+ struct swaybar_tray *tray;
+#endif
};
struct swaybar_output {
diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h
new file mode 100644
index 00000000..217e2d45
--- /dev/null
+++ b/include/swaybar/tray/tray.h
@@ -0,0 +1,28 @@
+#ifndef _SWAYBAR_TRAY_TRAY_H
+#define _SWAYBAR_TRAY_TRAY_H
+
+#include "config.h"
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-bus.h>
+#elif HAVE_ELOGIND
+#include <elogind/sd-bus.h>
+#endif
+#include <cairo.h>
+#include <stdint.h>
+
+struct swaybar;
+struct swaybar_output;
+
+struct swaybar_tray {
+ struct swaybar *bar;
+
+ int fd;
+ sd_bus *bus;
+};
+
+struct swaybar_tray *create_tray(struct swaybar *bar);
+void destroy_tray(struct swaybar_tray *tray);
+void tray_in(int fd, short mask, void *data);
+uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x);
+
+#endif
diff --git a/meson.build b/meson.build
index e1e0fc2d..981f74ac 100644
--- a/meson.build
+++ b/meson.build
@@ -66,6 +66,7 @@ endif
conf_data.set10('HAVE_GDK_PIXBUF', gdk_pixbuf.found())
conf_data.set10('HAVE_SYSTEMD', systemd.found())
conf_data.set10('HAVE_ELOGIND', elogind.found())
+conf_data.set10('HAVE_TRAY', get_option('enable-tray') and (systemd.found() or elogind.found()))
if not systemd.found() and not elogind.found()
warning('The sway binary must be setuid when compiled without (e)logind')
diff --git a/meson_options.txt b/meson_options.txt
index 2db852fc..4640618e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -6,3 +6,4 @@ option('zsh-completions', type: 'boolean', value: true, description: 'Install zs
option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.')
option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.')
option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications')
+option('enable-tray', type: 'boolean', value: false, description: 'Enable support for swaybar tray')
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 53e798bc..c26e76ce 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -18,6 +18,9 @@
#include "swaybar/ipc.h"
#include "swaybar/status_line.h"
#include "swaybar/render.h"
+#if HAVE_TRAY
+#include "swaybar/tray/tray.h"
+#endif
#include "ipc-client.h"
#include "list.h"
#include "log.h"
@@ -362,6 +365,10 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);
assert(pointer->cursor_surface);
+#if HAVE_TRAY
+ bar->tray = create_tray(bar);
+#endif
+
if (bar->config->workspace_buttons) {
ipc_get_workspaces(bar);
}
@@ -403,6 +410,11 @@ void bar_run(struct swaybar *bar) {
loop_add_fd(bar->eventloop, bar->status->read_fd, POLLIN,
status_in, bar);
}
+#if HAVE_TRAY
+ if (bar->tray) {
+ loop_add_fd(bar->eventloop, bar->tray->fd, POLLIN, tray_in, bar->tray->bus);
+ }
+#endif
while (1) {
errno = 0;
if (wl_display_flush(bar->display) == -1 && errno != EAGAIN) {
@@ -420,6 +432,9 @@ static void free_outputs(struct wl_list *list) {
}
void bar_teardown(struct swaybar *bar) {
+#if HAVE_TRAY
+ destroy_tray(bar->tray);
+#endif
free_outputs(&bar->outputs);
if (bar->config) {
free_config(bar->config);
diff --git a/swaybar/meson.build b/swaybar/meson.build
index c27cf2c2..b83f47e5 100644
--- a/swaybar/meson.build
+++ b/swaybar/meson.build
@@ -1,3 +1,28 @@
+tray_files = get_option('enable-tray') ? [
+ 'tray/tray.c',
+] : []
+
+swaybar_deps = [
+ cairo,
+ client_protos,
+ gdk_pixbuf,
+ jsonc,
+ math,
+ pango,
+ pangocairo,
+ rt,
+ wayland_client,
+ wayland_cursor,
+ wlroots,
+]
+if get_option('enable-tray')
+ if systemd.found()
+ swaybar_deps += systemd
+ elif elogind.found()
+ swaybar_deps += elogind
+ endif
+endif
+
executable(
'swaybar', [
'bar.c',
@@ -8,21 +33,10 @@ executable(
'main.c',
'render.c',
'status_line.c',
+ tray_files
],
include_directories: [sway_inc],
- dependencies: [
- cairo,
- client_protos,
- gdk_pixbuf,
- jsonc,
- math,
- pango,
- pangocairo,
- rt,
- wayland_client,
- wayland_cursor,
- wlroots,
- ],
+ dependencies: swaybar_deps,
link_with: [lib_sway_common, lib_sway_client],
install_rpath : rpathdir,
install: true
diff --git a/swaybar/render.c b/swaybar/render.c
index 96118c42..9fe4ee9c 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -14,6 +14,9 @@
#include "swaybar/ipc.h"
#include "swaybar/render.h"
#include "swaybar/status_line.h"
+#if HAVE_TRAY
+#include "swaybar/tray/tray.h"
+#endif
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
static const int WS_HORIZONTAL_PADDING = 5;
@@ -453,6 +456,12 @@ static uint32_t render_to_cairo(cairo_t *cairo, struct swaybar_output *output) {
* utilize the available space.
*/
double x = output->width * output->scale;
+#if HAVE_TRAY
+ if (bar->tray) {
+ uint32_t h = render_tray(cairo, output, &x);
+ max_height = h > max_height ? h : max_height;
+ }
+#endif
if (bar->status) {
uint32_t h = render_status_line(cairo, output, &x);
max_height = h > max_height ? h : max_height;
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c
new file mode 100644
index 00000000..d5fb3ea9
--- /dev/null
+++ b/swaybar/tray/tray.c
@@ -0,0 +1,21 @@
+#include <cairo.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "swaybar/bar.h"
+#include "swaybar/tray/tray.h"
+#include "log.h"
+
+struct swaybar_tray *create_tray(struct swaybar *bar) {
+ wlr_log(WLR_DEBUG, "Initializing tray");
+ return NULL;
+}
+
+void destroy_tray(struct swaybar_tray *tray) {
+}
+
+void tray_in(int fd, short mask, void *data) {
+}
+
+uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
+ return 0; // placeholder
+}