mirror of
https://github.com/swaywm/sway.git
synced 2024-11-13 05:54:11 +01:00
Implement bar option: id <custom-id>
If the id is defined by another bar it will just use the default id for the bar. Typically `bar-x`. If the id command is used multiple times within a bar block, the last one will 'win'.
This commit is contained in:
parent
2be742d02d
commit
401333e7c7
@ -65,6 +65,7 @@ static sway_cmd cmd_sticky;
|
|||||||
static sway_cmd cmd_workspace;
|
static sway_cmd cmd_workspace;
|
||||||
static sway_cmd cmd_ws_auto_back_and_forth;
|
static sway_cmd cmd_ws_auto_back_and_forth;
|
||||||
|
|
||||||
|
static sway_cmd bar_cmd_id;
|
||||||
static sway_cmd bar_cmd_position;
|
static sway_cmd bar_cmd_position;
|
||||||
static sway_cmd bar_cmd_strip_workspace_numbers;
|
static sway_cmd bar_cmd_strip_workspace_numbers;
|
||||||
static sway_cmd bar_cmd_tray_output;
|
static sway_cmd bar_cmd_tray_output;
|
||||||
@ -1523,6 +1524,35 @@ static struct cmd_handler handlers[] = {
|
|||||||
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
|
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct cmd_results *bar_cmd_id(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "id", EXPECTED_EQUAL_TO, 1))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *name = argv[0];
|
||||||
|
const char *oldname = config->current_bar->id;
|
||||||
|
|
||||||
|
// check if id is used by a previously defined bar
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < config->bars->length; ++i) {
|
||||||
|
struct bar_config *find = config->bars->items[i];
|
||||||
|
if (strcmp(name, find->id) == 0 && config->current_bar != find) {
|
||||||
|
return cmd_results_new(CMD_FAILURE, "id",
|
||||||
|
"Id '%s' already defined for another bar. Id unchanged (%s).",
|
||||||
|
name, oldname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sway_log(L_DEBUG, "Renaming bar: '%s' to '%s'", oldname, name);
|
||||||
|
|
||||||
|
// free old bar id
|
||||||
|
free(config->current_bar->id);
|
||||||
|
|
||||||
|
config->current_bar->id = strdup(name);
|
||||||
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
static struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
|
if ((error = checkarg(argc, "position", EXPECTED_EQUAL_TO, 1))) {
|
||||||
@ -1632,7 +1662,7 @@ static struct cmd_handler bar_handlers[] = {
|
|||||||
{ "colors", NULL },
|
{ "colors", NULL },
|
||||||
{ "font", NULL },
|
{ "font", NULL },
|
||||||
{ "hidden_state", NULL },
|
{ "hidden_state", NULL },
|
||||||
{ "id", NULL },
|
{ "id", bar_cmd_id },
|
||||||
{ "mode", NULL },
|
{ "mode", NULL },
|
||||||
{ "modifier", NULL },
|
{ "modifier", NULL },
|
||||||
{ "output", NULL },
|
{ "output", NULL },
|
||||||
|
Loading…
Reference in New Issue
Block a user