diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 9766c7602..302acde61 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -76,15 +76,6 @@ static NSUInteger getStyleMask(_GLFWwindow* window) return styleMask; } -// Center the cursor in the view of the window -// -static void centerCursor(_GLFWwindow *window) -{ - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); -} - // Returns whether the cursor is in the client area of the specified window // static GLFWbool cursorInClientArea(_GLFWwindow* window) @@ -142,7 +133,7 @@ static void updateCursorMode(_GLFWwindow* window) _glfwPlatformGetCursorPos(window, &_glfw.ns.restoreCursorPosX, &_glfw.ns.restoreCursorPosY); - centerCursor(window); + _glfwCenterCursor(window); CGAssociateMouseAndMouseCursorPosition(false); } else if (_glfw.ns.disabledCursorWindow == window) @@ -392,7 +383,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [window->context.nsgl.object update]; if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwCenterCursor(window); const int maximized = [window->ns.object isZoomed]; if (window->ns.maximized != maximized) @@ -427,7 +418,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; [window->context.nsgl.object update]; if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwCenterCursor(window); int x, y; _glfwPlatformGetWindowPos(window, &x, &y); @@ -453,7 +444,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)windowDidBecomeKey:(NSNotification *)notification { if (_glfw.ns.disabledCursorWindow == window) - centerCursor(window); + _glfwCenterCursor(window); _glfwInputWindowFocus(window, GLFW_TRUE); updateCursorMode(window); diff --git a/glfw/input.c b/glfw/input.c index ec9f014ee..53b43a32c 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -565,6 +565,15 @@ const char* _glfwGetKeyName(int key) } } +// Center the cursor in the middle of the window +// +void _glfwCenterCursor(_GLFWwindow* window) +{ + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/glfw/internal.h b/glfw/internal.h index 52d8d42f1..e8e823aa7 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -773,6 +773,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name, int hatCount); void _glfwFreeJoystick(_GLFWjoystick* js); const char* _glfwGetKeyName(int key); +void _glfwCenterCursor(_GLFWwindow* window); GLFWbool _glfwInitVulkan(int mode); void _glfwTerminateVulkan(void); diff --git a/glfw/window.c b/glfw/window.c index c5ab04afb..823f3612a 100644 --- a/glfw/window.c +++ b/glfw/window.c @@ -254,11 +254,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, if (window->monitor) { if (wndconfig.centerCursor) - { - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); - } + _glfwCenterCursor(window); } else { diff --git a/glfw/x11_window.c b/glfw/x11_window.c index e83c963b5..76b2084fb 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -403,15 +403,6 @@ static char* convertLatin1toUTF8(const char* source) return target; } -// Centers the cursor over the window client area -// -static void centerCursor(_GLFWwindow* window) -{ - int width, height; - _glfwPlatformGetWindowSize(window, &width, &height); - _glfwPlatformSetCursorPos(window, width / 2.0, height / 2.0); -} - // Updates the cursor image according to its cursor mode // static void updateCursorImage(_GLFWwindow* window) @@ -455,7 +446,7 @@ static void disableCursor(_GLFWwindow* window) &_glfw.x11.restoreCursorPosX, &_glfw.x11.restoreCursorPosY); updateCursorImage(window); - centerCursor(window); + _glfwCenterCursor(window); XGrabPointer(_glfw.x11.display, window->x11.handle, True, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync,