From 598e950296ce9fef24b54b4c01302ee68473fb8a Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 26 Oct 2018 09:44:01 +0100 Subject: swaybar: remove old tray implementation --- include/swaybar/tray/icon.h | 16 --------- include/swaybar/tray/sni.h | 82 --------------------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 include/swaybar/tray/icon.h delete mode 100644 include/swaybar/tray/sni.h (limited to 'include') diff --git a/include/swaybar/tray/icon.h b/include/swaybar/tray/icon.h deleted file mode 100644 index 1cc6ff9c..00000000 --- a/include/swaybar/tray/icon.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _SWAYBAR_ICON_H -#define _SWAYBAR_ICON_H - -#include -#include -#include - -/** - * Returns the image found by `name` that is closest to `size` - */ -cairo_surface_t *find_icon(const char *name, int size); - -/* Struct used internally only */ -struct subdir; - -#endif /* _SWAYBAR_ICON_H */ 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 @@ -#ifndef _SWAYBAR_SNI_H -#define _SWAYBAR_SNI_H - -#include -#include - -struct StatusNotifierItem { - /* Name registered to sni watcher */ - char *name; - /* Unique bus name, needed for determining signal origins */ - char *unique_name; - bool kde_special_snowflake; - - cairo_surface_t *image; - bool dirty; -}; - -/* Each output holds an sni_icon_ref of each item to render */ -struct sni_icon_ref { - cairo_surface_t *icon; - struct StatusNotifierItem *ref; -}; - -struct sni_icon_ref *sni_icon_ref_create(struct StatusNotifierItem *item, - int height); - -void sni_icon_ref_free(struct sni_icon_ref *sni_ref); - -/** - * Will return a new item and get its icon. (see warning below) - * May return `NULL` if `name` is not valid. - */ -struct StatusNotifierItem *sni_create(const char *name); - -/** - * `item` must be a struct StatusNotifierItem * - * `str` must be a NUL terminated char * - * - * Returns 0 if `item` has a name of `str` - */ -int sni_str_cmp(const void *item, const void *str); - -/** - * Returns 0 if `item` has a unique name of `str` or if - * `item->unique_name == NULL` - */ -int sni_uniq_cmp(const void *item, const void *str); - -/** - * Gets an icon for the given item if found. - * - * XXX - * This function keeps a reference to the item until it gets responses, make - * sure that the reference and item are valid during this time. - */ -void get_icon(struct StatusNotifierItem *item); - -/** - * Calls the "activate" method on the given StatusNotifierItem - * - * x and y should be where the item was clicked - */ -void sni_activate(struct StatusNotifierItem *item, uint32_t x, uint32_t y); - -/** - * Asks the item to draw a context menu at the given x and y coords - */ -void sni_context_menu(struct StatusNotifierItem *item, uint32_t x, uint32_t y); - -/** - * Calls the "secondary activate" method on the given StatusNotifierItem - * - * x and y should be where the item was clicked - */ -void sni_secondary(struct StatusNotifierItem *item, uint32_t x, uint32_t y); - -/** - * Deconstructs `item` - */ -void sni_free(struct StatusNotifierItem *item); - -#endif /* _SWAYBAR_SNI_H */ -- cgit v1.2.3 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 --- include/swaybar/bar.h | 8 ++++++++ include/swaybar/tray/tray.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 include/swaybar/tray/tray.h (limited to 'include') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 57c5114e..ef27012d 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -1,6 +1,7 @@ #ifndef _SWAYBAR_BAR_H #define _SWAYBAR_BAR_H #include +#include "config.h" #include "input.h" #include "pool-buffer.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" @@ -8,6 +9,9 @@ struct swaybar_config; struct swaybar_output; +#if HAVE_TRAY +struct swaybar_tray; +#endif struct swaybar_workspace; struct loop; @@ -38,6 +42,10 @@ struct swaybar { int ipc_socketfd; struct wl_list outputs; // swaybar_output::link + +#if HAVE_TRAY + struct swaybar_tray *tray; +#endif }; struct swaybar_output { diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h new file mode 100644 index 00000000..217e2d45 --- /dev/null +++ b/include/swaybar/tray/tray.h @@ -0,0 +1,28 @@ +#ifndef _SWAYBAR_TRAY_TRAY_H +#define _SWAYBAR_TRAY_TRAY_H + +#include "config.h" +#ifdef HAVE_SYSTEMD +#include +#elif HAVE_ELOGIND +#include +#endif +#include +#include + +struct swaybar; +struct swaybar_output; + +struct swaybar_tray { + struct swaybar *bar; + + int fd; + sd_bus *bus; +}; + +struct swaybar_tray *create_tray(struct swaybar *bar); +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); + +#endif -- cgit v1.2.3 From 02df3f67aad203e87602c0124489a41382994cbc Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Wed, 5 Dec 2018 17:28:14 +0000 Subject: swaybar: add StatusNotifierWatcher to tray --- include/swaybar/tray/tray.h | 4 ++++ include/swaybar/tray/watcher.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 include/swaybar/tray/watcher.h (limited to 'include') diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index 217e2d45..cc3e8133 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -12,12 +12,16 @@ struct swaybar; struct swaybar_output; +struct swaybar_watcher; struct swaybar_tray { struct swaybar *bar; int fd; sd_bus *bus; + + struct swaybar_watcher *watcher_xdg; + struct swaybar_watcher *watcher_kde; }; struct swaybar_tray *create_tray(struct swaybar *bar); 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 @@ +#ifndef _SWAYBAR_TRAY_WATCHER_H +#define _SWAYBAR_TRAY_WATCHER_H + +#include "swaybar/tray/tray.h" +#include "list.h" + +struct swaybar_watcher { + char *interface; + sd_bus *bus; + list_t *hosts; + list_t *items; + int version; +}; + +struct swaybar_watcher *create_watcher(char *protocol, sd_bus *bus); +void destroy_watcher(struct swaybar_watcher *watcher); + +#endif -- cgit v1.2.3 From 746600e6ed562db9395ac790b7749624006d80ad Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Thu, 6 Dec 2018 12:51:52 +0000 Subject: swaybar: implement icon themes and lookup for tray --- include/swaybar/tray/icon.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/swaybar/tray/tray.h | 4 ++++ 2 files changed, 48 insertions(+) create mode 100644 include/swaybar/tray/icon.h (limited to 'include') diff --git a/include/swaybar/tray/icon.h b/include/swaybar/tray/icon.h new file mode 100644 index 00000000..7a6c400c --- /dev/null +++ b/include/swaybar/tray/icon.h @@ -0,0 +1,44 @@ +#ifndef _SWAYBAR_TRAY_ICON_H +#define _SWAYBAR_TRAY_ICON_H + +#include "list.h" + +enum subdir_type { + THRESHOLD, + SCALABLE, + FIXED +}; + +struct icon_theme_subdir { + char *name; + int size; + enum subdir_type type; + int max_size; + int min_size; + int threshold; +}; + +struct icon_theme { + char *name; + char *comment; + char *inherits; + list_t *directories; // char * + + char *dir; + list_t *subdirs; // struct icon_theme_subdir * +}; + +void init_themes(list_t **themes, list_t **basedirs); +void finish_themes(list_t *themes, list_t *basedirs); + +/* + * Finds an icon of a specified size given a list of themes and base directories. + * If the icon is found, the pointers min_size & max_size are set to minimum & + * maximum size that the icon can be scaled to, respectively. + * Returns: path of icon (which should be freed), or NULL if the icon is not found. + */ +char *find_icon(list_t *themes, list_t *basedirs, char *name, int size, + char *theme, int *min_size, int *max_size); +char *find_icon_in_dir(char *name, char *dir, int *min_size, int *max_size); + +#endif diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index cc3e8133..8e15fb86 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -9,6 +9,7 @@ #endif #include #include +#include "list.h" struct swaybar; struct swaybar_output; @@ -22,6 +23,9 @@ struct swaybar_tray { struct swaybar_watcher *watcher_xdg; struct swaybar_watcher *watcher_kde; + + list_t *basedirs; // char * + list_t *themes; // struct swaybar_theme * }; struct swaybar_tray *create_tray(struct swaybar *bar); -- cgit v1.2.3 From e6cb55e2f8176b0ea8a6dbf15c728c56d8b74056 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:33:45 +0000 Subject: swaybar: add StatusNotifierHost to tray --- include/swaybar/tray/host.h | 17 +++++++++++++++++ include/swaybar/tray/tray.h | 4 ++++ 2 files changed, 21 insertions(+) create mode 100644 include/swaybar/tray/host.h (limited to 'include') 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 @@ +#ifndef _SWAYBAR_TRAY_HOST_H +#define _SWAYBAR_TRAY_HOST_H + +#include + +struct swaybar_tray; + +struct swaybar_host { + struct swaybar_tray *tray; + char *service; + char *watcher_interface; +}; + +bool init_host(struct swaybar_host *host, char *protocol, struct swaybar_tray *tray); +void finish_host(struct swaybar_host *host); + +#endif diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index 8e15fb86..1d976b4a 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -9,6 +9,7 @@ #endif #include #include +#include "swaybar/tray/host.h" #include "list.h" struct swaybar; @@ -21,6 +22,9 @@ struct swaybar_tray { int fd; sd_bus *bus; + struct swaybar_host host_xdg; + struct swaybar_host host_kde; + list_t *items; // char * struct swaybar_watcher *watcher_xdg; struct swaybar_watcher *watcher_kde; -- cgit v1.2.3 From 74655f835aa9fe0e976473d443f62d253602696c Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:33:45 +0000 Subject: swaybar: add StatusNotifierItem to tray --- include/swaybar/tray/item.h | 38 ++++++++++++++++++++++++++++++++++++++ include/swaybar/tray/tray.h | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 include/swaybar/tray/item.h (limited to 'include') diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h new file mode 100644 index 00000000..57affb78 --- /dev/null +++ b/include/swaybar/tray/item.h @@ -0,0 +1,38 @@ +#ifndef _SWAYBAR_TRAY_ITEM_H +#define _SWAYBAR_TRAY_ITEM_H + +#include +#include "swaybar/tray/tray.h" +#include "list.h" + +struct swaybar_pixmap { + int size; + unsigned char pixels[]; +}; + +struct swaybar_sni { + // icon properties + struct swaybar_tray *tray; + cairo_surface_t *icon; + int min_size; + int max_size; + + // dbus properties + char *watcher_id; + char *service; + char *path; + char *interface; + + char *status; + char *icon_name; + list_t *icon_pixmap; // struct swaybar_pixmap * + char *attention_icon_name; + list_t *attention_icon_pixmap; // struct swaybar_pixmap * + bool item_is_menu; + char *menu; +}; + +struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray); +void destroy_sni(struct swaybar_sni *sni); + +#endif diff --git a/include/swaybar/tray/tray.h b/include/swaybar/tray/tray.h index 1d976b4a..8958b69a 100644 --- a/include/swaybar/tray/tray.h +++ b/include/swaybar/tray/tray.h @@ -24,7 +24,7 @@ struct swaybar_tray { struct swaybar_host host_xdg; struct swaybar_host host_kde; - list_t *items; // char * + list_t *items; // struct swaybar_sni * struct swaybar_watcher *watcher_xdg; struct swaybar_watcher *watcher_kde; -- cgit v1.2.3 From 6b03c68775c9c638def342c82b1fa3beffa52645 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sun, 9 Dec 2018 15:10:41 +0000 Subject: swaybar: implement tray config --- include/sway/commands.h | 4 +--- include/sway/config.h | 8 ++++++++ include/swaybar/config.h | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/sway/commands.h b/include/sway/commands.h index 7bee2538..0e2d7931 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -182,11 +182,9 @@ sway_cmd cmd_workspace; sway_cmd cmd_ws_auto_back_and_forth; sway_cmd cmd_workspace_layout; -sway_cmd bar_cmd_activate_button; sway_cmd bar_cmd_binding_mode_indicator; sway_cmd bar_cmd_bindsym; sway_cmd bar_cmd_colors; -sway_cmd bar_cmd_context_button; sway_cmd bar_cmd_font; sway_cmd bar_cmd_gaps; sway_cmd bar_cmd_mode; @@ -197,13 +195,13 @@ sway_cmd bar_cmd_hidden_state; sway_cmd bar_cmd_icon_theme; sway_cmd bar_cmd_id; sway_cmd bar_cmd_position; -sway_cmd bar_cmd_secondary_button; sway_cmd bar_cmd_separator_symbol; sway_cmd bar_cmd_status_command; sway_cmd bar_cmd_pango_markup; sway_cmd bar_cmd_strip_workspace_numbers; sway_cmd bar_cmd_strip_workspace_name; sway_cmd bar_cmd_swaybar_command; +sway_cmd bar_cmd_tray_bindsym; sway_cmd bar_cmd_tray_output; sway_cmd bar_cmd_tray_padding; sway_cmd bar_cmd_wrap_scroll; diff --git a/include/sway/config.h b/include/sway/config.h index 86473e17..f604b054 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -6,6 +6,7 @@ #include #include #include +#include "../include/config.h" #include "list.h" #include "swaynag.h" #include "tree/container.h" @@ -253,6 +254,13 @@ struct bar_config { char *binding_mode_bg; char *binding_mode_text; } colors; + +#if HAVE_TRAY + char *icon_theme; + const char *tray_bindings[10]; // mouse buttons 0-9 + list_t *tray_outputs; // char * + int tray_padding; +#endif }; struct bar_binding { diff --git a/include/swaybar/config.h b/include/swaybar/config.h index fd7c6ec4..def70d5b 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -3,6 +3,7 @@ #include #include #include +#include "../include/config.h" #include "list.h" #include "util.h" @@ -64,6 +65,13 @@ struct swaybar_config { struct box_colors urgent_workspace; struct box_colors binding_mode; } colors; + +#if HAVE_TRAY + char *icon_theme; + char *tray_bindings[10]; // mouse buttons 0-9 + list_t *tray_outputs; // char * + int tray_padding; +#endif }; struct swaybar_config *init_config(void); -- cgit v1.2.3 From fa2c5282c1d09eced82a9c15a4ee26e7b00a37c4 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:37:33 +0000 Subject: swaybar: implement tray rendering --- include/swaybar/tray/item.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h index 57affb78..53d7e48c 100644 --- a/include/swaybar/tray/item.h +++ b/include/swaybar/tray/item.h @@ -1,10 +1,14 @@ #ifndef _SWAYBAR_TRAY_ITEM_H #define _SWAYBAR_TRAY_ITEM_H +#include #include +#include #include "swaybar/tray/tray.h" #include "list.h" +struct swaybar_output; + struct swaybar_pixmap { int size; unsigned char pixels[]; @@ -34,5 +38,7 @@ struct swaybar_sni { struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray); void destroy_sni(struct swaybar_sni *sni); +uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, + struct swaybar_sni *sni); #endif -- cgit v1.2.3 From 6becde024680503100c94702ed7d1fbf4d01576e Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:39:35 +0000 Subject: swaybar: implement mouse events for tray --- include/swaybar/bar.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index ef27012d..ad942242 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -70,6 +70,8 @@ struct swaybar_output { struct pool_buffer *current_buffer; bool dirty; bool frame_scheduled; + + uint32_t output_height, output_width, output_x, output_y; }; struct swaybar_workspace { -- cgit v1.2.3 From 2fd41fe9c85a866173fc2770ed7669871258bced Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 7 Dec 2018 12:40:45 +0000 Subject: swaybar: set bar dirty on SNI event --- include/swaybar/bar.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index ad942242..e377b8de 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -88,6 +88,8 @@ bool bar_setup(struct swaybar *bar, const char *socket_path); void bar_run(struct swaybar *bar); void bar_teardown(struct swaybar *bar); +void set_bar_dirty(struct swaybar *bar); + /* * Determines whether the bar should be visible and changes it to be so. * If the current visibility of the bar is the different to what it should be, -- cgit v1.2.3 From f33b5c5223a3eb8b63ff4361f43b82ad2104e84b Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Tue, 11 Dec 2018 16:27:39 +0000 Subject: swaybar: do not create tray if hidden --- include/swaybar/config.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/swaybar/config.h b/include/swaybar/config.h index def70d5b..1f6577bd 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -69,6 +69,7 @@ struct swaybar_config { #if HAVE_TRAY char *icon_theme; char *tray_bindings[10]; // mouse buttons 0-9 + bool tray_hidden; list_t *tray_outputs; // char * int tray_padding; #endif -- cgit v1.2.3 From 9e31f5d79ce9de8f1c73013b792aa94f355a1983 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Mon, 17 Dec 2018 23:52:15 +0000 Subject: swaybar: use KDE's SNI IconThemePath property --- include/swaybar/tray/item.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h index 53d7e48c..9bba7951 100644 --- a/include/swaybar/tray/item.h +++ b/include/swaybar/tray/item.h @@ -34,6 +34,7 @@ struct swaybar_sni { list_t *attention_icon_pixmap; // struct swaybar_pixmap * bool item_is_menu; char *menu; + char *icon_theme_path; // non-standard KDE property }; struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray); -- cgit v1.2.3