shift-shell/shell/contents/views/Desktop.qml
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

138 lines
4.8 KiB
QML

/*
* SPDX-FileCopyrightText: 2014 Aaron Seigo <aseigo@kde.org>
* SPDX-FileCopyrightText: 2012 Marco Martin <notmart@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.15
import org.kde.plasma.core as PlasmaCore
import org.kde.kquickcontrolsaddons 2.0
import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.state as MobileShellState
Rectangle {
id: root
property Item containment
color: (containment && containment.backgroundHints == PlasmaCore.Types.NoBackground) ? "transparent" : Kirigami.Theme.textColor
Component.onCompleted: {
initializeShellSingletons();
}
function initializeShellSingletons() {
console.log('Initializing DBus objects and popup providers...');
// Note: The calls here must be idempotent (support being called multiple times)
// - this is called every time there is a new desktop containment
// HACK: we need to initialize the DBus server somewhere in plasmashell, it might as well be here...
MobileShellState.ShellDBusObject.registerObject();
MobileShellState.PanelSettingsDBusObjectManager.registerObjects();
// Initialize the volume osd, and volume keys.
// Initialize notification popups.
// Initialize action popup buttons.
MobileShell.PopupProviderLoader.load();
}
function toggleWidgetExplorer(containment) {
console.log("Widget Explorer toggled");
if (widgetExplorerStack.source != "") {
widgetExplorerStack.source = "";
} else {
widgetExplorerStack.setSource(desktop.fileFromPackage("explorer", "WidgetExplorer.qml"), {"containment": containment, "containmentInterface": root.containment})
}
}
onContainmentChanged: {
if (containment == null) {
return;
}
containment.parent = root;
containment.visible = true;
containment.anchors.fill = root;
}
// This is taken from plasma-desktop's shell package, try to keep it in sync
// Handles taking accent color from wallpaper
Loader {
id: wallpaperColors
active: desktop.usedInAccentColor && root.containment && root.containment.wallpaper
asynchronous: true
sourceComponent: Kirigami.ImageColors {
id: imageColors
source: root.containment.wallpaper
readonly property color backgroundColor: Kirigami.Theme.backgroundColor
readonly property color textColor: Kirigami.Theme.textColor
property color colorFromPlugin: "transparent"
Kirigami.Theme.inherit: false
Kirigami.Theme.backgroundColor: backgroundColor
Kirigami.Theme.textColor: textColor
onBackgroundColorChanged: Qt.callLater(update)
onTextColorChanged: Qt.callLater(update)
property Binding colorBinding: Binding {
target: desktop
property: "accentColor"
value: {
if (!Qt.colorEqual(imageColors.colorFromPlugin, "transparent")) {
return imageColors.colorFromPlugin;
}
if (imageColors.palette.length === 0) {
return "transparent";
}
return imageColors.dominant;
}
when: desktop.usedInAccentColor // Without this, accentColor may still be updated after usedInAccentColor becomes false
}
property Connections repaintConnection: Connections {
target: root.containment.wallpaper
function onRepaintNeeded(color) {
imageColors.colorFromPlugin = color;
if (Qt.colorEqual(color, "transparent")) {
imageColors.update();
}
}
}
}
onLoaded: item.update()
}
Loader {
id: widgetExplorerStack
z: 99
asynchronous: true
y: containment ? containment.availableScreenRect.y : 0
height: containment ? containment.availableScreenRect.height : parent.height
width: parent.width
onLoaded: {
if (widgetExplorerStack.item) {
item.closed.connect(function() {
widgetExplorerStack.source = ""
});
item.topPanelHeight = containment.availableScreenRect.y
item.bottomPanelHeight = root.height - (containment.availableScreenRect.height + containment.availableScreenRect.y)
item.leftPanelWidth = containment.availableScreenRect.x
item.rightPanelWidth = root.width - (containment.availableScreenRect.width + containment.availableScreenRect.x)
}
}
}
}