Fix crash in WaylandGestures during global Wayland teardown

Description

This PR fixes a segmentation fault in Gwenview that occurs on Wayland when the zwp_pointer_gestures_v1 global object is removed (e.g., during compositor shutdown or when an input device is disconnected).

Previously, when the Wayland pointer gesture global was removed, PointerGestures::activeChanged was emitted and WaylandGestures::init() was unconditionally called. Inside init(), we attempt to fetch the native wl_pointer, which crashes inside QtWayland (QWaylandInputDevice::pointer) because the default input device has already been torn down and the pointer is null.

Changes Made

  • Check m_pointerGestures->isActive() before re-initializing gestures inside the activeChanged slot.
  • Safely destroy and delete the existing m_pinchGesture when the extension becomes inactive, preventing lingering and invalid Wayland objects.
  • Initialize m_pinchGesture to nullptr in the constructor to avoid the destruction of an uninitialized pointer.
  • Added a safety guard in init() to properly destroy and overwrite the previous m_pinchGesture if re-initialization occurs.

Bug Reference

Fixes Red Hat Bugzilla: #2480139

Merge request reports

Loading