Skip to content

Commit

Permalink
Merge pull request #18442 from jenshannoschwalm/control_maintenance
Browse files Browse the repository at this point in the history
Control maintenance
  • Loading branch information
TurboGit authored Feb 20, 2025
2 parents 7cc8d3d + cd93cd8 commit 5d1e0bb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/common/darktable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,10 +1828,12 @@ int dt_init(int argc, char *argv[], const gboolean init_gui, const gboolean load

if(init_gui)
{
darktable_splash_screen_set_progress(_("loading utility modules"));
darktable.lib = (dt_lib_t *)calloc(1, sizeof(dt_lib_t));
dt_lib_init(darktable.lib);

// init the gui part of views
darktable_splash_screen_set_progress(_("loading views"));
dt_view_manager_gui_init(darktable.view_manager);
}

Expand Down
49 changes: 13 additions & 36 deletions src/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,12 @@ void dt_control_init(const gboolean withgui)

// s->last_expose_time = dt_get_wtime();
s->log_pos = s->log_ack = 0;
s->log_busy = 0;
s->busy = 0;
s->log_message_timeout_id = 0;
dt_pthread_mutex_init(&s->log_mutex, NULL);

s->toast_pos = s->toast_ack = 0;
s->toast_busy = 0;
s->toast_message_timeout_id = 0;
dt_pthread_mutex_init(&s->toast_mutex, NULL);

pthread_cond_init(&s->cond, NULL);
dt_pthread_mutex_init(&s->cond_mutex, NULL);
Expand Down Expand Up @@ -371,7 +369,6 @@ void dt_control_cleanup(const gboolean withgui)
dt_pthread_mutex_destroy(&s->queue_mutex);
dt_pthread_mutex_destroy(&s->cond_mutex);
dt_pthread_mutex_destroy(&s->log_mutex);
dt_pthread_mutex_destroy(&s->toast_mutex);
dt_pthread_mutex_destroy(&s->res_mutex);
dt_pthread_mutex_destroy(&s->progress_system.mutex);
if(s->widgets) g_hash_table_destroy(s->widgets);
Expand Down Expand Up @@ -443,7 +440,7 @@ void dt_control_expose(GtkWidget *widget, cairo_t *cr)

// draw busy indicator
dt_pthread_mutex_lock(&dc->log_mutex);
if(dc->log_busy > 0)
if(dc->busy > 0)
{
dt_control_draw_busy_msg(cr, dc->width, dc->height);
}
Expand Down Expand Up @@ -566,10 +563,10 @@ static gboolean _dt_ctl_log_message_timeout_callback(gpointer data)
static gboolean _dt_ctl_toast_message_timeout_callback(gpointer data)
{
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->toast_mutex);
dt_pthread_mutex_lock(&dc->log_mutex);
dc->toast_ack = dc->toast_pos;
dc->toast_message_timeout_id = 0;
dt_pthread_mutex_unlock(&dc->toast_mutex);
dt_pthread_mutex_unlock(&dc->log_mutex);
dt_control_toast_redraw();
return FALSE;
}
Expand Down Expand Up @@ -612,7 +609,7 @@ void dt_control_button_pressed(double x,
dt_pthread_mutex_unlock(&dc->log_mutex);

// ack toast message:
dt_pthread_mutex_lock(&dc->toast_mutex);
dt_pthread_mutex_lock(&dc->log_mutex);
if(dc->toast_ack != dc->toast_pos)
{
if(which == 1 && y > yc - 10.0 && y < yc + 10.0)
Expand All @@ -623,11 +620,11 @@ void dt_control_button_pressed(double x,
dc->toast_message_timeout_id = 0;
}
dc->toast_ack = dc->toast_pos;
dt_pthread_mutex_unlock(&dc->toast_mutex);
dt_pthread_mutex_unlock(&dc->log_mutex);
return;
}
}
dt_pthread_mutex_unlock(&dc->toast_mutex);
dt_pthread_mutex_unlock(&dc->log_mutex);

if(!dt_view_manager_button_pressed(darktable.view_manager, x, y,
pressure, which, type, state))
Expand Down Expand Up @@ -676,7 +673,7 @@ void dt_control_log(const char *msg, ...)
static void _toast_log(const gboolean markup, const char *msg, va_list ap)
{
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->toast_mutex);
dt_pthread_mutex_lock(&dc->log_mutex);

