From f93a90d8f9112165bf7e56208e0f2bcfe2646ebf Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Tue, 17 May 2022 16:01:24 +0100 Subject: [PATCH] adjusted i3_workspaces to traverse down tree to get all open windows --- i3_workspaces.nim | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/i3_workspaces.nim b/i3_workspaces.nim index 798d256..832022a 100644 --- a/i3_workspaces.nim +++ b/i3_workspaces.nim @@ -43,8 +43,12 @@ proc buildString(ws: Workspace): string = else: str &= " " str &= "| " & ws.output & " | " - for app in ws.applications: - str &= app.class & " " & app.title & " | " + if ws.application.class != "": + str &= ws.application.class & " " & ws.application.title & " | " + else: + str = "" +# for app in ws.applications: +# str &= app.class & " " & app.title & " | " return str proc findWorkspace(workspace: string): Workspace = @@ -75,13 +79,15 @@ proc switchWorkspace(workspace: string) = # apps.add(name) # return (apps, focused) # -proc getApplication(node: JsonNode): Application = +proc getApplication(node: JsonNode, ws: Workspace = Workspace()): Application = var app = Application() let window = node["window_properties"] app.title = window["title"].getStr() app.class = window["class"].getStr() app.focused = node["focused"].getBool() app.urgent = node["urgent"].getBool() + #echo ws.num + #echo app.title & " " & app.class return app # proc findWorkspaces(node: JsonNode) = @@ -118,28 +124,33 @@ proc newWorkspace(node: JsonNode): Workspace = output: node["output"].getStr(), ) -proc findWorkspacesTree(node: JsonNode) = +proc findWorkspacesTree(node: JsonNode, parent: Workspace = Workspace()) = for channel in node["nodes"].getElems(): ### move this into for loop if want separate entry per window var ws: Workspace = Workspace() - if node{"type"}.getStr() == "workspace": + if parent.num > 0: + ws = parent + elif node{"type"}.getStr() == "workspace": if node["output"].getStr() == "__i3": return ws = newWorkspace(node) ### if channel{"window_properties"} != nil: - let app = getApplication(channel) + let app = getApplication(channel,ws) if ws.name != "": #if app.focused: # ws.focused = true ws.applications.add(app) ws.application = app + elif ws.num > 0 and len(channel{"nodes"}) > 0: + findWorkspacesTree(channel,ws) else: findWorkspacesTree(channel) ### move this into for loop if want separate entry per window if ws.name != "": ws.display_string = ws.buildString() - my_workspaces.add(ws) + if ws.display_string != "": + my_workspaces.add(ws) ### return