mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/embedded: support unmapped keys
This commit is contained in:
@ -261,7 +261,7 @@ void ghostty_surface_refresh(ghostty_surface_t);
|
|||||||
void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
|
void ghostty_surface_set_content_scale(ghostty_surface_t, double, double);
|
||||||
void ghostty_surface_set_focus(ghostty_surface_t, bool);
|
void ghostty_surface_set_focus(ghostty_surface_t, bool);
|
||||||
void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
|
void ghostty_surface_set_size(ghostty_surface_t, uint32_t, uint32_t);
|
||||||
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, ghostty_input_key_e, ghostty_input_mods_e);
|
void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, ghostty_input_key_e, ghostty_input_key_e, ghostty_input_mods_e);
|
||||||
void ghostty_surface_char(ghostty_surface_t, uint32_t);
|
void ghostty_surface_char(ghostty_surface_t, uint32_t);
|
||||||
void ghostty_surface_mouse_button(ghostty_surface_t, ghostty_input_mouse_state_e, ghostty_input_mouse_button_e, ghostty_input_mods_e);
|
void ghostty_surface_mouse_button(ghostty_surface_t, ghostty_input_mouse_state_e, ghostty_input_mouse_button_e, ghostty_input_mods_e);
|
||||||
void ghostty_surface_mouse_pos(ghostty_surface_t, double, double);
|
void ghostty_surface_mouse_pos(ghostty_surface_t, double, double);
|
||||||
|
@ -302,9 +302,20 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func keyDown(with event: NSEvent) {
|
override func keyDown(with event: NSEvent) {
|
||||||
|
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
|
||||||
|
keyAction(action, event: event)
|
||||||
|
|
||||||
|
self.interpretKeyEvents([event])
|
||||||
|
}
|
||||||
|
|
||||||
|
override func keyUp(with event: NSEvent) {
|
||||||
|
keyAction(GHOSTTY_ACTION_RELEASE, event: event)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func keyAction(_ action: ghostty_input_action_e, event: NSEvent) {
|
||||||
guard let surface = self.surface else { return }
|
guard let surface = self.surface else { return }
|
||||||
let mods = Self.translateFlags(event.modifierFlags)
|
let mods = Self.translateFlags(event.modifierFlags)
|
||||||
let action = event.isARepeat ? GHOSTTY_ACTION_REPEAT : GHOSTTY_ACTION_PRESS
|
let unmapped_key = Self.keycodes[event.keyCode] ?? GHOSTTY_KEY_INVALID
|
||||||
|
|
||||||
// We translate the key to the localized keyboard layout. However, we only support
|
// 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
|
// ASCII characters to make our translation easier across platforms. This is something
|
||||||
@ -320,19 +331,10 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Self.keycodes[event.keyCode] ?? GHOSTTY_KEY_INVALID
|
return unmapped_key
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ghostty_surface_key(surface, action, key, mods)
|
ghostty_surface_key(surface, action, key, unmapped_key, mods)
|
||||||
|
|
||||||
self.interpretKeyEvents([event])
|
|
||||||
}
|
|
||||||
|
|
||||||
override func keyUp(with event: NSEvent) {
|
|
||||||
guard let surface = self.surface else { return }
|
|
||||||
let key = Self.keycodes[event.keyCode] ?? GHOSTTY_KEY_INVALID
|
|
||||||
let mods = Self.translateFlags(event.modifierFlags)
|
|
||||||
ghostty_surface_key(surface, GHOSTTY_ACTION_RELEASE, key, mods)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: NSTextInputClient
|
// MARK: NSTextInputClient
|
||||||
|
@ -324,10 +324,11 @@ pub const Surface = struct {
|
|||||||
self: *Surface,
|
self: *Surface,
|
||||||
action: input.Action,
|
action: input.Action,
|
||||||
key: input.Key,
|
key: input.Key,
|
||||||
|
unmapped_key: input.Key,
|
||||||
mods: input.Mods,
|
mods: input.Mods,
|
||||||
) void {
|
) void {
|
||||||
// log.warn("key action={} key={} mods={}", .{ action, key, mods });
|
// log.warn("key action={} key={} mods={}", .{ action, key, mods });
|
||||||
self.core_surface.keyCallback(action, key, mods) catch |err| {
|
self.core_surface.keyCallback(action, key, unmapped_key, mods) catch |err| {
|
||||||
log.err("error in key callback err={}", .{err});
|
log.err("error in key callback err={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -460,11 +461,13 @@ pub const CAPI = struct {
|
|||||||
surface: *Surface,
|
surface: *Surface,
|
||||||
action: input.Action,
|
action: input.Action,
|
||||||
key: input.Key,
|
key: input.Key,
|
||||||
|
unmapped_key: input.Key,
|
||||||
mods: c_int,
|
mods: c_int,
|
||||||
) void {
|
) void {
|
||||||
surface.keyCallback(
|
surface.keyCallback(
|
||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
|
unmapped_key,
|
||||||
@bitCast(input.Mods, @truncate(u8, @bitCast(c_uint, mods))),
|
@bitCast(input.Mods, @truncate(u8, @bitCast(c_uint, mods))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user