Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
accelerators.h
Go to the documentation of this file.
1#include <gdk/gdkkeysyms.h>
2#include <gtk/gtk.h>
3#ifdef GDK_WINDOWING_WAYLAND
4#include <gdk/gdkwayland.h>
5#endif
6
7#include "common/dtpthread.h"
8
84#pragma once
85
86typedef struct dt_accels_t
87{
89 GtkAccelGroup *global_accels; // used, aka init it and free it
90 GtkAccelGroup *darkroom_accels; // darkroom-specific accels
91 GtkAccelGroup *lighttable_accels; // lighttable-specific accels
92
93 // reference to the above group currently loaded in the main window. don't init,
94 // don't free, only update
95 GtkAccelGroup *active_group;
96
97 GHashTable *acceleratables; // Key/value list of path/dt_shortcut_t
98 gint reset; // ref counter of how many parts disconnected accels
99 GdkKeymap *keymap; // default screen keymap to decode key values
100 GdkModifierType default_mod_mask; // set of modifier masks relevant only to key strokes
101
102 // TRUE if we didn't find a keyboardrc config file at startup and we need to init a new one
103 gboolean init;
104
105 // between key_pressed and key_release events, this stores the active key strokes
106 GtkAccelKey active_key;
107
108 // Temporarily disable accelerators
110
111 GtkAccelFlags flags;
112
113 dt_pthread_mutex_t lock;
114
115 // Views can register a global callback to handle scroll events
116 // for example while keystrokes are on.
117 struct scroll
118 {
119 gboolean (*callback)(GdkEventScroll event, void *data);
120 void *data;
121 } scroll;
123
125{
126 DT_SHORTCUT_UNSET = 0, // shortcut non-inited
127 DT_SHORTCUT_DEFAULT = 1, // shortcut inited with compile-time defaults
128 DT_SHORTCUT_USER = 2 // shortcut changed by user config
130
131typedef struct dt_shortcut_t
132{
133 GtkWidget *widget; // link to the widget being accelerated. Can be NULL.
134 GList *closure; // GList of GClosures, aka callback + data being accelerated. Has to be non-NULL if widget is NULL.
135 char *path; // global path for that accel
136 const char *signal; // widget signal to be wired to that accel
137 GtkAccelGroup *accel_group; // the accel_group to which this shortcut belongs
138 guint key; // default key
139 GdkModifierType mods; // default modifier
141 gboolean locked; // if shortcut can't be changed by user
142 gboolean virtual_shortcut; // if shortcut is mapped to a key-pressed event handler instead of a global action callback
143 const char *description; // user-legible description of the action
144 dt_accels_t *accels; // back-reference for convenience
146
147
148dt_accels_t *dt_accels_init(char *config_file, GtkAccelFlags flags);
149void dt_accels_cleanup(dt_accels_t *accels);
150
151
152gchar *dt_accels_build_path(const gchar *scope, const gchar *feature);
153
161
162
169
170
179void dt_accels_connect_active_group(dt_accels_t *accels, const gchar *group);
180
187
188
201void dt_accels_new_virtual_shortcut(dt_accels_t *accels, GtkAccelGroup *accel_group, const gchar *accel_path,
202 GtkWidget *widget,
203 guint key_val, GdkModifierType accel_mods);
204
205
207 gboolean (*action_callback)(GtkAccelGroup *group,
208 GObject *acceleratable, guint keyval,
209 GdkModifierType mods, gpointer user_data),
210 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
211 const gchar *action_name);
212
226void dt_accels_new_widget_shortcut(dt_accels_t *accels, GtkWidget *widget, const gchar *signal,
227 GtkAccelGroup *accel_group, const gchar *accel_path, guint key_val,
228 GdkModifierType accel_mods, const gboolean lock);
229
230
256 gboolean (*action_callback)(GtkAccelGroup *group, GObject *acceleratable,
257 guint keyval, GdkModifierType mods,
258 gpointer user_data),
259 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
260 const gchar *action_name, guint key_val, GdkModifierType accel_mods,
261 const gboolean lock, const char *description);
262
263
272gboolean dt_accels_dispatch(GtkWidget *w, GdkEvent *event, gpointer user_data);
273
282void dt_accels_attach_scroll_handler(dt_accels_t *accels, gboolean (*callback)(GdkEventScroll event, void *data),
283 void *data);
284
286
287
288// Temporarily enable/disable keyboard accels, for example during GtkEntry typing.
289// Connect it from Gtk focus in/out event handlers
290static inline void dt_accels_disable(dt_accels_t *accels, gboolean state)
291{
292 accels->disable_accels = state;
293}
294
318void dt_accels_remove_accel(dt_accels_t *accels, const char *path, gpointer data);
319
326void dt_accels_remove_shortcut(dt_accels_t *accels, const char *path);
327
334void dt_accels_window(dt_accels_t *accels, GtkWindow *main_window);
335
336void dt_accels_search(dt_accels_t *accels, GtkWindow *main_window);
void dt_accels_connect_accels(dt_accels_t *accels)
Actually enable accelerators after having loaded user config.
Definition accelerators.c:618
static void dt_accels_disable(dt_accels_t *accels, gboolean state)
Definition accelerators.h:290
void dt_accels_connect_active_group(dt_accels_t *accels, const gchar *group)
Connect the contextual active accels group to the window. Views can declare their own set of contextu...
Definition accelerators.c:211
void dt_accels_disconnect_active_group(dt_accels_t *accels)
Disconnect the contextual active accels group from the window.
Definition accelerators.c:232
gboolean dt_accels_dispatch(GtkWidget *w, GdkEvent *event, gpointer user_data)
Force our listener for all key strokes to bypass reserved Gtk keys.
Definition accelerators.c:822
void dt_accels_remove_shortcut(dt_accels_t *accels, const char *path)
Remove the shortcut object identified by path and all its accels.
Definition accelerators.c:671
dt_accels_t * dt_accels_init(char *config_file, GtkAccelFlags flags)
Definition accelerators.c:162
void dt_accels_search(dt_accels_t *accels, GtkWindow *main_window)
Definition accelerators.c:1524
void dt_accels_cleanup(dt_accels_t *accels)
Definition accelerators.c:187
dt_shortcut_type_t
Definition accelerators.h:125
@ DT_SHORTCUT_UNSET
Definition accelerators.h:126
@ DT_SHORTCUT_USER
Definition accelerators.h:128
@ DT_SHORTCUT_DEFAULT
Definition accelerators.h:127
void dt_accels_window(dt_accels_t *accels, GtkWindow *main_window)
Show the modal dialog listing all available keyboard shortcuts and letting user to set them.
Definition accelerators.c:1255
void dt_accels_new_virtual_shortcut(dt_accels_t *accels, GtkAccelGroup *accel_group, const gchar *accel_path, GtkWidget *widget, guint key_val, GdkModifierType accel_mods)
Add a new virtual shortcut. Virtual shortcuts are immutable, read-only and don't trigger any action....
Definition accelerators.c:391
void dt_accels_new_virtual_instance_shortcut(dt_accels_t *accels, gboolean(*action_callback)(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, gpointer user_data), gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope, const gchar *action_name)
Definition accelerators.c:419
gchar * dt_accels_build_path(const gchar *scope, const gchar *feature)
Definition accelerators.c:679
void dt_accels_remove_accel(dt_accels_t *accels, const char *path, gpointer data)
Recursively remove all accels for all shortcuts containing path. This is unneeded for accels attached...
Definition accelerators.c:656
void dt_accels_load_user_config(dt_accels_t *accels)
Loads keyboardrc.lang from config dir. This needs to run after we inited the accel map from widgets c...
Definition accelerators.c:566
void dt_accels_new_widget_shortcut(dt_accels_t *accels, GtkWidget *widget, const gchar *signal, GtkAccelGroup *accel_group, const gchar *accel_path, guint key_val, GdkModifierType accel_mods, const gboolean lock)
Register a new shortcut for a widget, setting up its path, default keys and accel group....
Definition accelerators.c:459
void dt_accels_new_action_shortcut(dt_accels_t *accels, gboolean(*action_callback)(GtkAccelGroup *group, GObject *acceleratable, guint keyval, GdkModifierType mods, gpointer user_data), gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope, const gchar *action_name, guint key_val, GdkModifierType accel_mods, const gboolean lock, const char *description)
Register a new shortcut for a generic action, setting up its path, default keys and accel group....
Definition accelerators.c:511
void dt_accels_attach_scroll_handler(dt_accels_t *accels, gboolean(*callback)(GdkEventScroll event, void *data), void *data)
Attach a new global scroll event callback. So far this is used in darkroom to redirect scroll events ...
Definition accelerators.c:868
void dt_accels_detach_scroll_handler(dt_accels_t *accels)
Definition accelerators.c:874
const char ** description(struct dt_iop_module_t *self)
Definition ashift.c:129
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
Definition accelerators.h:118
gboolean(* callback)(GdkEventScroll event, void *data)
Definition accelerators.h:119
void * data
Definition accelerators.h:120
Definition accelerators.h:87
GtkAccelFlags flags
Definition accelerators.h:111
gboolean disable_accels
Definition accelerators.h:109
GdkKeymap * keymap
Definition accelerators.h:99
gboolean init
Definition accelerators.h:103
GtkAccelKey active_key
Definition accelerators.h:106
GtkAccelGroup * global_accels
Definition accelerators.h:89
GtkAccelGroup * lighttable_accels
Definition accelerators.h:91
GdkModifierType default_mod_mask
Definition accelerators.h:100
char * config_file
Definition accelerators.h:88
dt_pthread_mutex_t lock
Definition accelerators.h:113
GHashTable * acceleratables
Definition accelerators.h:97
GtkAccelGroup * active_group
Definition accelerators.h:95
GtkAccelGroup * darkroom_accels
Definition accelerators.h:90
gint reset
Definition accelerators.h:98
Definition accelerators.h:132
GdkModifierType mods
Definition accelerators.h:139
GtkAccelGroup * accel_group
Definition accelerators.h:137
GList * closure
Definition accelerators.h:134
gboolean locked
Definition accelerators.h:141
dt_shortcut_type_t type
Definition accelerators.h:140
dt_accels_t * accels
Definition accelerators.h:144
GtkWidget * widget
Definition accelerators.h:133
gboolean virtual_shortcut
Definition accelerators.h:142
const char * signal
Definition accelerators.h:136
char * path
Definition accelerators.h:135
guint key
Definition accelerators.h:138
const char * description
Definition accelerators.h:143