diff --git a/kcm/src/outputconfig.cpp b/kcm/src/outputconfig.cpp --- a/kcm/src/outputconfig.cpp +++ b/kcm/src/outputconfig.cpp @@ -21,6 +21,7 @@ #include "outputconfig.h" #include "resolutionslider.h" +#include "scalingconfig.h" #include "collapsablebutton.h" #include "utils.h" #include "kcm_screen_debug.h" @@ -33,6 +34,7 @@ #include #include #include +#include #include #include @@ -137,6 +139,14 @@ formLayout->addRow(i18n("Scale:"), mScale); formLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum)); + } else { + QPushButton *scaleDialogButton = new QPushButton(i18n("Scale Display"), this); + connect(scaleDialogButton, &QPushButton::released, [this] { + QPointer dialog = new ScalingConfig(mOutput, this); + dialog->exec(); + delete dialog; + }); + formLayout->addWidget(scaleDialogButton); } CollapsableButton *advancedButton = new CollapsableButton(i18n("Advanced Settings"), this); diff --git a/kcm/src/scalingconfig.h b/kcm/src/scalingconfig.h --- a/kcm/src/scalingconfig.h +++ b/kcm/src/scalingconfig.h @@ -30,7 +30,7 @@ { Q_OBJECT public: - explicit ScalingConfig(const KScreen::OutputList &outputList, QWidget* parent = 0); + explicit ScalingConfig(const KScreen::OutputPtr &output, QWidget* parent = 0); virtual ~ScalingConfig(); protected: @@ -41,7 +41,8 @@ int scaleDPI() const; Ui::Scaling ui; qreal m_initialScalingFactor = 1.0; - KScreen::OutputList m_outputList; + QMap m_screenFactors; + KScreen::OutputPtr m_output; }; #endif // SCALINGCONFIG_H diff --git a/kcm/src/scalingconfig.cpp b/kcm/src/scalingconfig.cpp --- a/kcm/src/scalingconfig.cpp +++ b/kcm/src/scalingconfig.cpp @@ -30,9 +30,9 @@ //slider can only handle ints so goes 10-30 #define SLIDER_RATIO 10.0 -ScalingConfig::ScalingConfig(const KScreen::OutputList &outputList, QWidget* parent): +ScalingConfig::ScalingConfig(const KScreen::OutputPtr &output, QWidget* parent): QDialog(parent), - m_outputList(outputList) + m_output(output) { ui.setupUi(this); @@ -60,62 +60,55 @@ void ScalingConfig::load() { - //we load UI from a config, as rdb value might not be updated yet + m_initialScalingFactor = 1.0; + auto config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); - const qreal dpi = config->group("KScreen").readEntry("ScaleFactor", 1.0); - - m_initialScalingFactor = dpi; - ui.scaleSlider->setValue(dpi * SLIDER_RATIO); + const QString screenFactorsString = config->group("KScreen").readEntry("ScreenScaleFactors"); + const QStringList screenFactorList = screenFactorsString.split(';'); + for (const QString screenFactor : screenFactorList) { + const QStringList parts = screenFactor.split('='); + QString name = parts[0]; + qreal factor; + bool ok; + + if (parts.size() == 2 && (factor = parts[1].toDouble(&ok), ok)) { + m_screenFactors[name] = factor; + if (name == m_output->name()) { + m_initialScalingFactor = factor; + } + } + } + + ui.scaleSlider->setValue(m_initialScalingFactor * SLIDER_RATIO); } void ScalingConfig::accept() { - if (scaleFactor() == m_initialScalingFactor) { + const qreal scalingFactor = scaleFactor(); + if (scalingFactor == m_initialScalingFactor) { QDialog::accept(); return; } - const qreal scalingFactor = scaleFactor(); - - //save to config - auto config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); - config->group("KScreen").writeEntry("ScaleFactor", scalingFactor); - //write env var to be used by startkde.sh to populate the QT_SCREEN_SCALE_FACTORS env var - //we use QT_SCREEN_SCALE_FACTORS as opposed to QT_SCALE_FACTOR as we need to use one that will *NOT* scale fonts according to the scale - //scaling the fonts makes sense if you don't also set a font DPI, but we *need* to set a font DPI for both PlasmaShell which does it's own thing, and for KDE4/GTK2 applications + m_screenFactors[m_output->name()] = scalingFactor; + //write env var to be used by startkde.sh to populate the QT_SCREEN_SCALE_FACTORS env var + auto config = KSharedConfig::openConfig(QStringLiteral("kdeglobals")); QString screenFactors; - foreach (const KScreen::OutputPtr &output, m_outputList) { - screenFactors.append(output->name() + QLatin1Char('=') + QString::number(scalingFactor) + QLatin1Char(';')); + for (auto screenFactor = m_screenFactors.constBegin(); screenFactor != m_screenFactors.constEnd(); screenFactor++) { + screenFactors.append(screenFactor.key() + QLatin1Char('=') + QString::number(screenFactor.value()) + QLatin1Char(';')); } config->group("KScreen").writeEntry("ScreenScaleFactors", screenFactors); - - KConfig fontConfig("kcmfonts"); - auto fontConfigGroup = fontConfig.group("General"); - - if (qFuzzyCompare(scalingFactor, 1.0)) { - //if dpi is the default (96) remove the entry rather than setting it - QProcess proc; - proc.start(QStringLiteral("xrdb -quiet -remove -nocpp")); - if (proc.waitForStarted()) { - proc.write(QByteArray("Xft.dpi\n")); - proc.closeWriteChannel(); - proc.waitForFinished(); - } - fontConfigGroup.writeEntry("forceFontDPI", 0); - } else { - QProcess proc; - proc.start(QStringLiteral("xrdb -quiet -merge -nocpp")); - if (proc.waitForStarted()) { - proc.write(QByteArray("Xft.dpi: " + QString::number(scaleDPI()).toLatin1())); - proc.closeWriteChannel(); - proc.waitForFinished(); - } - fontConfigGroup.writeEntry("forceFontDPI", scaleDPI()); + //The forced font DPI is used both by Plasmashell and non-Qt 5 applications, so it's set + //to the DPI of the primary monitor. + if(m_output->isPrimary()) { + const qreal value = qFuzzyCompare(scalingFactor, 1.0) ? 0 : scaleDPI(); + KConfig("kcmfonts").group("General").writeEntry("forceFontDPI", value); + //It's not applied immediately as ScreenScaleFactors only takes effect on in next session, + //which would cause a mismatch between scale and font size. } - QDialog::accept(); } diff --git a/kcm/src/widget.h b/kcm/src/widget.h --- a/kcm/src/widget.h +++ b/kcm/src/widget.h @@ -94,7 +94,6 @@ QLabel *mPrimaryLabel = nullptr; QComboBox *mProfilesCombo = nullptr; - QPushButton *mScaleAllOutputsButton = nullptr; QPushButton *mUnifyButton = nullptr; QPushButton *mSaveProfileButton = nullptr; diff --git a/kcm/src/widget.cpp b/kcm/src/widget.cpp --- a/kcm/src/widget.cpp +++ b/kcm/src/widget.cpp @@ -33,7 +33,6 @@ #include "declarative/qmloutput.h" #include "declarative/qmlscreen.h" #include "utils.h" -#include "scalingconfig.h" #include #include @@ -119,17 +118,6 @@ vbox->addWidget(mUnifyButton); - mScaleAllOutputsButton = new QPushButton(i18n("Scale Display"), this); - connect(mScaleAllOutputsButton, &QPushButton::released, - [this] { - QPointer dialog = new ScalingConfig(mConfig->outputs(), this); - dialog->exec(); - delete dialog; - }); - - vbox->addWidget(mScaleAllOutputsButton); - - mOutputTimer = new QTimer(this); connect(mOutputTimer, &QTimer::timeout, this, &Widget::clearOutputIdentifiers); @@ -175,7 +163,6 @@ mControlPanel->setConfig(mConfig); mPrimaryCombo->setConfig(mConfig); mUnifyButton->setEnabled(mConfig->outputs().count() > 1); - mScaleAllOutputsButton->setVisible(!mConfig->supportedFeatures().testFlag(KScreen::Config::Feature::PerOutputScaling)); mPrimaryCombo->setVisible(mConfig->supportedFeatures().testFlag(KScreen::Config::Feature::PrimaryDisplay)); mPrimaryLabel->setVisible(mConfig->supportedFeatures().testFlag(KScreen::Config::Feature::PrimaryDisplay));