diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-14 02:39:24 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2015-12-14 12:56:45 +0100 |
commit | 74152043f4da7182339f181317960aa6cd01cffa (patch) | |
tree | 5baaf0a8650cc376cc53dcacefca00f6af626537 | |
parent | Fix rendering of borders on workspaces (swaybar) (diff) | |
download | sway-74152043f4da7182339f181317960aa6cd01cffa.tar.gz sway-74152043f4da7182339f181317960aa6cd01cffa.tar.zst sway-74152043f4da7182339f181317960aa6cd01cffa.zip |
Implement 'bar { }' block parsing
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 52 | ||||
-rw-r--r-- | sway/config.c | 29 |
3 files changed, 79 insertions, 5 deletions
diff --git a/include/config.h b/include/config.h index 4019f479..4e62ee68 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -77,6 +77,7 @@ struct bar_config { | |||
77 | char *status_command; | 77 | char *status_command; |
78 | char *font; | 78 | char *font; |
79 | int bar_height; | 79 | int bar_height; |
80 | int tray_padding; | ||
80 | bool workspace_buttons; | 81 | bool workspace_buttons; |
81 | bool strip_workspace_numbers; | 82 | bool strip_workspace_numbers; |
82 | bool binding_mode_indicator; | 83 | bool binding_mode_indicator; |
@@ -102,12 +103,14 @@ struct bar_config { | |||
102 | struct sway_config { | 103 | struct sway_config { |
103 | list_t *symbols; | 104 | list_t *symbols; |
104 | list_t *modes; | 105 | list_t *modes; |
106 | list_t *bars; | ||
105 | list_t *cmd_queue; | 107 | list_t *cmd_queue; |
106 | list_t *workspace_outputs; | 108 | list_t *workspace_outputs; |
107 | list_t *output_configs; | 109 | list_t *output_configs; |
108 | list_t *criteria; | 110 | list_t *criteria; |
109 | struct sway_mode *current_mode; | 111 | struct sway_mode *current_mode; |
110 | struct bar_config bar; | 112 | struct bar_config bar; |
113 | struct bar_config *current_bar; | ||
111 | uint32_t floating_mod; | 114 | uint32_t floating_mod; |
112 | uint32_t dragging_key; | 115 | uint32_t dragging_key; |
113 | uint32_t resizing_key; | 116 | uint32_t resizing_key; |
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 | ||
35 | static sway_cmd cmd_bar; | ||
35 | static sway_cmd cmd_bindsym; | 36 | static sway_cmd cmd_bindsym; |
36 | static sway_cmd cmd_debuglog; | 37 | static sway_cmd cmd_debuglog; |
37 | static sway_cmd cmd_exec; | 38 | static 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 | ||
1103 | static 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 | |||
1102 | static swayc_t *fetch_view_from_scratchpad() { | 1140 | static 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 */ |
1448 | static struct cmd_handler handlers[] = { | 1486 | static 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 | ||
1507 | static struct cmd_handler *find_handler(char *line, enum cmd_status block) { | 1546 | static 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 | ||
diff --git a/sway/config.c b/sway/config.c index 6c22556f..d5b75adf 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -38,6 +38,14 @@ static void free_mode(struct sway_mode *mode) { | |||
38 | free(mode); | 38 | free(mode); |
39 | } | 39 | } |
40 | 40 | ||
41 | static void free_bar(struct bar_config *bar) { | ||
42 | free(bar->mode); | ||
43 | free(bar->hidden_state); | ||
44 | free(bar->status_command); | ||
45 | free(bar->font); | ||
46 | free(bar); | ||
47 | } | ||
48 | |||
41 | void free_output_config(struct output_config *oc) { | 49 | void free_output_config(struct output_config *oc) { |
42 | free(oc->name); | 50 | free(oc->name); |
43 | free(oc); | 51 | free(oc); |
@@ -61,6 +69,11 @@ static void free_config(struct sway_config *config) { | |||
61 | } | 69 | } |
62 | list_free(config->modes); | 70 | list_free(config->modes); |
63 | 71 | ||
72 | for (i = 0; i < config->bars->length; ++i) { | ||
73 | free_bar(config->bars->items[i]); | ||
74 | } | ||
75 | list_free(config->bars); | ||
76 | |||
64 | free_flat_list(config->cmd_queue); | 77 | free_flat_list(config->cmd_queue); |
65 | 78 | ||
66 | for (i = 0; i < config->workspace_outputs->length; ++i) { | 79 | for (i = 0; i < config->workspace_outputs->length; ++i) { |
@@ -88,6 +101,7 @@ static bool file_exists(const char *path) { | |||
88 | static void config_defaults(struct sway_config *config) { | 101 | static void config_defaults(struct sway_config *config) { |
89 | config->symbols = create_list(); | 102 | config->symbols = create_list(); |
90 | config->modes = create_list(); | 103 | config->modes = create_list(); |
104 | config->bars = create_list(); | ||
91 | config->workspace_outputs = create_list(); | 105 | config->workspace_outputs = create_list(); |
92 | config->criteria = create_list(); | 106 | config->criteria = create_list(); |
93 | config->output_configs = create_list(); | 107 | config->output_configs = create_list(); |
@@ -248,11 +262,26 @@ bool read_config(FILE *file, bool is_active) { | |||
248 | } | 262 | } |
249 | break; | 263 | break; |
250 | 264 | ||
265 | case CMD_BLOCK_BAR: | ||
266 | if (block == CMD_BLOCK_END) { | ||
267 | block = CMD_BLOCK_BAR; | ||
268 | } else { | ||
269 | sway_log(L_ERROR, "Invalid block '%s'", line); | ||
270 | } | ||
271 | break; | ||
272 | |||
251 | case CMD_BLOCK_END: | 273 | case CMD_BLOCK_END: |
252 | switch(block) { | 274 | switch(block) { |
253 | case CMD_BLOCK_MODE: | 275 | case CMD_BLOCK_MODE: |
254 | sway_log(L_DEBUG, "End of mode block"); | 276 | sway_log(L_DEBUG, "End of mode block"); |
255 | config->current_mode = config->modes->items[0]; | 277 | config->current_mode = config->modes->items[0]; |
278 | block = CMD_BLOCK_END; | ||
279 | break; | ||
280 | |||
281 | case CMD_BLOCK_BAR: | ||
282 | sway_log(L_DEBUG, "End of bar block"); | ||
283 | config->current_bar = NULL; | ||
284 | block = CMD_BLOCK_END; | ||
256 | break; | 285 | break; |
257 | 286 | ||
258 | case CMD_BLOCK_END: | 287 | case CMD_BLOCK_END: |