wayland: Move MetaWindow ownership to window owning roles

There are two surface roles owning a MetaWindow: MetaWaylandShellSurface
(basis of MetaWaylandXdgToplevel, MetaWaylandXdgPopup,
MetaWaylandWlShellSurface, etc), and MetaXwaylandSurface.

With these two role types, the MetaWindow has two different types of
life times. With MetaWaylandShellSurface, the window is owned and
managed by the role itself, while with MetaXwaylandSurface, the
MetaWindow is tied to the X11 window, while the Wayland surface and its
role plays more the role of the backing rendering surface.

Before, for historical reasons, MetaWindow was part of
MetaWaylandSurface, even though just some roles used it, and before
'wayland: Untie MetaWindowXwayland lifetime from the wl_surface' had
equivalent life times as well. But since that commit, the management
changed. To not have the same fied in MetaWaylandSurface being managed
in such drastically different ways, rearrange it so that the roles that
has a MetaWindow themself manages it in the way it is meant to; meaning
MetaWaylandShellSurface practically owns it, while with Xwayland, the
existance of a MetaWindow is tracked via X11.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/835
This commit is contained in:
Jonas Ådahl
2019-10-09 09:57:40 +02:00
committed by Robert Mader
parent df642eb150
commit 44ae38599f
5 changed files with 265 additions and 127 deletions

View File

