@@ -122,26 +122,52 @@ public final class SuggestionWidgetController: NSObject {
122122 private lazy var chatPanelWindow = {
123123 let it = ChatWindow (
124124 contentRect: . zero,
125- styleMask: [ . resizable] ,
125+ styleMask: [ . resizable, . titled , . miniaturizable ] ,
126126 backing: . buffered,
127127 defer: false
128128 )
129+ it. minimizeWindow = { [ weak self] in
130+ self ? . store. send ( . chatPanel( . hideButtonClicked) )
131+ }
132+ it. titleVisibility = . hidden
133+ it. addTitlebarAccessoryViewController ( {
134+ let controller = NSTitlebarAccessoryViewController ( )
135+ let view = NSHostingView ( rootView: ChatTitleBar ( store: store. scope (
136+ state: \. chatPanelState,
137+ action: WidgetFeature . Action. chatPanel
138+ ) ) )
139+ controller. view = view
140+ view. frame = . init( x: 0 , y: 0 , width: 100 , height: 40 )
141+ controller. layoutAttribute = . left
142+ return controller
143+ } ( ) )
129144 it. isReleasedWhenClosed = false
130145 it. isOpaque = false
131146 it. backgroundColor = . clear
132147 it. level = . init( NSWindow . Level. floating. rawValue + 1 )
133- it. collectionBehavior = [ . fullScreenAuxiliary, . transient]
148+ it. collectionBehavior = [
149+ . fullScreenAuxiliary,
150+ . transient,
151+ . fullScreenPrimary,
152+ . fullScreenAllowsTiling,
153+ if #available( macOS 13 , * ) { [ . primary] } ,
154+ ]
134155 it. hasShadow = true
135156 it. contentView = NSHostingView (
136157 rootView: ChatWindowView (
137158 store: store. scope (
138159 state: \. chatPanelState,
139160 action: WidgetFeature . Action. chatPanel
140- )
161+ ) ,
162+ toggleVisibility: { [ weak it] isDisplayed in
163+ guard let window = it else { return }
164+ window. isPanelDisplayed = isDisplayed
165+ }
141166 )
142167 . environment ( \. chatTabPool, chatTabPool)
143168 )
144169 it. setIsVisible ( true )
170+ it. isPanelDisplayed = false
145171 it. delegate = self
146172 return it
147173 } ( )
@@ -249,31 +275,6 @@ extension SuggestionWidgetController: NSWindowDelegate {
249275 store. send ( . chatPanel( . detachChatPanel) )
250276 }
251277 }
252-
253- public func windowDidBecomeKey( _ notification: Notification ) {
254- guard ( notification. object as? NSWindow ) === chatPanelWindow else { return }
255- let screenFrame = NSScreen . screens. first ( where: { $0. frame. origin == . zero } ) ?
256- . frame ?? . zero
257- var mouseLocation = NSEvent . mouseLocation
258- let windowFrame = chatPanelWindow. frame
259- if mouseLocation. y > windowFrame. maxY - Style. chatWindowTitleBarHeight,
260- mouseLocation. y < windowFrame. maxY,
261- mouseLocation. x > windowFrame. minX,
262- mouseLocation. x < windowFrame. maxX
263- {
264- mouseLocation. y = screenFrame. size. height - mouseLocation. y
265- if let cgEvent = CGEvent (
266- mouseEventSource: nil ,
267- mouseType: . leftMouseDown,
268- mouseCursorPosition: mouseLocation,
269- mouseButton: . left
270- ) ,
271- let event = NSEvent ( cgEvent: cgEvent)
272- {
273- chatPanelWindow. performDrag ( with: event)
274- }
275- }
276- }
277278}
278279
279280// MARK: - Window Subclasses
@@ -288,16 +289,22 @@ class ChatWindow: NSWindow {
288289 override var canBecomeKey : Bool { true }
289290 override var canBecomeMain : Bool { true }
290291
291- override func mouseDown( with event: NSEvent ) {
292- let windowFrame = frame
293- let currentLocation = event. locationInWindow
294- if currentLocation. y > windowFrame. size. height - Style. chatWindowTitleBarHeight,
295- currentLocation. y < windowFrame. size. height,
296- currentLocation. x > 0 ,
297- currentLocation. x < windowFrame. width
298- {
299- performDrag ( with: event)
292+ var minimizeWindow : ( ) -> Void = { }
293+
294+ var isWindowHidden : Bool = false {
295+ didSet {
296+ alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
300297 }
301298 }
299+
300+ var isPanelDisplayed : Bool = false {
301+ didSet {
302+ alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
303+ }
304+ }
305+
306+ override func miniaturize( _: Any ? ) {
307+ minimizeWindow ( )
308+ }
302309}
303310
0 commit comments