Skip to content

Commit

Permalink
Make toasts less offensive
Browse files Browse the repository at this point in the history
The number of lines shown for toast and log messages could be felt to be too offensive,
this PR makes the number of lines
a) 1 for toast
b) 7 for log messages so there is a still a good chance to see every log message

Fixes comments about index errors and UI in darktable-org#16967
  • Loading branch information
jenshannoschwalm committed Aug 6, 2024
1 parent 43b23b4 commit d6ee1d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void dt_control_button_pressed(double x,
const double /*xc = wd/4.0-20,*/ yc = ht * 0.85 + 10.0;
if(darktable.control->log_ack != darktable.control->log_pos)
{
if(which == 1 /*&& x > xc - 10 && x < xc + 10*/ && y > yc - 10.0 && y < yc + 10.0)
if(which == 1 && y > yc - 10.0 && y < yc + 10.0)
{
if(darktable.control->log_message_timeout_id)
{
Expand All @@ -606,7 +606,7 @@ void dt_control_button_pressed(double x,
dt_pthread_mutex_lock(&darktable.control->toast_mutex);
if(darktable.control->toast_ack != darktable.control->toast_pos)
{
if(which == 1 /*&& x > xc - 10 && x < xc + 10*/ && y > yc - 10.0 && y < yc + 10.0)
if(which == 1 && y > yc - 10.0 && y < yc + 10.0)
{
if(darktable.control->toast_message_timeout_id)
{
Expand Down Expand Up @@ -639,7 +639,7 @@ void dt_control_log(const char *msg, ...)
va_start(ap, msg);
char *escaped_msg = g_markup_vprintf_escaped(msg, ap);
const int msglen = strlen(escaped_msg);
g_strlcpy(darktable.control->log_message[darktable.control->log_pos % DT_CTL_LOG_SIZE],
g_strlcpy(darktable.control->log_message[darktable.control->log_pos & (DT_CTL_LOG_SIZE-1)],
escaped_msg, DT_CTL_LOG_MSG_SIZE);
g_free(escaped_msg);
va_end(ap);
Expand All @@ -663,12 +663,12 @@ static void _toast_log(const gboolean markup, const char *msg, va_list ap)

// if we don't want markup, we escape <>&... so they are not interpreted later
if(markup)
vsnprintf(darktable.control->toast_message[darktable.control->toast_pos % DT_CTL_TOAST_SIZE],
vsnprintf(darktable.control->toast_message[darktable.control->toast_pos & (DT_CTL_TOAST_SIZE-1)],
DT_CTL_TOAST_MSG_SIZE, msg, ap);
else
{
char *escaped_msg = g_markup_vprintf_escaped(msg, ap);
g_strlcpy(darktable.control->toast_message[darktable.control->toast_pos % DT_CTL_TOAST_SIZE],
g_strlcpy(darktable.control->toast_message[darktable.control->toast_pos & (DT_CTL_TOAST_SIZE-1)],
escaped_msg, DT_CTL_TOAST_MSG_SIZE);
g_free(escaped_msg);
}
Expand Down
9 changes: 5 additions & 4 deletions src/control/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ struct dt_control_t;
/** sets the hinter message */
void dt_control_hinter_message(const struct dt_control_t *s, const char *message);

#define DT_CTL_LOG_SIZE 10
#define DT_CTL_LOG_SIZE 8 // must be power-of-2
#define DT_CTL_TOAST_SIZE 2

#define DT_CTL_LOG_MSG_SIZE 1000
#define DT_CTL_LOG_TIMEOUT 5000
#define DT_CTL_TOAST_SIZE 10
#define DT_CTL_TOAST_MSG_SIZE 300
#define DT_CTL_TOAST_TIMEOUT 1500
/**
Expand Down Expand Up @@ -159,14 +160,14 @@ typedef struct dt_control_t
gboolean lock_cursor_shape;

// message log
uint32_t log_pos, log_ack;
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
uint32_t toast_pos, toast_ack;
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;
Expand Down
28 changes: 14 additions & 14 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2644,20 +2644,20 @@ static void _ui_widget_redraw_callback(gpointer instance,
static void _ui_log_redraw_callback(gpointer instance,
GtkWidget *widget)
{
dt_control_t *dc = darktable.control;
// draw log message, if any
dt_pthread_mutex_lock(&darktable.control->log_mutex);
if(darktable.control->log_ack != darktable.control->log_pos)
dt_pthread_mutex_lock(&dc->log_mutex);
if(dc->log_ack != dc->log_pos)
{
const uint32_t first_message = MAX(darktable.control->log_ack,
darktable.control->log_pos - DT_CTL_LOG_SIZE + 1);
const int32_t first_message = MAX(dc->log_ack, dc->log_pos - (DT_CTL_LOG_SIZE-1));
gchar *message = g_malloc(ALLMESSSIZE);
if(message)
{
message[0] = 0;
for(uint32_t idx = first_message; idx < darktable.control->log_pos; idx++)
for(int32_t idx = first_message; idx < dc->log_pos; idx++)
{
g_strlcat(message, darktable.control->log_message[idx % DT_CTL_LOG_SIZE], ALLMESSSIZE);
if(idx != darktable.control->log_pos -1)
g_strlcat(message, dc->log_message[idx & (DT_CTL_LOG_SIZE-1)], ALLMESSSIZE);
if(idx != dc->log_pos -1)
g_strlcat(message, "\n", ALLMESSSIZE);
}
gtk_label_set_markup(GTK_LABEL(widget), message);
Expand All @@ -2682,20 +2682,20 @@ static void _ui_log_redraw_callback(gpointer instance,
static void _ui_toast_redraw_callback(gpointer instance,
GtkWidget *widget)
{
dt_control_t *dc = darktable.control;
// draw toast message, if any
dt_pthread_mutex_lock(&darktable.control->toast_mutex);
if(darktable.control->toast_ack != darktable.control->toast_pos)
dt_pthread_mutex_lock(&dc->toast_mutex);
if(dc->toast_ack != dc->toast_pos)
{
const uint32_t first_message = MAX(darktable.control->toast_ack,
darktable.control->toast_pos - DT_CTL_TOAST_SIZE + 1);
const int32_t first_message = MAX(dc->toast_ack, dc->toast_pos - (DT_CTL_TOAST_SIZE-1));
gchar *message = g_malloc(ALLMESSSIZE);
if(message)
{
message[0] = 0;
for(uint32_t idx = first_message; idx < darktable.control->toast_pos; idx++)
for(int32_t idx = first_message; idx < dc->toast_pos; idx++)
{
g_strlcat(message, darktable.control->toast_message[idx % DT_CTL_TOAST_SIZE], ALLMESSSIZE);
if(idx != darktable.control->toast_pos -1)
g_strlcat(message, darktable.control->toast_message[idx & (DT_CTL_TOAST_SIZE-1)], ALLMESSSIZE);
if(idx != dc->toast_pos -1)
g_strlcat(message, "\n", ALLMESSSIZE);
}
gtk_label_set_markup(GTK_LABEL(widget), message);
Expand Down

0 comments on commit d6ee1d6

Please sign in to comment.