mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
* file moved to new location
This commit is contained in:
parent
f6e5b3ca09
commit
0f41638d0f
@ -11,43 +11,43 @@ import Cocoa
|
||||
class InputSourceBarItem: CustomButtonTouchBarItem {
|
||||
|
||||
fileprivate var notificationCenter: CFNotificationCenter
|
||||
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, onTap: @escaping () -> (), onLongTap: @escaping () -> ()) {
|
||||
notificationCenter = CFNotificationCenterGetDistributedCenter();
|
||||
super.init(identifier: identifier, title: "⏳", onTap: onTap, onLongTap: onLongTap)
|
||||
|
||||
|
||||
observeIputSourceChangedNotification();
|
||||
textInputSourceDidChange()
|
||||
|
||||
|
||||
self.button.action = #selector(switchInputSource)
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
@objc public func textInputSourceDidChange() {
|
||||
let currentSource = TISCopyCurrentKeyboardInputSource().takeUnretainedValue()
|
||||
|
||||
var iconImage: NSImage? = nil
|
||||
|
||||
|
||||
if let imageURL = currentSource.iconImageURL {
|
||||
if let image = NSImage(contentsOf: imageURL) {
|
||||
iconImage = image
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if iconImage == nil, let iconRef = currentSource.iconRef {
|
||||
iconImage = NSImage(iconRef: iconRef)
|
||||
}
|
||||
|
||||
|
||||
if (iconImage != nil) {
|
||||
self.button.image = iconImage
|
||||
} else {
|
||||
self.button.title = currentSource.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc private func switchInputSource() {
|
||||
var inputSources: [TISInputSource] = []
|
||||
|
||||
@ -58,7 +58,7 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
||||
inputSources = elements.filter({
|
||||
$0.category == TISInputSource.Category.keyboardInputSource && $0.isSelectable
|
||||
})
|
||||
|
||||
|
||||
for item in inputSources {
|
||||
if (item.id != currentSource.id) {
|
||||
TISSelectInputSource(item)
|
||||
@ -72,7 +72,7 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
||||
let mySelf = Unmanaged<InputSourceBarItem>.fromOpaque(observer!).takeUnretainedValue()
|
||||
mySelf.textInputSourceDidChange()
|
||||
}
|
||||
|
||||
|
||||
CFNotificationCenterAddObserver(notificationCenter,
|
||||
UnsafeRawPointer(Unmanaged.passUnretained(self).toOpaque()),
|
||||
callback,
|
||||
@ -88,7 +88,7 @@ extension TISInputSource {
|
||||
return kTISCategoryKeyboardInputSource as String
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func getProperty(_ key: CFString) -> AnyObject? {
|
||||
let cfType = TISGetInputSourceProperty(self, key)
|
||||
if (cfType != nil) {
|
||||
@ -97,31 +97,31 @@ extension TISInputSource {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var id: String {
|
||||
return getProperty(kTISPropertyInputSourceID) as! String
|
||||
}
|
||||
|
||||
|
||||
var name: String {
|
||||
return getProperty(kTISPropertyLocalizedName) as! String
|
||||
}
|
||||
|
||||
|
||||
var category: String {
|
||||
return getProperty(kTISPropertyInputSourceCategory) as! String
|
||||
}
|
||||
|
||||
|
||||
var isSelectable: Bool {
|
||||
return getProperty(kTISPropertyInputSourceIsSelectCapable) as! Bool
|
||||
}
|
||||
|
||||
|
||||
var sourceLanguages: [String] {
|
||||
return getProperty(kTISPropertyInputSourceLanguages) as! [String]
|
||||
}
|
||||
|
||||
|
||||
var iconImageURL: URL? {
|
||||
return getProperty(kTISPropertyIconImageURL) as! URL?
|
||||
}
|
||||
|
||||
|
||||
var iconRef: IconRef? {
|
||||
return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef)) as IconRef?
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user