From 916944807b8c54e887959eef63c542d2f16afab1 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 15 May 2018 16:24:37 +0200 Subject: Client: Move cursor theme logic into its own class, QWaylandCursorTheme ...and out of QWaylandCursor. Encapsulates the ugly details of wayland cursor themes, and presents a simple interface. A theme is created with a given size and theme name. wl_cursor_images for a theme can be acquired through: wl_cursor_image *QWaylandCursorTheme::cursorImage(Qt::CursorShape shape); Change-Id: Ia6fc6f2997133ca25c1610ecdf075ecb5c4edbfa Reviewed-by: Paul Olav Tvete --- src/client/qwaylanddisplay.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/client/qwaylanddisplay.cpp') diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index 6a6370bf9..1cb499f5e 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -159,9 +159,7 @@ QWaylandDisplay::~QWaylandDisplay(void) delete mDndSelectionHandler.take(); #endif #if QT_CONFIG(cursor) - for (auto *cursorTheme : mCursorThemesBySize) - wl_cursor_theme_destroy(cursorTheme); - mCursorThemesBySize.clear(); + qDeleteAll(mCursorThemesBySize); #endif if (mDisplay) wl_display_disconnect(mDisplay); @@ -502,13 +500,9 @@ void QWaylandDisplay::setCursor(const QSharedPointer &buffer, co } } -struct ::wl_cursor_theme *QWaylandDisplay::loadCursorTheme(qreal devicePixelRatio) +QWaylandCursorTheme *QWaylandDisplay::loadCursorTheme(qreal devicePixelRatio) { - QByteArray themeName = qgetenv("XCURSOR_THEME"); - if (themeName.isEmpty()) - themeName = QByteArray("default"); - - int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); + static int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); if (cursorSize <= 0) cursorSize = 32; if (compositorVersion() >= 3) // set_buffer_scale is not supported on earlier versions @@ -517,13 +511,12 @@ struct ::wl_cursor_theme *QWaylandDisplay::loadCursorTheme(qreal devicePixelRati if (auto *theme = mCursorThemesBySize.value(cursorSize, nullptr)) return theme; - struct ::wl_cursor_theme *theme = wl_cursor_theme_load(themeName, cursorSize, shm()->object()); - - if (!theme) - qCWarning(lcQpaWayland) << "Could not load cursor theme" << themeName; + if (auto *theme = QWaylandCursorTheme::create(shm(), cursorSize)) { + mCursorThemesBySize[cursorSize] = theme; + return theme; + } - mCursorThemesBySize[cursorSize] = theme; - return theme; + return nullptr; } #endif // QT_CONFIG(cursor) -- cgit v1.2.3