// if we don't want markup, we escape <>&... so they are not interpreted later
if(markup)
Expand All @@ -694,7 +691,7 @@ static void _toast_log(const gboolean markup, const char *msg, va_list ap)

dc->toast_message_timeout_id
= g_timeout_add(DT_CTL_TOAST_TIMEOUT, _dt_ctl_toast_message_timeout_callback, NULL);
dt_pthread_mutex_unlock(&dc->toast_mutex);
dt_pthread_mutex_unlock(&dc->log_mutex);
// redraw center later in gui thread:
g_idle_add(_redraw_center, 0);
}
Expand Down Expand Up @@ -726,46 +723,26 @@ static void _control_log_ack_all()
dt_control_queue_redraw_center();
}

void dt_control_log_busy_enter()
void dt_control_busy_enter()
{
if(!dt_control_running()) return;
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->log_mutex);
dc->log_busy++;
dc->busy++;
dt_pthread_mutex_unlock(&dc->log_mutex);
}

void dt_control_toast_busy_enter()
{
if(!dt_control_running()) return;
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->toast_mutex);
dc->toast_busy++;
dt_pthread_mutex_unlock(&dc->toast_mutex);
}

void dt_control_log_busy_leave()
void dt_control_busy_leave()
{
if(!dt_control_running()) return;
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->log_mutex);
dc->log_busy--;
dc->busy--;
dt_pthread_mutex_unlock(&dc->log_mutex);
/* lets redraw */
dt_control_queue_redraw_center();
}

void dt_control_toast_busy_leave()
{
if(!dt_control_running()) return;
dt_control_t *dc = darktable.control;
dt_pthread_mutex_lock(&dc->toast_mutex);
dc->toast_busy--;
dt_pthread_mutex_unlock(&dc->toast_mutex);
/* lets redraw */
dt_control_queue_redraw_center();
}

