Skip to content

Commit b4cb427

Browse files
committed
GPU Wayland Display: set mouse cursor to default instead of being undefined
1 parent 36f196a commit b4cb427

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎GPU/GPUTracking/display/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if(GPUCA_EVENT_DISPLAY_VULKAN)
7878
if(GPUCA_EVENT_DISPLAY_WAYLAND)
7979
set(WAYLAND_PROTOCOL_HEADERS)
8080
set(WAYLAND_PROTOCOL_SOURCES)
81-
foreach(xml stable/xdg-shell/xdg-shell.xml stable/viewporter/viewporter.xml unstable/xdg-decoration/xdg-decoration-unstable-v1.xml staging/fractional-scale/fractional-scale-v1.xml)
81+
foreach(xml ${O2GPUWayland_PROTOCOLS}) # List and existence check in dependencies/FindO2GPUWayland.cmake
8282
get_filename_component(name ${xml} NAME_WE)
8383
string(REGEX REPLACE "(-unstable)?-v[0-9]+$" "" name ${name})
8484
set(header ${CMAKE_CURRENT_BINARY_DIR}/xdg-gen/${name}-client-protocol.h)

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.cxx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "xdg-shell-client-protocol.h"
4040
#include "xdg-decoration-client-protocol.h"
4141
#include "viewporter-client-protocol.h"
42+
#include "cursor-shape-client-protocol.h"
4243
#include <xkbcommon/xkbcommon.h>
4344
#include <linux/input-event-codes.h>
4445

@@ -157,6 +158,13 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
157158
}
158159

159160
auto pointer_enter = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
161+
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
162+
if (!me->mCursorShapeDevice && me->mCursorShapeManager) {
163+
me->mCursorShapeDevice = wp_cursor_shape_manager_v1_get_pointer(me->mCursorShapeManager, wl_pointer);
164+
}
165+
if (me->mCursorShapeDevice) {
166+
wp_cursor_shape_device_v1_set_shape(me->mCursorShapeDevice, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
167+
}
160168
};
161169
auto pointer_leave = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* wl_surface) {
162170
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
@@ -355,6 +363,8 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
355363
wl_seat_add_listener(me->mSeat, &me->mSeatListener, me);
356364
} else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
357365
me->mDecManager = (zxdg_decoration_manager_v1*)wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1);
366+
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
367+
me->mCursorShapeManager = (wp_cursor_shape_manager_v1*)wl_registry_bind(registry, name, &wp_cursor_shape_manager_v1_interface, 1);
358368
} else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
359369
me->mViewporter = (wp_viewporter*)wl_registry_bind(registry, name, &wp_viewporter_interface, 1);
360370
} else if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) {
@@ -600,6 +610,14 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
600610
mDisplayRunning = false;
601611
pthread_mutex_unlock(&mSemLockExit);
602612

613+
if (mCursorShapeDevice) {
614+
wp_cursor_shape_device_v1_destroy(mCursorShapeDevice);
615+
mCursorShapeDevice = nullptr;
616+
}
617+
if (mCursorShapeManager) {
618+
wp_cursor_shape_manager_v1_destroy(mCursorShapeManager);
619+
mCursorShapeManager = nullptr;
620+
}
603621
if (mPointer) {
604622
mSeatVersion >= WL_POINTER_RELEASE_SINCE_VERSION ? wl_pointer_release(mPointer) : wl_pointer_destroy(mPointer);
605623
mPointer = nullptr;

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
struct zxdg_decoration_manager_v1;
2727
struct wp_viewporter;
2828
struct wp_viewport;
29+
struct wp_cursor_shape_manager_v1;
30+
struct wp_cursor_shape_device_v1;
2931
struct zxdg_toplevel_decoration_v1;
3032
struct xkb_context;
3133
struct xkb_keymap;
@@ -106,6 +108,8 @@ class GPUDisplayFrontendWayland : public GPUDisplayFrontend
106108

107109
wp_viewporter* mViewporter = nullptr; // Fractional scaling (if both are available): buffer scale 1, buffer at physical size, viewport destination = logical size
108110
wp_fractional_scale_manager_v1* mFractionalScaleManager = nullptr;
111+
wp_cursor_shape_manager_v1* mCursorShapeManager = nullptr; // Sets the default cursor on pointer enter, otherwise the cursor image is undefined
112+
wp_cursor_shape_device_v1* mCursorShapeDevice = nullptr;
109113
wp_viewport* mViewport = nullptr;
110114
wp_fractional_scale_v1* mFractionalScale = nullptr;
111115

‎dependencies/FindO2GPUWayland.cmake‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ find_program(${PKGNAME}_SCANNER wayland-scanner)
2525
find_package(PkgConfig)
2626
if(PkgConfig_FOUND)
2727
pkg_get_variable(${PKGNAME}_PROTOCOLS_DIR wayland-protocols pkgdatadir)
28-
if(NOT ${PKGNAME}_PROTOCOLS_DIR OR NOT EXISTS "${${PKGNAME}_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml" OR NOT EXISTS "${${PKGNAME}_PROTOCOLS_DIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml" OR NOT EXISTS "${${PKGNAME}_PROTOCOLS_DIR}/stable/viewporter/viewporter.xml" OR NOT EXISTS "${${PKGNAME}_PROTOCOLS_DIR}/staging/fractional-scale/fractional-scale-v1.xml")
29-
message(STATUS "wayland xdg protocol missing in ${${PKGNAME}_PROTOCOLS_DIR}")
30-
unset(${PKGNAME}_PROTOCOLS_DIR)
31-
endif()
28+
set(${PKGNAME}_PROTOCOLS stable/xdg-shell/xdg-shell.xml
29+
stable/viewporter/viewporter.xml
30+
stable/tablet/tablet-v2.xml
31+
unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
32+
staging/fractional-scale/fractional-scale-v1.xml
33+
staging/cursor-shape/cursor-shape-v1.xml)
34+
foreach(xml ${${PKGNAME}_PROTOCOLS})
35+
if(${PKGNAME}_PROTOCOLS_DIR AND NOT EXISTS "${${PKGNAME}_PROTOCOLS_DIR}/${xml}")
36+
message(STATUS "wayland protocol ${xml} missing in ${${PKGNAME}_PROTOCOLS_DIR}")
37+
unset(${PKGNAME}_PROTOCOLS_DIR)
38+
endif()
39+
endforeach()
3240
endif()
3341

3442
include(FindPackageHandleStandardArgs)

0 commit comments

Comments
 (0)