mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
Fix HapticFeedback for new MacBook models
This commit is contained in:
parent
82ec231700
commit
68dfcddb29
@ -10,8 +10,24 @@ import IOKit
|
|||||||
|
|
||||||
class HapticFeedback {
|
class HapticFeedback {
|
||||||
private var actuatorRef: CFTypeRef?
|
private var actuatorRef: CFTypeRef?
|
||||||
private var deviceID: UInt64 = 0x200_0000_0100_0000
|
|
||||||
private var error: IOReturn = 0
|
// Here we have list of possible IDs for Haptic Generator Device. They are not constant
|
||||||
|
// To find deviceID, you will need IORegistryExplorer app from Additional Tools for Xcode dmg
|
||||||
|
// which you can download from https://developer.apple.com/download/more/?=Additional%20Tools
|
||||||
|
// Open IORegistryExplorer app, search for AppleMultitouchDevice and get "Multitouch ID"
|
||||||
|
// There should be programmatic way to get it but I can't find, no docs for macOS :(
|
||||||
|
private var possibleDeviceIDs: [UInt64] = [
|
||||||
|
0x200_0000_0100_0000, // MacBook Pro 2016/2017
|
||||||
|
0x300000080500000 // MacBook Pro 2019 (possibly 2018 as well)
|
||||||
|
]
|
||||||
|
|
||||||
|
init() {
|
||||||
|
// Let's find and init Haptic device
|
||||||
|
possibleDeviceIDs.forEach {(deviceID) in
|
||||||
|
guard actuatorRef == nil else {return}
|
||||||
|
actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't know how to do strong is enum one of
|
// Don't know how to do strong is enum one of
|
||||||
// 1 like back Click
|
// 1 like back Click
|
||||||
@ -25,31 +41,29 @@ class HapticFeedback {
|
|||||||
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
|
// you can get a plist `otool -s __TEXT __tpad_act_plist /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/Current/MultitouchSupport|tail -n +3|awk -F'\t' '{print $2}'|xxd -r -p`
|
||||||
|
|
||||||
func tap(strong: Int32) {
|
func tap(strong: Int32) {
|
||||||
actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
|
||||||
|
|
||||||
guard actuatorRef != nil else {
|
guard actuatorRef != nil else {
|
||||||
print("guard actuatorRef == nil")
|
print("guard actuatorRef == nil (can't find proper haptic device?)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorOpen(actuatorRef!)
|
var result: IOReturn
|
||||||
guard error == kIOReturnSuccess else {
|
|
||||||
|
result = MTActuatorOpen(actuatorRef!)
|
||||||
|
guard result == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorOpen")
|
print("guard MTActuatorOpen")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorActuate(actuatorRef!, strong, 0, 0.0, 0.0)
|
result = MTActuatorActuate(actuatorRef!, strong, 0, 0.0, 0.0)
|
||||||
guard error == kIOReturnSuccess else {
|
guard result == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorActuate")
|
print("guard MTActuatorActuate")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
error = MTActuatorClose(actuatorRef!)
|
result = MTActuatorClose(actuatorRef!)
|
||||||
guard error == kIOReturnSuccess else {
|
guard result == kIOReturnSuccess else {
|
||||||
print("guard MTActuatorClose")
|
print("guard MTActuatorClose")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user