diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-28 08:52:40 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-28 08:56:09 +0300 |
commit | 5dfff02437c66777c9473b8b0fa6ed0dcc7aaf8c (patch) | |
tree | ecb447bde95f07c6fa60c065ba35e86187bb8da0 /intern | |
parent | 138a4846e2dbb719a4e8f39b7ffd2d0f95db06c6 (diff) |
Fix switching between different grab types with GHOST/Wayland
Since [0], using the view navigation gizmo crashed with Wayland.
This only worked previously because GHOST_kGrabWrap was ignored.
Now the previous grab state is disabled before switching to a new
grab state.
[0]: da9e14b0b91c81d29c4e44f40ac299ae847367de
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemWayland.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 24d3f525c97..60ebe1abc8d 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -1933,11 +1933,37 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo return GHOST_kFailure; } + /* No change, success. */ + if (mode == mode_current) { + return GHOST_kSuccess; + } + input_t *input = d->inputs[0]; + if (mode_current == GHOST_kGrabHide) { + setCursorVisibility(true); + } + + if ((mode == GHOST_kGrabDisable) || + /* Switching from one grab mode to another, + * in this case disable the current locks as it makes logic confusing, + * postpone changing the cursor to avoid flickering. */ + (mode_current != 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; + } + } + if (mode != GHOST_kGrabDisable) { - /* TODO(@campbellbarton): Support #GHOST_kGrabWrap, - * where the cursor moves but is constrained to a region. */ + /* TODO(@campbellbarton): As WAYLAND does not support warping the pointer it may not be + * possible to support #GHOST_kGrabWrap by pragmatically settings it's coordinates. + * An alternative could be to draw the cursor in software (and hide the real cursor), + * or just accept a locked cursor on WAYLAND. */ input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer( d->relative_pointer_manager, input->pointer); zwp_relative_pointer_v1_add_listener( @@ -1953,20 +1979,6 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo 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; - } - - if (mode_current == GHOST_kGrabHide) { - setCursorVisibility(false); - } - } return GHOST_kSuccess; } |