Skip to content
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

Window aspect ratio constraining does not work under Wayland #302

Open
smcameron opened this issue Sep 1, 2021 · 2 comments
Open

Window aspect ratio constraining does not work under Wayland #302

smcameron opened this issue Sep 1, 2021 · 2 comments

Comments

@smcameron
Copy link
Owner

snis_xwindows_hacks.c prints out "Apparently not X11, no aspect ratio constraining for you!" because it's trying to set aspect ratio constraints via X11, and Wayland isn't X11. There may be a way to do it in Wayland, but I don't know how.

@smcameron
Copy link
Owner Author

smcameron commented Oct 29, 2021

This commit substantially mitigates the problem, I think: 72d120d

It works by catching SDL_WINDOWEVENT_SIZE_CHANGED and SDL_WINDOWEVENT_RESIZED, and getting the size of the window, and then adjusting the size to enforce the aspect ratio constraints. There are some gnarly details, like it seems as if you cannot call SDL_SetWindowSize() from the event handler (I don't know why not, this part doesn't make much sense to me, the event handling code is my code, and there's nothing special about it that I can see). In any case it sets a flag, and SDL_SetWindowSize() gets called later on after the event handling is done.

That being said, I haven't actually tested it under Wayland, but I did test it by turning off the xlib based aspect ratio constraining code and running it under X11. The only deficiency remaining is that it will still allow you to drag the window to sizes that do not conform to the aspect ratio constraint, but as soon as you release the mouse button, it will snap to the correct size and aspect ratio. So it's like 99% of the way there.

@smcameron
Copy link
Owner Author

Committed 2e6e18a snis_client: prevent infinite window resize event loop

The infinite event loop only occurred if you weren't using the window manager to enforce aspect ratio (e.g. you were not running X11, but (presumably) Wayland, or something else.)

And I suspect this may be related to why I was having trouble with calling SDL_SetWindowSize() from the event handler. If you call this, even passing the same window size as the window is already set to, it generates a SDL_WINDOWEVENT_RESIZED, which makes an infinite event loop. I might be able to call it from the event handler if I make sure to only call it if the size is actually changing.

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

No branches or pull requests

1 participant