libgdx / libgdx

Desktop/Android/HTML5/iOS Java game development framework
http://www.libgdx.com/
Apache License 2.0
23.09k stars 6.42k forks source link

On window minimize Screen.resize(0,0) called on Windows but not on Linux #7072

Open ErkkaLehmus opened 1 year ago

ErkkaLehmus commented 1 year ago

When user minimizes the game window, or alt-tabs out of a fullscreen mode, Screen.resize(0,0) gets called when running on Windows. But running on Linux (Debian MATE, if that matters) Screen.resize(0,0) is not called. I don't know if this is a bug, it just caused me some confusion.

Which is the intended behavior, calling resize(0,0) or not calling? On Linux it anyway correctly calls pause() and resume() which are handy for handling relevant logic when exiting / resuming the game window, so resize(0,0) seems redundant to me.

Using libGDX verion 1.11.0

Could not test on macOS for I don't have one

Please select the affected platforms

Frosty-J commented 1 year ago

In my Ubuntu MATE Linux experience, pause() doesn't get called on Alt+Tab. To detect that, a Lwjgl3WindowAdapter is required (focusLost(), focusGained()). Though it does get called on minimise, and resume() on unminimise.

The resize(0, 0) behaviour is odd to me - LWJGL2 wasn't like this, and it's a frequent source of bugs such as when generating a gdx-freetype font based on window size (generating a font of size 0 crashes it). The different behaviour across operating systems only adds to this oddness.

ErkkaLehmus commented 1 year ago

I did some further testing, and turns out you are correct: on Linux (MATE at least) pause() is not called on Alt+Tab when in windowed mode. Yet pause() is called when alt-tabbing out of fullscreen mode, at least with this configuration:


  config.setDecorated(false);
  config.setResizable(false);
  config.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode());

So, yeah - some oddity oddness, maybe? Naturally, one can live with this once one figures out how things work on each environment, but if possible it would be great to have consistent behavior on different Desktop OSes.

Frosty-J commented 1 year ago

pause() occurs when Alt+Tabbing with that configuration because the window automatically minimises. config.setAutoIconify(false) to stop that.

ErkkaLehmus commented 1 year ago

Ah, thanks for the clarification! Personally, I find pause() being called handy, for it is where I stop background music etc. when the game loses focus.

Is there then a way to make pause() to be called when alt-tabbing out in windowed mode? Or are we supposed to handle this kind of logic with Lwjgl3WindowAdapter focusLost() and focusGained() ?

Frosty-J commented 1 year ago

Hopefully someone more involved in the backends can say. Desktop is the odd one out, as the game is always running in comparison to other backends where the game actually pauses when switching to a different app on mobile or tab on GWT. For this reason, I give it special attention for this sort of stuff. I like to pause rendering etc. on minimise.

crykn commented 5 months ago

pause() being called when the window loses focus is part of #7287. As to whether resize(0, 0) should be called on pause – that depends on the platform, see #33. We could definitely document that behaviour better, but changing it is probably not a good idea if the resize(0, 0) calls actually serve a purpose (albeit a rather limited one).