sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 2be742d02d8dd26e111713d9bb52cd240d7d630b
parent 89025facbf900d4f14ccd83af95c93d2358578cf
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 14 Dec 2015 11:25:31 -0500

Merge pull request #314 from mikkeloscar/bar-id

Add initial support for custom bar-id
Diffstat:
Mcommon/CMakeLists.txt | 1+
Acommon/util.c | 15+++++++++++++++
Minclude/config.h | 7+++++++
Minclude/util.h | 5+++++
Msway/CMakeLists.txt | 1-
Msway/commands.c | 26+++++++++++++++++++-------
Dsway/util.c | 5-----
Mswaygrab/main.c | 11+----------
8 files changed, 48 insertions(+), 23 deletions(-)

diff --git 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/common/util.c b/common/util.c @@ -0,0 +1,15 @@ +#include "util.h" + +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/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/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/CMakeLists.txt b/sway/CMakeLists.txt @@ -21,7 +21,6 @@ add_executable(sway main.c output.c resize.c - util.c workspace.c ) diff --git 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); } @@ -1534,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); } @@ -1550,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; @@ -1587,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); } @@ -1603,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; diff --git a/sway/util.c b/sway/util.c @@ -1,5 +0,0 @@ -#include "util.h" - -int wrap(int i, int max) { - return ((i % max) + max) % max; -} diff --git a/swaygrab/main.c b/swaygrab/main.c @@ -8,21 +8,12 @@ #include <time.h> #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);