fix: bypass kglobalaccel in workspace_service.py using direct KWin VirtualDesktopManager DBus calls

This commit is contained in:
Sho 2026-08-01 23:34:42 +09:00
parent f495a4f8e2
commit 8efe6d5198

View File

@ -65,15 +65,32 @@ def get_status():
}
def switch_to(index):
try:
idx_target = int(index)
desktops_raw = subprocess.check_output(
["qdbus6", "--literal", "org.kde.KWin", "/VirtualDesktopManager", "org.kde.KWin.VirtualDesktopManager.desktops"],
text=True, stderr=subprocess.DEVNULL
)
matches = re.findall(r'\(uss\)\s*(\d+),\s*"([^"]+)"(?:,\s*"([^"]*)")?', desktops_raw)
if matches and 1 <= idx_target <= len(matches):
target_uuid = matches[idx_target - 1][1]
res = subprocess.run(
["qdbus6", "org.kde.KWin", "/VirtualDesktopManager", "org.kde.KWin.VirtualDesktopManager.setCurrent", target_uuid],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
if res.returncode == 0:
return
except Exception:
pass
try:
shortcut_name = f"Switch to Desktop {index}"
res = subprocess.run(
["qdbus6", "org.kde.kglobalaccel", "/component/kwin", "org.kde.kglobalaccel.Component.invokeShortcut", shortcut_name],
capture_output=True, text=True
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
if res.returncode != 0:
# Hyprland fallback
subprocess.run(["hyprctl", "dispatch", "workspace", str(index)], capture_output=True)
subprocess.run(["hyprctl", "dispatch", "workspace", str(index)], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except Exception:
pass