eventcontrollermotion: Add getters for the properties
authorBenjamin Otte <otte@redhat.com>
Sun, 15 Dec 2019 19:25:42 +0000 (20:25 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 15 Dec 2019 20:07:54 +0000 (21:07 +0100)
... 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
gtk/gtkeventcontrollermotion.c
gtk/gtkeventcontrollermotion.h
gtk/gtkmenuitem.c
gtk/gtkmodelbutton.c
gtk/gtkpopovermenu.c
gtk/gtktreeview.c

index d038dfcfe09b08c06fbfae88d39647f07419d3ae..4939bbda58c724c422a4c363758b960315104026 100644 (file)
@@ -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
index 9ba9bdd627cb484b65a44cd1f57619bead9b41b2..a9cc46848c11fb99883df5d1bf04bcd7b91969bd 100644 (file)
@@ -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;
+}
index 05d18529867e7ea9bcb2dcc01e93ce4c83f1ac07..dbbc8c5621ccdecd959e16dc5d4bb3daef5e2235 100644 (file)
@@ -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__ */
index 111d94ff89f54c0108206bc590b97dbd4f192aaf..1cd529babfa1a9f253168979883ea9723c8f4d11 100644 (file)
@@ -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);
 }
 
index 8d7bc1e408cab7929985982102acec2af1067d32..b40b30c9cea2040b19207ab8b16fed9519bccaf9 100644 (file)
@@ -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));
index 369c9d63607cff0ea86b232cf4ac184f59e7220a..62993b51e32b34ce96527184ed71b3b4f7471168 100644 (file)
@@ -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);
 }
 
index 4c51ba451ef5ceac794e9894917f0f165129ef60..76b24c08b45217f503d4fdfa7bbc95d500a61ffd 100644 (file)
@@ -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 */
 }