[mutter] wayland: Let MetaWaylandXdgPopup dismiss incorrectly placed popups



commit 132fbf49d7ac349df0e6e8b762367daf7f2524d0
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Jul 26 15:03:36 2019 +0200

    wayland: Let MetaWaylandXdgPopup dismiss incorrectly placed popups
    
    It's a xdg_popup detail, and not until the actual position is finalized
    is the actual correctness known.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/907

 src/core/constraints.c               | 41 ++----------------------------------
 src/core/window.c                    | 26 -----------------------
 src/wayland/meta-wayland-xdg-shell.c | 34 +++++++++++++++++++++++-------
 3 files changed, 28 insertions(+), 73 deletions(-)
---
diff --git a/src/core/constraints.c b/src/core/constraints.c
index 1b3676d20..89e70f3a8 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -145,8 +145,6 @@ typedef struct
    */
   GList  *usable_screen_region;
   GList  *usable_monitor_region;
-
-  gboolean should_unmanage;
 } ConstraintInfo;
 
 static gboolean do_screen_and_monitor_relative_constraints (MetaWindow     *window,
@@ -255,14 +253,6 @@ do_all_constraints (MetaWindow         *window,
       satisfied = satisfied &&
                   (*constraint->func) (window, info, priority, check_only);
 
-      if (info->should_unmanage)
-        {
-          meta_topic (META_DEBUG_GEOMETRY,
-                      "constraint %s wants to unmanage window.\n",
-                      constraint->name);
-          return TRUE;
-        }
-
       if (!check_only)
         {
           /* Log how the constraint modified the position */
@@ -322,12 +312,6 @@ meta_window_constrain (MetaWindow          *window,
      */
     satisfied = do_all_constraints (window, &info, priority, check_only);
 
-    if (info.should_unmanage)
-      {
-        meta_window_unmanage_on_idle (window);
-        return;
-      }
-
     /* Drop the least important constraints if we can't satisfy them all */
     priority++;
   }
@@ -439,8 +423,6 @@ setup_constraint_info (ConstraintInfo      *info,
   info->usable_monitor_region =
     meta_workspace_get_onmonitor_region (cur_workspace, logical_monitor);
 
-  info->should_unmanage = FALSE;
-
   /* Log all this information for debugging */
   meta_topic (META_DEBUG_GEOMETRY,
               "Setting up constraint info:\n"
@@ -855,27 +837,8 @@ constrain_custom_rule (MetaWindow         *window,
   switch (window->placement_state)
     {
     case META_PLACEMENT_STATE_CONSTRAINED:
-      {
-        MetaRectangle parent_buffer_rect;
-
-        meta_window_get_buffer_rect (parent, &parent_buffer_rect);
-        if (!meta_rectangle_overlap (&adjusted_unconstrained,
-                                     &parent_buffer_rect) &&
-            !meta_rectangle_is_adjacent_to (&adjusted_unconstrained,
-                                            &parent_buffer_rect))
-          {
-            g_warning ("Buggy client caused popup to be placed outside of "
-                       "parent window");
-            info->should_unmanage = TRUE;
-            return TRUE;
-          }
-        else
-          {
-            info->current = adjusted_unconstrained;
-            goto done;
-          }
-        break;
-      }
+      info->current = adjusted_unconstrained;
+      goto done;
     case META_PLACEMENT_STATE_UNCONSTRAINED:
       break;
     }
diff --git a/src/core/window.c b/src/core/window.c
index faa1086a7..509c78409 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -1600,32 +1600,6 @@ meta_window_unmanage (MetaWindow  *window,
   g_object_unref (window);
 }
 
-static gboolean
-unmanage_window_idle_callback (gpointer user_data)
-{
-  MetaWindow *window = META_WINDOW (user_data);
-  uint32_t timestamp;
-
-  window->unmanage_idle_id = 0;
-
-  timestamp = meta_display_get_current_time_roundtrip (window->display);
-  meta_window_unmanage (window, timestamp);
-
-  return G_SOURCE_REMOVE;
-}
-
-void
-meta_window_unmanage_on_idle (MetaWindow *window)
-{
-  if (window->unmanage_idle_id)
-    return;
-
-  window->unmanage_idle_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE,
-                                              unmanage_window_idle_callback,
-                                              window,
-                                              NULL);
-}
-
 static void
 set_wm_state (MetaWindow *window)
 {
diff --git a/src/wayland/meta-wayland-xdg-shell.c b/src/wayland/meta-wayland-xdg-shell.c
index 0ab83f07d..4123a83c3 100644
--- a/src/wayland/meta-wayland-xdg-shell.c
+++ b/src/wayland/meta-wayland-xdg-shell.c
@@ -26,6 +26,7 @@
 #include "wayland/meta-wayland-xdg-shell.h"
 
 #include "backends/meta-logical-monitor.h"
+#include "core/boxes-private.h"
 #include "core/window-private.h"
 #include "wayland/meta-wayland-outputs.h"
 #include "wayland/meta-wayland-popup.h"
@@ -512,15 +513,21 @@ meta_wayland_xdg_popup_unmap (MetaWaylandXdgPopup *xdg_popup)
 }
 
 static void
-xdg_popup_destructor (struct wl_resource *resource)
+dismiss_popup (MetaWaylandXdgPopup *xdg_popup)
 {
-  MetaWaylandXdgPopup *xdg_popup =
-    META_WAYLAND_XDG_POPUP (wl_resource_get_user_data (resource));
-
   if (xdg_popup->popup)
     meta_wayland_popup_dismiss (xdg_popup->popup);
   else
     meta_wayland_xdg_popup_unmap (xdg_popup);
+}
+
+static void
+xdg_popup_destructor (struct wl_resource *resource)
+{
+  MetaWaylandXdgPopup *xdg_popup =
+    META_WAYLAND_XDG_POPUP (wl_resource_get_user_data (resource));
+
+  dismiss_popup (xdg_popup);
 
   xdg_popup->resource = NULL;
 }
@@ -1031,6 +1038,9 @@ meta_wayland_xdg_popup_apply_state (MetaWaylandSurfaceRole  *surface_role,
   MetaWaylandSurface *surface =
     meta_wayland_surface_role_get_surface (surface_role);
   MetaWindow *window;
+  MetaRectangle buffer_rect;
+  MetaWindow *parent_window;
+  MetaRectangle parent_buffer_rect;
 
   if (xdg_popup->setup.parent_surface)
     finish_popup_setup (xdg_popup);
@@ -1072,6 +1082,17 @@ meta_wayland_xdg_popup_apply_state (MetaWaylandSurfaceRole  *surface_role,
       window_geometry = meta_wayland_xdg_surface_get_window_geometry (xdg_surface);
       meta_window_wayland_finish_move_resize (window, window_geometry, pending);
     }
+
+  parent_window = xdg_popup->parent_surface->window;
+  meta_window_get_buffer_rect (window, &buffer_rect);
+  meta_window_get_buffer_rect (parent_window, &parent_buffer_rect);
+  if (!meta_rectangle_overlap (&buffer_rect, &parent_buffer_rect) &&
+      !meta_rectangle_is_adjacent_to (&buffer_rect, &parent_buffer_rect))
+    {
+      g_warning ("Buggy client caused popup to be placed outside of "
+                 "parent window");
+      dismiss_popup (xdg_popup);
+    }
 }
 
 static MetaWaylandSurface *
@@ -1092,10 +1113,7 @@ meta_wayland_xdg_popup_reset (MetaWaylandXdgSurface *xdg_surface)
   MetaWaylandXdgSurfaceClass *xdg_surface_class =
     META_WAYLAND_XDG_SURFACE_CLASS (meta_wayland_xdg_popup_parent_class);
 
-  if (xdg_popup->popup)
-    meta_wayland_popup_dismiss (xdg_popup->popup);
-  else
-    meta_wayland_xdg_popup_unmap (xdg_popup);
+  dismiss_popup (xdg_popup);
 
   xdg_popup->dismissed_by_client = TRUE;
 


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