summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/util.c5
-rw-r--r--config.in2
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-rw-r--r--include/swaybar/bar.h1
-rw-r--r--include/swaybar/config.h1
-rw-r--r--sway/commands/bar.c1
-rw-r--r--sway/commands/bar/strip_workspace_name.c32
-rw-r--r--sway/commands/bar/strip_workspace_numbers.c17
-rw-r--r--sway/config/bar.c1
-rw-r--r--sway/ipc-json.c2
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-bar.5.scd4
-rw-r--r--swaybar/bar.c1
-rw-r--r--swaybar/config.c1
-rw-r--r--swaybar/ipc.c29
-rw-r--r--swaybar/render.c22
-rw-r--r--swayidle/swayidle.1.scd2
18 files changed, 90 insertions, 34 deletions
diff --git a/common/util.c b/common/util.c
index 0caafb39..40c64230 100644
--- a/common/util.c
+++ b/common/util.c
@@ -1,4 +1,4 @@
1#define _XOPEN_SOURCE 700 1#define _POSIX_C_SOURCE 200809L
2#include <assert.h> 2#include <assert.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <sys/stat.h> 4#include <sys/stat.h>
@@ -24,7 +24,8 @@ int numlen(int n) {
24 if (n == 0) { 24 if (n == 0) {
25 return 1; 25 return 1;
26 } 26 }
27 return log10(n) + 1; 27 // Account for the '-' in negative numbers.
28 return log10(abs(n)) + (n > 0 ? 1 : 2);
28} 29}
29 30
30static struct modifier_key { 31static struct modifier_key {
diff --git a/config.in b/config.in
index 9c751179..bb9e35c7 100644
--- a/config.in
+++ b/config.in
@@ -41,7 +41,7 @@ output * bg @datadir@/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
41# before-sleep 'swaylock -c 000000' 41# before-sleep 'swaylock -c 000000'
42# 42#
43# This will lock your screen after 300 seconds of inactivity, then turn off 43# This will lock your screen after 300 seconds of inactivity, then turn off
44# your displays after another 600 seconds, and turn your screens back on when 44# your displays after another 300 seconds, and turn your screens back on when
45# resumed. It will also lock your screen before your computer goes to sleep. 45# resumed. It will also lock your screen before your computer goes to sleep.
46 46
47### Input configuration 47### Input configuration
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 2fe8a631..b0339313 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -198,6 +198,7 @@ sway_cmd bar_cmd_separator_symbol;
198sway_cmd bar_cmd_status_command; 198sway_cmd bar_cmd_status_command;
199sway_cmd bar_cmd_pango_markup; 199sway_cmd bar_cmd_pango_markup;
200sway_cmd bar_cmd_strip_workspace_numbers; 200sway_cmd bar_cmd_strip_workspace_numbers;
201sway_cmd bar_cmd_strip_workspace_name;
201sway_cmd bar_cmd_swaybar_command; 202sway_cmd bar_cmd_swaybar_command;
202sway_cmd bar_cmd_tray_output; 203sway_cmd bar_cmd_tray_output;
203sway_cmd bar_cmd_tray_padding; 204sway_cmd bar_cmd_tray_padding;
diff --git a/include/sway/config.h b/include/sway/config.h
index 658b4a01..4927b8e0 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -224,6 +224,7 @@ struct bar_config {
224 bool wrap_scroll; 224 bool wrap_scroll;
225 char *separator_symbol; 225 char *separator_symbol;
226 bool strip_workspace_numbers; 226 bool strip_workspace_numbers;
227 bool strip_workspace_name;
227 bool binding_mode_indicator; 228 bool binding_mode_indicator;
228 bool verbose; 229 bool verbose;
229 pid_t pid; 230 pid_t pid;
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h
index 95b20510..57c5114e 100644
--- a/include/swaybar/bar.h
+++ b/include/swaybar/bar.h
@@ -68,6 +68,7 @@ struct swaybar_workspace {
68 struct wl_list link; // swaybar_output::workspaces 68 struct wl_list link; // swaybar_output::workspaces
69 int num; 69 int num;
70 char *name; 70 char *name;
71 char *label;
71 bool focused; 72 bool focused;
72 bool visible; 73 bool visible;
73 bool urgent; 74 bool urgent;
diff --git a/include/swaybar/config.h b/include/swaybar/config.h
index 5d40790a..700e6b60 100644
--- a/include/swaybar/config.h
+++ b/include/swaybar/config.h
@@ -34,6 +34,7 @@ struct swaybar_config {
34 char *hidden_state; 34 char *hidden_state;
35 char *modifier; 35 char *modifier;
36 bool strip_workspace_numbers; 36 bool strip_workspace_numbers;
37 bool strip_workspace_name;
37 bool binding_mode_indicator; 38 bool binding_mode_indicator;
38 bool wrap_scroll; 39 bool wrap_scroll;
39 bool workspace_buttons; 40 bool workspace_buttons;
diff --git a/sway/commands/bar.c b/sway/commands/bar.c
index c808aef2..f9ed530e 100644
--- a/sway/commands/bar.c
+++ b/sway/commands/bar.c
@@ -25,6 +25,7 @@ static struct cmd_handler bar_handlers[] = {
25 { "secondary_button", bar_cmd_secondary_button }, 25 { "secondary_button", bar_cmd_secondary_button },
26 { "separator_symbol", bar_cmd_separator_symbol }, 26 { "separator_symbol", bar_cmd_separator_symbol },
27 { "status_command", bar_cmd_status_command }, 27 { "status_command", bar_cmd_status_command },
28 { "strip_workspace_name", bar_cmd_strip_workspace_name },
28 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers }, 29 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
29 { "tray_output", bar_cmd_tray_output }, 30 { "tray_output", bar_cmd_tray_output },
30 { "tray_padding", bar_cmd_tray_padding }, 31 { "tray_padding", bar_cmd_tray_padding },
diff --git a/sway/commands/bar/strip_workspace_name.c b/sway/commands/bar/strip_workspace_name.c
new file mode 100644
index 00000000..79692f6e
--- /dev/null
+++ b/sway/commands/bar/strip_workspace_name.c
@@ -0,0 +1,32 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/commands.h"
4#include "log.h"
5#include "util.h"
6
7struct cmd_results *bar_cmd_strip_workspace_name(int argc, char **argv) {
8 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc,
10 "strip_workspace_name", EXPECTED_EQUAL_TO, 1))) {
11 return error;
12 }
13 if (!config->current_bar) {
14 return cmd_results_new(CMD_FAILURE,
15 "strip_workspace_name", "No bar defined.");
16 }
17
18 config->current_bar->strip_workspace_name =
19 parse_boolean(argv[0], config->current_bar->strip_workspace_name);
20
21 if (config->current_bar->strip_workspace_name) {
22 config->current_bar->strip_workspace_numbers = false;
23
24 wlr_log(WLR_DEBUG, "Stripping workspace name on bar: %s",
25 config->current_bar->id);
26 } else {
27 wlr_log(WLR_DEBUG, "Enabling workspace name on bar: %s",
28 config->current_bar->id);
29 }
30
31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
32}
diff --git a/sway/commands/bar/strip_workspace_numbers.c b/sway/commands/bar/strip_workspace_numbers.c
index 4e47d047..b33d01e5 100644
--- a/sway/commands/bar/strip_workspace_numbers.c
+++ b/sway/commands/bar/strip_workspace_numbers.c
@@ -2,6 +2,7 @@
2#include <strings.h> 2#include <strings.h>
3#include "sway/commands.h" 3#include "sway/commands.h"
4#include "log.h" 4#include "log.h"
5#include "util.h"
5 6
6struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) { 7struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
7 struct cmd_results *error = NULL; 8 struct cmd_results *error = NULL;
@@ -13,17 +14,19 @@ struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv) {
13 return cmd_results_new(CMD_FAILURE, 14 return cmd_results_new(CMD_FAILURE,
14 "strip_workspace_numbers", "No bar defined."); 15 "strip_workspace_numbers", "No bar defined.");
15 } 16 }
16 if (strcasecmp("yes", argv[0]) == 0) { 17
17 config->current_bar->strip_workspace_numbers = true; 18 config->current_bar->strip_workspace_numbers =
19 parse_boolean(argv[0], config->current_bar->strip_workspace_numbers);
20
21 if (config->current_bar->strip_workspace_numbers) {
22 config->current_bar->strip_workspace_name = false;
23
18 wlr_log(WLR_DEBUG, "Stripping workspace numbers on bar: %s", 24 wlr_log(WLR_DEBUG, "Stripping workspace numbers on bar: %s",
19 config->current_bar->id); 25 config->current_bar->id);
20 } else if (strcasecmp("no", argv[0]) == 0) { 26 } else {
21 config->current_bar->strip_workspace_numbers = false;
22 wlr_log(WLR_DEBUG, "Enabling workspace numbers on bar: %s", 27 wlr_log(WLR_DEBUG, "Enabling workspace numbers on bar: %s",
23 config->current_bar->id); 28 config->current_bar->id);
24 } else {
25 return cmd_results_new(CMD_INVALID,
26 "strip_workspace_numbers", "Invalid value %s", argv[0]);
27 } 29 }
30
28 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 31 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
29} 32}
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 7bca5f49..7009d0a0 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -100,6 +100,7 @@ struct bar_config *default_bar_config(void) {
100 bar->wrap_scroll = false; 100 bar->wrap_scroll = false;
101 bar->separator_symbol = NULL; 101 bar->separator_symbol = NULL;
102 bar->strip_workspace_numbers = false; 102 bar->strip_workspace_numbers = false;
103 bar->strip_workspace_name = false;
103 bar->binding_mode_indicator = true; 104 bar->binding_mode_indicator = true;
104 bar->verbose = false; 105 bar->verbose = false;
105 bar->pid = 0; 106 bar->pid = 0;
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index e3450df1..05e453ec 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -581,6 +581,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
581 json_object_new_boolean(bar->workspace_buttons)); 581 json_object_new_boolean(bar->workspace_buttons));
582 json_object_object_add(json, "strip_workspace_numbers", 582 json_object_object_add(json, "strip_workspace_numbers",
583 json_object_new_boolean(bar->strip_workspace_numbers)); 583 json_object_new_boolean(bar->strip_workspace_numbers));
584 json_object_object_add(json, "strip_workspace_name",
585 json_object_new_boolean(bar->strip_workspace_name));
584 json_object_object_add(json, "binding_mode_indicator", 586 json_object_object_add(json, "binding_mode_indicator",
585 json_object_new_boolean(bar->binding_mode_indicator)); 587 json_object_new_boolean(bar->binding_mode_indicator));
586 json_object_object_add(json, "verbose", 588 json_object_object_add(json, "verbose",
diff --git a/sway/meson.build b/sway/meson.build
index d9bc08f3..14822dbd 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -114,6 +114,7 @@ sway_sources = files(
114 'commands/bar/separator_symbol.c', 114 'commands/bar/separator_symbol.c',
115 'commands/bar/status_command.c', 115 'commands/bar/status_command.c',
116 'commands/bar/strip_workspace_numbers.c', 116 'commands/bar/strip_workspace_numbers.c',
117 'commands/bar/strip_workspace_name.c',
117 'commands/bar/swaybar_command.c', 118 'commands/bar/swaybar_command.c',
118 'commands/bar/tray_output.c', 119 'commands/bar/tray_output.c',
119 'commands/bar/tray_padding.c', 120 'commands/bar/tray_padding.c',
diff --git a/sway/sway-bar.5.scd b/sway/sway-bar.5.scd
index 873741c0..60ee9999 100644
--- a/sway/sway-bar.5.scd
+++ b/sway/sway-bar.5.scd
@@ -50,6 +50,10 @@ Sway allows configuring swaybar in the sway configuration file.
50*workspace\_buttons* yes|no 50*workspace\_buttons* yes|no
51 Enables or disables workspace buttons on the bar. Default is _yes_. 51 Enables or disables workspace buttons on the bar. Default is _yes_.
52 52
53*strip\_workspace\_name* yes|no
54 If set to _yes_, then workspace names will be omitted from the workspace
55 button and only the custom number will be shown. Default is _no_.
56
53*strip\_workspace\_numbers* yes|no 57*strip\_workspace\_numbers* yes|no
54 If set to _yes_, then workspace numbers will be omitted from the workspace 58 If set to _yes_, then workspace numbers will be omitted from the workspace
55 button and only the custom name will be shown. Default is _no_. 59 button and only the custom name will be shown. Default is _no_.
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 08c386a7..2178f542 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -31,6 +31,7 @@ void free_workspaces(struct wl_list *list) {
31 wl_list_for_each_safe(ws, tmp, list, link) { 31 wl_list_for_each_safe(ws, tmp, list, link) {
32 wl_list_remove(&ws->link); 32 wl_list_remove(&ws->link);
33 free(ws->name); 33 free(ws->name);
34 free(ws->label);
34 free(ws); 35 free(ws);
35 } 36 }
36} 37}
diff --git a/swaybar/config.c b/swaybar/config.c
index 0fd1f02e..0ab346b1 100644
--- a/swaybar/config.c
+++ b/swaybar/config.c
@@ -30,6 +30,7 @@ struct swaybar_config *init_config(void) {
30 config->hidden_state = strdup("hide"); 30 config->hidden_state = strdup("hide");
31 config->sep_symbol = NULL; 31 config->sep_symbol = NULL;
32 config->strip_workspace_numbers = false; 32 config->strip_workspace_numbers = false;
33 config->strip_workspace_name = false;
33 config->binding_mode_indicator = true; 34 config->binding_mode_indicator = true;
34 config->wrap_scroll = false; 35 config->wrap_scroll = false;
35 config->workspace_buttons = true; 36 config->workspace_buttons = true;
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index 706f968d..db4360c1 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -153,9 +153,10 @@ static bool ipc_parse_config(
153 return false; 153 return false;
154 } 154 }
155 json_object *markup, *mode, *hidden_state, *position, *status_command; 155 json_object *markup, *mode, *hidden_state, *position, *status_command;
156 json_object *font, *bar_height, *wrap_scroll, *workspace_buttons, *strip_workspace_numbers; 156 json_object *font, *bar_height, *wrap_scroll, *workspace_buttons;
157 json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol, *outputs; 157 json_object *strip_workspace_numbers, *strip_workspace_name;
158 json_object *bindings; 158 json_object *binding_mode_indicator, *verbose, *colors, *sep_symbol;
159 json_object *outputs, *bindings;
159 json_object_object_get_ex(bar_config, "mode", &mode); 160 json_object_object_get_ex(bar_config, "mode", &mode);
160 json_object_object_get_ex(bar_config, "hidden_state", &hidden_state); 161 json_object_object_get_ex(bar_config, "hidden_state", &hidden_state);
161 json_object_object_get_ex(bar_config, "position", &position); 162 json_object_object_get_ex(bar_config, "position", &position);
@@ -165,6 +166,7 @@ static bool ipc_parse_config(
165 json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll); 166 json_object_object_get_ex(bar_config, "wrap_scroll", &wrap_scroll);
166 json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons); 167 json_object_object_get_ex(bar_config, "workspace_buttons", &workspace_buttons);
167 json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers); 168 json_object_object_get_ex(bar_config, "strip_workspace_numbers", &strip_workspace_numbers);
169 json_object_object_get_ex(bar_config, "strip_workspace_name", &strip_workspace_name);
168 json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator); 170 json_object_object_get_ex(bar_config, "binding_mode_indicator", &binding_mode_indicator);
169 json_object_object_get_ex(bar_config, "verbose", &verbose); 171 json_object_object_get_ex(bar_config, "verbose", &verbose);
170 json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol); 172 json_object_object_get_ex(bar_config, "separator_symbol", &sep_symbol);
@@ -190,6 +192,9 @@ static bool ipc_parse_config(
190 if (strip_workspace_numbers) { 192 if (strip_workspace_numbers) {
191 config->strip_workspace_numbers = json_object_get_boolean(strip_workspace_numbers); 193 config->strip_workspace_numbers = json_object_get_boolean(strip_workspace_numbers);
192 } 194 }
195 if (strip_workspace_name) {
196 config->strip_workspace_name = json_object_get_boolean(strip_workspace_name);
197 }
193 if (binding_mode_indicator) { 198 if (binding_mode_indicator) {
194 config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator); 199 config->binding_mode_indicator = json_object_get_boolean(binding_mode_indicator);
195 } 200 }
@@ -298,6 +303,24 @@ bool ipc_get_workspaces(struct swaybar *bar) {
298 calloc(1, sizeof(struct swaybar_workspace)); 303 calloc(1, sizeof(struct swaybar_workspace));
299 ws->num = json_object_get_int(num); 304 ws->num = json_object_get_int(num);
300 ws->name = strdup(json_object_get_string(name)); 305 ws->name = strdup(json_object_get_string(name));
306 ws->label = strdup(ws->name);
307 // ws->num will be -1 if workspace name doesn't begin with int.
308 if (ws->num != -1) {
309 size_t len_offset = numlen(ws->num);
310 if (bar->config->strip_workspace_name) {
311 free(ws->label);
312 ws->label = malloc(len_offset + 1 * sizeof(char));
313 ws->label[len_offset] = '\0';
314 strncpy(ws->label, ws->name, len_offset);
315 } else if (bar->config->strip_workspace_numbers) {
316 len_offset += ws->label[len_offset] == ':';
317 if (strlen(ws->name) > len_offset) {
318 free(ws->label);
319 // Strip number prefix [1-?:] using len_offset.
320 ws->label = strdup(ws->name + len_offset);
321 }
322 }
323 }
301 ws->visible = json_object_get_boolean(visible); 324 ws->visible = json_object_get_boolean(visible);
302 ws->focused = json_object_get_boolean(focused); 325 ws->focused = json_object_get_boolean(focused);
303 if (ws->focused) { 326 if (ws->focused) {
diff --git a/swaybar/render.c b/swaybar/render.c
index 4ebf922e..8269a840 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -342,19 +342,6 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
342 return output->height; 342 return output->height;
343} 343}
344 344
345static const char *strip_workspace_number(const char *ws_name) {
346 size_t len = strlen(ws_name);
347 for (size_t i = 0; i < len; ++i) {
348 if (ws_name[i] < '0' || ws_name[i] > '9') {
349 if (':' == ws_name[i] && i < len - 1 && i > 0) {
350 return ws_name + i + 1;
351 }
352 return ws_name;
353 }
354 }
355 return ws_name;
356}
357
358static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output, 345static enum hotspot_event_handling workspace_hotspot_callback(struct swaybar_output *output,
359 int x, int y, enum x11_button button, void *data) { 346 int x, int y, enum x11_button button, void *data) {
360 if (button != LEFT) { 347 if (button != LEFT) {
@@ -368,11 +355,6 @@ static uint32_t render_workspace_button(cairo_t *cairo,
368 struct swaybar_output *output, 355 struct swaybar_output *output,
369 struct swaybar_workspace *ws, double *x) { 356 struct swaybar_workspace *ws, double *x) {
370 struct swaybar_config *config = output->bar->config; 357 struct swaybar_config *config = output->bar->config;
371 const char *name = ws->name;
372 if (config->strip_workspace_numbers) {
373 name = strip_workspace_number(ws->name);
374 }
375
376 struct box_colors box_colors; 358 struct box_colors box_colors;
377 if (ws->urgent) { 359 if (ws->urgent) {
378 box_colors = config->colors.urgent_workspace; 360 box_colors = config->colors.urgent_workspace;
@@ -388,7 +370,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
388 370
389 int text_width, text_height; 371 int text_width, text_height;
390 get_text_size(cairo, config->font, &text_width, &text_height, NULL, 372 get_text_size(cairo, config->font, &text_width, &text_height, NULL,
391 output->scale, config->pango_markup, "%s", name); 373 output->scale, config->pango_markup, "%s", ws->label);
392 374
393 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; 375 int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
394 int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; 376 int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale;
@@ -421,7 +403,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
421 cairo_set_source_u32(cairo, box_colors.text); 403 cairo_set_source_u32(cairo, box_colors.text);
422 cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y)); 404 cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
423 pango_printf(cairo, config->font, output->scale, config->pango_markup, 405 pango_printf(cairo, config->font, output->scale, config->pango_markup,
424 "%s", name); 406 "%s", ws->label);
425 407
426 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); 408 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
427 hotspot->x = *x; 409 hotspot->x = *x;
diff --git a/swayidle/swayidle.1.scd b/swayidle/swayidle.1.scd
index 3083163f..0e3b5c3c 100644
--- a/swayidle/swayidle.1.scd
+++ b/swayidle/swayidle.1.scd
@@ -49,7 +49,7 @@ swayidle \
49``` 49```
50 50
51This will lock your screen after 300 seconds of inactivity, then turn off your 51This will lock your screen after 300 seconds of inactivity, then turn off your
52displays after another 600 seconds, and turn your screens back on when resumed. 52displays after another 300 seconds, and turn your screens back on when resumed.
53It will also lock your screen before your computer goes to sleep. 53It will also lock your screen before your computer goes to sleep.
54 54
55# AUTHORS 55# AUTHORS