From 8eef7bd8d2a136acf369b8bab8b856ccd3b6aa92 Mon Sep 17 00:00:00 2001 From: Hanno Schwalm Date: Sat, 23 Nov 2024 07:11:07 +0100 Subject: [PATCH] Introduce dt_iop_has_focus() Implement a check for an iop module being in focus and make use of that where safely possible now. --- src/develop/imageop.c | 9 +++++++++ src/develop/imageop.h | 2 ++ src/iop/ashift.c | 13 +++---------- src/iop/clipping.c | 8 +------- src/iop/colorequal.c | 2 +- src/iop/crop.c | 8 +------- 6 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/develop/imageop.c b/src/develop/imageop.c index 1f8b07163ac1..3634793a086e 100644 --- a/src/develop/imageop.c +++ b/src/develop/imageop.c @@ -2310,6 +2310,15 @@ static gboolean _presets_scroll_callback(GtkWidget *widget, return TRUE; } +gboolean dt_iop_has_focus(dt_iop_module_t *module) +{ + return module + && module->dev + && module->dev->gui_attached + && module == module->dev->gui_module + && dt_dev_modulegroups_test_activated(darktable.develop); +} + void dt_iop_request_focus(dt_iop_module_t *module) { dt_develop_t *dev = darktable.develop; diff --git a/src/develop/imageop.h b/src/develop/imageop.h index c78fa5c7244a..4e2f627e21c8 100644 --- a/src/develop/imageop.h +++ b/src/develop/imageop.h @@ -412,6 +412,8 @@ GtkWidget *dt_iop_gui_header_button(dt_iop_module_t *module, /** requests the focus for this plugin (to draw overlays over the center image) */ void dt_iop_request_focus(dt_iop_module_t *module); +/** returns TRUE if tested module has focus */ +gboolean dt_iop_has_focus(dt_iop_module_t *module); /** allocate and load default settings from introspection. */ void dt_iop_default_init(dt_iop_module_t *module); /** loads default settings from database. */ diff --git a/src/iop/ashift.c b/src/iop/ashift.c index c22cb6e70aba..4d74fa7097d7 100644 --- a/src/iop/ashift.c +++ b/src/iop/ashift.c @@ -4054,13 +4054,6 @@ static gboolean _get_points(dt_iop_module_t *self, return FALSE; } -// does this gui have focus? -static gboolean _gui_has_focus(dt_iop_module_t *self) -{ - return (self->dev->gui_module == self - && dt_dev_modulegroups_test_activated(darktable.develop)); -} - /* this function replaces this sentence, it calls distort_transform() for this module on the pipe if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe, @@ -4154,7 +4147,7 @@ void gui_post_expose(dt_iop_module_t *self, // we draw the cropping area; we need x_off/y_off/width/height which is only available // after g->buf has been processed - if(g->buf && self->enabled && _gui_has_focus(self)) + if(g->buf && self->enabled && dt_iop_has_focus(self)) { // roi data of the preview pipe input buffer @@ -4354,7 +4347,7 @@ void gui_post_expose(dt_iop_module_t *self, if(g->fitting) return; // no structural data or visibility switched off? -> stop here - if(g->lines == NULL || !_gui_has_focus(self)) return; + if(g->lines == NULL || !dt_iop_has_focus(self)) return; // get hash value that reflects distortions from here to the end of the pixelpipe const dt_hash_t hash = dt_dev_hash_distort_plus(dev, @@ -5630,7 +5623,7 @@ void commit_params(dt_iop_module_t *self, d->orthocorr = (p->mode == ASHIFT_MODE_GENERIC) ? 0.0f : p->orthocorr; d->aspect = (p->mode == ASHIFT_MODE_GENERIC) ? 1.0f : p->aspect; - if(_gui_has_focus(self) + if(dt_iop_has_focus(self) || dt_isnan(p->cl) || dt_isnan(p->cr) || dt_isnan(p->ct) diff --git a/src/iop/clipping.c b/src/iop/clipping.c index 83cba2e4dcb7..13fcc7b550dd 100644 --- a/src/iop/clipping.c +++ b/src/iop/clipping.c @@ -391,12 +391,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self, return IOP_CS_RGB; } -static int gui_has_focus(dt_iop_module_t *self) -{ - return (self->dev->gui_module == self - && dt_dev_modulegroups_test_activated(darktable.develop)); -} - static void keystone_get_matrix(const dt_boundingbox_t k_space, float kxa, float kxb, float kxc, float kxd, float kya, float kyb, float kyc, float kyd, float *a, float *b, float *d, float *e, float *g, float *h) @@ -1328,7 +1322,7 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_ d->k_apply = 0; } - if(gui_has_focus(self)) + if(dt_iop_has_focus(self)) { d->cx = 0.0f; d->cy = 0.0f; diff --git a/src/iop/colorequal.c b/src/iop/colorequal.c index c528a7d4d446..ca9e3c8e7330 100644 --- a/src/iop/colorequal.c +++ b/src/iop/colorequal.c @@ -2537,7 +2537,7 @@ static gboolean _iop_colorequalizer_draw(GtkWidget *widget, dt_free_align(g->LUT); - if(self->enabled && (self == self->dev->gui_module) && g->picking) + if(self->enabled && dt_iop_has_focus(self) && g->picking) _draw_color_picker(self, cr, p, g, (double)graph_width, (double)graph_height); cairo_restore(cr); diff --git a/src/iop/crop.c b/src/iop/crop.c index 07e065c8a32a..4a500d614cb1 100644 --- a/src/iop/crop.c +++ b/src/iop/crop.c @@ -166,12 +166,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self, return IOP_CS_RGB; } -static int _gui_has_focus(dt_iop_module_t *self) -{ - return (self->dev->gui_module == self - && dt_dev_modulegroups_test_activated(darktable.develop)); -} - static void _commit_box(dt_iop_module_t *self, dt_iop_crop_gui_data_t *g, dt_iop_crop_params_t *p) @@ -421,7 +415,7 @@ void commit_params(dt_iop_module_t *self, dt_iop_crop_params_t *p = (dt_iop_crop_params_t *)p1; dt_iop_crop_data_t *d = piece->data; - if(_gui_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC)) + if(dt_iop_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC)) { d->cx = 0.0f; d->cy = 0.0f;