Some WinRT strangeness with reported window size

Hi,

I found some strangeness with WinRT when looking at app resume and the SDL
events “window resized” and “window size changed”:

  1. On the desktop, I’m changing the app from fullscreen to windowed mode.
    After changing the window size to make the window a little smaller, I
    minimize the window, then restore it again.

The issue I see is that the window events report the width and height of the
window as if it still was fullscreen. Somehow SDL did not "fully realize"
that the window is no longer fullscreen. Which is strange because all the
events that are fired during resizing the window are correct (e.g. when the
issue occurs, resizing the window again corrects the coordinates
immediately).

  1. On the phone, the coordinates reported by the 2 events seem to be
    inconsistent (at least for an app that is declared to support landscape
    only). Sometimes the corrdinates are reported with width < height, sometimes
    the other way 'round. There seem to be a number of notifications coming, and
    the “last” one after initial app start is different to the “last” one after
    resume, so that my app becomes confused.

I can help reproducing the issues if this proves to be difficult. Any help
is appreciated :slight_smile:

Regards,

Daniel

hardcoredaniel wrote:

  1. On the desktop, I’m changing the app from fullscreen to windowed mode. After changing the window size to make the window a little smaller, I minimize the window, then restore it again.

The issue I see is that the window events report the width and height of the window as if it still was fullscreen. Somehow SDL did not “fully realize” that the window is no longer fullscreen. Which is strange because all the events that are fired during resizing the window are correct (e.g. when the issue occurs, resizing the window again corrects the coordinates immediately).

I am unable to reproduce this. Can you provide a set of steps-to-reproduce, along with expected and observed results?

Also, which version/revision of SDL are you using?

– David L.

Hi David,

can you check out this app:

It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it’ll
immediately use the proper size.

The SDL version from this app is the state of trunk from around mid of june.
The behaviour does not change if I use SDL trunk from around 2 weeks ago.

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: DLudwig
Komu: sdl at lists.libsdl.org
Datum: 10. 10. 2016 22:27:52
P?edm?t: Re: [SDL] Some WinRT strangeness with reported window size

"

                      hardcoredaniel wrote:	 
  1. On the desktop, I’m changing the app from fullscreen to windowed mode.
    After changing the window size to make the window a little smaller, I
    minimize the window, then restore it again.

The issue I see is that the window events report the width and height of the
window as if it still was fullscreen. Somehow SDL did not "fully realize"
that the window is no longer fullscreen. Which is strange because all the
events that are fired during resizing the window are correct (e.g. when the
issue occurs, resizing the window again corrects the coordinates
immediately).

I am unable to reproduce this. Can you provide a set of steps-to-reproduce,
along with expected and observed results?

Also, which version/revision of SDL are you using?

– David L._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

hardcoredaniel wrote:

It will launch in fullscreen. When you resize it to windowed mode, change it to say 50% of its fullscreen size, minimize it, and then restore, it will display in invalid size. If you start resizing the window again, it’ll immediately use the proper size.

I see the bug reproduce in that app, but not in my own code. I’ve tried checking various SDL outputs as well (window size, renderer output size, viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against, preferably something dependency-free and single-file?

– David L.

Hi David,

I’m sorry for having you bothered with an issue that you could not have
reproduced due to missing information. After thinking about your
observations it occurred to me that some time ago I tried to implement some
workaround for the issue that the SDL app will not reliably start (resp
change to) fullscreen mode on PCs.

What I did was to add some code in my app to react on the window event “SDL_
WINDOWEVENT_SHOWN” and to call “SDL_SetWindowFullscreen” with SDL_TRUE as 2
nd parameter.

This worked well at app start, so that I forgot about this trick.
However, when restoring a minimized app that I changed to windowed mode
before, the system is not going to fullscreen despite that call (I’m not
sure whether or whom to blame, because I intentionally left fullscreen mode
before minimizing the window).
As the call to “SetWindowFullscreen” cannot return success/failure, SDL
doesn’t know about this and so probably assumes fullscreen was ok and sends
the SDL_WINDOWEVENT_RESIZED with the fullscreen coords.

So maybe I will have to modify the SDL sources myself to add a return code
to SetWindowFullscreen, return hard-coded success for all other platforms,
and success/failure for WinRT only. I remember your comment about such a
change not suiting all platforms where the success/failure of such operation
is reported asynchronously. Yet I have no other idea how to handle it.

BTW: Can you reproduce the width/height parameter inconsistency on the
mobile platform? Or is there a relation to my workaround as well?

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: DLudwig
Komu: sdl at lists.libsdl.org
Datum: 15. 10. 2016 20:07:53
P?edm?t: Re: [SDL] Some WinRT strangeness with reported window size

"

                      hardcoredaniel wrote:	 

It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it’ll
immediately use the proper size.

I see the bug reproduce in that app, but not in my own code. I’ve tried
checking various SDL outputs as well (window size, renderer output size,
viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against,
preferably something dependency-free and single-file?

– David L._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

Hi David,

I found that modifying SDL as described fixes the issue. FYI the (pretty
ugly) patch is below. Modifying the behaviour in SDL_video.c’s “update
fullscreen” depending on the result of the TryEnterFullscreen() mode fixes
all screen size issues for me.

Regards,

Daniel

— SDL_snapshot/src/video/SDL_sysvideo.h??? 2016-10-02 08:22:
14.323265900 +0200
+++ SDL_merged/src/video/SDL_sysvideo.h 2016-10-22 16:08:43.340540400 +0200
@@ -220,7 +220,11 @@
??? void (*RestoreWindow) (_THIS, SDL_Window * window);
??? void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool
bordered);
??? void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool
resizable);
+#ifdef WINRT
+??? int (*SetWindowFullscreen) (THIS, SDL_Window * window, SDL
VideoDisplay * display, SDL_bool fullscreen);
+#else
??? void (*SetWindowFullscreen) (THIS, SDL_Window * window, SDL
VideoDisplay * display, SDL_bool fullscreen);
+#endif
??? int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 *
ramp);
??? int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
??? void (*SetWindowGrab) (THIS, SDL_Window * window, SDL_bool grabbed);
diff -bBur SDL_snapshot/src/video/SDL_video.c SDL_merged/src/video/SDL

