[gtk/wip-kill-grabs] wip: Implement modality in gdk



commit 23f0cef7a66fc94b8d94b9a058010b3416092c58
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 26 19:44:48 2020 -0500

    wip: Implement modality in gdk
    
    Don't emit events on modal-shadowed surfaces.

 gdk/gdksurface.c        | 32 ++++++++++++++++++++++++++++++++
 gdk/gdksurfaceprivate.h |  1 +
 2 files changed, 33 insertions(+)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 8c9a23db10..f46ba84316 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -1816,6 +1816,21 @@ _gdk_surface_update_viewable (GdkSurface *surface)
   return set_viewable (surface, GDK_SURFACE_IS_MAPPED (surface));
 }
 
+static void
+propagate_modal (GdkSurface *surface,
+                 gboolean    modal)
+{
+  GdkSurface *parent = surface->transient_for;
+
+  modal = modal && GDK_SURFACE_IS_MAPPED (surface);
+
+  if (parent)
+    {
+      parent->modal_shadowed = modal;
+      propagate_modal (parent, modal || parent->modal_hint);
+    }
+}
+
 static void
 gdk_surface_show_internal (GdkSurface *surface, gboolean raise)
 {
@@ -1843,6 +1858,8 @@ gdk_surface_show_internal (GdkSurface *surface, gboolean raise)
     {
       if (gdk_surface_is_viewable (surface))
         gdk_surface_invalidate_rect (surface, NULL);
+
+      propagate_modal (surface, surface->modal_hint);
     }
 }
 
@@ -2006,6 +2023,9 @@ gdk_surface_hide (GdkSurface *surface)
 
   was_mapped = GDK_SURFACE_IS_MAPPED (surface);
 
+  if (surface->modal_hint)
+    propagate_modal (surface, FALSE);
+
   if (GDK_SURFACE_IS_MAPPED (surface))
     gdk_synthesize_surface_state (surface, 0, GDK_SURFACE_STATE_WITHDRAWN);
 
@@ -2862,7 +2882,11 @@ void
 gdk_surface_set_modal_hint (GdkSurface *surface,
                             gboolean   modal)
 {
+  surface->modal_hint = modal;
+
   GDK_SURFACE_GET_CLASS (surface)->set_modal_hint (surface, modal);
+
+  propagate_modal (surface, modal);
 }
 
 /**
@@ -2955,6 +2979,8 @@ gdk_surface_set_transient_for (GdkSurface *surface,
   surface->transient_for = parent;
 
   GDK_SURFACE_GET_CLASS (surface)->set_transient_for (surface, parent);
+
+  propagate_modal (surface, surface->modal_hint);
 }
 
 /**
@@ -4117,6 +4143,12 @@ gdk_surface_handle_event (GdkEvent *event)
 {
   gint64 begin_time = g_get_monotonic_time ();
   gboolean handled = FALSE;
+  GdkSurface *surface;
+
+  surface = gdk_event_get_surface (event);
+
+  if (surface->modal_shadowed)
+    return TRUE;
 
   if (check_autohide (event))
     return TRUE;
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index e1e1f3687c..9c2e0dddce 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -72,6 +72,7 @@ struct _GdkSurface
   guint in_update : 1;
   guint frame_clock_events_paused : 1;
   guint autohide : 1;
+  guint modal_shadowed : 1;
 
   struct {
     GdkGravity surface_anchor;


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