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

finetune presets selection for long lists #18103

Merged
merged 2 commits into from
Dec 29, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4367,12 +4367,12 @@ void dt_gui_collapsible_section_set_label(dt_gui_collapsible_section_t *cs,
dt_control_queue_redraw_widget(cs->label);
}

gboolean dt_gui_long_click(const int second,
const int first)
gboolean dt_gui_long_click(const guint second,
const guint first)
{
int delay = 0;
g_object_get(gtk_settings_get_default(), "gtk-double-click-time", &delay, NULL);
return second - first > delay;
return second - delay > first;
}

static int busy_nest_count = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ void dt_gui_update_collapsible_section(dt_gui_collapsible_section_t *cs);
void dt_gui_hide_collapsible_section(dt_gui_collapsible_section_t *cs);

// is delay between first and second click/press longer than double-click time?
gboolean dt_gui_long_click(const int second,
const int first);
gboolean dt_gui_long_click(const guint second,
const guint first);

// control whether the mouse pointer displays as a "busy" cursor, e.g. watch or timer
// the calls may be nested, but must be matched
Expand Down
28 changes: 21 additions & 7 deletions src/gui/presets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,18 +1253,28 @@ gboolean dt_gui_presets_autoapply_for_module(dt_iop_module_t *module, GtkWidget
return applied;
}

static guint _click_time = G_MAXUINT;

static gboolean _menuitem_motion_preset(GtkMenuItem *menuitem,
GdkEventMotion *event,
dt_iop_module_t *module)
{
if(!_click_time) _click_time = G_MAXUINT;

return FALSE;
}

static gboolean _menuitem_button_preset(GtkMenuItem *menuitem,
GdkEventButton *event,
dt_iop_module_t *module)
{
static guint click_time = G_MAXINT;
gboolean long_click = dt_gui_long_click(event->time, click_time);
gboolean long_click = dt_gui_long_click(event->time, _click_time);

gchar *name = g_object_get_data(G_OBJECT(menuitem), "dt-preset-name");

if(event->button == 1 || (module->flags() & IOP_FLAGS_ONE_INSTANCE))
if(event->button == 1)
{
if(click_time > event->time)
if(_click_time > event->time)
{
GtkContainer *menu = GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(menuitem)));
for(GList *c = gtk_container_get_children(menu); c; c = g_list_delete_link(c, c))
Expand All @@ -1274,9 +1284,9 @@ static gboolean _menuitem_button_preset(GtkMenuItem *menuitem,
dt_gui_presets_apply_preset(name, module);
}
}
else if(event->button == 3 && event->type == GDK_BUTTON_RELEASE)
else if(event->button == 3 && event->type == GDK_BUTTON_RELEASE && _click_time)
{
if(long_click)
if(long_click || (module->flags() & IOP_FLAGS_ONE_INSTANCE))
dt_shortcut_copy_lua((dt_action_t*)module, name);
else
{
Expand All @@ -1294,7 +1304,7 @@ static gboolean _menuitem_button_preset(GtkMenuItem *menuitem,
dt_iop_connect_accels_multi(module->so);
}

click_time = event->type == GDK_BUTTON_PRESS ? event->time : G_MAXINT;
_click_time = event->type == GDK_BUTTON_PRESS ? event->time : G_MAXUINT;
return long_click; // keep menu open on long click
}

Expand All @@ -1321,6 +1331,8 @@ static void _menuitem_connect_preset(GtkWidget *mi,
G_CALLBACK(_menuitem_button_preset), iop);
g_signal_connect(G_OBJECT(mi), "button-release-event",
G_CALLBACK(_menuitem_button_preset), iop);
g_signal_connect(G_OBJECT(mi), "motion-notify-event",
G_CALLBACK(_menuitem_motion_preset), iop);
gtk_widget_set_has_tooltip(mi, TRUE);
}

Expand Down Expand Up @@ -1819,6 +1831,8 @@ GtkMenu *dt_gui_presets_popup_menu_show_for_module(dt_iop_module_t *module)
if(module->set_preferences) module->set_preferences(GTK_MENU_SHELL(menu), module);
}

_click_time = 0;

return menu;
}

Expand Down
Loading