Rename things

Rename the can-pick property to can-target,
and redo the pick flags with more descriptive names.
This commit is contained in:
Matthias Clasen 2019-04-07 21:36:40 +00:00
parent 1b362d1f01
commit ef982b7d46
18 changed files with 56 additions and 52 deletions

View File

@ -243,7 +243,7 @@ pressed_cb (GtkGesture *gesture,
GtkWidget *child; GtkWidget *child;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)); widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
child = gtk_widget_pick (widget, x, y, 0); child = gtk_widget_pick (widget, x, y, GTK_PICK_DEFAULT);
if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_SECONDARY) if (gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)) == GDK_BUTTON_SECONDARY)
{ {

View File

@ -57,7 +57,7 @@ do_overlay (GtkWidget *do_widget)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox);
gtk_widget_set_can_pick (vbox, FALSE); gtk_widget_set_can_target (vbox, FALSE);
gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER); gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER); gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);

View File

@ -66,13 +66,13 @@ do_overlay2 (GtkWidget *do_widget)
image = gtk_picture_new_for_resource ("/overlay2/decor1.png"); image = gtk_picture_new_for_resource ("/overlay2/decor1.png");
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image);
gtk_widget_set_can_pick (image, FALSE); gtk_widget_set_can_target (image, FALSE);
gtk_widget_set_halign (image, GTK_ALIGN_START); gtk_widget_set_halign (image, GTK_ALIGN_START);
gtk_widget_set_valign (image, GTK_ALIGN_START); gtk_widget_set_valign (image, GTK_ALIGN_START);
image = gtk_picture_new_for_resource ("/overlay2/decor2.png"); image = gtk_picture_new_for_resource ("/overlay2/decor2.png");
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image);
gtk_widget_set_can_pick (image, FALSE); gtk_widget_set_can_target (image, FALSE);
gtk_widget_set_halign (image, GTK_ALIGN_END); gtk_widget_set_halign (image, GTK_ALIGN_END);
gtk_widget_set_valign (image, GTK_ALIGN_END); gtk_widget_set_valign (image, GTK_ALIGN_END);

View File

