@@ -42,7 +42,7 @@ fileprivate func applicationActivated(_ element: AXUIElement, _ pid: pid_t) thro
4242            let  window  =  ( appFocusedWindow !=  nil  && wid !=  nil )  ?  Windows . updateLastFocus ( appFocusedWindow!,  wid!) ? . first :  nil 
4343            app. focusedWindow =  window
4444            App . app. checkIfShortcutsShouldBeDisabled ( window,  app. runningApplication) 
45-             App . app. refreshOpenUi ( window !=  nil  ?  [ window!]  :  [ ] ) 
45+             App . app. refreshOpenUi ( window !=  nil  ?  [ window!]  :  [ ] ,   . refreshUiAfterExternalEvent ) 
4646        } 
4747    } 
4848} 
@@ -55,7 +55,11 @@ fileprivate func applicationHiddenOrShown(_ pid: pid_t, _ type: String) throws {
5555                // for AXUIElement of apps, CFEqual or == don't work; looks like a Cocoa bug
5656                return  $0. application. pid ==  pid
5757            } 
58-             App . app. refreshOpenUi ( windows) 
58+             // if we process the "shown" event too fast, the window won't be listed by CGSCopyWindowsWithOptionsAndTags
59+             // it will thus be detected as isTabbed. We add a delay to work around this scenario
60+             DispatchQueue . main. asyncAfter ( deadline:  . now( )  +  . milliseconds( 200 ) )  { 
61+                 App . app. refreshOpenUi ( windows,  . refreshUiAfterExternalEvent) 
62+             } 
5963        } 
6064    } 
6165} 
@@ -77,7 +81,7 @@ fileprivate func windowCreated(_ element: AXUIElement, _ pid: pid_t) throws {
7781                    let  window  =  Window ( element,  app,  wid,  axTitle,  isFullscreen,  isMinimized,  position,  size) 
7882                    Windows . appendAndUpdateFocus ( window) 
7983                    Windows . cycleFocusedWindowIndex ( 1 ) 
80-                     App . app. refreshOpenUi ( [ window] ) 
84+                     App . app. refreshOpenUi ( [ window] ,   . refreshUiAfterExternalEvent ) 
8185                } 
8286            } 
8387        } 
@@ -106,11 +110,11 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro
106110                    app. focusedWindow =  w
107111                } 
108112                if  let  windows =  Windows . updateLastFocus ( element,  wid)  { 
109-                     App . app. refreshOpenUi ( windows) 
113+                     App . app. refreshOpenUi ( windows,   . refreshUiAfterExternalEvent ) 
110114                }  else  if  AXUIElement . isActualWindow ( app,  wid,  level,  axTitle,  subrole,  role,  size)  { 
111115                    let  window  =  Window ( element,  app,  wid,  axTitle,  isFullscreen,  isMinimized,  position,  size) 
112116                    Windows . appendAndUpdateFocus ( window) 
113-                     App . app. refreshOpenUi ( [ window] ) 
117+                     App . app. refreshOpenUi ( [ window] ,   . refreshUiAfterExternalEvent ) 
114118                } 
115119            } 
116120        } 
@@ -142,7 +146,7 @@ fileprivate func windowDestroyed(_ element: AXUIElement, _ pid: pid_t) throws {
142146            } 
143147            if  Windows . list. count >  0  { 
144148                Windows . moveFocusedWindowIndexAfterWindowDestroyedInBackground ( index) 
145-                 App . app. refreshOpenUi ( [ ] ) 
149+                 App . app. refreshOpenUi ( [ ] ,   . refreshUiAfterExternalEvent ) 
146150            }  else  { 
147151                App . app. hideUi ( ) 
148152            } 
@@ -155,7 +159,7 @@ fileprivate func windowMiniaturizedOrDeminiaturized(_ element: AXUIElement, _ ty
155159        DispatchQueue . main. async { 
156160            if  let  window =  ( Windows . list. first  {  $0. isEqualRobust ( element,  wid)  } )  { 
157161                window. isMinimized =  type ==  kAXWindowMiniaturizedNotification
158-                 App . app. refreshOpenUi ( [ window] ) 
162+                 App . app. refreshOpenUi ( [ window] ,   . refreshUiAfterExternalEvent ) 
159163            } 
160164        } 
161165    } 
@@ -167,7 +171,7 @@ fileprivate func windowTitleChanged(_ element: AXUIElement) throws {
167171        DispatchQueue . main. async { 
168172            if  let  window =  ( Windows . list. first  {  $0. isEqualRobust ( element,  wid)  } ) ,  newTitle !=  window. title { 
169173                window. title =  window. bestEffortTitle ( newTitle) 
170-                 App . app. refreshOpenUi ( [ window] ) 
174+                 App . app. refreshOpenUi ( [ window] ,   . refreshUiAfterExternalEvent ) 
171175            } 
172176        } 
173177    } 
@@ -188,7 +192,7 @@ fileprivate func windowResizedOrMoved(_ element: AXUIElement) throws {
188192                    window. isFullscreen =  isFullscreen
189193                    App . app. checkIfShortcutsShouldBeDisabled ( window,  nil ) 
190194                } 
191-                 App . app. refreshOpenUi ( [ window] ) 
195+                 App . app. refreshOpenUi ( [ window] ,   . refreshUiAfterExternalEvent ) 
192196            } 
193197        } 
194198    } 
0 commit comments