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

[Wayland] Explicitly set min/max size for xdg-shell #4065

Merged
merged 1 commit into from
Mar 1, 2021

Conversation

flibitijibibo
Copy link
Collaborator

This is a Git-based replacement for #4047.

As a refresher: Wayland desktops currently have no way of knowing that our window is fixed-size; while we do ignore resize events in our callbacks, the desktop will still provide resize UI and a maximize button that can mess with the window in unintended ways. This patch is meant to address this, though on KDE the fix doesn't work until you toggle the border. If anyone familiar with KDE's implementation of server-side decorations we could use some help with this one...

@flibitijibibo
Copy link
Collaborator Author

flibitijibibo commented Feb 12, 2021

Test program:

#include <SDL.h>

int main(int argc, char **argv)
{
	SDL_Window *window;
	SDL_GLContext context;
	SDL_Event evt;
	int w;
	Uint8 run = 1;

	SDL_Init(SDL_INIT_VIDEO);
	window = SDL_CreateWindow(
		"Shell Test",
		SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,
		800,
		600,
		SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL
	);
	context = SDL_GL_CreateContext(window);

	while (run)
	{
		const Uint32 flags = SDL_GetWindowFlags(window);
		while (SDL_PollEvent(&evt) > 0)
		{
			if (evt.type == SDL_QUIT)
			{
				run = 0;
			}
			else if (evt.type == SDL_KEYDOWN)
			{
				if (evt.key.keysym.sym == SDLK_1)
				{
					SDL_SetWindowResizable(
						window,
						(flags & SDL_WINDOW_RESIZABLE) != SDL_WINDOW_RESIZABLE
					);
				}
				else if (evt.key.keysym.sym == SDLK_2)
				{
					SDL_SetWindowBordered(
						window,
						(flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS
					);
				}
				else if (evt.key.keysym.sym == SDLK_3)
				{
					SDL_SetWindowFullscreen(
						window,
						(flags & SDL_WINDOW_FULLSCREEN_DESKTOP) ?
							0 :
							SDL_WINDOW_FULLSCREEN_DESKTOP
					);
					SDL_SetWindowSize(window, 800, 600);
					SDL_SetWindowPosition(
						window,
						SDL_WINDOWPOS_CENTERED,
						SDL_WINDOWPOS_CENTERED
					);
				}
				else if (evt.key.keysym.sym == SDLK_4)
				{
					SDL_GetWindowMinimumSize(window, &w, NULL);
					if (w < 2)
					{
						SDL_SetWindowMinimumSize(window, 600, 400);
						SDL_SetWindowMaximumSize(window, 1000, 800);
					}
					else
					{
						SDL_SetWindowMinimumSize(window, 1, 1);
						SDL_SetWindowMaximumSize(window, 0x7FFFFFFF, 0x7FFFFFFF);
					}
				}
				else if (evt.key.keysym.sym == SDLK_5)
				{
					SDL_SetWindowSize(window, 800, 600);
					SDL_SetWindowPosition(
						window,
						SDL_WINDOWPOS_CENTERED,
						SDL_WINDOWPOS_CENTERED
					);
				}
			}
		}
		SDL_GL_SwapWindow(window);
	}

	SDL_GL_DeleteContext(context);
	SDL_DestroyWindow(window);
	SDL_Quit();
	return 0;
}

@flibitijibibo flibitijibibo changed the title [WIP] [Wayland] Explicitly set min/max size for xdg-shell [Wayland] Explicitly set min/max size for xdg-shell Mar 1, 2021
@flibitijibibo flibitijibibo marked this pull request as ready for review March 1, 2021 00:02
@flibitijibibo
Copy link
Collaborator Author

Updated to add zxdg code paths. From what I can tell this patch is as functional as it's going to get; we pass the information to the desktop but how it handles the information is up to them, it's effectively out of our control. In any case, this at least gives them the opportunity to do the right thing and the resize behavior is accurate based on local testing, so this is now good to merge.

@slouken slouken merged commit 57a927e into libsdl-org:main Mar 1, 2021
@flibitijibibo flibitijibibo deleted the xdg-shell branch March 1, 2021 03:40
SDL_VideoData *data = _this->driverdata;
SDL_WindowData *wind = window->driverdata;

if (resizable) {
Copy link

Choose a reason for hiding this comment

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

Just a video my girlfriend and I want back

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

Successfully merging this pull request may close these issues.

3 participants