From 89aee9ecde7ca28b5ed93514c07c41ed110849cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 22 Nov 2011 11:06:15 +0100 Subject: [PATCH] Added QPA window system interface handler for logical DPI changes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Logical DPI is independent from geometry and physical DPI. Change-Id: Ice487f61e1bda9e6791e2adf6998ebf61cdbaef2 Reviewed-by: Lars Knoll Reviewed-by: Jørgen Lind --- src/gui/kernel/qguiapplication.cpp | 23 ++++++++++++++++--- src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qwindowsysteminterface_qpa.cpp | 7 ++++++ src/gui/kernel/qwindowsysteminterface_qpa.h | 1 + src/gui/kernel/qwindowsysteminterface_qpa_p.h | 8 +++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 63e8909eeb..859295de2b 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -586,6 +586,10 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv QGuiApplicationPrivate::reportAvailableGeometryChange( static_cast(e)); break; + case QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInch: + QGuiApplicationPrivate::reportLogicalDotsPerInchChange( + static_cast(e)); + break; case QWindowSystemInterfacePrivate::Map: QGuiApplicationPrivate::processMapEvent(static_cast(e)); break; @@ -998,9 +1002,6 @@ void QGuiApplicationPrivate::reportGeometryChange(QWindowSystemInterfacePrivate: emit s->physicalDotsPerInchXChanged(s->physicalDotsPerInchX()); emit s->physicalDotsPerInchYChanged(s->physicalDotsPerInchY()); emit s->physicalDotsPerInchChanged(s->physicalDotsPerInch()); - emit s->logicalDotsPerInchXChanged(s->logicalDotsPerInchX()); - emit s->logicalDotsPerInchYChanged(s->logicalDotsPerInchY()); - emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch()); emit s->availableSizeChanged(s->availableSize()); emit s->availableGeometryChanged(s->availableGeometry()); } @@ -1021,6 +1022,22 @@ void QGuiApplicationPrivate::reportAvailableGeometryChange( emit s->availableGeometryChanged(s->availableGeometry()); } +void QGuiApplicationPrivate::reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e) +{ + // This operation only makes sense after the QGuiApplication constructor runs + if (QCoreApplication::startingUp()) + return; + + if (!e->screen) + return; + + QScreen *s = e->screen.data(); + + emit s->logicalDotsPerInchXChanged(s->logicalDotsPerInchX()); + emit s->logicalDotsPerInchYChanged(s->logicalDotsPerInchY()); + emit s->logicalDotsPerInchChanged(s->logicalDotsPerInch()); +} + void QGuiApplicationPrivate::processMapEvent(QWindowSystemInterfacePrivate::MapEvent *e) { if (!e->mapped) diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 255a1587f5..9c8a2ca642 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -125,6 +125,7 @@ public: static void reportScreenOrientationChange(QWindowSystemInterfacePrivate::ScreenOrientationEvent *e); static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e); static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e); + static void reportLogicalDotsPerInchChange(QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e); static void processMapEvent(QWindowSystemInterfacePrivate::MapEvent *e); static void processUnmapEvent(QWindowSystemInterfacePrivate::UnmapEvent *e); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 17a5bb4eda..979a168c05 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -278,6 +278,13 @@ void QWindowSystemInterface::handleScreenAvailableGeometryChange(QScreen *screen QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } +void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen) +{ + QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e = + new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); +} + void QWindowSystemInterface::handleMapEvent(QWindow *tlw) { QWindowSystemInterfacePrivate::MapEvent *e = new QWindowSystemInterfacePrivate::MapEvent(tlw); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 04e8a6e01c..d00f0af37c 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -117,6 +117,7 @@ public: static void handleScreenOrientationChange(QScreen *screen); static void handleScreenGeometryChange(QScreen *screen); static void handleScreenAvailableGeometryChange(QScreen *screen); + static void handleScreenLogicalDotsPerInchChange(QScreen *screen); // For event dispatcher implementations static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index 44746500aa..7d5455c06b 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -63,6 +63,7 @@ public: ScreenOrientation, ScreenGeometry, ScreenAvailableGeometry, + ScreenLogicalDotsPerInch, Map, Unmap, Expose @@ -215,6 +216,13 @@ public: QWeakPointer screen; }; + class ScreenLogicalDotsPerInchEvent : public WindowSystemEvent { + public: + ScreenLogicalDotsPerInchEvent(QScreen *s) + : WindowSystemEvent(ScreenLogicalDotsPerInch), screen(s) { } + QWeakPointer screen; + }; + class MapEvent : public WindowSystemEvent { public: MapEvent(QWindow *mapped)