Skip to content

sway/commands: Handle incorrect resize unit #8640

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sahinf
Copy link
Contributor

@sahinf sahinf commented Apr 1, 2025

problem: an invalid usage of the command resize set will cause sway to crash because it doesn't check for an invalid height.

solution:

  1. validate height along with width
  2. collect all the resize returns into a var in order to log potential errors before returning, so the user has more context as to why the resize config did not work.

fixes #8619

@sahinf sahinf force-pushed the fix-resize-crashing branch from d302b54 to d646a4e Compare April 2, 2025 02:41
@sahinf sahinf force-pushed the fix-resize-crashing branch from d646a4e to 86c68c8 Compare April 11, 2025 17:04
@@ -295,6 +295,7 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
struct cmd_results *res = handler->handle(argc-1, argv+1);
list_add(res_list, res);
if (res->status == CMD_INVALID) {
sway_log(SWAY_ERROR, "%s", res->error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't log command error results, these are displayed to the user by swaymsg.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these errors are from for_window directives within the config, not from the user running swaymsg. They currently don't get displayed to the user at all. Should they not get printed if from for_window directives?

for_window [app_id="Alacritty"] {
	floating enable
	move position 600 pt 200 pt
	resize set width 300 pt
	resize set height 300 pt
}
exec alacritty

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Yeah, would make sense to me to print from the function that executes for_window criteria.

@sahinf sahinf force-pushed the fix-resize-crashing branch from b291208 to 2dad368 Compare April 13, 2025 17:56
problem: an invalid usage of the command resize set will cause sway to crash because it doesn't check for an invalid height.

solution: validate height along with width.

fixes swaywm#8619

collect errors of all cmd_resize variations and bubble them up

Log invalid command usage

without this, the invalid command usages from the config criteria do not
get logged or printed to the user anywhere.
@sahinf sahinf force-pushed the fix-resize-crashing branch from 2dad368 to 02b3c6f Compare April 13, 2025 17:58
"<width|height|up|down|left|right> [<amount>] [px|ppt]'";

return cmd_results_new(CMD_INVALID, "%s", usage);
return error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like with this change we no longer report an error when executing resize foo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Sway crashes if 'pt' used for resize set width/height units, instead of 'px'
2 participants