[gnome-builder] sourcemap: avoid hysteresis from mouse hover



commit 213367f103566ba4fe0cd7146374ea89f3ba3764
Author: Christian Hergert <chergert redhat com>
Date:   Mon Mar 13 02:52:00 2017 -0700

    sourcemap: avoid hysteresis from mouse hover
    
    When the mouse is hovered over the sourcemap, we would get into a situation
    where it would just collapse/expand over and over again. This tracks if
    we are in the map and ensures stability during that time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779971

 libide/sourceview/ide-source-map.c |   44 ++++++++++++++++++++++++++++-------
 1 files changed, 35 insertions(+), 9 deletions(-)
---
diff --git a/libide/sourceview/ide-source-map.c b/libide/sourceview/ide-source-map.c
index 4327dbb..80cb61d 100644
--- a/libide/sourceview/ide-source-map.c
+++ b/libide/sourceview/ide-source-map.c
@@ -21,11 +21,12 @@
 #include <egg-signal-group.h>
 #include <glib/gi18n.h>
 
-#include "buffers/ide-buffer.h"
+#include "ide-macros.h"
 
-#include "ide-line-change-gutter-renderer.h"
-#include "ide-source-map.h"
-#include "ide-source-view.h"
+#include "buffers/ide-buffer.h"
+#include "sourceview/ide-line-change-gutter-renderer.h"
+#include "sourceview/ide-source-map.h"
+#include "sourceview/ide-source-view.h"
 
 #define CONCEAL_TIMEOUT 2000
 
@@ -38,6 +39,9 @@ struct _IdeSourceMap
   GtkSourceGutterRenderer   *line_renderer;
   guint                      delayed_conceal_timeout;
   guint                      show_map : 1;
+
+  guint                      in_map : 1;
+  guint                      in_view : 1;
 };
 
 G_DEFINE_TYPE (IdeSourceMap, ide_source_map, GTK_SOURCE_TYPE_MAP)
@@ -78,6 +82,16 @@ ide_source_map__enter_notify_event (IdeSourceMap     *self,
   g_assert (event != NULL);
   g_assert (GTK_IS_WIDGET (widget));
 
+  /* We use this same method for both the view and self,
+   * so if we are hovering our map, keep track of it.
+   */
+
+  if (IDE_IS_SOURCE_MAP (widget))
+    self->in_map = TRUE;
+
+  if (IDE_IS_SOURCE_VIEW (widget))
+    self->in_view = TRUE;
+
   if (self->show_map == FALSE)
     {
       self->show_map = TRUE;
@@ -92,12 +106,12 @@ ide_source_map_show_map_and_queue_fade (IdeSourceMap *self)
 {
   g_assert (IDE_IS_SOURCE_MAP (self));
 
-  if (self->delayed_conceal_timeout != 0)
-    g_source_remove (self->delayed_conceal_timeout);
+  ide_clear_source (&self->delayed_conceal_timeout);
 
-  self->delayed_conceal_timeout = g_timeout_add (CONCEAL_TIMEOUT,
-                                                 ide_source_map_do_conceal,
-                                                 self);
+  if (self->in_map == FALSE)
+    self->delayed_conceal_timeout = g_timeout_add (CONCEAL_TIMEOUT,
+                                                   ide_source_map_do_conceal,
+                                                   self);
 
   if (self->show_map == FALSE)
     {
@@ -115,6 +129,16 @@ ide_source_map__leave_notify_event (IdeSourceMap     *self,
   g_assert (event != NULL);
   g_assert (GTK_IS_WIDGET (widget));
 
+  /* We use this same method for both the view and self,
+   * so if we are hovering our map, keep track of it.
+   */
+
+  if (IDE_IS_SOURCE_MAP (widget))
+    self->in_map = FALSE;
+
+  if (IDE_IS_SOURCE_VIEW (widget))
+    self->in_view = FALSE;
+
   ide_source_map_show_map_and_queue_fade (self);
 
   return GDK_EVENT_PROPAGATE;
@@ -262,6 +286,8 @@ ide_source_map_init (IdeSourceMap *self)
 {
   GtkSourceGutter *gutter;
 
+  gtk_widget_add_events (GTK_WIDGET (self), GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+
   /* Buffer */
   self->buffer_signals = egg_signal_group_new (IDE_TYPE_BUFFER);
   egg_signal_group_connect_object (self->buffer_signals,


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