summaryrefslogtreecommitdiff
path: root/src/shortcuts.c
blob: 6853490147823eca6680f93394e8b631580168bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*:*
 * ggaze — keybinding -> GAction map
 *
 * Default keybinding table bound to "win.*" actions. Milestones add rows here
 * as new actions land. See docs/ui-and-interactions.md keybindings table.
 *
 * Copyright (c) 2026 ggaze contributors
 * SPDX-License-Identifier: GPL-3.0-or-later
 *:*/

#include "shortcuts.h"

#include <gtk/gtk.h>

typedef struct {
   guint           u_keyval;
   GdkModifierType e_mods;
   const char     *c_action; /* e.g. "win.next" */
} ShortcutEntry;

static const ShortcutEntry SHORTCUTS[] = {
   /* navigation (decision #7: vi-style + cursor keys) */
   {GDK_KEY_h, 0, "win.prev"},
   {GDK_KEY_Left, 0, "win.prev"},
   {GDK_KEY_l, 0, "win.next"},
   {GDK_KEY_Right, 0, "win.next"},
   {GDK_KEY_g, 0, "win.first"},
   {GDK_KEY_G, 0, "win.last"},
   /* open / quit / back */
   {GDK_KEY_o, 0, "win.open"},
   {GDK_KEY_q, 0, "win.quit"},
   {GDK_KEY_d, 0, "win.trash"},
   {GDK_KEY_D, GDK_SHIFT_MASK, "win.delete"},
   {GDK_KEY_u, 0, "win.undo"},
   {GDK_KEY_t, 0, "win.toggle-view"},
   {GDK_KEY_plus, 0, "win.zoom-in"},
   {GDK_KEY_equal, 0, "win.zoom-in"},
   {GDK_KEY_minus, 0, "win.zoom-out"},
   {GDK_KEY_underscore, 0, "win.zoom-out"},
};

void
shortcuts_install(GtkWidget *p_widget) {
   g_return_if_fail(GTK_IS_WIDGET(p_widget));
   GtkEventController *p_ctrl = gtk_shortcut_controller_new();
   gtk_shortcut_controller_set_scope(GTK_SHORTCUT_CONTROLLER(p_ctrl),
                                     GTK_SHORTCUT_SCOPE_MANAGED);
   for (gsize u_i = 0; u_i < G_N_ELEMENTS(SHORTCUTS); u_i++) {
      GtkShortcut *p_s =
         gtk_shortcut_new(GTK_SHORTCUT_TRIGGER(gtk_keyval_trigger_new(
                             SHORTCUTS[u_i].u_keyval, SHORTCUTS[u_i].e_mods)),
                          gtk_named_action_new(SHORTCUTS[u_i].c_action));
      gtk_shortcut_controller_add_shortcut(GTK_SHORTCUT_CONTROLLER(p_ctrl),
                                           p_s);
   }
   gtk_widget_add_controller(p_widget, GTK_EVENT_CONTROLLER(p_ctrl));
}