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
This commit is contained in:
David Edmundson 2018-06-23 18:13:48 +01:00
parent 263503f8ec
commit 9ff1f77e8e

View file

@ -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);
}