[gnome-shell] Add shell_button_box_fake_release



commit 0a17a28608d587b3121ec7bc30c35e2f2b466a5b
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 1 14:14:19 2009 -0400

    Add shell_button_box_fake_release
    
    The application menu code wants to do a popup after a given timeout
    while holding.  We can implement that by adding a function to
    manually break the grab held by the button box.
    
    Freeze+thaw around the hover and pressed property notification on leave
    since handlers may want to depend on the pressed state on a hover
    transition.

 src/shell-button-box.c |   31 ++++++++++++++++++++++++++++++-
 src/shell-button-box.h |    2 ++
 2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/src/shell-button-box.c b/src/shell-button-box.c
index a7f54c3..85ce121 100644
--- a/src/shell-button-box.c
+++ b/src/shell-button-box.c
@@ -89,9 +89,13 @@ shell_button_box_enter_event (ClutterActor         *actor,
   if (!shell_button_box_contains (box, event->source))
     return TRUE;
 
-  set_hover (box, TRUE);
+  g_object_freeze_notify (G_OBJECT (actor));
+
   if (box->priv->held)
     set_pressed (box, TRUE);
+  set_hover (box, TRUE);
+
+  g_object_thaw_notify (G_OBJECT (actor));
 
   return TRUE;
 }
@@ -159,6 +163,31 @@ shell_button_box_button_release_event (ClutterActor       *actor,
   return TRUE;
 }
 
+/**
+ * shell_button_box_fake_release:
+ * @box:
+ *
+ * If this button box is holding a pointer grab, this function will
+ * will ungrab it, and reset the pressed state.  The effect is
+ * similar to if the user had released the mouse button, but without
+ * emitting the activate signal.
+ *
+ * This function is useful if for example you want to do something after the user
+ * is holding the mouse button for a given period of time, breaking the
+ * grab.
+ */
+void
+shell_button_box_fake_release (ShellButtonBox *box)
+{
+  if (!box->priv->held)
+    return;
+
+  box->priv->held = FALSE;
+  clutter_ungrab_pointer ();
+
+  set_pressed (box, FALSE);
+}
+
 static void
 shell_button_box_set_property(GObject         *object,
                               guint            prop_id,
diff --git a/src/shell-button-box.h b/src/shell-button-box.h
index 20d136e..4bd756a 100644
--- a/src/shell-button-box.h
+++ b/src/shell-button-box.h
@@ -30,4 +30,6 @@ struct _ShellButtonBoxClass
 
 GType shell_button_box_get_type (void) G_GNUC_CONST;
 
+void shell_button_box_fake_release (ShellButtonBox *box);
+
 #endif /* __SHELL_BUTTON_BOX_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]