From 843ad38b3c427adb0bf319e9613d9813c8d9246c Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Wed, 7 Jun 2017 16:45:28 -0700 Subject: Implement Tray Icons This commit implements the StatusNotifierItem protocol, and enables swaybar to show tray icons. It also uses `xembedsniproxy` in order to communicate with xembed applications. The tray is completely optional, and can be disabled on compile time with the `enable-tray` option. Or on runtime with the bar config option `tray_output none`. Overview of changes: In swaybar very little is changed outside the tray subfolder except that all events are now polled in `event_loop.c`, this creates no functional difference. Six bar configuration options were added, these are detailed in sway-bar(5) The tray subfolder is where all protocol implementation takes place and is organised as follows: tray/sni_watcher.c: This file contains the StatusNotifierWatcher. It keeps track of items and hosts and reports when they come or go. tray/tray.c This file contains the StatusNotifierHost. It keeps track of sway's version of the items and represents the tray itself. tray/sni.c This file contains the StatusNotifierItem struct and all communication with individual items. tray/icon.c This file implements the icon theme protocol. It allows for finding icons by name, rather than by pixmap. tray/dbus.c This file allows for asynchronous DBus communication. See #986 #343 --- swaybar/ipc.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'swaybar/ipc.c') diff --git a/swaybar/ipc.c b/swaybar/ipc.c index b08eeea8..93d1219c 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -19,11 +19,19 @@ void ipc_send_workspace_command(const char *workspace_name) { static void ipc_parse_config(struct config *config, const char *payload) { json_object *bar_config = json_tokener_parse(payload); - json_object *tray_output, *mode, *hidden_bar, *position, *status_command; + json_object *markup, *mode, *hidden_bar, *position, *status_command; json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; - json_object *markup; +#ifdef ENABLE_TRAY + json_object *tray_output, *icon_theme, *tray_padding, *activate_button, *context_button; + json_object *secondary_button; json_object_object_get_ex(bar_config, "tray_output", &tray_output); + json_object_object_get_ex(bar_config, "icon_theme", &icon_theme); + json_object_object_get_ex(bar_config, "tray_padding", &tray_padding); + json_object_object_get_ex(bar_config, "activate_button", &activate_button); + json_object_object_get_ex(bar_config, "context_button", &context_button); + json_object_object_get_ex(bar_config, "secondary_button", &secondary_button); +#endif json_object_object_get_ex(bar_config, "mode", &mode); json_object_object_get_ex(bar_config, "hidden_bar", &hidden_bar); json_object_object_get_ex(bar_config, "position", &position); @@ -83,6 +91,34 @@ static void ipc_parse_config(struct config *config, const char *payload) { config->pango_markup = json_object_get_boolean(markup); } +#ifdef ENABLE_TRAY + if (tray_output) { + free(config->tray_output); + config->tray_output = strdup(json_object_get_string(tray_output)); + } + + if (icon_theme) { + free(config->icon_theme); + config->icon_theme = strdup(json_object_get_string(icon_theme)); + } + + if (tray_padding) { + config->tray_padding = json_object_get_int(tray_padding); + } + + if (activate_button) { + config->activate_button = json_object_get_int(activate_button); + } + + if (context_button) { + config->context_button = json_object_get_int(context_button); + } + + if (secondary_button) { + config->secondary_button = json_object_get_int(secondary_button); + } +#endif + // free previous outputs list int i; for (i = 0; i < config->outputs->length; ++i) { -- cgit v1.2.3