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
This commit is contained in:
Jonas Ådahl
2019-07-26 15:03:36 +02:00
parent d02c124e1d
commit 132fbf49d7
3 changed files with 28 additions and 73 deletions

View File

@ -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"
@ -511,16 +512,22 @@ meta_wayland_xdg_popup_unmap (MetaWaylandXdgPopup *xdg_popup)
meta_wayland_shell_surface_destroy_window (shell_surface);
}
static void
dismiss_popup (MetaWaylandXdgPopup *xdg_popup)
{
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));
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->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;