diff options
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWayland.cpp | 59 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWayland.h | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowWayland.cpp | 2 |
3 files changed, 35 insertions, 30 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 4a25b8bb9bb..24d3f525c97 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1920,6 +1920,8 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(bool visible) } GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mode, + const GHOST_TGrabCursorMode mode_current, + wl_surface *surface) { /* ignore, if the required protocols are not supported */ @@ -1933,36 +1935,37 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo input_t *input = d->inputs[0]; - switch (mode) { - case GHOST_kGrabDisable: - if (input->relative_pointer) { - zwp_relative_pointer_v1_destroy(input->relative_pointer); - input->relative_pointer = nullptr; - } - if (input->locked_pointer) { - zwp_locked_pointer_v1_destroy(input->locked_pointer); - input->locked_pointer = nullptr; - } - break; - - case GHOST_kGrabNormal: - break; - case GHOST_kGrabWrap: - input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( - d->relative_pointer_manager, input->pointer); - zwp_relative_pointer_v1_add_listener( - input->relative_pointer, &relative_pointer_listener, input); - input->locked_pointer = zwp_pointer_constraints_v1_lock_pointer( - d->pointer_constraints, - surface, - input->pointer, - nullptr, - ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); - break; + if (mode != GHOST_kGrabDisable) { + /* TODO(@campbellbarton): Support #GHOST_kGrabWrap, + * where the cursor moves but is constrained to a region. */ + input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( + d->relative_pointer_manager, input->pointer); + zwp_relative_pointer_v1_add_listener( + input->relative_pointer, &relative_pointer_listener, input); + input->locked_pointer = zwp_pointer_constraints_v1_lock_pointer( + d->pointer_constraints, + surface, + input->pointer, + nullptr, + ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT); + + if (mode == GHOST_kGrabHide) { + setCursorVisibility(false); + } + } + else { + if (input->relative_pointer) { + zwp_relative_pointer_v1_destroy(input->relative_pointer); + input->relative_pointer = nullptr; + } + if (input->locked_pointer) { + zwp_locked_pointer_v1_destroy(input->locked_pointer); + input->locked_pointer = nullptr; + } - case GHOST_kGrabHide: + if (mode_current == GHOST_kGrabHide) { setCursorVisibility(false); - break; + } } return GHOST_kSuccess; diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h index 1f664915ad3..01b47358618 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.h +++ b/intern/ghost/intern/GHOST_SystemWayland.h @@ -103,7 +103,9 @@ class GHOST_SystemWayland : public GHOST_System { GHOST_TSuccess setCursorVisibility(bool visible); - GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode, wl_surface *surface); + GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode, + const GHOST_TGrabCursorMode mode_current, + wl_surface *surface); private: struct display_t *d; diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp index 7ae06623c91..7f2a2c992d9 100644 --- a/intern/ghost/intern/GHOST_WindowWayland.cpp +++ b/intern/ghost/intern/GHOST_WindowWayland.cpp @@ -320,7 +320,7 @@ int &GHOST_WindowWayland::scale() GHOST_TSuccess GHOST_WindowWayland::setWindowCursorGrab(GHOST_TGrabCursorMode mode) { - return m_system->setCursorGrab(mode, w->surface); + return m_system->setCursorGrab(mode, m_cursorGrab, w->surface); } GHOST_TSuccess GHOST_WindowWayland::setWindowCursorShape(GHOST_TStandardCursor shape) |