Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit a8d2710

Browse files
committed
Adjust chat panel level behavior
1 parent 2bb0a70 commit a8d2710

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

Core/Sources/SuggestionWidget/WidgetWindowsController.swift

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,6 @@ extension WidgetWindowsController {
400400
windows.suggestionPanelWindow.alphaValue = noFocus ? 0 : 1
401401
windows.widgetWindow.alphaValue = noFocus ? 0 : 1
402402
windows.toastWindow.alphaValue = noFocus ? 0 : 1
403-
404-
if isChatPanelDetached {
405-
windows.chatPanelWindow.isWindowHidden = false
406-
} else {
407-
windows.chatPanelWindow.isWindowHidden = noFocus
408-
}
409403
} else if let activeApp, activeApp.isExtensionService {
410404
let noFocus = {
411405
guard let xcode = latestActiveXcode else { return true }
@@ -435,20 +429,11 @@ extension WidgetWindowsController {
435429
0
436430
}
437431
windows.toastWindow.alphaValue = noFocus ? 0 : 1
438-
if isChatPanelDetached {
439-
windows.chatPanelWindow.isWindowHidden = false
440-
} else {
441-
windows.chatPanelWindow.isWindowHidden = noFocus && !windows
442-
.chatPanelWindow.isKeyWindow
443-
}
444432
} else {
445433
windows.sharedPanelWindow.alphaValue = 1
446434
windows.suggestionPanelWindow.alphaValue = 0
447435
windows.widgetWindow.alphaValue = 0
448436
windows.toastWindow.alphaValue = 0
449-
if !isChatPanelDetached {
450-
windows.chatPanelWindow.isWindowHidden = true
451-
}
452437
}
453438
}
454439
}
@@ -543,7 +528,7 @@ extension WidgetWindowsController {
543528
} else {
544529
false
545530
}
546-
531+
547532
window.setFloatOnTop(latestAppIsXcodeOrExtension)
548533
}
549534

@@ -561,19 +546,9 @@ extension WidgetWindowsController {
561546
return
562547
}
563548

564-
guard disableFloatOnTopWhenTheChatPanelIsDetached else {
565-
window.setFloatOnTop(true)
566-
return
567-
}
568-
569549
let state = store.withState { $0 }
570550
let isChatPanelDetached = state.chatPanelState.isDetached
571551

572-
guard isChatPanelDetached else {
573-
window.setFloatOnTop(true)
574-
return
575-
}
576-
577552
let floatOnTopWhenOverlapsXcode = UserDefaults.shared
578553
.value(for: \.keepFloatOnTopIfChatPanelAndXcodeOverlaps)
579554

@@ -584,10 +559,8 @@ extension WidgetWindowsController {
584559
false
585560
}
586561

587-
if !floatOnTopWhenOverlapsXcode || !latestAppIsXcodeOrExtension {
588-
window.setFloatOnTop(false)
589-
} else {
590-
guard let xcode = await xcodeInspector.safe.latestActiveXcode else { return }
562+
async let overlap: Bool = { @MainActor in
563+
guard let xcode = await xcodeInspector.safe.latestActiveXcode else { return false }
591564
let windowElements = xcode.appElement.windows
592565
let overlap = windowElements.contains {
593566
if let position = $0.position, let size = $0.size {
@@ -601,8 +574,27 @@ extension WidgetWindowsController {
601574
}
602575
return false
603576
}
577+
return overlap
578+
}()
604579

605-
window.setFloatOnTop(overlap)
580+
if latestAppIsXcodeOrExtension {
581+
if floatOnTopWhenOverlapsXcode {
582+
let overlap = await overlap
583+
window.setFloatOnTop(overlap)
584+
} else {
585+
if disableFloatOnTopWhenTheChatPanelIsDetached, isChatPanelDetached {
586+
window.setFloatOnTop(false)
587+
} else {
588+
window.setFloatOnTop(true)
589+
}
590+
}
591+
} else {
592+
if floatOnTopWhenOverlapsXcode {
593+
let overlap = await overlap
594+
window.setFloatOnTop(overlap)
595+
} else {
596+
window.setFloatOnTop(false)
597+
}
606598
}
607599
}
608600

@@ -907,6 +899,7 @@ class WidgetWindow: CanBecomeKeyWindow {
907899
: .normal
908900

909901
if targetLevel != level {
902+
self.orderFrontRegardless()
910903
level = targetLevel
911904
}
912905
}

0 commit comments

Comments
 (0)