Client: Make CursorSurface inherit from QWaylandSurface

QWaylandSurface has now been decoupled from QWaylandWindow so we can share some
implementation with it and get rid of a lot of duplication.

Task-number: QTBUG-74373
Change-Id: Ieb9aa3a5cf11abe381b7cf407122d3ca7a9251fc
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
This commit is contained in:
Johan Klokkhammer Helsing 2019-04-05 14:36:57 +02:00 committed by Johan Helsing
parent 24be607d50
commit b384628f8b

View File

@ -41,6 +41,7 @@
#include "qwaylandintegration_p.h"
#include "qwaylandwindow_p.h"
#include "qwaylandsurface_p.h"
#include "qwaylandbuffer_p.h"
#if QT_CONFIG(wayland_datadevice)
#include "qwaylanddatadevice_p.h"
@ -190,23 +191,17 @@ QWaylandInputDevice::Pointer::~Pointer()
#if QT_CONFIG(cursor)
class CursorSurface : public QObject, public QtWayland::wl_surface
class CursorSurface : public QWaylandSurface
{
public:
explicit CursorSurface(QWaylandInputDevice::Pointer *pointer, QWaylandDisplay *display)
: m_pointer(pointer)
: QWaylandSurface(display)
, m_pointer(pointer)
{
init(display->createSurface(this));
//TODO: When we upgrade to libwayland 1.10, use wl_surface_get_version instead.
m_version = display->compositorVersion();
connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *screen) {
int oldScale = outputScale();
if (!m_screens.removeOne(static_cast<QWaylandScreen *>(screen->handle())))
return;
if (outputScale() != oldScale)
m_pointer->updateCursor();
});
connect(this, &QWaylandSurface::screensChanged,
m_pointer, &QWaylandInputDevice::Pointer::updateCursor);
}
void hide()
@ -246,38 +241,11 @@ public:
return scale;
}
protected:
void surface_enter(struct ::wl_output *output) override
{
int oldScale = outputScale();
auto *screen = QWaylandScreen::fromWlOutput(output);
if (m_screens.contains(screen))
return;
m_screens.append(screen);
if (outputScale() != oldScale)
m_pointer->updateCursor();
}
void surface_leave(struct ::wl_output *output) override
{
int oldScale = outputScale();
auto *screen = QWaylandScreen::fromWlOutput(output);
if (!m_screens.removeOne(screen))
return;
if (outputScale() != oldScale)
m_pointer->updateCursor();
}
private:
QWaylandInputDevice::Pointer *m_pointer = nullptr;
uint m_version = 0;
uint m_setSerial = 0;
QPoint m_hotspot;
QVector<QWaylandScreen *> m_screens;
};
QString QWaylandInputDevice::Pointer::cursorThemeName() const