diff --git a/CHANGES b/CHANGES index bc3d7d396..b702583d0 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,9 @@ This release contains contributions from (alphabetically by first name): means that modules now have easier access to timezone information. Translations for timezones have also been enabled, so it is **possible** at least to translate the displayed zones in the *locale* module. + - Branding can now specify whether to (try to) display the Calamares window + in the middle of the desktop or not. The *windowPlacement* key in + `branding.desc` specifies *center* or *free* placement. ## Modules ## - The *license* module has seen a significant change to its looks. diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 5d9b29c69..f70715aea 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -35,6 +35,12 @@ windowExpanding: normal # in CalamaresUtilsGui, 800x520. windowSize: 800px,520px +# Placement of Calamares window. Either "center" or "free". +# Whether "center" actually works does depend on the window +# manager in use (and only makes sense if you're not using +# *windowExpanding* set to "fullscreen"). +windowPlacement: center + # These are strings shown to the user in the user interface. # There is no provision for translating them -- since they # are names, the string is included as-is. diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 527f92c85..8e30dfa83 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -357,6 +358,20 @@ CalamaresApplication::initView() QTimer::singleShot( 0, m_moduleManager, &Calamares::ModuleManager::loadModules ); + 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; + } + } + } cDebug() << "STARTUP: CalamaresWindow created; loadModules started"; } diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index edbced5fa..a5b6e5dce 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -410,6 +410,9 @@ Branding::initSimpleSettings( const YAML::Node& doc ) { QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen }, { QStringLiteral( "noexpand" ), WindowExpansion::Fixed } }; + static const NamedEnumTable< WindowPlacement > placementNames { + { QStringLiteral( "free" ), WindowPlacement::Free }, { QStringLiteral( "center" ), WindowPlacement::Center } + }; bool ok = false; m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false ); @@ -420,6 +423,12 @@ Branding::initSimpleSettings( const YAML::Node& doc ) cWarning() << "Branding module-setting *windowExpanding* interpreted as" << expansionNames.find( m_windowExpansion, ok ); } + m_windowPlacement = placementNames.find( getString( doc, "windowPlacement" ), ok ); + if ( !ok ) + { + cWarning() << "Branding module-setting *windowPlacement* interpreted as" + << placementNames.find( m_windowPlacement, ok ); + } QString windowSize = getString( doc, "windowSize" ); if ( !windowSize.isEmpty() ) diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 3723fd07f..30e8be846 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -108,6 +108,13 @@ public: { } }; + /** @brief Placement of main window. + */ + enum class WindowPlacement + { + Center, + Free + }; static Branding* instance(); @@ -162,6 +169,7 @@ public: { return QPair< WindowDimension, WindowDimension >( m_windowWidth, m_windowHeight ); } + bool windowPlacementCentered() const { return m_windowPlacement == WindowPlacement::Center; } /** * Creates a map called "branding" in the global storage, and inserts an @@ -193,9 +201,10 @@ private: bool m_welcomeStyleCalamares; bool m_welcomeExpandingLogo; - WindowExpansion m_windowExpansion; + WindowExpansion m_windowExpansion; WindowDimension m_windowHeight, m_windowWidth; + WindowPlacement m_windowPlacement; }; template < typename U >