2023-04-01 07:09:57 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 by Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#include "prepareutil.h"
|
|
|
|
|
|
2023-11-06 03:08:28 +00:00
|
|
|
#include <kscreen/configmonitor.h>
|
|
|
|
|
#include <kscreen/getconfigoperation.h>
|
|
|
|
|
#include <kscreen/output.h>
|
|
|
|
|
#include <kscreen/setconfigoperation.h>
|
2023-04-01 07:09:57 +00:00
|
|
|
|
2023-11-06 04:10:20 +00:00
|
|
|
#include <QDBusPendingCallWatcher>
|
|
|
|
|
#include <QDBusPendingReply>
|
2024-10-09 05:47:30 +00:00
|
|
|
#include <QProcess>
|
2023-11-06 04:10:20 +00:00
|
|
|
|
2023-04-01 07:09:57 +00:00
|
|
|
PrepareUtil::PrepareUtil(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
2023-11-09 07:22:14 +00:00
|
|
|
, m_colorsSettings{new ColorsSettings(this)}
|
2023-04-01 07:09:57 +00:00
|
|
|
{
|
2023-11-06 03:08:28 +00:00
|
|
|
connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, [this](auto *op) {
|
|
|
|
|
m_config = qobject_cast<KScreen::GetConfigOperation *>(op)->config();
|
2023-04-01 07:09:57 +00:00
|
|
|
|
2023-11-06 03:08:28 +00:00
|
|
|
int scaling = 100;
|
|
|
|
|
|
|
|
|
|
// to determine the scaling value:
|
|
|
|
|
// try to take the primary display's scaling, otherwise use the scaling of any of the displays
|
|
|
|
|
for (KScreen::OutputPtr output : m_config->outputs()) {
|
|
|
|
|
scaling = output->scale() * 100;
|
2025-03-05 16:44:31 +00:00
|
|
|
m_output = output->id();
|
2023-11-06 03:08:28 +00:00
|
|
|
if (output->isPrimary()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_scaling = scaling;
|
|
|
|
|
Q_EMIT scalingChanged();
|
|
|
|
|
});
|
2023-11-06 04:10:20 +00:00
|
|
|
|
2023-11-09 07:22:14 +00:00
|
|
|
// set property initially
|
|
|
|
|
m_usingDarkTheme = m_colorsSettings->colorScheme() == "BreezeDark";
|
2023-04-01 07:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PrepareUtil::scaling() const
|
|
|
|
|
{
|
|
|
|
|
return m_scaling;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrepareUtil::setScaling(int scaling)
|
|
|
|
|
{
|
2023-11-06 03:08:28 +00:00
|
|
|
if (!m_config) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-01 07:09:57 +00:00
|
|
|
|
2023-11-06 03:08:28 +00:00
|
|
|
const auto outputs = m_config->outputs();
|
|
|
|
|
qreal scalingNum = ((double)scaling) / 100;
|
2023-04-01 07:09:57 +00:00
|
|
|
|
2023-11-06 03:08:28 +00:00
|
|
|
for (KScreen::OutputPtr output : outputs) {
|
2025-03-05 16:44:31 +00:00
|
|
|
if (output->id() == m_output) {
|
|
|
|
|
output->setScale(scalingNum);
|
|
|
|
|
}
|
2023-04-01 07:09:57 +00:00
|
|
|
}
|
2023-11-06 03:08:28 +00:00
|
|
|
|
|
|
|
|
auto setop = new KScreen::SetConfigOperation(m_config, this);
|
|
|
|
|
setop->exec();
|
|
|
|
|
|
|
|
|
|
m_scaling = scaling;
|
|
|
|
|
Q_EMIT scalingChanged();
|
2023-04-01 07:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList PrepareUtil::scalingOptions()
|
|
|
|
|
{
|
2024-10-08 03:42:13 +00:00
|
|
|
return {"50%", "75%", "100%", "125%", "150%", "175%", "200%", "225%", "250%", "275%", "300%"};
|
2023-04-01 07:09:57 +00:00
|
|
|
}
|
2023-11-06 04:10:20 +00:00
|
|
|
|
2023-11-09 07:22:14 +00:00
|
|
|
bool PrepareUtil::usingDarkTheme() const
|
|
|
|
|
{
|
|
|
|
|
return m_usingDarkTheme;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrepareUtil::setUsingDarkTheme(bool usingDarkTheme)
|
|
|
|
|
{
|
|
|
|
|
// use plasma-apply-colorscheme since it has logic for notifying the shell of changes
|
|
|
|
|
if (usingDarkTheme) {
|
|
|
|
|
QProcess::execute("plasma-apply-colorscheme", {QStringLiteral("BreezeDark")});
|
|
|
|
|
} else {
|
|
|
|
|
QProcess::execute("plasma-apply-colorscheme", {QStringLiteral("BreezeLight")});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_usingDarkTheme = usingDarkTheme;
|
|
|
|
|
Q_EMIT usingDarkThemeChanged();
|
|
|
|
|
}
|