From ba39e88680e782d165971a76db8651143b0abcce Mon Sep 17 00:00:00 2001 From: Deve Date: Fri, 12 May 2017 21:47:51 +0200 Subject: [PATCH] Update cursor when visibility is changed --- .../source/Irrlicht/CIrrDeviceWayland.cpp | 52 +++++++++++-------- .../source/Irrlicht/CIrrDeviceWayland.h | 4 ++ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp index 25bb8938c..7f235b6e5 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp @@ -68,28 +68,8 @@ public: CIrrDeviceWayland *device = static_cast(data); - //TODO: move it to better place - if (!device->getCursorControl()->isVisible() && - device->CreationParams.Fullscreen) - { - wl_pointer_set_cursor(pointer, serial, NULL, 0, 0); - } - else 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); - } - + device->enter_serial = serial; + device->updateCursor(); } static void @@ -103,7 +83,9 @@ public: uint32_t time, wl_fixed_t sx, wl_fixed_t sy) { CIrrDeviceWayland *device = static_cast(data); + device->getCursorControl()->setPosition(sx, sy); + SEvent irrevent; irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT; irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; @@ -694,6 +676,7 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) pointer = 0; keyboard = 0; ButtonStates = 0; + enter_serial = 0; wl_seat_add_listener(seat, &WaylandCallbacks::seat_listener, this); wl_output_add_listener(output, &WaylandCallbacks::output_listener, this); @@ -835,6 +818,7 @@ void CIrrDeviceWayland::createDriver() } } + void CIrrDeviceWayland::swapBuffers() { wl_display_dispatch_pending(display); @@ -842,6 +826,30 @@ void CIrrDeviceWayland::swapBuffers() } +void CIrrDeviceWayland::updateCursor() +{ + if (!getCursorControl()->isVisible() && CreationParams.Fullscreen) + { + wl_pointer_set_cursor(pointer, enter_serial, NULL, 0, 0); + } + else if (default_cursor) + { + wl_cursor_image* image = default_cursor->images[0]; + wl_buffer* buffer = wl_cursor_image_get_buffer(image); + + if (!buffer) + return; + + wl_pointer_set_cursor(pointer, enter_serial, cursor_surface, + image->hotspot_x, image->hotspot_y); + wl_surface_attach(cursor_surface, buffer, 0, 0); + wl_surface_damage(cursor_surface, 0, 0, + image->width, image->height); + wl_surface_commit(cursor_surface); + } +} + + //! runs the device. Returns false if device wants to be deleted bool CIrrDeviceWayland::run() { diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h index 579fe1bb9..6c55cd574 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h @@ -139,7 +139,9 @@ namespace irr { if (visible==IsVisible) return; + IsVisible = visible; + Device->updateCursor(); } //! Returns if the cursor is currently visible. @@ -267,9 +269,11 @@ namespace irr wl_egl_window *egl_window; u32 ButtonStates; + uint32_t enter_serial; ContextManagerEGL* getEGLContext() {return EglContext;} void swapBuffers(); + void updateCursor(); private: // XVisualInfo* visual;