[gtk/pick-insensitive: 2/4] widget: Allow picking insensitive widgets
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/pick-insensitive: 2/4] widget: Allow picking insensitive widgets
- Date: Sun, 7 Apr 2019 13:04:46 +0000 (UTC)
commit 2f30bbbbf2ba906a998ea9a098dd54aee42ad5da
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 7 12:46:57 2019 +0000
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.
demos/gtk-demo/dnd.c | 4 ++--
demos/gtk-demo/sliding_puzzle.c | 2 +-
gtk/gtkflowbox.c | 2 +-
gtk/gtkmain.c | 4 ++--
gtk/gtkpaned.c | 5 +++--
gtk/gtkpointerfocus.c | 2 +-
gtk/gtkrange.c | 4 ++--
gtk/gtktooltip.c | 2 +-
gtk/gtkwidget.c | 24 ++++++++++++++++--------
gtk/gtkwidget.h | 6 ++++--
gtk/gtkwidgetprivate.h | 1 -
gtk/gtkwindow.c | 7 ++++---
gtk/inspector/inspect-button.c | 2 +-
tests/testwidgettransforms.c | 2 +-
14 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c
index cb21d2f25b..48feeec356 100644
--- a/demos/gtk-demo/dnd.c
+++ b/demos/gtk-demo/dnd.c
@@ -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)
{
diff --git a/demos/gtk-demo/sliding_puzzle.c b/demos/gtk-demo/sliding_puzzle.c
index dd1bc65151..8acabd4d44 100644
--- a/demos/gtk-demo/sliding_puzzle.c
+++ b/demos/gtk-demo/sliding_puzzle.c
@@ -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)
{
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index 1cb1683606..56073a3eea 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -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;
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 2c61209eac..4995f0ed67 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -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,
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index b39057023f..669ba406e3 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -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
diff --git a/gtk/gtkpointerfocus.c b/gtk/gtkpointerfocus.c
index 6c2c90f455..80625aa532 100644
--- a/gtk/gtkpointerfocus.c
+++ b/gtk/gtkpointerfocus.c
@@ -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);
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index a26e882ec9..a1a6fc33ec 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -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 */
diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c
index f309fc7683..0141b0714f 100644
--- a/gtk/gtktooltip.c
+++ b/gtk/gtktooltip.c
@@ -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, TRUE);
if (picked_widget != NULL)
gtk_widget_translate_coordinates (event_widget, picked_widget, surface_x, surface_y, widget_x, widget_y);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 95cad7c640..426e8e304b 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -818,7 +818,8 @@ gtk_widget_real_snapshot (GtkWidget *widget,
static GtkWidget *
gtk_widget_real_pick (GtkWidget *widget,
gdouble x,
- gdouble y)
+ gdouble y,
+ gboolean reactive)
{
GtkWidget *child;
@@ -853,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;
}
@@ -11049,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
@@ -11061,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.
@@ -11069,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:
@@ -11099,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);
}
/**
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 4cc1161121..5a3610b448 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -337,7 +337,8 @@ struct _GtkWidgetClass
GtkWidget * (* pick) (GtkWidget *widget,
gdouble x,
- gdouble y);
+ gdouble y,
+ gboolean reactive);
/*< private >*/
@@ -753,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,
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 03c9f95923..015d938cf9 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -343,7 +343,6 @@ gboolean gtk_widget_run_controllers (GtkWidget
const GdkEvent *event,
GtkPropagationPhase phase);
-
/* inline getters */
static inline GtkWidget *
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 650eac6c3b..798031b5af 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -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
diff --git a/gtk/inspector/inspect-button.c b/gtk/inspector/inspect-button.c
index 76e52f4df1..a6e342a45b 100644
--- a/gtk/inspector/inspect-button.c
+++ b/gtk/inspector/inspect-button.c
@@ -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, TRUE);
}
return widget;
diff --git a/tests/testwidgettransforms.c b/tests/testwidgettransforms.c
index 1dd8d2c1ad..f1ad9eb32a 100644
--- a/tests/testwidgettransforms.c
+++ b/tests/testwidgettransforms.c
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]