Fix GHOST_kGrabHide in Wayland

Dragging number buttons wasn't grabbing the cursor and would stop
when the pointer reached the screen edge & wasn't setting the cursor
visible on completion.
This commit is contained in:
Campbell Barton 2022-05-27 16:29:45 +10:00
parent 46456a59c4
commit da9e14b0b9
Notes: blender-bot 2023-02-13 11:51:29 +01:00
Referenced by commit 5dfff02437, Fix switching between different grab types with GHOST/Wayland
3 changed files with 35 additions and 30 deletions

View File

@ -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;
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);
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;
case GHOST_kGrabHide:
if (mode == GHOST_kGrabHide) {
setCursorVisibility(false);
break;
}
}
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;

View File

@ -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;

View File

@ -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)