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
Cannot toggle fullscreen from key callback function #903
Comments
Your key callback sets the monitor (if any) that the window already has, so it shouldn't ever switch between windowed and full screen. Here is an example of a key callback toggling between windowed and full screen modes. |
I still don't understand how the call to glfwSetWindowMonitor does exactly what I want in main but not in the key callback. From the documentation of glfwSetWindowMonitor:
If I understand this correctly, the function changes the window to full screen when given a monitor, otherwise it changes to windowed mode. This is the behavior that the function exhibits when being called from main, but not from the key callback. Using the code you linked, the window moves to the 0, 0 position of the monitor that it is currently in, but is windowed, even when given a monitor. This is regardless of whether the window was created full screen or windowed. Creating the window full screen works perfectly, however I still haven't been able to switch to full screen after the window has been created. I also noticed this error, although I'm not sure what caused it and I don't know how to reproduce it:
|
I tested to see if it was my desktop environment causing the problem. I noticed that I can get toggling to work in Unity by using glfwGetPrimaryMonitor, but it doesn't work in DWM. This is odd because creating the window as full screen and changing it to fullscreen in main both work in DWM. |
Because in the key callback you set the monitor to the current monitor (if any) of the window as returned by
As a tiled window manager, DWM has some unusual ideas about window placement. What version of DWM are you using?
What is the output of |
I decided to remove glfwSetKeyCallback and use glfwGetKey instead to see if it would work. In the main loop: Alternatively:
The first example works every time. The second fails. I'm positive that the code is executed since debug statements work in the conditional. I think the same problem as with the callback function is happening here. I did some more testing:
It seems that glfwSetWindowMonitor only sometimes works if it is in an if conditional. I am sure the expression is true in these examples. |
I decided to get back to this. It still confuses me how glfwSetWindowMonitor works alone, but when in an if statement, even if the condition is true, it doesn't. If the window is started windowed and glfwSetWindowMonitor(glfwGetPrimaryMonitor(), 0, 0, 640, 480, 60) is called, the window is set to fullscreen, but only after the second time. The first time the key is pressed, it changes the resolution, but parts of the desktop are still visible. If the window moves away from the top left of the monitor, it may not be visible. After the second time, it becomes fullscreen with nothing but the window visible. If the window is started fullscreen, a similar behavior occurs. It takes a call to glfwSetWindowMonitor to make it really fullscreen. Otherwise the desktop is still visible. I decided to look at the source code of GLFW to see if I could find anything. In x11_window.c, in _glfwPlatformSetWindowMonitor, there is a bit of code:
If Now toggling to fullscreen works from a key but it still takes 2 calls to do it. In other words, it takes either switching to it twice or creating the window fullscreen and switching to it again. Switching to windowed takes only one call. |
Fullscreen switching/toggling during runtime won't work on dwm v6.1 without any patches. It simply forces it back into windowed mode. Also, if you toggle the bar of dwm and the window has been started in fullscreen mode, dwm forces it into windowed mode also. So |
The intended result of calling glfwSetWindowMonitor() is correct outside of the callback function, but not inside of it. It can switch fullscreen to windowed, but not the other way around.
The text was updated successfully, but these errors were encountered: