Adapt the cursor size per screen
Adapt the cursor size to the screen's devicePixelRatio, so we are not forced to have a tiny cursor on a high dpi screen or a huge cursor on external low-dpi displays. Change-Id: I3712dc64e5c5e2e05d0dc5943bd49ba5c1335cd3 Reviewed-by: Johan Helsing <johan.helsing@qt.io> Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
parent
9b49788540
commit
c683571411
@ -60,11 +60,14 @@ QWaylandCursor::QWaylandCursor(QWaylandScreen *screen)
|
|||||||
QByteArray cursorTheme = qgetenv("XCURSOR_THEME");
|
QByteArray cursorTheme = qgetenv("XCURSOR_THEME");
|
||||||
if (cursorTheme.isEmpty())
|
if (cursorTheme.isEmpty())
|
||||||
cursorTheme = QByteArray("default");
|
cursorTheme = QByteArray("default");
|
||||||
QByteArray cursorSizeFromEnv = qgetenv("XCURSOR_SIZE");
|
int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE");
|
||||||
bool hasCursorSize = false;
|
if (cursorSize <= 0)
|
||||||
int cursorSize = cursorSizeFromEnv.toInt(&hasCursorSize);
|
|
||||||
if (!hasCursorSize || cursorSize <= 0)
|
|
||||||
cursorSize = 32;
|
cursorSize = 32;
|
||||||
|
|
||||||
|
// wl_surface.set_buffer_scale is not supported on earlier versions
|
||||||
|
if (mDisplay->compositorVersion() >= 3)
|
||||||
|
cursorSize *= screen->devicePixelRatio();
|
||||||
|
|
||||||
mCursorTheme = wl_cursor_theme_load(cursorTheme, cursorSize, mDisplay->shm()->object());
|
mCursorTheme = wl_cursor_theme_load(cursorTheme, cursorSize, mDisplay->shm()->object());
|
||||||
if (!mCursorTheme)
|
if (!mCursorTheme)
|
||||||
qDebug() << "Could not load theme" << cursorTheme;
|
qDebug() << "Could not load theme" << cursorTheme;
|
||||||
@ -84,7 +87,7 @@ struct wl_cursor_image *QWaylandCursor::cursorImage(Qt::CursorShape newShape)
|
|||||||
/* Hide cursor */
|
/* Hide cursor */
|
||||||
if (newShape == Qt::BlankCursor)
|
if (newShape == Qt::BlankCursor)
|
||||||
{
|
{
|
||||||
mDisplay->setCursor(nullptr, nullptr);
|
mDisplay->setCursor(nullptr, nullptr, 1);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +128,10 @@ QSharedPointer<QWaylandBuffer> QWaylandCursor::cursorBitmapImage(const QCursor *
|
|||||||
|
|
||||||
void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window)
|
void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window)
|
||||||
{
|
{
|
||||||
Q_UNUSED(window)
|
|
||||||
|
|
||||||
const Qt::CursorShape newShape = cursor ? cursor->shape() : Qt::ArrowCursor;
|
const Qt::CursorShape newShape = cursor ? cursor->shape() : Qt::ArrowCursor;
|
||||||
|
|
||||||
if (newShape == Qt::BitmapCursor) {
|
if (newShape == Qt::BitmapCursor) {
|
||||||
mDisplay->setCursor(cursorBitmapImage(cursor), cursor->hotSpot());
|
mDisplay->setCursor(cursorBitmapImage(cursor), cursor->hotSpot(), window->screen()->devicePixelRatio());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
|
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
|
||||||
mDisplay->setCursor(buffer, image);
|
mDisplay->setCursor(buffer, image, window->screen()->devicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandCursor::pointerEvent(const QMouseEvent &event)
|
void QWaylandCursor::pointerEvent(const QMouseEvent &event)
|
||||||
|
@ -474,23 +474,23 @@ QWaylandInputDevice *QWaylandDisplay::defaultInputDevice() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
void QWaylandDisplay::setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image)
|
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
|
/* Qt doesn't tell us which input device we should set the cursor
|
||||||
* for, so set it for all devices. */
|
* for, so set it for all devices. */
|
||||||
for (int i = 0; i < mInputDevices.count(); i++) {
|
for (int i = 0; i < mInputDevices.count(); i++) {
|
||||||
QWaylandInputDevice *inputDevice = mInputDevices.at(i);
|
QWaylandInputDevice *inputDevice = mInputDevices.at(i);
|
||||||
inputDevice->setCursor(buffer, image);
|
inputDevice->setCursor(buffer, image, dpr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandDisplay::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot)
|
void QWaylandDisplay::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, qreal dpr)
|
||||||
{
|
{
|
||||||
/* Qt doesn't tell us which input device we should set the cursor
|
/* Qt doesn't tell us which input device we should set the cursor
|
||||||
* for, so set it for all devices. */
|
* for, so set it for all devices. */
|
||||||
for (int i = 0; i < mInputDevices.count(); i++) {
|
for (int i = 0; i < mInputDevices.count(); i++) {
|
||||||
QWaylandInputDevice *inputDevice = mInputDevices.at(i);
|
QWaylandInputDevice *inputDevice = mInputDevices.at(i);
|
||||||
inputDevice->setCursor(buffer, hotSpot);
|
inputDevice->setCursor(buffer, hotSpot, dpr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // QT_CONFIG(cursor)
|
#endif // QT_CONFIG(cursor)
|
||||||
|
@ -121,8 +121,8 @@ public:
|
|||||||
|
|
||||||
QWaylandWindowManagerIntegration *windowManagerIntegration() const;
|
QWaylandWindowManagerIntegration *windowManagerIntegration() const;
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
void setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image);
|
void setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, qreal dpr);
|
||||||
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot);
|
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, qreal dpr);
|
||||||
#endif
|
#endif
|
||||||
struct wl_display *wl_display() const { return mDisplay; }
|
struct wl_display *wl_display() const { return mDisplay; }
|
||||||
struct ::wl_registry *wl_registry() { return object(); }
|
struct ::wl_registry *wl_registry() { return object(); }
|
||||||
|
@ -371,7 +371,7 @@ void QWaylandInputDevice::setCursor(Qt::CursorShape newShape, QWaylandScreen *sc
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
|
struct wl_buffer *buffer = wl_cursor_image_get_buffer(image);
|
||||||
setCursor(buffer, image);
|
setCursor(buffer, image, screen->devicePixelRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandInputDevice::setCursor(const QCursor &cursor, QWaylandScreen *screen)
|
void QWaylandInputDevice::setCursor(const QCursor &cursor, QWaylandScreen *screen)
|
||||||
@ -381,20 +381,20 @@ void QWaylandInputDevice::setCursor(const QCursor &cursor, QWaylandScreen *scree
|
|||||||
|
|
||||||
mPointer->mCursorShape = cursor.shape();
|
mPointer->mCursorShape = cursor.shape();
|
||||||
if (cursor.shape() == Qt::BitmapCursor) {
|
if (cursor.shape() == Qt::BitmapCursor) {
|
||||||
setCursor(screen->waylandCursor()->cursorBitmapImage(&cursor), cursor.hotSpot());
|
setCursor(screen->waylandCursor()->cursorBitmapImage(&cursor), cursor.hotSpot(), screen->devicePixelRatio());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setCursor(cursor.shape(), screen);
|
setCursor(cursor.shape(), screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image)
|
void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, int bufferScale)
|
||||||
{
|
{
|
||||||
setCursor(buffer,
|
setCursor(buffer,
|
||||||
image ? QPoint(image->hotspot_x, image->hotspot_y) : QPoint(),
|
image ? QPoint(image->hotspot_x, image->hotspot_y) : QPoint(),
|
||||||
image ? QSize(image->width, image->height) : QSize());
|
image ? QSize(image->width, image->height) : QSize(), bufferScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size)
|
void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size, int bufferScale)
|
||||||
{
|
{
|
||||||
if (mCaps & WL_SEAT_CAPABILITY_POINTER) {
|
if (mCaps & WL_SEAT_CAPABILITY_POINTER) {
|
||||||
bool force = mPointer->mEnterSerial > mPointer->mCursorSerial;
|
bool force = mPointer->mEnterSerial > mPointer->mCursorSerial;
|
||||||
@ -417,14 +417,16 @@ void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, const QPoint &hotS
|
|||||||
mPointer->set_cursor(mPointer->mEnterSerial, pointerSurface,
|
mPointer->set_cursor(mPointer->mEnterSerial, pointerSurface,
|
||||||
hotSpot.x(), hotSpot.y());
|
hotSpot.x(), hotSpot.y());
|
||||||
wl_surface_attach(pointerSurface, buffer, 0, 0);
|
wl_surface_attach(pointerSurface, buffer, 0, 0);
|
||||||
|
if (mQDisplay->compositorVersion() >= 3)
|
||||||
|
wl_surface_set_buffer_scale(pointerSurface, bufferScale);
|
||||||
wl_surface_damage(pointerSurface, 0, 0, size.width(), size.height());
|
wl_surface_damage(pointerSurface, 0, 0, size.width(), size.height());
|
||||||
wl_surface_commit(pointerSurface);
|
wl_surface_commit(pointerSurface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWaylandInputDevice::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot)
|
void QWaylandInputDevice::setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, int bufferScale)
|
||||||
{
|
{
|
||||||
setCursor(buffer->buffer(), hotSpot, buffer->size());
|
setCursor(buffer->buffer(), hotSpot, buffer->size(), bufferScale);
|
||||||
mPixmapCursor = buffer;
|
mPixmapCursor = buffer;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -110,9 +110,9 @@ public:
|
|||||||
|
|
||||||
#if QT_CONFIG(cursor)
|
#if QT_CONFIG(cursor)
|
||||||
void setCursor(const QCursor &cursor, QWaylandScreen *screen);
|
void setCursor(const QCursor &cursor, QWaylandScreen *screen);
|
||||||
void setCursor(struct wl_buffer *buffer, struct ::wl_cursor_image *image);
|
void setCursor(struct wl_buffer *buffer, struct ::wl_cursor_image *image, int bufferScale);
|
||||||
void setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size);
|
void setCursor(struct wl_buffer *buffer, const QPoint &hotSpot, const QSize &size, int bufferScale);
|
||||||
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot);
|
void setCursor(const QSharedPointer<QWaylandBuffer> &buffer, const QPoint &hotSpot, int bufferScale);
|
||||||
#endif
|
#endif
|
||||||
void handleWindowDestroyed(QWaylandWindow *window);
|
void handleWindowDestroyed(QWaylandWindow *window);
|
||||||
void handleEndDrag();
|
void handleEndDrag();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user