mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-03 20:34:41 +00:00
macos: use the new self-hosted translation
This commit is contained in:
@@ -349,7 +349,15 @@ extension Ghostty {
|
||||
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
|
||||
keyAction(action, event: event)
|
||||
|
||||
self.interpretKeyEvents([event])
|
||||
// We specifically DO NOT call interpretKeyEvents because ghostty_surface_key
|
||||
// automatically handles all key translation, and we don't handle any commands
|
||||
// currently.
|
||||
//
|
||||
// It is possible that in the future we'll have to modify ghostty_surface_key
|
||||
// and the embedding API so that we can call this because macOS needs to do
|
||||
// some things with certain keys. I'm not sure. For now this works.
|
||||
//
|
||||
// self.interpretKeyEvents([event])
|
||||
}
|
||||
|
||||
override func keyUp(with event: NSEvent) {
|
||||
@@ -359,28 +367,7 @@ extension Ghostty {
|
||||
private func keyAction(_ action: ghostty_input_action_e, event: NSEvent) {
|
||||
guard let surface = self.surface else { return }
|
||||
let mods = Self.translateFlags(event.modifierFlags)
|
||||
let unmapped_key = Self.keycodes[event.keyCode] ?? GHOSTTY_KEY_INVALID
|
||||
|
||||
ghostty_surface_key2(surface, action, UInt32(event.keyCode), mods)
|
||||
|
||||
// We translate the key to the localized keyboard layout. However, we only support
|
||||
// ASCII characters to make our translation easier across platforms. This is something
|
||||
// we want to make a lot more robust in the future, so this will hopefully change.
|
||||
// For now, this makes most keyboard layouts work, and for those that don't, they can
|
||||
// use physical keycode mappings.
|
||||
let key = {
|
||||
if let str = event.characters(byApplyingModifiers: .init(rawValue: 0)) {
|
||||
if str.utf8.count == 1, let firstByte = str.utf8.first {
|
||||
if let translatedKey = Self.ascii[firstByte] {
|
||||
return translatedKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unmapped_key
|
||||
}()
|
||||
|
||||
ghostty_surface_key(surface, action, key, unmapped_key, mods)
|
||||
}
|
||||
|
||||
// MARK: Menu Handlers
|
||||
|
||||
Reference in New Issue
Block a user