diff --git a/src/api-wrappers/CGWindowID.swift b/src/api-wrappers/CGWindowID.swift index e7a94fb9..d8b39889 100644 --- a/src/api-wrappers/CGWindowID.swift +++ b/src/api-wrappers/CGWindowID.swift @@ -19,7 +19,7 @@ extension CGWindowID { // CGSHWCaptureWindowList var windowId_ = self let options: CGSWindowCaptureOptions = [.captureIgnoreGlobalClipShape, .windowCaptureNominalResolution] - let list = CGSHWCaptureWindowList(cgsMainConnectionId, &windowId_, 1, options) as! [CGImage] + let list = CGSHWCaptureWindowList(cgsMainConnectionId, &windowId_, 1, options).takeRetainedValue() as! [CGImage] return list.first // // CGWindowListCreateImage diff --git a/src/api-wrappers/PrivateApis.swift b/src/api-wrappers/PrivateApis.swift index bc7d131e..de4e26f7 100644 --- a/src/api-wrappers/PrivateApis.swift +++ b/src/api-wrappers/PrivateApis.swift @@ -36,7 +36,7 @@ func CGSMainConnectionID() -> CGSConnectionID // * offscreen content: no // * macOS 10.10+ @_silgen_name("CGSHWCaptureWindowList") -func CGSHWCaptureWindowList(_ cid: CGSConnectionID, _ windowList: inout CGWindowID, _ windowCount: UInt32, _ options: CGSWindowCaptureOptions) -> CFArray +func CGSHWCaptureWindowList(_ cid: CGSConnectionID, _ windowList: inout CGWindowID, _ windowCount: UInt32, _ options: CGSWindowCaptureOptions) -> Unmanaged // returns the connection ID for the provided window // * macOS 10.10+ diff --git a/src/logic/events/KeyboardEvents.swift b/src/logic/events/KeyboardEvents.swift index 294cc069..fa830b21 100644 --- a/src/logic/events/KeyboardEvents.swift +++ b/src/logic/events/KeyboardEvents.swift @@ -21,7 +21,6 @@ private func observe_() { callback: keyboardHandler, userInfo: nil) let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0) - CGEvent.tapEnable(tap: eventTap!, enable: true) CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes) CFRunLoopRun() } diff --git a/src/ui/main-window/ThumbnailTitleView.swift b/src/ui/main-window/ThumbnailTitleView.swift index 4affc0e1..5e306f08 100644 --- a/src/ui/main-window/ThumbnailTitleView.swift +++ b/src/ui/main-window/ThumbnailTitleView.swift @@ -12,6 +12,7 @@ class ThumbnailTitleView: BaseLabel { textContainer.lineFragmentPadding = 0 layoutManager.addTextContainer(textContainer) self.init(NSRect.zero, textContainer) + font = Preferences.font self.magicOffset = magicOffset textColor = Preferences.fontColor shadow = ThumbnailView.makeShadow(.darkGray) diff --git a/src/ui/main-window/ThumbnailView.swift b/src/ui/main-window/ThumbnailView.swift index db8b480d..0d469f02 100644 --- a/src/ui/main-window/ThumbnailView.swift +++ b/src/ui/main-window/ThumbnailView.swift @@ -8,8 +8,8 @@ class ThumbnailView: NSStackView { var minimizedIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledMinusSign, Preferences.fontIconSize, .white) var hiddenIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledDotSign, Preferences.fontIconSize, .white) var spaceIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledNumber0, Preferences.fontIconSize, .white) - var mouseDownCallback: MouseDownCallback! - var mouseMovedCallback: MouseMovedCallback! + var mouseDownCallback: (() -> Void)! + var mouseMovedCallback: (() -> Void)! var dragAndDropTimer: Timer? convenience init() { @@ -22,7 +22,7 @@ class ThumbnailView: NSStackView { observeDragAndDrop() } - func updateRecycledCellWithNewContent(_ element: Window, _ mouseDownCallback: @escaping MouseDownCallback, _ mouseMovedCallback: @escaping MouseMovedCallback, _ newHeight: CGFloat, _ screen: NSScreen) { + func updateRecycledCellWithNewContent(_ element: Window, _ index: Int, _ newHeight: CGFloat, _ screen: NSScreen) { window_ = element if thumbnail.image != element.thumbnail { thumbnail.image = element.thumbnail @@ -40,11 +40,9 @@ class ThumbnailView: NSStackView { let labelChanged = label.string != element.title if labelChanged { label.string = element.title - // workaround: setting string on NSTextView change the font (most likely a Cocoa bug) - label.font = Preferences.font } - assignIfDifferent(&hiddenIcon.isHidden, !window_!.isHidden) - assignIfDifferent(&minimizedIcon.isHidden, !window_!.isMinimized) + assignIfDifferent(&hiddenIcon.isHidden, !element.isHidden) + assignIfDifferent(&minimizedIcon.isHidden, !element.isMinimized) assignIfDifferent(&spaceIcon.isHidden, element.spaceIndex == nil || Spaces.isSingleSpace || Preferences.hideSpaceNumberLabels) if !spaceIcon.isHidden { if element.isOnAllSpaces { @@ -58,8 +56,8 @@ class ThumbnailView: NSStackView { let fontIconWidth = CGFloat([minimizedIcon, hiddenIcon, spaceIcon].filter { !$0.isHidden }.count) * (Preferences.fontIconSize + Preferences.intraCellPadding) assignIfDifferent(&label.textContainer!.size.width, frame.width - Preferences.iconSize - Preferences.intraCellPadding * 3 - fontIconWidth) assignIfDifferent(&subviews.first!.frame.size, frame.size) - self.mouseDownCallback = mouseDownCallback - self.mouseMovedCallback = mouseMovedCallback + self.mouseDownCallback = { () -> Void in App.app.focusSelectedWindow(element) } + self.mouseMovedCallback = { () -> Void in Windows.updateFocusedWindowIndex(index) } if trackingAreas.count == 0 { addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseMoved, .activeAlways], owner: self, userInfo: nil)) } else if trackingAreas.count > 0 && trackingAreas[0].rect != bounds { @@ -73,6 +71,27 @@ class ThumbnailView: NSStackView { } } + private func test5(index: Int) { + self.mouseMovedCallback = { () -> Void in Windows.updateFocusedWindowIndex(index) } + } + + private func test4(element: Window) { + self.mouseDownCallback = { () -> Void in App.app.focusSelectedWindow(element) } + } + + private func test3() { + assignIfDifferent(&subviews.first!.frame.size, frame.size) + } + + private func test2(fontIconWidth: CGFloat) { + assignIfDifferent(&label.textContainer!.size.width, frame.width - Preferences.iconSize - Preferences.intraCellPadding * 3 - fontIconWidth) + } + + private func test1() -> CGFloat { + let fontIconWidth = CGFloat([minimizedIcon, hiddenIcon, spaceIcon].filter { !$0.isHidden }.count) * (Preferences.fontIconSize + Preferences.intraCellPadding) + return fontIconWidth + } + private func observeDragAndDrop() { // NSImageView instances are registered to drag-and-drop by default thumbnail.unregisterDraggedTypes() @@ -174,5 +193,3 @@ class ThumbnailView: NSStackView { } } -typealias MouseDownCallback = () -> Void -typealias MouseMovedCallback = () -> Void diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index 260f8f09..4a9c0e7e 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -51,10 +51,7 @@ class ThumbnailsView: NSVisualEffectView { guard App.app.appIsBeingUsed else { return } guard window.shouldShowTheUser else { continue } let view = ThumbnailsView.recycledViews[index] - view.updateRecycledCellWithNewContent(window, - { () -> Void in App.app.focusSelectedWindow(window) }, - { () -> Void in Windows.updateFocusedWindowIndex(index) }, - height, screen) + view.updateRecycledCellWithNewContent(window, index, height, screen) let width = view.frame.size.width if (currentX + width).rounded(.down) > widthMax { currentX = CGFloat(0) diff --git a/src/ui/preferences-window/tabs/GeneralTab.swift b/src/ui/preferences-window/tabs/GeneralTab.swift index 2a2ee673..eb2cfeaf 100644 --- a/src/ui/preferences-window/tabs/GeneralTab.swift +++ b/src/ui/preferences-window/tabs/GeneralTab.swift @@ -146,7 +146,7 @@ class GeneralTab: NSViewController, PreferencePane { } } if (sender as! NSButton).state == .on { - LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, nil, itemUrl, nil, nil) + let _ = LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, nil, itemUrl, nil, nil).takeRetainedValue() } } } \ No newline at end of file