[gtk+/gtk-3-22] gtklinkbutton: Set cursor on button's event window



commit 0daf796763b98cd30775bc4bef959ce1b0aa0287
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jul 25 15:46:01 2017 +0200

    gtklinkbutton: Set cursor on button's event window
    
    Setting the cursor on the widget window (i.e. the parent widget's) is
    finicky because the cursor needs to be updated on crossing events, and
    will yield the wrong result for other master devices that happen to be
    in other areas of the same parent widget's window.
    
    Just set it always on the event window created by the GtkButton parent
    class. That window was causing the crossing events, so the rectangle
    that gets the hand cursor set will be the same size, and we don't need
    to track pointer crossing state that way.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785375

 gtk/gtklinkbutton.c |   42 +++++++++++-------------------------------
 1 files changed, 11 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 0ce64a2..e7aab31 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -106,13 +106,8 @@ static gboolean gtk_link_button_button_press (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static void     gtk_link_button_clicked      (GtkButton        *button);
 static gboolean gtk_link_button_popup_menu   (GtkWidget        *widget);
+static void     gtk_link_button_realize      (GtkWidget        *widget);
 static void     gtk_link_button_unrealize    (GtkWidget        *widget);
-static gboolean gtk_link_button_enter_cb     (GtkWidget        *widget,
-                                             GdkEventCrossing *event,
-                                             gpointer          user_data);
-static gboolean gtk_link_button_leave_cb     (GtkWidget        *widget,
-                                             GdkEventCrossing *event,
-                                             gpointer          user_data);
 static void gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
                                              GdkDragContext   *context,
                                              GtkSelectionData *selection,
@@ -149,6 +144,7 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
 
   widget_class->button_press_event = gtk_link_button_button_press;
   widget_class->popup_menu = gtk_link_button_popup_menu;
+  widget_class->realize = gtk_link_button_realize;
   widget_class->unrealize = gtk_link_button_unrealize;
 
   button_class->clicked = gtk_link_button_clicked;
@@ -223,10 +219,6 @@ gtk_link_button_init (GtkLinkButton *link_button)
   gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE);
   gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
 
-  g_signal_connect (link_button, "enter-notify-event",
-                   G_CALLBACK (gtk_link_button_enter_cb), NULL);
-  g_signal_connect (link_button, "leave-notify-event",
-                   G_CALLBACK (gtk_link_button_leave_cb), NULL);
   g_signal_connect (link_button, "drag-data-get",
                    G_CALLBACK (gtk_link_button_drag_data_get_cb), NULL);
 
@@ -311,7 +303,7 @@ set_hand_cursor (GtkWidget *widget,
   if (show_hand)
     cursor = gdk_cursor_new_from_name (display, "pointer");
 
-  gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
+  gdk_window_set_cursor (gtk_button_get_event_window (GTK_BUTTON (widget)), cursor);
   gdk_display_flush (display);
 
   if (cursor)
@@ -319,6 +311,14 @@ set_hand_cursor (GtkWidget *widget,
 }
 
 static void
+gtk_link_button_realize (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gtk_link_button_parent_class)->realize (widget);
+
+  set_hand_cursor (widget, TRUE);
+}
+
+static void
 gtk_link_button_unrealize (GtkWidget *widget)
 {
   set_hand_cursor (widget, FALSE);
@@ -452,26 +452,6 @@ gtk_link_button_popup_menu (GtkWidget *widget)
   return TRUE; 
 }
 
-static gboolean
-gtk_link_button_enter_cb (GtkWidget        *widget,
-                         GdkEventCrossing *crossing,
-                         gpointer          user_data)
-{
-  set_hand_cursor (widget, TRUE);
-  
-  return FALSE;
-}
-
-static gboolean
-gtk_link_button_leave_cb (GtkWidget        *widget,
-                         GdkEventCrossing *crossing,
-                         gpointer          user_data)
-{
-  set_hand_cursor (widget, FALSE);
-  
-  return FALSE;
-}
-
 static void
 gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
                                  GdkDragContext   *context,


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