diff --git a/app/settings/universalsettings.cpp b/app/settings/universalsettings.cpp index 12665c50b..2cf576352 100644 --- a/app/settings/universalsettings.cpp +++ b/app/settings/universalsettings.cpp @@ -58,6 +58,8 @@ UniversalSettings::UniversalSettings(KSharedConfig::Ptr config, QObject *parent) connect(this, &UniversalSettings::screenTrackerIntervalChanged, this, &UniversalSettings::saveConfig); connect(this, &UniversalSettings::showInfoWindowChanged, this, &UniversalSettings::saveConfig); connect(this, &UniversalSettings::versionChanged, this, &UniversalSettings::saveConfig); + + connect(this, &UniversalSettings::screenScalesChanged, this, &UniversalSettings::saveScalesConfig); } UniversalSettings::~UniversalSettings() @@ -75,6 +77,9 @@ void UniversalSettings::load() setAutostart(true); } + //! init screen scales + m_screenScalesGroup = m_universalGroup.group("ScreenScales"); + //! load configuration loadConfig(); @@ -374,6 +379,42 @@ void UniversalSettings::setMouseSensitivity(Types::MouseSensitivity sensitivity) emit mouseSensitivityChanged(); } +float UniversalSettings::screenWidthScale(QString screenName) const +{ + if (!m_screenScales.contains(screenName)) { + return 1; + } + + return m_screenScales[screenName].first; +} + +float UniversalSettings::screenHeightScale(QString screenName) const +{ + if (!m_screenScales.contains(screenName)) { + return 1; + } + + return m_screenScales[screenName].second; +} + +void UniversalSettings::setScreenScales(QString screenName, float widthScale, float heightScale) +{ + if (!m_screenScales.contains(screenName)) { + m_screenScales[screenName].first = widthScale; + m_screenScales[screenName].second = heightScale; + } else { + if (m_screenScales[screenName].first == widthScale + && m_screenScales[screenName].second == heightScale) { + return; + } + + m_screenScales[screenName].first = widthScale; + m_screenScales[screenName].second = heightScale; + } + + emit screenScalesChanged(); +} + void UniversalSettings::loadConfig() { m_version = m_universalGroup.readEntry("version", 1); @@ -389,6 +430,8 @@ void UniversalSettings::loadConfig() m_showInfoWindow = m_universalGroup.readEntry("showInfoWindow", true); m_memoryUsage = static_cast(m_universalGroup.readEntry("memoryUsage", (int)Types::SingleLayout)); m_mouseSensitivity = static_cast(m_universalGroup.readEntry("mouseSensitivity", (int)Types::HighSensitivity)); + + loadScalesConfig(); } void UniversalSettings::saveConfig() @@ -445,4 +488,26 @@ QScreen *UniversalSettings::atScreens(QQmlListProperty *property, int i return qGuiApp->screens().at(index); } +void UniversalSettings::loadScalesConfig() +{ + for (const auto &screenName : m_screenScalesGroup.keyList()) { + QString scalesStr = m_screenScalesGroup.readEntry(screenName, QString()); + QStringList scales = scalesStr.split(";"); + if (scales.count() == 2) { + m_screenScales[screenName] = qMakePair(scales[0].toFloat(), scales[1].toFloat()); + } + } +} + +void UniversalSettings::saveScalesConfig() +{ + for (const auto &screenName : m_screenScales.keys()) { + QStringList scales; + scales << QString::number(m_screenScales[screenName].first) << QString::number(m_screenScales[screenName].second); + m_screenScalesGroup.writeEntry(screenName, scales.join(";")); + } + + m_screenScalesGroup.sync(); +} + } diff --git a/app/settings/universalsettings.h b/app/settings/universalsettings.h index 55afb3c7c..4203942e4 100644 --- a/app/settings/universalsettings.h +++ b/app/settings/universalsettings.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -38,8 +39,12 @@ #include namespace Latte { - class LayoutManager; +} + +namespace Latte { +//width_scale, height_scale +typedef QPair ScreenScales; //! This class holds all the settings that are universally available //! independent of layouts @@ -113,6 +118,10 @@ public slots: Q_INVOKABLE QString splitterIconPath(); Q_INVOKABLE QString trademarkIconPath(); + Q_INVOKABLE float screenWidthScale(QString screenName) const; + Q_INVOKABLE float screenHeightScale(QString screenName) const; + Q_INVOKABLE void setScreenScales(QString screenName, float widthScale, float heightScale); + signals: void autostartChanged(); void canDisableBordersChanged(); @@ -125,13 +134,16 @@ signals: void layoutsMemoryUsageChanged(); void metaPressAndHoldEnabledChanged(); void mouseSensitivityChanged(); + void screenScalesChanged(); void screenTrackerIntervalChanged(); void showInfoWindowChanged(); void versionChanged(); private slots: void loadConfig(); + void loadScalesConfig(); void saveConfig(); + void saveScalesConfig(); private: void cleanupSettings(); @@ -163,8 +175,12 @@ private: Types::LayoutsMemoryUsage m_memoryUsage; Types::MouseSensitivity m_mouseSensitivity{Types::HighSensitivity}; + //! ScreenName, + QHash m_screenScales; + QPointer m_corona; + KConfigGroup m_screenScalesGroup; KConfigGroup m_universalGroup; KSharedConfig::Ptr m_config; diff --git a/containment/package/contents/config/main.xml b/containment/package/contents/config/main.xml index 7405acf6f..984985b5b 100644 --- a/containment/package/contents/config/main.xml +++ b/containment/package/contents/config/main.xml @@ -245,14 +245,6 @@ false - - 100 - - - - 100 - - true diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index 12cef4541..f07d1c48b 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -62,13 +62,13 @@ FocusScope { property int proposedWidth: 0.84 * proposedHeight + units.smallSpacing * 2 property int proposedHeight: 36 * theme.mSize(theme.defaultFont).height - //! user set scales based on its preference, e.g. 96% of the proposed size - property int userScaleWidth: plasmoid.configuration.windowWidthScale - property int userScaleHeight: plasmoid.configuration.windowHeightScale - //! chosen size to be applied, if the user has set or not a different scale for the settings window - property int chosenWidth: userScaleWidth !== 100 ? (userScaleWidth/100) * proposedWidth : proposedWidth - property int chosenHeight: userScaleHeight !== 100 ? (userScaleHeight/100) * heightLevel * proposedHeight : heightLevel * proposedHeight + property int chosenWidth: userScaleWidth !== 1 ? userScaleWidth * proposedWidth : proposedWidth + property int chosenHeight: userScaleHeight !== 1 ? userScaleHeight * heightLevel * proposedHeight : heightLevel * proposedHeight + + //! user set scales based on its preference, e.g. 96% of the proposed size + property real userScaleWidth: 1 + property real userScaleHeight: 1 readonly property real heightLevel: (dialog.expertLevel ? 100 : 1) @@ -105,6 +105,20 @@ FocusScope { } } + Component.onCompleted: { + updateScales(); + } + + Connections { + target: latteView.positioner + onCurrentScreenNameChanged: dialog.updateScales(); + } + + function updateScales() { + userScaleWidth = universalSettings.screenWidthScale(latteView.positioner.currentScreenName); + userScaleHeight = universalSettings.screenHeightScale(latteView.positioner.currentScreenName); + } + PlasmaCore.FrameSvgItem{ anchors.fill: parent imagePath: "dialogs/background" @@ -117,8 +131,10 @@ FocusScope { hoverEnabled: true property bool blockWheel: false + property bool updatingWidthScale: false + property bool updatingHeightScale: false property bool wheelTriggeredOnce: false - property int scaleStep: 4 + property real scaleStep: 0.04 onContainsMouseChanged: { if (!containsMouse) { @@ -127,10 +143,16 @@ FocusScope { } onWheel: { - if (blockWheel || !(wheel.modifiers & Qt.MetaModifier)){ + var metaModifier = (wheel.modifiers & Qt.MetaModifier); + var ctrlModifier = (wheel.modifiers & Qt.ControlModifier); + + if (blockWheel || !(metaModifier || ctrlModifier)){ return; } + updatingWidthScale = metaModifier || (dialog.expertLevel && ctrlModifier); + updatingHeightScale = !dialog.expertLevel && ctrlModifier; + blockWheel = true; wheelTriggeredOnce = true; scrollDelayer.start(); @@ -139,13 +161,27 @@ FocusScope { //positive direction if (angle > 12) { - plasmoid.configuration.windowWidthScale = plasmoid.configuration.windowWidthScale + scaleStep; - plasmoid.configuration.windowHeightScale = plasmoid.configuration.windowHeightScale + scaleStep; + var scales; + if (updatingWidthScale) { + userScaleWidth = userScaleWidth + scaleStep; + } + + if (updatingHeightScale) { + userScaleHeight = userScaleHeight + scaleStep; + } + + universalSettings.setScreenScales(latteView.positioner.currentScreenName, userScaleWidth, userScaleHeight); viewConfig.syncGeometry(); //negative direction } else if (angle < -12) { - plasmoid.configuration.windowWidthScale = plasmoid.configuration.windowWidthScale - scaleStep; - plasmoid.configuration.windowHeightScale = plasmoid.configuration.windowHeightScale - scaleStep; + if (updatingWidthScale) { + userScaleWidth = userScaleWidth - scaleStep; + } + + if (updatingHeightScale) { + userScaleHeight = userScaleHeight - scaleStep; + } + universalSettings.setScreenScales(latteView.positioner.currentScreenName, userScaleWidth, userScaleHeight); viewConfig.syncGeometry(); } } @@ -154,7 +190,9 @@ FocusScope { PlasmaComponents.Label{ anchors.top: parent.top anchors.horizontalCenter: parent.horizontalCenter - text: i18nc("view settings window scale","Window scale at %0%").arg(userScaleWidth) + text: backgroundMouseArea.updatingWidthScale ? + i18nc("view settings width scale","Width scale at %0%").arg(userScaleWidth * 100) : + i18nc("view settings height scale","Height scale at %0%").arg(userScaleHeight * 100) visible: backgroundMouseArea.containsMouse && backgroundMouseArea.wheelTriggeredOnce }