shift-shell/components/quicksettingsplugin/quicksettingsconfig.cpp
Devin Lin 839d5e2bff panels: Add support for defining device specific panel tweaks
This adds support for specifying options needed to deal with phone
display panel pecularities (ex. screen curves, notches, punch holes)

This is implemented as settings in ~/.config/plasmamobilerc, which can
set panel heights, paddings, and center spacings to duck display
cutouts. The pixel values are scaling independent, and so are not
affected when the display scaling is changed.

This is then exposed over DBus, so that components from outside of
plasmashell (ex. KWin) can access it easily without needing to connect to
kscreen themselves. Each screen is exposed as a single object.

Currently support is only added in the status bar and the navigation
panel.

Currently all screens have the settings applied. In the future, we may
want to limit this just to the internal screen (?)

---

This also adds a "devices" folder (in `devices/configs`) where per-device configs can be set.

This is installed to `/usr/share/plasma-mobile-device-configs`.
In `plasmamobilerc` (installed to `/etc/xdg/plasmamobilerc`, or
`~/.config/plasmamobilerc`), envmanager will read:

```toml
[Device]
device=oneplus-enchilada
```

for the device config to use and write its settings to
`~/.config/plasma-mobile/plasmamobilerc`.
2025-11-04 23:08:18 -05:00

71 lines
3.5 KiB
C++

/*
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "quicksettingsconfig.h"
#include <QDebug>
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
const QString QUICKSETTINGS_CONFIG_GROUP = QStringLiteral("QuickSettings");
QuickSettingsConfig::QuickSettingsConfig(QObject *parent)
: QObject{parent}
, m_config{KSharedConfig::openConfig(CONFIG_FILE)}
{
m_configWatcher = KConfigWatcher::create(m_config);
connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group) -> void {
if (group.name() == QUICKSETTINGS_CONFIG_GROUP) {
Q_EMIT enabledQuickSettingsChanged();
Q_EMIT disabledQuickSettingsChanged();
}
});
}
QList<QString> QuickSettingsConfig::enabledQuickSettings() const
{
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
// TODO move defaults to file
// we aren't worried about quicksettings not showing up though, any that are not specified will be automatically added to the end
return group.readEntry("enabledQuickSettings",
QList<QString>{QStringLiteral("org.kde.plasma.quicksetting.wifi"),
QStringLiteral("org.kde.plasma.quicksetting.mobiledata"),
QStringLiteral("org.kde.plasma.quicksetting.bluetooth"),
QStringLiteral("org.kde.plasma.quicksetting.flashlight"),
QStringLiteral("org.kde.plasma.quicksetting.screenrotation"),
QStringLiteral("org.kde.plasma.quicksetting.settingsapp"),
QStringLiteral("org.kde.plasma.quicksetting.airplanemode"),
QStringLiteral("org.kde.plasma.quicksetting.audio"),
QStringLiteral("org.kde.plasma.quicksetting.battery"),
QStringLiteral("org.kde.plasma.quicksetting.record"),
QStringLiteral("org.kde.plasma.quicksetting.nightcolor"),
QStringLiteral("org.kde.plasma.quicksetting.screenshot"),
QStringLiteral("org.kde.plasma.quicksetting.powermenu"),
QStringLiteral("org.kde.plasma.quicksetting.donotdisturb"),
QStringLiteral("org.kde.plasma.quicksetting.caffeine"),
QStringLiteral("org.kde.plasma.quicksetting.keyboardtoggle"),
QStringLiteral("org.kde.plasma.quicksetting.hotspot")});
}
void QuickSettingsConfig::setEnabledQuickSettings(QList<QString> &list)
{
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
group.writeEntry("enabledQuickSettings", list, KConfigGroup::Notify);
m_config->sync();
}
QList<QString> QuickSettingsConfig::disabledQuickSettings() const
{
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
return group.readEntry("disabledQuickSettings", QList<QString>{});
}
void QuickSettingsConfig::setDisabledQuickSettings(QList<QString> &list)
{
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
group.writeEntry("disabledQuickSettings", list, KConfigGroup::Notify);
m_config->sync();
}