Add swaybg_command

This commit is contained in:
Drew DeVault 2018-03-29 17:49:44 -04:00
parent 569b2bfd5d
commit 5c9cdbcdd2
7 changed files with 40 additions and 12 deletions

View file

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

View file

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

View file

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

View file

@ -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);
}

View file

@ -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", wlr_log(L_DEBUG, "Setting background for output %d to %s",
output_i, oc->background); output_i, oc->background);
size_t bufsize = 12; size_t len = snprintf(NULL, 0, "%s %d %s %s",
char output_id[bufsize]; config->swaybg_command ? config->swaybg_command : "swaybg",
snprintf(output_id, bufsize, "%d", output_i); output_i, oc->background, oc->background_option);
output_id[bufsize-1] = 0; char *command = malloc(len + 1);
if (!command) {
char *const cmd[] = { wlr_log(L_DEBUG, "Unable to allocate swaybg command");
"swaybg", return;
output_id, }
oc->background, snprintf(command, len + 1, "%s %d %s %s",
oc->background_option, config->swaybg_command ? config->swaybg_command : "swaybg",
NULL, 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(); output->sway_output->bg_pid = fork();
if (output->sway_output->bg_pid == 0) { if (output->sway_output->bg_pid == 0) {
execvp(cmd[0], cmd); execvp(cmd[0], cmd);

View file

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

View file

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