Add #105 PR from main

This commit is contained in:
Ly-sec 2025-08-12 17:29:18 +02:00
parent 5c8c57f05f
commit a867ae4bca

View file

@ -1,6 +1,5 @@
pragma Singleton pragma Singleton
pragma ComponentBehavior: Bound
pragma ComponentBehavior
import QtQuick import QtQuick
import Quickshell import Quickshell
@ -17,35 +16,35 @@ Singleton {
property var hlWorkspaces: Hyprland.workspaces.values property var hlWorkspaces: Hyprland.workspaces.values
// Detect which compositor we're using // Detect which compositor we're using
Component.onCompleted: { Component.onCompleted: {
console.log("Workspace initializing...") console.log("WorkspaceManager initializing...");
detectCompositor() detectCompositor();
} }
function detectCompositor() { function detectCompositor() {
try { try {
try { try {
if (Hyprland.eventSocketPath) { if (Hyprland.eventSocketPath) {
console.log("Detected Hyprland compositor") console.log("Detected Hyprland compositor");
isHyprland = true isHyprland = true;
isNiri = false isNiri = false;
initHyprland() initHyprland();
return return;
} }
} catch (e) { } catch (e) {
console.log("Hyprland not available:", e) console.log("Hyprland not available:", e);
} }
if (typeof Niri !== "undefined") { if (typeof Niri !== "undefined") {
console.log("Detected Niri service") console.log("Detected Niri service");
isHyprland = false isHyprland = false;
isNiri = true isNiri = true;
initNiri() initNiri();
return return;
} }
console.log("No supported compositor detected") console.log("No supported compositor detected");
} catch (e) { } catch (e) {
console.error("Error detecting compositor:", e) console.error("Error detecting compositor:", e);
} }
} }
@ -53,102 +52,105 @@ Singleton {
function initHyprland() { function initHyprland() {
try { try {
// Fixes the odd workspace issue. // Fixes the odd workspace issue.
Hyprland.refreshWorkspaces() Hyprland.refreshWorkspaces();
// hlWorkspaces = Hyprland.workspaces.values; // hlWorkspaces = Hyprland.workspaces.values;
// updateHyprlandWorkspaces(); // updateHyprlandWorkspaces();
return true return true;
} catch (e) { } catch (e) {
console.error("Error initializing Hyprland:", e) console.error("Error initializing Hyprland:", e);
isHyprland = false isHyprland = false;
return false return false;
} }
} }
onHlWorkspacesChanged: { onHlWorkspacesChanged: {
updateHyprlandWorkspaces() updateHyprlandWorkspaces();
} }
Connections { Connections {
target: Hyprland.workspaces target: Hyprland.workspaces
function onValuesChanged() { function onValuesChanged() {
updateHyprlandWorkspaces() updateHyprlandWorkspaces();
} }
} }
Connections { Connections {
target: Hyprland target: Hyprland
function onRawEvent(event) { function onRawEvent(event) {
updateHyprlandWorkspaces() updateHyprlandWorkspaces();
} }
} }
function updateHyprlandWorkspaces() { function updateHyprlandWorkspaces() {
workspaces.clear() workspaces.clear();
try { try {
for (var i = 0; i < hlWorkspaces.length; i++) { for (let i = 0; i < hlWorkspaces.length; i++) {
const ws = hlWorkspaces[i] const ws = hlWorkspaces[i];
// Only append workspaces with id >= 1
if (ws.id >= 1) {
workspaces.append({ workspaces.append({
"id": i, id: i,
"idx": ws.id, idx: ws.id,
"name": ws.name || "", name: ws.name || "",
"output": ws.monitor?.name || "", output: ws.monitor?.name || "",
"isActive": ws.active === true, isActive: ws.active === true,
"isFocused": ws.focused === true, isFocused: ws.focused === true,
"isUrgent": ws.urgent === true isUrgent: ws.urgent === true
}) });
} }
workspacesChanged() }
workspacesChanged();
} catch (e) { } catch (e) {
console.error("Error updating Hyprland workspaces:", e) console.error("Error updating Hyprland workspaces:", e);
} }
} }
function initNiri() { function initNiri() {
updateNiriWorkspaces() updateNiriWorkspaces();
} }
Connections { Connections {
target: Niri target: Niri
function onWorkspacesChanged() { function onWorkspacesChanged() {
updateNiriWorkspaces() updateNiriWorkspaces();
} }
} }
function updateNiriWorkspaces() { function updateNiriWorkspaces() {
const niriWorkspaces = Niri.workspaces || [] const niriWorkspaces = Niri.workspaces || [];
workspaces.clear() workspaces.clear();
for (var i = 0; i < niriWorkspaces.length; i++) { for (let i = 0; i < niriWorkspaces.length; i++) {
const ws = niriWorkspaces[i] const ws = niriWorkspaces[i];
workspaces.append({ workspaces.append({
"id": ws.id, id: ws.id,
"idx": ws.idx || 1, idx: ws.idx || 1,
"name": ws.name || "", name: ws.name || "",
"output": ws.output || "", output: ws.output || "",
"isFocused": ws.isFocused === true, isFocused: ws.isFocused === true,
"isActive": ws.isActive === true, isActive: ws.isActive === true,
"isUrgent": ws.isUrgent === true, isUrgent: ws.isUrgent === true,
"isOccupied": ws.isOccupied === true isOccupied: ws.isOccupied === true,
}) });
} }
workspacesChanged() workspacesChanged();
} }
function switchToWorkspace(workspaceId) { function switchToWorkspace(workspaceId) {
if (isHyprland) { if (isHyprland) {
try { try {
Hyprland.dispatch(`workspace ${workspaceId}`) Hyprland.dispatch(`workspace ${workspaceId}`);
} catch (e) { } catch (e) {
console.error("Error switching Hyprland workspace:", e) console.error("Error switching Hyprland workspace:", e);
} }
} else if (isNiri) { } else if (isNiri) {
try { try {
Quickshell.execDetached(["niri", "msg", "action", "focus-workspace", workspaceId.toString()]) Quickshell.execDetached(["niri", "msg", "action", "focus-workspace", workspaceId.toString()]);
} catch (e) { } catch (e) {
console.error("Error switching Niri workspace:", e) console.error("Error switching Niri workspace:", e);
} }
} else { } else {
console.warn("No supported compositor detected for workspace switching") console.warn("No supported compositor detected for workspace switching");
} }
} }
} }