Skip to content

Commit

Permalink
Introduce dt_iop_has_focus()
Browse files Browse the repository at this point in the history
Implement a check for an iop module being in focus and make use of that where safely possible now.
  • Loading branch information
jenshannoschwalm committed Dec 4, 2024
1 parent d19e145 commit e0f3af5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
9 changes: 9 additions & 0 deletions src/develop/imageop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/develop/imageop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
13 changes: 3 additions & 10 deletions src/iop/ashift.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions src/iop/clipping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/iop/colorequal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions src/iop/crop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e0f3af5

Please sign in to comment.