mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
get long tap to kill back into place
This commit is contained in:
parent
dd23a3bda8
commit
e9a7b6d32a
@ -189,7 +189,7 @@ class HapticClickGestureRecognizer: NSClickGestureRecognizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class LongPressGestureRecognizer: NSPressGestureRecognizer {
|
class LongPressGestureRecognizer: NSPressGestureRecognizer {
|
||||||
private let recognizeTimeout = 0.4
|
var recognizeTimeout = 0.4
|
||||||
private var timer: Timer?
|
private var timer: Timer?
|
||||||
|
|
||||||
override func touchesBegan(with event: NSEvent) {
|
override func touchesBegan(with event: NSEvent) {
|
||||||
|
|||||||
@ -86,6 +86,9 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem {
|
|||||||
item.longTapClosure = { [weak self] in
|
item.longTapClosure = { [weak self] in
|
||||||
self?.handleHalfLongPress(item: app)
|
self?.handleHalfLongPress(item: app)
|
||||||
}
|
}
|
||||||
|
item.killAppClosure = {[weak self] in
|
||||||
|
self?.handleLongPress(item: app)
|
||||||
|
}
|
||||||
|
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
@ -117,6 +120,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem {
|
|||||||
private func handleHalfLongPress(item: DockItem) {
|
private func handleHalfLongPress(item: DockItem) {
|
||||||
if let index = self.persistentAppIdentifiers.firstIndex(of: item.bundleIdentifier) {
|
if let index = self.persistentAppIdentifiers.firstIndex(of: item.bundleIdentifier) {
|
||||||
persistentAppIdentifiers.remove(at: index)
|
persistentAppIdentifiers.remove(at: index)
|
||||||
|
hardReloadItems()
|
||||||
} else {
|
} else {
|
||||||
persistentAppIdentifiers.append(item.bundleIdentifier)
|
persistentAppIdentifiers.append(item.bundleIdentifier)
|
||||||
}
|
}
|
||||||
@ -181,6 +185,8 @@ private let iconWidth = 32.0
|
|||||||
class DockBarItem: CustomButtonTouchBarItem {
|
class DockBarItem: CustomButtonTouchBarItem {
|
||||||
let dotView = NSView(frame: .zero)
|
let dotView = NSView(frame: .zero)
|
||||||
let dockItem: DockItem
|
let dockItem: DockItem
|
||||||
|
fileprivate var killGestureRecognizer: LongPressGestureRecognizer!
|
||||||
|
var killAppClosure: () -> Void = { }
|
||||||
|
|
||||||
var isRunning = false {
|
var isRunning = false {
|
||||||
didSet {
|
didSet {
|
||||||
@ -203,11 +209,18 @@ class DockBarItem: CustomButtonTouchBarItem {
|
|||||||
image = app.icon
|
image = app.icon
|
||||||
image?.size = NSSize(width: iconWidth, height: iconWidth)
|
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
|
self.finishViewConfiguration = { [weak self] in
|
||||||
guard let selfie = self else { return }
|
guard let selfie = self else { return }
|
||||||
selfie.dotView.layer?.cornerRadius = 1.5
|
selfie.dotView.layer?.cornerRadius = 1.5
|
||||||
selfie.view.addSubview(selfie.dotView)
|
selfie.view.addSubview(selfie.dotView)
|
||||||
selfie.redrawDotView()
|
selfie.redrawDotView()
|
||||||
|
selfie.view.addGestureRecognizer(selfie.killGestureRecognizer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,6 +230,10 @@ class DockBarItem: CustomButtonTouchBarItem {
|
|||||||
dotView.setFrameOrigin(NSPoint(x: 18.0 - Double(dotView.frame.size.width) / 2.0, y: iconWidth - 5))
|
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) {
|
required init?(coder _: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user