diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index f9c5084..f62ed9f 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -76,7 +76,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } else { TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier) } - + AppSettings.blacklistedAppIds = TouchBarController.shared.blacklistAppIdentifiers TouchBarController.shared.updateActiveApp() updateIsBlockedApp() @@ -132,7 +132,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let hapticFeedback = NSMenuItem(title: "Haptic Feedback", action: #selector(toggleHapticFeedback(_:)), keyEquivalent: "H") hapticFeedback.state = AppSettings.hapticFeedbackState ? .on : .off - let multitouchGestures = NSMenuItem(title: "Volume/Brightness gestures", action: #selector(toggleMultitouch(_:)), keyEquivalent: "") + let multitouchGestures = NSMenuItem(title: "Default Swipe Gestures", action: #selector(toggleMultitouch(_:)), keyEquivalent: "") multitouchGestures.state = AppSettings.multitouchGestures ? .on : .off let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "") diff --git a/MTMR/BasicView.swift b/MTMR/BasicView.swift index ce30af8..5d388cb 100644 --- a/MTMR/BasicView.swift +++ b/MTMR/BasicView.swift @@ -10,6 +10,7 @@ import Foundation class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate { + var onefinger: NSPanGestureRecognizer! var twofingers: NSPanGestureRecognizer! var threefingers: NSPanGestureRecognizer! var fourfingers: NSPanGestureRecognizer! @@ -30,6 +31,11 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate { stackView.orientation = .horizontal view = stackView + onefinger = NSPanGestureRecognizer(target: self, action: #selector(onefingerHandler(_:))) + onefinger.numberOfTouchesRequired = 1 + onefinger.allowedTouchTypes = .direct + view.addGestureRecognizer(onefinger) + twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:))) twofingers.numberOfTouchesRequired = 2 twofingers.allowedTouchTypes = .direct @@ -57,9 +63,31 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate { legacyPrevPositions[fingers] = position case .changed: if self.legacyGesturesEnabled { + if fingers == 1 { + let prevPos = legacyPrevPositions[fingers]! + if ((position - prevPos) > 3) || ((prevPos - position) > 3) { + if position > prevPos { + GenericKeyPress(keyCode: CGKeyCode(124)).send() + } else if position < prevPos { + GenericKeyPress(keyCode: CGKeyCode(123)).send() + } + legacyPrevPositions[fingers] = position + } + } if fingers == 2 { let prevPos = legacyPrevPositions[fingers]! - if ((position - prevPos) > 10) || ((prevPos - position) > 10) { + if ((position - prevPos) > 50) || ((prevPos - position) > 50) { + if position > prevPos { + GenericKeyPress(keyCode: CGKeyCode(124)).send() + } else if position < prevPos { + GenericKeyPress(keyCode: CGKeyCode(123)).send() + } + legacyPrevPositions[fingers] = position + } + } + if fingers == 3 { + let prevPos = legacyPrevPositions[fingers]! + if ((position - prevPos) > 15) || ((prevPos - position) > 15) { if position > prevPos { HIDPostAuxKey(NX_KEYTYPE_SOUND_UP) } else if position < prevPos { @@ -68,7 +96,7 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate { legacyPrevPositions[fingers] = position } } - if fingers == 3 { + if fingers == 4 { let prevPos = legacyPrevPositions[fingers]! if ((position - prevPos) > 15) || ((prevPos - position) > 15) { if position > prevPos { @@ -90,6 +118,11 @@ class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate { } } + @objc func onefingerHandler(_ sender: NSGestureRecognizer?) { + let position = (sender?.location(in: sender?.view).x)! + self.gestureHandler(position: position, fingers: 1, state: sender!.state) + } + @objc func twofingersHandler(_ sender: NSGestureRecognizer?) { let position = (sender?.location(in: sender?.view).x)! self.gestureHandler(position: position, fingers: 2, state: sender!.state) diff --git a/MTMR/Info.plist b/MTMR/Info.plist index 8ee6ef2..ae0a326 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.25 CFBundleVersion - 385 + 402 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/README.md b/README.md index 1e51a50..f69f6f7 100644 --- a/README.md +++ b/README.md @@ -104,11 +104,16 @@ The pre-installed configuration contains less or more than you'll probably want, ## Gestures -By default you can enable basic gestures from application menu (status bar -> MTMR icon -> Volume/Brightness gestures): -- two finger slide: change you Volume -- three finger slide: change you Brightness +### Default Gestures -### Custom gestures +By default you can enable basic gestures from application menu (status bar -> MTMR icon -> Default Swipe Gestures): + +- ```one finger slide```: Move Caret +- ```two finger slide```: Move Caret with precision +- ```three finger slide```: Increase/Decrease Volume +- ```four finger slide```: Increase/Decrease Brightness + +### Custom Gestures You can add custom actions for two/three/four finger swipes. To do it, you need to use `swipe` type: