shift-shell/components/mobileshellstate/panelsettingsdbusobjectmanager.h
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

95 lines
2.8 KiB
C++

// SPDX-FileCopyrightText: 2025 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QObject>
#include <QString>
#include <qqmlregistration.h>
#include <KConfigGroup>
#include <KConfigWatcher>
#include <KSharedConfig>
#include <kscreen/config.h>
class PanelSettingsDBusObject;
class PanelSettingsDBusObjectManager : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
PanelSettingsDBusObjectManager(QObject *parent = nullptr);
// called by QML
Q_INVOKABLE void registerObjects();
private:
bool m_initialized = false;
QList<PanelSettingsDBusObject *> m_dbusObjects;
KScreen::ConfigPtr m_kscreenConfig{nullptr};
};
class PanelSettingsDBusObject : public QObject
{
Q_OBJECT
// HACK: org.kde.plasmashell prefix seems to bug out and not compile with the qt macro, use this for now
Q_CLASSINFO("D-Bus Interface", "org.kde.plasmashellMobilePanels")
public:
PanelSettingsDBusObject(QObject *parent = nullptr);
void registerObject(KScreen::OutputPtr output);
int outputId() const;
QString outputName() const;
Q_SIGNALS:
Q_SCRIPTABLE void statusBarHeightChanged();
Q_SCRIPTABLE void statusBarLeftPaddingChanged();
Q_SCRIPTABLE void statusBarRightPaddingChanged();
Q_SCRIPTABLE void statusBarCenterSpacingChanged();
Q_SCRIPTABLE void navigationPanelHeightChanged();
Q_SCRIPTABLE void navigationPanelLeftPaddingChanged();
Q_SCRIPTABLE void navigationPanelRightPaddingChanged();
public Q_SLOTS:
Q_SCRIPTABLE qreal statusBarHeight() const;
Q_SCRIPTABLE qreal statusBarLeftPadding() const;
Q_SCRIPTABLE qreal statusBarRightPadding() const;
Q_SCRIPTABLE qreal statusBarCenterSpacing() const;
Q_SCRIPTABLE qreal navigationPanelHeight() const;
Q_SCRIPTABLE qreal navigationPanelLeftPadding() const;
Q_SCRIPTABLE qreal navigationPanelRightPadding() const;
private:
void updateFields();
void setStatusBarHeight(qreal statusBarHeight);
void setStatusBarLeftPadding(qreal statusBarLeftPadding);
void setStatusBarRightPadding(qreal statusBarRightPadding);
void setStatusBarCenterSpacing(qreal statusBarCenterSpacing);
void setNavigationPanelHeight(qreal navigationPanelHeight);
void setNavigationPanelLeftPadding(qreal navigationPanelLeftPadding);
void setNavigationPanelRightPadding(qreal navigationPanelRightPadding);
int m_outputId = -1;
QString m_outputName;
qreal m_statusBarHeight = -1;
qreal m_statusBarLeftPadding = 0;
qreal m_statusBarRightPadding = 0;
qreal m_statusBarCenterSpacing = 0;
qreal m_navigationPanelHeight = -1;
qreal m_navigationPanelLeftPadding = 0;
qreal m_navigationPanelRightPadding = 0;
KSharedConfig::Ptr m_config;
KConfigWatcher::Ptr m_configWatcher;
KScreen::OutputPtr m_output;
};