2014-03-19 09:26:17 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 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.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Jasper St. Pierre <jstpierre@mecheye.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "wayland/meta-window-wayland.h"
|
2014-03-19 09:26:17 -04:00
|
|
|
|
2016-06-10 03:21:21 -04:00
|
|
|
#include <errno.h>
|
2018-07-10 04:36:24 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "backends/meta-backend-private.h"
|
2016-11-30 23:52:07 -05:00
|
|
|
#include "backends/meta-backend-private.h"
|
2016-12-12 21:37:11 -05:00
|
|
|
#include "backends/meta-logical-monitor.h"
|
2015-03-02 22:13:05 -05:00
|
|
|
#include "compositor/meta-surface-actor-wayland.h"
|
2018-07-10 04:36:24 -04:00
|
|
|
#include "core/boxes-private.h"
|
|
|
|
#include "core/stack-tracker.h"
|
|
|
|
#include "core/window-private.h"
|
|
|
|
#include "meta/meta-x11-errors.h"
|
|
|
|
#include "wayland/meta-wayland-actor-surface.h"
|
|
|
|
#include "wayland/meta-wayland-private.h"
|
|
|
|
#include "wayland/meta-wayland-surface.h"
|
|
|
|
#include "wayland/meta-wayland-xdg-shell.h"
|
2014-03-19 09:26:17 -04:00
|
|
|
|
|
|
|
struct _MetaWindowWayland
|
|
|
|
{
|
|
|
|
MetaWindow parent;
|
2014-04-28 16:19:06 -04:00
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
int geometry_scale;
|
|
|
|
|
wayland-surface: Don't do pending move/resizes on all commits
We assume in meta_window_wayland_move_resize that the next commit that
changes the geometry will always be for our next pending operation, so
if we have a move pending on a resize, the next commit will trigger the
move. This is, of course, fundamentally wrong.
We broke this assumption even more now that we don't fizzle out calls to
meta_window_move_resize_internal and now call it on every commit, which
means that a simple damage and then commit would complete a pending
move.
This was even broken by apps like weston-terminal, which, when clicking
on the maximize button, first redraws the terminal with the maximize
button state back on hover on press, and would only redraw when it got
the configure event with the coordinates.
To track the correct commit to apply the move for, we implement the
ack_configure request and ignore all move/resizes that happen before
that.
Right now, we actually fizzle out the entire move/resize if there's a
future pending configure we're waiting on.
2014-07-27 11:23:17 -04:00
|
|
|
MetaWaylandSerial pending_configure_serial;
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
gboolean has_pending_state_change;
|
2014-07-27 11:37:18 -04:00
|
|
|
gboolean has_pending_move;
|
|
|
|
int pending_move_x;
|
|
|
|
int pending_move_y;
|
2014-05-12 18:05:31 -04:00
|
|
|
|
2016-07-01 03:14:12 -04:00
|
|
|
int last_sent_x;
|
|
|
|
int last_sent_y;
|
2014-05-12 18:05:31 -04:00
|
|
|
int last_sent_width;
|
|
|
|
int last_sent_height;
|
2018-09-14 13:06:55 -04:00
|
|
|
|
|
|
|
gboolean has_been_shown;
|
2014-03-19 09:26:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaWindowWaylandClass
|
|
|
|
{
|
|
|
|
MetaWindowClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaWindowWayland, meta_window_wayland, META_TYPE_WINDOW)
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
static int
|
|
|
|
get_window_geometry_scale_for_logical_monitor (MetaLogicalMonitor *logical_monitor)
|
|
|
|
{
|
2017-10-16 05:02:51 -04:00
|
|
|
g_assert (logical_monitor);
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
if (meta_is_stage_views_scaled ())
|
|
|
|
return 1;
|
|
|
|
else
|
2017-05-25 04:12:51 -04:00
|
|
|
return meta_logical_monitor_get_scale (logical_monitor);
|
2017-02-24 05:10:52 -05:00
|
|
|
}
|
|
|
|
|
2014-03-19 09:36:15 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_manage (MetaWindow *window)
|
|
|
|
{
|
2017-02-24 05:10:52 -05:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
2014-03-19 09:36:15 -04:00
|
|
|
MetaDisplay *display = window->display;
|
|
|
|
|
2017-10-16 05:02:51 -04:00
|
|
|
wl_window->geometry_scale = meta_window_wayland_get_geometry_scale (window);
|
2017-02-24 05:10:52 -05:00
|
|
|
|
2014-03-19 09:36:15 -04:00
|
|
|
meta_display_register_wayland_window (display, window);
|
|
|
|
|
|
|
|
{
|
2017-08-26 13:03:51 -04:00
|
|
|
meta_stack_tracker_record_add (window->display->stack_tracker,
|
2014-09-08 21:20:14 -04:00
|
|
|
window->stamp,
|
2014-03-19 09:36:15 -04:00
|
|
|
0);
|
|
|
|
}
|
2015-02-24 14:55:45 -05:00
|
|
|
|
2015-12-15 09:09:20 -05:00
|
|
|
meta_wayland_surface_window_managed (window->surface, window);
|
2014-03-19 09:36:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_unmanage (MetaWindow *window)
|
|
|
|
{
|
|
|
|
{
|
2017-08-26 13:03:51 -04:00
|
|
|
meta_stack_tracker_record_remove (window->display->stack_tracker,
|
2014-09-08 21:20:14 -04:00
|
|
|
window->stamp,
|
2014-03-19 09:36:15 -04:00
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_display_unregister_wayland_window (window->display, window);
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:12:44 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_ping (MetaWindow *window,
|
|
|
|
guint32 serial)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_ping (window->surface, serial);
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:07:44 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_delete (MetaWindow *window,
|
|
|
|
guint32 timestamp)
|
|
|
|
{
|
|
|
|
meta_wayland_surface_delete (window->surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_kill (MetaWindow *window)
|
|
|
|
{
|
2014-03-25 12:05:21 -04:00
|
|
|
MetaWaylandSurface *surface = window->surface;
|
|
|
|
struct wl_resource *resource = surface->resource;
|
|
|
|
|
|
|
|
/* Send the client an unrecoverable error to kill the client. */
|
|
|
|
wl_resource_post_error (resource,
|
|
|
|
WL_DISPLAY_ERROR_NO_MEMORY,
|
|
|
|
"User requested that we kill you. Sorry. Don't take it too personally.");
|
2014-03-20 15:07:44 -04:00
|
|
|
}
|
|
|
|
|
2014-03-20 15:16:57 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_focus (MetaWindow *window,
|
|
|
|
guint32 timestamp)
|
|
|
|
{
|
2018-11-13 02:56:53 -05:00
|
|
|
if (meta_window_is_focusable (window))
|
2017-08-26 14:51:28 -04:00
|
|
|
meta_x11_display_set_input_focus_window (window->display->x11_display,
|
|
|
|
window,
|
|
|
|
FALSE,
|
|
|
|
timestamp);
|
2014-03-20 15:16:57 -04:00
|
|
|
}
|
|
|
|
|
2014-05-20 15:54:39 -04:00
|
|
|
static void
|
|
|
|
surface_state_changed (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
|
2016-03-17 09:52:46 -04:00
|
|
|
/* don't send notify when the window is being unmanaged */
|
|
|
|
if (window->unmanaging)
|
|
|
|
return;
|
|
|
|
|
2014-05-20 15:54:39 -04:00
|
|
|
meta_wayland_surface_configure_notify (window->surface,
|
2016-07-01 03:14:12 -04:00
|
|
|
wl_window->last_sent_x,
|
|
|
|
wl_window->last_sent_y,
|
2014-05-20 15:54:39 -04:00
|
|
|
wl_window->last_sent_width,
|
wayland-surface: Don't do pending move/resizes on all commits
We assume in meta_window_wayland_move_resize that the next commit that
changes the geometry will always be for our next pending operation, so
if we have a move pending on a resize, the next commit will trigger the
move. This is, of course, fundamentally wrong.
We broke this assumption even more now that we don't fizzle out calls to
meta_window_move_resize_internal and now call it on every commit, which
means that a simple damage and then commit would complete a pending
move.
This was even broken by apps like weston-terminal, which, when clicking
on the maximize button, first redraws the terminal with the maximize
button state back on hover on press, and would only redraw when it got
the configure event with the coordinates.
To track the correct commit to apply the move for, we implement the
ack_configure request and ignore all move/resizes that happen before
that.
Right now, we actually fizzle out the entire move/resize if there's a
future pending configure we're waiting on.
2014-07-27 11:23:17 -04:00
|
|
|
wl_window->last_sent_height,
|
|
|
|
&wl_window->pending_configure_serial);
|
2014-05-20 15:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_grab_op_began (MetaWindow *window,
|
|
|
|
MetaGrabOp op)
|
|
|
|
{
|
2014-07-17 15:53:38 -04:00
|
|
|
if (meta_grab_op_is_resizing (op))
|
|
|
|
surface_state_changed (window);
|
2014-05-20 15:54:39 -04:00
|
|
|
|
|
|
|
META_WINDOW_CLASS (meta_window_wayland_parent_class)->grab_op_began (window, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_grab_op_ended (MetaWindow *window,
|
|
|
|
MetaGrabOp op)
|
|
|
|
{
|
2014-07-17 15:53:38 -04:00
|
|
|
if (meta_grab_op_is_resizing (op))
|
|
|
|
surface_state_changed (window);
|
2014-05-20 15:54:39 -04:00
|
|
|
|
|
|
|
META_WINDOW_CLASS (meta_window_wayland_parent_class)->grab_op_ended (window, op);
|
|
|
|
}
|
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_move_resize_internal (MetaWindow *window,
|
|
|
|
int gravity,
|
2014-05-21 13:59:13 -04:00
|
|
|
MetaRectangle unconstrained_rect,
|
2014-03-19 10:30:12 -04:00
|
|
|
MetaRectangle constrained_rect,
|
|
|
|
MetaMoveResizeFlags flags,
|
|
|
|
MetaMoveResizeResultFlags *result)
|
|
|
|
{
|
2014-04-28 16:19:06 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
2014-07-27 11:47:40 -04:00
|
|
|
gboolean can_move_now;
|
2016-07-01 03:14:12 -04:00
|
|
|
int configured_x;
|
|
|
|
int configured_y;
|
2015-03-23 09:22:19 -04:00
|
|
|
int configured_width;
|
|
|
|
int configured_height;
|
2017-02-24 04:05:01 -05:00
|
|
|
int geometry_scale;
|
2014-04-16 16:28:43 -04:00
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
g_assert (window->frame == NULL);
|
|
|
|
|
2016-03-17 09:52:46 -04:00
|
|
|
/* don't do anything if we're dropping the window, see #751847 */
|
|
|
|
if (window->unmanaging)
|
|
|
|
return;
|
|
|
|
|
2016-07-01 03:14:12 -04:00
|
|
|
configured_x = constrained_rect.x;
|
|
|
|
configured_y = constrained_rect.y;
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
/* The scale the window is drawn in might change depending on what monitor it
|
|
|
|
* is mainly on. Scale the configured rectangle to be in logical pixel
|
|
|
|
* coordinate space so that we can have a scale independent size to pass
|
|
|
|
* to the Wayland surface. */
|
2017-02-24 04:05:01 -05:00
|
|
|
geometry_scale = meta_window_wayland_get_geometry_scale (window);
|
2017-06-21 05:33:18 -04:00
|
|
|
if (flags & META_MOVE_RESIZE_UNMAXIMIZE)
|
|
|
|
{
|
|
|
|
/* On un-maximize, let the client decide on its size */
|
|
|
|
configured_width = 0;
|
|
|
|
configured_height = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
configured_width = constrained_rect.width / geometry_scale;
|
|
|
|
configured_height = constrained_rect.height / geometry_scale;
|
|
|
|
}
|
2015-03-23 09:22:19 -04:00
|
|
|
|
2014-03-19 10:30:12 -04:00
|
|
|
/* For wayland clients, the size is completely determined by the client,
|
|
|
|
* and while this allows to avoid some trickery with frames and the resulting
|
|
|
|
* lagging, we also need to insist a bit when the constraints would apply
|
|
|
|
* a different size than the client decides.
|
|
|
|
*
|
|
|
|
* Note that this is not generally a problem for normal toplevel windows (the
|
|
|
|
* constraints don't see the size hints, or just change the position), but
|
|
|
|
* it can be for maximized or fullscreen.
|
|
|
|
*/
|
|
|
|
|
2017-06-21 07:30:22 -04:00
|
|
|
if (flags & META_MOVE_RESIZE_FORCE_MOVE)
|
|
|
|
{
|
|
|
|
can_move_now = TRUE;
|
|
|
|
}
|
|
|
|
else if (flags & META_MOVE_RESIZE_WAYLAND_RESIZE)
|
2014-03-19 10:30:12 -04:00
|
|
|
{
|
|
|
|
/* This is a call to wl_surface_commit(), ignore the constrained_rect and
|
|
|
|
* update the real client size to match the buffer size.
|
|
|
|
*/
|
|
|
|
|
2014-07-17 17:26:22 -04:00
|
|
|
if (window->rect.width != unconstrained_rect.width ||
|
|
|
|
window->rect.height != unconstrained_rect.height)
|
|
|
|
{
|
|
|
|
*result |= META_MOVE_RESIZE_RESULT_RESIZED;
|
|
|
|
window->rect.width = unconstrained_rect.width;
|
|
|
|
window->rect.height = unconstrained_rect.height;
|
|
|
|
}
|
|
|
|
|
2014-04-16 16:28:43 -04:00
|
|
|
/* This is a commit of an attach. We should move the window to match the
|
|
|
|
* new position the client wants. */
|
2014-07-27 11:47:40 -04:00
|
|
|
can_move_now = TRUE;
|
2014-03-19 10:30:12 -04:00
|
|
|
}
|
2014-07-27 12:30:33 -04:00
|
|
|
else
|
2014-03-19 10:30:12 -04:00
|
|
|
{
|
2014-12-15 16:44:22 -05:00
|
|
|
/* If the size changed, or the state changed, then we have to wait until
|
|
|
|
* the client acks our configure before moving the window. */
|
2014-07-27 12:30:33 -04:00
|
|
|
if (constrained_rect.width != window->rect.width ||
|
2014-12-15 16:44:22 -05:00
|
|
|
constrained_rect.height != window->rect.height ||
|
|
|
|
(flags & META_MOVE_RESIZE_STATE_CHANGED))
|
2014-07-27 12:30:33 -04:00
|
|
|
{
|
2015-03-16 21:39:57 -04:00
|
|
|
/* If the constrained size is 1x1 and the unconstrained size is 0x0
|
|
|
|
* it means that we are trying to resize a window where the client has
|
|
|
|
* not yet committed a buffer. The 1x1 constrained size is a result of
|
|
|
|
* how the constraints code works. Lets avoid trying to have the
|
|
|
|
* client configure itself to draw on a 1x1 surface.
|
|
|
|
*
|
|
|
|
* We cannot guard against only an empty unconstrained_rect here,
|
|
|
|
* because the client may have created a xdg surface without a buffer
|
|
|
|
* attached and asked it to be maximized. In such case we should let
|
|
|
|
* it know about the expected window geometry of a maximized window,
|
|
|
|
* even though there is currently no buffer attached. */
|
2014-09-17 11:36:31 -04:00
|
|
|
if (unconstrained_rect.width == 0 &&
|
2015-03-16 21:39:57 -04:00
|
|
|
unconstrained_rect.height == 0 &&
|
|
|
|
constrained_rect.width == 1 &&
|
|
|
|
constrained_rect.height == 1)
|
2014-09-17 11:36:31 -04:00
|
|
|
return;
|
|
|
|
|
2014-07-27 12:30:33 -04:00
|
|
|
meta_wayland_surface_configure_notify (window->surface,
|
2016-07-01 03:14:12 -04:00
|
|
|
configured_x,
|
|
|
|
configured_y,
|
2015-03-23 09:22:19 -04:00
|
|
|
configured_width,
|
|
|
|
configured_height,
|
2014-07-27 12:30:33 -04:00
|
|
|
&wl_window->pending_configure_serial);
|
2014-07-27 11:47:40 -04:00
|
|
|
|
2014-07-27 12:30:33 -04:00
|
|
|
/* We need to wait until the resize completes before we can move */
|
|
|
|
can_move_now = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We're just moving the window, so we don't need to wait for a configure
|
|
|
|
* and then ack to simply move the window. */
|
|
|
|
can_move_now = TRUE;
|
|
|
|
}
|
2014-04-16 16:28:43 -04:00
|
|
|
}
|
2014-03-19 10:30:12 -04:00
|
|
|
|
2016-07-01 03:14:12 -04:00
|
|
|
wl_window->last_sent_x = configured_x;
|
|
|
|
wl_window->last_sent_y = configured_y;
|
2015-03-23 09:22:19 -04:00
|
|
|
wl_window->last_sent_width = configured_width;
|
|
|
|
wl_window->last_sent_height = configured_height;
|
2014-09-16 21:11:56 -04:00
|
|
|
|
2014-07-27 11:47:40 -04:00
|
|
|
if (can_move_now)
|
2014-04-16 16:16:01 -04:00
|
|
|
{
|
2014-04-28 18:15:03 -04:00
|
|
|
int new_x = constrained_rect.x;
|
|
|
|
int new_y = constrained_rect.y;
|
2014-04-28 16:20:53 -04:00
|
|
|
|
2014-04-28 15:51:41 -04:00
|
|
|
if (new_x != window->rect.x || new_y != window->rect.y)
|
2014-04-28 15:50:40 -04:00
|
|
|
{
|
|
|
|
*result |= META_MOVE_RESIZE_RESULT_MOVED;
|
2014-06-26 11:02:57 -04:00
|
|
|
window->rect.x = new_x;
|
|
|
|
window->rect.y = new_y;
|
2014-07-07 13:06:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int new_buffer_x = new_x - window->custom_frame_extents.left;
|
|
|
|
int new_buffer_y = new_y - window->custom_frame_extents.top;
|
2014-06-26 11:02:57 -04:00
|
|
|
|
2014-07-07 13:06:47 -04:00
|
|
|
if (new_buffer_x != window->buffer_rect.x || new_buffer_y != window->buffer_rect.y)
|
|
|
|
{
|
|
|
|
*result |= META_MOVE_RESIZE_RESULT_MOVED;
|
2014-07-17 15:27:47 -04:00
|
|
|
window->buffer_rect.x = new_buffer_x;
|
|
|
|
window->buffer_rect.y = new_buffer_y;
|
2014-04-28 15:50:40 -04:00
|
|
|
}
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
|
|
|
|
if (flags & META_MOVE_RESIZE_WAYLAND_STATE_CHANGED)
|
|
|
|
*result |= META_MOVE_RESIZE_RESULT_STATE_CHANGED;
|
2014-03-19 10:30:12 -04:00
|
|
|
}
|
2014-07-27 11:47:40 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int new_x = constrained_rect.x;
|
|
|
|
int new_y = constrained_rect.y;
|
|
|
|
|
|
|
|
if (new_x != window->rect.x || new_y != window->rect.y)
|
|
|
|
{
|
|
|
|
wl_window->has_pending_move = TRUE;
|
|
|
|
wl_window->pending_move_x = new_x;
|
|
|
|
wl_window->pending_move_y = new_y;
|
|
|
|
}
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
|
|
|
|
wl_window->has_pending_state_change = (flags & META_MOVE_RESIZE_STATE_CHANGED) != 0;
|
2014-07-27 11:47:40 -04:00
|
|
|
}
|
2014-03-19 10:30:12 -04:00
|
|
|
}
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
static void
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (int *width,
|
|
|
|
int *height,
|
|
|
|
float scale)
|
2015-03-23 09:22:19 -04:00
|
|
|
{
|
2016-04-06 08:07:08 -04:00
|
|
|
if (*width < G_MAXINT)
|
|
|
|
{
|
|
|
|
float new_width = (*width * scale);
|
|
|
|
*width = (int) MIN (new_width, G_MAXINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*height < G_MAXINT)
|
|
|
|
{
|
|
|
|
float new_height = (*height * scale);
|
|
|
|
*height = (int) MIN (new_height, G_MAXINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scale_rect_size (MetaRectangle *rect,
|
|
|
|
float scale)
|
|
|
|
{
|
|
|
|
scale_size (&rect->width, &rect->height, scale);
|
2015-03-23 09:22:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-08-24 06:54:50 -04:00
|
|
|
meta_window_wayland_update_main_monitor (MetaWindow *window,
|
|
|
|
MetaWindowUpdateMonitorFlags flags)
|
2015-03-23 09:22:19 -04:00
|
|
|
{
|
2016-11-30 23:52:07 -05:00
|
|
|
MetaBackend *backend = meta_get_backend ();
|
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2016-09-23 05:15:56 -04:00
|
|
|
MetaWindow *toplevel_window;
|
2016-12-01 02:15:52 -05:00
|
|
|
MetaLogicalMonitor *from;
|
|
|
|
MetaLogicalMonitor *to;
|
|
|
|
MetaLogicalMonitor *scaled_new;
|
2017-05-25 04:12:51 -04:00
|
|
|
float from_scale, to_scale;
|
2015-03-23 09:22:19 -04:00
|
|
|
float scale;
|
|
|
|
MetaRectangle rect;
|
|
|
|
|
|
|
|
from = window->monitor;
|
2016-09-23 05:15:56 -04:00
|
|
|
|
|
|
|
/* If the window is not a toplevel window (i.e. it's a popup window) just use
|
|
|
|
* the monitor of the toplevel. */
|
|
|
|
toplevel_window = meta_wayland_surface_get_toplevel_window (window->surface);
|
|
|
|
if (toplevel_window != window)
|
|
|
|
{
|
2018-08-27 11:49:52 -04:00
|
|
|
meta_window_update_monitor (toplevel_window, flags);
|
2016-09-23 17:09:39 -04:00
|
|
|
window->monitor = toplevel_window->monitor;
|
|
|
|
return;
|
2016-09-23 05:15:56 -04:00
|
|
|
}
|
2015-03-23 09:22:19 -04:00
|
|
|
|
2016-09-23 17:09:39 -04:00
|
|
|
/* Require both the current and the new monitor would be the new main monitor,
|
|
|
|
* even given the resulting scale the window would end up having. This is
|
|
|
|
* needed to avoid jumping back and forth between the new and the old, since
|
|
|
|
* changing main monitor may cause the window to be resized so that it no
|
|
|
|
* longer have that same new main monitor. */
|
2016-12-01 00:01:39 -05:00
|
|
|
to = meta_window_calculate_main_logical_monitor (window);
|
2016-09-23 17:09:39 -04:00
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
if (from == to)
|
|
|
|
return;
|
|
|
|
|
2017-08-18 02:21:11 -04:00
|
|
|
if (from == NULL || to == NULL)
|
|
|
|
{
|
|
|
|
window->monitor = to;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-24 06:56:31 -04:00
|
|
|
if (flags & META_WINDOW_UPDATE_MONITOR_FLAGS_FORCE)
|
2018-06-18 06:39:11 -04:00
|
|
|
{
|
|
|
|
window->monitor = to;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-25 04:12:51 -04:00
|
|
|
from_scale = meta_logical_monitor_get_scale (from);
|
|
|
|
to_scale = meta_logical_monitor_get_scale (to);
|
|
|
|
|
2017-08-18 02:21:11 -04:00
|
|
|
if (from_scale == to_scale)
|
2015-03-23 09:22:19 -04:00
|
|
|
{
|
|
|
|
window->monitor = to;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
if (meta_is_stage_views_scaled ())
|
|
|
|
{
|
|
|
|
window->monitor = to;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
/* To avoid a window alternating between two main monitors because scaling
|
|
|
|
* changes the main monitor, wait until both the current and the new scale
|
|
|
|
* will result in the same main monitor. */
|
2017-05-25 04:12:51 -04:00
|
|
|
scale = to_scale / from_scale;
|
2015-03-23 09:22:19 -04:00
|
|
|
rect = window->rect;
|
|
|
|
scale_rect_size (&rect, scale);
|
2016-11-30 23:52:07 -05:00
|
|
|
scaled_new =
|
|
|
|
meta_monitor_manager_get_logical_monitor_from_rect (monitor_manager, &rect);
|
2015-03-23 09:22:19 -04:00
|
|
|
if (to != scaled_new)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->monitor = to;
|
|
|
|
}
|
|
|
|
|
2015-03-02 22:13:05 -05:00
|
|
|
static void
|
2016-11-25 01:31:38 -05:00
|
|
|
meta_window_wayland_main_monitor_changed (MetaWindow *window,
|
|
|
|
const MetaLogicalMonitor *old)
|
2015-03-02 22:13:05 -05:00
|
|
|
{
|
2017-02-24 05:10:52 -05:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
int old_geometry_scale = wl_window->geometry_scale;
|
|
|
|
int geometry_scale;
|
2015-03-23 09:22:19 -04:00
|
|
|
float scale_factor;
|
|
|
|
MetaWaylandSurface *surface;
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
if (!window->monitor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
geometry_scale = meta_window_wayland_get_geometry_scale (window);
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
/* This function makes sure that window geometry, window actor geometry and
|
|
|
|
* surface actor geometry gets set according the old and current main monitor
|
|
|
|
* scale. If there either is no past or current main monitor, or if the scale
|
|
|
|
* didn't change, there is nothing to do. */
|
|
|
|
if (old == NULL ||
|
|
|
|
window->monitor == NULL ||
|
2017-02-24 05:10:52 -05:00
|
|
|
old_geometry_scale == geometry_scale)
|
2015-03-23 09:22:19 -04:00
|
|
|
return;
|
2015-03-02 22:13:05 -05:00
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
/* MetaWindow keeps its rectangles in the physical pixel coordinate space.
|
|
|
|
* When the main monitor of a window changes, it can cause the corresponding
|
|
|
|
* window surfaces to be scaled given the monitor scale, so we need to scale
|
|
|
|
* the rectangles in MetaWindow accordingly. */
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
scale_factor = (float) geometry_scale / old_geometry_scale;
|
2015-03-23 09:22:19 -04:00
|
|
|
|
|
|
|
/* Window size. */
|
|
|
|
scale_rect_size (&window->rect, scale_factor);
|
2015-09-16 02:16:48 -04:00
|
|
|
scale_rect_size (&window->unconstrained_rect, scale_factor);
|
2016-01-10 09:16:09 -05:00
|
|
|
scale_rect_size (&window->saved_rect, scale_factor);
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (&window->size_hints.min_width, &window->size_hints.min_height, scale_factor);
|
|
|
|
scale_size (&window->size_hints.max_width, &window->size_hints.max_height, scale_factor);
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
/* Window geometry offset (XXX: Need a better place, see
|
|
|
|
* meta_window_wayland_move_resize). */
|
|
|
|
window->custom_frame_extents.left =
|
|
|
|
(int)(scale_factor * window->custom_frame_extents.left);
|
|
|
|
window->custom_frame_extents.top =
|
|
|
|
(int)(scale_factor * window->custom_frame_extents.top);
|
|
|
|
|
|
|
|
/* Buffer rect. */
|
|
|
|
scale_rect_size (&window->buffer_rect, scale_factor);
|
|
|
|
window->buffer_rect.x =
|
|
|
|
window->rect.x - window->custom_frame_extents.left;
|
|
|
|
window->buffer_rect.y =
|
|
|
|
window->rect.y - window->custom_frame_extents.top;
|
|
|
|
|
|
|
|
meta_compositor_sync_window_geometry (window->display->compositor,
|
|
|
|
window,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
surface = window->surface;
|
2015-03-02 22:13:05 -05:00
|
|
|
if (surface)
|
|
|
|
{
|
2017-12-22 01:28:28 -05:00
|
|
|
MetaWaylandActorSurface *actor_surface =
|
|
|
|
META_WAYLAND_ACTOR_SURFACE (surface->role);
|
2015-03-02 22:13:05 -05:00
|
|
|
|
2017-12-22 01:28:28 -05:00
|
|
|
meta_wayland_actor_surface_sync_actor_state (actor_surface);
|
2015-03-02 22:13:05 -05:00
|
|
|
}
|
2015-03-23 09:22:19 -04:00
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
wl_window->geometry_scale = geometry_scale;
|
|
|
|
|
2015-03-23 09:22:19 -04:00
|
|
|
meta_window_emit_size_changed (window);
|
2015-03-02 22:13:05 -05:00
|
|
|
}
|
|
|
|
|
2016-10-07 11:55:32 -04:00
|
|
|
static uint32_t
|
|
|
|
meta_window_wayland_get_client_pid (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = window->surface;
|
|
|
|
struct wl_resource *resource = surface->resource;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
wl_client_get_credentials (wl_resource_get_client (resource), &pid, NULL, NULL);
|
|
|
|
return (uint32_t)pid;
|
|
|
|
}
|
|
|
|
|
2014-03-19 09:26:17 -04:00
|
|
|
static void
|
2014-05-12 18:19:11 -04:00
|
|
|
appears_focused_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2014-03-19 09:26:17 -04:00
|
|
|
{
|
2014-05-12 18:19:11 -04:00
|
|
|
MetaWindow *window = META_WINDOW (object);
|
2014-05-05 19:09:22 -04:00
|
|
|
surface_state_changed (window);
|
2014-05-12 18:19:11 -04:00
|
|
|
}
|
|
|
|
|
2018-09-14 13:06:55 -04:00
|
|
|
static void
|
|
|
|
on_window_shown (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
gboolean has_been_shown;
|
|
|
|
|
|
|
|
has_been_shown = wl_window->has_been_shown;
|
|
|
|
wl_window->has_been_shown = TRUE;
|
|
|
|
|
|
|
|
if (!has_been_shown)
|
|
|
|
meta_compositor_sync_updates_frozen (window->display->compositor, window);
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:19:11 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_init (MetaWindowWayland *wl_window)
|
|
|
|
{
|
|
|
|
MetaWindow *window = META_WINDOW (wl_window);
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
wl_window->geometry_scale = 1;
|
|
|
|
|
2014-05-12 18:19:11 -04:00
|
|
|
g_signal_connect (window, "notify::appears-focused",
|
|
|
|
G_CALLBACK (appears_focused_changed), NULL);
|
2018-09-14 13:06:55 -04:00
|
|
|
g_signal_connect (window, "shown",
|
|
|
|
G_CALLBACK (on_window_shown), NULL);
|
2014-03-19 09:26:17 -04:00
|
|
|
}
|
|
|
|
|
2017-03-17 08:34:52 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_force_restore_shortcuts (MetaWindow *window,
|
|
|
|
ClutterInputDevice *source)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
|
|
|
|
|
|
|
meta_wayland_compositor_restore_shortcuts (compositor, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_window_wayland_shortcuts_inhibited (MetaWindow *window,
|
|
|
|
ClutterInputDevice *source)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
|
|
|
|
|
|
|
return meta_wayland_compositor_is_shortcuts_inhibited (compositor, source);
|
|
|
|
}
|
|
|
|
|
2018-11-13 02:56:53 -05:00
|
|
|
static gboolean
|
|
|
|
meta_window_wayland_is_focusable (MetaWindow *window)
|
|
|
|
{
|
|
|
|
return window->input;
|
|
|
|
}
|
|
|
|
|
2019-01-30 14:41:11 -05:00
|
|
|
static gboolean
|
|
|
|
meta_window_wayland_can_ping (MetaWindow *window)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-01-09 07:19:40 -05:00
|
|
|
static gboolean
|
|
|
|
meta_window_wayland_is_stackable (MetaWindow *window)
|
|
|
|
{
|
|
|
|
return meta_wayland_surface_get_buffer (window->surface) != NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-14 13:03:38 -04:00
|
|
|
static gboolean
|
|
|
|
meta_window_wayland_are_updates_frozen (MetaWindow *window)
|
|
|
|
{
|
2018-09-14 13:06:55 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
|
|
|
|
return !wl_window->has_been_shown;
|
2018-09-14 13:03:38 -04:00
|
|
|
}
|
|
|
|
|
2018-12-30 07:55:52 -05:00
|
|
|
static void
|
|
|
|
meta_window_wayland_map (MetaWindow *window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_window_wayland_unmap (MetaWindow *window)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-19 09:26:17 -04:00
|
|
|
static void
|
|
|
|
meta_window_wayland_class_init (MetaWindowWaylandClass *klass)
|
|
|
|
{
|
2014-03-19 09:36:15 -04:00
|
|
|
MetaWindowClass *window_class = META_WINDOW_CLASS (klass);
|
|
|
|
|
|
|
|
window_class->manage = meta_window_wayland_manage;
|
|
|
|
window_class->unmanage = meta_window_wayland_unmanage;
|
2014-03-20 15:12:44 -04:00
|
|
|
window_class->ping = meta_window_wayland_ping;
|
2014-03-20 15:07:44 -04:00
|
|
|
window_class->delete = meta_window_wayland_delete;
|
|
|
|
window_class->kill = meta_window_wayland_kill;
|
2014-03-20 15:16:57 -04:00
|
|
|
window_class->focus = meta_window_wayland_focus;
|
2014-05-20 15:54:39 -04:00
|
|
|
window_class->grab_op_began = meta_window_wayland_grab_op_began;
|
|
|
|
window_class->grab_op_ended = meta_window_wayland_grab_op_ended;
|
2014-03-19 10:30:12 -04:00
|
|
|
window_class->move_resize_internal = meta_window_wayland_move_resize_internal;
|
2015-03-23 09:22:19 -04:00
|
|
|
window_class->update_main_monitor = meta_window_wayland_update_main_monitor;
|
2015-03-02 22:13:05 -05:00
|
|
|
window_class->main_monitor_changed = meta_window_wayland_main_monitor_changed;
|
2016-10-07 11:55:32 -04:00
|
|
|
window_class->get_client_pid = meta_window_wayland_get_client_pid;
|
2017-03-17 08:34:52 -04:00
|
|
|
window_class->force_restore_shortcuts = meta_window_wayland_force_restore_shortcuts;
|
|
|
|
window_class->shortcuts_inhibited = meta_window_wayland_shortcuts_inhibited;
|
2018-11-13 02:56:53 -05:00
|
|
|
window_class->is_focusable = meta_window_wayland_is_focusable;
|
2018-01-09 07:19:40 -05:00
|
|
|
window_class->is_stackable = meta_window_wayland_is_stackable;
|
2019-01-30 14:41:11 -05:00
|
|
|
window_class->can_ping = meta_window_wayland_can_ping;
|
2018-09-14 13:03:38 -04:00
|
|
|
window_class->are_updates_frozen = meta_window_wayland_are_updates_frozen;
|
2018-12-30 07:55:52 -05:00
|
|
|
window_class->map = meta_window_wayland_map;
|
|
|
|
window_class->unmap = meta_window_wayland_unmap;
|
2014-03-19 09:26:17 -04:00
|
|
|
}
|
2014-04-28 17:44:45 -04:00
|
|
|
|
2014-05-20 09:08:11 -04:00
|
|
|
MetaWindow *
|
|
|
|
meta_window_wayland_new (MetaDisplay *display,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
2016-07-22 04:04:47 -04:00
|
|
|
XWindowAttributes attrs = { 0 };
|
2014-05-20 09:08:11 -04:00
|
|
|
MetaWindow *window;
|
|
|
|
|
2016-07-22 04:04:47 -04:00
|
|
|
/*
|
|
|
|
* Set attributes used by _meta_window_shared_new, don't bother trying to fake
|
|
|
|
* X11 window attributes with the rest, since they'll be ignored anyway.
|
|
|
|
*/
|
2014-05-20 09:08:11 -04:00
|
|
|
attrs.x = 0;
|
|
|
|
attrs.y = 0;
|
2014-09-16 23:09:13 -04:00
|
|
|
attrs.width = 0;
|
|
|
|
attrs.height = 0;
|
2014-05-20 09:08:11 -04:00
|
|
|
attrs.depth = 24;
|
|
|
|
attrs.visual = NULL;
|
|
|
|
attrs.map_state = IsUnmapped;
|
2016-07-22 04:04:47 -04:00
|
|
|
attrs.override_redirect = False;
|
2014-05-20 09:08:11 -04:00
|
|
|
|
|
|
|
/* XXX: Note: In the Wayland case we currently still trap X errors while
|
|
|
|
* creating a MetaWindow because we will still be making various redundant
|
|
|
|
* X requests (passing a window xid of None) until we thoroughly audit all
|
|
|
|
* the code to make sure it knows about non X based clients...
|
|
|
|
*/
|
2017-08-27 14:48:55 -04:00
|
|
|
meta_x11_error_trap_push (display->x11_display); /* Push a trap over all of window
|
2017-08-26 12:27:50 -04:00
|
|
|
* creation, to reduce XSync() calls
|
|
|
|
*/
|
2014-05-20 09:08:11 -04:00
|
|
|
|
|
|
|
window = _meta_window_shared_new (display,
|
|
|
|
META_WINDOW_CLIENT_TYPE_WAYLAND,
|
|
|
|
surface,
|
|
|
|
None,
|
|
|
|
WithdrawnState,
|
|
|
|
META_COMP_EFFECT_CREATE,
|
|
|
|
&attrs);
|
|
|
|
|
2017-08-27 14:48:55 -04:00
|
|
|
meta_x11_error_trap_pop (display->x11_display); /* pop the XSync()-reducing trap */
|
2014-05-20 09:08:11 -04:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2014-07-28 06:04:23 -04:00
|
|
|
static gboolean
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
is_pending_ack_configure (MetaWindowWayland *wl_window,
|
|
|
|
MetaWaylandSerial *acked_configure_serial)
|
2014-07-28 06:04:23 -04:00
|
|
|
{
|
|
|
|
if (wl_window->pending_configure_serial.set)
|
|
|
|
{
|
|
|
|
/* If we're waiting for a configure and this isn't an ACK for
|
|
|
|
* any configure, then fizzle it out. */
|
|
|
|
if (!acked_configure_serial->set)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If we're waiting for a configure and this isn't an ACK for
|
|
|
|
* the configure we're waiting for, then fizzle it out. */
|
|
|
|
if (acked_configure_serial->value != wl_window->pending_configure_serial.value)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-03-23 09:10:20 -04:00
|
|
|
int
|
2017-02-24 04:05:01 -05:00
|
|
|
meta_window_wayland_get_geometry_scale (MetaWindow *window)
|
2015-03-23 09:10:20 -04:00
|
|
|
{
|
2017-10-16 05:02:51 -04:00
|
|
|
if (!window->monitor)
|
|
|
|
return 1;
|
|
|
|
|
2017-02-24 05:10:52 -05:00
|
|
|
return get_window_geometry_scale_for_logical_monitor (window->monitor);
|
2015-03-23 09:10:20 -04:00
|
|
|
}
|
|
|
|
|
2014-04-28 17:44:45 -04:00
|
|
|
/**
|
|
|
|
* meta_window_move_resize_wayland:
|
|
|
|
*
|
|
|
|
* Complete a resize operation from a wayland client.
|
|
|
|
*/
|
|
|
|
void
|
wayland-surface: Don't do pending move/resizes on all commits
We assume in meta_window_wayland_move_resize that the next commit that
changes the geometry will always be for our next pending operation, so
if we have a move pending on a resize, the next commit will trigger the
move. This is, of course, fundamentally wrong.
We broke this assumption even more now that we don't fizzle out calls to
meta_window_move_resize_internal and now call it on every commit, which
means that a simple damage and then commit would complete a pending
move.
This was even broken by apps like weston-terminal, which, when clicking
on the maximize button, first redraws the terminal with the maximize
button state back on hover on press, and would only redraw when it got
the configure event with the coordinates.
To track the correct commit to apply the move for, we implement the
ack_configure request and ignore all move/resizes that happen before
that.
Right now, we actually fizzle out the entire move/resize if there's a
future pending configure we're waiting on.
2014-07-27 11:23:17 -04:00
|
|
|
meta_window_wayland_move_resize (MetaWindow *window,
|
|
|
|
MetaWaylandSerial *acked_configure_serial,
|
|
|
|
MetaRectangle new_geom,
|
|
|
|
int dx,
|
|
|
|
int dy)
|
2014-04-28 17:44:45 -04:00
|
|
|
{
|
2014-04-28 18:15:03 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
2017-02-24 04:05:01 -05:00
|
|
|
int geometry_scale;
|
2014-05-01 19:09:13 -04:00
|
|
|
int gravity;
|
|
|
|
MetaRectangle rect;
|
2014-04-28 17:44:45 -04:00
|
|
|
MetaMoveResizeFlags flags;
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
gboolean pending_ack_configure;
|
2015-03-23 09:22:19 -04:00
|
|
|
|
|
|
|
/* new_geom is in the logical pixel coordinate space, but MetaWindow wants its
|
|
|
|
* rects to represent what in turn will end up on the stage, i.e. we need to
|
|
|
|
* scale new_geom to physical pixels given what buffer scale and texture scale
|
|
|
|
* is in use. */
|
2017-02-24 04:05:01 -05:00
|
|
|
|
|
|
|
geometry_scale = meta_window_wayland_get_geometry_scale (window);
|
|
|
|
new_geom.x *= geometry_scale;
|
|
|
|
new_geom.y *= geometry_scale;
|
|
|
|
new_geom.width *= geometry_scale;
|
|
|
|
new_geom.height *= geometry_scale;
|
2015-03-23 09:22:19 -04:00
|
|
|
|
|
|
|
/* The (dx, dy) offset is also in logical pixel coordinate space and needs
|
|
|
|
* to be scaled in the same way as new_geom. */
|
2017-02-24 04:05:01 -05:00
|
|
|
dx *= geometry_scale;
|
|
|
|
dy *= geometry_scale;
|
2014-04-28 17:44:45 -04:00
|
|
|
|
2014-07-17 15:24:06 -04:00
|
|
|
/* XXX: Find a better place to store the window geometry offsets. */
|
2014-07-17 16:42:41 -04:00
|
|
|
window->custom_frame_extents.left = new_geom.x;
|
|
|
|
window->custom_frame_extents.top = new_geom.y;
|
2014-07-17 15:24:06 -04:00
|
|
|
|
2014-12-15 16:28:47 -05:00
|
|
|
flags = META_MOVE_RESIZE_WAYLAND_RESIZE;
|
2014-04-28 17:44:45 -04:00
|
|
|
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
pending_ack_configure = is_pending_ack_configure (wl_window, acked_configure_serial);
|
|
|
|
|
2014-05-01 18:55:34 -04:00
|
|
|
/* x/y are ignored when we're doing interactive resizing */
|
2014-04-28 17:44:45 -04:00
|
|
|
if (!meta_grab_op_is_resizing (window->display->grab_op))
|
|
|
|
{
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
if (wl_window->has_pending_move && pending_ack_configure)
|
2014-05-01 18:55:34 -04:00
|
|
|
{
|
2014-07-27 11:37:18 -04:00
|
|
|
rect.x = wl_window->pending_move_x;
|
|
|
|
rect.y = wl_window->pending_move_y;
|
|
|
|
wl_window->has_pending_move = FALSE;
|
2014-12-15 16:28:47 -05:00
|
|
|
flags |= META_MOVE_RESIZE_MOVE_ACTION;
|
2014-05-01 18:55:34 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-14 16:45:48 -04:00
|
|
|
rect.x = window->rect.x;
|
|
|
|
rect.y = window->rect.y;
|
2014-05-01 18:55:34 -04:00
|
|
|
}
|
|
|
|
|
2014-04-28 17:44:45 -04:00
|
|
|
if (dx != 0 || dy != 0)
|
|
|
|
{
|
2014-05-01 19:09:13 -04:00
|
|
|
rect.x += dx;
|
|
|
|
rect.y += dy;
|
2014-12-15 16:28:47 -05:00
|
|
|
flags |= META_MOVE_RESIZE_MOVE_ACTION;
|
2014-04-28 17:44:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
window: Let implementations finish state changes
In the old, synchronous X.org world, we could assume that
a state change always meant a synchronizing the window
geometry right after. After firing an operation that
would change the window state, such as maximizing or
tiling the window,
With Wayland, however, this is not valid anymore, since
Wayland is asynchronous. In this scenario, we call
meta_window_move_resize_internal() twice: when the user
executes an state-changing operation, and when the server
ACKs this operation. This breaks the previous assumptions,
and as a consequence, it breaks the GNOME Shell animations
in Wayland.
The solution is giving the MetaWindow control over the time
when the window geometry is synchronized with the compositor.
That is done by introducing a new result flag. Wayland asks
for a compositor sync after receiving an ACK from the server,
while X11 asks for it right away.
Fixes #78
2018-04-17 22:42:33 -04:00
|
|
|
if (wl_window->has_pending_state_change && pending_ack_configure)
|
|
|
|
{
|
|
|
|
flags |= META_MOVE_RESIZE_WAYLAND_STATE_CHANGED;
|
|
|
|
wl_window->has_pending_state_change = FALSE;
|
|
|
|
}
|
|
|
|
|
2014-07-28 06:04:23 -04:00
|
|
|
wl_window->pending_configure_serial.set = FALSE;
|
|
|
|
|
2014-07-17 15:24:06 -04:00
|
|
|
rect.width = new_geom.width;
|
|
|
|
rect.height = new_geom.height;
|
2014-05-01 19:09:13 -04:00
|
|
|
|
|
|
|
if (rect.width != window->rect.width || rect.height != window->rect.height)
|
2014-12-15 16:28:47 -05:00
|
|
|
flags |= META_MOVE_RESIZE_RESIZE_ACTION;
|
2014-04-28 17:44:45 -04:00
|
|
|
|
2014-05-01 19:09:13 -04:00
|
|
|
gravity = meta_resize_gravity_from_grab_op (window->display->grab_op);
|
|
|
|
meta_window_move_resize_internal (window, flags, gravity, rect);
|
2014-04-28 17:44:45 -04:00
|
|
|
}
|
2015-03-25 02:39:30 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_wayland_place_relative_to (MetaWindow *window,
|
|
|
|
MetaWindow *other,
|
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
2017-02-24 04:05:01 -05:00
|
|
|
int geometry_scale;
|
2015-03-25 02:39:30 -04:00
|
|
|
|
|
|
|
/* If there is no monitor, we can't position the window reliably. */
|
|
|
|
if (!other->monitor)
|
|
|
|
return;
|
|
|
|
|
2017-02-24 04:05:01 -05:00
|
|
|
geometry_scale = meta_window_wayland_get_geometry_scale (other);
|
2015-03-25 02:39:30 -04:00
|
|
|
meta_window_move_frame (window, FALSE,
|
2017-02-24 04:05:01 -05:00
|
|
|
other->buffer_rect.x + (x * geometry_scale),
|
|
|
|
other->buffer_rect.y + (y * geometry_scale));
|
2015-03-25 02:39:30 -04:00
|
|
|
window->placed = TRUE;
|
|
|
|
}
|
2016-02-01 05:46:11 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_place_with_placement_rule (MetaWindow *window,
|
|
|
|
MetaPlacementRule *placement_rule)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&window->placement_rule, g_free);
|
|
|
|
window->placement_rule = g_new0 (MetaPlacementRule, 1);
|
|
|
|
*window->placement_rule = *placement_rule;
|
|
|
|
|
|
|
|
window->unconstrained_rect.width = placement_rule->width;
|
|
|
|
window->unconstrained_rect.height = placement_rule->height;
|
2017-06-21 07:30:22 -04:00
|
|
|
meta_window_force_placement (window, FALSE);
|
2016-02-01 05:46:11 -05:00
|
|
|
}
|
2016-04-06 08:07:08 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_wayland_set_min_size (MetaWindow *window,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
gint64 new_width, new_height;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
meta_topic (META_DEBUG_GEOMETRY, "Window %s sets min size %d x %d\n",
|
|
|
|
window->desc, width, height);
|
|
|
|
|
|
|
|
if (width == 0 && height == 0)
|
|
|
|
{
|
|
|
|
window->size_hints.min_width = 0;
|
|
|
|
window->size_hints.min_height = 0;
|
|
|
|
window->size_hints.flags &= ~PMinSize;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-24 04:05:01 -05:00
|
|
|
scale = (float) meta_window_wayland_get_geometry_scale (window);
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (&width, &height, scale);
|
|
|
|
|
|
|
|
new_width = width + (window->custom_frame_extents.left +
|
|
|
|
window->custom_frame_extents.right);
|
|
|
|
new_height = height + (window->custom_frame_extents.top +
|
|
|
|
window->custom_frame_extents.bottom);
|
|
|
|
|
|
|
|
window->size_hints.min_width = (int) MIN (new_width, G_MAXINT);
|
|
|
|
window->size_hints.min_height = (int) MIN (new_height, G_MAXINT);
|
|
|
|
window->size_hints.flags |= PMinSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_wayland_set_max_size (MetaWindow *window,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
|
|
|
|
{
|
|
|
|
gint64 new_width, new_height;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
meta_topic (META_DEBUG_GEOMETRY, "Window %s sets max size %d x %d\n",
|
|
|
|
window->desc, width, height);
|
|
|
|
|
|
|
|
if (width == 0 && height == 0)
|
|
|
|
{
|
|
|
|
window->size_hints.max_width = G_MAXINT;
|
|
|
|
window->size_hints.max_height = G_MAXINT;
|
|
|
|
window->size_hints.flags &= ~PMaxSize;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-24 04:05:01 -05:00
|
|
|
scale = (float) meta_window_wayland_get_geometry_scale (window);
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (&width, &height, scale);
|
|
|
|
|
|
|
|
new_width = width + (window->custom_frame_extents.left +
|
|
|
|
window->custom_frame_extents.right);
|
|
|
|
new_height = height + (window->custom_frame_extents.top +
|
|
|
|
window->custom_frame_extents.bottom);
|
|
|
|
|
|
|
|
window->size_hints.max_width = (int) ((new_width > 0 && new_width < G_MAXINT) ?
|
|
|
|
new_width : G_MAXINT);
|
|
|
|
window->size_hints.max_height = (int) ((new_height > 0 && new_height < G_MAXINT) ?
|
|
|
|
new_height : G_MAXINT);
|
|
|
|
window->size_hints.flags |= PMaxSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_wayland_get_min_size (MetaWindow *window,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
|
|
|
gint64 current_width, current_height;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
if (!(window->size_hints.flags & PMinSize))
|
|
|
|
{
|
|
|
|
/* Zero means unlimited */
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_width = window->size_hints.min_width -
|
|
|
|
(window->custom_frame_extents.left +
|
|
|
|
window->custom_frame_extents.right);
|
|
|
|
current_height = window->size_hints.min_height -
|
|
|
|
(window->custom_frame_extents.top +
|
|
|
|
window->custom_frame_extents.bottom);
|
|
|
|
|
|
|
|
*width = MAX (current_width, 0);
|
|
|
|
*height = MAX (current_height, 0);
|
|
|
|
|
2017-02-24 04:05:01 -05:00
|
|
|
scale = 1.0 / (float) meta_window_wayland_get_geometry_scale (window);
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (width, height, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_window_wayland_get_max_size (MetaWindow *window,
|
|
|
|
int *width,
|
|
|
|
int *height)
|
|
|
|
{
|
|
|
|
gint64 current_width = 0;
|
|
|
|
gint64 current_height = 0;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
if (!(window->size_hints.flags & PMaxSize))
|
|
|
|
{
|
|
|
|
/* Zero means unlimited */
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->size_hints.max_width < G_MAXINT)
|
|
|
|
current_width = window->size_hints.max_width -
|
|
|
|
(window->custom_frame_extents.left +
|
|
|
|
window->custom_frame_extents.right);
|
|
|
|
|
|
|
|
if (window->size_hints.max_height < G_MAXINT)
|
|
|
|
current_height = window->size_hints.max_height -
|
|
|
|
(window->custom_frame_extents.top +
|
|
|
|
window->custom_frame_extents.bottom);
|
|
|
|
|
|
|
|
*width = CLAMP (current_width, 0, G_MAXINT);
|
|
|
|
*height = CLAMP (current_height, 0, G_MAXINT);
|
|
|
|
|
2017-02-24 04:05:01 -05:00
|
|
|
scale = 1.0 / (float) meta_window_wayland_get_geometry_scale (window);
|
2016-04-06 08:07:08 -04:00
|
|
|
scale_size (width, height, scale);
|
|
|
|
}
|
|
|
|
|
wayland: Add function to query if window needs move or resize
This will be used by the next commit to determine when a window
geometry change should be ignored or not. Normally, it would be
enough to just check if the position and sizes changed.
The position, in this case, is relative to the client buffer, not
the global position. But because it is not global, there is one,
admitedly unlikely, situation where the window state is updated
while the client size and relative positions don't change.
One can trigger this by e.g. tiling the window to the half-left of
the monitor, then immediately tile it to half-right. In this case,
the window didn't change, just it's state, but nonetheless we need
to notify the compositor and run the full move/resize routines.
When that case happens, though, the MetaWindowWayland is tracking
the pending state change or a move. And this is what we need to
expose.
https://bugzilla.gnome.org/show_bug.cgi?id=780292
Issue: #78
2018-03-17 03:52:44 -04:00
|
|
|
gboolean
|
|
|
|
meta_window_wayland_needs_move_resize (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (window);
|
|
|
|
|
|
|
|
return wl_window->has_pending_state_change || wl_window->has_pending_move;
|
|
|
|
}
|