summaryrefslogtreecommitdiff
path: root/modules/controlcenter
diff options
context:
space:
mode:
authorATMDA <atdma2600@gmail.com>2025-11-19 14:07:53 -0500
committerATMDA <atdma2600@gmail.com>2025-11-19 14:07:53 -0500
commit50dd4e1c441db43bc4dee5d5007f28c52cef848b (patch)
tree6ab9e43c24cf48cdcf120c5fc1275cc4cb116cf0 /modules/controlcenter
parentrefactor: added state module (diff)
downloadcaelestia-shell-50dd4e1c441db43bc4dee5d5007f28c52cef848b.tar.gz
caelestia-shell-50dd4e1c441db43bc4dee5d5007f28c52cef848b.tar.bz2
caelestia-shell-50dd4e1c441db43bc4dee5d5007f28c52cef848b.zip
refactor: created pane registry
Diffstat (limited to 'modules/controlcenter')
-rw-r--r--modules/controlcenter/NavRail.qml36
-rw-r--r--modules/controlcenter/PaneRegistry.qml133
-rw-r--r--modules/controlcenter/Panes.qml58
-rw-r--r--modules/controlcenter/Session.qml3
4 files changed, 160 insertions, 70 deletions
diff --git a/modules/controlcenter/NavRail.qml b/modules/controlcenter/NavRail.qml
index 1de1a9e..ef338b2 100644
--- a/modules/controlcenter/NavRail.qml
+++ b/modules/controlcenter/NavRail.qml
@@ -117,35 +117,15 @@ Item {
}
}
- NavItem {
- Layout.topMargin: Appearance.spacing.large * 2
- icon: "router"
- label: "network"
- }
-
- NavItem {
- icon: "settings_bluetooth"
- label: "bluetooth"
- }
-
- NavItem {
- icon: "volume_up"
- label: "audio"
- }
+ Repeater {
+ model: PaneRegistry.count
- NavItem {
- icon: "palette"
- label: "appearance"
- }
-
- NavItem {
- icon: "task_alt"
- label: "taskbar"
- }
-
- NavItem {
- icon: "apps"
- label: "launcher"
+ NavItem {
+ required property int index
+ Layout.topMargin: index === 0 ? Appearance.spacing.large * 2 : 0
+ icon: PaneRegistry.getByIndex(index).icon
+ label: PaneRegistry.getByIndex(index).label
+ }
}
}
diff --git a/modules/controlcenter/PaneRegistry.qml b/modules/controlcenter/PaneRegistry.qml
new file mode 100644
index 0000000..df63c6e
--- /dev/null
+++ b/modules/controlcenter/PaneRegistry.qml
@@ -0,0 +1,133 @@
+pragma Singleton
+
+import QtQuick
+
+/**
+ * PaneRegistry
+ *
+ * Centralized registry for Control Center panes. This singleton provides a single
+ * source of truth for pane metadata (id, label, icon, component), eliminating
+ * the need for manual index management and making adding/removing panes trivial.
+ *
+ * Usage:
+ * - Panes.qml: Dynamically creates panes from registry
+ * - Session.qml: Derives panes list from registry
+ * - NavRail.qml: Uses registry for navigation items
+ */
+QtObject {
+ id: root
+
+ /**
+ * Pane metadata structure:
+ * - id: Unique identifier for the pane (string)
+ * - label: Display label for the pane (string)
+ * - icon: Material icon name (string)
+ * - component: Component path relative to controlcenter module (string)
+ */
+ readonly property list<QtObject> panes: [
+ QtObject {
+ readonly property string id: "network"
+ readonly property string label: "network"
+ readonly property string icon: "router"
+ readonly property string component: "network/NetworkingPane.qml"
+ },
+ QtObject {
+ readonly property string id: "bluetooth"
+ readonly property string label: "bluetooth"
+ readonly property string icon: "settings_bluetooth"
+ readonly property string component: "bluetooth/BtPane.qml"
+ },
+ QtObject {
+ readonly property string id: "audio"
+ readonly property string label: "audio"
+ readonly property string icon: "volume_up"
+ readonly property string component: "audio/AudioPane.qml"
+ },
+ QtObject {
+ readonly property string id: "appearance"
+ readonly property string label: "appearance"
+ readonly property string icon: "palette"
+ readonly property string component: "appearance/AppearancePane.qml"
+ },
+ QtObject {
+ readonly property string id: "taskbar"
+ readonly property string label: "taskbar"
+ readonly property string icon: "task_alt"
+ readonly property string component: "taskbar/TaskbarPane.qml"
+ },
+ QtObject {
+ readonly property string id: "launcher"
+ readonly property string label: "launcher"
+ readonly property string icon: "apps"
+ readonly property string component: "launcher/LauncherPane.qml"
+ }
+ ]
+
+ /**
+ * Get the count of registered panes
+ */
+ readonly property int count: panes.length
+
+ /**
+ * Get pane labels as a list of strings
+ * Useful for Session.qml's panes property
+ */
+ readonly property var labels: {
+ const result = [];
+ for (let i = 0; i < panes.length; i++) {
+ result.push(panes[i].label);
+ }
+ return result;
+ }
+
+ /**
+ * Get pane metadata by index
+ * @param index The index of the pane
+ * @return The pane metadata object or null if index is out of bounds
+ */
+ function getByIndex(index: int): QtObject {
+ if (index >= 0 && index < panes.length) {
+ return panes[index];
+ }
+ return null;
+ }
+
+ /**
+ * Get pane index by label
+ * @param label The label to search for
+ * @return The index of the pane or -1 if not found
+ */
+ function getIndexByLabel(label: string): int {
+ for (let i = 0; i < panes.length; i++) {
+ if (panes[i].label === label) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Get pane metadata by label
+ * @param label The label to search for
+ * @return The pane metadata object or null if not found
+ */
+ function getByLabel(label: string): QtObject {
+ const index = getIndexByLabel(label);
+ return getByIndex(index);
+ }
+
+ /**
+ * Get pane metadata by id
+ * @param id The id to search for
+ * @return The pane metadata object or null if not found
+ */
+ function getById(id: string): QtObject {
+ for (let i = 0; i < panes.length; i++) {
+ if (panes[i].id === id) {
+ return panes[i];
+ }
+ }
+ return null;
+ }
+}
+
diff --git a/modules/controlcenter/Panes.qml b/modules/controlcenter/Panes.qml
index 756d73a..b9256a9 100644
--- a/modules/controlcenter/Panes.qml
+++ b/modules/controlcenter/Panes.qml
@@ -9,6 +9,7 @@ import "launcher"
import qs.components
import qs.services
import qs.config
+import qs.modules.controlcenter
import Quickshell.Widgets
import QtQuick
import QtQuick.Layouts
@@ -76,45 +77,13 @@ ClippingRectangle {
}
}
- Pane {
- index: 0
- sourceComponent: NetworkingPane {
- session: root.session
- }
- }
-
- Pane {
- index: 1
- sourceComponent: BtPane {
- session: root.session
- }
- }
-
- Pane {
- index: 2
- sourceComponent: AudioPane {
- session: root.session
- }
- }
+ Repeater {
+ model: PaneRegistry.count
- Pane {
- index: 3
- sourceComponent: AppearancePane {
- session: root.session
- }
- }
-
- Pane {
- index: 4
- sourceComponent: TaskbarPane {
- session: root.session
- }
- }
-
- Pane {
- index: 5
- sourceComponent: LauncherPane {
- session: root.session
+ Pane {
+ required property int index
+ paneIndex: index
+ componentPath: PaneRegistry.getByIndex(index).component
}
}
@@ -135,8 +104,8 @@ ClippingRectangle {
component Pane: Item {
id: pane
- required property int index
- property alias sourceComponent: loader.sourceComponent
+ required property int paneIndex
+ required property string componentPath
implicitWidth: root.width
implicitHeight: root.height
@@ -146,7 +115,7 @@ ClippingRectangle {
// Function to compute if this pane should be active
function updateActive(): void {
- const diff = Math.abs(root.session.activeIndex - pane.index);
+ const diff = Math.abs(root.session.activeIndex - pane.paneIndex);
const isActivePane = diff === 0;
let shouldBeActive = false;
@@ -187,6 +156,13 @@ ClippingRectangle {
if (active && !pane.hasBeenLoaded) {
pane.hasBeenLoaded = true;
}
+
+ // Load the component with initial properties when activated
+ if (active && !item) {
+ loader.setSource(pane.componentPath, {
+ "session": root.session
+ });
+ }
}
onItemChanged: {
diff --git a/modules/controlcenter/Session.qml b/modules/controlcenter/Session.qml
index 5d7b094..9c6a754 100644
--- a/modules/controlcenter/Session.qml
+++ b/modules/controlcenter/Session.qml
@@ -1,8 +1,9 @@
import QtQuick
import "./state"
+import qs.modules.controlcenter
QtObject {
- readonly property list<string> panes: ["network", "bluetooth", "audio", "appearance", "taskbar", "launcher"]
+ readonly property list<string> panes: PaneRegistry.labels
required property var root
property bool floating: false