mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
upd to previous the commit
This commit is contained in:
parent
b69cdd5d60
commit
c4724e67bb
@ -18,6 +18,8 @@
|
|||||||
B082B271205C7D8000BC04DC /* MTMRUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B270205C7D8000BC04DC /* MTMRUITests.swift */; };
|
B082B271205C7D8000BC04DC /* MTMRUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B270205C7D8000BC04DC /* MTMRUITests.swift */; };
|
||||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */; };
|
||||||
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C1CFC9205C97D30021C862 /* WindowController.swift */; };
|
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C1CFC9205C97D30021C862 /* WindowController.swift */; };
|
||||||
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */; };
|
||||||
|
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */ = {isa = PBXBuildFile; fileRef = B0F8771C207AD35400D6E430 /* battery.scpt */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@ -58,6 +60,9 @@
|
|||||||
B082B272205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
B082B272205C7D8000BC04DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPress.swift; sourceTree = "<group>"; };
|
||||||
B0C1CFC9205C97D30021C862 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
|
B0C1CFC9205C97D30021C862 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = "<group>"; };
|
||||||
|
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TouchBarSupport.m; sourceTree = "<group>"; };
|
||||||
|
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarSupport.h; sourceTree = "<group>"; };
|
||||||
|
B0F8771C207AD35400D6E430 /* battery.scpt */ = {isa = PBXFileReference; lastKnownFileType = text; path = battery.scpt; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -130,6 +135,9 @@
|
|||||||
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
B082B258205C7D8000BC04DC /* Main.storyboard */,
|
||||||
B082B25B205C7D8000BC04DC /* Info.plist */,
|
B082B25B205C7D8000BC04DC /* Info.plist */,
|
||||||
B082B25C205C7D8000BC04DC /* MTMR.entitlements */,
|
B082B25C205C7D8000BC04DC /* MTMR.entitlements */,
|
||||||
|
B0F87719207AC1EA00D6E430 /* TouchBarSupport.m */,
|
||||||
|
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
|
||||||
|
B0F8771C207AD35400D6E430 /* battery.scpt */,
|
||||||
);
|
);
|
||||||
path = MTMR;
|
path = MTMR;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -215,12 +223,17 @@
|
|||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 0920;
|
LastSwiftUpdateCheck = 0920;
|
||||||
LastUpgradeCheck = 0920;
|
LastUpgradeCheck = 0930;
|
||||||
ORGANIZATIONNAME = "Anton Palgunov";
|
ORGANIZATIONNAME = "Anton Palgunov";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
B082B24E205C7D8000BC04DC = {
|
B082B24E205C7D8000BC04DC = {
|
||||||
CreatedOnToolsVersion = 9.2;
|
CreatedOnToolsVersion = 9.2;
|
||||||
ProvisioningStyle = Automatic;
|
ProvisioningStyle = Automatic;
|
||||||
|
SystemCapabilities = {
|
||||||
|
com.apple.Sandbox = {
|
||||||
|
enabled = 0;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
B082B260205C7D8000BC04DC = {
|
B082B260205C7D8000BC04DC = {
|
||||||
CreatedOnToolsVersion = 9.2;
|
CreatedOnToolsVersion = 9.2;
|
||||||
@ -261,6 +274,7 @@
|
|||||||
files = (
|
files = (
|
||||||
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */,
|
||||||
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */,
|
||||||
|
B0F8771D207AD35400D6E430 /* battery.scpt in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -288,6 +302,7 @@
|
|||||||
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */,
|
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */,
|
||||||
B082B255205C7D8000BC04DC /* ViewController.swift in Sources */,
|
B082B255205C7D8000BC04DC /* ViewController.swift in Sources */,
|
||||||
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */,
|
B0C1CFCA205C97D30021C862 /* WindowController.swift in Sources */,
|
||||||
|
B0F8771A207AC1EA00D6E430 /* TouchBarSupport.m in Sources */,
|
||||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||||
B059D624205E04F3006E6B86 /* TouchBarItems.swift in Sources */,
|
B059D624205E04F3006E6B86 /* TouchBarItems.swift in Sources */,
|
||||||
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
B0A7E9AA205D6AA400EEF070 /* KeyPress.swift in Sources */,
|
||||||
@ -351,6 +366,7 @@
|
|||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
CLANG_WARN_COMMA = YES;
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
@ -358,6 +374,7 @@
|
|||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
@ -408,6 +425,7 @@
|
|||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||||
CLANG_WARN_COMMA = YES;
|
CLANG_WARN_COMMA = YES;
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||||
|
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
CLANG_WARN_EMPTY_BODY = YES;
|
||||||
@ -415,6 +433,7 @@
|
|||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
CLANG_WARN_INT_CONVERSION = YES;
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||||
|
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||||
@ -447,7 +466,6 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = MTMR/MTMR.entitlements;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
||||||
@ -468,7 +486,6 @@
|
|||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = MTMR/MTMR.entitlements;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
DEVELOPMENT_TEAM = D6D8BR2QNB;
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>IDEDidComputeMac32BitWarning</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@ -16,7 +16,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||||
TouchBarController.shared.setupControlStripPresence()
|
TouchBarController.shared.setupControlStripPresence()
|
||||||
// Insert code here to initialize your application
|
// Insert code here to initialize your application
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ aNotification: Notification) {
|
func applicationWillTerminate(_ aNotification: Notification) {
|
||||||
|
|||||||
@ -8,23 +8,73 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
protocol KeyPress {
|
||||||
func KeyPress (keyCode: CGKeyCode) {
|
var keyCode: CGKeyCode { get }
|
||||||
let keyDown = CGEvent(keyboardEventSource: nil, virtualKey: keyCode, keyDown: true)
|
func send()
|
||||||
let keyUp = CGEvent(keyboardEventSource: nil, virtualKey: keyCode, keyDown: false)
|
|
||||||
|
|
||||||
keyDown?.post(tap: .cghidEventTap)
|
|
||||||
keyUp?.post(tap: .cghidEventTap)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ESCKeyPress() {
|
extension KeyPress {
|
||||||
KeyPress(keyCode: 53)
|
func send () {
|
||||||
|
let src = CGEventSource(stateID: .hidSystemState)
|
||||||
|
let keyDown = CGEvent(keyboardEventSource: src, virtualKey: keyCode, keyDown: true)
|
||||||
|
let keyUp = CGEvent(keyboardEventSource: src, virtualKey: keyCode, keyDown: false)
|
||||||
|
|
||||||
|
let loc: CGEventTapLocation = .cghidEventTap
|
||||||
|
keyDown?.post(tap: loc)
|
||||||
|
keyUp?.post(tap: loc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BrightnessUpPress() {
|
struct ESCKeyPress: KeyPress {
|
||||||
KeyPress(keyCode: 107)
|
let keyCode: CGKeyCode = 53
|
||||||
}
|
}
|
||||||
|
|
||||||
func BrightnessDownPress() {
|
struct BrightnessUpPress: KeyPress {
|
||||||
KeyPress(keyCode: 113)
|
let keyCode: CGKeyCode = 107
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BrightnessDownPress: KeyPress {
|
||||||
|
let keyCode: CGKeyCode = 113
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func doKey(_ key: Int, down: Bool) {
|
||||||
|
let flags = NSEvent.ModifierFlags(rawValue: down ? 0xa00 : 0xb00)
|
||||||
|
let data1 = (key << 16) | ((down ? 0xa : 0xb) << 8)
|
||||||
|
|
||||||
|
let ev = NSEvent.otherEvent(
|
||||||
|
with: NSEvent.EventType.systemDefined,
|
||||||
|
location: NSPoint(x:0.0, y:0.0),
|
||||||
|
modifierFlags: flags,
|
||||||
|
timestamp: TimeInterval(0),
|
||||||
|
windowNumber: 0,
|
||||||
|
context: nil,
|
||||||
|
// context: 0,
|
||||||
|
subtype: 8,
|
||||||
|
data1: data1,
|
||||||
|
data2: -1
|
||||||
|
)
|
||||||
|
let cev = ev!.cgEvent!
|
||||||
|
cev.post(tap: CGEventTapLocation(rawValue: 0)!)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HIDPostAuxKey(_ key: Int) {
|
||||||
|
doKey(key, down: true)
|
||||||
|
doKey(key, down: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// hidsystem/ev_keymap.h
|
||||||
|
let NX_KEYTYPE_SOUND_UP = 0
|
||||||
|
let NX_KEYTYPE_SOUND_DOWN = 1
|
||||||
|
|
||||||
|
let NX_KEYTYPE_BRIGHTNESS_UP = 2
|
||||||
|
let NX_KEYTYPE_BRIGHTNESS_DOWN = 3
|
||||||
|
|
||||||
|
let NX_KEYTYPE_PLAY = 16
|
||||||
|
let NX_KEYTYPE_NEXT = 17
|
||||||
|
let NX_KEYTYPE_PREVIOUS = 18
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict/>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
|
||||||
<true/>
|
|
||||||
<key>com.apple.security.files.user-selected.read-only</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@ -14,19 +14,40 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
|
|
||||||
let touchBar = NSTouchBar()
|
let touchBar = NSTouchBar()
|
||||||
|
|
||||||
|
var timer = Timer()
|
||||||
|
var timeButton: NSButton = NSButton()
|
||||||
|
|
||||||
private override init() {
|
private override init() {
|
||||||
super.init()
|
super.init()
|
||||||
touchBar.delegate = self
|
touchBar.delegate = self
|
||||||
touchBar.defaultItemIdentifiers = [.escButton, .volumeUp, .volumeDown, .time, .preferences]
|
touchBar.defaultItemIdentifiers = [
|
||||||
|
.escButton,
|
||||||
|
|
||||||
|
.brightDown,
|
||||||
|
.brightUp,
|
||||||
|
|
||||||
|
.prev,
|
||||||
|
.play,
|
||||||
|
.next,
|
||||||
|
|
||||||
|
.sleep,
|
||||||
|
.weather,
|
||||||
|
|
||||||
|
.volumeDown,
|
||||||
|
.volumeUp,
|
||||||
|
.battery,
|
||||||
|
.time,
|
||||||
|
]
|
||||||
self.presentTouchBar()
|
self.presentTouchBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupControlStripPresence() {
|
func setupControlStripPresence() {
|
||||||
DFRSystemModalShowsCloseBoxWhenFrontMost(true)
|
DFRSystemModalShowsCloseBoxWhenFrontMost(false)
|
||||||
let item = NSCustomTouchBarItem(identifier: .controlStripItem)
|
let item = NSCustomTouchBarItem(identifier: .controlStripItem)
|
||||||
item.view = NSButton(image: #imageLiteral(resourceName: "Strip"), target: self, action: #selector(presentTouchBar))
|
item.view = NSButton(image: #imageLiteral(resourceName: "Strip"), target: self, action: #selector(presentTouchBar))
|
||||||
NSTouchBarItem.addSystemTrayItem(item)
|
NSTouchBarItem.addSystemTrayItem(item)
|
||||||
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
DFRElementSetControlStripPresenceForIdentifier(.controlStripItem, true)
|
||||||
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.updateTime), userInfo: nil, repeats: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateControlStripPresence() {
|
func updateControlStripPresence() {
|
||||||
@ -45,59 +66,112 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
switch identifier {
|
switch identifier {
|
||||||
case .escButton:
|
case .escButton:
|
||||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
item.view = NSButton(title: "ESC", target: self, action: #selector(handleEsc))
|
item.view = NSButton(title: "esc", target: self, action: #selector(handleEsc))
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
case .brightUp:
|
||||||
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
item.view = NSButton(title: "🔆", target: self, action: #selector(handleBrightUp))
|
||||||
|
return item
|
||||||
|
case .brightDown:
|
||||||
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
item.view = NSButton(title: "🔅", target: self, action: #selector(handleBrightDown))
|
||||||
|
return item
|
||||||
|
|
||||||
case .volumeDown:
|
case .volumeDown:
|
||||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
item.view = NSButton(title: "V-", target: self, action: #selector(handleVolumeDown))
|
item.view = NSButton(title: "🔉", target: self, action: #selector(handleVolumeDown))
|
||||||
return item
|
return item
|
||||||
case .volumeUp:
|
case .volumeUp:
|
||||||
let item = NSCustomTouchBarItem(identifier: identifier)
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
item.view = NSButton(title: "V+", target: self, action: #selector(handleVolumeUp))
|
item.view = NSButton(title: "🔊", target: self, action: #selector(handleVolumeUp))
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
// case .prev:
|
||||||
|
// let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
// item.view = NSButton(title: "⏪", target: self, action: #selector(handlePrev))
|
||||||
|
// return item
|
||||||
|
case .play:
|
||||||
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
item.view = NSButton(title: "⏯", target: self, action: #selector(handlePlay))
|
||||||
|
return item
|
||||||
|
case .next:
|
||||||
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
item.view = NSButton(title: "⏩", target: self, action: #selector(handleNext))
|
||||||
|
return item
|
||||||
|
|
||||||
|
case .time:
|
||||||
|
let item = NSCustomTouchBarItem(identifier: identifier)
|
||||||
|
timeButton = NSButton(title: self.getCurrentTime(), target: self, action: nil)
|
||||||
|
item.view = timeButton
|
||||||
|
return item
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCurrentTime() -> String {
|
||||||
|
let date = Date()
|
||||||
|
let dateFormatter = DateFormatter()
|
||||||
|
dateFormatter.setLocalizedDateFormatFromTemplate("HH:mm")
|
||||||
|
let timestamp = dateFormatter.string(from: date)
|
||||||
|
return timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func updateTime() {
|
||||||
|
timeButton.title = getCurrentTime()
|
||||||
|
}
|
||||||
|
|
||||||
@objc func handleEsc() {
|
@objc func handleEsc() {
|
||||||
ESCKeyPress()
|
let sender = ESCKeyPress()
|
||||||
|
sender.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleVolumeUp() {
|
@objc func handleVolumeUp() {
|
||||||
self.volume(directon: "up")
|
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_UP))
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleVolumeDown() {
|
@objc func handleVolumeDown() {
|
||||||
self.volume(directon: "down")
|
HIDPostAuxKey(Int(NX_KEYTYPE_SOUND_DOWN))
|
||||||
}
|
}
|
||||||
|
|
||||||
func volume(directon: String) {
|
@objc func handleBrightDown() {
|
||||||
var myAppleScript = "set volume output volume (output volume of (get volume settings) - 5)"
|
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_DOWN))
|
||||||
|
|
||||||
if (directon == "up") {
|
let sender = BrightnessUpPress()
|
||||||
myAppleScript = "set volume output volume (output volume of (get volume settings) + 5)"
|
sender.send()
|
||||||
}
|
|
||||||
|
|
||||||
var error: NSDictionary?
|
|
||||||
if let scriptObject = NSAppleScript(source: myAppleScript) {
|
|
||||||
let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(&error)
|
|
||||||
|
|
||||||
print(output.stringValue as Any)
|
|
||||||
|
|
||||||
if (error != nil) {
|
|
||||||
print("error: \(String(describing: error))")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func brightness(directon: String) {
|
@objc func handleBrightUp() {
|
||||||
if (directon == "up") {
|
// HIDPostAuxKey(Int(NX_KEYTYPE_BRIGHTNESS_UP))
|
||||||
BrightnessUpPress()
|
|
||||||
print("BR - Up")
|
let sender = BrightnessDownPress()
|
||||||
} else {
|
sender.send()
|
||||||
BrightnessDownPress()
|
|
||||||
print("BR - Down")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc func handlePrev() {
|
||||||
|
HIDPostAuxKey(Int(NX_KEYTYPE_PREVIOUS))
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handlePlay() {
|
||||||
|
HIDPostAuxKey(Int(NX_KEYTYPE_PLAY))
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleNext() {
|
||||||
|
HIDPostAuxKey(Int(NX_KEYTYPE_NEXT))
|
||||||
|
}
|
||||||
|
|
||||||
|
// func getBattery() {
|
||||||
|
// var error: NSDictionary?
|
||||||
|
// if let scriptObject = NSAppleScript(source: <#T##String#>) {
|
||||||
|
// if let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(
|
||||||
|
// &error) {
|
||||||
|
// print(output.stringValue)
|
||||||
|
// } else if (error != nil) {
|
||||||
|
// print("error: \(error)")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,26 @@ import Cocoa
|
|||||||
|
|
||||||
extension NSTouchBarItem.Identifier {
|
extension NSTouchBarItem.Identifier {
|
||||||
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
|
static let escButton = NSTouchBarItem.Identifier("com.toxblh.mtmr.escButton")
|
||||||
static let time = NSTouchBarItem.Identifier("com.toxblh.mtmr.time")
|
|
||||||
|
// Volume
|
||||||
static let volumeUp = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeUp")
|
static let volumeUp = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeUp")
|
||||||
static let volumeDown = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeDown")
|
static let volumeDown = NSTouchBarItem.Identifier("com.toxblh.mtmr.volumeDown")
|
||||||
static let preferences = NSTouchBarItem.Identifier("com.toxblh.mtmr.preferences")
|
|
||||||
|
// 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")
|
static let controlStripItem = NSTouchBarItem.Identifier("com.toxblh.mtmr.controlStrip")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,3 +7,4 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "TouchBarPrivateApi.h"
|
#import "TouchBarPrivateApi.h"
|
||||||
|
#import "TouchBarSupport.h"
|
||||||
|
|||||||
@ -5,6 +5,7 @@ extern void DFRElementSetControlStripPresenceForIdentifier(NSTouchBarItemIdentif
|
|||||||
|
|
||||||
extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
|
extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
|
||||||
|
|
||||||
|
|
||||||
@interface NSTouchBarItem (PrivateMethods)
|
@interface NSTouchBarItem (PrivateMethods)
|
||||||
|
|
||||||
+ (void)addSystemTrayItem:(NSTouchBarItem *)item;
|
+ (void)addSystemTrayItem:(NSTouchBarItem *)item;
|
||||||
@ -13,6 +14,7 @@ extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface NSTouchBar (PrivateMethods)
|
@interface NSTouchBar (PrivateMethods)
|
||||||
|
|
||||||
// presentSystemModalFunctionBar:placement:systemTrayItemIdentifier:
|
// presentSystemModalFunctionBar:placement:systemTrayItemIdentifier:
|
||||||
@ -25,3 +27,4 @@ extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL);
|
|||||||
+ (void)minimizeSystemModalFunctionBar:(NSTouchBar *)touchBar;
|
+ (void)minimizeSystemModalFunctionBar:(NSTouchBar *)touchBar;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,12 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef TouchBarSupport_h
|
#import <Foundation/Foundation.h>
|
||||||
#define TouchBarSupport_h
|
|
||||||
|
|
||||||
|
@interface MediaKeys : NSObject
|
||||||
|
|
||||||
#endif /* TouchBarSupport_h */
|
+ (void)decreaseVolume;
|
||||||
|
+ (void)increaseVolume;
|
||||||
|
+ (void)muteVolume;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|||||||
@ -6,4 +6,61 @@
|
|||||||
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
// Copyright © 2018 Anton Palgunov. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import "TouchBarSupport.h"
|
||||||
|
|
||||||
|
@implementation MediaKeys
|
||||||
|
|
||||||
|
static io_connect_t get_event_driver(void)
|
||||||
|
{
|
||||||
|
static mach_port_t sEventDrvrRef = 0;
|
||||||
|
mach_port_t masterPort, service, iter;
|
||||||
|
kern_return_t kr;
|
||||||
|
|
||||||
|
if (!sEventDrvrRef)
|
||||||
|
{
|
||||||
|
kr = IOMasterPort( bootstrap_port, &masterPort );
|
||||||
|
kr = IOServiceGetMatchingServices( masterPort, IOServiceMatching( kIOHIDSystemClass ), &iter );
|
||||||
|
service = IOIteratorNext( iter );
|
||||||
|
kr = IOServiceOpen( service, mach_task_self(),
|
||||||
|
kIOHIDParamConnectType, &sEventDrvrRef );
|
||||||
|
IOObjectRelease( service );
|
||||||
|
IOObjectRelease( iter );
|
||||||
|
}
|
||||||
|
return sEventDrvrRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void HIDPostAuxKey( const UInt8 auxKeyCode )
|
||||||
|
{
|
||||||
|
NXEventData event;
|
||||||
|
kern_return_t kr;
|
||||||
|
IOGPoint loc = { 0, 0 };
|
||||||
|
|
||||||
|
// Key press event
|
||||||
|
UInt32 evtInfo = auxKeyCode << 16 | NX_KEYDOWN << 8;
|
||||||
|
bzero(&event, sizeof(NXEventData));
|
||||||
|
event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS;
|
||||||
|
event.compound.misc.L[0] = evtInfo;
|
||||||
|
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE );
|
||||||
|
|
||||||
|
// Key release event
|
||||||
|
evtInfo = auxKeyCode << 16 | NX_KEYUP << 8;
|
||||||
|
bzero(&event, sizeof(NXEventData));
|
||||||
|
event.compound.subType = NX_SUBTYPE_AUX_CONTROL_BUTTONS;
|
||||||
|
event.compound.misc.L[0] = evtInfo;
|
||||||
|
kr = IOHIDPostEvent( get_event_driver(), NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)decreaseVolume {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_SOUND_DOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)increaseVolume {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_SOUND_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)muteVolume {
|
||||||
|
HIDPostAuxKey(NX_KEYTYPE_MUTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
set theList to paragraphs of text of (do shell script "pmset -g batt")
|
||||||
|
set percent to word 6 of theList's item 2
|
||||||
|
set charge to word 7 of theList's item 2
|
||||||
|
|
||||||
|
if (charge = "charging") then
|
||||||
|
set iconC to "⚡️"
|
||||||
|
else
|
||||||
|
set iconC to ""
|
||||||
|
end if
|
||||||
|
|
||||||
|
set remainingRaw to my split(theList's item 2, " ")
|
||||||
|
set remainingTime to remainingRaw's item 5
|
||||||
|
|
||||||
|
if (remainingTime = "(no") then
|
||||||
|
set strTime to " (?)"
|
||||||
|
else if (remainingTime = "0:00") then
|
||||||
|
set strTime to ""
|
||||||
|
else
|
||||||
|
set strTime to " (" & remainingTime & ")"
|
||||||
|
end if
|
||||||
|
|
||||||
|
return iconC & percent & "%" & strTime
|
||||||
|
|
||||||
|
to split(someText, delimiter)
|
||||||
|
set AppleScript's text item delimiters to delimiter
|
||||||
|
set someText to someText's text items
|
||||||
|
set AppleScript's text item delimiters to {""}
|
||||||
|
return someText
|
||||||
|
end split
|
||||||
@ -4,12 +4,17 @@
|
|||||||
|
|
||||||
# My TouchBar. My rules
|
# My TouchBar. My rules
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="Resources/TouchBarV0.1.png">
|
||||||
|
</p>
|
||||||
|
|
||||||
My the idea is to create the program like a platform for plugins for customization TouchBar. I very like BTT and a full custom TouchBar. And I want to create it. And it's my the first Swift project for MacOS :)
|
My the idea is to create the program like a platform for plugins for customization TouchBar. I very like BTT and a full custom TouchBar. And I want to create it. And it's my the first Swift project for MacOS :)
|
||||||
|
|
||||||
### Roadmap
|
### Roadmap
|
||||||
- [x] Create the first prototype with TouchBar in Storyboard
|
- [x] Create the first prototype with TouchBar in Storyboard
|
||||||
- [x] Put in stripe menu on startup the application
|
- [x] Put in stripe menu on startup the application
|
||||||
- [ ] Find how to simulate real buttons like brightness, volume, night shift and etc.
|
- [x] Find how to simulate real buttons like brightness, volume, night shift and etc.
|
||||||
|
- [x] Time in touchbar!
|
||||||
- [ ] First the weather plugin
|
- [ ] First the weather plugin
|
||||||
- [ ] Create the same panel like in my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)
|
- [ ] Create the same panel like in my [BTT preset](https://github.com/Toxblh/btt-touchbar-preset)
|
||||||
- [ ] Find how to open full-screen TouchBar without the cross and stripe menu
|
- [ ] Find how to open full-screen TouchBar without the cross and stripe menu
|
||||||
|
|||||||
BIN
Resources/TouchBarV0.1.png
Normal file
BIN
Resources/TouchBarV0.1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Loading…
Reference in New Issue
Block a user