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

[rcore][desktop_glfw] Set AUTO_ICONIFY flag to false per default #4188

Merged
merged 2 commits into from
Aug 4, 2024

Conversation

SoloByte
Copy link
Contributor

@SoloByte SoloByte commented Jul 27, 2024

Previously AUTO_ICONIFY was only disabled if the user requested a Fullscreen window from the start. After that, changing this behavior on the user side was impossible, even when changing to a Fullscreen window.

The AUTO_ICONIFY causes problems on macOS. On macOS, if the window is minimized because of AUTO_ICONIFY then the only way to restore it is to click on the icon in the dock. In other words, when AUTO_ICONIFY is enabled alt/cmd-tabbing through Windows does not work correctly. On Windows, it works even when AUTO_ICONIFY is enabled.

Additionally, if a raylib window is in Fullscreen mode on another monitor the AUTO_ICONIFY behavior is a problem because the user might want the window to stay on the monitor even if it loses focus. (problem on all OS's)

AUTO_ICONIFY also restores the monitor hardware resolution if a fullscreen window loses focus. (is a good thing mostly but causes an issue with multiple monitors, see point above)

I set it to false per default on all operating systems to maintain consistency. The AUTO_ICONIFY behavior can be implemented by the user if needed:

void update()
{
	handleInput();

	bool currentWindowFocus = IsWindowFocused();
	if (currentWindowFocus != previousWindowFocus)
	{
		onFocusChanged(currentWindowFocus);
		previousWindowFocus = currentWindowFocus;
	}

}

void onFocusChanged(bool newFocus)
{
	if (newFocus == false) //window lost focus
	{
		if (IsWindowFullscreen())
		{
			wasFullscreen = true; //used for restoring fullscreen when window gains focus again
			ToggleFullscreen();
			MinimizeWindow();
		}
		else
		{
			if (!IsWindowMinimized()) MinimizeWindow();
		}
	}
	else // window gained focus
	{
		RestoreWindow();
		if (wasFullscreen) 
		{
			wasFullscreen = false;
			ToggleFullscreen();
		}
	}
}

If wanted/needed there are some other options to go about this:

  1. I only set the AUTO_ICONIFY flag to false per default on macOS. (this creates problems because the behavior is different on different platforms but has the advantage that nothing changes for Windows/Linux users)
  2. There is a way to set the AUTO_ICONIFY flag on the user side (like with other flags but I don't know how other backends handle this behavior)
  3. AUTO_ICONIFY is set to false per default and it is only set to true whenever fullscreen mode is activated. It is set to false again once fullscreen is exited.

Another example that just caused me problems with the AUTO_ICONIFY flag on Windows:

I wanted to make a screenshot of a raylib window for another PR using the Snipping Tool app. With the AUTO_ICONIFY flag enabled I could not do that because every time I focused the window of the snipping tool to make a screenshot the raylib window automatically minimized... So I am really for just disabling it.

Previously AUTO_ICONIFY was only disabled if the user requested a Fullscreen window from the start. After that it was not possible to change this behavior on the user side anymore, even when changing to a Fullscreen window.

The AUTO_ICONIFY causes problems on macOS. On macOS if the window is minimized because of AUTO_ICONIFY than the only way to restore it is to click on the icon in the dock. In other words when AUTO_ICONIFY is enabled alt/cmd-tabbing through windows does not work correctly. On windows it works even when AUTO_ICONIFY is enabled.

Additionally if a raylib window is in Fullscreen mode on another monitor the AUTO_ICONIFY behavior is a problem because the user might want to window to stay on the monitor even if it loses focus. (problem on all OS's)

AUTO_ICONIFY also restores the monitor hardware resolution if a fullscreen window loses focus.
src/platforms/rcore_desktop_glfw.c Outdated Show resolved Hide resolved
src/platforms/rcore_desktop_glfw.c Outdated Show resolved Hide resolved
@raysan5 raysan5 changed the title [GLFW] Set AUTO_ICONIFY flag to false per default [rcore][desktop_glfw] Set AUTO_ICONIFY flag to false per default Jul 27, 2024
Extra space removed and comments updated with a space at the beginning
@raysan5 raysan5 merged commit 596cc3a into raysan5:master Aug 4, 2024
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Aug 4, 2024

@SoloByte Thanks for the review

@SoloByte SoloByte deleted the glfw-auto-iconify-fix branch August 5, 2024 08:32
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.

2 participants