@@ -17,6 +17,9 @@ actor WidgetWindowsController: NSObject {
17
17
nonisolated let chatTabPool : ChatTabPool
18
18
19
19
var currentApplicationProcessIdentifier : pid_t ?
20
+
21
+ weak var currentXcodeApp : XcodeAppInstanceInspector ?
22
+ weak var previousXcodeApp : XcodeAppInstanceInspector ?
20
23
21
24
var cancellable : Set < AnyCancellable > = [ ]
22
25
var observeToAppTask : Task < Void , Error > ?
@@ -84,6 +87,12 @@ private extension WidgetWindowsController {
84
87
if app. isXcode {
85
88
updateWindowLocation ( animated: false , immediately: true )
86
89
updateWindowOpacity ( immediately: false )
90
+
91
+ if let xcodeApp = app as? XcodeAppInstanceInspector {
92
+ previousXcodeApp = currentXcodeApp ?? xcodeApp
93
+ currentXcodeApp = xcodeApp
94
+ }
95
+
87
96
} else {
88
97
updateWindowOpacity ( immediately: true )
89
98
updateWindowLocation ( animated: false , immediately: false )
@@ -149,7 +158,7 @@ private extension WidgetWindowsController {
149
158
. windowMoved,
150
159
. windowResized:
151
160
await updateWidgets ( immediately: false )
152
- await updateChatWindowLocation ( )
161
+ await updateAttachedChatWindowLocation ( notification )
153
162
case . created, . uiElementDestroyed, . xcodeCompletionPanelChanged,
154
163
. applicationDeactivated:
155
164
continue
@@ -446,14 +455,55 @@ extension WidgetWindowsController {
446
455
}
447
456
448
457
@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
+
451
472
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
+ }
456
502
}
503
+
504
+ windows. chatPanelWindow. setFrame ( frame, display: true , animate: true )
505
+
506
+ await adjustChatPanelWindowLevel ( )
457
507
}
458
508
}
459
509
@@ -496,7 +546,7 @@ extension WidgetWindowsController {
496
546
497
547
let isAttachedToXcodeEnabled = UserDefaults . shared. value ( for: \. autoAttachChatToXcode)
498
548
if isAttachedToXcodeEnabled {
499
- // update in `updateChatWindowLocation `
549
+ // update in `updateAttachedChatWindowLocation `
500
550
} else if isChatPanelDetached {
501
551
// don't update it!
502
552
} else {
0 commit comments