[gnome-shell/wip/pressure: 5/14] st-scroll-bar: use clutter_grab_pointer()



commit 08ec05a419ec0508214bdc47f98ab463d8dd684b
Author: Dan Winship <danw gnome org>
Date:   Fri Oct 28 17:32:32 2011 -0400

    st-scroll-bar: use clutter_grab_pointer()
    
    StScrollBar was intercepting motion events by using captured-event on
    the stage, which required additional dirty tricks, which required
    additional hacks. Simplify it by just using clutter_grab_pointer()
    instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671001

 js/ui/popupMenu.js     |   25 ----------------
 src/st/st-scroll-bar.c |   76 ++++++++++++++++++-----------------------------
 2 files changed, 29 insertions(+), 72 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index 0517837..10253b8 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -862,10 +862,6 @@ const PopupMenuBase = new Lang.Class({
         // for the menu which causes its prelight state to freeze
         this.blockSourceEvents = false;
 
-        // Can be set while a menu is up to let all events through without special
-        // menu handling useful for scrollbars in menus, and probably not otherwise.
-        this.passEvents = false;
-
         this._activeMenuItem = null;
         this._childMenus = [];
         this._settingsActions = { };
@@ -1284,24 +1280,6 @@ const PopupSubMenu = new Lang.Class({
                                          hscrollbar_policy: Gtk.PolicyType.NEVER,
                                          vscrollbar_policy: Gtk.PolicyType.NEVER });
 
-        // StScrollbar plays dirty tricks with events, calling
-        // clutter_set_motion_events_enabled (FALSE) during the scroll; this
-        // confuses our event tracking, so we just turn it off during the
-        // scroll.
-        let vscroll = this.actor.get_vscroll_bar();
-        vscroll.connect('scroll-start',
-                        Lang.bind(this, function() {
-                                      let topMenu = this._getTopMenu();
-                                      if (topMenu)
-                                          topMenu.passEvents = true;
-                                  }));
-        vscroll.connect('scroll-stop',
-                        Lang.bind(this, function() {
-                                      let topMenu = this._getTopMenu();
-                                      if (topMenu)
-                                          topMenu.passEvents = false;
-                                  }));
-
         this.actor.add_actor(this.box);
         this.actor._delegate = this;
         this.actor.clip_to_allocation = true;
@@ -2278,9 +2256,6 @@ const PopupMenuManager = new Lang.Class({
             this._owner.menuEventFilter(event))
             return true;
 
-        if (this._activeMenu != null && this._activeMenu.passEvents)
-            return false;
-
         if (this._didPop) {
             this._didPop = false;
             return true;
diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c
index 8353109..4858d84 100644
--- a/src/st/st-scroll-bar.c
+++ b/src/st/st-scroll-bar.c
@@ -52,7 +52,7 @@ struct _StScrollBarPrivate
 {
   StAdjustment *adjustment;
 
-  gulong        capture_handler;
+  gboolean      grabbed;
   gfloat        x_origin;
   gfloat        y_origin;
 
@@ -586,50 +586,35 @@ move_slider (StScrollBar *bar,
 static void
 stop_scrolling (StScrollBar *bar)
 {
-  ClutterStage *stage;
-
-  if (!bar->priv->capture_handler)
+  if (!bar->priv->grabbed)
     return;
 
-  stage = CLUTTER_STAGE (clutter_actor_get_stage (bar->priv->trough));
-  g_signal_handler_disconnect (stage, bar->priv->capture_handler);
-  bar->priv->capture_handler = 0;
-
-  clutter_stage_set_motion_events_enabled (stage, TRUE);
+  clutter_ungrab_pointer ();
+  bar->priv->grabbed = FALSE;
   g_signal_emit (bar, signals[SCROLL_STOP], 0);
 }
 
 static gboolean
-handle_capture_event_cb (ClutterActor *trough,
-                         ClutterEvent *event,
-                         StScrollBar  *bar)
+handle_motion_event_cb (ClutterActor       *trough,
+                        ClutterMotionEvent *event,
+                        StScrollBar        *bar)
 {
-  if (clutter_event_type (event) == CLUTTER_MOTION)
-    {
-      move_slider (bar,
-                   ((ClutterMotionEvent*) event)->x,
-                   ((ClutterMotionEvent*) event)->y);
-    }
-  else if (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE
-           && ((ClutterButtonEvent*) event)->button == 1)
-    {
-      ClutterActor *stage, *target;
-
-      stop_scrolling (bar);
-
-      /* check if the mouse pointer has left the handle during the drag and
-       * remove the hover state if it has */
-      stage = clutter_actor_get_stage (bar->priv->trough);
-      target = clutter_stage_get_actor_at_pos ((ClutterStage*) stage,
-                                               CLUTTER_PICK_REACTIVE,
-                                               ((ClutterButtonEvent*) event)->x,
-                                               ((ClutterButtonEvent*) event)->y);
-      if (target != bar->priv->handle)
-        {
-          st_widget_remove_style_pseudo_class ((StWidget*) bar->priv->handle, "hover");
-        }
-    }
+  if (!bar->priv->grabbed)
+    return FALSE;
 
+  move_slider (bar, event->x, event->y);
+  return TRUE;
+}
+
+static gboolean
+handle_button_release_event_cb (ClutterActor       *trough,
+                                ClutterButtonEvent *event,
+                                StScrollBar        *bar)
+{
+  if (event->button != 1)
+    return FALSE;
+
+  stop_scrolling (bar);
   return TRUE;
 }
 
@@ -638,7 +623,6 @@ handle_button_press_event_cb (ClutterActor       *actor,
                               ClutterButtonEvent *event,
                               StScrollBar        *bar)
 {
-  ClutterStage *stage;
   StScrollBarPrivate *priv = bar->priv;
 
   if (event->button != 1)
@@ -655,16 +639,10 @@ handle_button_press_event_cb (ClutterActor       *actor,
   priv->x_origin += clutter_actor_get_x (priv->trough);
   priv->y_origin += clutter_actor_get_y (priv->trough);
 
-  stage = CLUTTER_STAGE (clutter_actor_get_stage (bar->priv->trough));
-
-  /* Turn off picking for motion events */
-  clutter_stage_set_motion_events_enabled (stage, FALSE);
+  g_assert (!priv->grabbed);
 
-  priv->capture_handler = g_signal_connect_after (
-    clutter_actor_get_stage (priv->trough),
-    "captured-event",
-    G_CALLBACK (handle_capture_event_cb),
-    bar);
+  clutter_grab_pointer (priv->handle);
+  priv->grabbed = TRUE;
   g_signal_emit (bar, signals[SCROLL_START], 0);
 
   return TRUE;
@@ -881,6 +859,10 @@ st_scroll_bar_init (StScrollBar *self)
                            CLUTTER_ACTOR (self->priv->handle));
   g_signal_connect (self->priv->handle, "button-press-event",
                     G_CALLBACK (handle_button_press_event_cb), self);
+  g_signal_connect (self->priv->handle, "button-release-event",
+                    G_CALLBACK (handle_button_release_event_cb), self);
+  g_signal_connect (self->priv->handle, "motion-event",
+                    G_CALLBACK (handle_motion_event_cb), self);
 
   clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
 



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