diff --git a/include/ghostty.h b/include/ghostty.h index 5ec1885b0..598ce675b 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -1078,6 +1078,7 @@ GHOSTTY_API bool ghostty_config_get(ghostty_config_t, void*, const char*, uintpt GHOSTTY_API ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t, const char*, uintptr_t); +GHOSTTY_API bool ghostty_config_key_is_binding(ghostty_config_t, ghostty_input_key_s); GHOSTTY_API uint32_t ghostty_config_diagnostics_count(ghostty_config_t); GHOSTTY_API ghostty_diagnostic_s ghostty_config_get_diagnostic(ghostty_config_t, uint32_t); GHOSTTY_API ghostty_string_s ghostty_config_open_path(void); @@ -1089,7 +1090,6 @@ GHOSTTY_API void ghostty_app_tick(ghostty_app_t); GHOSTTY_API void* ghostty_app_userdata(ghostty_app_t); GHOSTTY_API void ghostty_app_set_focus(ghostty_app_t, bool); GHOSTTY_API bool ghostty_app_key(ghostty_app_t, ghostty_input_key_s); -GHOSTTY_API bool ghostty_app_key_is_binding(ghostty_app_t, ghostty_input_key_s); GHOSTTY_API void ghostty_app_keyboard_changed(ghostty_app_t); GHOSTTY_API void ghostty_app_open_config(ghostty_app_t); GHOSTTY_API void ghostty_app_update_config(ghostty_app_t, ghostty_config_t); diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 3342d1328..d4804cfe0 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -585,11 +585,11 @@ class AppDelegate: NSObject, guard NSApp.mainWindow == nil else { return event } // If this event as-is would result in a key binding then we send it. - if let app = ghostty.app { + if let app = ghostty.app, let config = ghostty.config.config { var ghosttyEvent = event.ghosttyKeyEvent(GHOSTTY_ACTION_PRESS) let match = (event.characters ?? "").withCString { ptr in ghosttyEvent.text = ptr - if !ghostty_app_key_is_binding(app, ghosttyEvent) { + if !ghostty_config_key_is_binding(config, ghosttyEvent) { return false } diff --git a/src/App.zig b/src/App.zig index 5446f4bf2..93ee7dea1 100644 --- a/src/App.zig +++ b/src/App.zig @@ -315,25 +315,6 @@ pub fn focusEvent(self: *App, focused: bool) void { self.focused = focused; } -/// Returns true if the given key event would trigger a keybinding -/// if it were to be processed. This is useful for determining if -/// a key event should be sent to the terminal or not. -pub fn keyEventIsBinding( - self: *App, - rt_app: *apprt.App, - event: input.KeyEvent, -) bool { - _ = self; - - switch (event.action) { - .release => return false, - .press, .repeat => {}, - } - - // If we have a keybinding for this event then we return true. - return rt_app.config.keybind.set.getEvent(event) != null; -} - /// Handle a key event at the app-scope. If this key event is used, /// this will return true and the caller shouldn't continue processing /// the event. If the event is not used, this will return false. diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index ad20cf465..730913eba 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -1466,8 +1466,8 @@ pub const CAPI = struct { /// if it were sent to the surface right now. The "right now" /// is important because things like trigger sequences are only /// valid until the next key event. - export fn ghostty_app_key_is_binding( - app: *App, + export fn ghostty_config_key_is_binding( + config: *Config, event: KeyEvent, ) bool { const core_event = event.keyEvent().core() orelse { @@ -1475,7 +1475,7 @@ pub const CAPI = struct { return false; }; - return app.core_app.keyEventIsBinding(app, core_event); + return config.keyEventIsBinding(core_event); } /// Notify the app that the keyboard was changed. This causes the diff --git a/src/config/Config.zig b/src/config/Config.zig index 13f78eea6..d981df67b 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -6397,6 +6397,22 @@ pub const RepeatableFontVariation = struct { } }; +/// Returns true if the given key event would trigger a keybinding +/// if it were to be processed. This is useful for determining if +/// a key event should be sent to the terminal or not. +pub fn keyEventIsBinding( + self: *Config, + event: inputpkg.KeyEvent, +) bool { + switch (event.action) { + .release => return false, + .press, .repeat => {}, + } + + // If we have a keybinding for this event then we return true. + return self.keybind.set.getEvent(event) != null; +} + /// Stores a set of keybinds. pub const Keybinds = struct { set: inputpkg.Binding.Set = .{},