1+ // Copyright (c) 2022 and onwards The McBopomofo Authors.
2+ //
3+ // Permission is hereby granted, free of charge, to any person
4+ // obtaining a copy of this software and associated documentation
5+ // files (the "Software"), to deal in the Software without
6+ // restriction, including without limitation the rights to use,
7+ // copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ // copies of the Software, and to permit persons to whom the
9+ // Software is furnished to do so, subject to the following
10+ // conditions:
11+ //
12+ // The above copyright notice and this permission notice shall be
13+ // included in all copies or substantial portions of the Software.
14+ //
15+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+ // OTHER DEALINGS IN THE SOFTWARE.
23+
124import AppKit
225import Carbon. HIToolbox
326import Foundation
@@ -9,26 +32,20 @@ struct ActiveInputSourceListCollectorPlugin: InfoCollectorPlugin {
932 func getStringValue( _ source: TISInputSource , _ property: CFString ) -> String ? {
1033 if let valuePts = TISGetInputSourceProperty ( source, property) {
1134 let value = Unmanaged < CFString > . fromOpaque ( valuePts) . takeUnretainedValue ( )
12- return value as? String
35+ return String ( value )
1336 }
1437 return nil
1538 }
1639
1740 // Use HIToolbox TIS APIs to get current and enabled input sources
1841 // Build a query for enabled input sources
1942 let keys : [ CFString : Any ] = [
20- kTISPropertyInputSourceIsEnabled: true as CFBoolean
43+ kTISPropertyInputSourceIsEnabled: kCFBooleanTrue as CFBoolean ,
44+ kTISPropertyInputSourceIsSelectCapable: kCFBooleanTrue as CFBoolean ,
45+ kTISPropertyInputSourceCategory: kTISCategoryKeyboardInputSource as CFString ,
2146 ]
2247 let dict = keys as CFDictionary
2348 var lines : [ String ] = [ ]
24-
25- // // Current input source
26- // if let current = TISCopyCurrentKeyboardInputSource()?.takeRetainedValue() {
27- // let currentName = getStringValue(current, kTISPropertyLocalizedName)
28- // let currentID = getStringValue(current, kTISPropertyInputSourceID)
29- // lines.append("- Current Input Source: \(currentName ?? "<unknown>") (\(currentID ?? ""))")
30- // }
31-
3249 // Enabled input sources
3350 if let list = TISCreateInputSourceList ( dict, false ) ? . takeRetainedValue ( )
3451 as? [ TISInputSource ]
@@ -37,7 +54,11 @@ struct ActiveInputSourceListCollectorPlugin: InfoCollectorPlugin {
3754 for src in list {
3855 let name = getStringValue ( src, kTISPropertyLocalizedName) ?? " <unknown> "
3956 let sid = getStringValue ( src, kTISPropertyInputSourceID) ?? " "
40- let category = getStringValue ( src, kTISPropertyInputSourceCategory) as? String ?? " "
57+ let category =
58+ getStringValue (
59+ src,
60+ kTISPropertyInputSourceCategory
61+ ) ?? " "
4162 lines. append ( " - \( name) ( \( sid) ) [ \( category) ] " )
4263 }
4364 }
0 commit comments