diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-12-05 17:36:37 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-31 20:40:18 +0000 |
commit | ef555012fa49e66c30264fcb7ab2d62391b4aa2e (patch) | |
tree | f57112fc252f9b5dd5f6d1ba27b6633b177c6151 /swaybar/tray/tray.c | |
parent | 5f65f339896fadf0011b75d78c869594876d35d9 (diff) |
swaybar: add skeleton dbus code to tray
Diffstat (limited to 'swaybar/tray/tray.c')
-rw-r--r-- | swaybar/tray/tray.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index d5fb3ea9..0a4f2955 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -1,19 +1,48 @@ #include <cairo.h> #include <stdint.h> #include <stdlib.h> +#include <string.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; + + sd_bus *bus; + int ret = sd_bus_open_user(&bus); + if (ret < 0) { + wlr_log(WLR_ERROR, "Failed to connect to user bus: %s", strerror(-ret)); + return NULL; + } + + struct swaybar_tray *tray = calloc(1, sizeof(struct swaybar_tray)); + if (!tray) { + return NULL; + } + tray->bar = bar; + tray->bus = bus; + tray->fd = sd_bus_get_fd(tray->bus); + return tray; } void destroy_tray(struct swaybar_tray *tray) { + if (!tray) { + return; + } + sd_bus_flush_close_unref(tray->bus); + free(tray); } void tray_in(int fd, short mask, void *data) { + sd_bus *bus = data; + int ret; + while ((ret = sd_bus_process(bus, NULL)) > 0) { + // This space intentionally left blank + } + if (ret < 0) { + wlr_log(WLR_ERROR, "Failed to process bus: %s", strerror(-ret)); + } } uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { |