aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-04 22:24:34 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-05 10:08:00 -0400
commit067fe9d0472ca24328a962e8704d4e843f2a8af1 (patch)
tree2ea56856183e855ca2681834d21516b2c2351341
parentMerge pull request #2095 from emersion/fullscreen-damage-only-visible (diff)
downloadsway-067fe9d0472ca24328a962e8704d4e843f2a8af1.tar.gz
sway-067fe9d0472ca24328a962e8704d4e843f2a8af1.tar.zst
sway-067fe9d0472ca24328a962e8704d4e843f2a8af1.zip
Support runtime var expansion and set at runtime
-rw-r--r--sway/commands.c9
-rw-r--r--sway/config.c8
-rw-r--r--sway/tree/workspace.c4
3 files changed, 19 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 3a86ae53..464c9932 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -112,6 +112,7 @@ static struct cmd_handler handlers[] = {
112 { "mouse_warping", cmd_mouse_warping }, 112 { "mouse_warping", cmd_mouse_warping },
113 { "output", cmd_output }, 113 { "output", cmd_output },
114 { "seat", cmd_seat }, 114 { "seat", cmd_seat },
115 { "set", cmd_set },
115 { "show_marks", cmd_show_marks }, 116 { "show_marks", cmd_show_marks },
116 { "workspace", cmd_workspace }, 117 { "workspace", cmd_workspace },
117 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, 118 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
@@ -120,7 +121,6 @@ static struct cmd_handler handlers[] = {
120/* Config-time only commands. Keep alphabetized */ 121/* Config-time only commands. Keep alphabetized */
121static struct cmd_handler config_handlers[] = { 122static struct cmd_handler config_handlers[] = {
122 { "default_orientation", cmd_default_orientation }, 123 { "default_orientation", cmd_default_orientation },
123 { "set", cmd_set },
124 { "swaybg_command", cmd_swaybg_command }, 124 { "swaybg_command", cmd_swaybg_command },
125 { "workspace_layout", cmd_workspace_layout }, 125 { "workspace_layout", cmd_workspace_layout },
126}; 126};
@@ -270,6 +270,13 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
270 goto cleanup; 270 goto cleanup;
271 } 271 }
272 272
273 // Var replacement, for all but first argument of set
274 for (int i = handler->handle == cmd_set ? 2 : 1; i < argc; ++i) {
275 argv[i] = do_var_replacement(argv[i]);
276 unescape_string(argv[i]);
277 strip_quotes(argv[i]);
278 }
279
273 if (!config->handler_context.using_criteria) { 280 if (!config->handler_context.using_criteria) {
274 // without criteria, the command acts upon the focused 281 // without criteria, the command acts upon the focused
275 // container 282 // container
diff --git a/sway/config.c b/sway/config.c
index 445c3d55..f382eefa 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -657,6 +657,14 @@ char *do_var_replacement(char *str) {
657 continue; 657 continue;
658 } 658 }
659 } 659 }
660 // Unescape double $ and move on
661 if (find[1] == '$') {
662 size_t length = strlen(find + 1);
663 strncpy(find, find + 1, length);
664 find[length] = '\0';
665 find += 2;
666 continue;
667 }
660 // Find matching variable 668 // Find matching variable
661 for (i = 0; i < config->symbols->length; ++i) { 669 for (i = 0; i < config->symbols->length; ++i) {
662 struct sway_variable *var = config->symbols->items[i]; 670 struct sway_variable *var = config->symbols->items[i];
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index f78ae9a5..3c42e259 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -128,12 +128,14 @@ char *workspace_next_name(const char *output_name) {
128 } 128 }
129 129
130 if (strcmp("workspace", cmd) == 0 && name) { 130 if (strcmp("workspace", cmd) == 0 && name) {
131 wlr_log(L_DEBUG, "Got valid workspace command for target: '%s'", name);
132 char *_target = strdup(name); 131 char *_target = strdup(name);
132 _target = do_var_replacement(_target);
133 strip_quotes(_target); 133 strip_quotes(_target);
134 while (isspace(*_target)) { 134 while (isspace(*_target)) {
135 memmove(_target, _target+1, strlen(_target+1)); 135 memmove(_target, _target+1, strlen(_target+1));
136 } 136 }
137 wlr_log(L_DEBUG, "Got valid workspace command for target: '%s'",
138 _target);
137 139
138 // Make sure that the command references an actual workspace 140 // Make sure that the command references an actual workspace
139 // not a command about workspaces 141 // not a command about workspaces