aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 17:20:03 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commitbf7a4cd0ebd465a0597e9eec0142fad222b396de (patch)
treef95c4b8cd8e7d06eaa1b688d3bcbb3249dc21129 /sway/commands.c
parentImplement enough IPC for swaybar to work (diff)
downloadsway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.gz
sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.tar.zst
sway-bf7a4cd0ebd465a0597e9eec0142fad222b396de.zip
Add bar configuration commands
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c135
1 files changed, 86 insertions, 49 deletions
diff --git a/sway/commands.c b/sway/commands.c
index b52eb200..8d8b643b 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -91,45 +91,9 @@ void apply_seat_config(struct seat_config *seat) {
91 sway_input_manager_apply_seat_config(input_manager, seat); 91 sway_input_manager_apply_seat_config(input_manager, seat);
92} 92}
93 93
94/** 94/* Keep alphabetized */
95 * Check and add color to buffer.
96 *
97 * return error object, or NULL if color is valid.
98 */
99struct cmd_results *add_color(const char *name, char *buffer, const char *color) {
100 int len = strlen(color);
101 if (len != 7 && len != 9) {
102 return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
103 }
104
105 if (color[0] != '#') {
106 return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
107 }
108
109 int i;
110 for (i = 1; i < len; ++i) {
111 if (!isxdigit(color[i])) {
112 return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
113 }
114 }
115
116 // copy color to buffer
117 strncpy(buffer, color, len);
118 // add default alpha channel if color was defined without it
119 if (len == 7) {
120 buffer[7] = 'f';
121 buffer[8] = 'f';
122 }
123 buffer[9] = '\0';
124
125 return NULL;
126}
127
128/**
129 * handlers that can run in either config or command context
130 * Keep alphabetized
131 */
132static struct cmd_handler handlers[] = { 95static struct cmd_handler handlers[] = {
96 { "bar", cmd_bar },
133 { "bindcode", cmd_bindcode }, 97 { "bindcode", cmd_bindcode },
134 { "bindsym", cmd_bindsym }, 98 { "bindsym", cmd_bindsym },
135 { "exec", cmd_exec }, 99 { "exec", cmd_exec },
@@ -141,18 +105,53 @@ static struct cmd_handler handlers[] = {
141 { "workspace", cmd_workspace }, 105 { "workspace", cmd_workspace },
142}; 106};
143 107
144/** 108static struct cmd_handler bar_handlers[] = {
145 * Commands that can *only* run in the config loading context 109 { "activate_button", bar_cmd_activate_button },
146 * Keep alphabetized 110 { "binding_mode_indicator", bar_cmd_binding_mode_indicator },
147 */ 111 { "bindsym", bar_cmd_bindsym },
112 { "colors", bar_cmd_colors },
113 { "context_button", bar_cmd_context_button },
114 { "font", bar_cmd_font },
115 { "height", bar_cmd_height },
116 { "hidden_state", bar_cmd_hidden_state },
117 { "icon_theme", bar_cmd_icon_theme },
118 { "id", bar_cmd_id },
119 { "mode", bar_cmd_mode },
120 { "modifier", bar_cmd_modifier },
121 { "output", bar_cmd_output },
122 { "pango_markup", bar_cmd_pango_markup },
123 { "position", bar_cmd_position },
124 { "secondary_button", bar_cmd_secondary_button },
125 { "separator_symbol", bar_cmd_separator_symbol },
126 { "status_command", bar_cmd_status_command },
127 { "strip_workspace_numbers", bar_cmd_strip_workspace_numbers },
128 { "swaybar_command", bar_cmd_swaybar_command },
129 { "tray_output", bar_cmd_tray_output },
130 { "tray_padding", bar_cmd_tray_padding },
131 { "workspace_buttons", bar_cmd_workspace_buttons },
132 { "wrap_scroll", bar_cmd_wrap_scroll },
133};
134
135static struct cmd_handler bar_colors_handlers[] = {
136 { "active_workspace", bar_colors_cmd_active_workspace },
137 { "background", bar_colors_cmd_background },
138 { "binding_mode", bar_colors_cmd_binding_mode },
139 { "focused_background", bar_colors_cmd_focused_background },
140 { "focused_separator", bar_colors_cmd_focused_separator },
141 { "focused_statusline", bar_colors_cmd_focused_statusline },
142 { "focused_workspace", bar_colors_cmd_focused_workspace },
143 { "inactive_workspace", bar_colors_cmd_inactive_workspace },
144 { "separator", bar_colors_cmd_separator },
145 { "statusline", bar_colors_cmd_statusline },
146 { "urgent_workspace", bar_colors_cmd_urgent_workspace },
147};
148
149/* Config-time only commands. Keep alphabetized */
148static struct cmd_handler config_handlers[] = { 150static struct cmd_handler config_handlers[] = {
149 { "set", cmd_set }, 151 { "set", cmd_set },
150}; 152};
151 153
152/** 154/* Runtime-only commands. Keep alphabetized */
153 * Commands that can *not* run in the config loading context
154 * Keep alphabetized
155 */
156static struct cmd_handler command_handlers[] = { 155static struct cmd_handler command_handlers[] = {
157 { "exit", cmd_exit }, 156 { "exit", cmd_exit },
158 { "focus", cmd_focus }, 157 { "focus", cmd_focus },
@@ -200,13 +199,19 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
200 199
201 bool config_loading = config->reading || !config->active; 200 bool config_loading = config->reading || !config->active;
202 201
203 if (block == CMD_BLOCK_INPUT) { 202 if (block == CMD_BLOCK_BAR) {
204 // input commands can run in either context 203 return bsearch(&d, bar_handlers,
204 sizeof(bar_handlers) / sizeof(struct cmd_handler),
205 sizeof(struct cmd_handler), handler_compare);
206 } else if (block == CMD_BLOCK_BAR_COLORS) {
207 return bsearch(&d, bar_colors_handlers,
208 sizeof(bar_colors_handlers) / sizeof(struct cmd_handler),
209 sizeof(struct cmd_handler), handler_compare);
210 } else if (block == CMD_BLOCK_INPUT) {
205 return bsearch(&d, input_handlers, 211 return bsearch(&d, input_handlers,
206 sizeof(input_handlers) / sizeof(struct cmd_handler), 212 sizeof(input_handlers) / sizeof(struct cmd_handler),
207 sizeof(struct cmd_handler), handler_compare); 213 sizeof(struct cmd_handler), handler_compare);
208 } else if (block == CMD_BLOCK_SEAT) { 214 } else if (block == CMD_BLOCK_SEAT) {
209 // seat commands can run in either context
210 return bsearch(&d, seat_handlers, 215 return bsearch(&d, seat_handlers,
211 sizeof(seat_handlers) / sizeof(struct cmd_handler), 216 sizeof(seat_handlers) / sizeof(struct cmd_handler),
212 sizeof(struct cmd_handler), handler_compare); 217 sizeof(struct cmd_handler), handler_compare);
@@ -558,3 +563,35 @@ const char *cmd_results_to_json(struct cmd_results *results) {
558 free(root); 563 free(root);
559 return json; 564 return json;
560} 565}
566
567/**
568 * Check and add color to buffer.
569 *
570 * return error object, or NULL if color is valid.
571 */
572struct cmd_results *add_color(const char *name,
573 char *buffer, const char *color) {
574 int len = strlen(color);
575 if (len != 7 && len != 9) {
576 return cmd_results_new(CMD_INVALID, name,
577 "Invalid color definition %s", color);
578 }
579 if (color[0] != '#') {
580 return cmd_results_new(CMD_INVALID, name,
581 "Invalid color definition %s", color);
582 }
583 for (int i = 1; i < len; ++i) {
584 if (!isxdigit(color[i])) {
585 return cmd_results_new(CMD_INVALID, name,
586 "Invalid color definition %s", color);
587 }
588 }
589 strncpy(buffer, color, len);
590 // add default alpha channel if color was defined without it
591 if (len == 7) {
592 buffer[7] = 'f';
593 buffer[8] = 'f';
594 }
595 buffer[9] = '\0';
596 return NULL;
597}