@@ -51,6 +51,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
5151 var eventSpec = EventTypeSpec ( eventClass: OSType ( kEventClassKeyboard) , eventKind: UInt32 ( kEventHotKeyPressed) )
5252 InstallEventHandler ( GetApplicationEventTarget ( ) , eventHotKeyHandler, 1 , & eventSpec, nil , & eventHandlerRef)
5353 registerEventHotKey ( Preferences . rotateShortcut)
54+
55+ // 입력기가 변경되는 시점에 ABC 입력기 제한 로직 실행
56+ NotificationCenter . default. addObserver (
57+ self ,
58+ selector: #selector( suppressABC) ,
59+ name: NSTextInputContext . keyboardSelectionDidChangeNotification,
60+ object: nil
61+ )
5462 }
5563
5664 func applicationWillTerminate( _ aNotification: Notification ) {
@@ -274,5 +282,54 @@ class AppDelegate: NSObject, NSApplicationDelegate {
274282 break
275283 }
276284 }
285+
286+ @objc private func suppressABC( _ aNotification: Notification ) {
287+ debug ( " \( String ( describing: aNotification) ) " )
288+
289+ guard Preferences . suppressABC == true else { return }
290+
291+ let current = TISCopyCurrentKeyboardInputSource ( ) ? . takeRetainedValue ( )
292+ guard let current = current else {
293+ warning ( " TISCopyCurrentKeyboardInputSource 실패 " )
294+ return
295+ }
296+
297+ let currentIDOpaque = TISGetInputSourceProperty ( current, kTISPropertyInputSourceID)
298+ guard let currentIDOpaque = currentIDOpaque else {
299+ warning ( " TISGetInputSourceProperty 실패 " )
300+ return
301+ }
302+ let currentID = Unmanaged < CFString > . fromOpaque ( currentIDOpaque) . takeUnretainedValue ( ) as String
303+
304+ if currentID != " com.apple.keylayout.ABC " {
305+ debug ( " 현재 입력기 ABC 아님: \( currentID) " )
306+ return
307+ }
308+
309+ let sokArray = TISCreateInputSourceList ( [
310+ kTISPropertyInputSourceType: kTISTypeKeyboardInputMode,
311+ kTISPropertyInputModeID: " com.kiding.inputmethod.sok.mode " as CFString
312+ ] as CFDictionary , false ) ? . takeRetainedValue ( ) as? [ TISInputSource ]
313+ guard let sokArray = sokArray else {
314+ warning ( " TISCreateInputSourceList 실패 " )
315+ return
316+ }
317+
318+ let sok = sokArray. first
319+ guard let sok = sok else {
320+ warning ( " sokArray.first 실패 " )
321+ return
322+ }
323+
324+ // "시스템 설정 > 암호" 필드에서는 무한 루프에 빠질 수 있음
325+ DispatchQueue . main. asyncAfter ( deadline: . now( ) + . milliseconds( 100 ) ) {
326+ guard TISSelectInputSource ( sok) == 0 else {
327+ warning ( " TISSelectInputSource 실패 " )
328+ return
329+ }
330+
331+ debug ( " ABC 입력기 제한 성공 " )
332+ }
333+ }
277334}
278335// swiftlint:enable function_body_length
0 commit comments