2018-10-28 21:25:47 +11:00
|
|
|
#include <cairo.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2018-12-06 04:36:37 +11:00
|
|
|
#include <string.h>
|
2018-10-28 21:25:47 +11:00
|
|
|
#include "swaybar/bar.h"
|
|
|
|
#include "swaybar/tray/tray.h"
|
2018-12-06 04:28:14 +11:00
|
|
|
#include "swaybar/tray/watcher.h"
|
2018-10-28 21:25:47 +11:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
struct swaybar_tray *create_tray(struct swaybar *bar) {
|
|
|
|
wlr_log(WLR_DEBUG, "Initializing tray");
|
2018-12-06 04:36:37 +11:00
|
|
|
|
|
|
|
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);
|
2018-12-06 04:28:14 +11:00
|
|
|
|
|
|
|
tray->watcher_xdg = create_watcher("freedesktop", tray->bus);
|
|
|
|
tray->watcher_kde = create_watcher("kde", tray->bus);
|
|
|
|
|
2018-12-06 04:36:37 +11:00
|
|
|
return tray;
|
2018-10-28 21:25:47 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_tray(struct swaybar_tray *tray) {
|
2018-12-06 04:36:37 +11:00
|
|
|
if (!tray) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-06 04:28:14 +11:00
|
|
|
destroy_watcher(tray->watcher_xdg);
|
|
|
|
destroy_watcher(tray->watcher_kde);
|
2018-12-06 04:36:37 +11:00
|
|
|
sd_bus_flush_close_unref(tray->bus);
|
|
|
|
free(tray);
|
2018-10-28 21:25:47 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void tray_in(int fd, short mask, void *data) {
|
2018-12-06 04:36:37 +11:00
|
|
|
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));
|
|
|
|
}
|
2018-10-28 21:25:47 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
|
|
|
|
return 0; // placeholder
|
|
|
|
}
|