[gtk+/wip/carlosg/event-delivery: 13/72] gtk: Update GtkPointerFocus targets on mapping/sensitivity changes



commit 469431c5a0f6c63b1ee77bc2dc247a169a62d6a6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 31 17:49:21 2017 +0200

    gtk: Update GtkPointerFocus targets on mapping/sensitivity changes
    
    Those are situations that must cause foci on these widgets to repick
    themselves.

 gtk/gtkwidget.c        |   18 ++++++++++++++++++
 gtk/gtkwindow.c        |   28 ++++++++++++++++++++++++++++
 gtk/gtkwindowprivate.h |    3 +++
 3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b38882c..b2d818a 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4374,6 +4374,19 @@ gtk_widget_hide_on_delete (GtkWidget *widget)
   return TRUE;
 }
 
+static void
+update_cursor_on_state_change (GtkWidget *widget)
+{
+  GtkWidget *toplevel;
+
+  toplevel = gtk_widget_get_toplevel (widget);
+  if (!GTK_IS_WINDOW (toplevel))
+    return;
+
+  gtk_window_update_pointer_focus_on_state_change (GTK_WINDOW (toplevel),
+                                                   widget);
+}
+
 /**
  * gtk_widget_map:
  * @widget: a #GtkWidget
@@ -4397,6 +4410,8 @@ gtk_widget_map (GtkWidget *widget)
 
       g_signal_emit (widget, widget_signals[MAP], 0);
 
+      update_cursor_on_state_change (widget);
+
       if (!_gtk_widget_get_has_window (widget))
         gtk_widget_queue_draw (widget);
 
@@ -4427,6 +4442,8 @@ gtk_widget_unmap (GtkWidget *widget)
 
       g_signal_emit (widget, widget_signals[UNMAP], 0);
 
+      update_cursor_on_state_change (widget);
+
       gtk_widget_pop_verify_invariants (widget);
       g_object_unref (widget);
     }
@@ -8331,6 +8348,7 @@ gtk_widget_set_sensitive (GtkWidget *widget,
         }
 
       gtk_widget_propagate_state (widget, &data);
+      update_cursor_on_state_change (widget);
     }
 
   g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_SENSITIVE]);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index fe08715..26ea1a0 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -11458,3 +11458,31 @@ gtk_window_update_pointer_focus (GtkWindow        *window,
       gtk_window_add_pointer_focus (window, focus);
     }
 }
+
+void
+gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
+                                                 GtkWidget *widget)
+{
+  GList *l = window->priv->foci, *cur;
+
+  while (l)
+    {
+      GtkPointerFocus *focus = l->data;
+
+      cur = l;
+      focus = cur->data;
+      l = cur->next;
+
+      if (GTK_WIDGET (focus->toplevel) == widget)
+        {
+          /* Unmapping the toplevel, remove pointer focus */
+          gtk_window_remove_pointer_focus (window, focus);
+          gtk_pointer_focus_free (focus);
+        }
+      else if (focus->target == widget ||
+               gtk_widget_is_ancestor (focus->target, widget))
+        {
+          gtk_pointer_focus_repick_target (focus);
+        }
+    }
+}
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index b8485c7..7f62cc7 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -154,6 +154,9 @@ void             gtk_window_update_pointer_focus (GtkWindow        *window,
                                                   gdouble           x,
                                                   gdouble           y);
 
+void             gtk_window_update_pointer_focus_on_state_change (GtkWindow *window,
+                                                                  GtkWidget *widget);
+
 G_END_DECLS
 
 #endif /* __GTK_WINDOW_PRIVATE_H__ */


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