Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
accelerators.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2011-2013 Jérémy Rosen.
4 Copyright (C) 2011 Robert Bieber.
5 Copyright (C) 2012 Richard Wonka.
6 Copyright (C) 2012, 2014, 2016-2017 Tobias Ellinghaus.
7 Copyright (C) 2016 Roman Lebedev.
8 Copyright (C) 2019-2020 Aldric Renaudin.
9 Copyright (C) 2020 Chris Elston.
10 Copyright (C) 2020-2022 Diederik Ter Rahe.
11 Copyright (C) 2020 Heiko Bauke.
12 Copyright (C) 2020 Hubert Kowalski.
13 Copyright (C) 2020-2021 Pascal Obry.
14 Copyright (C) 2021 Bill Ferguson.
15 Copyright (C) 2022 Martin Bařinka.
16 Copyright (C) 2023, 2025 Aurélien PIERRE.
17
18 darktable is free software: you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation, either version 3 of the License, or
21 (at your option) any later version.
22
23 darktable is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with darktable. If not, see <http://www.gnu.org/licenses/>.
30*/
31#include <gdk/gdkkeysyms.h>
32#include <gtk/gtk.h>
33#ifdef GDK_WINDOWING_WAYLAND
34#include <gdk/gdkwayland.h>
35#endif
36
37#include "common/dtpthread.h"
38
39#define DT_ACCELS_WIDGET_SHORTCUT_KEY "dt-accel-shortcut"
40#define DT_ACCELS_WIDGET_TOOLTIP_DISABLED_KEY "dt-accel-tooltip-disabled"
41
117#pragma once
118
119typedef struct dt_accels_t
120{
122 GtkAccelGroup *global_accels; // used, aka init it and free it
123 GtkAccelGroup *darkroom_accels; // darkroom-specific accels
124 GtkAccelGroup *lighttable_accels; // lighttable-specific accels
125 GtkAccelGroup *map_accels; // map-specific accels
126 GtkAccelGroup *print_accels; // print-specific accels
127 GtkAccelGroup *slideshow_accels; // slideshow-specific accels
128
129 // reference to the above group currently loaded in the main window. don't init,
130 // don't free, only update
131 GtkAccelGroup *active_group;
132
133 GHashTable *acceleratables; // Key/value list of path/dt_shortcut_t
134 gint reset; // ref counter of how many parts disconnected accels
135 GdkKeymap *keymap; // default screen keymap to decode key values
136 GdkModifierType default_mod_mask; // set of modifier masks relevant only to key strokes
137
138 // TRUE if we didn't find a keyboardrc config file at startup and we need to init a new one
139 gboolean init;
140
141 // between key_pressed and key_release events, this stores the active key strokes
142 GtkAccelKey active_key;
143
144 // Temporarily disable accelerators
146
147 GtkAccelFlags flags;
148
149 dt_pthread_mutex_t lock;
150
151 // Views can register a global callback to handle scroll events
152 // for example while keystrokes are on.
153 struct scroll
154 {
155 gboolean (*callback)(GdkEventScroll event, void *data);
156 void *data;
157 } scroll;
159
161{
162 DT_SHORTCUT_UNSET = 0, // shortcut non-inited
163 DT_SHORTCUT_DEFAULT = 1, // shortcut inited with compile-time defaults
164 DT_SHORTCUT_USER = 2 // shortcut changed by user config
166
167typedef struct dt_shortcut_t
168{
169 GtkWidget *widget; // link to the widget being accelerated. Can be NULL.
170 GList *closure; // GList of GClosures, aka callback + data being accelerated. Has to be non-NULL if widget is NULL.
171 char *path; // global path for that accel
172 const char *signal; // widget signal to be wired to that accel
173 GtkAccelGroup *accel_group; // the accel_group to which this shortcut belongs
174 guint key; // default key
175 GdkModifierType mods; // default modifier
177 gboolean locked; // if shortcut can't be changed by user
178 gboolean virtual_shortcut; // if shortcut is mapped to a key-pressed event handler instead of a global action callback
179 const char *description; // user-legible description of the action
180 dt_accels_t *accels; // back-reference for convenience
182
183
184dt_accels_t *dt_accels_init(char *config_file, GtkAccelFlags flags);
185void dt_accels_cleanup(dt_accels_t *accels);
186
187
188gchar *dt_accels_build_path(const gchar *scope, const gchar *feature);
189
197
198
205
206
215void dt_accels_connect_active_group(dt_accels_t *accels, const gchar *group);
216
223
224
237void dt_accels_new_virtual_shortcut(dt_accels_t *accels, GtkAccelGroup *accel_group, const gchar *accel_path,
238 GtkWidget *widget,
239 guint key_val, GdkModifierType accel_mods);
240
241
243 gboolean (*action_callback)(GtkAccelGroup *group,
244 GObject *acceleratable, guint keyval,
245 GdkModifierType mods, gpointer user_data),
246 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
247 const gchar *action_name);
248
262void dt_accels_new_widget_shortcut(dt_accels_t *accels, GtkWidget *widget, const gchar *signal,
263 GtkAccelGroup *accel_group, const gchar *accel_path, guint key_val,
264 GdkModifierType accel_mods, const gboolean lock);
265
266
292 gboolean (*action_callback)(GtkAccelGroup *group, GObject *acceleratable,
293 guint keyval, GdkModifierType mods,
294 gpointer user_data),
295 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
296 const gchar *action_name, guint key_val, GdkModifierType accel_mods,
297 const gboolean lock, const char *description);
298
299
308gboolean dt_accels_dispatch(GtkWidget *w, GdkEvent *event, gpointer user_data);
309
318void dt_accels_attach_scroll_handler(dt_accels_t *accels, gboolean (*callback)(GdkEventScroll event, void *data),
319 void *data);
320
322
323
324// Temporarily enable/disable keyboard accels, for example during GtkEntry typing.
325// Connect it from Gtk focus in/out event handlers
326static inline void dt_accels_disable(dt_accels_t *accels, gboolean state)
327{
328 accels->disable_accels = state;
329}
330
354void dt_accels_remove_accel(dt_accels_t *accels, const char *path, gpointer data);
355
362void dt_accels_remove_shortcut(dt_accels_t *accels, const char *path);
363
370void dt_accels_window(dt_accels_t *accels, GtkWindow *main_window);
371
372void dt_accels_search(dt_accels_t *accels, GtkWindow *main_window, GtkWidget *anchor);
void dt_accels_connect_accels(dt_accels_t *accels)
Actually enable accelerators after having loaded user config.
Definition accelerators.c:821
static void dt_accels_disable(dt_accels_t *accels, gboolean state)
Definition accelerators.h:326
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:386
void dt_accels_disconnect_active_group(dt_accels_t *accels)
Disconnect the contextual active accels group from the window.
Definition accelerators.c:422
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:1070
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:874
dt_accels_t * dt_accels_init(char *config_file, GtkAccelFlags flags)
Definition accelerators.c:327
void dt_accels_cleanup(dt_accels_t *accels)
Definition accelerators.c:356
dt_shortcut_type_t
Definition accelerators.h:161
@ DT_SHORTCUT_UNSET
Definition accelerators.h:162
@ DT_SHORTCUT_USER
Definition accelerators.h:164
@ DT_SHORTCUT_DEFAULT
Definition accelerators.h:163
void dt_accels_search(dt_accels_t *accels, GtkWindow *main_window, GtkWidget *anchor)
Definition accelerators.c:2019
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:1586
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:582
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:617
gchar * dt_accels_build_path(const gchar *scope, const gchar *feature)
Definition accelerators.c:882
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:859
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:769
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:657
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:712
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:1128
void dt_accels_detach_scroll_handler(dt_accels_t *accels)
Definition accelerators.c:1134
const char ** description(struct dt_iop_module_t *self)
Definition ashift.c:160
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
struct _GtkWidget GtkWidget
Definition splash.h:29
const float uint32_t state[4]
Definition src/develop/noise_generator.h:72
Definition accelerators.h:154
gboolean(* callback)(GdkEventScroll event, void *data)
Definition accelerators.h:155
void * data
Definition accelerators.h:156
Definition accelerators.h:120
GtkAccelFlags flags
Definition accelerators.h:147
gboolean disable_accels
Definition accelerators.h:145
GdkKeymap * keymap
Definition accelerators.h:135
gboolean init
Definition accelerators.h:139
GtkAccelGroup * slideshow_accels
Definition accelerators.h:127
GtkAccelKey active_key
Definition accelerators.h:142
GtkAccelGroup * map_accels
Definition accelerators.h:125
GtkAccelGroup * global_accels
Definition accelerators.h:122
GtkAccelGroup * print_accels
Definition accelerators.h:126
GtkAccelGroup * lighttable_accels
Definition accelerators.h:124
GdkModifierType default_mod_mask
Definition accelerators.h:136
char * config_file
Definition accelerators.h:121
dt_pthread_mutex_t lock
Definition accelerators.h:149
GHashTable * acceleratables
Definition accelerators.h:133
GtkAccelGroup * active_group
Definition accelerators.h:131
GtkAccelGroup * darkroom_accels
Definition accelerators.h:123
gint reset
Definition accelerators.h:134
Definition accelerators.h:168
GdkModifierType mods
Definition accelerators.h:175
GtkAccelGroup * accel_group
Definition accelerators.h:173
GList * closure
Definition accelerators.h:170
gboolean locked
Definition accelerators.h:177
dt_shortcut_type_t type
Definition accelerators.h:176
dt_accels_t * accels
Definition accelerators.h:180
GtkWidget * widget
Definition accelerators.h:169
gboolean virtual_shortcut
Definition accelerators.h:178
const char * signal
Definition accelerators.h:172
char * path
Definition accelerators.h:171
guint key
Definition accelerators.h:174
const char * description
Definition accelerators.h:179