2022-02-13 04:23:57 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mobileshellsettings.h"
|
|
|
|
|
|
2023-03-30 02:40:47 +00:00
|
|
|
#include <KIO/CommandLauncherJob>
|
|
|
|
|
#include <KNotificationJobUiDelegate>
|
|
|
|
|
#include <KPluginFactory>
|
2024-07-03 15:58:50 +00:00
|
|
|
#include <KRuntimePlatform>
|
2023-10-21 05:46:31 +00:00
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
#include <QDBusMessage>
|
|
|
|
|
#include <QDBusPendingCall>
|
2022-03-17 19:34:27 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2022-02-13 04:23:57 +00:00
|
|
|
const QString CONFIG_FILE = QStringLiteral("plasmamobilerc");
|
|
|
|
|
const QString GENERAL_CONFIG_GROUP = QStringLiteral("General");
|
2025-03-13 20:11:41 +00:00
|
|
|
const QString LOCKSCREEN_CONFIG_GROUP = QStringLiteral("Lockscreen");
|
2025-08-19 11:35:11 +00:00
|
|
|
const QString QUICKSETTINGS_CONFIG_GROUP = QStringLiteral("QuickSettings");
|
2022-02-13 04:23:57 +00:00
|
|
|
|
|
|
|
|
MobileShellSettings::MobileShellSettings(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
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-10-05 23:06:52 +00:00
|
|
|
, m_config{KSharedConfig::openConfig(CONFIG_FILE)}
|
2022-02-13 04:23:57 +00:00
|
|
|
{
|
|
|
|
|
m_configWatcher = KConfigWatcher::create(m_config);
|
|
|
|
|
connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
|
2024-10-17 17:20:14 +00:00
|
|
|
Q_UNUSED(names)
|
2022-02-13 04:23:57 +00:00
|
|
|
if (group.name() == GENERAL_CONFIG_GROUP) {
|
2022-04-29 20:15:53 +00:00
|
|
|
Q_EMIT vibrationsEnabledChanged();
|
2022-05-06 01:02:18 +00:00
|
|
|
Q_EMIT vibrationDurationChanged();
|
2022-04-30 00:02:33 +00:00
|
|
|
Q_EMIT animationsEnabledChanged();
|
2024-06-28 02:05:42 +00:00
|
|
|
Q_EMIT dateInStatusBarChanged();
|
2024-10-17 17:20:14 +00:00
|
|
|
Q_EMIT statusBarScaleFactorChanged();
|
2025-03-19 20:09:33 +00:00
|
|
|
Q_EMIT showBatteryPercentageChanged();
|
2022-02-13 04:23:57 +00:00
|
|
|
Q_EMIT navigationPanelEnabledChanged();
|
2025-12-14 04:38:13 +00:00
|
|
|
Q_EMIT gesturePanelEnabledChanged();
|
2023-11-05 20:14:37 +00:00
|
|
|
Q_EMIT alwaysShowKeyboardToggleOnNavigationPanelChanged();
|
2022-09-10 02:32:04 +00:00
|
|
|
Q_EMIT keyboardButtonEnabledChanged();
|
2022-05-21 14:54:33 +00:00
|
|
|
Q_EMIT taskSwitcherPreviewsEnabledChanged();
|
2022-05-31 03:37:00 +00:00
|
|
|
Q_EMIT actionDrawerTopLeftModeChanged();
|
|
|
|
|
Q_EMIT actionDrawerTopRightModeChanged();
|
2023-03-29 06:49:09 +00:00
|
|
|
Q_EMIT convergenceModeEnabledChanged();
|
2025-04-21 15:56:33 +00:00
|
|
|
Q_EMIT autoHidePanelsEnabledChanged();
|
2024-11-29 10:49:24 +00:00
|
|
|
Q_EMIT allowLogoutChanged();
|
2022-02-13 04:23:57 +00:00
|
|
|
}
|
2025-03-13 20:11:41 +00:00
|
|
|
if (group.name() == LOCKSCREEN_CONFIG_GROUP) {
|
|
|
|
|
Q_EMIT lockscreenLeftButtonActionChanged();
|
|
|
|
|
Q_EMIT lockscreenRightButtonActionChanged();
|
|
|
|
|
}
|
2025-08-19 11:35:11 +00:00
|
|
|
if (group.name() == QUICKSETTINGS_CONFIG_GROUP) {
|
|
|
|
|
Q_EMIT quickSettingsColumnsChanged();
|
|
|
|
|
}
|
2022-02-13 04:23:57 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-29 20:15:53 +00:00
|
|
|
bool MobileShellSettings::vibrationsEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("vibrationsEnabled", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setVibrationsEnabled(bool vibrationsEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("vibrationsEnabled", vibrationsEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 01:02:18 +00:00
|
|
|
int MobileShellSettings::vibrationDuration() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
2023-11-15 07:13:05 +00:00
|
|
|
return group.readEntry("vibrationDuration", 10);
|
2022-05-06 01:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setVibrationDuration(int vibrationDuration)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("vibrationDuration", vibrationDuration, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 00:02:33 +00:00
|
|
|
bool MobileShellSettings::animationsEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("animationsEnabled", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setAnimationsEnabled(bool animationsEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("animationsEnabled", animationsEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 02:05:42 +00:00
|
|
|
bool MobileShellSettings::dateInStatusBar() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("dateInStatusBar", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setDateInStatusBar(bool dateInStatusBar)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("dateInStatusBar", dateInStatusBar, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 17:20:14 +00:00
|
|
|
float MobileShellSettings::statusBarScaleFactor() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("statusBarScaleFactor", 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setStatusBarScaleFactor(float statusBarScaleFactor)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("statusBarScaleFactor", statusBarScaleFactor, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 20:09:33 +00:00
|
|
|
bool MobileShellSettings::showBatteryPercentage() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
2025-03-20 14:53:16 +00:00
|
|
|
return group.readEntry("showBatteryPercentage", true);
|
2025-03-19 20:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setShowBatteryPercentage(bool showBatteryPercentage)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("showBatteryPercentage", showBatteryPercentage, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-13 04:23:57 +00:00
|
|
|
bool MobileShellSettings::navigationPanelEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("navigationPanelEnabled", true);
|
|
|
|
|
}
|
2022-03-17 03:20:36 +00:00
|
|
|
|
|
|
|
|
void MobileShellSettings::setNavigationPanelEnabled(bool navigationPanelEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("navigationPanelEnabled", navigationPanelEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
2023-10-21 05:46:31 +00:00
|
|
|
|
2025-12-14 04:38:13 +00:00
|
|
|
updateNavigationBarsInPlasma();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MobileShellSettings::gesturePanelEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("gesturePanelEnabled", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setGesturePanelEnabled(bool gesturePanelEnabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("gesturePanelEnabled", gesturePanelEnabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
|
|
|
|
|
updateNavigationBarsInPlasma();
|
2022-03-17 03:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-05 20:14:37 +00:00
|
|
|
bool MobileShellSettings::alwaysShowKeyboardToggleOnNavigationPanel() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("alwaysShowKeyboardToggleOnNavigationPanel", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setAlwaysShowKeyboardToggleOnNavigationPanel(bool alwaysShowKeyboardToggleOnNavigationPanel)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("alwaysShowKeyboardToggleOnNavigationPanel", alwaysShowKeyboardToggleOnNavigationPanel, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 03:37:00 +00:00
|
|
|
MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopLeftMode() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return (ActionDrawerMode)group.readEntry("actionDrawerTopLeftMode", (int)ActionDrawerMode::Pinned);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setActionDrawerTopLeftMode(ActionDrawerMode actionDrawerMode)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("actionDrawerTopLeftMode", (int)actionDrawerMode, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-19 11:35:11 +00:00
|
|
|
int MobileShellSettings::quickSettingsColumns() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("quickSettingsColumns", 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setQuickSettingsColumns(int columns)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, QUICKSETTINGS_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("quickSettingsColumns", columns, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 03:37:00 +00:00
|
|
|
MobileShellSettings::ActionDrawerMode MobileShellSettings::actionDrawerTopRightMode() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return (ActionDrawerMode)group.readEntry("actionDrawerTopRightMode", (int)ActionDrawerMode::Expanded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setActionDrawerTopRightMode(ActionDrawerMode actionDrawerMode)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("actionDrawerTopRightMode", (int)actionDrawerMode, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
2023-03-29 06:49:09 +00:00
|
|
|
|
|
|
|
|
bool MobileShellSettings::convergenceModeEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("convergenceModeEnabled", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setConvergenceModeEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("convergenceModeEnabled", enabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
2023-03-30 02:40:47 +00:00
|
|
|
|
|
|
|
|
// update environment settings
|
|
|
|
|
auto *job = new KIO::CommandLauncherJob(QStringLiteral("plasma-mobile-envmanager --apply-settings"), {});
|
|
|
|
|
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled));
|
|
|
|
|
job->setDesktopName(QStringLiteral("org.kde.plasma-mobile-envmanager"));
|
|
|
|
|
job->start();
|
2023-03-29 06:49:09 +00:00
|
|
|
}
|
2023-10-21 05:46:31 +00:00
|
|
|
|
2025-04-21 15:56:33 +00:00
|
|
|
bool MobileShellSettings::autoHidePanelsEnabled() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("autoHidePanelsEnabled", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setAutoHidePanelsEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("autoHidePanelsEnabled", enabled, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 04:38:13 +00:00
|
|
|
void MobileShellSettings::updateNavigationBarsInPlasma()
|
2023-10-21 05:46:31 +00:00
|
|
|
{
|
2024-07-03 15:58:50 +00:00
|
|
|
// Do not update panels when not in Plasma Mobile
|
|
|
|
|
bool isMobilePlatform = KRuntimePlatform::runtimePlatform().contains("phone");
|
|
|
|
|
if (!isMobilePlatform) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-21 05:46:31 +00:00
|
|
|
auto message = QDBusMessage::createMethodCall(QLatin1String("org.kde.plasmashell"),
|
|
|
|
|
QLatin1String("/PlasmaShell"),
|
|
|
|
|
QLatin1String("org.kde.PlasmaShell"),
|
|
|
|
|
QLatin1String("evaluateScript"));
|
|
|
|
|
|
2025-12-14 04:38:13 +00:00
|
|
|
if (navigationPanelEnabled() || gesturePanelEnabled()) {
|
2023-10-21 05:46:31 +00:00
|
|
|
QString createNavigationPanelScript = R"(
|
2025-12-14 04:38:13 +00:00
|
|
|
let allPanels = panels();
|
|
|
|
|
let foundPanel = false;
|
|
|
|
|
for (var i = 0; i < allPanels.length; i++) {
|
|
|
|
|
if (allPanels[i].type === "org.kde.plasma.mobile.taskpanel") {
|
|
|
|
|
foundPanel = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!foundPanel) {
|
|
|
|
|
loadTemplate("org.kde.plasma.mobile.defaultNavigationPanel");
|
|
|
|
|
}
|
2023-10-21 05:46:31 +00:00
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
message << createNavigationPanelScript;
|
|
|
|
|
} else {
|
|
|
|
|
QString deleteNavigationPanelScript = R"(
|
|
|
|
|
let allPanels = panels();
|
|
|
|
|
for (var i = 0; i < allPanels.length; i++) {
|
|
|
|
|
if (allPanels[i].type === "org.kde.plasma.mobile.taskpanel") {
|
|
|
|
|
allPanels[i].remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)";
|
|
|
|
|
|
|
|
|
|
message << deleteNavigationPanelScript;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO check for error response
|
|
|
|
|
QDBusConnection::sessionBus().asyncCall(message);
|
|
|
|
|
}
|
2024-11-29 10:49:24 +00:00
|
|
|
|
|
|
|
|
bool MobileShellSettings::allowLogout() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP};
|
|
|
|
|
return group.readEntry("allowLogout", true);
|
|
|
|
|
}
|
2025-03-13 20:11:41 +00:00
|
|
|
|
|
|
|
|
MobileShellSettings::LockscreenButtonAction MobileShellSettings::lockscreenLeftButtonAction() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
|
|
|
|
return (LockscreenButtonAction)group.readEntry("lockscreenLeftButtonAction", (int)LockscreenButtonAction::None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setLockscreenLeftButtonAction(const LockscreenButtonAction action)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("lockscreenLeftButtonAction", (int)action, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MobileShellSettings::LockscreenButtonAction MobileShellSettings::lockscreenRightButtonAction() const
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
|
|
|
|
return (LockscreenButtonAction)group.readEntry("lockscreenRightButtonAction", (int)LockscreenButtonAction::None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MobileShellSettings::setLockscreenRightButtonAction(const LockscreenButtonAction action)
|
|
|
|
|
{
|
|
|
|
|
auto group = KConfigGroup{m_config, LOCKSCREEN_CONFIG_GROUP};
|
|
|
|
|
group.writeEntry("lockscreenRightButtonAction", (int)action, KConfigGroup::Notify);
|
|
|
|
|
m_config->sync();
|
2025-03-19 20:09:33 +00:00
|
|
|
}
|