Call updateHighDpiScaling() on screenAdded()
QHighDpiScaling has two init/update functions: - initHighDpiScaling(): called once during QGuiApplication construction - updateHighDpiScaling(): called whenever (relevant) screen configuration changes Currently the calls to updateHighDpiScaling() are made from multiple places including platform code. Simplify by calling it from two locations: - QWindowSystemInterface::handleScreenAdded() - QGuiApplicationPrivate::processScreenLogicalDotsPerInchChange() Replace comment about early calls to qt_defaultDpi with a test which calls qt_defaultDpiX/Y with no screens attached. (Looking at the qt_defaultDpiX() implementation, it is unlikely that there will be a problem as long as updateHighDpiScaling() is called before QGuiApplication::primaryScreen() starts returning a non-null value.) Change-Id: I447db42894617495843a5cb531a1322b000fed62 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
dd24b61d35
commit
776734576c
@ -153,8 +153,6 @@ Qt::ApplicationState QGuiApplicationPrivate::applicationState = Qt::ApplicationI
|
|||||||
Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
|
Qt::HighDpiScaleFactorRoundingPolicy QGuiApplicationPrivate::highDpiScaleFactorRoundingPolicy =
|
||||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
|
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough;
|
||||||
|
|
||||||
bool QGuiApplicationPrivate::highDpiScalingUpdated = false;
|
|
||||||
|
|
||||||
QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
|
QPointer<QWindow> QGuiApplicationPrivate::currentDragWindow;
|
||||||
|
|
||||||
QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints; // TODO remove
|
QList<QGuiApplicationPrivate::TabletPointData> QGuiApplicationPrivate::tabletDevicePoints; // TODO remove
|
||||||
@ -709,7 +707,6 @@ QGuiApplication::~QGuiApplication()
|
|||||||
QGuiApplicationPrivate::lastCursorPosition = {qreal(qInf()), qreal(qInf())};
|
QGuiApplicationPrivate::lastCursorPosition = {qreal(qInf()), qreal(qInf())};
|
||||||
QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow = nullptr;
|
QGuiApplicationPrivate::currentMousePressWindow = QGuiApplicationPrivate::currentMouseWindow = nullptr;
|
||||||
QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
|
QGuiApplicationPrivate::applicationState = Qt::ApplicationInactive;
|
||||||
QGuiApplicationPrivate::highDpiScalingUpdated = false;
|
|
||||||
QGuiApplicationPrivate::currentDragWindow = nullptr;
|
QGuiApplicationPrivate::currentDragWindow = nullptr;
|
||||||
QGuiApplicationPrivate::tabletDevicePoints.clear();
|
QGuiApplicationPrivate::tabletDevicePoints.clear();
|
||||||
}
|
}
|
||||||
@ -1245,13 +1242,6 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Many platforms have created QScreens at this point. Finish initializing
|
|
||||||
// QHighDpiScaling to be prepared for early calls to qt_defaultDpi().
|
|
||||||
if (QGuiApplication::primaryScreen()) {
|
|
||||||
QGuiApplicationPrivate::highDpiScalingUpdated = true;
|
|
||||||
QHighDpiScaling::updateHighDpiScaling();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the platform theme:
|
// Create the platform theme:
|
||||||
|
|
||||||
// 1) Fetch the platform name from the environment if present.
|
// 1) Fetch the platform name from the environment if present.
|
||||||
@ -1526,11 +1516,6 @@ void QGuiApplicationPrivate::eventDispatcherReady()
|
|||||||
createPlatformIntegration();
|
createPlatformIntegration();
|
||||||
|
|
||||||
platform_integration->initialize();
|
platform_integration->initialize();
|
||||||
|
|
||||||
// All platforms should have added screens at this point. Finish
|
|
||||||
// QHighDpiScaling initialization if it has not been done so already.
|
|
||||||
if (!QGuiApplicationPrivate::highDpiScalingUpdated)
|
|
||||||
QHighDpiScaling::updateHighDpiScaling();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QGuiApplicationPrivate::init()
|
void QGuiApplicationPrivate::init()
|
||||||
|
@ -233,7 +233,6 @@ public:
|
|||||||
static QWindow *currentMousePressWindow;
|
static QWindow *currentMousePressWindow;
|
||||||
static Qt::ApplicationState applicationState;
|
static Qt::ApplicationState applicationState;
|
||||||
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
|
static Qt::HighDpiScaleFactorRoundingPolicy highDpiScaleFactorRoundingPolicy;
|
||||||
static bool highDpiScalingUpdated;
|
|
||||||
static QPointer<QWindow> currentDragWindow;
|
static QPointer<QWindow> currentDragWindow;
|
||||||
|
|
||||||
// TODO remove this: QPointingDevice can store what we need directly
|
// TODO remove this: QPointingDevice can store what we need directly
|
||||||
|
@ -788,6 +788,7 @@ void QWindowSystemInterface::handleScreenAdded(QPlatformScreen *ps, bool isPrima
|
|||||||
QGuiApplicationPrivate::screen_list.append(screen);
|
QGuiApplicationPrivate::screen_list.append(screen);
|
||||||
|
|
||||||
QGuiApplicationPrivate::resetCachedDevicePixelRatio();
|
QGuiApplicationPrivate::resetCachedDevicePixelRatio();
|
||||||
|
QHighDpiScaling::updateHighDpiScaling();
|
||||||
|
|
||||||
emit qGuiApp->screenAdded(screen);
|
emit qGuiApp->screenAdded(screen);
|
||||||
|
|
||||||
|
@ -641,7 +641,6 @@ bool QWindowsScreenManager::handleScreenChanges()
|
|||||||
if (auto theme = QWindowsTheme::instance()) // QTBUG-85734/Wine
|
if (auto theme = QWindowsTheme::instance()) // QTBUG-85734/Wine
|
||||||
theme->refreshFonts();
|
theme->refreshFonts();
|
||||||
}
|
}
|
||||||
QHighDpiScaling::updateHighDpiScaling();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,6 @@ void QXcbConnection::updateScreens(const xcb_randr_notify_event_t *event)
|
|||||||
screen = createScreen(virtualDesktop, output, outputInfo.get());
|
screen = createScreen(virtualDesktop, output, outputInfo.get());
|
||||||
qCDebug(lcQpaScreen) << "output" << screen->name() << "is connected and enabled";
|
qCDebug(lcQpaScreen) << "output" << screen->name() << "is connected and enabled";
|
||||||
}
|
}
|
||||||
QHighDpiScaling::updateHighDpiScaling();
|
|
||||||
}
|
}
|
||||||
} else if (screen) {
|
} else if (screen) {
|
||||||
if (output.crtc == XCB_NONE && output.mode == XCB_NONE) {
|
if (output.crtc == XCB_NONE && output.mode == XCB_NONE) {
|
||||||
|
@ -314,6 +314,11 @@ void tst_QHighDpi::minimumDpr()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
extern int qt_defaultDpiX();
|
||||||
|
extern int qt_defaultDpiY();
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
void tst_QHighDpi::noscreens()
|
void tst_QHighDpi::noscreens()
|
||||||
{
|
{
|
||||||
// Create application object with a no-screens configuration (should not crash)
|
// Create application object with a no-screens configuration (should not crash)
|
||||||
@ -321,6 +326,11 @@ void tst_QHighDpi::noscreens()
|
|||||||
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(noScreens));
|
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(noScreens));
|
||||||
|
|
||||||
QCOMPARE(qApp->devicePixelRatio(), 1);
|
QCOMPARE(qApp->devicePixelRatio(), 1);
|
||||||
|
|
||||||
|
// Test calling qt_defaultDpiX/Y: These may be called early during QGuiApplication
|
||||||
|
// initialization, before the platform plugin has created screen objects. They
|
||||||
|
// should then 1) not crash and 2) return some default value.
|
||||||
|
QCOMPARE(qt_defaultDpiX(), qt_defaultDpiY());
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QHighDpi::screenAt_data()
|
void tst_QHighDpi::screenAt_data()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user