SessionCtl // Add caps lock notification support, etc.

This commit is contained in:
ShikiSuen 2022-09-29 12:47:26 +08:00
parent 487fb55926
commit f75bafdd01
6 changed files with 20 additions and 14 deletions

View File

@ -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).
// ====================
// 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
// requirements defined in MIT License.
import CocoaExtension
import IMKUtils
import PopupCompositionBuffer
import Shared
@ -40,6 +39,9 @@ class SessionCtl: IMKInputController {
// MARK: -
/// CapsLock
var isCapsLocked: Bool { NSEvent.modifierFlags.intersection(.deviceIndependentFlagsMask).contains(.capsLock) }
/// SessionCtl
var isASCIIMode = false {
didSet {
@ -159,7 +161,8 @@ extension SessionCtl {
keyHandler.clear() // handle State.Empty()
keyHandler.ensureKeyboardParser()
if isASCIIMode, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
if isASCIIMode, !isCapsLocked, PrefMgr.shared.disableShiftTogglingAlphanumericalMode { isASCIIMode = false }
if isCapsLocked { isASCIIMode = isCapsLocked } // CapsLock
///
/// macOS

View File

@ -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).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)

View File

@ -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).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)

View File

@ -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).
// ====================
// 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
// requirements defined in MIT License.
import CocoaExtension
import InputMethodKit
import NotifierUI
import Shared
@ -36,6 +35,18 @@ extension SessionCtl {
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
let shouldUseShiftToggleHandle: Bool = {
switch PrefMgr.shared.shiftKeyAccommodationBehavior {
@ -67,7 +78,7 @@ extension SessionCtl {
// MARK:
// Shift
if isASCIIMode { return false }
if isASCIIMode, !isCapsLocked { return false }
/// flags使 KeyHandler
/// flags

View File

@ -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).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)

View File

@ -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).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)