-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bar subcommand handler structs and selection #2808
Conversation
@ianyfan This should fix #2791 (comment) and the runtime prevention in #2751 |
Now that |
Bug - this config is invalid:
|
2b0ac2c
to
ac57935
Compare
Good catch. Should be fixed now. |
So what is the planned syntax for performing runtime commands for specific bars? Are you going to modify every command so that it can accept |
The easiest would be just |
Would there be any issues with bars having an id that is the same as the name of a subcommand? i.e. any ambiguities |
Also what would happen if the command was |
ac57935
to
6dc453f
Compare
With the last commit, the only invalid id should be
It could go one of three ways: (1) use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to review the later logic, but I'm not sure if it would change depending on these changes.
sway/commands/bar.c
Outdated
if (argc > 1) { | ||
struct bar_config *bar = NULL; | ||
if (!find_handler(argv[0], bar_handlers, sizeof(bar_handlers)) | ||
&& find_handler(argv[1], bar_handlers, sizeof(bar_handlers))) { | ||
if (!is_subcommand(argv[0]) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we disallowed bar <id> <subcommand>
in the config file?
Would this allow this check to be changed to !config->reading && find_handler(argv[1], bar_handlers, sizeof(bar_handlers))
? Then id id
would not have to be disallowed.
I'm not sure if this would change some later logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user wanted to define multiple bars in the config, this would force bar blocks again (expanded would work fine for one bar). Since there is no release allowing the bar <bar-id> <subcommand>
syntax, this could be an option since there probably aren't many people who have the expanded notation in their config.
Also, some insight into allowing bar <bar-id> <subcommand>
was to make it uniform with input <input-name>
, output <output-name>
, mode <mode-name>
, seat <seat-name>
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, it should be fine to keep the behaviour as it is.
However, is the first check !is_subcommand(argv[0])
actually required? Can't think of a (valid) case when that would be true but the later check false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
6dc453f
to
64b32d6
Compare
Actually, I think it should be the other way round, since if is new then it would spawn a new bar, and if the mode didn't affect that it would be weird. This would require small changes to the command code. Or maybe both should be changed, I don't know what happens in i3 if you include |
Why is |
Ideally, this will be replaced with an IPC barconfig_update event in the near future
Sounds good to me. Order of preference should then be: (1)
|
64b32d6
to
e246a78
Compare
} | ||
} | ||
if (!bar) { | ||
spawn = !config->reading; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to change spawning behaviour so it only needs to allocate once?
I'm thinking something like using a variable like spawn_with_id
.
I'm also confused why this loop is required later:
Line 95 in 782a835
for (int i = 0; i < config->bars->length; ++i) { |
since wouldn't the bar always be the last one?
Anyway, I think this may be outside of the scope of this PR, and I may open my own one. It otherwise looks good to me, and if you don't feel like dealing with this I'm happy to accept it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to change spawning behaviour so it only needs to allocate once? I'm thinking something like using a variable like spawn_with_id.
I'm not sure I understand what you are asking. That's line is inside the creation of a bar with a custom id. spawn
would not be set to true
if the bar already exists.
I'm also confused why this loop is required later [..] since wouldn't the bar always be the last one?
I'm actually not sure. I'm guessing its an artifact from an older version of the codebase. I'll remove the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop has been removed. I also fixed up a few of the commits to group them better since there were multiple small related changes.
Allows bar-subcommand to be a valid bar-ids Destroys runtime created bar if trying to use a config only subcommand Allow subcommands (except for id) to be ids
e246a78
to
2a0c7eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and works
Thanks! |
@RedSoxFan If you make the follow-up PR, can you remember to change the man pages to reflect this change in behaviour? Thanks |
Overview of changes:
mode
andhidden_state
are valid both in the config and during runtime.id
andswaybar_command
are only valid in the config.For a follow-up PR:
Once #2751 is merged, send the IPC
barconfig_update
event for the subcommands incmd_bar_handlers
and handle it in swaybar