Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
application.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2009-2014, 2016 johannes hanika.
4 Copyright (C) 2010 Alexandre Prokoudine.
5 Copyright (C) 2010-2014 Henrik Andersson.
6 Copyright (C) 2010, 2013-2014, 2016 Pascal de Bruijn.
7 Copyright (C) 2010 Richard Hughes.
8 Copyright (C) 2010 Stuart Henderson.
9 Copyright (C) 2010-2019 Tobias Ellinghaus.
10 Copyright (C) 2011 Antony Dovgal.
11 Copyright (C) 2011-2012, 2015 Jérémy Rosen.
12 Copyright (C) 2011 Moritz Lipp.
13 Copyright (C) 2011 Olivier Tribout.
14 Copyright (C) 2011 Robert Bieber.
15 Copyright (C) 2011-2013 Simon Spannagel.
16 Copyright (C) 2012, 2014, 2019-2022 Aldric Renaudin.
17 Copyright (C) 2012-2017, 2019-2020 parafin.
18 Copyright (C) 2012 Richard Wonka.
19 Copyright (C) 2013 Jochem Kossen.
20 Copyright (C) 2013, 2015, 2017-2022 Pascal Obry.
21 Copyright (C) 2013-2016, 2019-2020 Roman Lebedev.
22 Copyright (C) 2014 Mikhail Trishchenkov.
23 Copyright (C) 2015 Edouard Gomez.
24 Copyright (C) 2015 Pedro Côrte-Real.
25 Copyright (C) 2015, 2019 Ulrich Pegelow.
26 Copyright (C) 2016-2017 Peter Budai.
27 Copyright (C) 2017-2018, 2021 Dan Torop.
28 Copyright (C) 2017-2018 Matthieu Moy.
29 Copyright (C) 2017-2018 Rikard Öxler.
30 Copyright (C) 2018-2019 Edgardo Hoszowski.
31 Copyright (C) 2018 Mario Lueder.
32 Copyright (C) 2019-2020, 2022-2023, 2025-2026 Aurélien PIERRE.
33 Copyright (C) 2019 emeikei.
34 Copyright (C) 2019 Heiko Bauke.
35 Copyright (C) 2019 jakubfi.
36 Copyright (C) 2019 vacaboja.
37 Copyright (C) 2020 Bill Ferguson.
38 Copyright (C) 2020-2022 Chris Elston.
39 Copyright (C) 2020-2021 David-Tillmann Schaefer.
40 Copyright (C) 2020-2022 Diederik Ter Rahe.
41 Copyright (C) 2020 Hanno Schwalm.
42 Copyright (C) 2020 Harold le Clément de Saint-Marcq.
43 Copyright (C) 2020-2021 Hubert Kowalski.
44 Copyright (C) 2020 Marco.
45 Copyright (C) 2020, 2022 Miloš Komarčević.
46 Copyright (C) 2020-2021 Philippe Weyland.
47 Copyright (C) 2020 quovadit.
48 Copyright (C) 2020-2021 Ralf Brown.
49 Copyright (C) 2021 darkelectron.
50 Copyright (C) 2021 lhietal.
51 Copyright (C) 2021 luzpaz.
52 Copyright (C) 2022 Martin Bařinka.
53 Copyright (C) 2022 Nicolas Auffray.
54 Copyright (C) 2022 Roman Neuhauser.
55 Copyright (C) 2022 Victor Forsiuk.
56 Copyright (C) 2023 Luca Zulberti.
57 Copyright (C) 2023 Maurizio Paglia.
58 Copyright (C) 2025 Alynx Zhou.
59 Copyright (C) 2025-2026 Guillaume Stutin.
60
61 darktable is free software: you can redistribute it and/or modify
62 it under the terms of the GNU General Public License as published by
63 the Free Software Foundation, either version 3 of the License, or
64 (at your option) any later version.
65
66 darktable is distributed in the hope that it will be useful,
67 but WITHOUT ANY WARRANTY; without even the implied warranty of
68 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69 GNU General Public License for more details.
70
71 You should have received a copy of the GNU General Public License
72 along with darktable. If not, see <http://www.gnu.org/licenses/>.
73*/
74#include "darktable.h"
75#include "common/paths.h" // DT_PATH_MAX
76#include "metadata/colorlabels.h" // DT_COLORLABELS_*
77#include "gui/screen_metrics.h"
81#include "common/l10n.h"
83#include "common/utility.h"
84#include "gui/guides.h"
85#include "gui/import.h"
86#include "widgets/expander.h"
87
88#include "common/collection.h"
89#include "common/selection.h"
90#include "gui/application.h"
92#include "gui/common/film_gui.h"
98#include "gui/splash.h"
99#include "gui/closing.h"
100#include "gui/alert.h"
102
103#include "common/conf.h"
104#include "control/control.h"
105#include "control/jobs.h"
106#include "control/signal.h"
107#include "gui/presets.h"
108#include "views/view.h"
109
110#include <gdk/gdkkeysyms.h>
111#ifdef GDK_WINDOWING_WAYLAND
112#include <gdk/gdkwayland.h>
113#endif
114#ifdef _WIN32
115#include <gdk/gdkwin32.h>
116#endif
117#include <gtk/gtk.h>
118#include <math.h>
119#include <stdlib.h>
120#include <stdio.h>
121#include <string.h>
122#include "widgets/container.h"
123#include "widgets/widget_style.h"
124#ifdef MAC_INTEGRATION
125#include <gtkosxapplication.h>
126#endif
127#ifdef GDK_WINDOWING_QUARTZ
128#include "osx/osx.h"
129#endif
130
131/*
132 * NEW UI API
133 */
134
135/* generic callback for redraw widget signals */
136
137/* widgets/ carries its own colour-label indices so it needs no application header. This is
138 * the only place both enums are visible, so this is where they are pinned together. */
139_Static_assert((int)DT_WIDGET_COLORLABEL_RED == (int)DT_COLORLABELS_RED
142 "widget colour-label indices drifted from dt_colorlabels_enum");
143
144static void _update_display_profile(void);
145static void _ui_widget_redraw_callback(gpointer instance, GtkWidget *widget);
146/* callback for redraw log signals */
147static void _ui_log_redraw_callback(gpointer instance, GtkWidget *widget);
148static void _ui_toast_redraw_callback(gpointer instance, GtkWidget *widget);
149
150// set class function to add CSS classes with just a simple line call
151
152
153
154/* ------------------------------------------------------------------------------------------
155 * Widget-callback suppression depth (see darktable.h for the rationale and API).
156 * ------------------------------------------------------------------------------------------ */
157/* Sub-handle accessors for the GUI singleton (declared in gui/application.h). The orchestrator
158 * binds darktable.gui via dt_gui_get_global(); these narrow it to the parts callers
159 * actually want, so they stop walking the application struct. */
161{
162 return dt_gui_get_global()->ui;
163}
164
166{
167 return dt_gui_get_global()->accels;
168}
169
174
179
180
181
182
183
184/*
185 * OLD UI API
186 */
187static void _init_widgets(dt_gui_gtk_t *gui);
188static gboolean _configure(GtkWidget *da, GdkEventConfigure *event, gpointer user_data);
189
190
191
192
193static gboolean _draw(GtkWidget *da, cairo_t *cr, gpointer user_data)
194{
195 /* cr is GTK's double buffer, clipped to what was invalidated; the centre paints into it */
196 dt_control_expose(cr, gtk_widget_get_allocated_width(da), gtk_widget_get_allocated_height(da));
197 return TRUE;
198}
199
200
201static gboolean _scrolled(GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
202{
203 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
204
205 int delta_y;
206 if(dt_gui_get_scroll_unit_delta(event, &delta_y))
207 {
208 return dt_view_manager_scrolled(darktable.view_manager, event->x, event->y,
209 delta_y < 0,
210 event->state, delta_y);
211 }
212
213 return FALSE;
214}
215
216
218{
219 dt_pthread_mutex_lock(&darktable.gui->mutex);
220 GtkWidget *widget = dt_ui_main_window(darktable.gui->ui);
221 const GdkWindowState window_state = gdk_window_get_state(gtk_widget_get_window(widget));
222 dt_conf_set_bool("ui_last/maximized", (window_state & GDK_WINDOW_STATE_MAXIMIZED));
223 int width, height;
224 gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
225 dt_conf_set_int("ui_last/window_width", width);
226 dt_conf_set_int("ui_last/window_height", height);
227
228 gboolean save_window_position = TRUE;
229#ifdef GDK_WINDOWING_WAYLAND
230 GdkDisplay *display = gtk_widget_get_display(widget);
231 if(GDK_IS_WAYLAND_DISPLAY(display))
232 save_window_position = FALSE;
233#endif
234
235 if(save_window_position)
236 {
237 GdkWindow *gdk_window = gtk_widget_get_window(widget);
238 GdkDisplay *window_display = gtk_widget_get_display(widget);
239 if(!IS_NULL_PTR(gdk_window) && !IS_NULL_PTR(window_display))
240 {
241 GdkMonitor *monitor = gdk_display_get_monitor_at_window(window_display, gdk_window);
242 if(!IS_NULL_PTR(monitor))
243 {
244 const int n_monitors = gdk_display_get_n_monitors(window_display);
245 int monitor_index = -1;
246 for(int i = 0; i < n_monitors; i++)
247 {
248 if(gdk_display_get_monitor(window_display, i) == monitor)
249 {
250 monitor_index = i;
251 break;
252 }
253 }
254 if(monitor_index >= 0)
255 dt_conf_set_int("ui_last/window_monitor", monitor_index);
256 }
257 }
258
259 if(!(window_state & GDK_WINDOW_STATE_MAXIMIZED))
260 {
261 int x, y;
262 gtk_window_get_position(GTK_WINDOW(widget), &x, &y);
263 dt_conf_set_int("ui_last/window_x", x);
264 dt_conf_set_int("ui_last/window_y", y);
265 }
266 }
267
269
270 return 0;
271}
272
273
275{
276 GtkWidget *win = dt_ui_main_window(darktable.gui->ui);
277 dt_gui_add_class(win, "dt_gui_quit");
278 gtk_window_set_title(GTK_WINDOW(win), _("Closing Ansel..."));
279
281
282 // Write out windows dimension
284
285 // hide main window
286 gtk_widget_hide(dt_ui_main_window(darktable.gui->ui));
287}
288
289gboolean dt_gui_quit_callback(GtkWidget *widget, GdkEvent *event, gpointer user_data)
290{
292 return TRUE;
293}
294
296{
297 dt_free(darktable.gui->last_preset);
298 darktable.gui->last_preset = g_strdup(name);
299}
300
301#ifdef MAC_INTEGRATION
302#ifdef GTK_TYPE_OSX_APPLICATION
303static gboolean _osx_quit_callback(GtkOSXApplication *OSXapp, gpointer user_data)
304#else
305static gboolean _osx_quit_callback(GtkosxApplication *OSXapp, gpointer user_data)
306#endif
307{
308 GList *windows, *window;
309 windows = gtk_window_list_toplevels();
310 for(window = windows; !IS_NULL_PTR(window); window = g_list_next(window))
311 if(gtk_window_get_modal(GTK_WINDOW(window->data)) && gtk_widget_get_visible(GTK_WIDGET(window->data)))
312 break;
314 g_list_free(windows);
315 windows = NULL;
316 return TRUE;
317}
318
319#ifdef GTK_TYPE_OSX_APPLICATION
320static gboolean _osx_openfile_callback(GtkOSXApplication *OSXapp, gchar *path, gpointer user_data)
321#else
322static gboolean _osx_openfile_callback(GtkosxApplication *OSXapp, gchar *path, gpointer user_data)
323#endif
324{
325 return dt_load_from_string(path, TRUE, NULL) > 0;
326}
327#endif
328
329static gboolean _configure(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
330{
331 static int oldw = 0;
332 static int oldh = 0;
333 if(oldw != event->width || oldh != event->height)
334 {
335 // maybe we are on another screen now with > 50% of the area
337 }
338 oldw = event->width;
339 oldh = event->height;
340
341#ifndef GDK_WINDOWING_QUARTZ
342 dt_configure_ppd_dpi((dt_gui_gtk_t *) user_data);
343#endif
344
345 return dt_control_configure(da, event, user_data);
346}
347
348static gboolean _window_configure(GtkWidget *da, GdkEvent *event, gpointer user_data)
349{
350 static int oldx = 0;
351 static int oldy = 0;
352 if(oldx != event->configure.x || oldy != event->configure.y)
353 {
354 // maybe we are on another screen now with > 50% of the area
356 oldx = event->configure.x;
357 oldy = event->configure.y;
358 }
359 return FALSE;
360}
361
363{
364 gboolean valid;
365 double x;
366 double y;
367 guint32 time_ms;
370 double pressure;
371 gboolean have_tilt;
372 double tilt_x;
373 double tilt_y;
375
377
378static inline double _clamp01d(const double value)
379{
380 return MIN(1.0, MAX(0.0, value));
381}
382
383static const gdouble *_event_axes(const GdkEvent *event)
384{
385 if(IS_NULL_PTR(event)) return NULL;
386 switch(event->type)
387 {
388 case GDK_MOTION_NOTIFY:
389 return ((const GdkEventMotion *)event)->axes;
390 case GDK_BUTTON_PRESS:
391 case GDK_2BUTTON_PRESS:
392 case GDK_3BUTTON_PRESS:
393 case GDK_BUTTON_RELEASE:
394 return ((const GdkEventButton *)event)->axes;
395 default:
396 return NULL;
397 }
398}
399
400static gboolean _get_axis_value_for_source(const GdkEvent *event, GdkDevice *source_device,
401 const GdkAxisUse axis, double *value, gboolean *from_source_map)
402{
403 if(from_source_map) *from_source_map = FALSE;
404 if(IS_NULL_PTR(value)) return FALSE;
405
406 const gdouble *axes = _event_axes(event);
407 if(source_device && axes)
408 {
409 double source_value = 0.0;
410 if(gdk_device_get_axis(source_device, (gdouble *)axes, axis, &source_value))
411 {
412 *value = source_value;
413 if(from_source_map) *from_source_map = TRUE;
414 return TRUE;
415 }
416 }
417
418 return gdk_event_get_axis((GdkEvent *)event, axis, value);
419}
420
421static gboolean _sample_axis_from_device_state(GdkWindow *window, GdkDevice *device,
422 const GdkAxisUse axis, double *value)
423{
424 if(IS_NULL_PTR(window) || IS_NULL_PTR(device) || IS_NULL_PTR(value)) return FALSE;
425 if(gdk_device_get_source(device) == GDK_SOURCE_KEYBOARD) return FALSE;
426 if(gdk_device_get_device_type(device) == GDK_DEVICE_TYPE_SLAVE)
427 {
428 GdkDisplay *display = gdk_device_get_display(device);
429 if(!display || !gdk_display_device_is_grabbed(display, device)) return FALSE;
430 }
431
432 const int n_axes = gdk_device_get_n_axes(device);
433 if(n_axes <= 0) return FALSE;
434
435 double *axes = g_newa(double, n_axes);
436 memset(axes, 0, sizeof(double) * n_axes);
437 GdkModifierType modifiers = 0;
438 gdk_device_get_state(device, window, axes, &modifiers);
439 return gdk_device_get_axis(device, axes, axis, value);
440}
441
442static gboolean _sample_tablet_state_from_devices(const GdkEvent *event,
443 double *pressure, gboolean *have_pressure,
444 double *tilt_x, double *tilt_y, gboolean *have_tilt,
445 const char **picked_device_name)
446{
447 if(pressure) *pressure = 0.0;
448 if(have_pressure) *have_pressure = FALSE;
449 if(tilt_x) *tilt_x = 0.0;
450 if(tilt_y) *tilt_y = 0.0;
451 if(have_tilt) *have_tilt = FALSE;
452 if(picked_device_name) *picked_device_name = NULL;
453
454 if(IS_NULL_PTR(darktable.gui)) return FALSE;
455 GdkWindow *window = gdk_event_get_window((GdkEvent *)event);
456 if(IS_NULL_PTR(window)) window = gtk_widget_get_window(dt_ui_center(darktable.gui->ui));
457 if(IS_NULL_PTR(window)) return FALSE;
458
459 int best_score = -1;
460 double best_p = 0.0;
461 gboolean best_have_p = FALSE;
462 double best_tx = 0.0;
463 double best_ty = 0.0;
464 gboolean best_have_t = FALSE;
465 const char *best_name = NULL;
466
467 GdkSeat *seat = gdk_display_get_default() ? gdk_display_get_default_seat(gdk_display_get_default()) : NULL;
468 GList *runtime_devices = seat ? gdk_seat_get_slaves(seat, GDK_SEAT_CAPABILITY_ALL_POINTING) : NULL;
469
470 for(GList *l = runtime_devices; l; l = g_list_next(l))
471 {
472 GdkDevice *device = (GdkDevice *)l->data;
473 if(IS_NULL_PTR(device)) continue;
474 const GdkInputSource source = gdk_device_get_source(device);
475 if(source == GDK_SOURCE_KEYBOARD) continue;
476 if(gdk_device_get_device_type(device) == GDK_DEVICE_TYPE_SLAVE)
477 {
478 GdkDisplay *display = gdk_device_get_display(device);
479 /* gdk_device_get_state() requires slave devices to be grabbed.
480 * Skip non-grabbed slaves to avoid GTK/GDK criticals. */
481 if(!display || !gdk_display_device_is_grabbed(display, device)) continue;
482 }
483
484 const GdkAxisFlags axis_flags = gdk_device_get_axes(device);
485 const gboolean supports_pressure = (axis_flags & GDK_AXIS_FLAG_PRESSURE) != 0;
486 const gboolean supports_x_tilt = (axis_flags & GDK_AXIS_FLAG_XTILT) != 0;
487 const gboolean supports_y_tilt = (axis_flags & GDK_AXIS_FLAG_YTILT) != 0;
488 const gboolean pen_like = (source == GDK_SOURCE_PEN || source == GDK_SOURCE_ERASER || source == GDK_SOURCE_CURSOR);
489 if(!supports_pressure && !supports_x_tilt && !supports_y_tilt && !pen_like) continue;
490
491 const int n_axes = gdk_device_get_n_axes(device);
492 if(n_axes <= 0) continue;
493 double *axes = g_newa(double, n_axes);
494 memset(axes, 0, sizeof(double) * n_axes);
495 GdkModifierType modifiers = 0;
496 gdk_device_get_state(device, window, axes, &modifiers);
497
498 double p = 0.0;
499 gboolean have_p = FALSE;
500 double tx = 0.0;
501 double ty = 0.0;
502 gboolean have_tx = FALSE;
503 gboolean have_ty = FALSE;
504
505 for(int i = 0; i < n_axes; i++)
506 {
507 const GdkAxisUse use = gdk_device_get_axis_use(device, i);
508 if(use == GDK_AXIS_PRESSURE)
509 {
510 p = axes[i];
511 have_p = TRUE;
512 }
513 else if(use == GDK_AXIS_XTILT)
514 {
515 tx = axes[i];
516 have_tx = TRUE;
517 }
518 else if(use == GDK_AXIS_YTILT)
519 {
520 ty = axes[i];
521 have_ty = TRUE;
522 }
523 }
524
525 const gboolean have_t = have_tx || have_ty;
526 const int score = (have_p ? 2 : 0) + (have_t ? 2 : 0) + (p > 1e-4 ? 4 : 0)
527 + ((hypot(tx, ty) > 1e-4) ? 3 : 0) + (pen_like ? 1 : 0);
528 if(score <= best_score) continue;
529
530 best_score = score;
531 best_p = p;
532 best_have_p = have_p;
533 best_tx = tx;
534 best_ty = ty;
535 best_have_t = have_t;
536 best_name = gdk_device_get_name(device);
537 }
538 if(runtime_devices)
539 {
540 g_list_free(runtime_devices);
541 runtime_devices = NULL;
542 }
543
544 if(best_score < 0) return FALSE;
545 if(pressure) *pressure = best_p;
546 if(have_pressure) *have_pressure = best_have_p;
547 if(tilt_x) *tilt_x = best_tx;
548 if(tilt_y) *tilt_y = best_ty;
549 if(have_tilt) *have_tilt = best_have_t;
550 if(picked_device_name) *picked_device_name = best_name;
551 return TRUE;
552}
553
554static dt_control_pointer_input_t _extract_pointer_input(const GdkEvent *event, const double x, const double y,
555 const guint32 time_ms, const gboolean reset_kinematics,
556 const char *tag)
557{
558 dt_control_pointer_input_t input = { 0 };
559 input.x = x;
560 input.y = y;
561 input.time_ms = time_ms;
562 GdkDevice *source_device = gdk_event_get_source_device((GdkEvent *)event);
563 GdkDevice *event_device = gdk_event_get_device((GdkEvent *)event);
564 GdkDevice *device = source_device ? source_device : event_device;
565 const GdkInputSource source = device ? gdk_device_get_source(device) : GDK_SOURCE_MOUSE;
566 const GdkAxisFlags axis_flags = device ? gdk_device_get_axes(device) : 0;
567 const gboolean supports_pressure = (axis_flags & GDK_AXIS_FLAG_PRESSURE) != 0;
568 const gboolean supports_x_tilt = (axis_flags & GDK_AXIS_FLAG_XTILT) != 0;
569 const gboolean supports_y_tilt = (axis_flags & GDK_AXIS_FLAG_YTILT) != 0;
570 gboolean read_pressure = FALSE;
571 gboolean read_x_tilt = FALSE;
572 gboolean read_y_tilt = FALSE;
573 gboolean map_pressure_source = FALSE;
574 gboolean map_xtilt_source = FALSE;
575 gboolean map_ytilt_source = FALSE;
576 gboolean state_pressure_source = FALSE;
577 gboolean state_pressure_event = FALSE;
578 gboolean state_xtilt_source = FALSE;
579 gboolean state_ytilt_source = FALSE;
580 gboolean fallback_pressure = FALSE;
581 gboolean fallback_tilt = FALSE;
582 const char *fallback_device_name = NULL;
583 GdkDeviceTool *tool = gdk_event_get_device_tool((GdkEvent *)event);
584 const int tool_type = tool ? (int)gdk_device_tool_get_tool_type(tool) : -1;
585 const gboolean tool_is_stylus
586 = tool && (tool_type == GDK_DEVICE_TOOL_TYPE_PEN || tool_type == GDK_DEVICE_TOOL_TYPE_ERASER
587 || tool_type == GDK_DEVICE_TOOL_TYPE_BRUSH || tool_type == GDK_DEVICE_TOOL_TYPE_PENCIL
588 || tool_type == GDK_DEVICE_TOOL_TYPE_AIRBRUSH);
589 gboolean is_tablet_like = supports_pressure || supports_x_tilt || supports_y_tilt || tool_is_stylus;
590 GdkWindow *window = gdk_event_get_window((GdkEvent *)event);
591 if(IS_NULL_PTR(window) && darktable.gui) window = gtk_widget_get_window(dt_ui_center(darktable.gui->ui));
592
593 {
594 double pressure = 0.0;
595 if(_get_axis_value_for_source(event, source_device, GDK_AXIS_PRESSURE, &pressure, &map_pressure_source))
596 {
597 read_pressure = TRUE;
598 input.pressure = _clamp01d(pressure);
599 input.has_pressure = TRUE;
600 _tablet_motion_state.have_pressure = TRUE;
601 _tablet_motion_state.pressure = input.pressure;
602 }
603 else if(is_tablet_like && _tablet_motion_state.have_pressure)
604 {
605 input.pressure = _tablet_motion_state.pressure;
606 input.has_pressure = TRUE;
607 }
608 else if(!is_tablet_like)
609 {
610 _tablet_motion_state.have_pressure = FALSE;
611 }
612 }
613
614 if(input.has_pressure && input.pressure <= 0.0 && window)
615 {
616 double p_state = 0.0;
617 if(source_device && _sample_axis_from_device_state(window, source_device, GDK_AXIS_PRESSURE, &p_state))
618 {
619 input.pressure = _clamp01d(p_state);
620 state_pressure_source = TRUE;
621 }
622 else if(event_device
623 && _sample_axis_from_device_state(window, event_device, GDK_AXIS_PRESSURE, &p_state))
624 {
625 input.pressure = _clamp01d(p_state);
626 state_pressure_event = TRUE;
627 }
628 }
629
630 {
631 double x_tilt = 0.0;
632 double y_tilt = 0.0;
633 const gboolean has_x_tilt
634 = _get_axis_value_for_source(event, source_device, GDK_AXIS_XTILT, &x_tilt, &map_xtilt_source);
635 const gboolean has_y_tilt
636 = _get_axis_value_for_source(event, source_device, GDK_AXIS_YTILT, &y_tilt, &map_ytilt_source);
637 read_x_tilt = has_x_tilt;
638 read_y_tilt = has_y_tilt;
639 if(has_x_tilt || has_y_tilt)
640 {
641 input.tilt_x = CLAMP(x_tilt, -1.0, 1.0);
642 input.tilt_y = CLAMP(y_tilt, -1.0, 1.0);
643 input.has_tilt = TRUE;
644 _tablet_motion_state.have_tilt = TRUE;
645 _tablet_motion_state.tilt_x = input.tilt_x;
646 _tablet_motion_state.tilt_y = input.tilt_y;
647 }
648 else if(is_tablet_like && _tablet_motion_state.have_tilt)
649 {
650 input.tilt_x = _tablet_motion_state.tilt_x;
651 input.tilt_y = _tablet_motion_state.tilt_y;
652 input.has_tilt = TRUE;
653 }
654 else if(!is_tablet_like)
655 {
656 _tablet_motion_state.have_tilt = FALSE;
657 }
658 }
659
660 if(!input.has_tilt && window)
661 {
662 double tx_state = 0.0, ty_state = 0.0;
663 const gboolean has_tx = source_device && _sample_axis_from_device_state(window, source_device, GDK_AXIS_XTILT, &tx_state);
664 const gboolean has_ty = source_device && _sample_axis_from_device_state(window, source_device, GDK_AXIS_YTILT, &ty_state);
665 if(has_tx || has_ty)
666 {
667 input.tilt_x = CLAMP(tx_state, -1.0, 1.0);
668 input.tilt_y = CLAMP(ty_state, -1.0, 1.0);
669 input.has_tilt = TRUE;
670 _tablet_motion_state.have_tilt = TRUE;
671 _tablet_motion_state.tilt_x = input.tilt_x;
672 _tablet_motion_state.tilt_y = input.tilt_y;
673 state_xtilt_source = has_tx;
674 state_ytilt_source = has_ty;
675 }
676 }
677
678 if(input.has_tilt)
679 input.tilt = _clamp01d(hypot(input.tilt_x, input.tilt_y));
680 else
681 input.tilt = 0.0;
682
683 if(!input.has_pressure || !input.has_tilt)
684 {
685 double fb_pressure = 0.0;
686 gboolean fb_have_pressure = FALSE;
687 double fb_tilt_x = 0.0;
688 double fb_tilt_y = 0.0;
689 gboolean fb_have_tilt = FALSE;
690 if(_sample_tablet_state_from_devices(event, &fb_pressure, &fb_have_pressure,
691 &fb_tilt_x, &fb_tilt_y, &fb_have_tilt,
692 &fallback_device_name))
693 {
694 if(!input.has_pressure && fb_have_pressure)
695 {
696 input.pressure = _clamp01d(fb_pressure);
697 input.has_pressure = TRUE;
698 fallback_pressure = TRUE;
699 }
700 if(!input.has_tilt && fb_have_tilt)
701 {
702 input.tilt_x = CLAMP(fb_tilt_x, -1.0, 1.0);
703 input.tilt_y = CLAMP(fb_tilt_y, -1.0, 1.0);
704 input.tilt = _clamp01d(hypot(input.tilt_x, input.tilt_y));
705 input.has_tilt = TRUE;
706 fallback_tilt = TRUE;
707 }
708 }
709 }
710
711 if(input.has_pressure || input.has_tilt) is_tablet_like = TRUE;
712
713 if(reset_kinematics)
714 {
718 _tablet_motion_state.time_ms = time_ms;
719 _tablet_motion_state.speed_px_s = 0.0;
720 input.acceleration = 0.0;
721 return input;
722 }
723
724 if(_tablet_motion_state.valid && time_ms > _tablet_motion_state.time_ms)
725 {
726 const double dt_s = MAX((double)(time_ms - _tablet_motion_state.time_ms), 1.0) * 1e-3;
727 const double dx = x - _tablet_motion_state.x;
728 const double dy = y - _tablet_motion_state.y;
729 const double speed_px_s = hypot(dx, dy) / dt_s;
730 const double accel_px_s2 = fabs(speed_px_s - _tablet_motion_state.speed_px_s) / dt_s;
731 /* Normalize acceleration for stylus mapping. 25000 px/s² keeps a useful
732 * dynamic range while clipping extreme event jitter. */
733 input.acceleration = _clamp01d(accel_px_s2 / 25000.0);
734 _tablet_motion_state.speed_px_s = speed_px_s;
735 }
736 else
737 {
738 input.acceleration = 0.0;
739 _tablet_motion_state.speed_px_s = 0.0;
740 }
741
745 _tablet_motion_state.time_ms = time_ms;
746
748 "[tablet] %s dev='%s' src_dev='%s' evt_dev='%s' src=%d tablet=%d tool=%d supports[p=%d xt=%d yt=%d] read[p=%d xt=%d yt=%d] map_src[p=%d xt=%d yt=%d] state[p_src=%d p_evt=%d xt_src=%d yt_src=%d] fallback[p=%d t=%d dev='%s'] values[p=%.4f tx=%.4f ty=%.4f t=%.4f a=%.4f] xy=(%.1f, %.1f) t_ms=%u reset=%d\n",
749 tag ? tag : "event",
750 device ? gdk_device_get_name(device) : "<none>",
751 source_device ? gdk_device_get_name(source_device) : "<none>",
752 event_device ? gdk_device_get_name(event_device) : "<none>",
753 (int)source,
754 is_tablet_like ? 1 : 0,
755 tool_type,
756 supports_pressure ? 1 : 0,
757 supports_x_tilt ? 1 : 0,
758 supports_y_tilt ? 1 : 0,
759 read_pressure ? 1 : 0,
760 read_x_tilt ? 1 : 0,
761 read_y_tilt ? 1 : 0,
762 map_pressure_source ? 1 : 0,
763 map_xtilt_source ? 1 : 0,
764 map_ytilt_source ? 1 : 0,
765 state_pressure_source ? 1 : 0,
766 state_pressure_event ? 1 : 0,
767 state_xtilt_source ? 1 : 0,
768 state_ytilt_source ? 1 : 0,
769 fallback_pressure ? 1 : 0,
770 fallback_tilt ? 1 : 0,
771 fallback_device_name ? fallback_device_name : "<none>",
772 input.has_pressure ? input.pressure : -1.0,
773 input.has_tilt ? input.tilt_x : 0.0,
774 input.has_tilt ? input.tilt_y : 0.0,
775 input.has_tilt ? input.tilt : 0.0,
776 input.acceleration,
777 x, y,
778 time_ms,
779 reset_kinematics ? 1 : 0);
780
781 return input;
782}
783
784/* The three pointer handlers below hand the modifier state on WHOLE. Masking it to the low
785 * four bits keeps SHIFT, LOCK, CONTROL and MOD1 -- every modifier that matters on X11 and
786 * Win32, and none of the one that matters on Quartz: a physical Cmd is reported there as
787 * GDK_MOD2_MASK (0x10), on button and motion events exactly as on key events, and that is the
788 * bit DT_PRIMARY_MASK resolves to and every shortcut is matched against. Dropping it makes
789 * every primary+click and primary+drag gesture in the application unreachable on macOS --
790 * inserting a mask node, constraining a shape, the colour picker's area gestures -- while the
791 * same code works on the other platforms, since CONTROL survives the mask there.
792 *
793 * Nothing downstream reads these bits raw: every consumer goes through dt_modifier_is() /
794 * dt_modifiers_include() (widgets/widget_settings.h), which mask with
795 * gtk_accelerator_get_default_mod_mask() -- the button bits a drag adds are not in it, and
796 * neither is GDK_MOD2_MASK on X11, where that bit is NumLock rather than a modifier anyone
797 * presses on purpose. _scrolled() above already passes the whole state for the same reason. */
798static gboolean _button_pressed(GtkWidget *w, GdkEventButton *event, gpointer user_data)
799{
800 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
801
802 /* Reset Gtk focus */
804 gtk_widget_grab_focus(w);
805
806 const dt_control_pointer_input_t input = _extract_pointer_input((const GdkEvent *)event, event->x, event->y,
807 event->time, TRUE, "button-press");
809 const double pressure = input.has_pressure ? input.pressure : 1.0;
810 dt_control_button_pressed(event->x, event->y, pressure, event->button, event->type, event->state);
811 return FALSE;
812}
813
814static gboolean _button_released(GtkWidget *w, GdkEventButton *event, gpointer user_data)
815{
816 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
817 const dt_control_pointer_input_t input = _extract_pointer_input((const GdkEvent *)event, event->x, event->y,
818 event->time, FALSE, "button-release");
820 dt_control_button_released(event->x, event->y, event->button, event->state);
821
822 return TRUE;
823}
824
825static gboolean _mouse_moved(GtkWidget *w, GdkEventMotion *event, gpointer user_data)
826{
827 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
828
829 const dt_control_pointer_input_t input = _extract_pointer_input((const GdkEvent *)event, event->x, event->y,
830 event->time, FALSE, "motion");
832 dt_control_mouse_moved(event->x, event->y, input.has_pressure ? input.pressure : 1.0, event->state);
833 return FALSE;
834}
835
836#ifdef _WIN32
837/* Arbitrary stable subclass identifier encoded as ASCII "ASNN".
838 * It only needs to stay unique within this process for SetWindowSubclass(). */
839#define DT_WIN32_CURSOR_SUBCLASS_CENTER ((UINT_PTR)0x41534e4e)
840
841static LRESULT CALLBACK _center_win32_cursor_proc(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param,
842 UINT_PTR subclass_id, DWORD_PTR ref_data)
843{
844 /* On Win32, DefSubclassProc() answers WM_SETCURSOR for the drawing area in center view by
845 * restoring the window-class default arrow on every mouse move. The center
846 * view already selected the proper cursor through GDK, so swallow the
847 * client-area reset and keep the current cursor unchanged until the view
848 * requests another explicit cursor change. */
849 if(subclass_id == DT_WIN32_CURSOR_SUBCLASS_CENTER && message == WM_SETCURSOR && LOWORD(l_param) == HTCLIENT)
850 return TRUE;
851
852 return DefSubclassProc(hwnd, message, w_param, l_param);
853}
854
855static void _center_realize(GtkWidget *widget, gpointer user_data)
856{
857 GdkWindow *center_window = gtk_widget_get_window(widget);
858 HWND center_hwnd = center_window ? (HWND)gdk_win32_window_get_handle(center_window) : NULL;
859 if(!IS_NULL_PTR(center_hwnd))
860 SetWindowSubclass(center_hwnd, _center_win32_cursor_proc, DT_WIN32_CURSOR_SUBCLASS_CENTER, (DWORD_PTR)widget);
861}
862
863static void _center_unrealize(GtkWidget *widget, gpointer user_data)
864{
865 GdkWindow *center_window = gtk_widget_get_window(widget);
866 HWND center_hwnd = center_window ? (HWND)gdk_win32_window_get_handle(center_window) : NULL;
867 if(!IS_NULL_PTR(center_hwnd))
868 RemoveWindowSubclass(center_hwnd, _center_win32_cursor_proc, DT_WIN32_CURSOR_SUBCLASS_CENTER);
869}
870#endif
871
872static gboolean _key_pressed(GtkWidget *w, GdkEventKey *event)
873{
874 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
876 return TRUE;
877}
878
879/* A key RELEASE is routed exactly like the press, and for the same reason the press is: a mode
880 * held for as long as a key is down has to be told when it comes up, or it is entered and never
881 * left. GTK routes only the press by default, so the release gets its own handler.
882 *
883 * It returns FALSE rather than TRUE: a release carries no shortcut of its own, and claiming it
884 * would stop it reaching anything else that is watching. */
885static gboolean _key_released(GtkWidget *w, GdkEventKey *event)
886{
887 if(!gtk_window_is_active(GTK_WINDOW(darktable.gui->ui->main_window))) return FALSE;
889 return FALSE;
890}
891
892/* Keyboard trace for "-d input", installed by dt_gui_gtk_init() on that flag alone.
893 *
894 * A keystroke goes to whichever toplevel holds the focus, and each of them handles keys on
895 * its own: dt_accels_dispatch() sees the main window's, a dialog or a standalone panel sees
896 * its own, and a focused text entry swallows what it consumes before either. There is no
897 * single handler the whole program's keys pass through, so an emission hook takes them at
898 * the signal instead -- it runs ahead of every handler and whatever they return.
899 *
900 * The hook is on "event", NOT on "key-press-event". GtkWidget emits the generic signal
901 * first and only emits the specific one if nothing handled it, and the keys worth tracing
902 * are precisely the handled ones: dt_accels_dispatch() is connected to "event" on the main
903 * window and returns TRUE for every keystroke that fires a shortcut, so a hook on
904 * "key-press-event" prints every key the program ignores and none of the ones it acts on.
905 *
906 * One keystroke reaches the hook several times: gtk_propagate_event() hands it to the
907 * toplevel, which walks the focus chain until a widget handles it. It is the same GdkEvent
908 * throughout, so the first emission is printed and the repeats are skipped. Identity is the
909 * tuple the windowing system filled in, which two distinct keystrokes cannot share --
910 * auto-repeat does reuse a timestamp for the release and the press it pairs with, but those
911 * differ by type.
912 */
913static gboolean _log_key_event(GSignalInvocationHint *hint, guint n_params, const GValue *params, gpointer data)
914{
915 static GdkEventType last_type = GDK_NOTHING;
916 static guint32 last_time = 0;
917 static guint last_keyval = 0;
918 static guint last_state = 0;
919 static guint16 last_keycode = 0;
920
921 const GdkEventKey *event = (const GdkEventKey *)g_value_get_boxed(&params[1]);
922 if(IS_NULL_PTR(event) || (event->type != GDK_KEY_PRESS && event->type != GDK_KEY_RELEASE)) return TRUE;
923
924 if(event->type == last_type && event->time == last_time && event->keyval == last_keyval
925 && event->state == last_state && event->hardware_keycode == last_keycode)
926 return TRUE;
927
928 last_type = event->type;
929 last_time = event->time;
930 last_keyval = event->keyval;
931 last_state = event->state;
932 last_keycode = event->hardware_keycode;
933
934 // `state` holds the modifiers as they were BEFORE this event, so a modifier key's own
935 // press carries none of its own bit while its release carries it -- the same keyval either
936 // way. That is GDK's contract, not a decoding accident, and reading the trace requires it,
937 // which is why the primary modifier is named from the KEY below and not from the state.
938 GdkModifierType mods = (GdkModifierType)(event->state & gtk_accelerator_get_default_mod_mask());
939
940 // The primary modifier is spelled by the application, not by GTK's per-platform naming
941 // table: DT_PRIMARY_MASK is the bit every shortcut is registered and matched against, and on
942 // Quartz one physical Cmd also sets GDK's virtual GDK_META_MASK duplicate next to it -- which
943 // gtk_accelerator_name() renders as a SECOND modifier ("<Primary><Mod2>"), spelling one
944 // keystroke as two. Both bits come out here and the token is printed once, the same way
945 // _accels_keys_decode() (widgets/accelerators.c) and dt_modifier_is() drop that duplicate
946 // before matching. The raw state is printed as well, so nothing is hidden.
947 gboolean primary_mod = (mods & DT_PRIMARY_MASK) != 0;
948 mods = (GdkModifierType)(mods & ~DT_PRIMARY_MASK);
949#ifdef GDK_WINDOWING_QUARTZ
950 primary_mod = primary_mod || (mods & GDK_META_MASK) != 0;
951 mods = (GdkModifierType)(mods & ~GDK_META_MASK);
952 // Cmd, which GDK reports as the Meta keysym on this backend.
953 const gboolean primary_key = event->keyval == GDK_KEY_Meta_L || event->keyval == GDK_KEY_Meta_R;
954#else
955 const gboolean primary_key = event->keyval == GDK_KEY_Control_L || event->keyval == GDK_KEY_Control_R;
956#endif
957
958 // The key that IS the primary modifier is announced as such -- with the physical key it
959 // stands for, since that differs per platform -- and then carries no separate modifier
960 // token of its own, which would name it twice on the release.
961 gchar *accel = gtk_accelerator_name(event->keyval, mods);
962 GtkWidget *widget = GTK_WIDGET(g_value_get_object(&params[0]));
963 // Every toplevel is a GtkWindow, so the type alone cannot say whether a key reached the main
964 // window or a panel holding the keyboard; the title can.
965 const gchar *title = GTK_IS_WINDOW(widget) ? gtk_window_get_title(GTK_WINDOW(widget)) : NULL;
966 dt_print(DT_DEBUG_INPUT, "[input] key %s: %s%s%s%s (keyval 0x%x, keycode %u, state 0x%x) on %s%s%s%s\n",
967 (event->type == GDK_KEY_PRESS) ? "pressed" : "released",
968 (primary_mod && !primary_key) ? "<Primary>" : "", primary_key ? "<Primary> (" : "",
969 IS_NULL_PTR(accel) ? "<unnamed>" : accel, primary_key ? ")" : "",
970 event->keyval, (unsigned int)event->hardware_keycode, event->state,
971 IS_NULL_PTR(widget) ? "<none>" : G_OBJECT_TYPE_NAME(widget), IS_NULL_PTR(title) ? "" : " \"",
972 IS_NULL_PTR(title) ? "" : title, IS_NULL_PTR(title) ? "" : "\"");
973 dt_free(accel);
974
975 return TRUE;
976}
977
978static gboolean _center_leave(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
979{
981 return TRUE;
982}
983
984static gboolean _center_enter(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
985{
987 return TRUE;
988}
989
990static const char* _get_source_name(int pos)
991{
992 static const gchar *SOURCE_NAMES[]
993 = { "GDK_SOURCE_MOUSE", "GDK_SOURCE_PEN", "GDK_SOURCE_ERASER", "GDK_SOURCE_CURSOR",
994 "GDK_SOURCE_KEYBOARD", "GDK_SOURCE_TOUCHSCREEN", "GDK_SOURCE_TOUCHPAD", "GDK_SOURCE_TRACKPOINT",
995 "GDK_SOURCE_TABLET_PAD" };
996 if(pos >= G_N_ELEMENTS(SOURCE_NAMES)) return "<UNKNOWN>";
997 return SOURCE_NAMES[pos];
998}
999
1000static const char* _get_mode_name(int pos)
1001{
1002 static const gchar *MODE_NAMES[] = { "GDK_MODE_DISABLED", "GDK_MODE_SCREEN", "GDK_MODE_WINDOW" };
1003 if(pos >= G_N_ELEMENTS(MODE_NAMES)) return "<UNKNOWN>";
1004 return MODE_NAMES[pos];
1005}
1006
1007static const char* _get_axis_name(int pos)
1008{
1009 static const gchar *AXIS_NAMES[]
1010 = { "GDK_AXIS_IGNORE", "GDK_AXIS_X", "GDK_AXIS_Y", "GDK_AXIS_PRESSURE",
1011 "GDK_AXIS_XTILT", "GDK_AXIS_YTILT", "GDK_AXIS_WHEEL", "GDK_AXIS_DISTANCE",
1012 "GDK_AXIS_ROTATION", "GDK_AXIS_SLIDER", "GDK_AXIS_LAST" };
1013 if(pos >= G_N_ELEMENTS(AXIS_NAMES)) return "<UNKNOWN>";
1014 return AXIS_NAMES[pos];
1015}
1016
1017
1018/* ---- Host hooks for the shortcut system (widgets/accelerators.c) --------------------- */
1019#define DT_ACCEL_SEARCH_RECENT_KEY "plugins/accel_search/recent_entries"
1020
1022{
1023 return dt_gui_main_window();
1024}
1025
1035
1036/* dt_control_change_cursor() and dt_toast_log() are macros, so the widget hooks need real
1037 * functions to point at. */
1038// The host owns the preferences; widgets only know the key they were given.
1039static gboolean _widget_stored_int(const char *key, int *value)
1040{
1041 if(!dt_conf_key_exists(key)) return FALSE;
1043 return TRUE;
1044}
1045
1046static void _widget_store_int(const char *key, int value)
1047{
1049}
1050
1051static gboolean _widget_stored_bool(const char *key)
1052{
1053 return dt_conf_get_bool(key);
1054}
1055
1056static void _widget_store_bool(const char *key, gboolean value)
1057{
1059}
1060
1061// The display profile can only be probed once the control loop is up: before that there is no
1062// realised window to read an X atom or a colord property from. common/colorspaces.c does not
1063// know what a control loop is, so the check lives here, with the three call sites it guards.
1069
1070// Relay a display-profile change onto the signal bus. colorspaces/ raises nothing itself.
1075
1080
1081static void _widget_cursor(GdkCursorType cursor)
1082{
1084}
1085
1086static void _widget_message(const char *message)
1087{
1088 dt_toast_log("%s", message);
1089}
1090
1091static gint _accels_top_offset(void)
1092{
1095 if(IS_NULL_PTR(top_panel) || !gtk_widget_get_visible(top_panel)) return 0;
1096 return gtk_widget_get_allocated_height(top_panel);
1097}
1098
1099static gchar *_accels_recent_get(int index)
1100{
1101 gchar *key = g_strdup_printf("%s/%d", DT_ACCEL_SEARCH_RECENT_KEY, index);
1103 dt_free(key);
1104 return value;
1105}
1106
1107static void _accels_recent_set(int index, const char *value)
1108{
1109 gchar *key = g_strdup_printf("%s/%d", DT_ACCEL_SEARCH_RECENT_KEY, index);
1111 dt_free(key);
1112}
1113
1114/* The pixelpipe cache alerts when it cannot serve an allocation -- it is full, or the system itself
1115 * runs out of memory: the module that needed the memory fails and the image is not updated, which
1116 * a toast would stop saying too soon. */
1117static void _pixelpipe_cache_alert(const char *message, const char *item)
1118{
1119 dt_gui_alert(_("Not enough memory"), message, item, FALSE);
1120}
1121
1122/* common/ reports startup progress; opening the splash on the first message is display
1123 * state, so it lives here rather than in whatever subsystem happens to be slow. */
1124static void _gui_startup_progress(const char *message)
1125{
1126 // dt_gui_splash_init() already no-ops once the splash exists, so no "have I opened it?"
1127 // flag is needed here -- which is the same flag common/opencl.c used to carry.
1129 dt_gui_splash_updatef("%s", message);
1130}
1131
1132/* GUI-thread half of _gui_refresh_thumbnail(). Ends in gtk_widget_queue_draw(), so it must
1133 * not run anywhere else. */
1134static void _refresh_thumbnail_widgets(int32_t imgid, gboolean refresh_filmstrip)
1135{
1136 struct dt_ui_t *ui = dt_gui_get_ui();
1137 if(IS_NULL_PTR(ui)) return;
1138
1140
1141 // Best-effort: refreshing the filmstrip spawns an export thread that competes with the
1142 // realtime darkroom main preview, so darkroom write paths ask for it to be skipped.
1143 if(refresh_filmstrip)
1145}
1146
1147/* What crosses the thread boundary: two values, and deliberately nothing else. A request
1148 * carrying a dt_thumbnail_t* or a GtkWidget* would need that object refcounted, because the
1149 * GUI thread can destroy it between the worker posting the request and the main loop running
1150 * it -- the hazard libs/backgroundjobs.c already pays a refcount for. An image id cannot go
1151 * stale; the widget lookup happens on the GUI thread, where the answer is valid or absent. */
1157
1158static gboolean _refresh_thumbnail_on_gui_thread(gpointer user_data)
1159{
1160 const _thumbnail_refresh_request_t *request = (const _thumbnail_refresh_request_t *)user_data;
1162 return G_SOURCE_REMOVE;
1163}
1164
1165/* common/ announces that an image's thumbnail is stale; this turns that into the two
1166 * widget refreshes. Registered at the end of dt_gui_gtk_init(), so headless runs never
1167 * have a handler and the notification is a no-op there.
1168 *
1169 * The announcement arrives on whatever thread changed the image, and most of them are not
1170 * this one: dt_image_history_changed() is reached from the flip/rotate job, from the import
1171 * job and from style application, all of which run in the job queue. The refresh ends in
1172 * gtk_widget_queue_draw(), which walks the widget hierarchy and edits the toplevel's
1173 * invalidation region -- structures the GUI thread is reading at the same time. That is
1174 * Sentry 142561119: an access violation inside GTK's own memmove, on the job thread, with
1175 * dt_control_work() still on the stack underneath it.
1176 *
1177 * So the work is marshalled onto the main loop unless we are already on it. Running inline
1178 * when we are keeps the ordering every existing GUI-thread caller already relies on. */
1179static void _gui_refresh_thumbnail(int32_t imgid, gboolean refresh_filmstrip)
1180{
1182 {
1183 _refresh_thumbnail_widgets(imgid, refresh_filmstrip);
1184 return;
1185 }
1186
1188 request->imgid = imgid;
1189 request->refresh_filmstrip = refresh_filmstrip;
1190 g_main_context_invoke_full(NULL, G_PRIORITY_DEFAULT, _refresh_thumbnail_on_gui_thread, request, g_free);
1191}
1192
1194{
1195 /* lets zero mem */
1196 memset(gui, 0, sizeof(dt_gui_gtk_t));
1197
1198 // The collection and the selection are lighttable state -- which images the grid shows,
1199 // which of them are picked -- so the GUI creates them, not dt_init(): a GUI-less process
1200 // (ansel-cli) must not pay for the user's collection query and selection reload just to
1201 // export one file. Both modules treat "never created" as a no-op at their own boundary.
1202 // Created before any widget below, so everything the GUI builds can already read them.
1205 dt_guides_init(); // darkroom overlay registry: same argument, nothing to overlay without a GUI
1206
1207 // GUI-side handler for backend import events (an inverted dependency): registered here
1208 // rather than in dt_init() -- the handler drives GTK widgets, and the registration site
1209 // in import_jobs.c NULL-checks before calling, so a GUI-less process simply runs with
1210 // the slot empty. dt_dev_history_gui_init() is its darkroom sibling and registers from
1211 // views/darkroom.c gui_init(), the layer entitled to see develop/.
1213
1214 dt_pthread_mutex_init(&gui->mutex, NULL);
1215
1216 // force gtk3 to use normal scroll bars instead of the popup thing. they get in the way of controls
1217 // the alternative would be to gtk_scrolled_window_set_overlay_scrolling(..., FALSE); every single widget
1218 // that might have scroll bars
1219 g_setenv("GTK_OVERLAY_SCROLLING", "0", 0);
1220
1221 // same for ubuntus overlay-scrollbar-gtk3
1222 g_setenv("LIBOVERLAY_SCROLLBAR", "0", 0);
1223
1224 // unset gtk rc from kde:
1225 char path[DT_PATH_MAX] = { 0 }, datadir[DT_PATH_MAX] = { 0 }, sharedir[DT_PATH_MAX] = { 0 }, configdir[DT_PATH_MAX] = { 0 };
1226 dt_loc_get_datadir(datadir, sizeof(datadir));
1227 dt_loc_get_sharedir(sharedir, sizeof(sharedir));
1228 dt_loc_get_user_config_dir(configdir, sizeof(configdir));
1229
1230 const char *css_theme = dt_conf_get_string_const("ui_last/theme");
1231 if(css_theme)
1232 g_strlcpy(gui->gtkrc, css_theme, sizeof(gui->gtkrc));
1233 else
1234 g_snprintf(gui->gtkrc, sizeof(gui->gtkrc), "ansel");
1235
1236#ifdef MAC_INTEGRATION
1237#ifdef GTK_TYPE_OSX_APPLICATION
1238 GtkOSXApplication *OSXApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
1239 gtk_osxapplication_set_menu_bar(
1240 OSXApp, GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up
1241#else
1242 GtkosxApplication *OSXApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
1243 gtkosx_application_set_menu_bar(
1244 OSXApp, GTK_MENU_SHELL(gtk_menu_bar_new())); // needed for default entries to show up
1245#endif
1246 g_signal_connect(G_OBJECT(OSXApp), "NSApplicationBlockTermination", G_CALLBACK(_osx_quit_callback), NULL);
1247 g_signal_connect(G_OBJECT(OSXApp), "NSApplicationOpenFile", G_CALLBACK(_osx_openfile_callback), NULL);
1248#endif
1249
1250 GtkWidget *widget;
1251 gui->ui = g_malloc0(sizeof(dt_ui_t));
1252 gui->center_tooltip = 0;
1253 gui->culling_mode = FALSE;
1254 gui->presets_popup_menu = NULL;
1255 gui->last_preset = NULL;
1256 gui->export_popup.window = NULL;
1257 gui->export_popup.module = NULL;
1258 gui->styles_popup.window = NULL;
1259 gui->styles_popup.module = NULL;
1260
1261 // smooth scrolling must be enabled to handle trackpad/touch events
1262 dt_widget_set_scroll_mask(GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK);
1263
1264 // Emulates the same feature as Gtk focus but for scrolling events
1265 // The GtkWidget capturing scrolling events will write its address in this pointer
1267
1268 // Init global accels. We localize the config because accels pathes use translated GUI labels.
1269 // User switching between languages may loose their custom shortcuts if we didn't localize them.
1270 // NOTE: needs to be inited before widgets, more specifically before the global menu
1271 gchar *keyboardrc = g_strdup_printf("keyboardrc.%s", dt_l10n_get_current_lang(dt_l10n_get_global()));
1272 gchar *keyboardrc_path = g_build_filename(configdir, keyboardrc, NULL);
1273
1274 GtkAccelFlags flags = 0;
1275 if(dt_conf_get_bool("accels/mask")) flags |= GTK_ACCEL_MASK;
1276 gui->accels = dt_accels_init(keyboardrc_path, flags);
1277 dt_free(keyboardrc);
1278 dt_free(keyboardrc_path);
1279
1280 // Load the user's saved shortcuts right away, before _init_widgets() below builds the
1281 // main window and enters the default view. Views call dt_accels_connect_accels() from
1282 // their own enter() (see e.g. views/lighttable.c), which happens well before darktable.c's
1283 // own later, single dt_accels_connect_accels() call -- without this earlier load, that
1284 // first connect reconciles every shortcut against an empty accel map (key=0, mods=0) and
1285 // permanently records it as a deliberate "user cleared this shortcut" override, before the
1286 // real saved value has had a chance to be read at all. This must be the ONLY call to
1287 // dt_accels_load_user_config(): calling it again anywhere later would re-read the
1288 // still-on-disk (unsaved until exit) file and clobber any normalization applied to the
1289 // live GtkAccelMap since this first load.
1291
1292 // Initializing widgets
1293 _init_widgets(gui);
1294
1295 //init overlay colors
1297
1298 dt_concat_path_file(path, datadir, "icons");
1299 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), path);
1300 dt_concat_path_file(path, sharedir, "icons");
1301 gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), path);
1302
1303 GtkWidget *center = dt_ui_center(darktable.gui->ui);
1304 widget = center;
1305
1306 gtk_widget_set_can_focus(widget, TRUE);
1307 gtk_widget_set_visible(widget, TRUE);
1308 gtk_widget_grab_focus(widget);
1309 gtk_widget_add_events(widget, GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK | GDK_TABLET_PAD_MASK);
1310 g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(_configure), gui);
1311 g_signal_connect(G_OBJECT(widget), "draw", G_CALLBACK(_draw), NULL);
1312 g_signal_connect(G_OBJECT(widget), "motion-notify-event", G_CALLBACK(_mouse_moved), NULL);
1313 g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(_key_pressed), NULL);
1314 g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(_key_released), NULL);
1315 g_signal_connect(G_OBJECT(widget), "leave-notify-event", G_CALLBACK(_center_leave), NULL);
1316 g_signal_connect(G_OBJECT(widget), "enter-notify-event", G_CALLBACK(_center_enter), NULL);
1317 g_signal_connect(G_OBJECT(widget), "button-press-event", G_CALLBACK(_button_pressed), NULL);
1318 g_signal_connect(G_OBJECT(widget), "button-release-event", G_CALLBACK(_button_released), NULL);
1319 g_signal_connect(G_OBJECT(widget), "scroll-event", G_CALLBACK(_scrolled), NULL);
1320#ifdef _WIN32
1321 g_signal_connect(G_OBJECT(widget), "realize", G_CALLBACK(_center_realize), NULL);
1322 g_signal_connect(G_OBJECT(widget), "unrealize", G_CALLBACK(_center_unrealize), NULL);
1323 if(gtk_widget_get_realized(widget))
1324 _center_realize(widget, NULL);
1325#endif
1326
1328
1330 // update the profile when the window is moved. resize is already handled in configure()
1331 widget = dt_ui_main_window(darktable.gui->ui);
1332 g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(_window_configure), NULL);
1333
1335
1336 // load theme
1338
1339 // let's try to support pressure sensitive input devices like tablets for mask drawing
1340 dt_print(DT_DEBUG_INPUT, "[input device] Input devices found:\n\n");
1341
1342 GList *input_devices
1343 = gdk_seat_get_slaves(gdk_display_get_default_seat(gdk_display_get_default()), GDK_SEAT_CAPABILITY_ALL);
1344 const int manager_slave_count = 0;
1345 const int manager_floating_count = 0;
1346 GList *stylus_devices
1347 = gdk_seat_get_slaves(gdk_display_get_default_seat(gdk_display_get_default()), GDK_SEAT_CAPABILITY_TABLET_STYLUS);
1348 dt_print(DT_DEBUG_INPUT, "[input device] seat capabilities bitmask: %u\n",
1349 (unsigned int)gdk_seat_get_capabilities(gdk_display_get_default_seat(gdk_display_get_default())));
1350 dt_print(DT_DEBUG_INPUT, "[input device] stylus-capable devices reported by seat: %d\n", g_list_length(stylus_devices));
1351 dt_print(DT_DEBUG_INPUT, "[input device] manager fallback devices: slave=%d floating=%d merged_total=%d\n",
1352 manager_slave_count, manager_floating_count, g_list_length(input_devices));
1353 for(GList *l = stylus_devices; !IS_NULL_PTR(l); l = g_list_next(l))
1354 {
1355 GdkDevice *device = (GdkDevice *)l->data;
1356 if(IS_NULL_PTR(device)) continue;
1357 dt_print(DT_DEBUG_INPUT, " [tablet seat] %s source=%s axes_flags=%u n_axes=%d\n",
1358 gdk_device_get_name(device), _get_source_name(gdk_device_get_source(device)),
1359 (unsigned int)gdk_device_get_axes(device), gdk_device_get_n_axes(device));
1360 }
1361 if(stylus_devices)
1362 {
1363 g_list_free(stylus_devices);
1364 stylus_devices = NULL;
1365 }
1366 for(GList *l = input_devices; !IS_NULL_PTR(l); l = g_list_next(l))
1367 {
1368 GdkDevice *device = (GdkDevice *)l->data;
1369 if(IS_NULL_PTR(device)) continue;
1370 const GdkInputSource source = gdk_device_get_source(device);
1371 const gint n_axes = (source == GDK_SOURCE_KEYBOARD ? 0 : gdk_device_get_n_axes(device));
1372
1373 // force-enable everything we find in screen mode.
1374 // TODO: make that an user param ?
1375 gdk_device_set_mode(device, GDK_MODE_SCREEN);
1376
1377 dt_print(DT_DEBUG_INPUT, "%s (%s), source: %s, mode: %s, %d axes, %d keys\n", gdk_device_get_name(device),
1378 (source != GDK_SOURCE_KEYBOARD) && gdk_device_get_has_cursor(device) ? "with cursor" : "no cursor",
1379 _get_source_name(source),
1380 _get_mode_name(gdk_device_get_mode(device)), n_axes,
1381 source != GDK_SOURCE_KEYBOARD ? gdk_device_get_n_keys(device) : 0);
1382
1383 for(int i = 0; i < n_axes; i++)
1384 {
1385 dt_print(DT_DEBUG_INPUT, " %s\n", _get_axis_name(gdk_device_get_axis_use(device, i)));
1386 }
1387 dt_print(DT_DEBUG_INPUT, "\n");
1388 }
1389 if(input_devices)
1390 {
1391 g_list_free(input_devices);
1392 input_devices = NULL;
1393 }
1394
1395 // The keystroke trace costs an emission hook on every event every widget receives --
1396 // motion included -- so it is installed only when the channel it prints on is on. Debug
1397 // flags are parsed from the command line before this runs and never change afterwards.
1399 {
1400 g_signal_add_emission_hook(g_signal_lookup("event", GTK_TYPE_WIDGET), 0, _log_key_event, NULL, NULL);
1401 }
1402
1403 // Gtk seems to capture some reserved shortcuts (Tab). We need to bypass it entirely
1404 // by hacking all events.
1405 gtk_widget_add_events(dt_ui_main_window(gui->ui), dt_widget_scroll_mask());
1406 g_signal_connect(G_OBJECT(dt_ui_main_window(gui->ui)), "event", G_CALLBACK(dt_accels_dispatch), gui->accels);
1407
1408 // finally set the cursor to be the default.
1409 // for some reason this is needed on some systems to pick up the correctly themed cursor
1410 dt_control_change_cursor(GDK_LEFT_PTR);
1412
1413 // Tell common/ how to repaint a stale thumbnail. The backend announces staleness and
1414 // knows nothing about thumbtables; this is the only place the two are connected.
1415 // Tell the widget layer which thread owns widget state, and how the user wants scrolling.
1417 dt_widget_set_scroll_reversed(dt_conf_get_bool("scroll/reverse_x"), dt_conf_get_bool("scroll/reverse_y"));
1418
1433
1443
1444 return 0;
1445}
1446
1448{
1449 GtkWidget *widget = dt_ui_center(darktable.gui->ui);
1450 GtkAllocation allocation;
1451 gtk_widget_get_allocation(widget, &allocation);
1452
1453 /* Pre-configure the views so a draw arriving before the first configure-event has a valid
1454 * size to work with.
1455 *
1456 * The size handed over must be THE SAME size the configure-event handler will report for the
1457 * same widget, and it was not: this passed the allocation minus twice an 8 px `tabborder',
1458 * while dt_control_configure() passes the event's width and height untouched. Two callers,
1459 * one widget, two answers 16 px apart -- so the view was configured at one size here and at
1460 * another as soon as GTK delivered an allocation, and a view that recomputes on a size change
1461 * (the darkroom pipeline does) paid for both.
1462 *
1463 * The border was not drawn by anything: `tabborder' was written on the line above and read on
1464 * the line below, and nowhere else in the program. It is gone. */
1465 dt_view_manager_configure(darktable.view_manager, allocation.width, allocation.height);
1466#ifdef MAC_INTEGRATION
1467#ifdef GTK_TYPE_OSX_APPLICATION
1468 gtk_osxapplication_ready(g_object_new(GTK_TYPE_OSX_APPLICATION, NULL));
1469#else
1470 gtkosx_application_ready(g_object_new(GTKOSX_TYPE_APPLICATION, NULL));
1471#endif
1472#endif
1473#ifdef GDK_WINDOWING_QUARTZ
1475#endif
1476 /* start the event loop */
1477 gtk_main();
1478
1479 dt_cleanup();
1480}
1481
1482
1484{
1485 GtkWidget *widget = gui->ui->main_window;
1486
1487 gui->ppd = dt_get_system_gui_ppd(widget);
1488 dt_widget_set_ppd(gui->ppd);
1489 gui->filter_image = CAIRO_FILTER_GOOD;
1491
1492 // get the screen resolution
1493 const float screen_dpi_overwrite = dt_conf_get_float("screen_dpi_overwrite");
1494 if(screen_dpi_overwrite > 0.0)
1495 {
1496 gui->dpi = screen_dpi_overwrite;
1497 gdk_screen_set_resolution(gtk_widget_get_screen(widget), screen_dpi_overwrite);
1498 dt_print(DT_DEBUG_CONTROL, "[screen resolution] setting the screen resolution to %f dpi as specified in "
1499 "the configuration file\n",
1500 screen_dpi_overwrite);
1501 }
1502 else
1503 {
1504#ifdef GDK_WINDOWING_QUARTZ
1505 dt_osx_autoset_dpi(widget);
1506#endif
1507 gui->dpi = gdk_screen_get_resolution(gtk_widget_get_screen(widget));
1508 if(gui->dpi < 0.0)
1509 {
1510 gui->dpi = 96.0;
1511 gdk_screen_set_resolution(gtk_widget_get_screen(widget), 96.0);
1512 dt_print(DT_DEBUG_CONTROL, "[screen resolution] setting the screen resolution to the default 96 dpi\n");
1513 }
1514 else
1515 dt_print(DT_DEBUG_CONTROL, "[screen resolution] setting the screen resolution to %f dpi\n", gui->dpi);
1516 }
1517 gui->dpi_factor
1518 = gui->dpi / 96;
1519 dt_screen_set_dpi(gui->dpi); // the raw resolution, for whoever reports it rather than scales by it
1520 dt_widget_set_dpi_factor(gui->dpi_factor); // according to man xrandr and the docs of gdk_screen_set_resolution 96 is the default
1521
1522 // em depends on the screen DPI (point -> px), so refresh it here too.
1524}
1525
1526// Last DT_GUI_BOX_SPACING value actually applied to containers. Used to retarget exactly
1527// the containers that carry the standard spacing when em changes, leaving deliberate 0-spacing
1528// and custom-spacing containers untouched. Seeded with the pre-em reference (10px).
1529static gint _last_box_spacing = 10;
1530
1531typedef struct _spacing_ctx_t { gint old_s, new_s; } _spacing_ctx_t;
1532
1533// Recursively retarget GtkBox/GtkGrid/GtkFlowBox children whose spacing still equals the
1534// previously-applied standard spacing. Setting spacing inside gtk_container_foreach() doesn't
1535// mutate the child list, so the walk is safe.
1536static void _refresh_container_spacing(GtkWidget *w, gpointer user_data)
1537{
1538 const _spacing_ctx_t *c = (const _spacing_ctx_t *)user_data;
1539
1540 if(GTK_IS_BOX(w))
1541 {
1542 if(gtk_box_get_spacing(GTK_BOX(w)) == c->old_s) gtk_box_set_spacing(GTK_BOX(w), c->new_s);
1543 }
1544 else if(GTK_IS_FLOW_BOX(w))
1545 {
1546 if((gint)gtk_flow_box_get_row_spacing(GTK_FLOW_BOX(w)) == c->old_s)
1547 gtk_flow_box_set_row_spacing(GTK_FLOW_BOX(w), c->new_s);
1548 if((gint)gtk_flow_box_get_column_spacing(GTK_FLOW_BOX(w)) == c->old_s)
1549 gtk_flow_box_set_column_spacing(GTK_FLOW_BOX(w), c->new_s);
1550 }
1551 else if(GTK_IS_GRID(w))
1552 {
1553 if((gint)gtk_grid_get_row_spacing(GTK_GRID(w)) == c->old_s)
1554 gtk_grid_set_row_spacing(GTK_GRID(w), c->new_s);
1555 if((gint)gtk_grid_get_column_spacing(GTK_GRID(w)) == c->old_s)
1556 gtk_grid_set_column_spacing(GTK_GRID(w), c->new_s);
1557 }
1558
1559 if(GTK_IS_CONTAINER(w))
1560 gtk_container_foreach(GTK_CONTAINER(w), _refresh_container_spacing, user_data);
1561}
1562
1563// Propagate a new DT_GUI_BOX_SPACING to already-built containers across every toplevel, so a
1564// runtime font/DPI change updates the inner gutters live (gtk_*_set_spacing bakes the value into
1565// the widget at creation time, so reloading the CSS alone is not enough).
1567{
1568 const gint new_s = DT_GUI_BOX_SPACING;
1569 if(new_s == _last_box_spacing) return;
1570
1571 _spacing_ctx_t c = { _last_box_spacing, new_s };
1572 GList *toplevels = gtk_window_list_toplevels(); // list owned by us, elements not reffed
1573 for(GList *l = toplevels; l; l = l->next)
1574 _refresh_container_spacing(GTK_WIDGET(l->data), &c);
1575 g_list_free(toplevels);
1576
1577 _last_box_spacing = new_s;
1578}
1579
1581{
1582 dt_gui_gtk_t *gui = darktable.gui;
1583 if(!gui || !gui->ui || !gui->ui->main_window) return;
1584
1585 GtkStyleContext *ctx = gtk_widget_get_style_context(gui->ui->main_window);
1586 PangoFontDescription *desc = NULL;
1587 gtk_style_context_get(ctx, gtk_style_context_get_state(ctx), GTK_STYLE_PROPERTY_FONT, &desc, NULL);
1588 if(!desc) return;
1589
1590 const gint size = pango_font_description_get_size(desc);
1591 if(size > 0)
1592 {
1593 if(pango_font_description_get_size_is_absolute(desc))
1594 // already device-independent px
1595 gui->em = (double)size / PANGO_SCALE;
1596 else
1597 // points -> px at the screen DPI, matching how GTK renders point-sized fonts
1598 gui->em = (double)size / PANGO_SCALE * gui->dpi / 72.0;
1599
1601 }
1602 pango_font_description_free(desc);
1603
1604 // The new em may change DT_GUI_BOX_SPACING; push it to existing containers so the change is live.
1606}
1607
1608void dt_gui_set_pango_resolution(PangoLayout *layout)
1609{
1610 if(IS_NULL_PTR(layout) || !darktable.gui) return;
1611 // Cairo-drawn text is laid out in points; the screen DPI converts those to device-independent px,
1612 // matching how GTK renders the rest of the UI. Centralized here so call sites never hand-write the DPI.
1613 pango_cairo_context_set_resolution(pango_layout_get_context(layout), darktable.gui->dpi);
1614}
1615
1616
1617static gboolean _focus_in_out_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
1618{
1619 gtk_window_set_urgency_hint(GTK_WINDOW(widget), FALSE);
1620 return FALSE;
1621}
1622
1623static gboolean _ui_log_button_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
1624{
1625 gtk_widget_hide(GTK_WIDGET(user_data));
1626 return TRUE;
1627}
1628
1629static gboolean _ui_toast_button_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
1630{
1631 gtk_widget_hide(GTK_WIDGET(user_data));
1632 return TRUE;
1633}
1634
1636{
1638 GtkWidget *widget;
1639
1640 // Creating the main window
1641 gui->ui->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1642 gtk_widget_set_name(gui->ui->main_window , "main_window");
1643 gtk_window_set_role(GTK_WINDOW(gui->ui->main_window ), "main-app");
1644 gtk_window_set_icon_name(GTK_WINDOW(gui->ui->main_window ), "ansel");
1645 gtk_window_set_title(GTK_WINDOW(gui->ui->main_window ), "Ansel");
1646
1647 // Init the titlebar ASAP because we replace the desktop titlebar & decoration with ours
1648 dt_ui_init_titlebar(gui->ui);
1649
1651
1652 gtk_window_set_default_size(GTK_WINDOW(gui->ui->main_window), DT_PIXEL_APPLY_DPI(1200), DT_PIXEL_APPLY_DPI(800));
1653
1654 // NOTE: allowing full-screen on startup shits the bed with MacOS
1655 if(dt_conf_get_bool("ui_last/maximized"))
1656 {
1657 gboolean restore_window_position = TRUE;
1658#ifdef GDK_WINDOWING_WAYLAND
1659 GdkDisplay *display = gtk_widget_get_display(gui->ui->main_window);
1660 if(GDK_IS_WAYLAND_DISPLAY(display))
1661 restore_window_position = FALSE;
1662#endif
1663
1664 if(restore_window_position)
1665 {
1666 GdkDisplay *window_display = gtk_widget_get_display(gui->ui->main_window);
1667 GdkMonitor *monitor = NULL;
1668
1669 if(!IS_NULL_PTR(window_display))
1670 {
1671 if(dt_conf_key_exists("ui_last/window_monitor"))
1672 {
1673 const int monitor_index = dt_conf_get_int("ui_last/window_monitor");
1674 if(monitor_index >= 0 && monitor_index < gdk_display_get_n_monitors(window_display))
1675 monitor = gdk_display_get_monitor(window_display, monitor_index);
1676 }
1677
1678 if(IS_NULL_PTR(monitor)
1679 && dt_conf_key_exists("ui_last/window_x")
1680 && dt_conf_key_exists("ui_last/window_y"))
1681 {
1682 const int x = dt_conf_get_int("ui_last/window_x");
1683 const int y = dt_conf_get_int("ui_last/window_y");
1684 monitor = gdk_display_get_monitor_at_point(window_display, x, y);
1685 }
1686
1687 if(IS_NULL_PTR(monitor))
1688 monitor = gdk_display_get_primary_monitor(window_display);
1689 if(IS_NULL_PTR(monitor) && gdk_display_get_n_monitors(window_display) > 0)
1690 monitor = gdk_display_get_monitor(window_display, 0);
1691 }
1692
1693 if(!IS_NULL_PTR(monitor))
1694 {
1695 GdkRectangle workarea = { 0 };
1696 gdk_monitor_get_workarea(monitor, &workarea);
1697 gtk_window_move(GTK_WINDOW(gui->ui->main_window), workarea.x, workarea.y);
1698 }
1699 }
1700
1701 gtk_window_maximize(GTK_WINDOW(gui->ui->main_window));
1702 }
1703 else
1704 {
1705 int width = dt_conf_get_int("ui_last/window_width");
1706 int height = dt_conf_get_int("ui_last/window_height");
1707 gtk_window_resize(GTK_WINDOW(gui->ui->main_window), width, height);
1708
1709 gboolean restore_window_position = TRUE;
1710#ifdef GDK_WINDOWING_WAYLAND
1711 GdkDisplay *display = gtk_widget_get_display(gui->ui->main_window);
1712 if(GDK_IS_WAYLAND_DISPLAY(display))
1713 restore_window_position = FALSE;
1714#endif
1715
1716 if(restore_window_position
1717 && dt_conf_key_exists("ui_last/window_x")
1718 && dt_conf_key_exists("ui_last/window_y"))
1719 {
1720 const int x = dt_conf_get_int("ui_last/window_x");
1721 const int y = dt_conf_get_int("ui_last/window_y");
1722
1723 int clamped_x = x;
1724 int clamped_y = y;
1725 GdkDisplay *window_display = gtk_widget_get_display(gui->ui->main_window);
1726 GdkMonitor *monitor = NULL;
1727
1728 if(!IS_NULL_PTR(window_display))
1729 {
1730 if(dt_conf_key_exists("ui_last/window_monitor"))
1731 {
1732 const int monitor_index = dt_conf_get_int("ui_last/window_monitor");
1733 if(monitor_index >= 0 && monitor_index < gdk_display_get_n_monitors(window_display))
1734 monitor = gdk_display_get_monitor(window_display, monitor_index);
1735 }
1736
1737 if(IS_NULL_PTR(monitor))
1738 monitor = gdk_display_get_monitor_at_point(window_display, x + width / 2, y + height / 2);
1739 if(IS_NULL_PTR(monitor))
1740 monitor = gdk_display_get_primary_monitor(window_display);
1741 if(IS_NULL_PTR(monitor) && gdk_display_get_n_monitors(window_display) > 0)
1742 monitor = gdk_display_get_monitor(window_display, 0);
1743 }
1744
1745 if(!IS_NULL_PTR(monitor))
1746 {
1747 GdkRectangle workarea = { 0 };
1748 gdk_monitor_get_workarea(monitor, &workarea);
1749
1750 const int max_x = workarea.x + MAX(0, workarea.width - width);
1751 const int max_y = workarea.y + MAX(0, workarea.height - height);
1752 clamped_x = CLAMP(x, workarea.x, max_x);
1753 clamped_y = CLAMP(y, workarea.y, max_y);
1754 }
1755
1756 gtk_window_move(GTK_WINDOW(gui->ui->main_window), clamped_x, clamped_y);
1757 }
1758 }
1759
1761
1762 g_signal_connect(G_OBJECT(gui->ui->main_window ), "delete_event", G_CALLBACK(dt_gui_quit_callback), NULL);
1763 g_signal_connect(G_OBJECT(gui->ui->main_window ), "focus-in-event", G_CALLBACK(_focus_in_out_event), NULL);
1764 g_signal_connect(G_OBJECT(gui->ui->main_window ), "focus-out-event", G_CALLBACK(_focus_in_out_event), NULL);
1765 g_signal_connect_after(G_OBJECT(gui->ui->main_window ), "key-press-event", G_CALLBACK(_key_pressed), NULL);
1766 g_signal_connect_after(G_OBJECT(gui->ui->main_window ), "key-release-event", G_CALLBACK(_key_released), NULL);
1767
1768 container = gui->ui->main_window;
1769
1770 // Adding the outermost vbox
1771 widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, DT_GUI_BOX_SPACING);
1772 gtk_container_add(GTK_CONTAINER(container), widget);
1773 gtk_widget_show(widget);
1774
1775 /* connect to signal redraw all */
1777 G_CALLBACK(_ui_widget_redraw_callback), gui->ui->main_window);
1778
1779 container = widget;
1780
1781 // Initializing the main table
1783
1784 /* the log message */
1785 GtkWidget *eb = gtk_event_box_new();
1786 darktable.gui->ui->log_msg = gtk_label_new("");
1787 g_signal_connect(G_OBJECT(eb), "button-press-event", G_CALLBACK(_ui_log_button_press_event),
1788 darktable.gui->ui->log_msg);
1789 gtk_label_set_ellipsize(GTK_LABEL(darktable.gui->ui->log_msg), PANGO_ELLIPSIZE_MIDDLE);
1790 dt_gui_add_class(darktable.gui->ui->log_msg, "dt_messages");
1791 gtk_container_add(GTK_CONTAINER(eb), darktable.gui->ui->log_msg);
1792 gtk_widget_set_valign(eb, GTK_ALIGN_CENTER);
1793 gtk_widget_set_halign(eb, GTK_ALIGN_CENTER);
1794 gtk_overlay_add_overlay(GTK_OVERLAY(darktable.gui->ui->center_base), eb);
1795 //gtk_overlay_reorder_overlay(GTK_OVERLAY(darktable.gui->ui->center_base), eb, -1);
1796
1797 /* the toast message */
1798 eb = gtk_event_box_new();
1799 darktable.gui->ui->toast_msg = gtk_label_new("");
1800 g_signal_connect(G_OBJECT(eb), "button-press-event", G_CALLBACK(_ui_toast_button_press_event),
1801 darktable.gui->ui->toast_msg);
1802 gtk_widget_set_events(eb, GDK_BUTTON_PRESS_MASK | dt_widget_scroll_mask());
1803 g_signal_connect(G_OBJECT(eb), "scroll-event", G_CALLBACK(_scrolled), NULL);
1804 gtk_label_set_ellipsize(GTK_LABEL(darktable.gui->ui->toast_msg), PANGO_ELLIPSIZE_MIDDLE);
1805
1806 PangoAttrList *attrlist = pango_attr_list_new();
1807 PangoAttribute *attr = pango_attr_font_features_new("tnum");
1808 pango_attr_list_insert(attrlist, attr);
1809 gtk_label_set_attributes(GTK_LABEL(darktable.gui->ui->toast_msg), attrlist);
1810 pango_attr_list_unref(attrlist);
1811
1812 dt_gui_add_class(darktable.gui->ui->toast_msg, "dt_messages");
1813 gtk_container_add(GTK_CONTAINER(eb), darktable.gui->ui->toast_msg);
1814 gtk_widget_set_valign(eb, GTK_ALIGN_START);
1815 gtk_widget_set_halign(eb, GTK_ALIGN_CENTER);
1816 gtk_overlay_add_overlay(GTK_OVERLAY(darktable.gui->ui->center_base), eb);
1817 //gtk_overlay_reorder_overlay(GTK_OVERLAY(darktable.gui->ui->center_base), eb, -1);
1818
1819 /* update log message label */
1821 darktable.gui->ui->log_msg);
1822
1823 /* update toast message label */
1825 darktable.gui->ui->toast_msg);
1826
1827
1828 // Showing everything
1829 gtk_widget_show_all(dt_ui_main_window(gui->ui));
1830
1831 gtk_widget_set_visible(dt_ui_log_msg(gui->ui), FALSE);
1832 gtk_widget_set_visible(dt_ui_toast_msg(gui->ui), FALSE);
1833}
1834
1836{
1837 g_return_if_fail(GTK_IS_CONTAINER(ui->containers[c]));
1838
1839 if(GTK_WIDGET(ui->containers[c]) != gtk_widget_get_parent(w)) return;
1840
1841 gtk_container_set_focus_child(GTK_CONTAINER(ui->containers[c]), w);
1842 gtk_widget_queue_draw(ui->containers[c]);
1843}
1844
1845void dt_ui_container_foreach(dt_ui_t *ui, const dt_ui_container_t c, GtkCallback callback)
1846{
1847 g_return_if_fail(GTK_IS_CONTAINER(ui->containers[c]));
1848 gtk_container_foreach(GTK_CONTAINER(ui->containers[c]), callback, (gpointer)ui->containers[c]);
1849}
1850
1855
1857{
1858 if(darktable.gui && !gtk_window_is_active(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui))))
1859 {
1860 gtk_window_set_urgency_hint(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), TRUE);
1861#ifdef MAC_INTEGRATION
1862#ifdef GTK_TYPE_OSX_APPLICATION
1863 gtk_osxapplication_attention_request(g_object_new(GTK_TYPE_OSX_APPLICATION, NULL), INFO_REQUEST);
1864#else
1865 gtkosx_application_attention_request(g_object_new(GTKOSX_TYPE_APPLICATION, NULL), INFO_REQUEST);
1866#endif
1867#endif
1868 }
1869}
1870
1871/* this is called as a signal handler, the signal raising logic asserts the gdk lock. */
1872static void _ui_widget_redraw_callback(gpointer instance, GtkWidget *widget)
1873{
1874 gtk_widget_queue_draw(widget);
1875}
1876
1877static void _ui_log_redraw_callback(gpointer instance, GtkWidget *widget)
1878{
1879 // draw log message, if any
1880 dt_control_t *const control = dt_control_get_global();
1882 if(!GTK_IS_LABEL(widget))
1883 {
1885 return;
1886 }
1887 if(dt_control_get_global()->log_ack != dt_control_get_global()->log_pos)
1888 {
1889 if(strcmp(dt_control_get_global()->log_message[dt_control_get_global()->log_ack], gtk_label_get_text(GTK_LABEL(widget))))
1890 gtk_label_set_markup(GTK_LABEL(widget), dt_control_get_global()->log_message[dt_control_get_global()->log_ack]);
1891 gtk_widget_show(widget);
1892 }
1893 else
1894 {
1895 gtk_widget_hide(widget);
1896 }
1898}
1899
1900static void _ui_toast_redraw_callback(gpointer instance, GtkWidget *widget)
1901{
1902 // draw toast message, if any
1903 dt_control_t *const control = dt_control_get_global();
1905 if(!GTK_IS_LABEL(widget))
1906 {
1908 return;
1909 }
1910 if(dt_control_get_global()->toast_ack != dt_control_get_global()->toast_pos)
1911 {
1912 if(strcmp(dt_control_get_global()->toast_message[dt_control_get_global()->toast_ack], gtk_label_get_text(GTK_LABEL(widget))))
1913 gtk_label_set_markup(GTK_LABEL(widget), dt_control_get_global()->toast_message[dt_control_get_global()->toast_ack]);
1914 if(!gtk_widget_get_visible(widget))
1915 {
1916 const int h = gtk_widget_get_allocated_height(dt_ui_center_base(darktable.gui->ui));
1917 gtk_widget_set_margin_bottom(gtk_widget_get_parent(widget), 0.15 * h - DT_PIXEL_APPLY_DPI(10));
1918 gtk_widget_show(widget);
1919 }
1920 }
1921 else
1922 {
1923 if(gtk_widget_get_visible(widget)) gtk_widget_hide(widget);
1924 }
1926}
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938// TODO: should that go to another place than gtk.c?
1939void dt_gui_add_help_link(GtkWidget *widget, char *link)
1940{
1941 g_object_set_data_full(G_OBJECT(widget), "dt-help-url", link, g_free);
1942 gtk_widget_add_events(widget, GDK_BUTTON_PRESS_MASK);
1943}
1944
1945// load a CSS theme
1946void dt_gui_load_theme(const char *theme)
1947{
1948 char theme_css[DT_PATH_MAX] = { 0 };
1949 g_snprintf(theme_css, sizeof(theme_css), "%s.css", theme);
1950
1951 if(!dt_conf_key_exists("use_system_font"))
1952 dt_conf_set_bool("use_system_font", TRUE);
1953
1954 //set font size
1955 if(dt_conf_get_bool("use_system_font"))
1956 gtk_settings_reset_property(gtk_settings_get_default(), "gtk-font-name");
1957 else
1958 {
1959 //font name can only use period as decimal separator
1960 //but printf format strings use comma for some locales, so replace comma with period
1961 gchar *font_size = g_strdup_printf(_("%.1f"), dt_conf_get_float("font_size"));
1962 gchar *font_size_updated = dt_util_str_replace(font_size, ",", ".");
1963 gchar *font_name = g_strdup_printf(_("Sans %s"), font_size_updated);
1964 g_object_set(gtk_settings_get_default(), "gtk-font-name", font_name, NULL);
1965 dt_free(font_size_updated);
1966 dt_free(font_size);
1967 dt_free(font_name);
1968 }
1969
1970 gchar *path, *usercsspath;
1971 char datadir[DT_PATH_MAX] = { 0 }, configdir[DT_PATH_MAX] = { 0 };
1972 dt_loc_get_datadir(datadir, sizeof(datadir));
1973 dt_loc_get_user_config_dir(configdir, sizeof(configdir));
1974
1975 // user dir theme
1976 path = g_build_filename(configdir, "themes", theme_css, NULL);
1977 if(!g_file_test(path, G_FILE_TEST_EXISTS))
1978 {
1979 // dt dir theme
1980 dt_free(path);
1981 path = g_build_filename(datadir, "themes", theme_css, NULL);
1982 if(!g_file_test(path, G_FILE_TEST_EXISTS))
1983 {
1984 // fallback to default theme
1985 dt_free(path);
1986 path = g_build_filename(datadir, "themes", "ansel.css", NULL);
1987 dt_conf_set_string("ui_last/theme", "ansel");
1988 }
1989 else
1990 dt_conf_set_string("ui_last/theme", theme);
1991 }
1992 else
1993 dt_conf_set_string("ui_last/theme", theme);
1994
1995 GError *error = NULL;
1996
1997 GtkStyleProvider *themes_style_provider = GTK_STYLE_PROVIDER(gtk_css_provider_new());
1998 gtk_style_context_add_provider_for_screen
1999 (gdk_screen_get_default(), themes_style_provider, GTK_STYLE_PROVIDER_PRIORITY_USER + 1);
2000
2001 usercsspath = g_build_filename(configdir, "user.css", NULL);
2002
2003 gchar *path_uri = g_filename_to_uri(path, NULL, &error);
2004 if(IS_NULL_PTR(path_uri))
2005 fprintf(stderr, "%s: could not convert path %s to URI. Error: %s\n", G_STRFUNC, path, error->message);
2006
2007 gchar *usercsspath_uri = g_filename_to_uri(usercsspath, NULL, &error);
2008 if(IS_NULL_PTR(usercsspath_uri))
2009 fprintf(stderr, "%s: could not convert path %s to URI. Error: %s\n", G_STRFUNC, usercsspath, error->message);
2010
2011 gchar *themecss = NULL;
2012 if(dt_conf_get_bool("themes/usercss") && g_file_test(usercsspath, G_FILE_TEST_EXISTS))
2013 {
2014 themecss = g_strjoin(NULL, "@import url('", path_uri,
2015 "'); @import url('", usercsspath_uri, "');", NULL);
2016 }
2017 else
2018 {
2019 themecss = g_strjoin(NULL, "@import url('", path_uri, "');", NULL);
2020 }
2021
2022 dt_free(path_uri);
2023 dt_free(usercsspath_uri);
2024 dt_free(path);
2025 dt_free(usercsspath);
2026
2027 if(dt_conf_get_bool("ui/hide_tooltips"))
2028 {
2029 gchar *newcss = g_strjoin(NULL, themecss, " tooltip {opacity: 0; background: transparent;}", NULL);
2030 dt_free(themecss);
2031 themecss = newcss;
2032 }
2033
2034 if(!gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(themes_style_provider), themecss, -1, &error))
2035 {
2036 fprintf(stderr, "%s: error parsing combined CSS %s: %s\n", G_STRFUNC, themecss, error->message);
2037 g_clear_error(&error);
2038 }
2039
2040 dt_free(themecss);
2041
2042 g_object_unref(themes_style_provider);
2043
2044 // setup the colors
2045
2046 GdkRGBA *c = dt_widget_colors();
2047 GtkWidget *main_window = dt_ui_main_window(darktable.gui->ui);
2048 GtkStyleContext *ctx = gtk_widget_get_style_context(main_window);
2049
2050 c[DT_GUI_COLOR_BG] = (GdkRGBA){ 0.1333, 0.1333, 0.1333, 1.0 };
2051
2052 struct color_init
2053 {
2054 const char *name;
2055 GdkRGBA default_col;
2056 } init[DT_GUI_COLOR_LAST] = {
2057 [DT_GUI_COLOR_DARKROOM_BG] = { "darkroom_bg_color", { .2, .2, .2, 1.0 } },
2058 [DT_GUI_COLOR_DARKROOM_PREVIEW_BG] = { "darkroom_preview_bg_color", { .1, .1, .1, 1.0 } },
2059 [DT_GUI_COLOR_LIGHTTABLE_BG] = { "lighttable_bg_color", { .2, .2, .2, 1.0 } },
2060 [DT_GUI_COLOR_LIGHTTABLE_PREVIEW_BG] = { "lighttable_preview_bg_color", { .1, .1, .1, 1.0 } },
2061 [DT_GUI_COLOR_LIGHTTABLE_FONT] = { "lighttable_bg_font_color", { .7, .7, .7, 1.0 } },
2062 [DT_GUI_COLOR_PRINT_BG] = { "print_bg_color", { .2, .2, .2, 1.0 } },
2063 [DT_GUI_COLOR_BRUSH_CURSOR] = { "brush_cursor", { 1., 1., 1., 0.9 } },
2064 [DT_GUI_COLOR_BRUSH_TRACE] = { "brush_trace", { 0., 0., 0., 0.8 } },
2065 [DT_GUI_COLOR_BUTTON_FG] = { "button_fg", { 0.7, 0.7, 0.7, 0.55 } },
2066 [DT_GUI_COLOR_THUMBNAIL_BG] = { "thumbnail_bg_color", { 0.4, 0.4, 0.4, 1.0 } },
2067 [DT_GUI_COLOR_THUMBNAIL_SELECTED_BG] = { "thumbnail_selected_bg_color", { 0.8, 0.8, 0.8, 1.0 } },
2068 [DT_GUI_COLOR_THUMBNAIL_HOVER_BG] = { "thumbnail_hover_bg_color", { 0.65, 0.65, 0.65, 1.0 } },
2069 [DT_GUI_COLOR_THUMBNAIL_OUTLINE] = { "thumbnail_outline_color", { 0.2, 0.2, 0.2, 1.0 } },
2070 [DT_GUI_COLOR_THUMBNAIL_SELECTED_OUTLINE] = { "thumbnail_selected_outline_color", { 0.4, 0.4, 0.4, 1.0 } },
2071 [DT_GUI_COLOR_THUMBNAIL_HOVER_OUTLINE] = { "thumbnail_hover_outline_color", { 0.6, 0.6, 0.6, 1.0 } },
2072 [DT_GUI_COLOR_THUMBNAIL_FONT] = { "thumbnail_font_color", { 0.425, 0.425, 0.425, 1.0 } },
2073 [DT_GUI_COLOR_THUMBNAIL_SELECTED_FONT] = { "thumbnail_selected_font_color", { 0.5, 0.5, 0.5, 1.0 } },
2074 [DT_GUI_COLOR_THUMBNAIL_HOVER_FONT] = { "thumbnail_hover_font_color", { 0.7, 0.7, 0.7, 1.0 } },
2075 [DT_GUI_COLOR_THUMBNAIL_BORDER] = { "thumbnail_border_color", { 0.1, 0.1, 0.1, 1.0 } },
2076 [DT_GUI_COLOR_THUMBNAIL_SELECTED_BORDER] = { "thumbnail_selected_border_color", { 0.9, 0.9, 0.9, 1.0 } },
2077 [DT_GUI_COLOR_FILMSTRIP_BG] = { "filmstrip_bg_color", { 0.2, 0.2, 0.2, 1.0 } },
2078 [DT_GUI_COLOR_PREVIEW_HOVER_BORDER] = { "preview_hover_border_color", { 0.9, 0.9, 0.9, 1.0 } },
2079 [DT_GUI_COLOR_LOG_BG] = { "log_bg_color", { 0.1, 0.1, 0.1, 1.0 } },
2080 [DT_GUI_COLOR_LOG_FG] = { "log_fg_color", { 0.6, 0.6, 0.6, 1.0 } },
2081 [DT_GUI_COLOR_MAP_COUNT_SAME_LOC] = { "map_count_same_loc_color", { 1.0, 1.0, 1.0, 1.0 } },
2082 [DT_GUI_COLOR_MAP_COUNT_DIFF_LOC] = { "map_count_diff_loc_color", { 1.0, 0.85, 0.0, 1.0 } },
2083 [DT_GUI_COLOR_MAP_COUNT_BG] = { "map_count_bg_color", { 0.0, 0.0, 0.0, 1.0 } },
2084 [DT_GUI_COLOR_MAP_LOC_SHAPE_HIGH] = { "map_count_circle_color_h", { 1.0, 1.0, 0.8, 1.0 } },
2085 [DT_GUI_COLOR_MAP_LOC_SHAPE_LOW] = { "map_count_circle_color_l", { 0.0, 0.0, 0.0, 1.0 } },
2086 [DT_GUI_COLOR_MAP_LOC_SHAPE_DEF] = { "map_count_circle_color_d", { 1.0, 0.0, 0.0, 1.0 } },
2087 [DT_GUI_COLOR_WARNING] = { "warning_color", { 1.0, 0.647, 0.0, 1.0 } },
2088 };
2089
2090 // starting from 1 as DT_GUI_COLOR_BG is not part of this table
2091 for(int i = 1; i < DT_GUI_COLOR_LAST; i++)
2092 {
2093 if(!gtk_style_context_lookup_color(ctx, init[i].name, &c[i]))
2094 {
2095 c[i] = init[i].default_col;
2096 }
2097 }
2098
2100
2101 // The active theme/font may change the root font size, so refresh the cached em
2102 // that drives DT_GUI_BOX_SPACING.
2104}
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158// draw rounded rectangle
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2178{
2179 // Refocus window, useful if we just closed a popup/modal/transient
2180 gtk_window_present_with_time(GTK_WINDOW(dt_ui_main_window(darktable.gui->ui)), GDK_CURRENT_TIME);
2181
2182 // Desperate measure to refocus the window
2183 gtk_grab_add(dt_ui_main_window(darktable.gui->ui));
2184 gtk_grab_remove(dt_ui_main_window(darktable.gui->ui));
2185 gtk_widget_grab_focus(dt_ui_main_window(darktable.gui->ui));
2186
2187 // dt_view_manager_name() returns the translated display name (e.g. "Table lumineuse"), not the
2188 // internal id: compare against module_name, which is stable and untranslated.
2189 const dt_view_t *current_view = dt_view_manager_get_current_view(darktable.view_manager);
2190 if(!IS_NULL_PTR(current_view) && !strcmp(current_view->module_name, "lighttable"))
2191 {
2192 gtk_widget_grab_focus(darktable.gui->ui->thumbtable_lighttable->grid);
2193 }
2194 else
2195 {
2196 gtk_widget_grab_focus(dt_ui_center(darktable.gui->ui));
2197 }
2198
2199 // Be sure to re-enable accelerators
2200 dt_accels_disable(darktable.gui->accels, FALSE);
2201}
2202
2203// clang-format off
2204// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
2205// vim: shiftwidth=2 expandtab tabstop=2 cindent
2206// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
2207// clang-format on
void dt_accels_set_top_offset_handler(dt_accels_top_offset_handler_t handler)
gboolean dt_accels_dispatch(GtkWidget *w, GdkEvent *event, gpointer user_data)
Force our listener for all key strokes to bypass reserved Gtk keys.
dt_accels_t * dt_accels_init(char *config_file, GtkAccelFlags flags)
void dt_accels_set_refocus_handler(dt_accels_refocus_handler_t handler)
void dt_accels_set_recent_handlers(dt_accels_recent_get_handler_t get, dt_accels_recent_set_handler_t set)
void dt_accels_set_global(dt_accels_t *accels)
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...
static void dt_accels_disable(dt_accels_t *accels, gboolean state)
#define DT_PRIMARY_MASK
void dt_gui_alert(const char *title, const char *message, const char *item, const gboolean once)
Definition alert.c:412
static const char * _get_source_name(int pos)
static gboolean _widget_stored_int(const char *key, int *value)
static double _clamp01d(const double value)
static void _accels_recent_set(int index, const char *value)
static gboolean _sample_tablet_state_from_devices(const GdkEvent *event, double *pressure, gboolean *have_pressure, double *tilt_x, double *tilt_y, gboolean *have_tilt, const char **picked_device_name)
static void _ui_widget_redraw_callback(gpointer instance, GtkWidget *widget)
static gint _accels_top_offset(void)
GtkWidget * dt_gui_main_window(void)
static gboolean _button_released(GtkWidget *w, GdkEventButton *event, gpointer user_data)
static dt_control_pointer_input_t _extract_pointer_input(const GdkEvent *event, const double x, const double y, const guint32 time_ms, const gboolean reset_kinematics, const char *tag)
void dt_ui_container_foreach(dt_ui_t *ui, const dt_ui_container_t c, GtkCallback callback)
calls a callback on all children widgets from container
gboolean dt_gui_quit_callback(GtkWidget *widget, GdkEvent *event, gpointer user_data)
static gboolean _center_leave(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
static gboolean _key_released(GtkWidget *w, GdkEventKey *event)
static const gdouble * _event_axes(const GdkEvent *event)
static gint _widget_natural_width(GtkWidget *widget)
static const char * _get_mode_name(int pos)
static void _center_unrealize(GtkWidget *widget, gpointer user_data)
static void _widget_store_bool(const char *key, gboolean value)
static void _widget_message(const char *message)
static gboolean _key_pressed(GtkWidget *w, GdkEventKey *event)
static gboolean _center_enter(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data)
struct dt_accels_t * dt_gui_get_accels(void)
static gboolean _ui_toast_button_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
static gboolean _button_pressed(GtkWidget *w, GdkEventButton *event, gpointer user_data)
static dt_tablet_motion_state_t _tablet_motion_state
static gchar * _accels_recent_get(int index)
static gboolean _draw(GtkWidget *da, cairo_t *cr, gpointer user_data)
static gboolean _ui_log_button_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
static void _notify_profile_changed(void)
void dt_ui_container_destroy_children(dt_ui_t *ui, const dt_ui_container_t c)
destroy all child widgets from container
static gboolean _log_key_event(GSignalInvocationHint *hint, guint n_params, const GValue *params, gpointer data)
struct dt_ui_t * dt_gui_get_ui(void)
static gboolean _widget_stored_bool(const char *key)
static LRESULT CALLBACK _center_win32_cursor_proc(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id, DWORD_PTR ref_data)
static void _pixelpipe_cache_alert(const char *message, const char *item)
void dt_gui_load_theme(const char *theme)
static void _widget_cursor(GdkCursorType cursor)
int dt_gui_gtk_write_config()
void dt_gui_store_last_preset(const char *name)
void dt_configure_ppd_dpi(dt_gui_gtk_t *gui)
GtkWidget * dt_gui_center_widget(void)
static gboolean _get_axis_value_for_source(const GdkEvent *event, GdkDevice *source_device, const GdkAxisUse axis, double *value, gboolean *from_source_map)
static const char * _get_axis_name(int pos)
void dt_gui_gtk_quit()
static gboolean _refresh_thumbnail_on_gui_thread(gpointer user_data)
static void _refresh_thumbnail_widgets(int32_t imgid, gboolean refresh_filmstrip)
static void _init_widgets(dt_gui_gtk_t *gui)
static void _update_display_profile(void)
static gboolean _mouse_moved(GtkWidget *w, GdkEventMotion *event, gpointer user_data)
#define DT_ACCEL_SEARCH_RECENT_KEY
void dt_gui_add_help_link(GtkWidget *widget, char *link)
#define DT_WIN32_CURSOR_SUBCLASS_CENTER
void dt_ui_notify_user()
draw user's attention
static void _notebook_page_changed(gpointer owner)
static gboolean _focus_in_out_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
static void _ui_log_redraw_callback(gpointer instance, GtkWidget *widget)
int dt_gui_gtk_init(dt_gui_gtk_t *gui)
static void _widget_store_int(const char *key, int value)
void dt_gui_refocus_center()
static void _gui_refresh_thumbnail(int32_t imgid, gboolean refresh_filmstrip)
static void _refresh_all_container_spacing(void)
static gint _last_box_spacing
void dt_gui_set_pango_resolution(PangoLayout *layout)
static gboolean _configure(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
static gboolean _scrolled(GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
static void _ui_toast_redraw_callback(gpointer instance, GtkWidget *widget)
void dt_gui_gtk_run(dt_gui_gtk_t *gui)
static GtkWidget * _widget_root_window(void)
static void _refresh_container_spacing(GtkWidget *w, gpointer user_data)
static gboolean _window_configure(GtkWidget *da, GdkEvent *event, gpointer user_data)
static void _center_realize(GtkWidget *widget, gpointer user_data)
static void _gui_startup_progress(const char *message)
void dt_ui_container_focus_widget(dt_ui_t *ui, const dt_ui_container_t c, GtkWidget *w)
gives a widget focus in the container
static gboolean _sample_axis_from_device_state(GdkWindow *window, GdkDevice *device, const GdkAxisUse axis, double *value)
void dt_gui_update_em(void)
static void error(char *msg)
Definition ashift_lsd.c:202
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
void init(dt_imageio_module_format_t *self)
Definition avif.c:157
uint32_t container(dt_lib_module_t *self)
void dt_gui_closing_quit(void)
Definition closing.c:384
void dt_gui_closing_wait(void)
Definition closing.c:389
void dt_collection_init_global(void)
Definition collection.c:143
void dt_collection_gui_register_handlers(void)
@ DT_COLORLABELS_PURPLE
Definition colorlabels.h:46
@ DT_COLORLABELS_LAST
Definition colorlabels.h:47
@ DT_COLORLABELS_RED
Definition colorlabels.h:42
static const float x
static void _notify_profile_changed(void)
void dt_colorspaces_set_profile_changed_handler(dt_colorspaces_profile_changed_handler_t handler)
Register the one callback fired when the display profile changes.
void dt_colorspaces_set_display_profile(const dt_colorspaces_color_profile_type_t profile_type, GtkWidget *widget)
Refresh the cached display profile from the monitor showing widget (X atom, colord,...
The colour-profile module's API: which profiles exist, and how to apply one.
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
void dt_conf_set_bool(const char *name, int val)
int dt_conf_get_bool(const char *name)
int dt_conf_key_exists(const char *key)
Does key have a value?
float dt_conf_get_float(const char *name)
Float for name, clamped to its declared bounds.
gchar * dt_conf_get_string(const char *name)
Read the stored string for name as a private copy.
void dt_conf_set_int(const char *name, int val)
int dt_conf_get_int(const char *name)
Integer for name, clamped to the bounds declared in the XML.
void dt_conf_set_string(const char *name, const char *val)
const char * dt_conf_get_string_const(const char *name)
Borrow the stored string for name without copying it.
void dt_gui_container_destroy_children(GtkContainer *container)
Definition container.c:80
void dt_control_set_shutdown_wait_handler(dt_control_shutdown_wait_t handler)
Definition control.c:470
void dt_control_key_pressed(GdkEventKey *event)
Definition control.c:682
void dt_control_button_pressed(double x, double y, double pressure, int which, int type, uint32_t state)
Definition control.c:792
void dt_toast_log(const char *msg,...)
Definition control.c:922
void dt_control_set_alert_handler(dt_control_alert_handler_t handler)
Install the alert handler; NULL restores the fallback to dt_control_log().
Definition control.c:871
void dt_control_mouse_leave()
Definition control.c:667
gboolean dt_control_configure(GtkWidget *da, GdkEventConfigure *event, gpointer user_data)
Definition control.c:530
void dt_control_button_released(double x, double y, int which, uint32_t state)
Definition control.c:692
void dt_control_set_pointer_input(const dt_control_pointer_input_t *input)
Definition control.c:77
int dt_control_running()
Definition control.c:442
void dt_control_mouse_moved(double x, double y, double pressure, int which)
Definition control.c:677
void dt_control_key_released(GdkEventKey *event)
Definition control.c:687
void dt_control_mouse_enter()
Definition control.c:672
void dt_control_expose(cairo_t *cr, const int width, const int height)
Definition control.c:609
#define dt_control_change_cursor(cursor)
Definition control.h:122
struct dt_control_t * dt_control_get_global(void)
Definition darktable.c:654
int dt_load_from_string(const gchar *input, gboolean open_image_in_dr, gboolean *single_image)
Definition darktable.c:392
void dt_cleanup()
Definition darktable.c:1867
darktable_t darktable
Definition darktable.c:213
struct dt_gui_gtk_t * dt_gui_get_global(void)
Definition darktable.c:526
dev roi_request value
GtkWidget * window
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:127
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
Initialise a mutex. With mutexattr NULL – which is how 54 of the 56 call sites in this tree spell it ...
Definition dtpthread.h:104
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
Definition dtpthread.h:117
void dt_loc_get_sharedir(char *sharedir, size_t bufsize)
void dt_loc_get_datadir(char *datadir, size_t bufsize)
void dt_loc_get_user_config_dir(char *configdir, size_t bufsize)
void dt_film_gui_register_handlers(void)
Definition film_gui.c:116
void dt_folder_survey_gui_register_handlers()
int instance
One module instance's contribution, as data.
Definition geometry.h:101
void * data
Definition geometry.h:111
void dt_gui_presets_init()
void dt_guides_init(void)
Definition guides.c:594
void dt_guides_set_overlay_colors()
Definition guides.c:680
void dt_history_merge_gui_register_handlers(void)
void dt_gui_import_init_handlers(void)
Register the GUI-side import handlers (the discarded-files recap dialog).
Definition import.c:1791
const char * dt_l10n_get_current_lang(dt_l10n_t *l10n)
Definition l10n.c:457
struct dt_l10n_t * dt_l10n_get_global(void)
Definition darktable.c:639
static const dt_iop_drawlayer_params_t * params
Definition layers.h:80
@ DT_DEBUG_INPUT
Definition logging.h:64
@ DT_DEBUG_CONTROL
Definition logging.h:52
@ DT_DEBUG_MASKS
Definition logging.h:62
int32_t dt_get_debug_flags(void)
Definition darktable.c:2094
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
char * key
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
size_t size
Definition mipmap_cache.c:3
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
g_free(manifest_path)
void dt_osx_focus_window()
Definition osx.mm:289
void dt_osx_autoset_dpi(GtkWidget *widget)
Definition osx.mm:55
#define DT_PATH_MAX
Buffer size for a filesystem path anywhere in Ansel.
Definition paths.h:57
void dt_concat_path_file(char destination[4096], const char path[4096], const char *const file)
Append a constant filename to a variable, stack-based, fixed-sized, directory, and add a / in-between...
Definition darktable.c:2683
const char * name
Definition pdf.h:90
void dt_dev_pixelpipe_cache_set_alert_handler(dt_pixelpipe_cache_alert_handler_t alert)
Install the alert handler. The GUI installs it, once it exists, apart from the others: without a GUI ...
Pixelpipe cache for storing intermediate results in the pixelpipe.
@ DT_COLORSPACE_DISPLAY
The monitor profile – the one list entry that mutates after init.
void dt_screen_set_dpi(double dpi)
void dt_selection_init_global(void)
Definition selection.c:85
#define DT_DEBUG_CONTROL_SIGNAL_RAISE(ctlsig, signal,...)
Definition signal.h:390
struct dt_control_signal_t * dt_control_signal_get_global(void)
Definition darktable.c:619
@ DT_SIGNAL_CONTROL_REDRAW_ALL
This signal is raised when dt_control_queue_redraw() is called. no param, no returned value.
Definition signal.h:73
@ DT_SIGNAL_CONTROL_TOAST_REDRAW
This signal is raised when dt_control_toast_redraw() is called. no param, no returned value.
Definition signal.h:292
@ DT_SIGNAL_CONTROL_NOTEBOOK_TAB_CHANGED
This signal is raised when a GtkNotebook created/registered via dt_ui_notebook_set_picker_owner() swi...
Definition signal.h:306
@ DT_SIGNAL_CONTROL_PROFILE_CHANGED
This signal is raised when the screen profile has changed no param, no returned value.
Definition signal.h:240
@ DT_SIGNAL_CONTROL_LOG_REDRAW
This signal is raised when dt_control_log_redraw() is called. no param, no returned value.
Definition signal.h:287
#define DT_DEBUG_CONTROL_SIGNAL_CONNECT(ctlsig, signal, cb, user_data)
Definition signal.h:400
void dt_gui_splash_init(void)
Definition splash.c:516
void dt_gui_splash_updatef(const char *format,...)
Definition splash.c:691
void dt_gui_splash_set_transient_for(GtkWidget *parent)
Definition splash.c:83
void dt_startup_progress_set_handler(dt_startup_progress_handler_t handler)
dt_pthread_mutex_t log_mutex
Definition control.h:233
dt_pthread_mutex_t toast_mutex
Definition control.h:240
int32_t center_tooltip
GtkWidget * module
dt_accels_t * accels
GtkMenu * presets_popup_menu
char gtkrc[DT_PATH_MAX]
double dpi_factor
dt_ui_t * ui
dt_pthread_mutex_t mutex
gboolean culling_mode
GtkWidget * window
cairo_filter_t filter_image
char * last_preset
struct dt_gui_gtk_t::@310034163271067065001067313203076354050152156220 export_popup
struct dt_gui_gtk_t::@203355275301244245372310074133053245302222037030 styles_popup
dt_thumbtable_t * thumbtable_lighttable
GtkWidget * containers[DT_UI_CONTAINER_SIZE]
GtkWidget * main_window
dt_thumbtable_t * thumbtable_filmstrip
GtkWidget * panels[DT_UI_PANEL_SIZE]
char module_name[64]
Definition view.h:155
typedef double((*spd)(unsigned long int wavelength, double TempK))
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29
void dt_thumbnail_notify_set_handler(dt_thumbnail_refresh_handler_t handler)
A widget to manage and display image thumbnails in Ansel's lighttable and filmstrip views.
#define dt_thumbtable_refresh_thumbnail(table, imgid, reinit)
Definition thumbtable.h:301
gchar * dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute)
Definition utility.c:163
void dt_view_manager_configure(dt_view_manager_t *vm, int width, int height)
Definition view.c:665
int dt_view_manager_scrolled(dt_view_manager_t *vm, double x, double y, int up, int state, int delta_y)
Definition view.c:677
const dt_view_t * dt_view_manager_get_current_view(dt_view_manager_t *vm)
Definition view.c:144
void dt_widget_set_ppd(double ppd)
void dt_widget_set_cursor_handler(dt_widget_cursor_handler_t handler)
gboolean dt_gui_get_scroll_unit_delta(const GdkEventScroll *event, int *delta)
void dt_widget_set_debug_overlays(gboolean enabled)
void dt_widget_set_dpi_factor(double factor)
void dt_widget_set_image_filter(cairo_filter_t filter)
void dt_widget_set_scroll_reversed(gboolean reverse_x, gboolean reverse_y)
GdkRGBA * dt_widget_colors(void)
void dt_gui_freeze_reset(void)
void dt_widget_set_theme_loaded(gboolean loaded)
void dt_widget_set_natural_width_handler(dt_widget_natural_width_handler_t handler)
gboolean dt_widget_on_gui_thread(void)
Is the calling thread the one that owns widget state?
void dt_widget_set_root_window_handler(dt_widget_root_window_handler_t handler)
void dt_widget_set_em_size(double em)
void dt_widget_set_gui_thread(pthread_t thread)
void dt_widget_set_notebook_page_handler(dt_widget_notebook_page_handler_t handler)
void dt_widget_set_refocus_handler(dt_widget_refocus_handler_t handler)
GdkEventMask dt_widget_scroll_mask(void)
void dt_widget_set_scroll_focus(GtkWidget *widget)
double dt_get_system_gui_ppd(GtkWidget *widget)
void dt_widget_set_storage_handlers(dt_widget_stored_int_getter_t get_int, dt_widget_stored_int_setter_t set_int, dt_widget_stored_bool_getter_t get_bool, dt_widget_stored_bool_setter_t set_bool)
void dt_widget_set_message_handler(dt_widget_message_handler_t handler)
void dt_widget_set_mouse_radius(float radius, float clamped)
void dt_widget_set_scroll_mask(GdkEventMask mask)
@ DT_WIDGET_COLORLABEL_RED
@ DT_WIDGET_COLORLABEL_PURPLE
@ DT_WIDGET_COLORLABEL_COUNT
@ DT_GUI_COLOR_BG
@ DT_GUI_COLOR_DARKROOM_PREVIEW_BG
@ DT_GUI_COLOR_LIGHTTABLE_FONT
@ DT_GUI_COLOR_MAP_LOC_SHAPE_HIGH
@ DT_GUI_COLOR_LOG_FG
@ DT_GUI_COLOR_BRUSH_CURSOR
@ DT_GUI_COLOR_LAST
@ DT_GUI_COLOR_THUMBNAIL_FONT
@ DT_GUI_COLOR_THUMBNAIL_SELECTED_BG
@ DT_GUI_COLOR_MAP_COUNT_BG
@ DT_GUI_COLOR_LOG_BG
@ DT_GUI_COLOR_THUMBNAIL_SELECTED_BORDER
@ DT_GUI_COLOR_THUMBNAIL_OUTLINE
@ DT_GUI_COLOR_MAP_LOC_SHAPE_LOW
@ DT_GUI_COLOR_LIGHTTABLE_BG
@ DT_GUI_COLOR_BUTTON_FG
@ DT_GUI_COLOR_DARKROOM_BG
@ DT_GUI_COLOR_THUMBNAIL_BORDER
@ DT_GUI_COLOR_LIGHTTABLE_PREVIEW_BG
@ DT_GUI_COLOR_WARNING
@ DT_GUI_COLOR_MAP_COUNT_SAME_LOC
@ DT_GUI_COLOR_MAP_COUNT_DIFF_LOC
@ DT_GUI_COLOR_THUMBNAIL_BG
@ DT_GUI_COLOR_PREVIEW_HOVER_BORDER
@ DT_GUI_COLOR_FILMSTRIP_BG
@ DT_GUI_COLOR_BRUSH_TRACE
@ DT_GUI_COLOR_THUMBNAIL_SELECTED_FONT
@ DT_GUI_COLOR_THUMBNAIL_SELECTED_OUTLINE
@ DT_GUI_COLOR_THUMBNAIL_HOVER_BG
@ DT_GUI_COLOR_PRINT_BG
@ DT_GUI_COLOR_MAP_LOC_SHAPE_DEF
@ DT_GUI_COLOR_THUMBNAIL_HOVER_FONT
@ DT_GUI_COLOR_THUMBNAIL_HOVER_OUTLINE
#define DT_UI_SCALE_DEVICE(value)
#define DT_GUI_BOX_SPACING
#define DT_PIXEL_APPLY_DPI(value)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)
GtkWidget * dt_ui_toast_msg(dt_ui_t *ui)
GtkWidget * dt_ui_center(dt_ui_t *ui)
void dt_ui_cleanup_titlebar(dt_ui_t *ui)
void dt_ui_init_titlebar(dt_ui_t *ui)
int dt_ui_panel_get_size(dt_ui_t *ui, const dt_ui_panel_t p)
gboolean dt_ui_panel_ancestor(dt_ui_t *ui, const dt_ui_panel_t p, GtkWidget *w)
GtkWidget * dt_ui_log_msg(dt_ui_t *ui)
GtkWidget * dt_ui_main_window(dt_ui_t *ui)
void dt_ui_init_main_table(GtkWidget *parent, dt_ui_t *ui)
GtkWidget * dt_ui_center_base(dt_ui_t *ui)
dt_ui_container_t
@ DT_UI_PANEL_TOP
@ DT_UI_PANEL_LEFT
@ DT_UI_PANEL_RIGHT