Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration of button-pressed and button-released to new GtkGesture API. #16919

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/dtgtk/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ void dtgtk_button_set_active(GtkDarktableButton *button, gboolean active)
button->icon_flags &= ~CPF_ACTIVE;
}

GtkGesture *dtgtk_button_default_handler_new(
GtkWidget *widget,
guint button,
GCallback func_press,
GCallback func_release,
gpointer data)
{
GtkGesture *gesture = gtk_gesture_multi_press_new(widget);
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), button);

if (func_press != NULL)
{
g_signal_connect(G_OBJECT(gesture), "pressed", func_press, data);
}

if (func_release != NULL)
{
g_signal_connect(G_OBJECT(gesture), "released", func_release, data);
}

return gesture;
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Expand Down
16 changes: 16 additions & 0 deletions src/dtgtk/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ void dtgtk_button_set_paint(GtkDarktableButton *button, DTGTKCairoPaintIconFunc
/** set the active state of the button icon */
void dtgtk_button_set_active(GtkDarktableButton *button, gboolean active);

/**
* Create default handler for primary button.
* @param widget widget to create the gesture object for
* @param button type of button
* @param func_press gets called when button will be pressed
* @param func_release gets called when button will be released
* @param data user data send to function
* @return new gesture object; receiver is responsible for deletion
*/
GtkGesture *dtgtk_button_default_handler_new(
GtkWidget *widget,
guint button,
GCallback func_press,
GCallback func_release,
gpointer data);

G_END_DECLS

// clang-format off
Expand Down
36 changes: 24 additions & 12 deletions src/dtgtk/culling.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,18 @@ static gboolean _event_enter_notify(GtkWidget *widget,
return TRUE;
}

static gboolean _event_button_press(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_button_press(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
GdkEventButton *event = (GdkEventButton *)gtk_gesture_get_last_event(GTK_GESTURE(gesture), NULL);

dt_culling_t *table = (dt_culling_t *)user_data;

if(event->button == 1 && event->type == GDK_BUTTON_PRESS)
if(event->button == 1)
{
// make sure any edition field loses the focus
gtk_widget_grab_focus(dt_ui_center(darktable.gui->ui));
Expand All @@ -642,7 +647,7 @@ static gboolean _event_button_press(GtkWidget *widget,

const dt_imgid_t id = dt_control_get_mouse_over_id();

if(dt_is_valid_imgid(id) && event->button == 1 && event->type == GDK_2BUTTON_PRESS)
if(dt_is_valid_imgid(id) && event->button == 1 && n_press == 2)
{
dt_view_manager_switch(darktable.view_manager, "darkroom");
return TRUE;
Expand Down Expand Up @@ -739,9 +744,12 @@ static gboolean _event_motion_notify(GtkWidget *widget,
return TRUE;
}

static gboolean _event_button_release(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_button_release(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
dt_culling_t *table = (dt_culling_t *)user_data;
table->panning = FALSE;
Expand Down Expand Up @@ -928,12 +936,16 @@ dt_culling_t *dt_culling_new(dt_culling_mode_t mode)
G_CALLBACK(_event_leave_notify), table);
g_signal_connect(G_OBJECT(table->widget), "enter-notify-event",
G_CALLBACK(_event_enter_notify), table);
g_signal_connect(G_OBJECT(table->widget), "button-press-event",
G_CALLBACK(_event_button_press), table);
g_signal_connect(G_OBJECT(table->widget), "motion-notify-event",
G_CALLBACK(_event_motion_notify), table);
g_signal_connect(G_OBJECT(table->widget), "button-release-event",
G_CALLBACK(_event_button_release), table);

// the button handler will react on all mouse buttons (0 as argument)
table->gesture_button_all = dtgtk_button_default_handler_new(
GTK_WIDGET(table->widget),
0,
G_CALLBACK(_event_button_press),
G_CALLBACK(_event_button_release),
table);

// we register globals signals
DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals,
Expand Down
4 changes: 4 additions & 0 deletions src/dtgtk/culling.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ typedef struct dt_culling_t
dt_thumbnail_overlay_t overlays; // overlays type
int overlays_block_timeout; // overlay block visibility duration
gboolean show_tooltips; // are tooltips visible ?

// different controller for event processing
GtkGesture *gesture_button_all;

} dt_culling_t;

dt_culling_t *dt_culling_new(dt_culling_mode_t mode);
Expand Down
22 changes: 19 additions & 3 deletions src/dtgtk/resetlabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,26 @@ static void dtgtk_reset_label_init(GtkDarktableResetLabel *label)
{
}

static gboolean _reset_label_callback(GtkDarktableResetLabel *label, GdkEventButton *event, gpointer user_data)
static gboolean _reset_label_callback(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
if(event->type == GDK_2BUTTON_PRESS)
if(n_press == 2)
{
// on double click, reset all settings
GtkDarktableResetLabel *label = (GtkDarktableResetLabel *)user_data;

memcpy(((char *)label->module->params) + label->offset,
((char *)label->module->default_params) + label->offset, label->size);
if(label->module->gui_update) label->module->gui_update(label->module);
dt_dev_add_history_item(darktable.develop, label->module, FALSE);

return TRUE;
}

return FALSE;
}

Expand All @@ -57,7 +67,13 @@ GtkWidget *dtgtk_reset_label_new(const gchar *text, dt_iop_module_t *module, voi
gtk_widget_set_tooltip_text(GTK_WIDGET(label), _("double-click to reset"));
gtk_container_add(GTK_CONTAINER(label), GTK_WIDGET(label->lb));
gtk_widget_add_events(GTK_WIDGET(label), GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(label), "button-press-event", G_CALLBACK(_reset_label_callback), (gpointer)NULL);

label->gesture_button_primary = dtgtk_button_default_handler_new(
GTK_WIDGET(label),
GDK_BUTTON_PRIMARY,
G_CALLBACK(_reset_label_callback),
NULL,
label);

return (GtkWidget *)label;
}
Expand Down
5 changes: 5 additions & 0 deletions src/dtgtk/resetlabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#pragma once

#include "develop/imageop.h"
#include "dtgtk/button.h"

#include <gtk/gtk.h>

G_BEGIN_DECLS
Expand All @@ -33,6 +35,9 @@ struct _GtkDarktableResetLabel
dt_iop_module_t *module;
int offset; // offset in params to reset
int size; // size of param to reset

// different controller for event processing
GtkGesture *gesture_button_primary;
};

/** instantiate a new darktable reset label for the given module and param. */
Expand Down
81 changes: 54 additions & 27 deletions src/dtgtk/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,25 +940,34 @@ static gboolean _event_main_motion(GtkWidget *widget,
return FALSE;
}

static gboolean _event_main_press(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_main_press(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
GdkEventButton *event = (GdkEventButton *)gtk_gesture_get_last_event(GTK_GESTURE(gesture), NULL);

dt_thumbnail_t *thumb = (dt_thumbnail_t *)user_data;
if(event->button == 1
&& ((event->type == GDK_2BUTTON_PRESS && !thumb->single_click)
|| (event->type == GDK_BUTTON_PRESS
&& ((n_press == 2 && !thumb->single_click)
|| (n_press == 1
&& dt_modifier_is(event->state, 0) && thumb->single_click)))
{
dt_control_set_mouse_over_id(thumb->imgid);
// to ensure we haven't lost imgid during double-click
}
return FALSE;
}
static gboolean _event_main_release(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_main_release(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
GdkEventButton *event = (GdkEventButton *)gtk_gesture_get_last_event(GTK_GESTURE(gesture), NULL);
dt_thumbnail_t *thumb = (dt_thumbnail_t *)user_data;

if(event->button == 1
Expand All @@ -979,17 +988,26 @@ static gboolean _event_main_release(GtkWidget *widget,
return FALSE;
}

static gboolean _event_rating_press(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_rating_press(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
return TRUE;
}
static gboolean _event_rating_release(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
static gboolean _event_rating_release(
GtkGestureMultiPress *gesture,
int n_press,
double x,
double y,
gpointer user_data)
{
GdkEventButton *event = (GdkEventButton *)gtk_gesture_get_last_event(GTK_GESTURE(gesture), NULL);
dt_thumbnail_t *thumb = (dt_thumbnail_t *)user_data;
GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));

if(thumb->disable_actions)
return FALSE;
if(dtgtk_thumbnail_btn_is_hidden(widget))
Expand Down Expand Up @@ -1401,10 +1419,12 @@ GtkWidget *dt_thumbnail_create_widget(dt_thumbnail_t *thumb,
g_signal_connect(G_OBJECT(thumb->w_main), "drag-motion",
G_CALLBACK(_event_main_drag_motion), thumb);

g_signal_connect(G_OBJECT(thumb->w_main), "button-press-event",
G_CALLBACK(_event_main_press), thumb);
g_signal_connect(G_OBJECT(thumb->w_main), "button-release-event",
G_CALLBACK(_event_main_release), thumb);
thumb->gesture_button_all_main = dtgtk_button_default_handler_new(
GTK_WIDGET(thumb->w_main),
0,
G_CALLBACK(_event_main_press),
G_CALLBACK(_event_main_release),
thumb);

g_object_set_data(G_OBJECT(thumb->w_main), "thumb", thumb);
DT_DEBUG_CONTROL_SIGNAL_CONNECT(darktable.signals, DT_SIGNAL_ACTIVE_IMAGES_CHANGE,
Expand Down Expand Up @@ -1549,10 +1569,14 @@ GtkWidget *dt_thumbnail_create_widget(dt_thumbnail_t *thumb,
gtk_widget_set_valign(thumb->w_reject, GTK_ALIGN_END);
gtk_widget_set_halign(thumb->w_reject, GTK_ALIGN_START);
gtk_widget_show(thumb->w_reject);
g_signal_connect(G_OBJECT(thumb->w_reject), "button-press-event",
G_CALLBACK(_event_rating_press), thumb);
g_signal_connect(G_OBJECT(thumb->w_reject), "button-release-event",
G_CALLBACK(_event_rating_release), thumb);

thumb->gesture_button_all_reject = dtgtk_button_default_handler_new(
GTK_WIDGET(thumb->w_reject),
0,
G_CALLBACK(_event_rating_press),
G_CALLBACK(_event_rating_release),
thumb);

g_signal_connect(G_OBJECT(thumb->w_reject), "enter-notify-event",
G_CALLBACK(_event_btn_enter_leave), thumb);
g_signal_connect(G_OBJECT(thumb->w_reject), "leave-notify-event",
Expand All @@ -1567,11 +1591,14 @@ GtkWidget *dt_thumbnail_create_widget(dt_thumbnail_t *thumb,
G_CALLBACK(_event_star_enter), thumb);
g_signal_connect(G_OBJECT(thumb->w_stars[i]), "leave-notify-event",
G_CALLBACK(_event_star_leave), thumb);
g_signal_connect(G_OBJECT(thumb->w_stars[i]), "button-press-event",
G_CALLBACK(_event_rating_press), thumb);
g_signal_connect(G_OBJECT(thumb->w_stars[i]), "button-release-event",
G_CALLBACK(_event_rating_release),
thumb);

thumb->gesture_button_all_stars[i] = dtgtk_button_default_handler_new(
GTK_WIDGET(thumb->w_stars[i]),
0,
G_CALLBACK(_event_rating_press),
G_CALLBACK(_event_rating_release),
thumb);

gtk_widget_set_name(thumb->w_stars[i], "thumb-star");
dt_action_define(&darktable.control->actions_thumb, NULL, "rating",
thumb->w_stars[i], &dt_action_def_rating);
Expand Down
6 changes: 6 additions & 0 deletions src/dtgtk/thumbnail.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ typedef struct
gboolean display_focus; // do we display rectangles to show focused part of the image

gboolean busy; // should we show the busy message ?

// different controller for event processing
GtkGesture *gesture_button_all_main;
GtkGesture *gesture_button_all_reject;
GtkGesture *gesture_button_all_stars[MAX_STARS];

} dt_thumbnail_t;

dt_thumbnail_t *dt_thumbnail_new(const int width,
Expand Down
Loading