@@ -82,7 +82,7 @@ actor WidgetWindowsController: NSObject {
8282 }
8383
8484 updateWindowStateTask = Task { [weak self] in
85- if let self { await handleXcodeFullscreenChange () }
85+ if let self { await handleSpaceChange () }
8686
8787 await withThrowingTaskGroup(of: Void.self) { [weak self] group in
8888 // active space did change
@@ -92,7 +92,7 @@ actor WidgetWindowsController: NSObject {
9292 for await _ in sequence {
9393 guard let self else { return }
9494 try Task.checkCancellation()
95- await handleXcodeFullscreenChange ()
95+ await handleSpaceChange ()
9696 }
9797 }
9898 }
@@ -160,7 +160,7 @@ private extension WidgetWindowsController {
160160
161161 switch notification.kind {
162162 case .focusedWindowChanged:
163- await handleXcodeFullscreenChange ()
163+ await handleSpaceChange ()
164164 await hideWidgetForTransitions()
165165 await updateWidgetsAndNotifyChangeOfEditor(immediately: true)
166166 case .focusedUIElementChanged:
@@ -402,7 +402,7 @@ extension WidgetWindowsController {
402402 windows. toastWindow. alphaValue = noFocus ? 0 : 1
403403
404404 if isChatPanelDetached {
405- windows. chatPanelWindow. isWindowHidden = !hasChat
405+ windows. chatPanelWindow. isWindowHidden = false
406406 } else {
407407 windows. chatPanelWindow. isWindowHidden = noFocus
408408 }
@@ -436,7 +436,7 @@ extension WidgetWindowsController {
436436 }
437437 windows. toastWindow. alphaValue = noFocus ? 0 : 1
438438 if isChatPanelDetached {
439- windows. chatPanelWindow. isWindowHidden = !hasChat
439+ windows. chatPanelWindow. isWindowHidden = false
440440 } else {
441441 windows. chatPanelWindow. isWindowHidden = noFocus && !windows
442442 . chatPanelWindow. isKeyWindow
@@ -584,7 +584,7 @@ extension WidgetWindowsController {
584584 }
585585
586586 @MainActor
587- func handleXcodeFullscreenChange ( ) async {
587+ func handleSpaceChange ( ) async {
588588 let activeXcode = await XcodeInspector . shared. safe. activeXcode
589589
590590 let xcode = activeXcode? . appElement
@@ -593,19 +593,26 @@ extension WidgetWindowsController {
593593 } else {
594594 false
595595 }
596+
597+ let isXcodeActive = xcode? . isFrontmost ?? false
596598
597- [
598- windows. chatPanelWindow,
599+ await [
599600 windows. sharedPanelWindow,
600601 windows. suggestionPanelWindow,
601602 windows. widgetWindow,
602603 windows. toastWindow,
603604 ] . forEach {
604- $0. send ( . didChangeActiveSpace( fullscreen: isFullscreen) )
605+ if isXcodeActive {
606+ $0. moveToActiveSpace ( )
607+ }
608+ }
609+
610+ if isXcodeActive, !windows. chatPanelWindow. isDetached {
611+ await windows. chatPanelWindow. moveToActiveSpace ( )
605612 }
606613
607- if windows. fullscreenDetector. isOnActiveSpace, xcode? . focusedWindow != nil {
608- windows. orderFront ( )
614+ if await windows. fullscreenDetector. isOnActiveSpace, xcode? . focusedWindow != nil {
615+ await windows. orderFront ( )
609616 }
610617 }
611618}
@@ -796,7 +803,7 @@ public final class WidgetWindows {
796803 it. isReleasedWhenClosed = false
797804 it. isOpaque = false
798805 it. backgroundColor = . clear
799- it. level = widgetLevel ( 0 )
806+ it. level = widgetLevel ( 2 )
800807 it. hasShadow = false
801808 it. contentView = NSHostingView (
802809 rootView: ToastPanelView ( store: store. scope (
@@ -845,26 +852,10 @@ class WidgetWindow: CanBecomeKeyWindow {
845852 case switchingSpace
846853 }
847854
848- enum Action {
849- case didChangeActiveSpace( fullscreen: Bool )
850- }
851-
852855 var defaultCollectionBehavior : NSWindow . CollectionBehavior {
853856 [ . fullScreenAuxiliary, . transient]
854857 }
855858
856- var fullscreenCollectionBehavior : NSWindow . CollectionBehavior {
857- // .canJoinAllSpaces is required for macOS 15 (beta?) to display widgets in fullscreen mode.
858- // But adding this behavior will create another issue that the widgets will display
859- // whenever user switch spaces, so we are setting it only when the window is in fullscreen
860- // mode.
861- [ . fullScreenAuxiliary, . transient, . canJoinAllSpaces]
862- }
863-
864- var switchingSpaceCollectionBehavior : NSWindow . CollectionBehavior {
865- [ . fullScreenAuxiliary, . transient]
866- }
867-
868859 var isFullscreen : Bool {
869860 styleMask. contains ( . fullScreen)
870861 }
@@ -876,19 +867,19 @@ class WidgetWindow: CanBecomeKeyWindow {
876867 case . none:
877868 collectionBehavior = defaultCollectionBehavior
878869 case . switchingSpace:
879- collectionBehavior = switchingSpaceCollectionBehavior
880- case let . normal( fullscreen) :
881- collectionBehavior = fullscreen
882- ? fullscreenCollectionBehavior
883- : defaultCollectionBehavior
870+ collectionBehavior = defaultCollectionBehavior. union ( . moveToActiveSpace)
871+ case . normal:
872+ collectionBehavior = defaultCollectionBehavior
884873 }
885874 }
886875 }
887-
888- func send( _ action: Action ) {
889- switch action {
890- case let . didChangeActiveSpace( fullscreen) :
891- state = . normal( fullscreen: fullscreen)
876+
877+ func moveToActiveSpace( ) {
878+ let previousState = state
879+ state = . switchingSpace
880+ Task { @MainActor in
881+ try await Task . sleep ( nanoseconds: 50_000_000 )
882+ self . state = previousState
892883 }
893884 }
894885}
0 commit comments