[calamares] Refactor center-placement
- Just move it to its own function where it can have more documentation - Tested on multi-screen setups SEE #1293
This commit is contained in:
parent
61b6d058d7
commit
fcb0109b7b
@ -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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user