@@ -17,6 +17,9 @@ actor WidgetWindowsController: NSObject {
1717 nonisolated let chatTabPool : ChatTabPool
1818
1919 var currentApplicationProcessIdentifier : pid_t ?
20+
21+ weak var currentXcodeApp : XcodeAppInstanceInspector ?
22+ weak var previousXcodeApp : XcodeAppInstanceInspector ?
2023
2124 var cancellable : Set < AnyCancellable > = [ ]
2225 var observeToAppTask : Task < Void , Error > ?
@@ -84,6 +87,12 @@ private extension WidgetWindowsController {
8487 if app. isXcode {
8588 updateWindowLocation ( animated: false , immediately: true )
8689 updateWindowOpacity ( immediately: false )
90+
91+ if let xcodeApp = app as? XcodeAppInstanceInspector {
92+ previousXcodeApp = currentXcodeApp ?? xcodeApp
93+ currentXcodeApp = xcodeApp
94+ }
95+
8796 } else {
8897 updateWindowOpacity ( immediately: true )
8998 updateWindowLocation ( animated: false , immediately: false )
@@ -149,7 +158,7 @@ private extension WidgetWindowsController {
149158 . windowMoved,
150159 . windowResized:
151160 await updateWidgets ( immediately: false )
152- await updateChatWindowLocation ( )
161+ await updateAttachedChatWindowLocation ( notification )
153162 case . created, . uiElementDestroyed, . xcodeCompletionPanelChanged,
154163 . applicationDeactivated:
155164 continue
@@ -446,14 +455,55 @@ extension WidgetWindowsController {
446455 }
447456
448457 @MainActor
449- func updateChatWindowLocation( ) {
450- let state = store. withState { $0 }
458+ func updateAttachedChatWindowLocation( _ notif: XcodeAppInstanceInspector . AXNotification ? = nil ) async {
459+ guard let currentXcodeApp = ( await currentXcodeApp) ,
460+ let currentFocusedWindow = currentXcodeApp. appElement. focusedWindow,
461+ let currentXcodeScreen = currentXcodeApp. appScreen,
462+ let currentXcodeRect = currentFocusedWindow. rect
463+ else { return }
464+
465+ if let previousXcodeApp = ( await previousXcodeApp) ,
466+ currentXcodeApp. processIdentifier == previousXcodeApp. processIdentifier {
467+ if currentFocusedWindow. isFullScreen == true {
468+ return
469+ }
470+ }
471+
451472 let isAttachedToXcodeEnabled = UserDefaults . shared. value ( for: \. autoAttachChatToXcode)
452- if isAttachedToXcodeEnabled {
453- if state. chatPanelState. isPanelDisplayed && !windows. chatPanelWindow. isWindowHidden {
454- let frame = UpdateLocationStrategy . getChatPanelFrame ( isAttachedToXcodeEnabled: isAttachedToXcodeEnabled)
455- windows. chatPanelWindow. setFrame ( frame, display: true , animate: true )
473+ guard isAttachedToXcodeEnabled else { return }
474+
475+ if let notif = notif {
476+ let dialogIdentifiers = [ " open_quickly " , " alert " ]
477+ if dialogIdentifiers. contains ( notif. element. identifier) { return }
478+ }
479+
480+ let state = store. withState { $0 }
481+ if state. chatPanelState. isPanelDisplayed && !windows. chatPanelWindow. isWindowHidden {
482+ var frame = UpdateLocationStrategy . getChatPanelFrame (
483+ isAttachedToXcodeEnabled: true ,
484+ xcodeApp: currentXcodeApp
485+ )
486+
487+ let screenMaxX = currentXcodeScreen. visibleFrame. maxX
488+ if screenMaxX - currentXcodeRect. maxX < Style . minChatPanelWidth
489+ {
490+ if let previousXcodeRect = ( await previousXcodeApp? . appElement. focusedWindow? . rect) ,
491+ screenMaxX - previousXcodeRect. maxX < Style . minChatPanelWidth
492+ {
493+ let isSameScreen = currentXcodeScreen. visibleFrame. intersects ( windows. chatPanelWindow. frame)
494+ // Only update y and height
495+ frame = . init(
496+ x: isSameScreen ? windows. chatPanelWindow. frame. minX : frame. minX,
497+ y: frame. minY,
498+ width: isSameScreen ? windows. chatPanelWindow. frame. width : frame. width,
499+ height: frame. height
500+ )
501+ }
456502 }
503+
504+ windows. chatPanelWindow. setFrame ( frame, display: true , animate: true )
505+
506+ await adjustChatPanelWindowLevel ( )
457507 }
458508 }
459509
@@ -496,7 +546,7 @@ extension WidgetWindowsController {
496546
497547 let isAttachedToXcodeEnabled = UserDefaults . shared. value ( for: \. autoAttachChatToXcode)
498548 if isAttachedToXcodeEnabled {
499- // update in `updateChatWindowLocation `
549+ // update in `updateAttachedChatWindowLocation `
500550 } else if isChatPanelDetached {
501551 // don't update it!
502552 } else {
0 commit comments