video.c
— SDL_snapshot/src/video/SDL_video.c? 2016-10-08 10:16:43.377628700 +0200
+++ SDL_merged/src/video/SDL_video.c??? 2016-10-22 17:26:58.402858000 +0200
@@ -1265,7 +1265,14 @@
??? }

??? if (_this->SetWindowFullscreen) {
+#ifdef WINRT
+??? if (_this->SetWindowFullscreen(_this, other,
display, SDL_TRUE) != 0)
+??? {
+??? resized = SDL_FALSE;
+??? }
+#else
??? _this->SetWindowFullscreen(this, other, display, SDL
TRUE);
+#endif
??? }
??? display->fullscreen_window = other;
diff -bBur SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp SDL_merged/src/
video/winrt/SDL_winrtvideo.cpp
— SDL_snapshot/src/video/winrt/SDL_winrtvideo.cpp??? 2016-10-02 08:22:
18.423455500 +0200
+++ SDL_merged/src/video/winrt/SDL_winrtvideo.cpp??? 2016-10-22 17:27:
36.208419200 +0200
@@ -80,9 +81,10 @@
?/* Window functions */
?static int WINRT_CreateWindow(_THIS, SDL_Window * window);
?static void WINRT_SetWindowSize(_THIS, SDL_Window * window);
-static void WINRT_SetWindowFullscreen(THIS, SDL_Window * window, SDL
VideoDisplay * display, SDL_bool fullscreen);
+static int WINRT_SetWindowFullscreen(THIS, SDL_Window * window, SDL
VideoDisplay * display, SDL_bool fullscreen);
?static void WINRT_DestroyWindow(_THIS, SDL_Window * window);
?static SDL_bool WINRT_GetWindowWMInfo(THIS, SDL_Window * window, SDL
SysWMinfo * info);
+static int WINRT_GetDisplayDPI(_THIS, SDL_VideoDisplay * sdl_display, float

  • ddpi, float * hdpi, float * vdpi);

?/* Misc functions */
@@ -723,23 +726,49 @@
?#endif
?}

-void
+int
?WINRT_SetWindowFullscreen(THIS, SDL_Window * window, SDL_VideoDisplay *
display, SDL_bool fullscreen)
?{
?#if NTDDI_VERSION >= NTDDI_WIN10
??? SDL_WindowData * data = (SDL_WindowData *)window->driverdata;
??? bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get());
+??? bool rememberMode = false;
+??? int successVal = 0;+
+??? const char *hint = SDL_GetHint(SDL_HINT_WINRT_REMEMBER_WINDOW

FULLSCREEN_PREFERENCE);
+??? if (hint) {
+??? if (*hint == ‘1’) {
+??? rememberMode = true;
+??? }
+??? }
+
??? if (isWindowActive) {
??? if (fullscreen) {
??? if (!data->appView->IsFullScreenMode) {
-??? data->appView->TryEnterFullScreenMode();??? // TODO, WinRT:
return failure (to caller?) from TryEnterFullScreenMode()
+??? if (data->appView->TryEnterFullScreenMode()
== true) {
+??? if (rememberMode == true) {
+??? data->appView->
PreferredLaunchWindowingMode = ApplicationViewWindowingMode::FullScreen;
+??? }
+??? } else {
+??? successVal = -1;
+??? }
??? }
??? } else {
??? if (data->appView->IsFullScreenMode) {
??? data->appView->ExitFullScreenMode();
+
+??? if (rememberMode == true) {
+??? data->appView->
PreferredLaunchWindowingMode = ApplicationViewWindowingMode::Auto;
+??? }
??? }
??? }
??? }
+??? else {
+??? successVal = -1;
+??? }
+??? return successVal;
+#else
+??? return 0;
?#endif
?}

