aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-12-09 15:10:41 +0000
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-12-31 20:40:18 +0000
commit6b03c68775c9c638def342c82b1fa3beffa52645 (patch)
treea3b18d948f8e2a51151f24aab47c552f28a17f70 /sway
parentswaybar: add StatusNotifierItem to tray (diff)
downloadsway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.gz
sway-6b03c68775c9c638def342c82b1fa3beffa52645.tar.zst
sway-6b03c68775c9c638def342c82b1fa3beffa52645.zip
swaybar: implement tray config
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/bar.c4
-rw-r--r--sway/commands/bar/activate_button.c8
-rw-r--r--sway/commands/bar/context_button.c8
-rw-r--r--sway/commands/bar/icon_theme.c25
-rw-r--r--sway/commands/bar/secondary_button.c8
-rw-r--r--sway/commands/bar/tray_bindsym.c55
-rw-r--r--sway/commands/bar/tray_output.c39
-rw-r--r--sway/commands/bar/tray_padding.c37
-rw-r--r--sway/config/bar.c9
-rw-r--r--sway/ipc-json.c37
-rw-r--r--sway/meson.build4
-rw-r--r--sway/sway-bar.5.scd25
12 files changed, 207 insertions, 52 deletions
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index 0cf94907..507ee10a 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -8,11 +8,9 @@
8 8
9// Must be in alphabetical order for bsearch 9// Must be in alphabetical order for bsearch
10static struct cmd_handler bar_handlers[] = { 10static struct cmd_handler bar_handlers[] = {
11 { "activate_button", bar_cmd_activate_button },
12 { "binding_mode_indicator", bar_cmd_binding_mode_indicator }, 11 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
13 { "bindsym", bar_cmd_bindsym }, 12 { "bindsym", bar_cmd_bindsym },
14 { "colors", bar_cmd_colors }, 13 { "colors", bar_cmd_colors },
15 { "context_button", bar_cmd_context_button },
16 { "font", bar_cmd_font }, 14 { "font", bar_cmd_font },
17 { "gaps", bar_cmd_gaps }, 15 { "gaps", bar_cmd_gaps },
18 { "height", bar_cmd_height }, 16 { "height", bar_cmd_height },
@@ -23,11 +21,11 @@ static struct cmd_handler bar_handlers[] = {
23 { "output", bar_cmd_output }, 21 { "output", bar_cmd_output },
24 { "pango_markup", bar_cmd_pango_markup }, 22 { "pango_markup", bar_cmd_pango_markup },
25 { "position", bar_cmd_position }, 23 { "position", bar_cmd_position },
26 { "secondary_button", bar_cmd_secondary_button },
27 { "separator_symbol", bar_cmd_separator_symbol }, 24 { "separator_symbol", bar_cmd_separator_symbol },
28 { "status_command", bar_cmd_status_command }, 25 { "status_command", bar_cmd_status_command },
29 { "strip_workspace_name", bar_cmd_strip_workspace_name }, 26 { "strip_workspace_name", bar_cmd_strip_workspace_name },
30 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, 27 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
28 { "tray_bindsym", bar_cmd_tray_bindsym },
31 { "tray_output", bar_cmd_tray_output }, 29 { "tray_output", bar_cmd_tray_output },
32 { "tray_padding", bar_cmd_tray_padding }, 30 { "tray_padding", bar_cmd_tray_padding },
33 { "workspace_buttons", bar_cmd_workspace_buttons }, 31 { "workspace_buttons", bar_cmd_workspace_buttons },
diff --git a/sway/commands/bar/activate_button.c b/sway/commands/bar/activate_button.c
deleted file mode 100644
index 7310e7ec..00000000
--- a/sway/commands/bar/activate_button.c
+++ /dev/null
@@ -1,8 +0,0 @@
1#include <stdlib.h>
2#include "sway/commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_activate_button(int argc, char **argv) {
6 // TODO TRAY
7 return cmd_results_new(CMD_INVALID, "activate_button", "TODO TRAY");
8}
diff --git a/sway/commands/bar/context_button.c b/sway/commands/bar/context_button.c
deleted file mode 100644
index 3b76885a..00000000
--- a/sway/commands/bar/context_button.c
+++ /dev/null
@@ -1,8 +0,0 @@
1#include <stdlib.h>
2#include "sway/commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_context_button(int argc, char **argv) {
6 // TODO TRAY
7 return cmd_results_new(CMD_INVALID, "context_button", "TODO TRAY");
8}
diff --git a/sway/commands/bar/icon_theme.c b/sway/commands/bar/icon_theme.c
index 0e30409b..9d3b6040 100644
--- a/sway/commands/bar/icon_theme.c
+++ b/sway/commands/bar/icon_theme.c
@@ -1,7 +1,28 @@
1#define _POSIX_C_SOURCE 200809L
1#include <string.h> 2#include <string.h>
3#include "config.h"
2#include "sway/commands.h" 4#include "sway/commands.h"
5#include "sway/config.h"
6#include "log.h"
3 7
4struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) { 8struct cmd_results *bar_cmd_icon_theme(int argc, char **argv) {
5 // TODO TRAY 9#if HAVE_TRAY
6 return cmd_results_new(CMD_INVALID, "icon_theme", "TODO TRAY"); 10 struct cmd_results *error = NULL;
11 if ((error = checkarg(argc, "icon_theme", EXPECTED_EQUAL_TO, 1))) {
12 return error;
13 }
14
15 if (!config->current_bar) {
16 return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined.");
17 }
18
19 wlr_log(WLR_DEBUG, "[Bar %s] Setting icon theme to %s",
20 config->current_bar->id, argv[0]);
21 free(config->current_bar->icon_theme);
22 config->current_bar->icon_theme = strdup(argv[0]);
23 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
24#else
25 return cmd_results_new(CMD_INVALID, "icon_theme",
26 "Sway has been compiled without tray support");
27#endif
7} 28}
diff --git a/sway/commands/bar/secondary_button.c b/sway/commands/bar/secondary_button.c
deleted file mode 100644
index 449124cb..00000000
--- a/sway/commands/bar/secondary_button.c
+++ /dev/null
@@ -1,8 +0,0 @@
1#include <stdlib.h>
2#include "sway/commands.h"
3#include "log.h"
4
5struct cmd_results *bar_cmd_secondary_button(int argc, char **argv) {
6 // TODO TRAY
7 return cmd_results_new(CMD_INVALID, "secondary_button", "TODO TRAY");
8}
diff --git a/sway/commands/bar/tray_bindsym.c b/sway/commands/bar/tray_bindsym.c
new file mode 100644
index 00000000..ad413446
--- /dev/null
+++ b/sway/commands/bar/tray_bindsym.c
@@ -0,0 +1,55 @@
1#include <strings.h>
2#include "config.h"
3#include "sway/commands.h"
4#include "sway/config.h"
5#include "log.h"
6
7struct cmd_results *bar_cmd_tray_bindsym(int argc, char **argv) {
8#if HAVE_TRAY
9 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "tray_bindsym", EXPECTED_EQUAL_TO, 2))) {
11 return error;
12 }
13
14 if (!config->current_bar) {
15 return cmd_results_new(CMD_FAILURE, "tray_bindsym", "No bar defined.");
16 }
17
18 int button = 0;
19 if (strncasecmp(argv[0], "button", strlen("button")) == 0 &&
20 strlen(argv[0]) == strlen("button0")) {
21 button = argv[0][strlen("button")] - '0';
22 }
23 if (button < 1 || button > 9) {
24 return cmd_results_new(CMD_FAILURE, "tray_bindsym",
25 "[Bar %s] Only buttons 1 to 9 are supported",
26 config->current_bar->id);
27 }
28
29 static const char *commands[] = {
30 "ContextMenu",
31 "Activate",
32 "SecondaryActivate",
33 "ScrollDown",
34 "ScrollLeft",
35 "ScrollRight",
36 "ScrollUp",
37 "nop"
38 };
39
40 for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); ++i) {
41 if (strcasecmp(argv[1], commands[i]) == 0) {
42 wlr_log(WLR_DEBUG, "[Bar %s] Binding button %d to %s",
43 config->current_bar->id, button, commands[i]);
44 config->current_bar->tray_bindings[button] = commands[i];
45 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
46 }
47 }
48
49 return cmd_results_new(CMD_INVALID, "tray_bindsym",
50 "[Bar %s] Invalid command %s", config->current_bar->id, argv[1]);
51#else
52 return cmd_results_new(CMD_INVALID, "tray_bindsym",
53 "Sway has been compiled without tray support");
54#endif
55}
diff --git a/sway/commands/bar/tray_output.c b/sway/commands/bar/tray_output.c
index e6c77128..19ecc5c1 100644
--- a/sway/commands/bar/tray_output.c
+++ b/sway/commands/bar/tray_output.c
@@ -1,7 +1,42 @@
1#define _POSIX_C_SOURCE 200809L
1#include <string.h> 2#include <string.h>
3#include "config.h"
2#include "sway/commands.h" 4#include "sway/commands.h"
5#include "sway/config.h"
6#include "list.h"
7#include "log.h"
3 8
4struct cmd_results *bar_cmd_tray_output(int argc, char **argv) { 9struct cmd_results *bar_cmd_tray_output(int argc, char **argv) {
5 // TODO TRAY 10#if HAVE_TRAY
6 return cmd_results_new(CMD_INVALID, "tray_output", "TODO TRAY"); 11 struct cmd_results *error = NULL;
12 if ((error = checkarg(argc, "tray_output", EXPECTED_EQUAL_TO, 1))) {
13 return error;
14 }
15
16 if (!config->current_bar) {
17 return cmd_results_new(CMD_FAILURE, "tray_output", "No bar defined.");
18 }
19
20 list_t *outputs = config->current_bar->tray_outputs;
21 if (!outputs) {
22 config->current_bar->tray_outputs = outputs = create_list();
23 }
24
25 if (strcmp(argv[0], "none") == 0) {
26 wlr_log(WLR_DEBUG, "Hiding tray on bar: %s", config->current_bar->id);
27 for (int i = 0; i < outputs->length; ++i) {
28 free(outputs->items[i]);
29 }
30 outputs->length = 0;
31 } else {
32 wlr_log(WLR_DEBUG, "Showing tray on output '%s' for bar: %s", argv[0],
33 config->current_bar->id);
34 list_add(outputs, strdup(argv[0]));
35 }
36
37 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
38#else
39 return cmd_results_new(CMD_INVALID, "tray_output",
40 "Sway has been compiled without tray support");
41#endif
7} 42}
diff --git a/sway/commands/bar/tray_padding.c b/sway/commands/bar/tray_padding.c
index 91c56f19..eb795b00 100644
--- a/sway/commands/bar/tray_padding.c
+++ b/sway/commands/bar/tray_padding.c
@@ -1,9 +1,42 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <strings.h> 2#include <strings.h>
3#include "config.h"
3#include "sway/commands.h" 4#include "sway/commands.h"
5#include "sway/config.h"
4#include "log.h" 6#include "log.h"
5 7
6struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { 8struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
7 // TODO TRAY 9#if HAVE_TRAY
8 return cmd_results_new(CMD_INVALID, "tray_padding", "TODO TRAY"); 10 struct cmd_results *error = NULL;
11 if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) {
12 return error;
13 }
14 if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_MOST, 2))) {
15 return error;
16 }
17
18 if (!config->current_bar) {
19 return cmd_results_new(CMD_FAILURE, "tray_padding", "No bar defined.");
20 }
21 struct bar_config *bar = config->current_bar;
22
23 char *end;
24 int padding = strtol(argv[0], &end, 10);
25 if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) {
26 return cmd_results_new(CMD_INVALID, "tray_padding",
27 "[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]);
28 }
29
30 if (argc == 2 && strcasecmp(argv[1], "px") != 0) {
31 return cmd_results_new(CMD_INVALID, "tray_padding",
32 "Expected 'tray_padding <px> [px]'");
33 }
34
35 wlr_log(WLR_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding);
36 config->current_bar->tray_padding = padding;
37 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
38#else
39 return cmd_results_new(CMD_INVALID, "tray_padding",
40 "Sway has been compiled without tray support");
41#endif
9} 42}
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 45c9e998..670219f1 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -12,6 +12,7 @@
12#include <signal.h> 12#include <signal.h>
13#include "sway/config.h" 13#include "sway/config.h"
14#include "sway/output.h" 14#include "sway/output.h"
15#include "config.h"
15#include "stringop.h" 16#include "stringop.h"
16#include "list.h" 17#include "list.h"
17#include "log.h" 18#include "log.h"
@@ -77,6 +78,10 @@ void free_bar_config(struct bar_config *bar) {
77 free(bar->colors.binding_mode_border); 78 free(bar->colors.binding_mode_border);
78 free(bar->colors.binding_mode_bg); 79 free(bar->colors.binding_mode_bg);
79 free(bar->colors.binding_mode_text); 80 free(bar->colors.binding_mode_text);
81#if HAVE_TRAY
82 list_free_items_and_destroy(bar->tray_outputs);
83 free(bar->icon_theme);
84#endif
80 free(bar); 85 free(bar);
81} 86}
82 87
@@ -165,6 +170,10 @@ struct bar_config *default_bar_config(void) {
165 bar->colors.binding_mode_bg = NULL; 170 bar->colors.binding_mode_bg = NULL;
166 bar->colors.binding_mode_text = NULL; 171 bar->colors.binding_mode_text = NULL;
167 172
173#if HAVE_TRAY
174 bar->tray_padding = 2;
175#endif
176
168 list_add(config->bars, bar); 177 list_add(config->bars, bar);
169 return bar; 178 return bar;
170cleanup: 179cleanup:
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 96701dc2..53e0e335 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -1,6 +1,7 @@
1#include <json-c/json.h> 1#include <json-c/json.h>
2#include <stdio.h> 2#include <stdio.h>
3#include <ctype.h> 3#include <ctype.h>
4#include "config.h"
4#include "log.h" 5#include "log.h"
5#include "sway/config.h" 6#include "sway/config.h"
6#include "sway/ipc-json.h" 7#include "sway/ipc-json.h"
@@ -785,5 +786,41 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
785 } 786 }
786 json_object_object_add(json, "outputs", outputs); 787 json_object_object_add(json, "outputs", outputs);
787 } 788 }
789#if HAVE_TRAY
790 // Add tray outputs if defined
791 if (bar->tray_outputs && bar->tray_outputs->length > 0) {
792 json_object *tray_outputs = json_object_new_array();
793 for (int i = 0; i < bar->tray_outputs->length; ++i) {
794 const char *name = bar->tray_outputs->items[i];
795 json_object_array_add(tray_outputs, json_object_new_string(name));
796 }
797 json_object_object_add(json, "tray_outputs", tray_outputs);
798 }
799
800 json_object *tray_bindings = json_object_new_array();
801 for (int i = 0; i < 10; ++i) {
802 if (bar->tray_bindings[i]) {
803 json_object *bind = json_object_new_object();
804 json_object_object_add(bind, "input_code",
805 json_object_new_int(i));
806 json_object_object_add(bind, "command",
807 json_object_new_string(bar->tray_bindings[i]));
808 json_object_array_add(tray_bindings, bind);
809 }
810 }
811 if (json_object_array_length(tray_bindings) > 0) {
812 json_object_object_add(json, "tray_bindings", tray_bindings);
813 } else {
814 json_object_put(tray_bindings);
815 }
816
817 if (bar->icon_theme) {
818 json_object_object_add(json, "icon_theme",
819 json_object_new_string(bar->icon_theme));
820 }
821
822 json_object_object_add(json, "tray_padding",
823 json_object_new_int(bar->tray_padding));
824#endif
788 return json; 825 return json;
789} 826}
diff --git a/sway/meson.build b/sway/meson.build
index 6d446acb..7f739287 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -99,11 +99,9 @@ sway_sources = files(
99 'commands/workspace_layout.c', 99 'commands/workspace_layout.c',
100 'commands/ws_auto_back_and_forth.c', 100 'commands/ws_auto_back_and_forth.c',
101 101
102 'commands/bar/activate_button.c',
103 'commands/bar/binding_mode_indicator.c', 102 'commands/bar/binding_mode_indicator.c',
104 'commands/bar/bindsym.c', 103 'commands/bar/bindsym.c',
105 'commands/bar/colors.c', 104 'commands/bar/colors.c',
106 'commands/bar/context_button.c',
107 'commands/bar/font.c', 105 'commands/bar/font.c',
108 'commands/bar/gaps.c', 106 'commands/bar/gaps.c',
109 'commands/bar/height.c', 107 'commands/bar/height.c',
@@ -115,12 +113,12 @@ sway_sources = files(
115 'commands/bar/output.c', 113 'commands/bar/output.c',
116 'commands/bar/pango_markup.c', 114 'commands/bar/pango_markup.c',
117 'commands/bar/position.c', 115 'commands/bar/position.c',
118 'commands/bar/secondary_button.c',
119 'commands/bar/separator_symbol.c', 116 'commands/bar/separator_symbol.c',
120 'commands/bar/status_command.c', 117 'commands/bar/status_command.c',
121 'commands/bar/strip_workspace_numbers.c', 118 'commands/bar/strip_workspace_numbers.c',
122 'commands/bar/strip_workspace_name.c', 119 'commands/bar/strip_workspace_name.c',
123 'commands/bar/swaybar_command.c', 120 'commands/bar/swaybar_command.c',
121 'commands/bar/tray_bindsym.c',
124 'commands/bar/tray_output.c', 122 'commands/bar/tray_output.c',
125 'commands/bar/tray_padding.c', 123 'commands/bar/tray_padding.c',
126 'commands/bar/workspace_buttons.c', 124 'commands/bar/workspace_buttons.c',
diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd
index a3c6af2e..2357591d 100644
--- a/sway/sway-bar.5.scd
+++ b/sway/sway-bar.5.scd
@@ -100,27 +100,20 @@ The following commands configure the tray.
100The _button_ argument in all cases is a platform-specific button code. On Linux 100The _button_ argument in all cases is a platform-specific button code. On Linux
101you can find a list of these at linux/input-event-codes.h. 101you can find a list of these at linux/input-event-codes.h.
102 102
103*activate\_button* <button> 103*tray\_bindsym* button<n> ContextMenu|Activate|SecondaryActivate|ScrollDown|ScrollLeft|ScrollRight|ScrollUp|nop
104 Sets the button to be used for the _activate_ (primary click) tray item 104 Binds mouse button _n_ (1 to 9) to the specified action. Use the command
105 event. The default is BTN\_LEFT (0x110). 105 _nop_ to disable the default action (Activate for button 1, ContextMenu for
106 106 button 2 and SecondaryActivate for button 3).
107*context\_button* <button>
108 Sets the button to be used for the _context menu_ (right click) tray item
109 event. The default is BTN\_RIGHT (0x111).
110
111*secondary\_button* <button>
112 Sets the button to be used for the _secondary_ (middle click) tray item
113 event. The default is BTN\_MIDDLE (0x112).
114
115*tray\_output* none|all|<output>
116 Sets the output that the tray will appear on or none. Unlike i3bar, swaybar
117 is able to show icons on any number of bars and outputs without races.
118 The default is _all_.
119 107
120*tray\_padding* <px> [px] 108*tray\_padding* <px> [px]
121 Sets the pixel padding of the system tray. This padding will surround the 109 Sets the pixel padding of the system tray. This padding will surround the
122 tray on all sides and between each item. The default value for _px_ is 2. 110 tray on all sides and between each item. The default value for _px_ is 2.
123 111
112*tray\_output* none|<output>
113 Restrict the tray to a certain output, can be specified multiple times. If
114 omitted, the tray will be displayed on all outputs. Unlike i3bar, swaybar
115 can show icons on any number of bars and outputs without races.
116
124*icon\_theme* <name> 117*icon\_theme* <name>
125 Sets the icon theme that sway will look for item icons in. This option has 118 Sets the icon theme that sway will look for item icons in. This option has
126 no default value, because sway will always default to the fallback theme, 119 no default value, because sway will always default to the fallback theme,