From 17d09342e9c7d2bc2352780e4fc7b5eff35f0b22 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Jan 2020 00:27:11 +0100 Subject: [PATCH 1/4] [libcalamaresui] Add a setting for window placement --- src/branding/default/branding.desc | 6 ++++++ src/libcalamaresui/Branding.cpp | 9 +++++++++ src/libcalamaresui/Branding.h | 11 ++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) 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/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 > From 60c659c82b90e91222ed572fcebc9935f2c31d45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Jan 2020 00:28:52 +0100 Subject: [PATCH 2/4] Changes: document new branding element --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) 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. From 43caf7b46a51531ec6d5e55b03eb7606219fadad Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Jan 2020 00:34:15 +0100 Subject: [PATCH 3/4] [calamares] Restore functionality for 'center window' --- src/calamares/CalamaresApplication.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 527f92c85..c5fdb6273 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -357,6 +357,10 @@ CalamaresApplication::initView() QTimer::singleShot( 0, m_moduleManager, &Calamares::ModuleManager::loadModules ); + if ( Calamares::Branding::instance() && Calamares::Branding::instance()->windowPlacementCentered() ) + { + m_mainwindow->move( this->desktop()->availableGeometry().center() - m_mainwindow->rect().center() ); + } cDebug() << "STARTUP: CalamaresWindow created; loadModules started"; } From 121013fd96beadae60727b573c47343f69ffa622 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 7 Jan 2020 01:06:26 +0100 Subject: [PATCH 4/4] [calamares] Avoid deprecated desktop() - Put Calamares on the first screen where it fits - This is wordy and weird --- src/calamares/CalamaresApplication.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index c5fdb6273..8e30dfa83 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -359,7 +360,17 @@ CalamaresApplication::initView() if ( Calamares::Branding::instance() && Calamares::Branding::instance()->windowPlacementCentered() ) { - m_mainwindow->move( this->desktop()->availableGeometry().center() - m_mainwindow->rect().center() ); + 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"; }