Skip to content

Commit 2c04b70

Browse files
committed
Bind overlay windows to window IDs
1 parent 06ecb6e commit 2c04b70

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

OverlayWindow/Sources/OverlayWindow/OverlayWindowController.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public final class OverlayWindowController {
1414
static var ideWindowOverlayWindowControllerContentProviderFactories:
1515
[IDEWorkspaceWindowOverlayWindowControllerContentProviderFactory] = []
1616

17-
var ideWindowOverlayWindowControllers: [URL: IDEWorkspaceWindowOverlayWindowController] = [:]
17+
var ideWindowOverlayWindowControllers =
18+
[CGWindowID: IDEWorkspaceWindowOverlayWindowController]()
1819
var updateWindowStateTask: Task<Void, Error>?
1920

2021
lazy var fullscreenDetector = {
@@ -79,9 +80,8 @@ private extension OverlayWindowController {
7980
let windowInspector = XcodeInspector.shared
8081
.focusedWindow as? WorkspaceXcodeWindowInspector
8182
{
82-
let workspaceURL = windowInspector.workspaceURL
8383
createNewIDEOverlayWindowController(
84-
for: workspaceURL,
84+
for: windowInspector.windowID,
8585
inspector: windowInspector,
8686
application: app.runningApplication
8787
)
@@ -98,17 +98,17 @@ private extension OverlayWindowController {
9898
defer { self.observeWindowChange() }
9999

100100
guard XcodeInspector.shared.activeApplication?.isXcode ?? false else {
101-
var closedControllers: [URL] = []
102-
for (url, controller) in self.ideWindowOverlayWindowControllers {
101+
var closedControllers: [CGWindowID] = []
102+
for (id, controller) in self.ideWindowOverlayWindowControllers {
103103
if controller.isWindowClosed {
104104
controller.dim()
105-
closedControllers.append(url)
105+
closedControllers.append(id)
106106
} else {
107107
controller.dim()
108108
}
109109
}
110-
for url in closedControllers {
111-
self.removeIDEOverlayWindowController(for: url)
110+
for id in closedControllers {
111+
self.removeIDEOverlayWindowController(for: id)
112112
}
113113
return
114114
}
@@ -122,19 +122,19 @@ private extension OverlayWindowController {
122122

123123
let windowInspector = XcodeInspector.shared.focusedWindow
124124
if let ideWindowInspector = windowInspector as? WorkspaceXcodeWindowInspector {
125-
let workspaceURL = ideWindowInspector.workspaceURL
125+
let windowID = ideWindowInspector.windowID
126126
// Workspace window is active
127127
// Hide all controllers first
128-
for (url, controller) in self.ideWindowOverlayWindowControllers {
129-
if url != workspaceURL {
128+
for (id, controller) in self.ideWindowOverlayWindowControllers {
129+
if id != windowID {
130130
controller.hide()
131131
}
132132
}
133-
if let controller = self.ideWindowOverlayWindowControllers[workspaceURL] {
133+
if let controller = self.ideWindowOverlayWindowControllers[windowID] {
134134
controller.access()
135135
} else {
136136
self.createNewIDEOverlayWindowController(
137-
for: workspaceURL,
137+
for: windowID,
138138
inspector: ideWindowInspector,
139139
application: app.runningApplication
140140
)
@@ -150,7 +150,7 @@ private extension OverlayWindowController {
150150
}
151151

152152
func createNewIDEOverlayWindowController(
153-
for workspaceURL: URL,
153+
for windowID: CGWindowID,
154154
inspector: WorkspaceXcodeWindowInspector,
155155
application: NSRunningApplication
156156
) {
@@ -164,21 +164,21 @@ private extension OverlayWindowController {
164164
}
165165
)
166166
newController.access()
167-
ideWindowOverlayWindowControllers[workspaceURL] = newController
167+
ideWindowOverlayWindowControllers[windowID] = newController
168168
}
169-
170-
func removeIDEOverlayWindowController(for workspaceURL: URL) {
171-
if let controller = ideWindowOverlayWindowControllers[workspaceURL] {
169+
170+
func removeIDEOverlayWindowController(for id: CGWindowID) {
171+
if let controller = ideWindowOverlayWindowControllers[id] {
172172
controller.destroy()
173173
}
174-
ideWindowOverlayWindowControllers[workspaceURL] = nil
174+
ideWindowOverlayWindowControllers[id] = nil
175175
}
176176

177177
func handleSpaceChange() async {
178178
let windowInspector = XcodeInspector.shared.focusedWindow
179179
guard let activeWindowController = {
180180
if let windowInspector = windowInspector as? WorkspaceXcodeWindowInspector {
181-
return ideWindowOverlayWindowControllers[windowInspector.workspaceURL]
181+
return ideWindowOverlayWindowControllers[windowInspector.windowID]
182182
} else {
183183
return nil
184184
}

0 commit comments

Comments
 (0)