apprt/embedded: API for checking if there are global keybinds

This commit is contained in:
Mitchell Hashimoto
2024-09-23 20:45:46 -07:00
parent c5eeb514cd
commit 0f3f01483e
2 changed files with 19 additions and 0 deletions

View File

@ -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();

View File

@ -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 .{};