Compare commits

...

4 Commits

Author SHA1 Message Date
Matthias Clasen
9003609fc5 inspector: Allow picking insensitive widgets again
Use the new argument to gtk_widget_pick to allow picking
insensitive widgets.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/51
2019-04-07 13:02:54 +00:00
Matthias Clasen
f8a3d05ce1 tooltip: Allow tooltips on insensitive widgets again
Use the new argument to gtk_widget_pick to allow picking
insensitive widgets.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1816
2019-04-07 13:01:46 +00:00
Matthias Clasen
2f30bbbbf2 widget: Allow picking insensitive widgets
Add a reactive argument to gtk_widget_pick, and return
insensitive widgets when it is FALSE. Update all callers
and the implementations of the pick vfunc.
2019-04-07 12:58:19 +00:00
Matthias Clasen
ca07a41f1c widget: Change definition of gtk_widget_contains
Make this function just about location, leave out
reactiveness.

Drop the vfunc. We can decide this purely with the
information we have, no need to call out to application code.

Take the rounded rectangle into account for determining
the answer.
2019-04-07 12:35:15 +00:00
14 changed files with 44 additions and 57 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -292,7 +292,8 @@ get_handle_area (GtkPaned *paned,
static GtkWidget *
gtk_paned_pick (GtkWidget *widget,
double x,
double y)
double y,
gboolean reactive)
{
GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = gtk_paned_get_instance_private (paned);
@@ -303,7 +304,7 @@ gtk_paned_pick (GtkWidget *widget,
if (graphene_rect_contains_point (&handle_area, &(graphene_point_t){x, y}))
return priv->handle_widget;
return GTK_WIDGET_CLASS (gtk_paned_parent_class)->pick (widget, x, y);
return GTK_WIDGET_CLASS (gtk_paned_parent_class)->pick (widget, x, y, reactive);
}
static void

View File

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

View File

@@ -1864,7 +1864,7 @@ gtk_range_long_press_gesture_pressed (GtkGestureLongPress *gesture,
GtkRangePrivate *priv = gtk_range_get_instance_private (range);
GtkWidget *mouse_location;
mouse_location = gtk_widget_pick (GTK_WIDGET (range), x, y);
mouse_location = gtk_widget_pick (GTK_WIDGET (range), x, y, TRUE);
if (mouse_location == priv->slider_widget && !priv->zoom)
{
@@ -1908,7 +1908,7 @@ gtk_range_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
"gtk-primary-button-warps-slider", &primary_warps,
NULL);
mouse_location = gtk_widget_pick (widget, x, y);
mouse_location = gtk_widget_pick (widget, x, y, TRUE);
/* For the purposes of this function, we ignore fill and highlight and
* handle them like the trough */

View File

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

View File

@@ -815,24 +815,11 @@ gtk_widget_real_snapshot (GtkWidget *widget,
gtk_widget_snapshot_child (widget, child, snapshot);
}
static gboolean
gtk_widget_real_contains (GtkWidget *widget,
gdouble x,
gdouble y)
{
GtkCssBoxes boxes;
gtk_css_boxes_init (&boxes, widget);
/* XXX: This misses rounded rects */
return graphene_rect_contains_point (gtk_css_boxes_get_border_rect (&boxes),
&(graphene_point_t){x, y});
}
static GtkWidget *
gtk_widget_real_pick (GtkWidget *widget,
gdouble x,
gdouble y)
gdouble y,
gboolean reactive)
{
GtkWidget *child;
@@ -867,7 +854,7 @@ gtk_widget_real_pick (GtkWidget *widget,
graphene_point3d_interpolate (&p0, &p1, p0.z / (p0.z - p1.z), &res);
picked = gtk_widget_pick (child, res.x, res.y);
picked = gtk_widget_pick (child, res.x, res.y, reactive);
if (picked)
return picked;
}
@@ -982,7 +969,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->priv->accessible_role = ATK_ROLE_INVALID;
klass->get_accessible = gtk_widget_real_get_accessible;
klass->contains = gtk_widget_real_contains;
klass->pick = gtk_widget_real_pick;
widget_props[PROP_NAME] =
@@ -11042,11 +11028,6 @@ gtk_widget_get_allocation (GtkWidget *widget,
* The coordinates for (@x, @y) must be in widget coordinates, so
* (0, 0) is assumed to be the top left of @widget's content area.
*
* Pass-through widgets and insensitive widgets do never respond to
* input and will therefor always return %FALSE here. See
* gtk_widget_set_can_pick() and gtk_widget_set_sensitive() for
* details about those functions.
*
* Returns: %TRUE if @widget contains (@x, @y).
**/
gboolean
@@ -11054,14 +11035,14 @@ gtk_widget_contains (GtkWidget *widget,
gdouble x,
gdouble y)
{
GtkCssBoxes boxes;
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
if (!gtk_widget_get_can_pick (widget) ||
!_gtk_widget_is_sensitive (widget) ||
!_gtk_widget_is_drawable (widget))
return FALSE;
gtk_css_boxes_init (&boxes, widget);
return GTK_WIDGET_GET_CLASS (widget)->contains (widget, x, y);
return gsk_rounded_rect_contains_point (gtk_css_boxes_get_border_box (&boxes),
&GRAPHENE_POINT_INIT (x, y));
}
/**
@@ -11069,6 +11050,7 @@ gtk_widget_contains (GtkWidget *widget,
* @widget: the widget to query
* @x: X coordinate to test, relative to @widget's origin
* @y: Y coordinate to test, relative to @widget's origin
* @reactive: whether to return only widgets that are sensitive and can be picked
*
* Finds the descendant of @widget (including @widget itself) closest
* to the screen at the point (@x, @y). The point must be given in
@@ -11081,7 +11063,7 @@ gtk_widget_contains (GtkWidget *widget,
* Widgets are however free to customize their picking algorithm.
*
* This function is used on the toplevel to determine the widget below
* the mouse cursor for purposes of hover hilighting and delivering events.
* the mouse cursor for purposes of hover highlighting and delivering events.
*
* Returns: (nullable) (transfer none): The widget descendant at the given
* coordinate or %NULL if none.
@@ -11089,17 +11071,23 @@ gtk_widget_contains (GtkWidget *widget,
GtkWidget *
gtk_widget_pick (GtkWidget *widget,
gdouble x,
gdouble y)
gdouble y,
gboolean reactive)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (!gtk_widget_get_can_pick (widget) ||
!_gtk_widget_is_sensitive (widget) ||
!_gtk_widget_is_drawable (widget))
if (!_gtk_widget_is_drawable (widget))
return NULL;
if (reactive)
{
if (!gtk_widget_get_can_pick (widget) ||
!_gtk_widget_is_sensitive (widget))
return NULL;
}
switch (priv->overflow)
{
default:
@@ -11119,7 +11107,7 @@ gtk_widget_pick (GtkWidget *widget,
break;
}
return GTK_WIDGET_GET_CLASS (widget)->pick (widget, x, y);
return GTK_WIDGET_GET_CLASS (widget)->pick (widget, x, y, reactive);
}
/**

View File

@@ -222,7 +222,6 @@ struct _GtkWidget
* @style_updated: Signal emitted when the GtkStyleContext of a widget
* is changed.
* @snapshot: Vfunc for gtk_widget_snapshot().
* @contains: Vfunc for gtk_widget_contains().
* @pick: Vfunc for gtk_widget_pick().
*/
struct _GtkWidgetClass
@@ -336,12 +335,10 @@ struct _GtkWidgetClass
void (* snapshot) (GtkWidget *widget,
GtkSnapshot *snapshot);
gboolean (* contains) (GtkWidget *widget,
gdouble x,
gdouble y);
GtkWidget * (* pick) (GtkWidget *widget,
gdouble x,
gdouble y);
gdouble y,
gboolean reactive);
/*< private >*/
@@ -757,7 +754,8 @@ gboolean gtk_widget_contains (GtkWidget *widget,
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_widget_pick (GtkWidget *widget,
gdouble x,
gdouble y);
gdouble y,
gboolean reactive);
GDK_AVAILABLE_IN_ALL
void gtk_widget_add_controller (GtkWidget *widget,

View File

@@ -343,7 +343,6 @@ gboolean gtk_widget_run_controllers (GtkWidget
const GdkEvent *event,
GtkPropagationPhase phase);
/* inline getters */
static inline GtkWidget *

View File

@@ -738,7 +738,8 @@ static void popover_get_rect (GtkWindowPopover *popover,
static GtkWidget *
gtk_window_pick (GtkWidget *widget,
gdouble x,
gdouble y)
gdouble y,
gboolean reactive)
{
GtkWindow *window = GTK_WINDOW (widget);
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
@@ -754,12 +755,12 @@ gtk_window_pick (GtkWidget *widget,
x, y,
&dest_x, &dest_y);
picked = gtk_widget_pick (popover->widget, dest_x, dest_y);
picked = gtk_widget_pick (popover->widget, dest_x, dest_y, reactive);
if (picked)
return picked;
}
return GTK_WIDGET_CLASS (gtk_window_parent_class)->pick (widget, x, y);
return GTK_WIDGET_CLASS (gtk_window_parent_class)->pick (widget, x, y, reactive);
}
static void

View File

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

View File

@@ -187,7 +187,7 @@ gtk_transform_tester_snapshot (GtkWidget *widget,
const float py = y;
GtkWidget *picked;
#if 1
picked = gtk_widget_pick (widget, px, py);
picked = gtk_widget_pick (widget, px, py, TRUE);
#else
{
int dx, dy;