mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-10-31 10:28:36 +00:00
Added Haptic feddback on click all buttons
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// HapticFeedback.swift
|
||||
// MTMR
|
||||
//
|
||||
// Created by Anton Palgunov on 09/04/2018.
|
||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||
//
|
||||
|
||||
import IOKit
|
||||
|
||||
class HapticFeedback {
|
||||
private var actuatorRef: CFTypeRef?
|
||||
private var deviceID: UInt64 = 0x200000001000000
|
||||
private var error: IOReturn = 0
|
||||
|
||||
// Don't know how to do strong is enum one of
|
||||
// 1 like backClick
|
||||
// 2 (like Click)
|
||||
// 3 (week)
|
||||
// 4 (medium)
|
||||
// 5 (week medium)
|
||||
// 6 (strong)
|
||||
// 15 (nothing)
|
||||
// 16 (nothing)
|
||||
|
||||
func tap(strong:Int32) -> Void {
|
||||
let actuatorRef = MTActuatorCreateFromDeviceID(deviceID).takeRetainedValue()
|
||||
|
||||
// TODO: Need to fix warning
|
||||
guard actuatorRef != nil else {
|
||||
print("guard actuatorRef == nil")
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorOpen(actuatorRef)
|
||||
guard error == kIOReturnSuccess else {
|
||||
print("guard MTActuatorOpen")
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorActuate(actuatorRef, strong, 0, 0.0, 0.0)
|
||||
guard error == kIOReturnSuccess else {
|
||||
print("guard MTActuatorActuate")
|
||||
return
|
||||
}
|
||||
|
||||
error = MTActuatorClose(actuatorRef)
|
||||
guard error == kIOReturnSuccess else {
|
||||
print("guard MTActuatorClose")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,45 +11,47 @@ import Cocoa
|
||||
extension NSTouchBarItem.Identifier {
|
||||
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
|
||||
static let dismissButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.dismissButton")
|
||||
|
||||
|
||||
// Volume
|
||||
static let volumeUp = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeUp")
|
||||
static let volumeDown = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeDown")
|
||||
|
||||
|
||||
// Brightness
|
||||
static let brightUp = NSTouchBarItem.Identifier("com.toxblh.mtmr.brightUp")
|
||||
static let brightDown = NSTouchBarItem.Identifier("com.toxblh.mtmr.brightDown")
|
||||
|
||||
|
||||
// Music
|
||||
static let prev = NSTouchBarItem.Identifier("com.toxblh.mtmr.prev")
|
||||
static let next = NSTouchBarItem.Identifier("com.toxblh.mtmr.next")
|
||||
static let play = NSTouchBarItem.Identifier("com.toxblh.mtmr.play")
|
||||
|
||||
|
||||
// Plugins
|
||||
static let sleep = NSTouchBarItem.Identifier("com.toxblh.mtmr.sleep")
|
||||
static let weather = NSTouchBarItem.Identifier("com.toxblh.mtmr.weather")
|
||||
static let time = NSTouchBarItem.Identifier("com.toxblh.mtmr.time")
|
||||
static let battery = NSTouchBarItem.Identifier("com.toxblh.mtmr.battery")
|
||||
static let nowPlaying = NSTouchBarItem.Identifier("com.toxblh.mtmr.nowPlaying")
|
||||
|
||||
|
||||
static let controlStripItem = NSTouchBarItem.Identifier("com.toxblh.mtmr.controlStrip")
|
||||
}
|
||||
|
||||
class CustomButtonTouchBarItem: NSCustomTouchBarItem {
|
||||
let tapClosure: (NSCustomTouchBarItem) -> ()
|
||||
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, title: String, onTap callback: @escaping (NSCustomTouchBarItem) -> ()) {
|
||||
self.tapClosure = callback
|
||||
super.init(identifier: identifier)
|
||||
self.view = NSButton(title: title, target: self, action: #selector(didTapped))
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
@objc func didTapped() {
|
||||
self.tapClosure(self)
|
||||
let hf: HapticFeedback = HapticFeedback()
|
||||
hf.tap(strong: 6)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,3 +8,13 @@
|
||||
|
||||
#import "TouchBarPrivateApi.h"
|
||||
#import "TouchBarSupport.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
CF_EXPORT CFTypeRef MTActuatorCreateFromDeviceID(UInt64 deviceID);
|
||||
CF_EXPORT IOReturn MTActuatorOpen(CFTypeRef actuatorRef);
|
||||
CF_EXPORT IOReturn MTActuatorClose(CFTypeRef actuatorRef);
|
||||
CF_EXPORT IOReturn MTActuatorActuate(CFTypeRef actuatorRef, SInt32 actuationID, UInt32 arg1, Float32 arg2, Float32 arg3);
|
||||
CF_EXPORT bool MTActuatorIsOpen(CFTypeRef actuatorRef);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
Reference in New Issue
Block a user