Add swaybg_command

master
Drew DeVault 7 years ago
parent 569b2bfd5d
commit 5c9cdbcdd2

@ -141,6 +141,7 @@ sway_cmd cmd_splith;
sway_cmd cmd_splitt;
sway_cmd cmd_splitv;
sway_cmd cmd_sticky;
sway_cmd cmd_swaybg_command;
sway_cmd cmd_unmark;
sway_cmd cmd_workspace;
sway_cmd cmd_ws_auto_back_and_forth;

@ -282,6 +282,7 @@ struct sway_config {
list_t *active_bar_modifiers;
struct sway_mode *current_mode;
struct bar_config *current_bar;
char *swaybg_command;
uint32_t floating_mod;
uint32_t dragging_key;
uint32_t resizing_key;

@ -149,6 +149,7 @@ static struct cmd_handler bar_colors_handlers[] = {
/* Config-time only commands. Keep alphabetized */
static struct cmd_handler config_handlers[] = {
{ "set", cmd_set },
{ "swaybg_command", cmd_swaybg_command },
};
/* Runtime-only commands. Keep alphabetized */

@ -0,0 +1,20 @@
#include <string.h>
#include "sway/commands.h"
#include "log.h"
#include "stringop.h"
struct cmd_results *cmd_swaybg_command(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "swaybg_command", EXPECTED_AT_LEAST, 1))) {
return error;
}
if (config->swaybg_command) {
free(config->swaybg_command);
}
config->swaybg_command = join_args(argv, argc);
wlr_log(L_DEBUG, "Using custom swaybg command: %s",
config->swaybg_command);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

@ -180,19 +180,20 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
wlr_log(L_DEBUG, "Setting background for output %d to %s",
output_i, oc->background);
size_t bufsize = 12;
char output_id[bufsize];
snprintf(output_id, bufsize, "%d", output_i);
output_id[bufsize-1] = 0;
char *const cmd[] = {
"swaybg",
output_id,
oc->background,
oc->background_option,
NULL,
};
size_t len = snprintf(NULL, 0, "%s %d %s %s",
config->swaybg_command ? config->swaybg_command : "swaybg",
output_i, oc->background, oc->background_option);
char *command = malloc(len + 1);
if (!command) {
wlr_log(L_DEBUG, "Unable to allocate swaybg command");
return;
}
snprintf(command, len + 1, "%s %d %s %s",
config->swaybg_command ? config->swaybg_command : "swaybg",
output_i, oc->background, oc->background_option);
wlr_log(L_DEBUG, "-> %s", command);
char *const cmd[] = { "sh", "-c", command, NULL };
output->sway_output->bg_pid = fork();
if (output->sway_output->bg_pid == 0) {
execvp(cmd[0], cmd);

@ -20,6 +20,7 @@ sway_sources = files(
'commands/seat/attach.c',
'commands/seat/fallback.c',
'commands/set.c',
'commands/swaybg_command.c',
'commands/bar/activate_button.c',
'commands/bar/binding_mode_indicator.c',
'commands/bar/bindsym.c',

@ -43,6 +43,9 @@ The following commands may only be used in the configuration file.
Sets variable $name to _value_. You can use the new variable in the arguments
of future commands.
**swaybg_command** <command>::
Executes custom bg command, default is _swaybg_.
The following commands cannot be used directly in the configuration file.
They are expected to be used with **bindsym** or at runtime through **swaymsg**(1).

Loading…
Cancel
Save