diff --git a/include/ghostty.h b/include/ghostty.h index 072a8536a..676cbd5e0 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -531,6 +531,7 @@ void ghostty_app_keyboard_changed(ghostty_app_t); void ghostty_app_open_config(ghostty_app_t); void ghostty_app_reload_config(ghostty_app_t); bool ghostty_app_needs_confirm_quit(ghostty_app_t); +bool ghostty_app_has_global_keybinds(ghostty_app_t); ghostty_surface_config_s ghostty_surface_config_new(); diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index b59ab1c9d..be3df896a 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -161,6 +161,19 @@ pub const App = struct { self.keymap.deinit(); } + /// Returns true if there are any global keybinds in the configuration. + pub fn hasGlobalKeybinds(self: *const App) bool { + var it = self.config.keybind.set.bindings.iterator(); + while (it.next()) |entry| { + switch (entry.value_ptr.*) { + .leader => {}, + .leaf => |leaf| if (leaf.flags.global) return true, + } + } + + return false; + } + /// This should be called whenever the keyboard layout was changed. pub fn reloadKeymap(self: *App) !void { // Reload the keymap @@ -1514,6 +1527,11 @@ pub const CAPI = struct { return v.core_app.needsConfirmQuit(); } + /// Returns true if the app has global keybinds. + export fn ghostty_app_has_global_keybinds(v: *App) bool { + return v.hasGlobalKeybinds(); + } + /// Returns initial surface options. export fn ghostty_surface_config_new() apprt.Surface.Options { return .{};