From e27df2341592080483dcf42320f71c1e2fbed133 Mon Sep 17 00:00:00 2001 From: Deve Date: Thu, 4 May 2017 21:06:40 +0200 Subject: [PATCH] Draw mouse cursor --- CMakeLists.txt | 2 +- .../source/Irrlicht/CIrrDeviceWayland.cpp | 45 +++++++++++++++++++ .../source/Irrlicht/CIrrDeviceWayland.h | 7 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 500c2c893..f0eadd45a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -426,7 +426,7 @@ if(UNIX AND NOT APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") target_link_libraries(supertuxkart "-fsanitize=address") endif() - target_link_libraries(supertuxkart wayland-client wayland-egl EGL xkbcommon) + target_link_libraries(supertuxkart wayland-client wayland-egl wayland-cursor EGL xkbcommon) endif() if(BUILD_RECORDER) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp index 8b5af4b0c..5df1c3505 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp @@ -65,6 +65,26 @@ public: wl_fixed_t sx, wl_fixed_t sy) { printf("enter!\n"); + + CIrrDeviceWayland *device = static_cast(data); + + + if (device->default_cursor) + { + wl_cursor_image* image = device->default_cursor->images[0]; + wl_buffer* buffer = wl_cursor_image_get_buffer(image); + + if (!buffer) + return; + + wl_pointer_set_cursor(pointer, serial, device->cursor_surface, + image->hotspot_x, image->hotspot_y); + wl_surface_attach(device->cursor_surface, buffer, 0, 0); + wl_surface_damage(device->cursor_surface, 0, 0, + image->width, image->height); + wl_surface_commit(device->cursor_surface); + } + } static void @@ -512,6 +532,19 @@ public: printf("binding seat\n"); dev->seat = static_cast(wl_registry_bind(registry, name, &wl_seat_interface, 1)); } + else if (strcmp(interface, "wl_shm") == 0) { + dev->shm = static_cast(wl_registry_bind(registry, name, &wl_shm_interface, 1)); + dev->cursor_theme = wl_cursor_theme_load(NULL, 32, dev->shm); + if (!dev->cursor_theme) { + printf("unable to load default theme\n"); + return; + } + dev->default_cursor = + wl_cursor_theme_get_cursor(dev->cursor_theme, "left_ptr"); + if (!dev->default_cursor) { + printf("unable to load default left pointer\n"); + } + } else if (strcmp(interface, "wl_output") == 0) { printf("binding output\n"); @@ -616,6 +649,8 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) wl_output_add_listener(output, &WaylandCallbacks::output_listener, this); shell_surface = NULL; + cursor_surface = NULL; + cursor_theme = NULL; // create keymap createKeyMap(); @@ -626,6 +661,8 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) // create the window, only if we do not use the null device if (!createWindow()) return; + + cursor_surface = wl_compositor_create_surface(compositor); } // create cursor control @@ -653,8 +690,16 @@ CIrrDeviceWayland::~CIrrDeviceWayland() wl_keyboard_destroy(keyboard); wl_pointer_destroy(pointer); wl_seat_destroy(seat); + + if (cursor_surface) + wl_surface_destroy(cursor_surface); + + if (cursor_theme) + wl_cursor_theme_destroy(cursor_theme); + if (shell_surface) wl_shell_surface_destroy(shell_surface); + wl_registry_destroy(registry); wl_display_flush(display); wl_display_disconnect(display); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h index b6558d63b..17d33fcfb 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -246,6 +247,12 @@ namespace irr wl_pointer *pointer; wl_keyboard *keyboard; wl_output *output; + + wl_shm* shm; + wl_cursor_theme* cursor_theme; + wl_cursor* default_cursor; + wl_surface* cursor_surface; + xkb_context *xkbctx; xkb_keymap *keymap; xkb_state *state;