aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 17:49:44 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit5c9cdbcdd2a07e2ced7b60d629a3e20bd7c8bf68 (patch)
tree08a5de486cfceb091b5b1faa5e8ea893bea1de57
parentMove bar config into its own file (diff)
downloadsway-5c9cdbcdd2a07e2ced7b60d629a3e20bd7c8bf68.tar.gz
sway-5c9cdbcdd2a07e2ced7b60d629a3e20bd7c8bf68.tar.zst
sway-5c9cdbcdd2a07e2ced7b60d629a3e20bd7c8bf68.zip
Add swaybg_command
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/swaybg_command.c20
-rw-r--r--sway/config/output.c25
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.txt3
7 files changed, 40 insertions, 12 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index dda286a2..1291d5fb 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -141,6 +141,7 @@ sway_cmd cmd_splith;
141sway_cmd cmd_splitt; 141sway_cmd cmd_splitt;
142sway_cmd cmd_splitv; 142sway_cmd cmd_splitv;
143sway_cmd cmd_sticky; 143sway_cmd cmd_sticky;
144sway_cmd cmd_swaybg_command;
144sway_cmd cmd_unmark; 145sway_cmd cmd_unmark;
145sway_cmd cmd_workspace; 146sway_cmd cmd_workspace;
146sway_cmd cmd_ws_auto_back_and_forth; 147sway_cmd cmd_ws_auto_back_and_forth;
diff --git a/include/sway/config.h b/include/sway/config.h
index dbcfc91e..4a7fee0f 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -282,6 +282,7 @@ struct sway_config {
282 list_t *active_bar_modifiers; 282 list_t *active_bar_modifiers;
283 struct sway_mode *current_mode; 283 struct sway_mode *current_mode;
284 struct bar_config *current_bar; 284 struct bar_config *current_bar;
285 char *swaybg_command;
285 uint32_t floating_mod; 286 uint32_t floating_mod;
286 uint32_t dragging_key; 287 uint32_t dragging_key;
287 uint32_t resizing_key; 288 uint32_t resizing_key;
diff --git a/sway/commands.c b/sway/commands.c
index 8d8b643b..38e2f764 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -149,6 +149,7 @@ static struct cmd_handler bar_colors_handlers[] = {
149/* Config-time only commands. Keep alphabetized */ 149/* Config-time only commands. Keep alphabetized */
150static struct cmd_handler config_handlers[] = { 150static struct cmd_handler config_handlers[] = {
151 { "set", cmd_set }, 151 { "set", cmd_set },
152 { "swaybg_command", cmd_swaybg_command },
152}; 153};
153 154
154/* Runtime-only commands. Keep alphabetized */ 155/* Runtime-only commands. Keep alphabetized */
diff --git a/sway/commands/swaybg_command.c b/sway/commands/swaybg_command.c
new file mode 100644
index 00000000..770d4821
--- /dev/null
+++ b/sway/commands/swaybg_command.c
@@ -0,0 +1,20 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "log.h"
4#include "stringop.h"
5
6struct cmd_results *cmd_swaybg_command(int argc, char **argv) {
7 struct cmd_results *error = NULL;
8 if ((error = checkarg(argc, "swaybg_command", EXPECTED_AT_LEAST, 1))) {
9 return error;
10 }
11
12 if (config->swaybg_command) {
13 free(config->swaybg_command);
14 }
15 config->swaybg_command = join_args(argv, argc);
16 wlr_log(L_DEBUG, "Using custom swaybg command: %s",
17 config->swaybg_command);
18
19 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
20}
diff --git a/sway/config/output.c b/sway/config/output.c
index 24b4a18e..c3ec61b7 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -180,19 +180,20 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
180 wlr_log(L_DEBUG, "Setting background for output %d to %s", 180 wlr_log(L_DEBUG, "Setting background for output %d to %s",
181 output_i, oc->background); 181 output_i, oc->background);
182 182
183 size_t bufsize = 12; 183 size_t len = snprintf(NULL, 0, "%s %d %s %s",
184 char output_id[bufsize]; 184 config->swaybg_command ? config->swaybg_command : "swaybg",
185 snprintf(output_id, bufsize, "%d", output_i); 185 output_i, oc->background, oc->background_option);
186 output_id[bufsize-1] = 0; 186 char *command = malloc(len + 1);
187 187 if (!command) {
188 char *const cmd[] = { 188 wlr_log(L_DEBUG, "Unable to allocate swaybg command");
189 "swaybg", 189 return;
190 output_id, 190 }
191 oc->background, 191 snprintf(command, len + 1, "%s %d %s %s",
192 oc->background_option, 192 config->swaybg_command ? config->swaybg_command : "swaybg",
193 NULL, 193 output_i, oc->background, oc->background_option);
194 }; 194 wlr_log(L_DEBUG, "-> %s", command);
195 195
196 char *const cmd[] = { "sh", "-c", command, NULL };
196 output->sway_output->bg_pid = fork(); 197 output->sway_output->bg_pid = fork();
197 if (output->sway_output->bg_pid == 0) { 198 if (output->sway_output->bg_pid == 0) {
198 execvp(cmd[0], cmd); 199 execvp(cmd[0], cmd);
diff --git a/sway/meson.build b/sway/meson.build
index ac65d05e..54c03061 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -20,6 +20,7 @@ sway_sources = files(
20 'commands/seat/attach.c', 20 'commands/seat/attach.c',
21 'commands/seat/fallback.c', 21 'commands/seat/fallback.c',
22 'commands/set.c', 22 'commands/set.c',
23 'commands/swaybg_command.c',
23 'commands/bar/activate_button.c', 24 'commands/bar/activate_button.c',
24 'commands/bar/binding_mode_indicator.c', 25 'commands/bar/binding_mode_indicator.c',
25 'commands/bar/bindsym.c', 26 'commands/bar/bindsym.c',
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 6c9bce7a..900e499a 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -43,6 +43,9 @@ The following commands may only be used in the configuration file.
43 Sets variable $name to _value_. You can use the new variable in the arguments 43 Sets variable $name to _value_. You can use the new variable in the arguments
44 of future commands. 44 of future commands.
45 45
46**swaybg_command** <command>::
47 Executes custom bg command, default is _swaybg_.
48
46The following commands cannot be used directly in the configuration file. 49The following commands cannot be used directly in the configuration file.
47They are expected to be used with **bindsym** or at runtime through **swaymsg**(1). 50They are expected to be used with **bindsym** or at runtime through **swaymsg**(1).
48 51