void dt_control_queue_redraw()
{
DT_CONTROL_SIGNAL_RAISE(DT_SIGNAL_CONTROL_REDRAW_ALL);
Expand Down
13 changes: 5 additions & 8 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ gboolean dt_control_configure(GtkWidget *da, GdkEventConfigure *event, gpointer
void dt_control_log(const char *msg, ...) __attribute__((format(printf, 1, 2)));
void dt_toast_log(const char *msg, ...) __attribute__((format(printf, 1, 2)));
void dt_toast_markup_log(const char *msg, ...) __attribute__((format(printf, 1, 2)));
void dt_control_log_busy_enter(void);
void dt_control_toast_busy_enter(void);
void dt_control_log_busy_leave(void);
void dt_control_toast_busy_leave(void);
void dt_control_busy_enter();
void dt_control_busy_leave();
void dt_control_draw_busy_msg(cairo_t *cr, int width, int height);
// disable the possibility to change the cursor shape with dt_control_change_cursor
void dt_control_forbid_change_cursor(void);
Expand Down Expand Up @@ -167,19 +165,18 @@ typedef struct dt_control_t
dt_imgid_t last_clicked_filmstrip_id;
gboolean lock_cursor_shape;

int busy;
dt_pthread_mutex_t log_mutex;

// message log
int32_t log_pos, log_ack;
char log_message[DT_CTL_LOG_SIZE][DT_CTL_LOG_MSG_SIZE];
guint log_message_timeout_id;
int log_busy;
dt_pthread_mutex_t log_mutex;

// toast log
int32_t toast_pos, toast_ack;
char toast_message[DT_CTL_TOAST_SIZE][DT_CTL_TOAST_MSG_SIZE];
guint toast_message_timeout_id;
int toast_busy;
dt_pthread_mutex_t toast_mutex;

// gui settings
dt_pthread_mutex_t global_mutex, image_mutex;
Expand Down
15 changes: 5 additions & 10 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ void dt_dev_process_image_job(dt_develop_t *dev,
return;
}

dt_control_log_busy_enter();
dt_control_toast_busy_enter();
dt_control_busy_enter();
pipe->input_timestamp = dev->timestamp;
// let gui know to draw preview instead of us, if it's there:
pipe->status = DT_DEV_PIXELPIPE_RUNNING;
Expand All @@ -327,8 +326,7 @@ void dt_dev_process_image_job(dt_develop_t *dev,
// failed to load raw?
if(!buf.buf)
{
dt_control_log_busy_leave();
dt_control_toast_busy_leave();
dt_control_busy_leave();
pipe->status = DT_DEV_PIXELPIPE_DIRTY;
dt_pthread_mutex_unlock(&pipe->mutex);
dev->image_invalid_cnt++;
Expand Down Expand Up @@ -384,8 +382,7 @@ void dt_dev_process_image_job(dt_develop_t *dev,
if(dev->gui_leaving)
{
dt_mipmap_cache_release(&buf);
dt_control_log_busy_leave();
dt_control_toast_busy_leave();
dt_control_busy_leave();
pipe->status = DT_DEV_PIXELPIPE_INVALID;
dt_pthread_mutex_unlock(&pipe->mutex);
return;
Expand Down Expand Up @@ -442,8 +439,7 @@ void dt_dev_process_image_job(dt_develop_t *dev,
if(dev->image_force_reload || pipe->loading || pipe->input_changed)
{
dt_mipmap_cache_release(&buf);
dt_control_log_busy_leave();
dt_control_toast_busy_leave();
dt_control_busy_leave();
pipe->status = DT_DEV_PIXELPIPE_INVALID;
dt_pthread_mutex_unlock(&pipe->mutex);
return;
Expand All @@ -468,8 +464,7 @@ void dt_dev_process_image_job(dt_develop_t *dev,
dev->image_invalid_cnt = 0;
dt_mipmap_cache_release(&buf);
// if a widget needs to be redraw there's the DT_SIGNAL_*_PIPE_FINISHED signals
dt_control_log_busy_leave();
dt_control_toast_busy_leave();
dt_control_busy_leave();
dt_pthread_mutex_unlock(&pipe->mutex);

if(dev->gui_attached && !dev->gui_leaving && signal != -1)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ static void _ui_toast_redraw_callback(gpointer instance,
{
dt_control_t *dc = darktable.control;
// draw toast message, if any
dt_pthread_mutex_lock(&darktable.control->toast_mutex);
dt_pthread_mutex_lock(&darktable.control->log_mutex);
if(dc->toast_ack != dc->toast_pos)
{
const int32_t first_message = MAX(dc->toast_ack, dc->toast_pos - (DT_CTL_TOAST_SIZE-1));
Expand Down Expand Up @@ -2875,7 +2875,7 @@ static void _ui_toast_redraw_callback(gpointer instance,
{
if(gtk_widget_get_visible(widget)) gtk_widget_hide(widget);
}
dt_pthread_mutex_unlock(&darktable.control->toast_mutex);
dt_pthread_mutex_unlock(&darktable.control->log_mutex);
}
#undef ALLMESSSIZE

Expand Down
4 changes: 2 additions & 2 deletions src/libs/print_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ void gui_post_expose(struct dt_lib_module_t *self,
{
// if the image is missing, we reload it again
g_timeout_add(250, _expose_again, ps);
if(!ps->busy) dt_control_log_busy_enter();
if(!ps->busy) dt_control_busy_enter();
ps->busy = TRUE;
}
else
Expand All @@ -2016,7 +2016,7 @@ void gui_post_expose(struct dt_lib_module_t *self,
cairo_paint_with_alpha(cr, alpha);
cairo_surface_destroy(surf);
cairo_restore(cr);
if(ps->busy) dt_control_log_busy_leave();
if(ps->busy) dt_control_busy_leave();
ps->busy = FALSE;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/tethering.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static void _expose_tethered_mode(dt_view_t *self,
{
// if the image is missing, we reload it again
g_timeout_add(250, _expose_again, NULL);
if(!lib->busy) dt_control_log_busy_enter();
if(!lib->busy) dt_control_busy_enter();
lib->busy = TRUE;
}
else
Expand All @@ -388,7 +388,7 @@ static void _expose_tethered_mode(dt_view_t *self,
cairo_set_source_surface(cr, surf, 0.0, 0.0);
cairo_paint(cr);
cairo_surface_destroy(surf);
if(lib->busy) dt_control_log_busy_leave();
if(lib->busy) dt_control_busy_leave();
lib->busy = FALSE;
}

Expand Down

0 comments on commit 5d1e0bb

Please sign in to comment.