@@ -98,6 +98,7 @@ ScreenShot {
9898
9999 function collectWorkspaceWindows (workspaceNode , result ) {
100100 const stack = [workspaceNode]
101+ const seenWindowKeys = ({})
101102 while (stack .length > 0 ) {
102103 const node = stack .pop ()
103104 if (! node) {
@@ -106,31 +107,44 @@ ScreenShot {
106107
107108 const nodes = node .nodes ?? []
108109 const floatingNodes = node .floating_nodes ?? []
109- for (let i = 0 ; i < nodes .length ; i++ ) {
110- stack .push (nodes[i])
111- }
112110 for (let i = 0 ; i < floatingNodes .length ; i++ ) {
113111 stack .push (floatingNodes[i])
114112 }
113+ for (let i = 0 ; i < nodes .length ; i++ ) {
114+ stack .push (nodes[i])
115+ }
115116
116117 const isCon = node .type === " con"
118+ const isFloatingCon = node .type === " floating_con"
117119 const isLeaf = nodes .length === 0 && floatingNodes .length === 0
118120 const rect = node .rect
119121 const hasRect = rect && Number (rect .width ) > 0 && Number (rect .height ) > 0
120122 const hasWindowMeta = node .app_id || node .window || node .window_properties
123+ const isSelectableWindowNode = (isCon || isFloatingCon) && isLeaf && hasWindowMeta
124+
125+ if (! isSelectableWindowNode || ! hasRect) {
126+ continue
127+ }
121128
122- if (! isCon || ! isLeaf || ! hasRect || ! hasWindowMeta) {
129+ const windowTitle = String (node .name ?? " " )
130+ const windowClass = String (node .app_id ?? node .window_properties ? .class ?? " " )
131+ const windowAddress = String (node .id ?? " " )
132+ const dedupeKey = windowAddress !== " "
133+ ? windowAddress
134+ : [Number (rect .x ), Number (rect .y ), Number (rect .width ), Number (rect .height ), windowTitle, windowClass].join (" |" )
135+ if (seenWindowKeys[dedupeKey]) {
123136 continue
124137 }
138+ seenWindowKeys[dedupeKey] = true
125139
126140 result .push ({
127141 x: Number (rect .x ) - root .monitorOffsetX ,
128142 y: Number (rect .y ) - root .monitorOffsetY ,
129143 width: Number (rect .width ),
130144 height: Number (rect .height ),
131- title: String ( node . name ?? " " ) ,
132- cls: String ( node . app_id ?? node . window_properties ? . class ?? " " ) ,
133- address: String ( node . id ?? " " )
145+ title: windowTitle ,
146+ cls: windowClass ,
147+ address: windowAddress
134148 })
135149 }
136150 }
0 commit comments