aboutsummaryrefslogtreecommitdiffstats
path: root/include/swaybar/tray
diff options
context:
space:
mode:
Diffstat (limited to 'include/swaybar/tray')
-rw-r--r--include/swaybar/tray/host.h17
-rw-r--r--include/swaybar/tray/icon.h52
-rw-r--r--include/swaybar/tray/item.h45
-rw-r--r--include/swaybar/tray/sni.h82
-rw-r--r--include/swaybar/tray/tray.h40
-rw-r--r--include/swaybar/tray/watcher.h18
6 files changed, 160 insertions, 94 deletions
diff --git a/include/swaybar/tray/host.h b/include/swaybar/tray/host.h
new file mode 100644
index 00000000..2d4cf82b
--- /dev/null
+++ b/include/swaybar/tray/host.h
@@ -0,0 +1,17 @@
1#ifndef _SWAYBAR_TRAY_HOST_H
2#define _SWAYBAR_TRAY_HOST_H
3
4#include <stdbool.h>
5
6struct swaybar_tray;
7
8struct swaybar_host {
9 struct swaybar_tray *tray;
10 char *service;
11 char *watcher_interface;
12};
13
14bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray);
15void finish_host(struct swaybar_host *host);
16
17#endif
diff --git a/include/swaybar/tray/icon.h b/include/swaybar/tray/icon.h
index 1cc6ff9c..7a6c400c 100644
--- a/include/swaybar/tray/icon.h
+++ b/include/swaybar/tray/icon.h
@@ -1,16 +1,44 @@
1#ifndef _SWAYBAR_ICON_H 1#ifndef _SWAYBAR_TRAY_ICON_H
2#define _SWAYBAR_ICON_H 2#define _SWAYBAR_TRAY_ICON_H
3 3
4#include <stdint.h> 4#include "list.h"
5#include <stdbool.h>
6#include <client/cairo.h>
7 5
8/** 6enum subdir_type {
9 * Returns the image found by `name` that is closest to `size` 7 THRESHOLD,
10 */ 8 SCALABLE,
11cairo_surface_t *find_icon(const char *name, int size); 9 FIXED
10};
11
12struct icon_theme_subdir {
13 char *name;
14 int size;
15 enum subdir_type type;
16 int max_size;
17 int min_size;
18 int threshold;
19};
20
21struct icon_theme {
22 char *name;
23 char *comment;
24 char *inherits;
25 list_t *directories; // char *
12 26
13/* Struct used internally only */ 27 char *dir;
14struct subdir; 28 list_t *subdirs; // struct icon_theme_subdir *
29};
30
31void init_themes(list_t **themes, list_t **basedirs);
32void finish_themes(list_t *themes, list_t *basedirs);
33
34/*
35 * Finds an icon of a specified size given a list of themes and base directories.
36 * If the icon is found, the pointers min_size & max_size are set to minimum &
37 * maximum size that the icon can be scaled to, respectively.
38 * Returns: path of icon (which should be freed), or NULL if the icon is not found.
39 */
40char *find_icon(list_t *themes, list_t *basedirs, char *name, int size,
41 char *theme, int *min_size, int *max_size);
42char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size);
15 43
16#endif /* _SWAYBAR_ICON_H */ 44#endif
diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h
new file mode 100644
index 00000000..9bba7951
--- /dev/null
+++ b/include/swaybar/tray/item.h
@@ -0,0 +1,45 @@
1#ifndef _SWAYBAR_TRAY_ITEM_H
2#define _SWAYBAR_TRAY_ITEM_H
3
4#include <cairo.h>
5#include <stdbool.h>
6#include <stdint.h>
7#include "swaybar/tray/tray.h"
8#include "list.h"
9
10struct swaybar_output;
11
12struct swaybar_pixmap {
13 int size;
14 unsigned char pixels[];
15};
16
17struct swaybar_sni {
18 // icon properties
19 struct swaybar_tray *tray;
20 cairo_surface_t *icon;
21 int min_size;
22 int max_size;
23
24 // dbus properties
25 char *watcher_id;
26 char *service;
27 char *path;
28 char *interface;
29
30 char *status;
31 char *icon_name;
32 list_t *icon_pixmap; // struct swaybar_pixmap *
33 char *attention_icon_name;
34 list_t *attention_icon_pixmap; // struct swaybar_pixmap *
35 bool item_is_menu;
36 char *menu;
37 char *icon_theme_path; // non-standard KDE property
38};
39
40struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray);
41void destroy_sni(struct swaybar_sni *sni);
42uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
43 struct swaybar_sni *sni);
44
45#endif
diff --git a/include/swaybar/tray/sni.h b/include/swaybar/tray/sni.h
deleted file mode 100644
index c2544e2a..00000000
--- a/include/swaybar/tray/sni.h
+++ /dev/null
@@ -1,82 +0,0 @@
1#ifndef _SWAYBAR_SNI_H
2#define _SWAYBAR_SNI_H
3
4#include <stdbool.h>
5#include <client/cairo.h>
6
7struct StatusNotifierItem {
8 /* Name registered to sni watcher */
9 char *name;
10 /* Unique bus name, needed for determining signal origins */
11 char *unique_name;
12 bool kde_special_snowflake;
13
14 cairo_surface_t *image;
15 bool dirty;
16};
17
18/* Each output holds an sni_icon_ref of each item to render */
19struct sni_icon_ref {
20 cairo_surface_t *icon;
21 struct StatusNotifierItem *ref;
22};
23
24struct sni_icon_ref *sni_icon_ref_create(struct StatusNotifierItem *item,
25 int height);
26
27void sni_icon_ref_free(struct sni_icon_ref *sni_ref);
28
29/**
30 * Will return a new item and get its icon. (see warning below)
31 * May return `NULL` if `name` is not valid.
32 */
33struct StatusNotifierItem *sni_create(const char *name);
34
35/**
36 * `item` must be a struct StatusNotifierItem *
37 * `str` must be a NUL terminated char *
38 *
39 * Returns 0 if `item` has a name of `str`
40 */
41int sni_str_cmp(const void *item, const void *str);
42
43/**
44 * Returns 0 if `item` has a unique name of `str` or if
45 * `item->unique_name == NULL`
46 */
47int sni_uniq_cmp(const void *item, const void *str);
48
49/**
50 * Gets an icon for the given item if found.
51 *
52 * XXX
53 * This function keeps a reference to the item until it gets responses, make
54 * sure that the reference and item are valid during this time.
55 */
56void get_icon(struct StatusNotifierItem *item);
57
58/**
59 * Calls the "activate" method on the given StatusNotifierItem
60 *
61 * x and y should be where the item was clicked
62 */
63void sni_activate(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
64
65/**
66 * Asks the item to draw a context menu at the given x and y coords
67 */
68void sni_context_menu(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
69
70/**
71 * Calls the "secondary activate" method on the given StatusNotifierItem
72 *
73 * x and y should be where the item was clicked
74 */
75void sni_secondary(struct StatusNotifierItem *item, uint32_t x, uint32_t y);
76
77/**
78 * Deconstructs `item`
79 */
80void sni_free(struct StatusNotifierItem *item);
81
82#endif /* _SWAYBAR_SNI_H */
diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h
new file mode 100644
index 00000000..8958b69a
--- /dev/null
+++ b/include/swaybar/tray/tray.h
@@ -0,0 +1,40 @@
1#ifndef _SWAYBAR_TRAY_TRAY_H
2#define _SWAYBAR_TRAY_TRAY_H
3
4#include "config.h"
5#ifdef HAVE_SYSTEMD
6#include <systemd/sd-bus.h>
7#elif HAVE_ELOGIND
8#include <elogind/sd-bus.h>
9#endif
10#include <cairo.h>
11#include <stdint.h>
12#include "swaybar/tray/host.h"
13#include "list.h"
14
15struct swaybar;
16struct swaybar_output;
17struct swaybar_watcher;
18
19struct swaybar_tray {
20 struct swaybar *bar;
21
22 int fd;
23 sd_bus *bus;
24
25 struct swaybar_host host_xdg;
26 struct swaybar_host host_kde;
27 list_t *items; // struct swaybar_sni *
28 struct swaybar_watcher *watcher_xdg;
29 struct swaybar_watcher *watcher_kde;
30
31 list_t *basedirs; // char *
32 list_t *themes; // struct swaybar_theme *
33};
34
35struct swaybar_tray *create_tray(struct swaybar *bar);
36void destroy_tray(struct swaybar_tray *tray);
37void tray_in(int fd, short mask, void *data);
38uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x);
39
40#endif
diff --git a/include/swaybar/tray/watcher.h b/include/swaybar/tray/watcher.h
new file mode 100644
index 00000000..8f276da8
--- /dev/null
+++ b/include/swaybar/tray/watcher.h
@@ -0,0 +1,18 @@
1#ifndef _SWAYBAR_TRAY_WATCHER_H
2#define _SWAYBAR_TRAY_WATCHER_H
3
4#include "swaybar/tray/tray.h"
5#include "list.h"
6
7struct swaybar_watcher {
8 char *interface;
9 sd_bus *bus;
10 list_t *hosts;
11 list_t *items;
12 int version;
13};
14
15struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus);
16void destroy_watcher(struct swaybar_watcher *watcher);
17
18#endif