[gimp/wip/Jehan/layers-dockable-refresh: 13/58] app: more responsive lock popover.




commit fad252c179cb02c0764c12a01826fb88a1aae40d
Author: Jehan <jehan girinstud io>
Date:   Wed Feb 10 19:03:28 2021 +0100

    app: more responsive lock popover.
    
    First of all, let's use gtk_widget_show|hide() instead of
    gtk_popover_popup|down() because these GtkPopover API sometimes "block"
    when clicking very fast on the item list, sometimes up to 2 or 3 seconds
    (at least it feels like seconds, I haven't actually timed it!). I'm sure
    the ones who developed it thought it was nice to have slow popping
    dialogs, but when working fast, this can only be frustrating).
    
    The second responsiveness change is that when clicking out of useful
    popover area, it should not only close, but the event should be passed
    onto the item tree view when relevant. This allows for instance to
    directly click on an eye cell to change a layer visibility without
    having to click twice.

 app/widgets/gimpitemtreeview.c | 49 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
---
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index 641bcdb4a3..48060abefe 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -214,6 +214,9 @@ static void   gimp_item_tree_view_lock_toggled      (GtkWidget         *widget,
                                                      GimpItemTreeView  *view);
 static void   gimp_item_tree_view_update_lock_box   (GimpItemTreeView  *view,
                                                      GimpItem          *item);
+static gboolean gimp_item_tree_view_popover_button_press (GtkWidget        *widget,
+                                                          GdkEvent         *event,
+                                                          GimpItemTreeView *view);
 
 static gboolean gimp_item_tree_view_item_pre_clicked(GimpCellRendererViewable *cell,
                                                      const gchar              *path_str,
@@ -559,6 +562,10 @@ gimp_item_tree_view_constructed (GObject *object)
   /* Lock popover. */
   item_view->priv->lock_popover = gtk_popover_new (GTK_WIDGET (tree_view->view));
   gtk_popover_set_modal (GTK_POPOVER (item_view->priv->lock_popover), TRUE);
+  g_signal_connect (item_view->priv->lock_popover,
+                    "button-press-event",
+                    G_CALLBACK (gimp_item_tree_view_popover_button_press),
+                    item_view);
   gtk_container_add (GTK_CONTAINER (item_view->priv->lock_popover), item_view->priv->lock_box);
   gtk_widget_show (item_view->priv->lock_box);
 }
@@ -1751,7 +1758,7 @@ gimp_item_tree_view_lock_clicked (GtkCellRendererToggle *toggle,
       gtk_popover_set_pointing_to (GTK_POPOVER (view->priv->lock_popover), &rect);
       gtk_tree_path_free (path);
 
-      gtk_popover_popup (GTK_POPOVER (view->priv->lock_popover));
+      gtk_widget_show (view->priv->lock_popover);
     }
 }
 
@@ -1963,6 +1970,46 @@ gimp_item_tree_view_update_lock_box (GimpItemTreeView *view,
   view->priv->lock_box_item = item;
 }
 
+static gboolean
+gimp_item_tree_view_popover_button_press (GtkWidget        *widget,
+                                          GdkEvent         *event,
+                                          GimpItemTreeView *view)
+{
+  GimpContainerTreeView *tree_view    = GIMP_CONTAINER_TREE_VIEW (view);
+  GdkEventButton        *bevent       = (GdkEventButton *) event;
+  GdkEvent              *new_event;
+
+  /* If we get to the popover signal handling, it means we didn't click
+   * inside popover's buttons, which would have stopped the signal
+   * first. So we were going to hide the popover anyway.
+   * Nevertheless I do with with gtk_widget_hide() instead of
+   * gtk_popover_popdown() because the animation stuff is very buggy
+   * (sometimes the popup stays displayed even though it doesn't react,
+   * blocking the GUI for a second or so).
+   * Moreover I directly retransfer the event as though it was sent to
+   * the item tree view. This allows much faster GUI interaction, not
+   * having to click twice, once to close the popup, then a second for
+   * the actual action (like eye switching or lock on another item or
+   * item selection).
+   */
+  gtk_widget_hide (widget);
+
+  if (gtk_tree_view_get_path_at_pos (tree_view->view,
+                                     bevent->x, bevent->y,
+                                     NULL, NULL, NULL, NULL))
+    {
+      new_event = gdk_event_copy (event);
+      g_object_unref (new_event->any.window);
+      new_event->any.window     = g_object_ref (gtk_widget_get_window (GTK_WIDGET (tree_view->view)));
+      new_event->any.send_event = TRUE;
+
+      gtk_main_do_event (new_event);
+      gdk_event_free (new_event);
+    }
+
+  return GDK_EVENT_STOP;
+}
+
 
 /*  GtkTreeView callbacks  */
 


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