Screen Size Incorrect After Resizing on VNC
Hello,
We have a service that runs a VNC session through a browser. In this session we are running a Unity standalone application. When the browser is resized, the desktop resolution is changed to match the new size of the browser window. The Unity window is maximized so it automatically resizes as well. However, Unity reports the screen size (Screen.currentResolution.width/height) and window size (Screen.width/height) incorrectly after resizing. I have confirmed that windows is correctly detecting the change in screen size and is sending the correct messages to the window.
To get information for the issue I was getting reports on the size of the screen and the window from the following places:
Unity - Screen.currentResolution.width, Screen.currentResolution.height
Unity - Screen.width, Screen.height
Windows – GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)
Windows – GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)
Windows – GetWindowRect
Windows correctly reports the size of the window and screen, and sends the WM_DISPLAYCHANGE message to the window. However, despite resizing with the screen, Unity reports that the screen size has remained the same. There are a few issues when the resolution is increased from the starting resolution. Unity seems to be enforcing a maximum size and caps Screen.SetResolution at what it believes to be the size of the screen. Despite this, the window can still be made larger than this limit by maximizing it. However, exceeding this size causes a couple of issues described below.
The UI gets stretched to fit the actual window dimension and becomes distorted & blurry
Interacting in the UI with the mouse does not work as expected. You need to click at the pixel offset of the button based on the size of the screen according to Unity. However, since the screen is not actually this size to click a button you need to click above and to the left of where the button is on screen.
If you can answer any of these questions it would be a great help with fixing the issue.
What is Unity using to determine when the resolution changes?
Is there a way we can force Unity to update the screen resolution.
Is there a way to force Unity to use a screen size larger than what it believes the screen resolution to be?
Screen.SetResolution is capped at the original resolution.
Resizing the window in Windows causes the above symptoms.
Thank you for your help,
Aaron
Answer by danw_unity · Feb 25, 2016 at 11:39 PM
Hi,
Are you using the "Resizeable window" option in the Player Settings?
Aside from that, I find that resizing the desktop is a messy thing to do on Windows. I prefer the TeamViewer way of working, where the remote computer sees the desktop as it is on the host, but scaled to whatever window you view it in. Depends what you are trying to achieve of course.
Hope this helps,
Dan
Unity Support
Answer by Zuecafajm · Feb 26, 2016 at 08:18 PM
Hello,
We do have the "Resizeable window" option checked, and the window is kept maximized so it automatically resizes with the desktop. Unfortunately we aren't able to use TeamViewer as a solution.
If you have any other things to try or could answer any of the questions from my original post I'd appreciate it.
Thank you, Aaron