[gtk] eventcontrollermotion: Add getters for the properties
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] eventcontrollermotion: Add getters for the properties
- Date: Sun, 15 Dec 2019 20:08:39 +0000 (UTC)
commit dff86c0e121c39291b705a2c654f28693c1198a2
Author: Benjamin Otte <otte redhat com>
Date: Sun Dec 15 20:25:42 2019 +0100
eventcontrollermotion: Add getters for the properties
... and use them.
Also, rename them from is/contains-pointer-focus to is/contains-pointer,
that's clear enough and not too long.
Finally, adapt the semantics of contains-pointer to mirror
GtkEventControllerKey::contains-focus. If is-pointer is set, so is
contains-pointer, they are not exclusive.
Which is what all users of this property wanted, too.
docs/reference/gtk/gtk4-sections.txt | 2 +
gtk/gtkeventcontrollermotion.c | 89 ++++++++++++++++++++++++------------
gtk/gtkeventcontrollermotion.h | 5 ++
gtk/gtkmenuitem.c | 16 +------
gtk/gtkmodelbutton.c | 9 +---
gtk/gtkpopovermenu.c | 9 +---
gtk/gtktreeview.c | 9 +---
7 files changed, 72 insertions(+), 67 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index d038dfcfe0..4939bbda58 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -6689,6 +6689,8 @@ GtkEventControllerMotion
gtk_event_controller_motion_new
gtk_event_controller_motion_get_pointer_origin
gtk_event_controller_motion_get_pointer_target
+gtk_event_controller_motion_contains_pointer
+gtk_event_controller_motion_is_pointer
<SUBSECTION Standard>
GTK_TYPE_EVENT_CONTROLLER_MOTION
diff --git a/gtk/gtkeventcontrollermotion.c b/gtk/gtkeventcontrollermotion.c
index 9ba9bdd627..a9cc46848c 100644
--- a/gtk/gtkeventcontrollermotion.c
+++ b/gtk/gtkeventcontrollermotion.c
@@ -43,8 +43,8 @@ struct _GtkEventControllerMotion
const GdkEvent *current_event;
- guint is_pointer_focus : 1;
- guint contains_pointer_focus : 1;
+ guint is_pointer : 1;
+ guint contains_pointer : 1;
};
struct _GtkEventControllerMotionClass
@@ -60,8 +60,8 @@ enum {
};
enum {
- PROP_IS_POINTER_FOCUS = 1,
- PROP_CONTAINS_POINTER_FOCUS,
+ PROP_IS_POINTER = 1,
+ PROP_CONTAINS_POINTER,
NUM_PROPERTIES
};
@@ -89,11 +89,11 @@ update_pointer_focus (GtkEventControllerMotion *motion,
case GDK_NOTIFY_ANCESTOR:
case GDK_NOTIFY_NONLINEAR:
is_pointer = enter;
- contains_pointer = FALSE;
+ contains_pointer = enter;
break;
case GDK_NOTIFY_INFERIOR:
is_pointer = enter;
- contains_pointer = !enter;
+ contains_pointer = TRUE;
break;
case GDK_NOTIFY_UNKNOWN:
default:
@@ -102,15 +102,15 @@ update_pointer_focus (GtkEventControllerMotion *motion,
}
g_object_freeze_notify (G_OBJECT (motion));
- if (motion->is_pointer_focus != is_pointer)
+ if (motion->is_pointer != is_pointer)
{
- motion->is_pointer_focus = is_pointer;
- g_object_notify (G_OBJECT (motion), "is-pointer-focus");
+ motion->is_pointer = is_pointer;
+ g_object_notify (G_OBJECT (motion), "is-pointer");
}
- if (motion->contains_pointer_focus != contains_pointer)
+ if (motion->contains_pointer != contains_pointer)
{
- motion->contains_pointer_focus = contains_pointer;
- g_object_notify (G_OBJECT (motion), "contains-pointer-focus");
+ motion->contains_pointer = contains_pointer;
+ g_object_notify (G_OBJECT (motion), "contains-pointer");
}
g_object_thaw_notify (G_OBJECT (motion));
}
@@ -182,12 +182,12 @@ gtk_event_controller_motion_get_property (GObject *object,
switch (prop_id)
{
- case PROP_IS_POINTER_FOCUS:
- g_value_set_boolean (value, controller->is_pointer_focus);
+ case PROP_IS_POINTER:
+ g_value_set_boolean (value, controller->is_pointer);
break;
- case PROP_CONTAINS_POINTER_FOCUS:
- g_value_set_boolean (value, controller->contains_pointer_focus);
+ case PROP_CONTAINS_POINTER:
+ g_value_set_boolean (value, controller->contains_pointer);
break;
default:
@@ -206,37 +206,37 @@ gtk_event_controller_motion_class_init (GtkEventControllerMotionClass *klass)
controller_class->handle_event = gtk_event_controller_motion_handle_event;
/**
- * GtkEventControllerMotion:is-pointer-focus:
+ * GtkEventControllerMotion:is-pointer:
*
* Whether the pointer is in the controllers widget itself,
- * as opposed to in a descendent widget. See
- * #GtkEventControllerMotion:contains-pointer-focus.
+ * as opposed to in a descendent widget. See also
+ * #GtkEventControllerMotion:contains-pointer.
*
* When handling crossing events, this property is updated
* before #GtkEventControllerMotion::enter or
* #GtkEventControllerMotion::leave are emitted.
*/
- props[PROP_IS_POINTER_FOCUS] =
- g_param_spec_boolean ("is-pointer-focus",
- P_("Is Pointer Focus"),
+ props[PROP_IS_POINTER] =
+ g_param_spec_boolean ("is-pointer",
+ P_("Is Pointer"),
P_("Whether the pointer is in the controllers widget"),
FALSE,
G_PARAM_READABLE);
/**
- * GtkEventControllerMotion:contains-pointer-focus:
+ * GtkEventControllerMotion:contains-pointer:
*
- * Whether the pointer is in a descendant of the controllers widget.
- * See #GtkEventControllerMotion:is-pointer-focus.
+ * Whether the pointer is in the controllers widget or a descendant.
+ * See also #GtkEventControllerMotion:is-pointer.
*
* When handling crossing events, this property is updated
* before #GtkEventControllerMotion::enter or
* #GtkEventControllerMotion::leave are emitted.
*/
- props[PROP_CONTAINS_POINTER_FOCUS] =
- g_param_spec_boolean ("contains-pointer-focus",
- P_("Contains Pointer Focus"),
- P_("Whether the pointer is in a descendant of the controllers widget"),
+ props[PROP_CONTAINS_POINTER] =
+ g_param_spec_boolean ("contains-pointer",
+ P_("Contains Pointer"),
+ P_("Whether the pointer is inthe controllers widget or a descendant"),
FALSE,
G_PARAM_READABLE);
@@ -381,3 +381,34 @@ gtk_event_controller_motion_get_pointer_target (GtkEventControllerMotion *contro
return (GtkWidget *)gdk_event_get_related_target (controller->current_event);
}
+/**
+ * gtk_event_controller_motion_contains_pointer:
+ * @self: a #GtkEventControllerMotion
+ *
+ * Returns the value of the GtkEventControllerMotion:contains-pointer property.
+ *
+ * Returns: %TRUE if a pointer is within @self or one of its children
+ */
+gboolean
+gtk_event_controller_motion_contains_pointer (GtkEventControllerMotion *self)
+{
+ g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (self), FALSE);
+
+ return self->contains_pointer;
+}
+
+/**
+ * gtk_event_controller_motion_is_pointer:
+ * @self: a #GtkEventControllerKey
+ *
+ * Returns the value of the GtkEventControllerMotion:is-pointer property.
+ *
+ * Returns: %TRUE if a pointer is within @self but not one of its children
+ */
+gboolean
+gtk_event_controller_motion_is_pointer (GtkEventControllerMotion *self)
+{
+ g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER_MOTION (self), FALSE);
+
+ return self->is_pointer;
+}
diff --git a/gtk/gtkeventcontrollermotion.h b/gtk/gtkeventcontrollermotion.h
index 05d1852986..dbbc8c5621 100644
--- a/gtk/gtkeventcontrollermotion.h
+++ b/gtk/gtkeventcontrollermotion.h
@@ -50,6 +50,11 @@ GtkWidget * gtk_event_controller_motion_get_pointer_origin (GtkEventCont
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_event_controller_motion_get_pointer_target (GtkEventControllerMotion *controller);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_event_controller_motion_contains_pointer (GtkEventControllerMotion *self);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_event_controller_motion_is_pointer (GtkEventControllerMotion *self);
+
G_END_DECLS
#endif /* __GTK_EVENT_CONTROLLER_MOTION_H__ */
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 111d94ff89..1cd529babf 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -1118,7 +1118,6 @@ gtk_menu_item_enter (GtkEventController *controller,
GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
GtkMenuShell *menu_shell;
GdkEvent *event;
- gboolean is_focus, contains_focus;
event = gtk_get_current_event (); /* FIXME controller event */
@@ -1133,14 +1132,9 @@ gtk_menu_item_enter (GtkEventController *controller,
menu_shell = gtk_menu_item_get_menu_shell (menu_item);
- g_object_get (controller,
- "is-pointer-focus", &is_focus,
- "contains-pointer-focus", &contains_focus,
- NULL);
-
if (menu_shell != NULL &&
menu_shell->priv->active &&
- (is_focus || contains_focus))
+ gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
gtk_menu_shell_select_item (menu_shell, GTK_WIDGET (menu_item));
}
@@ -1152,16 +1146,10 @@ gtk_menu_item_leave (GtkEventController *controller,
{
GtkMenuItem *menu_item = GTK_MENU_ITEM (user_data);
GtkMenuShell *menu_shell = gtk_menu_item_get_menu_shell (menu_item);
- gboolean is_focus, contains_focus;
-
- g_object_get (controller,
- "is-pointer-focus", &is_focus,
- "contains-pointer-focus", &contains_focus,
- NULL);
if (menu_shell &&
!menu_item->priv->submenu &&
- !(is_focus || contains_focus))
+ !gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
gtk_menu_shell_deselect (menu_shell);
}
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 8d7bc1e408..b40b30c9ce 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -1325,18 +1325,11 @@ enter_cb (GtkEventController *controller,
{
GtkWidget *target;
GtkWidget *popover;
- gboolean is;
- gboolean contains;
target = gtk_event_controller_get_widget (controller);
popover = gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU);
- g_object_get (controller,
- "is-pointer-focus", &is,
- "contains-pointer-focus", &contains,
- NULL);
-
- if (popover && (is || contains))
+ if (popover && gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
{
if (gtk_popover_menu_get_open_submenu (GTK_POPOVER_MENU (popover)) != NULL)
start_open (GTK_MODEL_BUTTON (target));
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 369c9d6360..62993b51e3 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -237,17 +237,10 @@ leave_cb (GtkEventController *controller,
gpointer data)
{
GtkWidget *target;
- gboolean is;
- gboolean contains;
target = gtk_event_controller_get_widget (controller);
- g_object_get (controller,
- "is-pointer-focus", &is,
- "contains-pointer-focus", &contains,
- NULL);
-
- if (!(is || contains))
+ if (!gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
gtk_popover_menu_set_active_item (GTK_POPOVER_MENU (target), NULL);
}
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 4c51ba451e..76b24c08b4 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -5583,20 +5583,13 @@ gtk_tree_view_motion_controller_leave (GtkEventControllerMotion *controller,
GdkNotifyType detail,
GtkTreeView *tree_view)
{
- gboolean is_focus, contains_focus;
-
if (tree_view->priv->prelight_node)
gtk_widget_queue_draw (GTK_WIDGET (tree_view));
tree_view->priv->event_last_x = -10000;
tree_view->priv->event_last_y = -10000;
- g_object_get (controller,
- "is-pointer-focus", &is_focus,
- "contains-pointer-focus", &contains_focus,
- NULL);
-
- if (!is_focus && !contains_focus)
+ if (!gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
prelight_or_select (tree_view, NULL, NULL, -1000, -1000); /* not possibly over an arrow */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]