Merge pull request #1083 from gpanders/control-key-handling

macos: special case handling of some control keys
This commit is contained in:
Mitchell Hashimoto
2023-12-13 13:50:06 -08:00
committed by GitHub

View File

@ -783,7 +783,7 @@ extension Ghostty {
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
// By setting this to non-nil, we note that we'rein a keyDown event. From here, // By setting this to non-nil, we note that we're in a keyDown event. From here,
// we call interpretKeyEvents so that we can handle complex input such as Korean // we call interpretKeyEvents so that we can handle complex input such as Korean
// language. // language.
keyTextAccumulator = [] keyTextAccumulator = []
@ -825,6 +825,48 @@ extension Ghostty {
keyAction(GHOSTTY_ACTION_RELEASE, event: event) keyAction(GHOSTTY_ACTION_RELEASE, event: event)
} }
/// Special case handling for some control keys
override func performKeyEquivalent(with event: NSEvent) -> Bool {
// Only process keys when Control is the only modifier
if (!event.modifierFlags.contains(.control) ||
!event.modifierFlags.isDisjoint(with: [.shift, .command, .option])) {
return false
}
// Only process key down events
if (event.type != .keyDown) {
return false
}
let equivalent: String
switch (event.charactersIgnoringModifiers) {
case "/":
// Treat C-/ as C-_. We do this because C-/ makes macOS make a beep
// sound and we don't like the beep sound.
equivalent = "_"
default:
// Ignore other events
return false
}
let newEvent = NSEvent.keyEvent(
with: .keyDown,
location: event.locationInWindow,
modifierFlags: .control,
timestamp: event.timestamp,
windowNumber: event.windowNumber,
context: nil,
characters: equivalent,
charactersIgnoringModifiers: equivalent,
isARepeat: event.isARepeat,
keyCode: event.keyCode
)
self.keyDown(with: newEvent!)
return true
}
override func flagsChanged(with event: NSEvent) { override func flagsChanged(with event: NSEvent) {
let mod: UInt32; let mod: UInt32;
switch (event.keyCode) { switch (event.keyCode) {