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] Keeping CORE.Window.position properly in sync with glfw window position #4190

Merged
merged 5 commits into from
Aug 24, 2024

Conversation

SoloByte
Copy link
Contributor

CORE.Window.position is now properly kept in sync with the glfw window position.

  • WindowPosCallback added
  • SetWindowPos now updates CORE.Window.position as well
  • Fullscreen & Borderless Fullscreen now properly user CORE.Window.position for setting CORE.Window.prevposition

Those changes should not change any behavior other than fixing ToggleFullscreen() not restoring the window to the correct previous window position.


FYI: There will be another PR for fixing the remaining problems with fullscreen & borderless fullscreen

  • restoring window size correctly and using already existing CORE.Window.prevscreen for it
  • BorderlessFullscreen using glfw SetWindowMonitor function as well to fix borderless fullscreen on macOS
  • some small misc fixes.

CORE.Window.position is now properly kept in sync with the glfw window position.
@casperbear
Copy link

There is a small issue in RayLib 5 when calling ToggleFullscreen() changes the angle Camera3D looks at. (And calling ToggleFullscreen() again changes the angle back). I wonder if this fix fixes that issue as well.

@SoloByte SoloByte changed the title [GLFW] Keeping CORE.Window.position properly in sync with glfw window position [rcore][desktop_glfw] Keeping CORE.Window.position properly in sync with glfw window position Jul 27, 2024
Comments updated.
@casperbear
Copy link

@raysan5 @SoloByte With the raylibdll.lib built from https://github.com/SoloByte/raylib/tree/glfw-window-pos-callback the bug with Camera3D angle jumping when switching between resolutions is indeed fixed. I tested it a 3d project. So this PR can be considered as a bug fix, not a just-in-case improvement. The relevant code I tested it with:

inline constexpr int SCREEN_WIDTH = 1920;
inline constexpr int WINDOWED_SCREEN_HEIGHT = 1080;
inline constexpr int FULL_SCREEN_HEIGHT = 1200;

if ((IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT)) && (IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_KP_ENTER)))
        {
            if (IsWindowFullscreen())
            {
                ToggleFullscreen();
                screenWidth = SCREEN_WIDTH;
                screenHeight = WINDOWED_SCREEN_HEIGHT;
                SetWindowSize(screenWidth, screenHeight);
            }
            else
            {
                screenWidth = SCREEN_WIDTH;
                screenHeight = FULL_SCREEN_HEIGHT;
                SetWindowSize(screenWidth, screenHeight);
                ToggleFullscreen();
            }
        }

@SoloByte
Copy link
Contributor Author

SoloByte commented Aug 1, 2024

Thanks for testing this :)

I did not think this would fix something else right away ^^

(This PR does fix restoring the window position correctly after exiting fullscreen)

I don't know if CORE.Window.position needs to be set initially in InitPlatform() as well. I will look into it before I forget.

This also fixes not centering the window correctly when the high dpi flag was enabled.
@SoloByte
Copy link
Contributor Author

SoloByte commented Aug 1, 2024

The new commit should set CORE.Window.position correctly from the start in InitPlatform(). I also had to fix the code for centering the window on start-up when the high dpi flag is enabled so that CORE.Window.position would be set correctly as well.

@casperbear You could recheck it, it should not have changed anything (hopefully).

I have tested it both on windows 11 & macOS with both high dpi flag enabled & disabled.

Here the render size has to be used again in case the high dpi flag is enabled.
@casperbear
Copy link

@SoloByte yes, Camera3D angle is still preserved when changing from windowed to fullscreen and back with RayLib from commit 7bd4888
In both cases: when windowed window is centered on the desktop and not centered on the desktop.
My setup is Windows 7 64-bit and one 1920x1200 monitor.

Update Window Position right away in ToggleFullscreen() & ToggleBorderlessWindowed() functions
@raysan5 raysan5 merged commit 0c06a08 into raysan5:master Aug 24, 2024
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Aug 24, 2024

@SoloByte The improvement looks good to me, thanks for the review and sorry for the late review.

@SoloByte
Copy link
Contributor Author

@SoloByte The improvement looks good to me, thanks for the review and sorry for the late review.

Thanks, and no worries because of the delay :)

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.

3 participants