Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-06-30 15:53:20 +0300
committerCampbell Barton <campbell@blender.org>2022-06-30 16:46:57 +0300
commit6bd2c6789b244a03bccdb254502567691c42b944 (patch)
tree264949e98f2d99a91e9a393c0cd3478ef1701a77 /intern
parentdf40e9d0aad0c2a5b649d99c25e991a3664501c5 (diff)
GHOST: get/set cursor position now uses client instead of screen coords
Use client (window) relative coordinates for cursor position access, this only moves the conversion from window-manager into GHOST, (no functional changes). This is needed for fix a bug in GHOST/Wayland which doesn't support accessing absolute cursor coordinates & the window is needed to properly access the cursor coordinates. As it happens every caller to GHOST_GetCursorPosition was already making the values window-relative, so there is little benefit in attempting to workaround the problem on the Wayland side. If needed the screen-space versions of functions can be exposed again.
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/GHOST_C-api.h19
-rw-r--r--intern/ghost/GHOST_ISystem.h19
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp34
-rw-r--r--intern/ghost/intern/GHOST_System.cpp23
-rw-r--r--intern/ghost/intern/GHOST_System.h11
5 files changed, 95 insertions, 11 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 0f05e501d17..4cbc0d65b11 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -383,27 +383,28 @@ extern bool GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle);
extern GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool visible);
/**
- * Returns the current location of the cursor (location in screen coordinates)
+ * Returns the current location of the cursor (location in client relative coordinates)
* \param systemhandle: The handle to the system.
* \param x: The x-coordinate of the cursor.
* \param y: The y-coordinate of the cursor.
* \return Indication of success.
*/
-extern GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
- int32_t *x,
- int32_t *y);
-
+GHOST_TSuccess GHOST_GetCursorPosition(const GHOST_SystemHandle systemhandle,
+ const GHOST_WindowHandle windowhandle,
+ int32_t *x,
+ int32_t *y);
/**
- * Updates the location of the cursor (location in screen coordinates).
+ * Updates the location of the cursor (location in client relative coordinates).
* Not all operating systems allow the cursor to be moved (without the input device being moved).
* \param systemhandle: The handle to the system.
* \param x: The x-coordinate of the cursor.
* \param y: The y-coordinate of the cursor.
* \return Indication of success.
*/
-extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
- int32_t x,
- int32_t y);
+GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
+ GHOST_WindowHandle windowhandle,
+ int32_t x,
+ int32_t y);
void GHOST_GetCursorGrabState(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode *r_mode,
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index d7485975906..91cf1c4c558 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -365,6 +365,25 @@ class GHOST_ISystem {
***************************************************************************************/
/**
+ * Returns the current location of the cursor (location in window coordinates)
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * \return Indication of success.
+ */
+ virtual GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window,
+ int32_t &x,
+ int32_t &y) const = 0;
+ /**
+ * Updates the location of the cursor (location in window coordinates).
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * \return Indication of success.
+ */
+ virtual GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window,
+ int32_t x,
+ int32_t y) = 0;
+
+ /**
* Returns the current location of the cursor (location in screen coordinates)
* \param x: The x-coordinate of the cursor.
* \param y: The y-coordinate of the cursor.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 8c690767810..65e7de707ec 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -348,19 +348,49 @@ GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, bool v
return window->setCursorVisibility(visible);
}
-GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle, int32_t *x, int32_t *y)
+/* Unused, can expose again if needed although WAYLAND
+ * can only properly use client relative coordinates, so leave disabled if possible. */
+#if 0
+GHOST_TSuccess GHOST_GetCursorPositionScreenCoords(GHOST_SystemHandle systemhandle,
+ int32_t *x,
+ int32_t *y)
{
GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
return system->getCursorPosition(*x, *y);
}
-GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle, int32_t x, int32_t y)
+GHOST_TSuccess GHOST_SetCursorPositionScreenCoords(GHOST_SystemHandle systemhandle,
+ int32_t x,
+ int32_t y)
{
GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
return system->setCursorPosition(x, y);
}
+#endif
+
+GHOST_TSuccess GHOST_GetCursorPosition(const GHOST_SystemHandle systemhandle,
+ const GHOST_WindowHandle windowhandle,
+ int32_t *x,
+ int32_t *y)
+{
+ const GHOST_ISystem *system = (const GHOST_ISystem *)systemhandle;
+ const GHOST_IWindow *window = (const GHOST_IWindow *)windowhandle;
+
+ return system->getCursorPositionClientRelative(window, *x, *y);
+}
+
+GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
+ GHOST_WindowHandle windowhandle,
+ int32_t x,
+ int32_t y)
+{
+ GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
+ GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+ return system->setCursorPositionClientRelative(window, x, y);
+}
GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode mode,
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index 2f4ab9ee37c..cf04287af9f 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -260,6 +260,29 @@ GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent *event)
return success;
}
+GHOST_TSuccess GHOST_System::getCursorPositionClientRelative(const GHOST_IWindow *window,
+ int32_t &x,
+ int32_t &y) const
+{
+ /* Sub-classes that can implement this directly should do so. */
+ int32_t screen_x, screen_y;
+ GHOST_TSuccess success = getCursorPosition(screen_x, screen_y);
+ if (success == GHOST_kSuccess) {
+ window->screenToClient(screen_x, screen_y, x, y);
+ }
+ return success;
+}
+
+GHOST_TSuccess GHOST_System::setCursorPositionClientRelative(GHOST_IWindow *window,
+ int32_t x,
+ int32_t y)
+{
+ /* Sub-classes that can implement this directly should do so. */
+ int32_t screen_x, screen_y;
+ window->clientToScreen(x, y, screen_x, screen_y);
+ return setCursorPosition(screen_x, screen_y);
+}
+
GHOST_TSuccess GHOST_System::getModifierKeyState(GHOST_TModifierKey mask, bool &isDown) const
{
GHOST_ModifierKeys keys;
diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h
index e4a49551222..42f0a773dea 100644
--- a/intern/ghost/intern/GHOST_System.h
+++ b/intern/ghost/intern/GHOST_System.h
@@ -203,6 +203,17 @@ class GHOST_System : public GHOST_ISystem {
* Cursor management functionality
***************************************************************************************/
+ /* Client relative functions use a default implementation
+ * that converts from screen-coordinates to client coordinates.
+ * Implementations may override. */
+
+ GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window,
+ int32_t &x,
+ int32_t &y) const override;
+ GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window,
+ int32_t x,
+ int32_t y) override;
+
/**
* Inherited from GHOST_ISystem but left pure virtual
* <pre>