1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-05 21:15:38 -05:00

Workspace click fix

This commit is contained in:
bbedward
2025-07-11 21:50:41 -04:00
parent 483ce1cd93
commit 0afe57e527
2 changed files with 19 additions and 18 deletions

View File

@@ -241,18 +241,27 @@ Singleton {
return switchToWorkspace(workspace.id)
}
function switchToWorkspaceByNumber(number) {
function switchToWorkspaceByNumber(number, output) {
if (!niriAvailable) return false
// Find workspace by number (1-based)
var workspace = allWorkspaces.find(w => (w.idx + 1) === number)
if (workspace) {
var targetOutput = output || currentOutput
if (!targetOutput) {
console.warn("NiriWorkspaceService: No output specified for workspace switching")
return false
}
// Get workspaces for the target output, sorted by idx
var outputWorkspaces = allWorkspaces.filter(w => w.output === targetOutput).sort((a, b) => a.idx - b.idx)
// Use sequential index (number is 1-based, array is 0-based)
if (number >= 1 && number <= outputWorkspaces.length) {
var workspace = outputWorkspaces[number - 1]
console.log("DEBUG: Switching to workspace ID", workspace.id, "for sequential number", number, "on", targetOutput)
return switchToWorkspace(workspace.id)
}
// If not found, try to switch by number directly
Quickshell.execDetached(["niri", "msg", "action", "focus-workspace", number.toString()])
return true
console.warn("NiriWorkspaceService: No workspace", number, "found on output", targetOutput)
return false
}
function getWorkspaceByIndex(index) {

View File

@@ -300,15 +300,11 @@ EOF`
Connections {
target: NiriWorkspaceService
function onAllWorkspacesChanged() {
var oldCurrent = workspaceSwitcher.currentWorkspace
workspaceSwitcher.workspaceList = workspaceSwitcher.getDisplayWorkspaces()
workspaceSwitcher.currentWorkspace = workspaceSwitcher.getDisplayActiveWorkspace()
console.log("DEBUG: TopBar onAllWorkspacesChanged for", topBar.screenName, "- current workspace:", oldCurrent, "→", workspaceSwitcher.currentWorkspace)
}
function onFocusedWorkspaceIndexChanged() {
var oldCurrent = workspaceSwitcher.currentWorkspace
workspaceSwitcher.currentWorkspace = workspaceSwitcher.getDisplayActiveWorkspace()
console.log("DEBUG: TopBar onFocusedWorkspaceIndexChanged for", topBar.screenName, "- current workspace:", oldCurrent, "→", workspaceSwitcher.currentWorkspace)
}
function onNiriAvailableChanged() {
if (NiriWorkspaceService.niriAvailable) {
@@ -329,6 +325,7 @@ EOF`
Rectangle {
property bool isActive: modelData === workspaceSwitcher.currentWorkspace
property bool isHovered: mouseArea.containsMouse
property int sequentialNumber: index + 1 // 1-based sequential number per monitor
width: isActive ? Theme.spacingXL + Theme.spacingS : Theme.spacingL
@@ -359,13 +356,8 @@ EOF`
cursorShape: Qt.PointingHandCursor
onClicked: {
// Use NiriWorkspaceService for workspace switching
if (NiriWorkspaceService.niriAvailable) {
NiriWorkspaceService.switchToWorkspaceByNumber(modelData)
} else {
// Fallback for when service isn't ready
Quickshell.execDetached(["niri", "msg", "action", "focus-workspace", modelData.toString()])
}
// Use sequential workspace number directly - niri focus-workspace uses 1,2,3,etc per monitor
Quickshell.execDetached(["niri", "msg", "action", "focus-workspace", sequentialNumber.toString()])
}
}
}