aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 74b307e6..d6da1de3 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -32,6 +32,7 @@ struct cmd_handler {
32 sway_cmd *handle; 32 sway_cmd *handle;
33}; 33};
34 34
35static sway_cmd cmd_bar;
35static sway_cmd cmd_bindsym; 36static sway_cmd cmd_bindsym;
36static sway_cmd cmd_debuglog; 37static sway_cmd cmd_debuglog;
37static sway_cmd cmd_exec; 38static sway_cmd cmd_exec;
@@ -1099,6 +1100,43 @@ static struct cmd_results *cmd_resize(int argc, char **argv) {
1099 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1100 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1100} 1101}
1101 1102
1103static struct cmd_results *cmd_bar(int argc, char **argv) {
1104 struct cmd_results *error = NULL;
1105 if ((error = checkarg(argc, "bar", EXPECTED_EQUAL_TO, 1))) {
1106 return error;
1107 }
1108
1109 if (strcmp("{", argv[0]) != 0) {
1110 return cmd_results_new(CMD_INVALID, "bar",
1111 "Expected '{' at start of bar config definition.");
1112 }
1113
1114 if (!config->reading) {
1115 return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file.");
1116 }
1117
1118 // Create new bar from default bar config
1119 struct bar_config *bar = NULL;
1120 bar = malloc(sizeof*bar);
1121 bar->mode = strdup(config->bar.mode);
1122 bar->hidden_state = strdup(config->bar.hidden_state);
1123 bar->modifier = config->bar.modifier;
1124 bar->position = config->bar.position;
1125 bar->status_command = strdup(config->bar.status_command);
1126 bar->font = strdup(config->bar.font);
1127 bar->bar_height = config->bar.bar_height;
1128 bar->workspace_buttons = config->bar.workspace_buttons;
1129 bar->strip_workspace_numbers = config->bar.strip_workspace_numbers;
1130 bar->binding_mode_indicator = config->bar.binding_mode_indicator;
1131 bar->tray_padding = config->bar.tray_padding;
1132 list_add(config->bars, bar);
1133
1134 // Set current bar
1135 config->current_bar = bar;
1136 sway_log(L_DEBUG, "Configuring bar");
1137 return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL);
1138}
1139
1102static swayc_t *fetch_view_from_scratchpad() { 1140static swayc_t *fetch_view_from_scratchpad() {
1103 if (sp_index >= scratchpad->length) { 1141 if (sp_index >= scratchpad->length) {
1104 sp_index = 0; 1142 sp_index = 0;
@@ -1446,6 +1484,7 @@ static struct cmd_results *cmd_ws_auto_back_and_forth(int argc, char **argv) {
1446 1484
1447/* Keep alphabetized */ 1485/* Keep alphabetized */
1448static struct cmd_handler handlers[] = { 1486static struct cmd_handler handlers[] = {
1487 { "bar", cmd_bar },
1449 { "bindsym", cmd_bindsym }, 1488 { "bindsym", cmd_bindsym },
1450 { "debuglog", cmd_debuglog }, 1489 { "debuglog", cmd_debuglog },
1451 { "default_orientation", cmd_orientation }, 1490 { "default_orientation", cmd_orientation },
@@ -1505,14 +1544,17 @@ static int handler_compare(const void *_a, const void *_b) {
1505} 1544}
1506 1545
1507static struct cmd_handler *find_handler(char *line, enum cmd_status block) { 1546static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
1508 struct cmd_handler *h = handlers;
1509 if (block == CMD_BLOCK_BAR) {
1510 h = bar_handlers;
1511 }
1512 struct cmd_handler d = { .command=line }; 1547 struct cmd_handler d = { .command=line };
1513 struct cmd_handler *res = bsearch(&d, h, 1548 struct cmd_handler *res = NULL;
1549 if (block == CMD_BLOCK_BAR) {
1550 res = bsearch(&d, bar_handlers,
1551 sizeof(bar_handlers) / sizeof(struct cmd_handler),
1552 sizeof(struct cmd_handler), handler_compare);
1553 } else {
1554 res = bsearch(&d, handlers,
1514 sizeof(handlers) / sizeof(struct cmd_handler), 1555 sizeof(handlers) / sizeof(struct cmd_handler),
1515 sizeof(struct cmd_handler), handler_compare); 1556 sizeof(struct cmd_handler), handler_compare);
1557 }
1516 return res; 1558 return res;
1517} 1559}
1518 1560