list, flow box: Make unpaired releases opt-in

We don't want a pointer that is moved off a scrollbar
to trigger a row when it gets released. To avoid this,
require an explicit opt-in to handling unpaired-releases.
This commit is contained in:
Matthias Clasen 2017-12-30 23:23:16 -05:00
parent 1be0b6d2d5
commit 72c9853999
2 changed files with 60 additions and 3 deletions

View File

@ -112,6 +112,9 @@ static void gtk_flow_box_bound_model_changed (GListModel *list,
guint added,
gpointer user_data);
static void gtk_flow_box_set_accept_unpaired_release (GtkFlowBox *box,
gboolean accept);
static void gtk_flow_box_check_model_compat (GtkFlowBox *box);
static void
@ -616,6 +619,7 @@ enum {
PROP_MAX_CHILDREN_PER_LINE,
PROP_SELECTION_MODE,
PROP_ACTIVATE_ON_SINGLE_CLICK,
PROP_ACCEPT_UNPAIRED_RELEASE,
/* orientable */
PROP_ORIENTATION,
@ -642,6 +646,7 @@ struct _GtkFlowBoxPrivate {
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
gboolean activate_on_single_click;
gboolean accept_unpaired_release;
guint16 min_children_per_line;
guint16 max_children_per_line;
@ -2686,7 +2691,7 @@ gtk_flow_box_multipress_unpaired_release (GtkGestureMultiPress *gesture,
GtkFlowBoxPrivate *priv = BOX_PRIV (box);
GtkFlowBoxChild *child;
if (!priv->activate_on_single_click)
if (!priv->activate_on_single_click || !priv->accept_unpaired_release)
return;
child = gtk_flow_box_get_child_at_pos (box, x, y);
@ -3302,6 +3307,9 @@ gtk_flow_box_get_property (GObject *object,
case PROP_ACTIVATE_ON_SINGLE_CLICK:
g_value_set_boolean (value, priv->activate_on_single_click);
break;
case PROP_ACCEPT_UNPAIRED_RELEASE:
g_value_set_boolean (value, priv->accept_unpaired_release);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -3350,6 +3358,9 @@ gtk_flow_box_set_property (GObject *object,
case PROP_ACTIVATE_ON_SINGLE_CLICK:
gtk_flow_box_set_activate_on_single_click (box, g_value_get_boolean (value));
break;
case PROP_ACCEPT_UNPAIRED_RELEASE:
gtk_flow_box_set_accept_unpaired_release (box, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -3445,6 +3456,13 @@ gtk_flow_box_class_init (GtkFlowBoxClass *class)
TRUE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
props[PROP_ACCEPT_UNPAIRED_RELEASE] =
g_param_spec_boolean ("accept-unpaired-release",
P_("Accept unpaired release"),
P_("Accept an unpaired release event"),
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFlowBox:homogeneous:
*
@ -4387,7 +4405,18 @@ gtk_flow_box_get_activate_on_single_click (GtkFlowBox *box)
return BOX_PRIV (box)->activate_on_single_click;
}
static void
gtk_flow_box_set_accept_unpaired_release (GtkFlowBox *box,
gboolean accept)
{
if (BOX_PRIV (box)->accept_unpaired_release == accept)
return;
BOX_PRIV (box)->accept_unpaired_release = accept;
g_object_notify_by_pspec (G_OBJECT (box), props[PROP_ACCEPT_UNPAIRED_RELEASE]);
}
/* Selection handling {{{2 */
/**

View File

@ -104,6 +104,7 @@ typedef struct
GtkWidget *scrollable_parent;
GtkAdjustment *adjustment;
gboolean activate_single_click;
gboolean accept_unpaired_release;
GtkGesture *multipress_gesture;
@ -151,6 +152,7 @@ enum {
PROP_0,
PROP_SELECTION_MODE,
PROP_ACTIVATE_ON_SINGLE_CLICK,
PROP_ACCEPT_UNPAIRED_RELEASE,
LAST_PROPERTY
};
@ -232,6 +234,8 @@ static void gtk_list_box_select_all_between (GtkList
gboolean modify);
static gboolean gtk_list_box_unselect_all_internal (GtkListBox *box);
static void gtk_list_box_selected_rows_changed (GtkListBox *box);
static void gtk_list_box_set_accept_unpaired_release (GtkListBox *box,
gboolean accept);
static void gtk_list_box_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
guint n_press,
@ -310,6 +314,9 @@ gtk_list_box_get_property (GObject *obj,
case PROP_ACTIVATE_ON_SINGLE_CLICK:
g_value_set_boolean (value, priv->activate_single_click);
break;
case PROP_ACCEPT_UNPAIRED_RELEASE:
g_value_set_boolean (value, priv->accept_unpaired_release);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@ -332,6 +339,9 @@ gtk_list_box_set_property (GObject *obj,
case PROP_ACTIVATE_ON_SINGLE_CLICK:
gtk_list_box_set_activate_on_single_click (box, g_value_get_boolean (value));
break;
case PROP_ACCEPT_UNPAIRED_RELEASE:
gtk_list_box_set_accept_unpaired_release (box, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@ -415,6 +425,13 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
TRUE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_ACCEPT_UNPAIRED_RELEASE] =
g_param_spec_boolean ("accept-unpaired-release",
P_("Accept unpaired release"),
P_("Accept unpaired release"),
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, LAST_PROPERTY, properties);
/**
@ -1400,6 +1417,17 @@ gtk_list_box_get_activate_on_single_click (GtkListBox *box)
return BOX_PRIV (box)->activate_single_click;
}
void
gtk_list_box_set_accept_unpaired_release (GtkListBox *box,
gboolean accept)
{
if (BOX_PRIV (box)->accept_unpaired_release == accept)
return;
BOX_PRIV (box)->accept_unpaired_release = accept;
g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_ACCEPT_UNPAIRED_RELEASE]);
}
static void
gtk_list_box_add_move_binding (GtkBindingSet *binding_set,
@ -1791,7 +1819,7 @@ gtk_list_box_multipress_unpaired_release (GtkGestureMultiPress *gesture,
GtkListBoxPrivate *priv = BOX_PRIV (box);
GtkListBoxRow *row;
if (!priv->activate_single_click)
if (!priv->activate_single_click || !priv->accept_unpaired_release)
return;
row = gtk_list_box_get_row_at_y (box, y);