Skip to content

Commit

Permalink
display(macOS): support forcing num lock on
Browse files Browse the repository at this point in the history
Resolves #4625
  • Loading branch information
osy committed Mar 3, 2023
1 parent d1d2899 commit 626d288
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Platform/macOS/Display/VMDisplayQemuMetalWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class VMDisplayQemuMetalWindowController: VMDisplayQemuWindowController {
@Setting("CtrlRightClick") private var isCtrlRightClick: Bool = false
@Setting("AlternativeCaptureKey") private var isAlternativeCaptureKey: Bool = false
@Setting("IsCapsLockKey") private var isCapsLockKey: Bool = false
@Setting("IsNumLockForced") private var isNumLockForced: Bool = false
@Setting("InvertScroll") private var isInvertScroll: Bool = false
@Setting("QEMURendererFPSLimit") private var rendererFpsLimit: Int = 0
private var settingObservations = [NSKeyValueObservation]()
Expand Down Expand Up @@ -535,4 +536,17 @@ extension VMDisplayQemuMetalWindowController: VMMetalViewInputDelegate {
}
vmInput.keyLock = locks
}

/// Update virtual num lock status if we force num pad to on
func didUseNumericPad() {
guard isNumLockForced else {
return // nothing to do
}
guard let vmInput = vmInput else {
return
}
if !vmInput.keyLock.contains(.num) {
vmInput.keyLock.insert(.num)
}
}
}
3 changes: 3 additions & 0 deletions Platform/macOS/Display/VMMetalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class VMMetalView: MTKView {
override func keyDown(with event: NSEvent) {
guard !event.isARepeat else { return }
logger.trace("key down: \(event.keyCode)")
if event.modifierFlags.contains(.numericPad) {
inputDelegate?.didUseNumericPad()
}
lastKeyDown = getScanCodeForEvent(event)
inputDelegate?.keyDown(scanCode: lastKeyDown!)
}
Expand Down
1 change: 1 addition & 0 deletions Platform/macOS/Display/VMMetalViewInputDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ protocol VMMetalViewInputDelegate: class {
func syncCapsLock(with modifier: NSEvent.ModifierFlags?)
func captureMouse()
func releaseMouse()
func didUseNumericPad()
}
5 changes: 5 additions & 0 deletions Platform/macOS/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct InputSettingsView: View {
@AppStorage("CtrlRightClick") var isCtrlRightClick = false
@AppStorage("AlternativeCaptureKey") var isAlternativeCaptureKey = false
@AppStorage("IsCapsLockKey") var isCapsLockKey = false
@AppStorage("IsNumLockForced") var isNumLockForced = false
@AppStorage("InvertScroll") var isInvertScroll = false
@AppStorage("NoUsbPrompt") var isNoUsbPrompt = false

Expand All @@ -124,6 +125,9 @@ struct InputSettingsView: View {
Toggle(isOn: $isCapsLockKey, label: {
Text("Caps Lock (⇪) is treated as a key")
}).help("If enabled, caps lock will be handled like other keys. If disabled, it is treated as a toggle that is synchronized with the host.")
Toggle(isOn: $isNumLockForced, label: {
Text("Num Lock is forced on")
}).help("If enabled, num lock will always be on to the guest. Note this may make your keyboard's num lock indicator out of sync.")
}

Section(header: Text("QEMU USB")) {
Expand All @@ -145,6 +149,7 @@ extension UserDefaults {
@objc dynamic var NoUsbPrompt: Bool { false }
@objc dynamic var AlternativeCaptureKey: Bool { false }
@objc dynamic var IsCapsLockKey: Bool { false }
@objc dynamic var IsNumLockForced: Bool { false }
@objc dynamic var NoSaveScreenshot: Bool { false }
@objc dynamic var InvertScroll: Bool { false }
@objc dynamic var QEMURendererBackend: Int { 0 }
Expand Down

0 comments on commit 626d288

Please sign in to comment.