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
|
// CGSHWCaptureWindowList
|
||||||
var windowId_ = self
|
var windowId_ = self
|
||||||
let options: CGSWindowCaptureOptions = [.captureIgnoreGlobalClipShape, .windowCaptureNominalResolution]
|
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
|
return list.first
|
||||||
|
|
||||||
// // CGWindowListCreateImage
|
// // CGWindowListCreateImage
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func CGSMainConnectionID() -> CGSConnectionID
|
|||||||
// * offscreen content: no
|
// * offscreen content: no
|
||||||
// * macOS 10.10+
|
// * macOS 10.10+
|
||||||
@_silgen_name("CGSHWCaptureWindowList")
|
@_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
|
// returns the connection ID for the provided window
|
||||||
// * macOS 10.10+
|
// * macOS 10.10+
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ private func observe_() {
|
|||||||
callback: keyboardHandler,
|
callback: keyboardHandler,
|
||||||
userInfo: nil)
|
userInfo: nil)
|
||||||
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
|
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
|
||||||
CGEvent.tapEnable(tap: eventTap!, enable: true)
|
|
||||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
|
||||||
CFRunLoopRun()
|
CFRunLoopRun()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class ThumbnailTitleView: BaseLabel {
|
|||||||
textContainer.lineFragmentPadding = 0
|
textContainer.lineFragmentPadding = 0
|
||||||
layoutManager.addTextContainer(textContainer)
|
layoutManager.addTextContainer(textContainer)
|
||||||
self.init(NSRect.zero, textContainer)
|
self.init(NSRect.zero, textContainer)
|
||||||
|
font = Preferences.font
|
||||||
self.magicOffset = magicOffset
|
self.magicOffset = magicOffset
|
||||||
textColor = Preferences.fontColor
|
textColor = Preferences.fontColor
|
||||||
shadow = ThumbnailView.makeShadow(.darkGray)
|
shadow = ThumbnailView.makeShadow(.darkGray)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class ThumbnailView: NSStackView {
|
|||||||
var minimizedIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledMinusSign, Preferences.fontIconSize, .white)
|
var minimizedIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledMinusSign, Preferences.fontIconSize, .white)
|
||||||
var hiddenIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledDotSign, Preferences.fontIconSize, .white)
|
var hiddenIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledDotSign, Preferences.fontIconSize, .white)
|
||||||
var spaceIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledNumber0, Preferences.fontIconSize, .white)
|
var spaceIcon = ThumbnailFontIconView(ThumbnailFontIconView.sfSymbolCircledNumber0, Preferences.fontIconSize, .white)
|
||||||
var mouseDownCallback: MouseDownCallback!
|
var mouseDownCallback: (() -> Void)!
|
||||||
var mouseMovedCallback: MouseMovedCallback!
|
var mouseMovedCallback: (() -> Void)!
|
||||||
var dragAndDropTimer: Timer?
|
var dragAndDropTimer: Timer?
|
||||||
|
|
||||||
convenience init() {
|
convenience init() {
|
||||||
@@ -22,7 +22,7 @@ class ThumbnailView: NSStackView {
|
|||||||
observeDragAndDrop()
|
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
|
window_ = element
|
||||||
if thumbnail.image != element.thumbnail {
|
if thumbnail.image != element.thumbnail {
|
||||||
thumbnail.image = element.thumbnail
|
thumbnail.image = element.thumbnail
|
||||||
@@ -40,11 +40,9 @@ class ThumbnailView: NSStackView {
|
|||||||
let labelChanged = label.string != element.title
|
let labelChanged = label.string != element.title
|
||||||
if labelChanged {
|
if labelChanged {
|
||||||
label.string = element.title
|
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(&hiddenIcon.isHidden, !element.isHidden)
|
||||||
assignIfDifferent(&minimizedIcon.isHidden, !window_!.isMinimized)
|
assignIfDifferent(&minimizedIcon.isHidden, !element.isMinimized)
|
||||||
assignIfDifferent(&spaceIcon.isHidden, element.spaceIndex == nil || Spaces.isSingleSpace || Preferences.hideSpaceNumberLabels)
|
assignIfDifferent(&spaceIcon.isHidden, element.spaceIndex == nil || Spaces.isSingleSpace || Preferences.hideSpaceNumberLabels)
|
||||||
if !spaceIcon.isHidden {
|
if !spaceIcon.isHidden {
|
||||||
if element.isOnAllSpaces {
|
if element.isOnAllSpaces {
|
||||||
@@ -58,8 +56,8 @@ class ThumbnailView: NSStackView {
|
|||||||
let fontIconWidth = CGFloat([minimizedIcon, hiddenIcon, spaceIcon].filter { !$0.isHidden }.count) * (Preferences.fontIconSize + Preferences.intraCellPadding)
|
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(&label.textContainer!.size.width, frame.width - Preferences.iconSize - Preferences.intraCellPadding * 3 - fontIconWidth)
|
||||||
assignIfDifferent(&subviews.first!.frame.size, frame.size)
|
assignIfDifferent(&subviews.first!.frame.size, frame.size)
|
||||||
self.mouseDownCallback = mouseDownCallback
|
self.mouseDownCallback = { () -> Void in App.app.focusSelectedWindow(element) }
|
||||||
self.mouseMovedCallback = mouseMovedCallback
|
self.mouseMovedCallback = { () -> Void in Windows.updateFocusedWindowIndex(index) }
|
||||||
if trackingAreas.count == 0 {
|
if trackingAreas.count == 0 {
|
||||||
addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseMoved, .activeAlways], owner: self, userInfo: nil))
|
addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseMoved, .activeAlways], owner: self, userInfo: nil))
|
||||||
} else if trackingAreas.count > 0 && trackingAreas[0].rect != bounds {
|
} 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() {
|
private func observeDragAndDrop() {
|
||||||
// NSImageView instances are registered to drag-and-drop by default
|
// NSImageView instances are registered to drag-and-drop by default
|
||||||
thumbnail.unregisterDraggedTypes()
|
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 App.app.appIsBeingUsed else { return }
|
||||||
guard window.shouldShowTheUser else { continue }
|
guard window.shouldShowTheUser else { continue }
|
||||||
let view = ThumbnailsView.recycledViews[index]
|
let view = ThumbnailsView.recycledViews[index]
|
||||||
view.updateRecycledCellWithNewContent(window,
|
view.updateRecycledCellWithNewContent(window, index, height, screen)
|
||||||
{ () -> Void in App.app.focusSelectedWindow(window) },
|
|
||||||
{ () -> Void in Windows.updateFocusedWindowIndex(index) },
|
|
||||||
height, screen)
|
|
||||||
let width = view.frame.size.width
|
let width = view.frame.size.width
|
||||||
if (currentX + width).rounded(.down) > widthMax {
|
if (currentX + width).rounded(.down) > widthMax {
|
||||||
currentX = CGFloat(0)
|
currentX = CGFloat(0)
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ class GeneralTab: NSViewController, PreferencePane {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sender as! NSButton).state == .on {
|
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