From 9ff1f77e8edaa0c87aeee1cdcc698e42121e2c59 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Sat, 23 Jun 2018 18:13:48 +0100 Subject: [PATCH] Support cursor scaling in X windowed backend Test Plan: Ran kwin_wayland --windowed --scale2 Hovered over deco. Got massive and detailed cursor Hovered over a wayland client (Qt 5.11 not dev) Got a massive, but slightly blocky cursor Reviewers: #kwin, graesslin Reviewed By: #kwin, graesslin Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D13642 --- plugins/platforms/x11/windowed/x11windowed_backend.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/platforms/x11/windowed/x11windowed_backend.cpp b/plugins/platforms/x11/windowed/x11windowed_backend.cpp index 95306b027c..2e26a00923 100644 --- a/plugins/platforms/x11/windowed/x11windowed_backend.cpp +++ b/plugins/platforms/x11/windowed/x11windowed_backend.cpp @@ -404,19 +404,24 @@ void X11WindowedBackend::updateSize(xcb_configure_notify_event_t *event) } } -void X11WindowedBackend::createCursor(const QImage &img, const QPoint &hotspot) +void X11WindowedBackend::createCursor(const QImage &srcImage, const QPoint &hotspot) { const xcb_pixmap_t pix = xcb_generate_id(m_connection); const xcb_gcontext_t gc = xcb_generate_id(m_connection); const xcb_cursor_t cid = xcb_generate_id(m_connection); + //right now on X we only have one scale between all screens, and we know we will have at least one screen + const qreal outputScale = screenScales().first(); + const QSize targetSize = srcImage.size() * outputScale / srcImage.devicePixelRatio(); + const QImage img = srcImage.scaled(targetSize, Qt::KeepAspectRatio); + xcb_create_pixmap(m_connection, 32, pix, m_screen->root, img.width(), img.height()); xcb_create_gc(m_connection, gc, pix, 0, nullptr); xcb_put_image(m_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, img.width(), img.height(), 0, 0, 0, 32, img.byteCount(), img.constBits()); XRenderPicture pic(pix, 32); - xcb_render_create_cursor(m_connection, cid, pic, hotspot.x(), hotspot.y()); + xcb_render_create_cursor(m_connection, cid, pic, qRound(hotspot.x() * outputScale), qRound(hotspot.y() * outputScale)); for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) { xcb_change_window_attributes(m_connection, (*it).window, XCB_CW_CURSOR, &cid); }