@ -228,7 +228,7 @@ puzzle_button_pressed (GtkGestureMultiPress *gesture,
int l, t, i; int l, t, i;
int pos; int pos;
child = gtk_widget_pick (grid, x, y, 0); child = gtk_widget_pick (grid, x, y, GTK_PICK_DEFAULT);
if (!child) if (!child)
{ {

View File

@ -4516,8 +4516,8 @@ gtk_widget_set_can_focus
gtk_widget_get_focus_on_click gtk_widget_get_focus_on_click
gtk_widget_set_focus_on_click gtk_widget_set_focus_on_click
gtk_widget_set_focus_child gtk_widget_set_focus_child
gtk_widget_get_can_pick gtk_widget_get_can_target
gtk_widget_set_can_pick gtk_widget_set_can_target
gtk_widget_get_has_surface gtk_widget_get_has_surface
gtk_widget_set_has_surface gtk_widget_set_has_surface
gtk_widget_get_sensitive gtk_widget_get_sensitive

View File

@ -3117,7 +3117,7 @@ gtk_entry_ensure_progress_widget (GtkEntry *entry)
priv->progress_widget = g_object_new (GTK_TYPE_PROGRESS_BAR, priv->progress_widget = g_object_new (GTK_TYPE_PROGRESS_BAR,
"css-name", "progress", "css-name", "progress",
NULL); NULL);
gtk_widget_set_can_pick (priv->progress_widget, FALSE); gtk_widget_set_can_target (priv->progress_widget, FALSE);
gtk_widget_set_parent (priv->progress_widget, GTK_WIDGET (entry)); gtk_widget_set_parent (priv->progress_widget, GTK_WIDGET (entry));

View File

@ -1042,12 +1042,16 @@ typedef enum {
/** /**
* GtkPickFlags: * GtkPickFlags:
* @GTK_PICK_ALL: Include insensitive widgets and widgets marked as "can't pick" * @GTK_PICK_DEFAULT: The default behavior, include widgets that are receiving events
* @GTK_PICK_INSENSITIVE: Include widgets that are insensitive
* @GTK_PICK_NON_TARGETABLE: Include widgets that are marked as non-targetable. See #GtkWidget::can-target
* *
* Flags that influence the behavior of gtk_widget_pick() * Flags that influence the behavior of gtk_widget_pick()
*/ */
typedef enum { typedef enum {
GTK_PICK_ALL = 1 << 0 GTK_PICK_DEFAULT = 0,
GTK_PICK_INSENSITIVE = 1 << 0,
GTK_PICK_NON_TARGETABLE = 1 << 1
} GtkPickFlags; } GtkPickFlags;
#endif /* __GTK_ENUMS_H__ */ #endif /* __GTK_ENUMS_H__ */

View File

@ -3928,7 +3928,7 @@ gtk_flow_box_get_child_at_pos (GtkFlowBox *box,
gint x, gint x,
gint y) gint y)
{ {
GtkWidget *child = gtk_widget_pick (GTK_WIDGET (box), x, y, 0); GtkWidget *child = gtk_widget_pick (GTK_WIDGET (box), x, y, GTK_PICK_DEFAULT);
if (!child) if (!child)
return NULL; return NULL;

View File

@ -1703,7 +1703,7 @@ handle_pointing_event (GdkEvent *event)
target = gtk_window_lookup_pointer_focus_implicit_grab (toplevel, device, sequence); target = gtk_window_lookup_pointer_focus_implicit_grab (toplevel, device, sequence);
if (!target) if (!target)
target = gtk_widget_pick (toplevel_widget, x, y, 0); target = gtk_widget_pick (toplevel_widget, x, y, GTK_PICK_DEFAULT);
if (!target) if (!target)
target = toplevel_widget; target = toplevel_widget;
@ -1742,7 +1742,7 @@ handle_pointing_event (GdkEvent *event)
if (event->any.type == GDK_BUTTON_RELEASE) if (event->any.type == GDK_BUTTON_RELEASE)
{ {
GtkWidget *new_target; GtkWidget *new_target;
new_target = gtk_widget_pick (GTK_WIDGET (toplevel), x, y, 0); new_target = gtk_widget_pick (GTK_WIDGET (toplevel), x, y, GTK_PICK_DEFAULT);
if (new_target == NULL) if (new_target == NULL)
new_target = GTK_WIDGET (toplevel); new_target = GTK_WIDGET (toplevel);
gtk_synthesize_crossing_events (GTK_ROOT (toplevel), target, new_target, event, gtk_synthesize_crossing_events (GTK_ROOT (toplevel), target, new_target, event,

View File

@ -135,7 +135,7 @@ gtk_pointer_focus_repick_target (GtkPointerFocus *focus)
{ {
GtkWidget *target; GtkWidget *target;
target = gtk_widget_pick (GTK_WIDGET (focus->toplevel), focus->x, focus->y, 0); target = gtk_widget_pick (GTK_WIDGET (focus->toplevel), focus->x, focus->y, GTK_PICK_DEFAULT);
if (target == NULL) if (target == NULL)
target = GTK_WIDGET (focus->toplevel); target = GTK_WIDGET (focus->toplevel);
gtk_pointer_focus_set_target (focus, target); gtk_pointer_focus_set_target (focus, target);

View File

@ -1865,7 +1865,7 @@ gtk_range_long_press_gesture_pressed (GtkGestureLongPress *gesture,
GtkRangePrivate *priv = gtk_range_get_instance_private (range); GtkRangePrivate *priv = gtk_range_get_instance_private (range);
GtkWidget *mouse_location; GtkWidget *mouse_location;
mouse_location = gtk_widget_pick (GTK_WIDGET (range), x, y, 0); mouse_location = gtk_widget_pick (GTK_WIDGET (range), x, y, GTK_PICK_DEFAULT);
if (mouse_location == priv->slider_widget && !priv->zoom) if (mouse_location == priv->slider_widget && !priv->zoom)
{ {

View File

@ -434,7 +434,7 @@ _gtk_widget_find_at_coords (GdkSurface *surface,
if (!event_widget) if (!event_widget)
return NULL; return NULL;
picked_widget = gtk_widget_pick (event_widget, surface_x, surface_y, GTK_PICK_ALL); picked_widget = gtk_widget_pick (event_widget, surface_x, surface_y, GTK_PICK_INSENSITIVE);
if (picked_widget != NULL) if (picked_widget != NULL)
gtk_widget_translate_coordinates (event_widget, picked_widget, surface_x, surface_y, widget_x, widget_y); gtk_widget_translate_coordinates (event_widget, picked_widget, surface_x, surface_y, widget_x, widget_y);

View File

@ -546,7 +546,7 @@ enum {
PROP_CAN_FOCUS, PROP_CAN_FOCUS,
PROP_HAS_FOCUS, PROP_HAS_FOCUS,
PROP_IS_FOCUS, PROP_IS_FOCUS,
PROP_CAN_PICK, PROP_CAN_TARGET,
PROP_FOCUS_ON_CLICK, PROP_FOCUS_ON_CLICK,
PROP_CAN_DEFAULT, PROP_CAN_DEFAULT,
PROP_HAS_DEFAULT, PROP_HAS_DEFAULT,
@ -1012,9 +1012,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
FALSE, FALSE,
GTK_PARAM_READWRITE); GTK_PARAM_READWRITE);
widget_props[PROP_CAN_PICK] = widget_props[PROP_CAN_TARGET] =
g_param_spec_boolean ("can-pick", g_param_spec_boolean ("can-target",
P_("Can pick"), P_("Can target"),
P_("Whether the widget can receive pointer events"), P_("Whether the widget can receive pointer events"),
FALSE, FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
@ -2187,8 +2187,8 @@ gtk_widget_set_property (GObject *object,
if (g_value_get_boolean (value)) if (g_value_get_boolean (value))
gtk_widget_grab_focus (widget); gtk_widget_grab_focus (widget);
break; break;
case PROP_CAN_PICK: case PROP_CAN_TARGET:
gtk_widget_set_can_pick (widget, g_value_get_boolean (value)); gtk_widget_set_can_target (widget, g_value_get_boolean (value));
break; break;
case PROP_FOCUS_ON_CLICK: case PROP_FOCUS_ON_CLICK:
gtk_widget_set_focus_on_click (widget, g_value_get_boolean (value)); gtk_widget_set_focus_on_click (widget, g_value_get_boolean (value));
@ -2368,8 +2368,8 @@ gtk_widget_get_property (GObject *object,
case PROP_IS_FOCUS: case PROP_IS_FOCUS:
g_value_set_boolean (value, gtk_widget_is_focus (widget)); g_value_set_boolean (value, gtk_widget_is_focus (widget));
break; break;
case PROP_CAN_PICK: case PROP_CAN_TARGET:
g_value_set_boolean (value, gtk_widget_get_can_pick (widget)); g_value_set_boolean (value, gtk_widget_get_can_target (widget));
break; break;
case PROP_FOCUS_ON_CLICK: case PROP_FOCUS_ON_CLICK:
g_value_set_boolean (value, gtk_widget_get_focus_on_click (widget)); g_value_set_boolean (value, gtk_widget_get_focus_on_click (widget));
@ -2808,7 +2808,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
#ifdef G_ENABLE_DEBUG #ifdef G_ENABLE_DEBUG
priv->highlight_resize = FALSE; priv->highlight_resize = FALSE;
#endif #endif
priv->can_pick = TRUE; priv->can_target = TRUE;
switch (_gtk_widget_get_direction (widget)) switch (_gtk_widget_get_direction (widget))
{ {
@ -11041,12 +11041,13 @@ gtk_widget_pick (GtkWidget *widget,
if (!_gtk_widget_is_drawable (widget)) if (!_gtk_widget_is_drawable (widget))
return NULL; return NULL;
if ((flags & GTK_PICK_ALL) == 0) if (!(flags & GTK_PICK_NON_TARGETABLE) &&
{ !gtk_widget_get_can_target (widget))
if (!gtk_widget_get_can_pick (widget) || return NULL;
!_gtk_widget_is_sensitive (widget))
return NULL; if (!(flags & GTK_PICK_INSENSITIVE) &&
} !_gtk_widget_is_sensitive (widget))
return NULL;
switch (priv->overflow) switch (priv->overflow)
{ {
@ -13462,31 +13463,30 @@ gtk_widget_get_cursor (GtkWidget *widget)
} }
/** /**
* gtk_widget_set_can_pick: * gtk_widget_set_can_target:
* @widget: a #GtkWidget * @widget: a #GtkWidget
* @can_pick: whether this widget should be able to receive pointer events * @can_target: whether this widget should be able to receive pointer events
* *
* Sets whether @widget can be the target of pointer events and * Sets whether @widget can be the target of pointer events.
* can be returned by gtk_widget_pick().
*/ */
void void
gtk_widget_set_can_pick (GtkWidget *widget, gtk_widget_set_can_target (GtkWidget *widget,
gboolean can_pick) gboolean can_target)
{ {
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
can_pick = !!can_pick; can_target = !!can_target;
if (priv->can_pick == can_pick) if (priv->can_target == can_target)
return; return;
priv->can_pick = can_pick; priv->can_target = can_target;
g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CAN_PICK]); g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CAN_TARGET]);
} }
/** /**
* gtk_widget_get_can_pick: * gtk_widget_get_can_target:
* @widget: a #GtkWidget * @widget: a #GtkWidget
* *
* Queries whether @widget can be the target of pointer events. * Queries whether @widget can be the target of pointer events.
@ -13494,11 +13494,11 @@ gtk_widget_set_can_pick (GtkWidget *widget,
* Returns: %TRUE if @widget can receive pointer events * Returns: %TRUE if @widget can receive pointer events
*/ */
gboolean gboolean
gtk_widget_get_can_pick (GtkWidget *widget) gtk_widget_get_can_target (GtkWidget *widget)
{ {
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
return priv->can_pick; return priv->can_target;
} }
/** /**

View File

@ -469,10 +469,10 @@ GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_get_focus_on_click (GtkWidget *widget); gboolean gtk_widget_get_focus_on_click (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_widget_set_can_pick (GtkWidget *widget, void gtk_widget_set_can_target (GtkWidget *widget,
gboolean can_pick); gboolean can_target);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_get_can_pick (GtkWidget *widget); gboolean gtk_widget_get_can_target (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@ -73,7 +73,7 @@ struct _GtkWidgetPrivate
guint shadowed : 1; guint shadowed : 1;
guint child_visible : 1; guint child_visible : 1;
guint multidevice : 1; guint multidevice : 1;
guint can_pick : 1; guint can_target : 1;
/* Queue-resize related flags */ /* Queue-resize related flags */
guint resize_needed : 1; /* queue_resize() has been called but no get_preferred_size() yet */ guint resize_needed : 1; /* queue_resize() has been called but no get_preferred_size() yet */

View File

@ -55,7 +55,7 @@ find_widget_at_pointer (GdkDevice *device)
gdk_surface_get_device_position (gtk_widget_get_surface (widget), gdk_surface_get_device_position (gtk_widget_get_surface (widget),
device, &x, &y, NULL); device, &x, &y, NULL);
widget = gtk_widget_pick (widget, x, y, GTK_PICK_ALL); widget = gtk_widget_pick (widget, x, y, GTK_PICK_INSENSITIVE|GTK_PICK_NON_TARGETABLE);
} }
return widget; return widget;

View File

@ -459,7 +459,7 @@ test_input_stacking (void)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox); gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox);
gtk_widget_set_can_pick (vbox, FALSE); gtk_widget_set_can_target (vbox, FALSE);
gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER); gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER); gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);

View File

@ -187,12 +187,12 @@ gtk_transform_tester_snapshot (GtkWidget *widget,
const float py = y; const float py = y;
GtkWidget *picked; GtkWidget *picked;
#if 1 #if 1
picked = gtk_widget_pick (widget, px, py, 0); picked = gtk_widget_pick (widget, px, py, GTK_PICK_DEFAULT);
#else #else
{ {
int dx, dy; int dx, dy;
gtk_widget_translate_coordinates (widget, self->test_widget, px, py, &dx, &dy); gtk_widget_translate_coordinates (widget, self->test_widget, px, py, &dx, &dy);
picked = gtk_widget_pick (self->test_widget, dx, dy); picked = gtk_widget_pick (self->test_widget, dx, dy, GTK_PICK_DEFAULT);
} }
#endif #endif