SessionCtl // Add caps lock notification support, etc.
This commit is contained in:
parent
487fb55926
commit
f75bafdd01
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
@ -8,6 +6,7 @@
|
||||||
// marks, or product names of Contributor, except as required to fulfill notice
|
// marks, or product names of Contributor, except as required to fulfill notice
|
||||||
// requirements defined in MIT License.
|
// requirements defined in MIT License.
|
||||||
|
|
||||||
|
import CocoaExtension
|
||||||
import IMKUtils
|
import IMKUtils
|
||||||
import PopupCompositionBuffer
|
import PopupCompositionBuffer
|
||||||
import Shared
|
import Shared
|
||||||
|
@ -40,6 +39,9 @@ class SessionCtl: IMKInputController {
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
||||||
|
/// 當前 CapsLock 按鍵是否被摁下。
|
||||||
|
var isCapsLocked: Bool { NSEvent.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.capsLock) }
|
||||||
|
|
||||||
/// 當前這個 SessionCtl 副本是否處於英數輸入模式。
|
/// 當前這個 SessionCtl 副本是否處於英數輸入模式。
|
||||||
var isASCIIMode = false {
|
var isASCIIMode = false {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -159,7 +161,8 @@ extension SessionCtl {
|
||||||
keyHandler.clear() // 這句不要砍,因為後面 handle State.Empty() 不一定執行。
|
keyHandler.clear() // 這句不要砍,因為後面 handle State.Empty() 不一定執行。
|
||||||
keyHandler.ensureKeyboardParser()
|
keyHandler.ensureKeyboardParser()
|
||||||
|
|
||||||
if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
|
if isASCIIMode, !isCapsLocked, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
|
||||||
|
if isCapsLocked { isASCIIMode = isCapsLocked } // 同步 CapsLock 狀態。
|
||||||
|
|
||||||
/// 必須加上下述條件,否則會在每次切換至輸入法本體的視窗(比如偏好設定視窗)時會卡死。
|
/// 必須加上下述條件,否則會在每次切換至輸入法本體的視窗(比如偏好設定視窗)時會卡死。
|
||||||
/// 這是很多 macOS 副廠輸入法的常見失誤之處。
|
/// 這是很多 macOS 副廠輸入法的常見失誤之處。
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
@ -8,6 +6,7 @@
|
||||||
// marks, or product names of Contributor, except as required to fulfill notice
|
// marks, or product names of Contributor, except as required to fulfill notice
|
||||||
// requirements defined in MIT License.
|
// requirements defined in MIT License.
|
||||||
|
|
||||||
|
import CocoaExtension
|
||||||
import InputMethodKit
|
import InputMethodKit
|
||||||
import NotifierUI
|
import NotifierUI
|
||||||
import Shared
|
import Shared
|
||||||
|
@ -36,6 +35,18 @@ extension SessionCtl {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Caps Lock 通知與切換處理。
|
||||||
|
if event.type == .flagsChanged, event.keyCode == KeyCode.kCapsLock.rawValue {
|
||||||
|
let isCapsLockTurnedOn = event.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.capsLock)
|
||||||
|
let status = NSLocalizedString("NotificationSwitchShift", comment: "")
|
||||||
|
Notifier.notify(
|
||||||
|
message: isCapsLockTurnedOn
|
||||||
|
? "Caps Lock" + NSLocalizedString("Alphanumerical Input Mode", comment: "") + "\n" + status
|
||||||
|
: NSLocalizedString("Chinese Input Mode", comment: "") + "\n" + status
|
||||||
|
)
|
||||||
|
isASCIIMode = isCapsLockTurnedOn
|
||||||
|
}
|
||||||
|
|
||||||
// 用 Shift 開關半形英數模式,僅對 macOS 10.15 及之後的 macOS 有效。
|
// 用 Shift 開關半形英數模式,僅對 macOS 10.15 及之後的 macOS 有效。
|
||||||
let shouldUseShiftToggleHandle: Bool = {
|
let shouldUseShiftToggleHandle: Bool = {
|
||||||
switch PrefMgr.shared.shiftKeyAccommodationBehavior {
|
switch PrefMgr.shared.shiftKeyAccommodationBehavior {
|
||||||
|
@ -67,7 +78,7 @@ extension SessionCtl {
|
||||||
// MARK: 針對客體的具體處理
|
// MARK: 針對客體的具體處理
|
||||||
|
|
||||||
// 不再讓威注音處理由 Shift 切換到的英文模式的按鍵輸入。
|
// 不再讓威注音處理由 Shift 切換到的英文模式的按鍵輸入。
|
||||||
if isASCIIMode { return false }
|
if isASCIIMode, !isCapsLocked { return false }
|
||||||
|
|
||||||
/// 這裡仍舊需要判斷 flags。之前使輸入法狀態卡住無法敲漢字的問題已在 KeyHandler 內修復。
|
/// 這裡仍舊需要判斷 flags。之前使輸入法狀態卡住無法敲漢字的問題已在 KeyHandler 內修復。
|
||||||
/// 這裡不判斷 flags 的話,用方向鍵前後定位光標之後,再次試圖觸發組字區時、反而會在首次按鍵時失敗。
|
/// 這裡不判斷 flags 的話,用方向鍵前後定位光標之後,再次試圖觸發組字區時、反而會在首次按鍵時失敗。
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
|
||||||
// All possible vChewing-specific modifications are of:
|
|
||||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
// ====================
|
// ====================
|
||||||
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
|
Loading…
Reference in New Issue