From 5f65f339896fadf0011b75d78c869594876d35d9 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sun, 28 Oct 2018 10:25:47 +0000 Subject: swaybar: add tray interface --- swaybar/bar.c | 15 +++++++++++++++ swaybar/meson.build | 40 +++++++++++++++++++++++++++------------- swaybar/render.c | 9 +++++++++ swaybar/tray/tray.c | 21 +++++++++++++++++++++ 4 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 swaybar/tray/tray.c (limited to 'swaybar') 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 +#include +#include +#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 +} -- cgit v1.2.3