output/background: parse background mode into enum #8564
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change parses the background mode in the
output ... background ...
command instead of validating the mode string and then copying it around. Doing so avoids a number ofstrdup()
calls and associatedfree()
s, making the logic and failure handling paths inoutput_cmd_background()
somewhat easier to follow.It turns out this change also fixes a mismatch between the way the background subcommand parsed modes (case insensitively) and the way
swaybg
does (exact match). Previously bothwould be accepted by
sway
, butswaybg
would only use the centering mode on the first image, and would print a warning on the second.Notes:
enum background_mode
is AFAIK the first enum without a real_DEFAULT
behavior, so I've named the null case_UNSET
. Is there an existing convention for this?background_mode_names
table is used insway/commands/output/background.c
(for parsing) andsway/config/output.c
(debug output andspawn_swaybg()
); I've put it in the former file, but am not certain about the right place for it.spawn_swaybg()
, which currently allocates an array of pointers to strings with a longer lifespan -- parsing and then reprinting colors would require temporary allocations or per-output_config scratch space to hold the colors. There are other solutions, but none I've found to be clean and simple so far.Edit: looks like there are compile werrors becauseEdit 2: fixed,execvp
takeschar *const argv[]
, notconst char *const argv[]
; I may need to rethink this, depending on what execvp does.execvp
does not modify its input and its signature is constrained by history per Rationale section of man 3p execvp.