2018-03-29 23:20:03 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/ipc-server.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode) {
|
|
|
|
char *old_mode = bar->mode;
|
|
|
|
if (strcasecmp("toggle", mode) == 0 && !config->reading) {
|
|
|
|
if (strcasecmp("dock", bar->mode) == 0) {
|
|
|
|
bar->mode = strdup("hide");
|
2019-02-10 17:04:12 +01:00
|
|
|
} else{
|
2018-03-29 23:20:03 +02:00
|
|
|
bar->mode = strdup("dock");
|
|
|
|
}
|
|
|
|
} else if (strcasecmp("dock", mode) == 0) {
|
|
|
|
bar->mode = strdup("dock");
|
|
|
|
} else if (strcasecmp("hide", mode) == 0) {
|
|
|
|
bar->mode = strdup("hide");
|
|
|
|
} else if (strcasecmp("invisible", mode) == 0) {
|
|
|
|
bar->mode = strdup("invisible");
|
2019-02-24 06:59:36 +01:00
|
|
|
} else if (strcasecmp("overlay", mode) == 0) {
|
|
|
|
bar->mode = strdup("overlay");
|
2018-03-29 23:20:03 +02:00
|
|
|
} else {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID, "Invalid value %s", mode);
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(old_mode, bar->mode) != 0) {
|
2019-09-03 03:41:11 +02:00
|
|
|
if (!config->current_bar) {
|
2018-03-29 23:20:03 +02:00
|
|
|
ipc_event_barconfig_update(bar);
|
|
|
|
}
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id);
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// free old mode
|
|
|
|
free(old_mode);
|
2018-10-01 00:06:40 +02:00
|
|
|
return NULL;
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cmd_results *bar_cmd_mode(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
|
|
|
if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) {
|
|
|
|
return error;
|
|
|
|
}
|
2018-10-23 11:40:03 +02:00
|
|
|
if ((error = checkarg(argc, "mode", EXPECTED_AT_MOST, 2))) {
|
2018-03-29 23:20:03 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (config->reading && argc > 1) {
|
2018-03-30 04:05:16 +02:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2019-01-11 00:27:21 +01:00
|
|
|
"Unexpected value %s in config mode", argv[1]);
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 03:41:11 +02:00
|
|
|
if (config->current_bar && argc == 2 &&
|
|
|
|
strcmp(config->current_bar->id, argv[1]) != 0) {
|
|
|
|
return cmd_results_new(CMD_INVALID, "Conflicting bar ids: %s and %s",
|
|
|
|
config->current_bar->id, argv[1]);
|
|
|
|
}
|
|
|
|
|
2018-03-29 23:20:03 +02:00
|
|
|
const char *mode = argv[0];
|
2021-11-23 05:52:19 +01:00
|
|
|
if (config->current_bar) {
|
2018-10-01 00:06:40 +02:00
|
|
|
error = bar_set_mode(config->current_bar, mode);
|
|
|
|
} else {
|
|
|
|
const char *id = argc == 2 ? argv[1] : NULL;
|
|
|
|
for (int i = 0; i < config->bars->length; ++i) {
|
|
|
|
struct bar_config *bar = config->bars->items[i];
|
|
|
|
if (id) {
|
|
|
|
if (strcmp(id, bar->id) == 0) {
|
|
|
|
error = bar_set_mode(bar, mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if ((error = bar_set_mode(bar, mode))) {
|
|
|
|
break;
|
|
|
|
}
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-11 00:27:21 +01:00
|
|
|
return error ? error : cmd_results_new(CMD_SUCCESS, NULL);
|
2018-03-29 23:20:03 +02:00
|
|
|
}
|