diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-05-15 09:58:18 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-05-28 09:10:31 +0000 |
commit | 633d4e6fd121fe128aec78bb9c137c4f2f82f1ce (patch) | |
tree | f5ac15b1f4de5357c2463cc660e9812f9ad15ca9 /src/client/qwaylanddisplay.cpp | |
parent | d579651f7ef737d480791a2680eb57aa0e29c260 (diff) |
Client: Only load cursor theme once
Now cursor themes load once per device pixel ratio, and not once per screen.
Task-number: QTBUG-67796
Change-Id: I4c253e65a791d69e7d510c4228989390a4343110
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/client/qwaylanddisplay.cpp')
-rw-r--r-- | src/client/qwaylanddisplay.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index 9cbb3524d..6a6370bf9 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -50,6 +50,9 @@ #if QT_CONFIG(wayland_datadevice) #include "qwaylanddatadevicemanager_p.h" #endif +#if QT_CONFIG(cursor) +#include <wayland-cursor.h> +#endif #include "qwaylandhardwareintegration_p.h" #include "qwaylandinputcontext_p.h" @@ -151,9 +154,15 @@ QWaylandDisplay::~QWaylandDisplay(void) mWaylandIntegration->destroyScreen(screen); } mScreens.clear(); + #if QT_CONFIG(wayland_datadevice) delete mDndSelectionHandler.take(); #endif +#if QT_CONFIG(cursor) + for (auto *cursorTheme : mCursorThemesBySize) + wl_cursor_theme_destroy(cursorTheme); + mCursorThemesBySize.clear(); +#endif if (mDisplay) wl_display_disconnect(mDisplay); } @@ -472,6 +481,7 @@ QWaylandInputDevice *QWaylandDisplay::defaultInputDevice() const } #if QT_CONFIG(cursor) + void QWaylandDisplay::setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, qreal dpr) { /* Qt doesn't tell us which input device we should set the cursor @@ -491,6 +501,31 @@ void QWaylandDisplay::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, co inputDevice->setCursor(buffer, hotSpot, dpr); } } + +struct ::wl_cursor_theme *QWaylandDisplay::loadCursorTheme(qreal devicePixelRatio) +{ + QByteArray themeName = qgetenv("XCURSOR_THEME"); + if (themeName.isEmpty()) + themeName = QByteArray("default"); + + int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); + if (cursorSize <= 0) + cursorSize = 32; + if (compositorVersion() >= 3) // set_buffer_scale is not supported on earlier versions + cursorSize *= devicePixelRatio; + + 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; + + mCursorThemesBySize[cursorSize] = theme; + return theme; +} + #endif // QT_CONFIG(cursor) } |