99 lines
2.6 KiB
QML
99 lines
2.6 KiB
QML
|
|
import qs.services
|
|
import qs.util
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Hyprland
|
|
|
|
Scope {
|
|
id: root
|
|
|
|
required property QtObject window
|
|
required property ShellScreen screen
|
|
property alias uiState: uiState
|
|
|
|
PersistentProperties {
|
|
id: uiState
|
|
reloadableId: `uiState-${root.screen.name}`
|
|
|
|
readonly property QtObject window: root.window
|
|
|
|
// Open panels
|
|
property bool dashboard
|
|
property bool launcher
|
|
property bool osd
|
|
property bool session
|
|
|
|
property bool blockScreen
|
|
|
|
// Other state
|
|
property ListModel workspaces
|
|
property int dashboardTab: 0
|
|
property bool osdVolumeReact: true
|
|
property bool osdBrightnessReact: true
|
|
|
|
Component.onCompleted: {
|
|
workspaces = listModelComp.createObject(this);
|
|
States.load(root.screen, this);
|
|
}
|
|
}
|
|
|
|
// Workspace Handling
|
|
|
|
Component {
|
|
id: listModelComp
|
|
ListModel {}
|
|
}
|
|
|
|
// Initialize workspace list
|
|
Timer {
|
|
running: true
|
|
interval: Hypr.arbitraryRaceConditionDelay
|
|
onTriggered: {
|
|
// NOTE: Reinitialize workspace list on reload because persistence doesn't work
|
|
uiState.workspaces = listModelComp.createObject(uiState);
|
|
Hypr.workspaces.values.forEach(w => {
|
|
if (w.monitor === Hypr.monitorFor(root.screen))
|
|
uiState.workspaces.append({"workspace": w});
|
|
})
|
|
}
|
|
}
|
|
|
|
// Remove deleted workspaces
|
|
Connections {
|
|
target: Hypr.workspaces
|
|
function onObjectRemovedPost(workspace, index) {
|
|
root.removeWorkspace(workspace);
|
|
}
|
|
}
|
|
|
|
// Update workspaces moved between monitors
|
|
// (also handles initialized workspaces)
|
|
Instantiator {
|
|
model: Hypr.workspaces
|
|
delegate: Connections {
|
|
required property HyprlandWorkspace modelData
|
|
target: modelData
|
|
function onMonitorChanged() {
|
|
if (modelData.monitor === Hypr.monitorFor(root.screen)) {
|
|
uiState.workspaces.append({"workspace": modelData});
|
|
} else {
|
|
root.removeWorkspace(modelData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function removeWorkspace(workspace: HyprlandWorkspace): void {
|
|
let i = 0;
|
|
while (i < uiState.workspaces.count) {
|
|
const w = uiState.workspaces.get(i).workspace;
|
|
if (w === workspace) {
|
|
uiState.workspaces.remove(i);
|
|
} else {
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|