---------- P?vodn? zpr?va ----------
Od: hardcoredaniel <@hardcoredaniel>
Komu: sdl at lists.libsdl.org
Datum: 18. 10. 2016 17:15:17
P?edm?t: Re: [SDL] Some WinRT strangeness with reported window size

"
Hi David,

I’m sorry for having you bothered with an issue that you could not have
reproduced due to missing information. After thinking about your
observations it occurred to me that some time ago I tried to implement some
workaround for the issue that the SDL app will not reliably start (resp
change to) fullscreen mode on PCs.

What I did was to add some code in my app to react on the window event “SDL_
WINDOWEVENT_SHOWN” and to call “SDL_SetWindowFullscreen” with SDL_TRUE as 2
nd parameter.

This worked well at app start, so that I forgot about this trick.
However, when restoring a minimized app that I changed to windowed mode
before, the system is not going to fullscreen despite that call (I’m not
sure whether or whom to blame, because I intentionally left fullscreen mode
before minimizing the window).
As the call to “SetWindowFullscreen” cannot return success/failure, SDL
doesn’t know about this and so probably assumes fullscreen was ok and sends
the SDL_WINDOWEVENT_RESIZED with the fullscreen coords.

So maybe I will have to modify the SDL sources myself to add a return code
to SetWindowFullscreen, return hard-coded success for all other platforms,
and success/failure for WinRT only. I remember your comment about such a
change not suiting all platforms where the success/failure of such operation
is reported asynchronously. Yet I have no other idea how to handle it.

BTW: Can you reproduce the width/height parameter inconsistency on the
mobile platform? Or is there a relation to my workaround as well?

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: DLudwig
Komu: sdl at lists.libsdl.org
Datum: 15. 10. 2016 20:07:53
P?edm?t: Re: [SDL] Some WinRT strangeness with reported window size

"

                      hardcoredaniel wrote:	 

It will launch in fullscreen. When you resize it to windowed mode, change it
to say 50% of its fullscreen size, minimize it, and then restore, it will
display in invalid size. If you start resizing the window again, it’ll
immediately use the proper size.

I see the bug reproduce in that app, but not in my own code. I’ve tried
checking various SDL outputs as well (window size, renderer output size,
viewport, and a few other things), and am not yet seeing any discrepencies.

Do you have sample code that I could try building + testing against,
preferably something dependency-free and single-file?

– David L.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

Hi Daniel,

Any chance that you could provide some sample code, maybe some project file(s), with which one could use to reliably reproduce the bug you were initially seeing?

– David L.

Hi David,

sorry for the long delay for my reply.

I do not have a small project, mine is rather big (repo size ~3G). But I
hope you have some scratch disk space :slight_smile:

Please check out these 2 repos next to each other (e.g. into the same root
dir) from bitbucket:

https://hcdaniel at bitbucket.org/hcdaniel/wmelite-dependencies-for-linux-and-
android
https://hcdaniel at bitbucket.org/hcdaniel/wmelite-rapaki-edition

The names of the repos must be kept because the project references go across
the repos.

Then you can open this project:

?wmelite-rapaki-edition/vs2015_uwp/wmelite_sdl_mixer/wmelite_sdl_mixer.sln

And compilation/running should work.

The SDL fork that the project references to has the change for fullscreen
already implemented. I hope that you can easily remove this reference and
point it to SDL trunk instead, to see the difference.

Regards,

Daniel

---------- P?vodn? zpr?va ----------
Od: DLudwig
Komu: sdl at lists.libsdl.org
Datum: 23. 10. 2016 18:25:44
P?edm?t: Re: [SDL] Some WinRT strangeness with reported window size

"

Hi Daniel,

Any chance that you could provide some sample code, maybe some project file
(s), with which one could use to reliably reproduce the bug you were
initially seeing?

– David L._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"

An update on this bug, which I finally was able to get back to:

I am no longer able to reproduce this bug. This includes using the version in the Store, and compiled using code I pulled from Mercurial, earlier this afternoon.

I have updated Windows since then, to the “Windows 10 Creators Update”. Perhaps this was a bug in Windows, itself?

– David L.