diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-12-07 12:37:33 +0000 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-12-31 20:40:18 +0000 |
commit | fa2c5282c1d09eced82a9c15a4ee26e7b00a37c4 (patch) | |
tree | ec9e36055d21478466d663e2dc1796658ab273ca /swaybar/tray/tray.c | |
parent | 6b03c68775c9c638def342c82b1fa3beffa52645 (diff) |
swaybar: implement tray rendering
Diffstat (limited to 'swaybar/tray/tray.c')
-rw-r--r-- | swaybar/tray/tray.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/swaybar/tray/tray.c b/swaybar/tray/tray.c index 4ef28a78..f186ed86 100644 --- a/swaybar/tray/tray.c +++ b/swaybar/tray/tray.c @@ -2,6 +2,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include "swaybar/config.h" #include "swaybar/bar.h" #include "swaybar/tray/icon.h" #include "swaybar/tray/host.h" @@ -70,6 +71,28 @@ void tray_in(int fd, short mask, void *data) { } } +static int cmp_output(const void *item, const void *cmp_to) { + return strcmp(item, cmp_to); +} + uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) { - return 0; // placeholder + struct swaybar_config *config = output->bar->config; + if (config->tray_outputs) { + if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) { + return 0; + } + } // else display on all + + if ((int) output->height*output->scale <= 2*config->tray_padding) { + return 2*config->tray_padding + 1; + } + + uint32_t max_height = 0; + struct swaybar_tray *tray = output->bar->tray; + for (int i = 0; i < tray->items->length; ++i) { + uint32_t h = render_sni(cairo, output, x, tray->items->items[i]); + max_height = h > max_height ? h : max_height; + } + + return max_height; } |