@@ -122,26 +122,40 @@ 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+ }
129132 it. isReleasedWhenClosed = false
130133 it. isOpaque = false
131134 it. backgroundColor = . clear
132135 it. level = . init( NSWindow . Level. floating. rawValue + 1 )
133- it. collectionBehavior = [ . fullScreenAuxiliary, . transient]
136+ it. collectionBehavior = [
137+ . fullScreenAuxiliary,
138+ . transient,
139+ . fullScreenPrimary,
140+ . fullScreenAllowsTiling,
141+ if #available( macOS 13 , * ) { [ . primary] }
142+ ]
134143 it. hasShadow = true
135144 it. contentView = NSHostingView (
136145 rootView: ChatWindowView (
137146 store: store. scope (
138147 state: \. chatPanelState,
139148 action: WidgetFeature . Action. chatPanel
140- )
149+ ) ,
150+ toggleVisibility: { [ weak it] isDisplayed in
151+ guard let window = it else { return }
152+ window. isPanelDisplayed = isDisplayed
153+ }
141154 )
142155 . environment ( \. chatTabPool, chatTabPool)
143156 )
144157 it. setIsVisible ( true )
158+ it. isPanelDisplayed = false
145159 it. delegate = self
146160 return it
147161 } ( )
@@ -249,31 +263,6 @@ extension SuggestionWidgetController: NSWindowDelegate {
249263 store. send ( . chatPanel( . detachChatPanel) )
250264 }
251265 }
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- }
277266}
278267
279268// MARK: - Window Subclasses
@@ -287,17 +276,22 @@ class CanBecomeKeyWindow: NSWindow {
287276class ChatWindow : NSWindow {
288277 override var canBecomeKey : Bool { true }
289278 override var canBecomeMain : Bool { true }
290-
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)
279+
280+ var minimizeWindow : ( ) -> Void = { }
281+
282+ var isWindowHidden : Bool = false {
283+ didSet {
284+ alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
300285 }
301286 }
287+ var isPanelDisplayed : Bool = false {
288+ didSet {
289+ alphaValue = isPanelDisplayed && !isWindowHidden ? 1 : 0
290+ }
291+ }
292+
293+ override func miniaturize( _ sender: Any ? ) {
294+ minimizeWindow ( )
295+ }
302296}
303297
0 commit comments