@ -24,6 +24,7 @@
#include "wayland/meta-wayland-shell-surface.h"
#include "compositor/meta-surface-actor-wayland.h"
#include "compositor/meta-window-actor-private.h"
#include "compositor/meta-window-actor-wayland.h"
#include "wayland/meta-wayland-actor-surface.h"
#include "wayland/meta-wayland-buffer.h"
@ -31,9 +32,18 @@
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-window-wayland.h"
G_DEFINE_ABSTRACT_TYPE (MetaWaylandShellSurface,
meta_wayland_shell_surface,
META_TYPE_WAYLAND_ACTOR_SURFACE)
typedef struct _MetaWaylandShellSurfacePrivate
{
MetaWindow *window;
gulong unmanaging_handler_id;
gulong position_changed_handler_id;
gulong effects_completed_handler_id;
} MetaWaylandShellSurfacePrivate;
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandShellSurface,
meta_wayland_shell_surface,
META_TYPE_WAYLAND_ACTOR_SURFACE)
void
meta_wayland_shell_surface_calculate_geometry (MetaWaylandShellSurface *shell_surface,
@ -81,16 +91,93 @@ meta_wayland_shell_surface_determine_geometry (MetaWaylandShellSurface *shell_su
*out_geometry = intersected_geometry;
}
void
meta_wayland_shell_surface_set_window (MetaWaylandShellSurface *shell_surface,
MetaWindow *window)
static void
clear_window (MetaWaylandShellSurface *shell_surface)
{
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (shell_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActor *surface_actor;
if (!priv->window)
return;
g_clear_signal_handler (&priv->unmanaging_handler_id,
priv->window);
g_clear_signal_handler (&priv->position_changed_handler_id,
priv->window);
g_clear_signal_handler (&priv->effects_completed_handler_id,
meta_window_actor_from_window (priv->window));
priv->window = NULL;
surface_actor = meta_wayland_surface_get_actor (surface);
if (surface_actor)
clutter_actor_set_reactive (CLUTTER_ACTOR (surface_actor), FALSE);
meta_wayland_surface_notify_unmapped (surface);
}
static void
window_unmanaging (MetaWindow *window,
MetaWaylandShellSurface *shell_surface)
{
clear_window (shell_surface);
}
static void
window_position_changed (MetaWindow *window,
MetaWaylandSurface *surface)
{
meta_wayland_surface_update_outputs_recursively (surface);
}
static void
window_actor_effects_completed (MetaWindowActor *window_actor,
MetaWaylandSurface *surface)
{
meta_wayland_surface_update_outputs_recursively (surface);
meta_wayland_compositor_repick (surface->compositor);
}
void
meta_wayland_shell_surface_set_window (MetaWaylandShellSurface *shell_surface,
MetaWindow *window)
{
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (shell_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActor *surface_actor;
g_assert (!priv->window);
priv->window = window;
surface_actor = meta_wayland_surface_get_actor (surface);
if (surface_actor)
clutter_actor_set_reactive (CLUTTER_ACTOR (surface_actor), TRUE);
priv->unmanaging_handler_id =
g_signal_connect (window,
"unmanaging",
G_CALLBACK (window_unmanaging),
shell_surface);
priv->position_changed_handler_id =
g_signal_connect (window,
"position-changed",
G_CALLBACK (window_position_changed),
surface);
priv->effects_completed_handler_id =
g_signal_connect (meta_window_actor_from_window (window),
"effects-completed",
G_CALLBACK (window_actor_effects_completed),
surface);
meta_wayland_surface_set_window (surface, window);
meta_window_update_monitor (window, META_WINDOW_UPDATE_MONITOR_FLAGS_NONE);
}
@ -150,21 +237,27 @@ static void
meta_wayland_shell_surface_surface_pre_apply_state (MetaWaylandSurfaceRole *surface_role,
MetaWaylandSurfaceState *pending)
{
MetaWaylandShellSurface *shell_surface =
META_WAYLAND_SHELL_SURFACE (surface_role);
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaWindow *window;
window = meta_wayland_surface_get_window (surface);
if (pending->newly_attached &&
!surface->buffer_ref.buffer &&
window)
meta_window_queue (window, META_QUEUE_CALC_SHOWING);
priv->window)
meta_window_queue (priv->window, META_QUEUE_CALC_SHOWING);
}
static void
meta_wayland_shell_surface_surface_apply_state (MetaWaylandSurfaceRole *surface_role,
MetaWaylandSurfaceState *pending)
{
MetaWaylandShellSurface *shell_surface =
META_WAYLAND_SHELL_SURFACE (surface_role);
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWaylandActorSurface *actor_surface =
META_WAYLAND_ACTOR_SURFACE (surface_role);
MetaWaylandSurface *surface =
@ -182,7 +275,7 @@ meta_wayland_shell_surface_surface_apply_state (MetaWaylandSurfaceRole *surface
if (!buffer)
return;
window = meta_wayland_surface_get_window (surface);
window = priv->window;
if (!window)
return;
@ -194,15 +287,28 @@ meta_wayland_shell_surface_surface_apply_state (MetaWaylandSurfaceRole *surface
meta_wayland_surface_get_height (surface) * geometry_scale;
}
static MetaWindow *
meta_wayland_shell_surface_get_window (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandShellSurface *shell_surface =
META_WAYLAND_SHELL_SURFACE (surface_role);
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
return priv->window;
}
static void
meta_wayland_shell_surface_notify_subsurface_state_changed (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandShellSurface *shell_surface =
META_WAYLAND_SHELL_SURFACE (surface_role);
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWindow *window;
MetaWindowActor *window_actor;
window = meta_wayland_surface_get_window (surface);
window = priv->window;
if (!window)
return;
@ -247,22 +353,20 @@ meta_wayland_shell_surface_sync_actor_state (MetaWaylandActorSurface *actor_surf
void
meta_wayland_shell_surface_destroy_window (MetaWaylandShellSurface *shell_surface)
{
MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (shell_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaWaylandShellSurfacePrivate *priv =
meta_wayland_shell_surface_get_instance_private (shell_surface);
MetaWindow *window;
MetaDisplay *display;
uint32_t timestamp;
window = meta_wayland_surface_get_window (surface);
window = priv->window;
if (!window)
return;
display = meta_window_get_display (window);
timestamp = meta_display_get_current_time_roundtrip (display);
meta_window_unmanage (window, timestamp);
g_assert (!meta_wayland_surface_get_window (surface));
g_assert (!priv->window);
}
static void
@ -298,6 +402,7 @@ meta_wayland_shell_surface_class_init (MetaWaylandShellSurfaceClass *klass)
meta_wayland_shell_surface_surface_apply_state;
surface_role_class->notify_subsurface_state_changed =
meta_wayland_shell_surface_notify_subsurface_state_changed;
surface_role_class->get_window = meta_wayland_shell_surface_get_window;
actor_surface_class->get_geometry_scale =
meta_wayland_shell_surface_get_geometry_scale;