Skip to content

Commit

Permalink
More Productive Gestures (Toxblh#289)
Browse files Browse the repository at this point in the history
* Scroll Functionality Works

* updated md

* Update README.md

* Update README.md

* attempted to fix readme

* fixed readme

* fixed readme
  • Loading branch information
jazzhpatel authored and tomeresk committed Jul 16, 2021
1 parent a1369d9 commit 9322227
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MTMR/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} else {
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier)
}

AppSettings.blacklistedAppIds = TouchBarController.shared.blacklistAppIdentifiers
TouchBarController.shared.updateActiveApp()
updateIsBlockedApp()
Expand Down Expand Up @@ -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: "")
Expand Down
37 changes: 35 additions & 2 deletions MTMR/BasicView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation


class BasicView: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
var onefinger: NSPanGestureRecognizer!
var twofingers: NSPanGestureRecognizer!
var threefingers: NSPanGestureRecognizer!
var fourfingers: NSPanGestureRecognizer!
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion MTMR/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>0.25</string>
<key>CFBundleVersion</key>
<string>385</string>
<string>402</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 9322227

Please sign in to comment.