aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/bar/tray_padding.c
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-06-07 16:45:28 -0700
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-06-07 17:49:16 -0700
commit843ad38b3c427adb0bf319e9613d9813c8d9246c (patch)
treee02a5b06e2b6923371fd53724791c147c18a1fa4 /sway/commands/bar/tray_padding.c
parentMerge pull request #1232 from johalun/master-freebsd (diff)
downloadsway-843ad38b3c427adb0bf319e9613d9813c8d9246c.tar.gz
sway-843ad38b3c427adb0bf319e9613d9813c8d9246c.tar.zst
sway-843ad38b3c427adb0bf319e9613d9813c8d9246c.zip
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
Diffstat (limited to 'sway/commands/bar/tray_padding.c')
-rw-r--r--sway/commands/bar/tray_padding.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c
index 8c559f65..ac0572ce 100644
--- a/sway/commands/bar/tray_padding.c
+++ b/sway/commands/bar/tray_padding.c
@@ -1,30 +1,34 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <string.h>
3#include <strings.h> 2#include <strings.h>
4#include "sway/commands.h" 3#include "sway/commands.h"
5#include "log.h" 4#include "log.h"
6 5
7struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { 6struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
7 const char *cmd_name = "tray_padding";
8#ifndef ENABLE_TRAY
9 return cmd_results_new(CMD_INVALID, cmd_name, "Invalid %s command"
10 "%s called, but sway was compiled without tray support",
11 cmd_name, cmd_name);
12#else
8 struct cmd_results *error = NULL; 13 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) { 14 if ((error = checkarg(argc, cmd_name, EXPECTED_AT_LEAST, 1))) {
10 return error; 15 return error;
11 } 16 }
12 17
13 if (!config->current_bar) { 18 if (!config->current_bar) {
14 return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined."); 19 return cmd_results_new(CMD_FAILURE, cmd_name, "No bar defined.");
15 } 20 }
16 21
17 int padding = atoi(argv[0]); 22 if (argc == 1 || (argc == 2 && strcasecmp("px", argv[1]) == 0)) {
18 if (padding < 0) { 23 char *inv;
19 return cmd_results_new(CMD_INVALID, "tray_padding", 24 uint32_t padding = strtoul(argv[0], &inv, 10);
20 "Invalid padding value %s, minimum is 0", argv[0]); 25 if (*inv == '\0' || strcasecmp(inv, "px") == 0) {
26 config->current_bar->tray_padding = padding;
27 sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29 }
21 } 30 }
22 31 return cmd_results_new(CMD_FAILURE, cmd_name,
23 if (argc > 1 && strcasecmp("px", argv[1]) != 0) { 32 "Expected 'tray_padding <padding>[px]'");
24 return cmd_results_new(CMD_INVALID, "tray_padding", 33#endif
25 "Unknown unit %s", argv[1]);
26 }
27 config->current_bar->tray_padding = padding;
28 sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id);
29 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
30} 34}