Hi!
This patch adds support for variables for output names to kanshi. This
allows setting short readable names for long output names that would
otherwise be pretty unreadable and makes longer configs much more
readable.
This is accomplished by adding a new directive `set $variable "variable
value"` and a list of variables in the `kanshi_config` struct. Each time
an output name is parsed in `parse_profile_output()`, if the name starts
with a dollar sign, the value of the variable with that name is used
instead.
There is currently no way to escape the dollar sign for outputs whose
name starts with a dollar sign, but I have never actually seen that in
practice. If support for escaping the dollar sign is required for you to
accept this feature, I will add it in V3 of this patch series.
Changes since V1: adjusted to use the libscfg parser
This patch set implements https://todo.sr.ht/~emersion/kanshi/106
Ferdinand "yrlf" Bachmann
Ferdinand Bachmann (1):
Add support for setting output name variables
doc/kanshi.5.scd | 3 +++
include/config.h | 7 +++++
parser.c | 68 ++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 73 insertions(+), 5 deletions(-)
--
2.38.5
kanshi/patches/.build.yml: FAILED in 22s
[Add support for setting output name variables][0] v2 from [~yrlf][1]
[0]: https://lists.sr.ht/~emersion/public-inbox/patches/49136
[1]: mailto:me@yrlf.at
✗ #1142222 FAILED kanshi/patches/.build.yml https://builds.sr.ht/~emersion/job/1142222
Sorry for the delay.
I think finding a solution to this use-case is definitely a good idea,
but I'm wondering what the best solution is.
A generic "set" command makes it sound like this will work just like
regular variable substitution, with features we don't really need such
as replacement of a part of the output name, and replacement throughout
the whole config file (not just for the output name). One may expect the
following to "work", but it won't, and won't print any obvious error:
set $foo bar
profile {
output "$foo 4242" mode 1920x1080
exec "echo $foo"
}
Maybe a less surprising syntax would be to have a dedicated way to setup
an output alias?
output DP-1 alias main
profile {
output main mode 1920x1080
}
Something surprising would be that the "output" command syntax would be
different inside and outside the "profile" directive. (That said, it may
be desirable to make the syntax outside of the "profile" directive a
superset of the syntax inside, so that defaults can be set -- but this
requires more thought.)
I can try implementing the 'output X alias Y' syntax and see how that
works out. The output alias directive should IMO only be recognized on
the top level, outside any profiles.
The output defaults on the top level is an interesting idea. This could
be useful in the future for things like setting a default mode and scale
for specific outputs so that profiles don't need to repeat themselves.
An alternative to overloading the "output" syntax would be to do it the
other way round and have a dedicated alias command, though I'm not sure
if that would be better. I think I'll go forward with implementing
'output X alias Y' on the top level first.
kanshi/patches/.build.yml: FAILED in 22s
[Add support for setting output name variables][0] v2 from [~yrlf][1]
[0]: https://lists.sr.ht/~emersion/public-inbox/patches/49136
[1]: mailto:me@yrlf.at
✗ #1142222 FAILED kanshi/patches/.build.yml https://builds.sr.ht/~emersion/job/1142222
Sorry for the delay.
I think finding a solution to this use-case is definitely a good idea,
but I'm wondering what the best solution is.
A generic "set" command makes it sound like this will work just like
regular variable substitution, with features we don't really need such
as replacement of a part of the output name, and replacement throughout
the whole config file (not just for the output name). One may expect the
following to "work", but it won't, and won't print any obvious error:
set $foo bar
profile {
output "$foo 4242" mode 1920x1080
exec "echo $foo"
}
Maybe a less surprising syntax would be to have a dedicated way to setup
an output alias?
output DP-1 alias main
profile {
output main mode 1920x1080
}
Something surprising would be that the "output" command syntax would be
different inside and outside the "profile" directive. (That said, it may
be desirable to make the syntax outside of the "profile" directive a
superset of the syntax inside, so that defaults can be set -- but this
requires more thought.)
Any other solution ideas?