diff --git a/include/ghostty.h b/include/ghostty.h index 798957b50..d2d74ea6c 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -293,7 +293,7 @@ void ghostty_surface_refresh(ghostty_surface_t); void ghostty_surface_set_content_scale(ghostty_surface_t, double, double); void ghostty_surface_set_focus(ghostty_surface_t, bool); 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_key_e, ghostty_input_mods_e); +void ghostty_surface_key(ghostty_surface_t, ghostty_input_action_e, uint32_t, ghostty_input_mods_e); 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_pos(ghostty_surface_t, double, double); @@ -308,9 +308,6 @@ void ghostty_surface_binding_action(ghostty_surface_t, ghostty_binding_action_e, // Don't use these unless you know what you're doing. void ghostty_set_window_background_blur(ghostty_surface_t, void *); -// TODO new key processing API -void ghostty_surface_key2(ghostty_surface_t, ghostty_input_action_e, uint32_t, ghostty_input_mods_e); - #ifdef __cplusplus } #endif diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index cb32a7ccf..4892dd248 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -382,20 +382,6 @@ pub const Surface = struct { } pub fn keyCallback( - self: *Surface, - action: input.Action, - key: input.Key, - unmapped_key: input.Key, - mods: input.Mods, - ) void { - // log.warn("key action={} key={} mods={}", .{ action, key, mods }); - self.core_surface.keyCallback(action, key, unmapped_key, mods) catch |err| { - log.err("error in key callback err={}", .{err}); - return; - }; - } - - pub fn key2Callback( self: *Surface, action: input.Action, keycode: u32, @@ -412,14 +398,14 @@ pub const Surface = struct { mods, ); - log.warn("TRANSLATE: action={} keycode={x} dead={} key={any} key_str={s} mods={}", .{ - action, - keycode, - result.composing, - result.text, - result.text, - mods, - }); + // log.warn("TRANSLATE: action={} keycode={x} dead={} key={any} key_str={s} mods={}", .{ + // action, + // keycode, + // result.composing, + // result.text, + // result.text, + // mods, + // }); // If this is a dead key, then we're composing a character and // we end processing here. We don't process keybinds for dead keys. @@ -625,30 +611,20 @@ pub const CAPI = struct { surface.focusCallback(focused); } - /// Tell the surface that it needs to schedule a render + /// Send this for raw keypresses (i.e. the keyDown event on macOS). + /// This will handle the keymap translation and send the appropriate + /// key and char events. + /// + /// You do NOT need to also send "ghostty_surface_char" unless + /// you want to send a unicode character that is not associated + /// with a keypress, i.e. IME keyboard. export fn ghostty_surface_key( - surface: *Surface, - action: input.Action, - key: input.Key, - unmapped_key: input.Key, - mods: c_int, - ) void { - surface.keyCallback( - action, - key, - unmapped_key, - @bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(mods))))), - ); - } - - /// TODO: new key processing - export fn ghostty_surface_key2( surface: *Surface, action: input.Action, keycode: u32, c_mods: c_int, ) void { - surface.key2Callback( + surface.keyCallback( action, keycode, @bitCast(@as(u8, @truncate(@as(c_uint, @bitCast(c_mods))))), @@ -658,7 +634,9 @@ pub const CAPI = struct { }; } - /// Tell the surface that it needs to schedule a render + /// Send for a unicode character. This is used for IME input. This + /// should only be sent for characters that are not the result of + /// key events. export fn ghostty_surface_char(surface: *Surface, codepoint: u32) void { surface.charCallback(codepoint); }