From 9236b2f00eaeca8d034e4b6fa3dd2f11aef4f831 Mon Sep 17 00:00:00 2001 From: LemmyCook Date: Fri, 19 Sep 2025 15:53:06 -0400 Subject: [PATCH] autoformatting --- Modules/Bar/Widgets/ActiveWindow.qml | 5 +- Services/CompositorService.qml | 31 ++++---- Services/HyprlandService.qml | 79 ++++++++++-------- Services/NiriService.qml | 115 +++++++++++++-------------- 4 files changed, 118 insertions(+), 112 deletions(-) diff --git a/Modules/Bar/Widgets/ActiveWindow.qml b/Modules/Bar/Widgets/ActiveWindow.qml index 7a296e82..5e6eb2f8 100644 --- a/Modules/Bar/Widgets/ActiveWindow.qml +++ b/Modules/Bar/Widgets/ActiveWindow.qml @@ -32,7 +32,6 @@ Item { readonly property string windowTitle: CompositorService.getFocusedWindowTitle() - readonly property bool showIcon: (widgetSettings.showIcon !== undefined) ? widgetSettings.showIcon : widgetMetadata.showIcon // 6% of total width @@ -43,7 +42,7 @@ Item { readonly property bool isVertical: barPosition === "left" || barPosition === "right" readonly property bool compact: (Settings.data.bar.density === "compact") - readonly property real textSize: { + readonly property real textSize: { var base = isVertical ? width : height return Math.max(1, compact ? base * 0.43 : base * 0.33) } @@ -53,8 +52,6 @@ Item { implicitHeight: (barPosition === "left" || barPosition === "right") ? calculatedVerticalHeight() : Math.round(Style.barHeight * scaling) implicitWidth: (barPosition === "left" || barPosition === "right") ? Math.round(Style.capsuleHeight * 0.8 * scaling) : (horizontalLayout.implicitWidth + Style.marginM * 2 * scaling) - - visible: windowTitle !== "" function calculatedVerticalHeight() { diff --git a/Services/CompositorService.qml b/Services/CompositorService.qml index 0f0e41cd..8fc7c935 100644 --- a/Services/CompositorService.qml +++ b/Services/CompositorService.qml @@ -71,28 +71,29 @@ Singleton { } function setupBackendConnections() { - if (!backend) return + if (!backend) + return // Connect backend signals to facade signals backend.workspaceChanged.connect(() => { - // Sync workspaces when they change - syncWorkspaces() - // Forward the signal - workspaceChanged() - }) - + // Sync workspaces when they change + syncWorkspaces() + // Forward the signal + workspaceChanged() + }) + backend.activeWindowChanged.connect(activeWindowChanged) backend.windowListChanged.connect(() => { - // Sync windows when they change - windows = backend.windows - // Forward the signal - windowListChanged() - }) + // Sync windows when they change + windows = backend.windows + // Forward the signal + windowListChanged() + }) // Property bindings backend.focusedWindowIndexChanged.connect(() => { - focusedWindowIndex = backend.focusedWindowIndex - }) + focusedWindowIndex = backend.focusedWindowIndex + }) // Initial sync syncWorkspaces() @@ -166,4 +167,4 @@ Singleton { function suspend() { Quickshell.execDetached(["systemctl", "suspend"]) } -} \ No newline at end of file +} diff --git a/Services/HyprlandService.qml b/Services/HyprlandService.qml index 99e1fdb4..1b36cf4b 100644 --- a/Services/HyprlandService.qml +++ b/Services/HyprlandService.qml @@ -31,15 +31,16 @@ Item { // Initialization function initialize() { - if (initialized) return - + if (initialized) + return + try { Hyprland.refreshWorkspaces() Hyprland.refreshToplevels() Qt.callLater(() => { - safeUpdateWorkspaces() - safeUpdateWindows() - }) + safeUpdateWorkspaces() + safeUpdateWindows() + }) initialized = true Logger.log("HyprlandService", "Initialized successfully") } catch (e) { @@ -59,7 +60,7 @@ Item { try { workspaces.clear() workspaceCache = {} - + if (!Hyprland.workspaces || !Hyprland.workspaces.values) { return } @@ -69,7 +70,8 @@ Item { for (var i = 0; i < hlWorkspaces.length; i++) { const ws = hlWorkspaces[i] - if (!ws || ws.id < 1) continue + if (!ws || ws.id < 1) + continue const wsData = { "id": i, @@ -81,7 +83,7 @@ Item { "isUrgent": ws.urgent === true, "isOccupied": occupiedIds[ws.id] === true } - + workspaceCache[ws.id] = wsData workspaces.append(wsData) } @@ -93,7 +95,7 @@ Item { // Get occupied workspace IDs safely function getOccupiedWorkspaceIds() { const occupiedIds = {} - + try { if (!Hyprland.toplevels || !Hyprland.toplevels.values) { return occupiedIds @@ -102,21 +104,24 @@ Item { const hlToplevels = Hyprland.toplevels.values for (var i = 0; i < hlToplevels.length; i++) { const toplevel = hlToplevels[i] - if (!toplevel) continue - + if (!toplevel) + continue + try { const wsId = toplevel.workspace ? toplevel.workspace.id : null if (wsId !== null && wsId !== undefined) { occupiedIds[wsId] = true } } catch (e) { + // Ignore individual toplevel errors } } } catch (e) { + // Return empty if we can't determine occupancy } - + return occupiedIds } @@ -125,7 +130,7 @@ Item { try { const windowsList = [] windowCache = {} - + if (!Hyprland.toplevels || !Hyprland.toplevels.values) { windows = [] focusedWindowIndex = -1 @@ -137,13 +142,14 @@ Item { for (var i = 0; i < hlToplevels.length; i++) { const toplevel = hlToplevels[i] - if (!toplevel) continue + if (!toplevel) + continue const windowData = extractWindowData(toplevel) if (windowData) { windowsList.push(windowData) windowCache[windowData.id] = windowData - + if (windowData.isFocused) { newFocusedIndex = windowsList.length - 1 } @@ -151,7 +157,7 @@ Item { } windows = windowsList - + if (newFocusedIndex !== focusedWindowIndex) { focusedWindowIndex = newFocusedIndex activeWindowChanged() @@ -163,18 +169,20 @@ Item { // Extract window data safely from a toplevel function extractWindowData(toplevel) { - if (!toplevel) return null - + if (!toplevel) + return null + try { // Safely extract properties const windowId = safeGetProperty(toplevel, "address", "") - if (!windowId) return null - + if (!windowId) + return null + const appId = extractAppId(toplevel) const title = safeGetProperty(toplevel, "title", "") const wsId = toplevel.workspace ? toplevel.workspace.id : null const focused = toplevel.activated === true - + return { "id": windowId, "title": title, @@ -189,29 +197,33 @@ Item { // Extract app ID from various possible sources function extractAppId(toplevel) { - if (!toplevel) return "" - + if (!toplevel) + return "" + // Try direct properties var appId = safeGetProperty(toplevel, "class", "") - if (appId) return appId - + if (appId) + return appId + appId = safeGetProperty(toplevel, "initialClass", "") - if (appId) return appId - + if (appId) + return appId + appId = safeGetProperty(toplevel, "appId", "") - if (appId) return appId - + if (appId) + return appId + // Try lastIpcObject try { const ipcData = toplevel.lastIpcObject if (ipcData) { - return String(ipcData.class || ipcData.initialClass || - ipcData.appId || ipcData.wm_class || "") + return String(ipcData.class || ipcData.initialClass || ipcData.appId || ipcData.wm_class || "") } } catch (e) { + // Ignore IPC errors } - + return "" } @@ -223,6 +235,7 @@ Item { return String(value) } } catch (e) { + // Property access failed } return defaultValue @@ -272,4 +285,4 @@ Item { Logger.error("HyprlandService", "Failed to logout:", e) } } -} \ No newline at end of file +} diff --git a/Services/NiriService.qml b/Services/NiriService.qml index 1929bc97..b65d9d19 100644 --- a/Services/NiriService.qml +++ b/Services/NiriService.qml @@ -48,31 +48,31 @@ Item { for (const ws of workspacesData) { workspacesList.push({ - "id": ws.id, - "idx": ws.idx, - "name": ws.name || "", - "output": ws.output || "", - "isFocused": ws.is_focused === true, - "isActive": ws.is_active === true, - "isUrgent": ws.is_urgent === true, - "isOccupied": ws.active_window_id ? true : false - }) + "id": ws.id, + "idx": ws.idx, + "name": ws.name || "", + "output": ws.output || "", + "isFocused": ws.is_focused === true, + "isActive": ws.is_active === true, + "isUrgent": ws.is_urgent === true, + "isOccupied": ws.active_window_id ? true : false + }) } // Sort workspaces by output, then by index workspacesList.sort((a, b) => { - if (a.output !== b.output) { - return a.output.localeCompare(b.output) - } - return a.idx - b.idx - }) + if (a.output !== b.output) { + return a.output.localeCompare(b.output) + } + return a.idx - b.idx + }) // Update the workspaces ListModel workspaces.clear() for (var i = 0; i < workspacesList.length; i++) { workspaces.append(workspacesList[i]) } - + workspaceChanged() } catch (e) { Logger.error("NiriService", "Failed to parse workspaces:", e, line) @@ -92,15 +92,15 @@ Item { try { const windowsData = JSON.parse(line) const windowsList = [] - + for (const win of windowsData) { windowsList.push({ - "id": win.id, - "title": win.title || "", - "appId": win.app_id || "", - "workspaceId": win.workspace_id || null, - "isFocused": win.is_focused === true - }) + "id": win.id, + "title": win.title || "", + "appId": win.app_id || "", + "workspaceId": win.workspace_id || null, + "isFocused": win.is_focused === true + }) } windowsList.sort((a, b) => a.id - b.id) @@ -115,7 +115,7 @@ Item { break } } - + activeWindowChanged() } catch (e) { Logger.error("NiriService", "Failed to parse windows:", e, line) @@ -132,32 +132,27 @@ Item { stdout: SplitParser { onRead: data => { - try { - const event = JSON.parse(data.trim()) + try { + const event = JSON.parse(data.trim()) - if (event.WorkspacesChanged) { - updateWorkspaces() - } - else if (event.WindowOpenedOrChanged) { - handleWindowOpenedOrChanged(event.WindowOpenedOrChanged) - } - else if (event.WindowClosed) { - handleWindowClosed(event.WindowClosed) - } - else if (event.WindowsChanged) { - handleWindowsChanged(event.WindowsChanged) - } - else if (event.WorkspaceActivated) { - updateWorkspaces() - } - else if (event.WindowFocusChanged) { - handleWindowFocusChanged(event.WindowFocusChanged) - } - // Removed OverviewOpenedOrClosed handling - } catch (e) { - Logger.error("NiriService", "Error parsing event stream:", e, data) - } - } + if (event.WorkspacesChanged) { + updateWorkspaces() + } else if (event.WindowOpenedOrChanged) { + handleWindowOpenedOrChanged(event.WindowOpenedOrChanged) + } else if (event.WindowClosed) { + handleWindowClosed(event.WindowClosed) + } else if (event.WindowsChanged) { + handleWindowsChanged(event.WindowsChanged) + } else if (event.WorkspaceActivated) { + updateWorkspaces() + } else if (event.WindowFocusChanged) { + handleWindowFocusChanged(event.WindowFocusChanged) + } + // Removed OverviewOpenedOrClosed handling + } catch (e) { + Logger.error("NiriService", "Error parsing event stream:", e, data) + } + } } } @@ -205,7 +200,7 @@ Item { try { const windowId = eventData.id const windowIndex = windows.findIndex(w => w.id === windowId) - + if (windowIndex >= 0) { // If this was the focused window, clear focus if (windowIndex === focusedWindowIndex) { @@ -229,15 +224,15 @@ Item { try { const windowsData = eventData.windows const windowsList = [] - + for (const win of windowsData) { windowsList.push({ - "id": win.id, - "title": win.title || "", - "appId": win.app_id || "", - "workspaceId": win.workspace_id || null, - "isFocused": win.is_focused === true - }) + "id": win.id, + "title": win.title || "", + "appId": win.app_id || "", + "workspaceId": win.workspace_id || null, + "isFocused": win.is_focused === true + }) } windowsList.sort((a, b) => a.id - b.id) @@ -252,7 +247,7 @@ Item { break } } - + activeWindowChanged() } catch (e) { Logger.error("NiriService", "Error handling WindowsChanged:", e) @@ -262,14 +257,14 @@ Item { function handleWindowFocusChanged(eventData) { try { const focusedId = eventData.id - + if (focusedId) { const newIndex = windows.findIndex(w => w.id === focusedId) focusedWindowIndex = newIndex >= 0 ? newIndex : -1 } else { focusedWindowIndex = -1 } - + activeWindowChanged() } catch (e) { Logger.error("NiriService", "Error handling WindowFocusChanged:", e) @@ -292,4 +287,4 @@ Item { Logger.error("NiriService", "Failed to logout:", e) } } -} \ No newline at end of file +}