diff --git a/.config/quickshell/modules/common/PersistentStates.qml b/.config/quickshell/modules/common/PersistentStates.qml index c991c47dc..eb62219d0 100644 --- a/.config/quickshell/modules/common/PersistentStates.qml +++ b/.config/quickshell/modules/common/PersistentStates.qml @@ -5,8 +5,12 @@ pragma ComponentBehavior: Bound Singleton { property QtObject sidebar: QtObject { + property QtObject centerGroup: QtObject { + property int selectedTab: 0 + } property QtObject bottomGroup: QtObject { property bool collapsed: false + property int selectedTab: 0 } } diff --git a/.config/quickshell/modules/common/widgets/PrimaryTabBar.qml b/.config/quickshell/modules/common/widgets/PrimaryTabBar.qml index 9ceac9e4d..84fac10d7 100644 --- a/.config/quickshell/modules/common/widgets/PrimaryTabBar.qml +++ b/.config/quickshell/modules/common/widgets/PrimaryTabBar.qml @@ -7,6 +7,7 @@ import Quickshell ColumnLayout { id: root spacing: 0 + property bool _initialized: false required property var tabButtonList // Something like [{"icon": "notifications", "name": qsTr("Notifications")}, {"icon": "volume_up", "name": qsTr("Volume mixer")}] required property var externalTrackedTab property bool enableIndicatorAnimation: false @@ -16,7 +17,13 @@ ColumnLayout { id: tabBar Layout.fillWidth: true currentIndex: root.externalTrackedTab - onCurrentIndexChanged: root.onCurrentIndexChanged(currentIndex) + onCurrentIndexChanged: { + if (!root._initialized) { + root._initialized = true + return + } + root.onCurrentIndexChanged(currentIndex) + } background: Item { WheelHandler { diff --git a/.config/quickshell/modules/sidebarRight/BottomWidgetGroup.qml b/.config/quickshell/modules/sidebarRight/BottomWidgetGroup.qml index 882d3a035..66ebf051f 100644 --- a/.config/quickshell/modules/sidebarRight/BottomWidgetGroup.qml +++ b/.config/quickshell/modules/sidebarRight/BottomWidgetGroup.qml @@ -14,13 +14,17 @@ Rectangle { color: Appearance.colors.colLayer1 clip: true implicitHeight: collapsed ? collapsedBottomWidgetGroupRow.implicitHeight : bottomWidgetGroupRow.implicitHeight - property int selectedTab: 0 + property int selectedTab: PersistentStates.sidebar.bottomGroup.selectedTab property bool collapsed: PersistentStates.sidebar.bottomGroup.collapsed property var tabs: [ {"type": "calendar", "name": "Calendar", "icon": "calendar_month", "widget": calendarWidget}, {"type": "todo", "name": "To Do", "icon": "done_outline", "widget": todoWidget} ] + onSelectedTabChanged: { + PersistentStateManager.setState("sidebar.bottomGroup.selectedTab", selectedTab) + } + Behavior on implicitHeight { NumberAnimation { duration: Appearance.animation.elementMove.duration diff --git a/.config/quickshell/modules/sidebarRight/CenterWidgetGroup.qml b/.config/quickshell/modules/sidebarRight/CenterWidgetGroup.qml index d69403a38..ede9e7219 100644 --- a/.config/quickshell/modules/sidebarRight/CenterWidgetGroup.qml +++ b/.config/quickshell/modules/sidebarRight/CenterWidgetGroup.qml @@ -16,23 +16,27 @@ Rectangle { radius: Appearance.rounding.normal color: Appearance.colors.colLayer1 - property int currentTab: 0 + property int selectedTab: PersistentStates.sidebar.centerGroup.selectedTab property var tabButtonList: [{"icon": "notifications", "name": qsTr("Notifications")}, {"icon": "volume_up", "name": qsTr("Volume mixer")}] + onSelectedTabChanged: { + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", selectedTab) + } + Keys.onPressed: (event) => { if (event.key === Qt.Key_PageDown || event.key === Qt.Key_PageUp) { if (event.key === Qt.Key_PageDown) { - root.currentTab = Math.min(root.currentTab + 1, root.tabButtonList.length - 1) + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", Math.min(root.selectedTab + 1, root.tabButtonList.length - 1)) } else if (event.key === Qt.Key_PageUp) { - root.currentTab = Math.max(root.currentTab - 1, 0) + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", Math.max(root.selectedTab - 1, 0)) } event.accepted = true; } if (event.modifiers === Qt.ControlModifier) { if (event.key === Qt.Key_Tab) { - root.currentTab = (root.currentTab + 1) % root.tabButtonList.length; + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", (root.selectedTab + 1) % root.tabButtonList.length); } else if (event.key === Qt.Key_Backtab) { - root.currentTab = (root.currentTab - 1 + root.tabButtonList.length) % root.tabButtonList.length; + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", (root.selectedTab - 1 + root.tabButtonList.length) % root.tabButtonList.length); } event.accepted = true; } @@ -46,9 +50,10 @@ Rectangle { PrimaryTabBar { id: tabBar tabButtonList: root.tabButtonList - externalTrackedTab: root.currentTab + externalTrackedTab: root.selectedTab + function onCurrentIndexChanged(currentIndex) { - root.currentTab = currentIndex + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", currentIndex) } } @@ -57,10 +62,10 @@ Rectangle { Layout.topMargin: 5 Layout.fillWidth: true Layout.fillHeight: true - currentIndex: currentTab + currentIndex: root.selectedTab onCurrentIndexChanged: { tabBar.enableIndicatorAnimation = true - root.currentTab = currentIndex + PersistentStateManager.setState("sidebar.centerGroup.selectedTab", currentIndex) } clip: true diff --git a/.config/quickshell/services/PersistentStateManager.qml b/.config/quickshell/services/PersistentStateManager.qml index a69702a7f..0f1857b86 100644 --- a/.config/quickshell/services/PersistentStateManager.qml +++ b/.config/quickshell/services/PersistentStateManager.qml @@ -29,6 +29,7 @@ Singleton { } function setState(nestedKey, value) { + // console.log(`[PersistentStateManager] Setting state: ${nestedKey} = ${value}`); let keys = nestedKey.split("."); let obj = PersistentStates; let parents = [obj]; @@ -53,7 +54,6 @@ Singleton { } function saveStates() { - console.log("[PersistentStateManager] Saving states to file:", root.filePath) const plainStates = ObjectUtils.toPlainObject(PersistentStates) stateFileView.setText(JSON.stringify(plainStates, null, 2)) }