Commit 554644f9 authored by Jonas Ådahl's avatar Jonas Ådahl

wayland: Rework asynchronous window configuration

This changes how asynchronous window configuration works. Prior to this
commit, it worked by MetaWindowWayland remembering the last
configuration it sent, then when the Wayland client got back to it, it
tried to figure out whether it was a acknowledgment of the configuration
or not, and finish the move. This failed if the client had acknowledged
a configuration older than the last one sent, and it had hacks to
somewhat deal with wl_shell's lack of configuration serial numbers.

This commits scraps that and makes the MetaWindowWayland take ownership
of sent configurations, including generating serial numbers. The
wl_shell implementation is changed to emulate serial numbers (assuming
each commit acknowledges the last sent configure event). Each
configuration sent to the client is kept around until the client one. At
this point, the position used for that particular configuration is used
when applying the acknowledged state, meaning cases where we have
already sent a new configuration when the client acknowledges a previous
one, we'll still use the correct position for the window.

!907
parent cc444d49
......@@ -565,6 +565,8 @@ if have_wayland
'wayland/meta-wayland-versions.h',
'wayland/meta-wayland-viewporter.c',
'wayland/meta-wayland-viewporter.h',
'wayland/meta-wayland-window-configuration.c',
'wayland/meta-wayland-window-configuration.h',
'wayland/meta-wayland-wl-shell.c',
'wayland/meta-wayland-wl-shell.h',
'wayland/meta-wayland-xdg-foreign.c',
......
......@@ -34,6 +34,7 @@
#include "wayland/meta-wayland-shell-surface.h"
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-wayland-versions.h"
#include "wayland/meta-wayland-window-configuration.h"
#include "wayland/meta-wayland.h"
#include "wayland/meta-window-wayland.h"
......@@ -77,7 +78,6 @@ typedef struct _MetaWaylandZxdgSurfaceV6Private
{
struct wl_resource *resource;
MetaWaylandZxdgShellV6Client *shell_client;
MetaWaylandSerial acked_configure_serial;
MetaRectangle geometry;
guint configure_sent : 1;
......@@ -143,8 +143,9 @@ meta_wayland_zxdg_surface_v6_get_shell_resource (MetaWaylandZxdgSurfaceV6 *xdg_s
static MetaRectangle
meta_wayland_zxdg_surface_v6_get_window_geometry (MetaWaylandZxdgSurfaceV6 *xdg_surface);
static uint32_t
meta_wayland_zxdg_surface_v6_send_configure (MetaWaylandZxdgSurfaceV6 *xdg_surface);
static void
meta_wayland_zxdg_surface_v6_send_configure (MetaWaylandZxdgSurfaceV6 *xdg_surface,
MetaWaylandWindowConfiguration *configuration);
static MetaWaylandSurface *
surface_from_xdg_surface_resource (struct wl_resource *resource)
......@@ -590,10 +591,8 @@ fill_states (struct wl_array *states,
}
static void
meta_wayland_zxdg_toplevel_v6_send_configure (MetaWaylandZxdgToplevelV6 *xdg_toplevel,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_zxdg_toplevel_v6_send_configure (MetaWaylandZxdgToplevelV6 *xdg_toplevel,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandZxdgSurfaceV6 *xdg_surface =
META_WAYLAND_ZXDG_SURFACE_V6 (xdg_toplevel);
......@@ -602,23 +601,17 @@ meta_wayland_zxdg_toplevel_v6_send_configure (MetaWaylandZxdgToplevelV6 *xdg_top
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
struct wl_array states;
uint32_t serial;
wl_array_init (&states);
fill_states (&states, surface->window);
zxdg_toplevel_v6_send_configure (xdg_toplevel->resource,
new_width, new_height,
configuration->width,
configuration->height,
&states);
wl_array_release (&states);
serial = meta_wayland_zxdg_surface_v6_send_configure (xdg_surface);
if (sent_serial)
{
sent_serial->set = TRUE;
sent_serial->value = serial;
}
meta_wayland_zxdg_surface_v6_send_configure (xdg_surface, configuration);
}
static gboolean
......@@ -684,7 +677,12 @@ meta_wayland_zxdg_toplevel_v6_commit (MetaWaylandSurfaceRole *surface_role,
if (!xdg_surface_priv->configure_sent)
{
meta_wayland_zxdg_toplevel_v6_send_configure (xdg_toplevel, 0, 0, NULL);
MetaWaylandWindowConfiguration *configuration;
configuration = meta_wayland_window_configuration_new_empty ();
meta_wayland_zxdg_toplevel_v6_send_configure (xdg_toplevel,
configuration);
meta_wayland_window_configuration_free (configuration);
return;
}
......@@ -697,18 +695,13 @@ meta_wayland_zxdg_toplevel_v6_commit (MetaWaylandSurfaceRole *surface_role,
geometry_changed = !meta_rectangle_equal (&old_geometry, &xdg_surface_priv->geometry);
if (geometry_changed || meta_window_wayland_has_pending_move_resize (window))
if (geometry_changed || pending->has_acked_configure_serial)
{
MetaRectangle window_geometry;
MetaWaylandSerial *acked_configure_serial;
window_geometry =
meta_wayland_zxdg_surface_v6_get_window_geometry (xdg_surface);
acked_configure_serial = &xdg_surface_priv->acked_configure_serial;
meta_window_wayland_finish_move_resize (window,
acked_configure_serial,
window_geometry,
pending->dx, pending->dy);
meta_window_wayland_finish_move_resize (window, window_geometry, pending);
}
else if (pending->dx != 0 || pending->dy != 0)
{
......@@ -741,8 +734,6 @@ meta_wayland_zxdg_toplevel_v6_commit (MetaWaylandSurfaceRole *surface_role,
}
}
xdg_surface_priv->acked_configure_serial.set = FALSE;
}
static MetaWaylandSurface *
......@@ -752,12 +743,8 @@ meta_wayland_zxdg_toplevel_v6_get_toplevel (MetaWaylandSurfaceRole *surface_role
}
static void
meta_wayland_zxdg_toplevel_v6_configure (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_zxdg_toplevel_v6_configure (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandZxdgToplevelV6 *xdg_toplevel =
META_WAYLAND_ZXDG_TOPLEVEL_V6 (shell_surface);
......@@ -772,9 +759,7 @@ meta_wayland_zxdg_toplevel_v6_configure (MetaWaylandShellSurface *shell_surface,
if (!xdg_toplevel->resource)
return;
meta_wayland_zxdg_toplevel_v6_send_configure (xdg_toplevel,
new_width, new_height,
sent_serial);
meta_wayland_zxdg_toplevel_v6_send_configure (xdg_toplevel, configuration);
}
static void
......@@ -979,7 +964,6 @@ meta_wayland_zxdg_popup_v6_commit (MetaWaylandSurfaceRole *surface_role,
MetaWaylandSurfaceRoleClass *surface_role_class;
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaRectangle window_geometry;
if (xdg_popup->setup.parent_surface)
finish_popup_setup (xdg_popup);
......@@ -998,12 +982,16 @@ meta_wayland_zxdg_popup_v6_commit (MetaWaylandSurfaceRole *surface_role,
if (!surface->buffer_ref.buffer)
return;
window_geometry =
meta_wayland_zxdg_surface_v6_get_window_geometry (xdg_surface);
meta_window_wayland_finish_move_resize (surface->window,
NULL,
window_geometry,
pending->dx, pending->dy);
if (pending->has_acked_configure_serial)
{
MetaRectangle window_geometry;
window_geometry =
meta_wayland_zxdg_surface_v6_get_window_geometry (xdg_surface);
meta_window_wayland_finish_move_resize (surface->window,
window_geometry,
pending);
}
}
static MetaWaylandSurface *
......@@ -1018,12 +1006,8 @@ meta_wayland_zxdg_popup_v6_get_toplevel (MetaWaylandSurfaceRole *surface_role)
}
static void
meta_wayland_zxdg_popup_v6_configure (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_zxdg_popup_v6_configure (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandZxdgPopupV6 *xdg_popup =
META_WAYLAND_ZXDG_POPUP_V6 (shell_surface);
......@@ -1045,11 +1029,13 @@ meta_wayland_zxdg_popup_v6_configure (MetaWaylandShellSurface *shell_surface,
return;
geometry_scale = meta_window_wayland_get_geometry_scale (parent_window);
x = (new_x - parent_window->rect.x) / geometry_scale;
y = (new_y - parent_window->rect.y) / geometry_scale;
x = (configuration->x - parent_window->rect.x) / geometry_scale;
y = (configuration->y - parent_window->rect.y) / geometry_scale;
zxdg_popup_v6_send_configure (xdg_popup->resource,
x, y, new_width, new_height);
meta_wayland_zxdg_surface_v6_send_configure (xdg_surface);
x, y,
configuration->width, configuration->height);
meta_wayland_zxdg_surface_v6_send_configure (xdg_surface, configuration);
}
static void
......@@ -1208,21 +1194,16 @@ meta_wayland_zxdg_surface_v6_is_assigned (MetaWaylandZxdgSurfaceV6 *xdg_surface)
return priv->resource != NULL;
}
static uint32_t
meta_wayland_zxdg_surface_v6_send_configure (MetaWaylandZxdgSurfaceV6 *xdg_surface)
static void
meta_wayland_zxdg_surface_v6_send_configure (MetaWaylandZxdgSurfaceV6 *xdg_surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandZxdgSurfaceV6Private *priv =
meta_wayland_zxdg_surface_v6_get_instance_private (xdg_surface);
struct wl_display *display;
uint32_t serial;
display = wl_client_get_display (wl_resource_get_client (priv->resource));
serial = wl_display_next_serial (display);
zxdg_surface_v6_send_configure (priv->resource, serial);
zxdg_surface_v6_send_configure (priv->resource, configuration->serial);
priv->configure_sent = TRUE;
return serial;
}
static void
......@@ -1307,12 +1288,12 @@ zxdg_surface_v6_ack_configure (struct wl_client *client,
struct wl_resource *resource,
uint32_t serial)
{
MetaWaylandZxdgSurfaceV6 *xdg_surface = wl_resource_get_user_data (resource);
MetaWaylandZxdgSurfaceV6Private *priv =
meta_wayland_zxdg_surface_v6_get_instance_private (xdg_surface);
MetaWaylandSurface *surface = surface_from_xdg_surface_resource (resource);
MetaWaylandSurfaceState *pending;
priv->acked_configure_serial.set = TRUE;
priv->acked_configure_serial.value = serial;
pending = meta_wayland_surface_get_pending_state (surface);
pending->has_acked_configure_serial = TRUE;
pending->acked_configure_serial = serial;
}
static const struct zxdg_surface_v6_interface meta_wayland_zxdg_surface_v6_interface = {
......
......@@ -100,22 +100,13 @@ meta_wayland_shell_surface_set_window (MetaWaylandShellSurface *shell_surface,
}
void
meta_wayland_shell_surface_configure (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_shell_surface_configure (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandShellSurfaceClass *shell_surface_class =
META_WAYLAND_SHELL_SURFACE_GET_CLASS (shell_surface);
shell_surface_class->configure (shell_surface,
new_x,
new_y,
new_width,
new_height,
sent_serial);
shell_surface_class->configure (shell_surface, configuration);
}
void
......
......@@ -33,12 +33,8 @@ struct _MetaWaylandShellSurfaceClass
{
MetaWaylandActorSurfaceClass parent_class;
void (*configure) (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial);
void (*configure) (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration);
void (*managed) (MetaWaylandShellSurface *shell_surface,
MetaWindow *window);
void (*ping) (MetaWaylandShellSurface *shell_surface,
......@@ -46,12 +42,8 @@ struct _MetaWaylandShellSurfaceClass
void (*close) (MetaWaylandShellSurface *shell_surface);
};
void meta_wayland_shell_surface_configure (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial);
void meta_wayland_shell_surface_configure (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration);
void meta_wayland_shell_surface_ping (MetaWaylandShellSurface *shell_surface,
uint32_t serial);
......
......@@ -426,6 +426,7 @@ meta_wayland_surface_state_set_default (MetaWaylandSurfaceState *state)
wl_list_init (&state->frame_callback_list);
state->has_new_geometry = FALSE;
state->has_acked_configure_serial = FALSE;
state->has_new_min_size = FALSE;
state->has_new_max_size = FALSE;
......@@ -511,6 +512,12 @@ meta_wayland_surface_state_merge_into (MetaWaylandSurfaceState *from,
to->has_new_geometry = TRUE;
}
if (from->has_acked_configure_serial)
{
to->acked_configure_serial = from->acked_configure_serial;
to->has_acked_configure_serial = TRUE;
}
if (from->has_new_min_size)
{
to->new_min_width = from->new_min_width;
......@@ -1501,22 +1508,15 @@ meta_wayland_shell_init (MetaWaylandCompositor *compositor)
}
void
meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandShellSurface *shell_surface =
META_WAYLAND_SHELL_SURFACE (surface->role);
g_signal_emit (surface, surface_signals[SURFACE_CONFIGURE], 0);
meta_wayland_shell_surface_configure (shell_surface,
new_x, new_y,
new_width, new_height,
sent_serial);
meta_wayland_shell_surface_configure (shell_surface, configuration);
}
void
......
......@@ -64,11 +64,6 @@ struct _MetaWaylandSurfaceRoleClass
gboolean (*should_cache_state) (MetaWaylandSurfaceRole *surface_role);
};
struct _MetaWaylandSerial {
gboolean set;
uint32_t value;
};
struct _MetaWaylandSurfaceState
{
GObject parent;
......@@ -98,6 +93,9 @@ struct _MetaWaylandSurfaceState
MetaRectangle new_geometry;
gboolean has_new_geometry;
gboolean has_acked_configure_serial;
uint32_t acked_configure_serial;
/* pending min/max size in window geometry coordinates */
gboolean has_new_min_size;
int new_min_width;
......@@ -254,12 +252,8 @@ void meta_wayland_surface_unref_buffer_use_count (MetaWaylandSurf
void meta_wayland_surface_set_window (MetaWaylandSurface *surface,
MetaWindow *window);
void meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
int new_x,
int new_y,
int width,
int height,
MetaWaylandSerial *sent_serial);
void meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
MetaWaylandWindowConfiguration *configuration);
void meta_wayland_surface_ping (MetaWaylandSurface *surface,
guint32 serial);
......
......@@ -51,10 +51,11 @@ typedef struct _MetaWaylandBuffer MetaWaylandBuffer;
typedef struct _MetaWaylandRegion MetaWaylandRegion;
typedef struct _MetaWaylandSurface MetaWaylandSurface;
typedef struct _MetaWaylandSurfaceState MetaWaylandSurfaceState;
typedef struct _MetaWaylandOutput MetaWaylandOutput;
typedef struct _MetaWaylandSerial MetaWaylandSerial;
typedef struct _MetaWaylandWindowConfiguration MetaWaylandWindowConfiguration;
typedef struct _MetaWaylandPointerClient MetaWaylandPointerClient;
......
/*
* Copyright (C) 2019 Red Hat
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
*/
#include "config.h"
#include "wayland/meta-wayland-window-configuration.h"
static uint32_t global_serial_counter = 0;
MetaWaylandWindowConfiguration *
meta_wayland_window_configuration_new (int x,
int y,
int width,
int height)
{
MetaWaylandWindowConfiguration *configuration;
configuration = g_new0 (MetaWaylandWindowConfiguration, 1);
*configuration = (MetaWaylandWindowConfiguration) {
.serial = ++global_serial_counter,
.has_position = TRUE,
.x = x,
.y = y,
.has_size = TRUE,
.width = width,
.height = height,
};
return configuration;
}
MetaWaylandWindowConfiguration *
meta_wayland_window_configuration_new_empty (void)
{
MetaWaylandWindowConfiguration *configuration;
configuration = g_new0 (MetaWaylandWindowConfiguration, 1);
*configuration = (MetaWaylandWindowConfiguration) {
.serial = ++global_serial_counter,
};
return configuration;
}
void
meta_wayland_window_configuration_free (MetaWaylandWindowConfiguration *configuration)
{
g_free (configuration);
}
/*
* Copyright (C) 2019 Red Hat
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
*/
#ifndef META_WAYLAND_WINDOW_CONFIGURATION_H
#define META_WAYLAND_WINDOW_CONFIGURATION_H
#include <glib.h>
#include <stdint.h>
#include "wayland/meta-wayland-types.h"
struct _MetaWaylandWindowConfiguration
{
uint32_t serial;
gboolean has_position;
int x;
int y;
gboolean has_size;
int width;
int height;
};
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new (int x,
int y,
int width,
int height);
MetaWaylandWindowConfiguration * meta_wayland_window_configuration_new_empty (void);
void meta_wayland_window_configuration_free (MetaWaylandWindowConfiguration *configuration);
#endif /* META_WAYLAND_WINDOW_CONFIGURATION_H */
......@@ -32,6 +32,7 @@
#include "wayland/meta-wayland-shell-surface.h"
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-wayland-versions.h"
#include "wayland/meta-wayland-window-configuration.h"
#include "wayland/meta-wayland.h"
#include "wayland/meta-window-wayland.h"
......@@ -65,6 +66,8 @@ struct _MetaWaylandWlShellSurface
int x;
int y;
uint32_t emulated_ack_configure_serial;
};
static void
......@@ -613,9 +616,11 @@ wl_shell_surface_role_commit (MetaWaylandSurfaceRole *surface_role,
meta_wayland_shell_surface_calculate_geometry (shell_surface, &geom);
}
meta_window_wayland_finish_move_resize (window,
NULL,
geom, pending->dx, pending->dy);
pending->has_acked_configure_serial = TRUE;
pending->acked_configure_serial =
wl_shell_surface->emulated_ack_configure_serial;
meta_window_wayland_finish_move_resize (window, geom, pending);
}
static MetaWaylandSurface *
......@@ -632,12 +637,8 @@ wl_shell_surface_role_get_toplevel (MetaWaylandSurfaceRole *surface_role)
}
static void
wl_shell_surface_role_configure (MetaWaylandShellSurface *shell_surface,
int new_x,
int new_y,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
wl_shell_surface_role_configure (MetaWaylandShellSurface *shell_surface,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandWlShellSurface *wl_shell_surface =
META_WAYLAND_WL_SHELL_SURFACE (shell_surface);
......@@ -647,7 +648,9 @@ wl_shell_surface_role_configure (MetaWaylandShellSurface *shell_surface,
wl_shell_surface_send_configure (wl_shell_surface->resource,
0,
new_width, new_height);
configuration->width, configuration->height);
wl_shell_surface->emulated_ack_configure_serial = configuration->serial;
}
static void
......
......@@ -34,6 +34,7 @@
#include "wayland/meta-wayland-shell-surface.h"
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-wayland-versions.h"
#include "wayland/meta-wayland-window-configuration.h"
#include "wayland/meta-wayland.h"
#include "wayland/meta-window-wayland.h"
......@@ -77,7 +78,6 @@ typedef struct _MetaWaylandXdgSurfacePrivate
{
struct wl_resource *resource;
MetaWaylandXdgShellClient *shell_client;
MetaWaylandSerial acked_configure_serial;
MetaRectangle geometry;
guint configure_sent : 1;
......@@ -145,8 +145,9 @@ meta_wayland_xdg_surface_get_wm_base_resource (MetaWaylandXdgSurface *xdg_surfac
static MetaRectangle
meta_wayland_xdg_surface_get_window_geometry (MetaWaylandXdgSurface *xdg_surface);
static uint32_t
meta_wayland_xdg_surface_send_configure (MetaWaylandXdgSurface *xdg_surface);
static void
meta_wayland_xdg_surface_send_configure (MetaWaylandXdgSurface *xdg_surface,
MetaWaylandWindowConfiguration *configuration);
static MetaWaylandSurface *
surface_from_xdg_surface_resource (struct wl_resource *resource)
......@@ -622,30 +623,22 @@ fill_states (MetaWaylandXdgToplevel *xdg_toplevel,
}
static void
meta_wayland_xdg_toplevel_send_configure (MetaWaylandXdgToplevel *xdg_toplevel,
int new_width,
int new_height,
MetaWaylandSerial *sent_serial)
meta_wayland_xdg_toplevel_send_configure (MetaWaylandXdgToplevel *xdg_toplevel,
MetaWaylandWindowConfiguration *configuration)
{
MetaWaylandXdgSurface *xdg_surface = META_WAYLAND_XDG_SURFACE (xdg_toplevel);
struct wl_array states;
uint32_t serial;
wl_array_init (&states);
fill_states (xdg_toplevel, &states);
xdg_toplevel_send_configure (xdg_toplevel->resource,
new_width, new_height,
configuration->width,
configuration->height,
&states);
wl_array_release (&states);
serial = meta_wayland_xdg_surface_send_configure (xdg_surface);
if (sent_serial)
{
sent_serial->set = TRUE;
sent_serial->value = serial;
}
meta_wayland_xdg_surface_send_configure (xdg_surface, configuration);
}