fix: plug some minor memory leaks
This commit is contained in:
1 parent
5a4f206bb4
commit
0de7a5515c
7 files changed
+33
-19
No files matched your search
@@ -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
|
||||
|
||||
@@ -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<CFArray>
|
||||
|
||||
// returns the connection ID for the provided window
|
||||
// * macOS 10.10+
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user