1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
SPDX-FileCopyrightText: 2020 Konrad Materka <materka@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.12
import org.kde.plasma.core 2.1 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
//This object contains state of the SystemTray, mainly related to the 'expanded' state
QtObject {
//true if System Tray is 'expanded'. It may be when:
// - there is an active applet or
// - 'Status and Notification' with hidden items is shown
property bool expanded: false
//set when there is an applet selected
property Item activeApplet
//allow expanded change only when activated at least once
//this is to suppress expanded state change during Plasma startup
property bool acceptExpandedChange: false
// These properties allow us to keep track of where the expanded applet
// was and is on the panel, allowing PlasmoidPopupContainer.qml to animate
// depending on their locations.
property int oldVisualIndex: -1
property int newVisualIndex: -1
function setActiveApplet(applet, visualIndex) {
if (visualIndex === undefined) {
oldVisualIndex = -1
newVisualIndex = -1
} else {
oldVisualIndex = (activeApplet && activeApplet.status === PlasmaCore.Types.PassiveStatus) ? 9999 : newVisualIndex
newVisualIndex = visualIndex
}
const oldApplet = activeApplet
activeApplet = applet
if (oldApplet && oldApplet !== applet) {
oldApplet.expanded = false
}
expanded = true
}
onExpandedChanged: {
if (expanded) {
Plasmoid.status = PlasmaCore.Types.RequiresAttentionStatus
} else {
Plasmoid.status = PlasmaCore.Types.PassiveStatus;
if (activeApplet) {
// if not expanded we don't have an active applet anymore
activeApplet.expanded = false
activeApplet = null
}
}
acceptExpandedChange = false
Plasmoid.expanded = expanded
}
//listen on SystemTray AppletInterface signals
property Connections plasmoidConnections: Connections {
target: Plasmoid.self
//emitted when activation is requested, for example by using a global keyboard shortcut
function onActivated() {
acceptExpandedChange = true
}
function onExpandedChanged() {
if (acceptExpandedChange) {
expanded = Plasmoid.expanded
} else {
Plasmoid.expanded = expanded
}
}
}
property Connections activeAppletConnections: Connections {
target: activeApplet
function onExpandedChanged() {
if (!activeApplet.expanded) {
expanded = false
}
}
}
}
|