Skip to content

Commit

Permalink
get long tap to kill back into place
Browse files Browse the repository at this point in the history
  • Loading branch information
ReDetection committed Oct 27, 2019
1 parent dd23a3b commit e9a7b6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MTMR/CustomButtonTouchBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class HapticClickGestureRecognizer: NSClickGestureRecognizer {
}

class LongPressGestureRecognizer: NSPressGestureRecognizer {
private let recognizeTimeout = 0.4
var recognizeTimeout = 0.4
private var timer: Timer?

override func touchesBegan(with event: NSEvent) {
Expand Down
17 changes: 17 additions & 0 deletions MTMR/Widgets/AppScrubberTouchBarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem {
item.longTapClosure = { [weak self] in
self?.handleHalfLongPress(item: app)
}
item.killAppClosure = {[weak self] in
self?.handleLongPress(item: app)
}

return item
}
Expand Down Expand Up @@ -117,6 +120,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem {
private func handleHalfLongPress(item: DockItem) {
if let index = self.persistentAppIdentifiers.firstIndex(of: item.bundleIdentifier) {
persistentAppIdentifiers.remove(at: index)
hardReloadItems()
} else {
persistentAppIdentifiers.append(item.bundleIdentifier)
}
Expand Down Expand Up @@ -181,6 +185,8 @@ private let iconWidth = 32.0
class DockBarItem: CustomButtonTouchBarItem {
let dotView = NSView(frame: .zero)
let dockItem: DockItem
fileprivate var killGestureRecognizer: LongPressGestureRecognizer!
var killAppClosure: () -> Void = { }

var isRunning = false {
didSet {
Expand All @@ -203,11 +209,18 @@ class DockBarItem: CustomButtonTouchBarItem {
image = app.icon
image?.size = NSSize(width: iconWidth, height: iconWidth)

killGestureRecognizer = LongPressGestureRecognizer(target: self, action: #selector(firePanGestureRecognizer))
killGestureRecognizer.allowedTouchTypes = .direct
killGestureRecognizer.recognizeTimeout = 1.5
killGestureRecognizer.minimumPressDuration = 1.5
killGestureRecognizer.isEnabled = isRunning

self.finishViewConfiguration = { [weak self] in
guard let selfie = self else { return }
selfie.dotView.layer?.cornerRadius = 1.5
selfie.view.addSubview(selfie.dotView)
selfie.redrawDotView()
selfie.view.addGestureRecognizer(selfie.killGestureRecognizer)
}
}

Expand All @@ -217,6 +230,10 @@ class DockBarItem: CustomButtonTouchBarItem {
dotView.setFrameOrigin(NSPoint(x: 18.0 - Double(dotView.frame.size.width) / 2.0, y: iconWidth - 5))
}

@objc func firePanGestureRecognizer() {
self.killAppClosure()
}

required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down

0 comments on commit e9a7b6d

Please sign in to comment.