From 45b959f601d103c9c308807b55f62f1859556b59 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Mon, 14 Dec 2015 17:07:31 +0100 Subject: [PATCH 1/4] Move numlen(1) to sway/util.c --- include/util.h | 5 +++++ sway/util.c | 10 ++++++++++ swaygrab/main.c | 11 +---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/util.h b/include/util.h index 8e65e6d6..9cb861dd 100644 --- a/include/util.h +++ b/include/util.h @@ -6,4 +6,9 @@ */ int wrap(int i, int max); +/** + * Count number of digits in int + */ +int numlen(int n); + #endif diff --git a/sway/util.c b/sway/util.c index 9a59ddf9..ed6d033f 100644 --- a/sway/util.c +++ b/sway/util.c @@ -3,3 +3,13 @@ int wrap(int i, int max) { return ((i % max) + max) % max; } + +int numlen(int n) { + if (n >= 1000000) return 7; + if (n >= 100000) return 6; + if (n >= 10000) return 5; + if (n >= 1000) return 4; + if (n >= 100) return 3; + if (n >= 10) return 2; + return 1; +} diff --git a/swaygrab/main.c b/swaygrab/main.c index 681a6da4..2c6cf2dd 100644 --- a/swaygrab/main.c +++ b/swaygrab/main.c @@ -8,21 +8,12 @@ #include #include "log.h" #include "ipc-client.h" +#include "util.h" void sway_terminate(void) { exit(EXIT_FAILURE); } -int numlen(int n) { - if (n >= 1000000) return 7; - if (n >= 100000) return 6; - if (n >= 10000) return 5; - if (n >= 1000) return 4; - if (n >= 100) return 3; - if (n >= 10) return 2; - return 1; -} - void grab_and_apply_magick(const char *file, const char *output, int socketfd, int raw) { uint32_t len = strlen(output); From cf56c41c10b85882d7563c95abe185f450b4ec2b Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Mon, 14 Dec 2015 17:16:38 +0100 Subject: [PATCH 2/4] Move sway/util.c to common/util.c --- common/CMakeLists.txt | 1 + {sway => common}/util.c | 0 sway/CMakeLists.txt | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) rename {sway => common}/util.c (100%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index f7d44ec5..a40f096d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -2,6 +2,7 @@ add_library(sway-common ipc-client.c list.c log.c + util.c readline.c stringop.c ) diff --git a/sway/util.c b/common/util.c similarity index 100% rename from sway/util.c rename to common/util.c diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index aa553492..894163b8 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -21,7 +21,6 @@ add_executable(sway main.c output.c resize.c - util.c workspace.c ) From c6b13163c93f7464ae21fa238fadc238b8ef2936 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Mon, 14 Dec 2015 16:24:01 +0100 Subject: [PATCH 3/4] Add initial support for custom bar-id --- include/config.h | 7 +++++++ sway/commands.c | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 04528e27..0f3ce550 100644 --- a/include/config.h +++ b/include/config.h @@ -72,6 +72,13 @@ struct bar_config { * In "show" mode, it will always be shown on top of the active workspace. */ char *hidden_state; + /** + * Id name used to identify the bar through IPC. + * + * Defaults to bar-x, where x corresponds to the position of the + * embedding bar block in the config file (bar-0, bar-1, ...). + */ + char *id; uint32_t modifier; enum desktop_shell_panel_position position; char *status_command; diff --git a/sway/commands.c b/sway/commands.c index b0235dba..ea138dfc 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -15,6 +15,7 @@ #include "layout.h" #include "focus.h" #include "log.h" +#include "util.h" #include "workspace.h" #include "commands.h" #include "container.h" @@ -1124,9 +1125,20 @@ static struct cmd_results *cmd_bar(int argc, char **argv) { bar->tray_padding = config->bar.tray_padding; list_add(config->bars, bar); + // set bar id + int i; + for (i = 0; i < config->bars->length; ++i) { + if (bar == config->bars->items[i]) { + const int len = 5 + numlen(i); // "bar-" + i + \0 + bar->id = malloc(len * sizeof(char)); + snprintf(bar->id, len, "bar-%d", i); + break; + } + } + // Set current bar config->current_bar = bar; - sway_log(L_DEBUG, "Configuring bar"); + sway_log(L_DEBUG, "Configuring bar %s", bar->id); return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); } From 2cedf88273dcec1f79ecb20582c876584db10d36 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Mon, 14 Dec 2015 16:26:59 +0100 Subject: [PATCH 4/4] Add bar id to debug logs --- sway/commands.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index ea138dfc..ba16260f 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1546,7 +1546,7 @@ static struct cmd_results *bar_cmd_position(int argc, char **argv) { return error; } - sway_log(L_DEBUG, "Setting bar position '%s'", argv[0]); + sway_log(L_DEBUG, "Setting bar position '%s' for bar: %s", argv[0], config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -1562,10 +1562,10 @@ static struct cmd_results *bar_cmd_strip_workspace_numbers(int argc, char **argv if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->strip_workspace_numbers = true; - sway_log(L_DEBUG, "Stripping workspace numbers on bar"); + sway_log(L_DEBUG, "Stripping workspace numbers on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->strip_workspace_numbers = false; - sway_log(L_DEBUG, "Enabling workspace numbers on bar"); + sway_log(L_DEBUG, "Enabling workspace numbers on bar: %s", config->current_bar->id); } else { error = cmd_results_new(CMD_INVALID, "strip_workspace_numbers", "Invalid value %s", argv[0]); return error; @@ -1599,7 +1599,7 @@ static struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) { "Unknown unit %s", argv[1]); } config->current_bar->tray_padding = padding; - sway_log(L_DEBUG, "Enabling tray padding of %d px", padding); + sway_log(L_DEBUG, "Enabling tray padding of %d px on bar: %s", padding, config->current_bar->id); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -1615,10 +1615,10 @@ static struct cmd_results *bar_cmd_workspace_buttons(int argc, char **argv) { if (strcasecmp("yes", argv[0]) == 0) { config->current_bar->workspace_buttons = true; - sway_log(L_DEBUG, "Enabling workspace buttons on bar"); + sway_log(L_DEBUG, "Enabling workspace buttons on bar: %s", config->current_bar->id); } else if (strcasecmp("no", argv[0]) == 0) { config->current_bar->workspace_buttons = false; - sway_log(L_DEBUG, "Disabling workspace buttons on bar"); + sway_log(L_DEBUG, "Disabling workspace buttons on bar: %s", config->current_bar->id); } else { error = cmd_results_new(CMD_INVALID, "workspace_buttons", "Invalid value %s", argv[0]); return error;