From fcb0109b7b600c2bab429f0af8064ef34c0e8005 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Jan 2020 09:56:13 +0100 Subject: [PATCH] [calamares] Refactor center-placement - Just move it to its own function where it can have more documentation - Tested on multi-screen setups SEE #1293 --- src/calamares/CalamaresApplication.cpp | 47 ++++++++++++++++++++------ 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 8e30dfa83..a4ae30acb 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -343,6 +343,41 @@ CalamaresApplication::initModuleManager() m_moduleManager->init(); } +/** @brief centers the widget @p w on (a) screen + * + * This tries to duplicate the (deprecated) qApp->desktop()->availableGeometry() + * placement by iterating over screens and putting Calamares in the first + * one where it fits; this is *generally* the primary screen. + * + * With debugging, it would look something like this (2 screens attached, + * primary at +1080+240 because I have a very strange X setup). Before + * being mapped, the Calamares window is at +0+0 but does have a size. + * The first screen's geometry includes the offset from the origin in + * screen coordinates. + * + * Proposed window size: 1024 520 + * Window QRect(0,0 1024x520) + * Screen QRect(1080,240 2560x1440) + * Moving QPoint(1848,700) + * Screen QRect(0,0 1080x1920) + * + */ +static void +centerWindowOnScreen( QWidget* w ) +{ + QList< QScreen* > screens = qApp->screens(); + QPoint windowCenter = w->rect().center(); + + for ( const auto* screen : screens ) + { + QPoint screenCenter = screen->availableGeometry().center(); + if ( !itFits && ( screenCenter.x() >= windowCenter.x() ) && ( screenCenter.y() >= windowCenter.y() ) ) + { + w->move( screenCenter - windowCenter ); + break; + } + } +} void CalamaresApplication::initView() @@ -360,17 +395,7 @@ CalamaresApplication::initView() if ( Calamares::Branding::instance() && Calamares::Branding::instance()->windowPlacementCentered() ) { - QList< QScreen* > screens = qApp->screens(); - QPoint windowCenter = m_mainwindow->rect().center(); - for ( const auto* screen : screens ) - { - QPoint screenCenter = screen->availableGeometry().center(); - if ( ( screenCenter.x() >= windowCenter.x() ) && ( screenCenter.y() >= windowCenter.y() ) ) - { - m_mainwindow->move( screenCenter - windowCenter ); - break; - } - } + centerWindowOnScreen( m_mainwindow ); } cDebug() << "STARTUP: CalamaresWindow created; loadModules started"; }