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

X11: black screen when tabbing out of fullscreen #4674

Closed
ChillerDragon opened this issue Aug 19, 2021 · 2 comments
Closed

X11: black screen when tabbing out of fullscreen #4674

ChillerDragon opened this issue Aug 19, 2021 · 2 comments

Comments

@ChillerDragon
Copy link

Tabbing out of fullscreen SDL2 applications used to be instant for me.

this commit introduced a black screen when tabbing in and out
8e35ff5

and this commit then changed the black screen to some sort of "fade out" window getting smaller
25cd749

Tested on X11 nvidia gnome systems on archlinux and debian 11

The not so minimal test code I used. But every fullscreen project should work.

#include <SDL2/SDL.h>

SDL_Window *g_window = NULL;

int Init(int *Screen)
{
	// print sdl version
	{
		SDL_version Compiled;
		SDL_version Linked;

		SDL_VERSION(&Compiled);
		SDL_GetVersion(&Linked);
		printf("[sdl] SDL version %d.%d.%d (compiled = %d.%d.%d)\n", Linked.major, Linked.minor, Linked.patch,
			Compiled.major, Compiled.minor, Compiled.patch);
	}
	if(!SDL_WasInit(SDL_INIT_VIDEO))
	{
		if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
		{
			printf("[gfx] unable to init SDL video: %s\n", SDL_GetError());
			return 1;
		}
	}
	// store desktop resolution for settings reset button
	SDL_DisplayMode DisplayMode;
	if(SDL_GetDesktopDisplayMode(*Screen, &DisplayMode))
	{
		printf("[gfx] unable to get desktop resolution: %s\n", SDL_GetError());
		return 1;
	}
	int SdlFlags = SDL_WINDOW_OPENGL | \
		       SDL_WINDOW_INPUT_GRABBED | \
		       SDL_WINDOW_INPUT_FOCUS | \
		       SDL_WINDOW_MOUSE_FOCUS | \
		       SDL_WINDOW_FULLSCREEN;
	g_window = SDL_CreateWindow(
		"SDL2",
		SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,
		DisplayMode.w,
		DisplayMode.h,
		SdlFlags);
	return 0;
}

int main(int argc, char* argv[]) {
	if(SDL_Init(0))
	{
		puts("SDL_Init failed");
		return 1;
	}
	int Screen = 0;
	Init(&Screen);
	
	if(g_window == NULL)
	{
		puts("SDL_CreateWindow failed");
		return 1;
	}
	
	SDL_Renderer *renderer = NULL;
	renderer = SDL_CreateRenderer(g_window,
		                    -1,
		                    SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
	if(renderer == NULL)
	{
		puts("SDL_CreateRenderer failed");
		return 1;
	}
	SDL_SetRenderDrawColor(renderer,
	                       0x10,
	                       0xb0,
	                       0x10,
	                       SDL_ALPHA_OPAQUE);
	
	SDL_RenderFillRect(renderer, NULL);
	SDL_RenderPresent(renderer);
	SDL_Event event;
	while (SDL_WaitEvent(&event) >= 0)
	{
		switch (event.type)
		{
			case SDL_QUIT:
				return(0);
				break;
			default: break;
		}
	}
	SDL_DestroyWindow(g_window);
	SDL_DestroyRenderer(renderer);
	SDL_Quit();
	return 0;
}
@ChillerDragon
Copy link
Author

SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS=0 fixes it

@akortunov
Copy link

akortunov commented Sep 27, 2021

I got this issue with OpenMW (which uses SDL2) as well with 2.0.16 - there is a black screen for several seconds in fullsreen mode during game start, exit or tabbing in/out.

A mentioned workaround with SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS removes black screen during tabbing, but not during launch/exit.

I tested commit 25cd749 and it fixes the issue, but 2.0.16 is the latest release and it is already treated as stable by some Linux distros, so it would be nice to have a workaround for 2.0.16.

@slouken slouken closed this as completed Nov 7, 2023
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

3 participants