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
126 // reference to the above group currently loaded in the main window. don't init,
127 // don't free, only update
128 GtkAccelGroup *active_group;
129
130 GHashTable *acceleratables; // Key/value list of path/dt_shortcut_t
131 gint reset; // ref counter of how many parts disconnected accels
132 GdkKeymap *keymap; // default screen keymap to decode key values
133 GdkModifierType default_mod_mask; // set of modifier masks relevant only to key strokes
134
135 // TRUE if we didn't find a keyboardrc config file at startup and we need to init a new one
136 gboolean init;
137
138 // between key_pressed and key_release events, this stores the active key strokes
139 GtkAccelKey active_key;
140
141 // Temporarily disable accelerators
143
144 GtkAccelFlags flags;
145
146 dt_pthread_mutex_t lock;
147
148 // Views can register a global callback to handle scroll events
149 // for example while keystrokes are on.
150 struct scroll
151 {
152 gboolean (*callback)(GdkEventScroll event, void *data);
153 void *data;
154 } scroll;
156
158{
159 DT_SHORTCUT_UNSET = 0, // shortcut non-inited
160 DT_SHORTCUT_DEFAULT = 1, // shortcut inited with compile-time defaults
161 DT_SHORTCUT_USER = 2 // shortcut changed by user config
163
164typedef struct dt_shortcut_t
165{
166 GtkWidget *widget; // link to the widget being accelerated. Can be NULL.
167 GList *closure; // GList of GClosures, aka callback + data being accelerated. Has to be non-NULL if widget is NULL.
168 char *path; // global path for that accel
169 const char *signal; // widget signal to be wired to that accel
170 GtkAccelGroup *accel_group; // the accel_group to which this shortcut belongs
171 guint key; // default key
172 GdkModifierType mods; // default modifier
174 gboolean locked; // if shortcut can't be changed by user
175 gboolean virtual_shortcut; // if shortcut is mapped to a key-pressed event handler instead of a global action callback
176 const char *description; // user-legible description of the action
177 dt_accels_t *accels; // back-reference for convenience
179
180
181dt_accels_t *dt_accels_init(char *config_file, GtkAccelFlags flags);
182void dt_accels_cleanup(dt_accels_t *accels);
183
184
185gchar *dt_accels_build_path(const gchar *scope, const gchar *feature);
186
194
195
202
203
212void dt_accels_connect_active_group(dt_accels_t *accels, const gchar *group);
213
220
221
234void dt_accels_new_virtual_shortcut(dt_accels_t *accels, GtkAccelGroup *accel_group, const gchar *accel_path,
235 GtkWidget *widget,
236 guint key_val, GdkModifierType accel_mods);
237
238
240 gboolean (*action_callback)(GtkAccelGroup *group,
241 GObject *acceleratable, guint keyval,
242 GdkModifierType mods, gpointer user_data),
243 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
244 const gchar *action_name);
245
259void dt_accels_new_widget_shortcut(dt_accels_t *accels, GtkWidget *widget, const gchar *signal,
260 GtkAccelGroup *accel_group, const gchar *accel_path, guint key_val,
261 GdkModifierType accel_mods, const gboolean lock);
262
263
289 gboolean (*action_callback)(GtkAccelGroup *group, GObject *acceleratable,
290 guint keyval, GdkModifierType mods,
291 gpointer user_data),
292 gpointer data, GtkAccelGroup *accel_group, const gchar *action_scope,
293 const gchar *action_name, guint key_val, GdkModifierType accel_mods,
294 const gboolean lock, const char *description);
295
296
305gboolean dt_accels_dispatch(GtkWidget *w, GdkEvent *event, gpointer user_data);
306
315void dt_accels_attach_scroll_handler(dt_accels_t *accels, gboolean (*callback)(GdkEventScroll event, void *data),
316 void *data);
317
319
320
321// Temporarily enable/disable keyboard accels, for example during GtkEntry typing.
322// Connect it from Gtk focus in/out event handlers
323static inline void dt_accels_disable(dt_accels_t *accels, gboolean state)
324{
325 accels->disable_accels = state;
326}
327
351void dt_accels_remove_accel(dt_accels_t *accels, const char *path, gpointer data);
352
359void dt_accels_remove_shortcut(dt_accels_t *accels, const char *path);
360
367void dt_accels_window(dt_accels_t *accels, GtkWindow *main_window);
368
369void 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:793
static void dt_accels_disable(dt_accels_t *accels, gboolean state)
Definition accelerators.h:323
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:376
void dt_accels_disconnect_active_group(dt_accels_t *accels)
Disconnect the contextual active accels group from the window.
Definition accelerators.c:397
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:1042
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:846
dt_accels_t * dt_accels_init(char *config_file, GtkAccelFlags flags)
Definition accelerators.c:326
void dt_accels_cleanup(dt_accels_t *accels)
Definition accelerators.c:352
dt_shortcut_type_t
Definition accelerators.h:158
@ DT_SHORTCUT_UNSET
Definition accelerators.h:159
@ DT_SHORTCUT_USER
Definition accelerators.h:161
@ DT_SHORTCUT_DEFAULT
Definition accelerators.h:160
void dt_accels_search(dt_accels_t *accels, GtkWindow *main_window, GtkWidget *anchor)
Definition accelerators.c:1964
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:1532
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:556
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:591
gchar * dt_accels_build_path(const gchar *scope, const gchar *feature)
Definition accelerators.c:854
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:831
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:741
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:631
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:686
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:1094
void dt_accels_detach_scroll_handler(dt_accels_t *accels)
Definition accelerators.c:1100
const char ** description(struct dt_iop_module_t *self)
Definition ashift.c:159
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
struct _GtkWidget GtkWidget
Definition splash.h:29
Definition accelerators.h:151
gboolean(* callback)(GdkEventScroll event, void *data)
Definition accelerators.h:152
void * data
Definition accelerators.h:153
Definition accelerators.h:120
GtkAccelFlags flags
Definition accelerators.h:144
gboolean disable_accels
Definition accelerators.h:142
GdkKeymap * keymap
Definition accelerators.h:132
gboolean init
Definition accelerators.h:136
GtkAccelKey active_key
Definition accelerators.h:139
GtkAccelGroup * global_accels
Definition accelerators.h:122
GtkAccelGroup * lighttable_accels
Definition accelerators.h:124
GdkModifierType default_mod_mask
Definition accelerators.h:133
char * config_file
Definition accelerators.h:121
dt_pthread_mutex_t lock
Definition accelerators.h:146
GHashTable * acceleratables
Definition accelerators.h:130
GtkAccelGroup * active_group
Definition accelerators.h:128
GtkAccelGroup * darkroom_accels
Definition accelerators.h:123
gint reset
Definition accelerators.h:131
Definition accelerators.h:165
GdkModifierType mods
Definition accelerators.h:172
GtkAccelGroup * accel_group
Definition accelerators.h:170
GList * closure
Definition accelerators.h:167
gboolean locked
Definition accelerators.h:174
dt_shortcut_type_t type
Definition accelerators.h:173
dt_accels_t * accels
Definition accelerators.h:177
GtkWidget * widget
Definition accelerators.h:166
gboolean virtual_shortcut
Definition accelerators.h:175
const char * signal
Definition accelerators.h:169
char * path
Definition accelerators.h:168
guint key
Definition accelerators.h:171
const char * description
Definition accelerators.h:176