148 lines
4.2 KiB
QML
148 lines
4.2 KiB
QML
import qs.config
|
|
import qs.custom
|
|
import qs.services
|
|
import qs.util
|
|
import Quickshell
|
|
import QtQuick
|
|
|
|
Scope {
|
|
id: root
|
|
|
|
// Workspace Handling
|
|
|
|
function allWorkspaces(): list<int> {
|
|
let ids = [];
|
|
States.screens.forEach((uiState, _, _) => {
|
|
for (let i = 0; i < uiState.workspaces.count; i++) {
|
|
ids.push(uiState.workspaces.get(i).workspace.id);
|
|
}
|
|
})
|
|
return ids;
|
|
}
|
|
|
|
function nextWorkspace(): int {
|
|
let id = 1;
|
|
const ws = allWorkspaces();
|
|
while (ws.includes(id)) id++;
|
|
return id;
|
|
}
|
|
|
|
// Workspace Commands
|
|
|
|
function newWorkspace(): void {
|
|
Hypr.dispatch(`focusworkspaceoncurrentmonitor ${nextWorkspace()}`);
|
|
}
|
|
|
|
CustomShortcut {
|
|
name: "newworkspace"
|
|
description: "Go to a new workspace"
|
|
onPressed: root.newWorkspace();
|
|
}
|
|
|
|
function moveToNewWorkspace(): void {
|
|
Hypr.dispatch(`hy3:movetoworkspace ${nextWorkspace()}`);
|
|
}
|
|
|
|
CustomShortcut {
|
|
name: "movetonewworkspace"
|
|
description: "Move the current window to a new workspace"
|
|
onPressed: root.moveToNewWorkspace();
|
|
}
|
|
|
|
function goToWorkspace(index: int): void {
|
|
const uiState = States.getForActive();
|
|
if (index > uiState.workspaces.count) return;
|
|
let id;
|
|
if (index === uiState.workspaces.count) {
|
|
if (uiState.workspaces.get(index - 1).workspace === Hypr.focusedWorkspace
|
|
&& Hypr.focusedWorkspace.toplevels.values.length === 0) return;
|
|
id = root.nextWorkspace();
|
|
} else {
|
|
id = uiState.workspaces.get(index).workspace.id;
|
|
}
|
|
if (id === Hypr.focusedWorkspace.id) return;
|
|
Hypr.dispatch(`workspace ${id}`);
|
|
}
|
|
|
|
Instantiator {
|
|
model: [...Array(10).keys()]
|
|
delegate: CustomShortcut {
|
|
required property int modelData
|
|
name: `workspace${modelData + 1}`
|
|
description: `Go to workspace ${modelData + 1}`
|
|
onPressed: root.goToWorkspace(modelData)
|
|
}
|
|
}
|
|
|
|
function moveToWorkspace(index: int): void {
|
|
const uiState = States.getForActive();
|
|
if (index > uiState.workspaces.count) return;
|
|
let id;
|
|
if (index === uiState.workspaces.count) {
|
|
if (uiState.workspaces.get(index - 1).workspace === Hypr.focusedWorkspace
|
|
&& Hypr.focusedWorkspace.toplevels.values.length === 0) return;
|
|
id = nextWorkspace();
|
|
} else {
|
|
id = uiState.workspaces.get(index).workspace.id;
|
|
}
|
|
if (id === Hypr.focusedWorkspace.id) return;
|
|
Hypr.dispatch(`hy3:movetoworkspace ${id}`);
|
|
}
|
|
|
|
Instantiator {
|
|
model: [...Array(10).keys()]
|
|
delegate: CustomShortcut {
|
|
required property int modelData
|
|
name: `movetoworkspace${modelData + 1}`
|
|
description: `Move the focused window to workspace ${modelData + 1}`
|
|
onPressed: root.moveToWorkspace(modelData)
|
|
}
|
|
}
|
|
|
|
// Panels
|
|
|
|
CustomShortcut {
|
|
name: "dashboard"
|
|
description: "Cycle dashboard tabs"
|
|
onPressed: {
|
|
const uiState = States.getForActive();
|
|
if (uiState.dashboard) {
|
|
uiState.dashboardTab = (uiState.dashboardTab + 1) % 5;
|
|
} else {
|
|
uiState.dashboard = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
CustomShortcut {
|
|
name: "launcher"
|
|
description: "Toggle launcher"
|
|
onPressed: {
|
|
const uiState = States.getForActive();
|
|
uiState.launcher = !uiState.launcher;
|
|
}
|
|
}
|
|
|
|
CustomShortcut {
|
|
name: "session"
|
|
description: "Toggle session menu"
|
|
onPressed: {
|
|
const uiState = States.getForActive();
|
|
uiState.session = !uiState.session;
|
|
}
|
|
}
|
|
|
|
CustomShortcut {
|
|
name: "escape"
|
|
description: "Close every panel"
|
|
onPressed: {
|
|
States.screens.forEach((uiState, _, _) => {
|
|
uiState.dashboard = false;
|
|
uiState.launcher = false;
|
|
uiState.osd = false;
|
|
uiState.session = false;
|
|
uiState.blockScreen = false;
|
|
});
|
|
}
|
|
}
|
|
}
|