From 5654347c5d511c53146fe4ce1710938b311d986e Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 28 Sep 2020 04:50:57 +0300 Subject: Use glfwSetFramebufferSizeCallback instead of glfwSetWindowSizeCallback Framebuffer size is scaled by the display scale. This fixes the game being shrunk to the bottom left quarter of the window on Wayland HiDPI setups. Corresponding change in librw: glfwGetWindowSize -> glfwGetFramebufferSize. --- src/skel/glfw/glfw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index b9dbf5ac..f1b9c695 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -881,7 +881,7 @@ void psPostRWinit(void) RwEngineGetVideoModeInfo(&vm, GcurSelVM); glfwSetKeyCallback(PSGLOBAL(window), keypressCB); - glfwSetWindowSizeCallback(PSGLOBAL(window), resizeCB); + glfwSetFramebufferSizeCallback(PSGLOBAL(window), resizeCB); glfwSetScrollCallback(PSGLOBAL(window), scrollCB); glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB); -- cgit v1.2.3 From b95accb8ff6a594d1a920b94823b38be3515f149 Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 28 Sep 2020 04:52:13 +0300 Subject: glfw: scale cursor position by the ratio of framebuffer to screen size This fixes the mouse being constrained to the top left quarter of the window on Wayland HiDPI setups. --- src/skel/glfw/glfw.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index f1b9c695..d7054b9c 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -1397,8 +1397,11 @@ _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { // TODO this only works in frontend(and luckily only frontend use this). Fun fact: if I get pos manually in game, glfw reports that it's > 32000 void cursorCB(GLFWwindow* window, double xpos, double ypos) { - FrontEndMenuManager.m_nMouseTempPosX = xpos; - FrontEndMenuManager.m_nMouseTempPosY = ypos; + int bufw, bufh, winw, winh; + glfwGetWindowSize(window, &winw, &winh); + glfwGetFramebufferSize(window, &bufw, &bufh); + FrontEndMenuManager.m_nMouseTempPosX = xpos * (bufw / winw); + FrontEndMenuManager.m_nMouseTempPosY = ypos * (bufh / winh); } void -- cgit v1.2.3 From 0205960a2fe13174b5dc17abf080b6821a3c883a Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 28 Sep 2020 04:53:15 +0300 Subject: Use GLFW_CURSOR_DISABLED (glfw's native mouse restriction) On Wayland, clients cannot move the mouse pointer. Mouse constraints, as required for 3D camera movement, are an explicit specific thing, and glfw supports it with GLFW_CURSOR_DISABLED. Use DISABLED, unless we're in a menu in windowed mode, where HIDDEN is still appropriate. --- src/skel/glfw/glfw.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index d7054b9c..e954e04b 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -1628,6 +1628,8 @@ main(int argc, char *argv[]) #endif { glfwPollEvents(); + glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, + (FrontEndMenuManager.m_bMenuActive && !PSGLOBAL(fullScreen)) ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_DISABLED); if( ForegroundApp ) { switch ( gGameState ) -- cgit v1.2.3 From 7d03a6fe291ff72edcf517dda1de8aee40941019 Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 28 Sep 2020 04:59:14 +0300 Subject: Use CLOCK_MONOTONIC_FAST when available (FreeBSD) CLOCK_MONOTONIC_FAST is the equivalent of Linux's CLOCK_MONOTONIC_RAW. --- src/skel/glfw/glfw.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index e954e04b..02546ffc 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -235,8 +235,10 @@ double psTimer(void) { struct timespec start; -#ifdef __linux__ +#if defined(CLOCK_MONOTONIC_RAW) clock_gettime(CLOCK_MONOTONIC_RAW, &start); +#elif defined(CLOCK_MONOTONIC_FAST) + clock_gettime(CLOCK_MONOTONIC_FAST, &start); #else clock_gettime(CLOCK_MONOTONIC, &start); #endif -- cgit v1.2.3 From 3b1debaa0d5341bdb954654503424fb12b529894 Mon Sep 17 00:00:00 2001 From: erorcun Date: Mon, 16 Nov 2020 15:28:10 +0300 Subject: Fix mouse lock/high-dpi --- src/skel/glfw/glfw.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index d8d168c5..86abca64 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -885,7 +885,13 @@ void _InputInitialiseJoys() long _InputInitialiseMouse() { +#ifdef IMPROVED_VIDEOMODE + // May be windowed, transition will be handled in CMenuManager::SwitchMenuOnAndOff() glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#else + // Always fullscreen, disable mouse + glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_DISABLED); +#endif return 0; } @@ -1416,11 +1422,13 @@ _InputTranslateShiftKeyUpDown(RsKeyCodes *rs) { // TODO this only works in frontend(and luckily only frontend use this). Fun fact: if I get pos manually in game, glfw reports that it's > 32000 void cursorCB(GLFWwindow* window, double xpos, double ypos) { - int bufw, bufh, winw, winh; - glfwGetWindowSize(window, &winw, &winh); - glfwGetFramebufferSize(window, &bufw, &bufh); - FrontEndMenuManager.m_nMouseTempPosX = xpos * (bufw / winw); - FrontEndMenuManager.m_nMouseTempPosY = ypos * (bufh / winh); + if (!FrontEndMenuManager.m_bMenuActive) + return; + + int winw, winh; + glfwGetWindowSize(PSGLOBAL(window), &winw, &winh); + FrontEndMenuManager.m_nMouseTempPosX = xpos * (RsGlobal.maximumWidth / winw); + FrontEndMenuManager.m_nMouseTempPosY = ypos * (RsGlobal.maximumHeight / winh); } void @@ -1648,8 +1656,6 @@ main(int argc, char *argv[]) #endif { glfwPollEvents(); - glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, - (FrontEndMenuManager.m_bMenuActive && !PSGLOBAL(fullScreen)) ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_DISABLED); if( ForegroundApp ) { switch ( gGameState ) -- cgit v1.2.3 From f33ed2892a7a083d10c89b93b0122c6b4100a9a2 Mon Sep 17 00:00:00 2001 From: erorcun Date: Mon, 16 Nov 2020 15:49:00 +0300 Subject: Fix mouse lock/high-dpi 2 --- src/skel/glfw/glfw.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/skel/glfw') diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 86abca64..982e8641 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -885,13 +885,7 @@ void _InputInitialiseJoys() long _InputInitialiseMouse() { -#ifdef IMPROVED_VIDEOMODE - // May be windowed, transition will be handled in CMenuManager::SwitchMenuOnAndOff() glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); -#else - // Always fullscreen, disable mouse - glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_DISABLED); -#endif return 0; } -- cgit v1.2.3