2009-06-13 16:45:32 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2013-02-15 13:42:08 -05:00
|
|
|
/*
|
|
|
|
* SECTION:stack-tracker
|
|
|
|
* @short_description: Track stacking order for compositor
|
|
|
|
*
|
|
|
|
* #MetaStackTracker maintains the most accurate view we have at a
|
|
|
|
* given point of time of the ordering of the children of the root
|
|
|
|
* window (including override-redirect windows.) This is used to order
|
|
|
|
* the windows when the compositor draws them.
|
|
|
|
*
|
|
|
|
* By contrast, #MetaStack is responsible for keeping track of how we
|
|
|
|
* think that windows *should* be ordered. For windows we manage
|
|
|
|
* (non-override-redirect windows), the two stacking orders will be
|
|
|
|
* the same.
|
|
|
|
*/
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2009-06-13 16:45:32 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-03-05 19:29:12 -05:00
|
|
|
#include "frame.h"
|
2009-06-13 16:45:32 -04:00
|
|
|
#include "screen-private.h"
|
|
|
|
#include "stack-tracker.h"
|
2011-03-05 19:29:12 -05:00
|
|
|
#include <meta/util.h>
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2011-03-05 19:29:12 -05:00
|
|
|
#include <meta/compositor.h>
|
2009-06-14 08:04:28 -04:00
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
/* The complexity here comes from resolving two competing factors:
|
|
|
|
*
|
|
|
|
* - We need to have a view of the stacking order that takes into
|
|
|
|
* account everything we have done without waiting for events
|
|
|
|
* back from the X server; we don't want to draw intermediate
|
|
|
|
* partially-stacked stack states just because we haven't received
|
|
|
|
* some notification yet.
|
|
|
|
*
|
|
|
|
* - Only the X server has an accurate view of the complete stacking;
|
|
|
|
* when we make a request to restack windows, we don't know how
|
|
|
|
* it will affect override-redirect windows, because at any point
|
|
|
|
* applications may restack these windows without our involvement.
|
|
|
|
*
|
|
|
|
* The technique we use is that we keep three sets of information:
|
|
|
|
*
|
|
|
|
* - The stacking order on the server as known from the last
|
|
|
|
* event we received.
|
|
|
|
* - A queue of stacking requests that *we* made subsequent to
|
|
|
|
* that last event.
|
|
|
|
* - A predicted stacking order, derived from applying the queued
|
|
|
|
* requests to the last state from the server.
|
|
|
|
*
|
|
|
|
* When we receive a new event: a) we compare the serial in the event to
|
|
|
|
* the serial of the queued requests and remove any that are now
|
2010-11-13 14:07:07 -05:00
|
|
|
* no longer pending b) if necessary, drop the predicted stacking
|
|
|
|
* order to recompute it at the next opportunity.
|
2009-06-13 16:45:32 -04:00
|
|
|
*
|
|
|
|
* Possible optimizations:
|
|
|
|
* Keep the stacks as an array + reverse-mapping hash table to avoid
|
|
|
|
* linear lookups.
|
|
|
|
* Keep the stacks as a GList + reverse-mapping hash table to avoid
|
|
|
|
* linear lookups and to make restacking constant-time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef union _MetaStackOp MetaStackOp;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
STACK_OP_ADD,
|
|
|
|
STACK_OP_REMOVE,
|
|
|
|
STACK_OP_RAISE_ABOVE,
|
|
|
|
STACK_OP_LOWER_BELOW
|
|
|
|
} MetaStackOpType;
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
typedef enum {
|
|
|
|
APPLY_DEFAULT = 0,
|
|
|
|
/* Only do restacking that we can do locally without changing
|
|
|
|
* the order of X windows. After we've received any stack
|
|
|
|
* events from the X server, we apply the locally cached
|
|
|
|
* ops in this mode to handle the non-X parts */
|
|
|
|
NO_RESTACK_X_WINDOWS = 1 << 0,
|
|
|
|
/* If the stacking operation wouldn't change the order of X
|
|
|
|
* windows, ignore it. We use this when applying events received
|
|
|
|
* from X so that a spontaneous ConfigureNotify (for a move, say)
|
|
|
|
* doesn't change the stacking of X windows with respect to
|
|
|
|
* Wayland windows. */
|
|
|
|
IGNORE_NOOP_X_RESTACK = 1 << 1
|
|
|
|
} ApplyFlags;
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
/* MetaStackOp represents a "stacking operation" - a change to
|
|
|
|
* apply to a window stack. Depending on the context, it could
|
|
|
|
* either reflect a request we have sent to the server, or a
|
|
|
|
* notification event we received from the X server.
|
|
|
|
*/
|
|
|
|
union _MetaStackOp
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
MetaStackOpType type;
|
|
|
|
gulong serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window;
|
2009-06-13 16:45:32 -04:00
|
|
|
} any;
|
|
|
|
struct {
|
|
|
|
MetaStackOpType type;
|
|
|
|
gulong serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window;
|
2009-06-13 16:45:32 -04:00
|
|
|
} add;
|
|
|
|
struct {
|
|
|
|
MetaStackOpType type;
|
|
|
|
gulong serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window;
|
2009-06-13 16:45:32 -04:00
|
|
|
} remove;
|
|
|
|
struct {
|
|
|
|
MetaStackOpType type;
|
|
|
|
gulong serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window;
|
|
|
|
guint64 sibling;
|
2009-06-13 16:45:32 -04:00
|
|
|
} raise_above;
|
|
|
|
struct {
|
|
|
|
MetaStackOpType type;
|
|
|
|
gulong serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window;
|
|
|
|
guint64 sibling;
|
2009-06-13 16:45:32 -04:00
|
|
|
} lower_below;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MetaStackTracker
|
|
|
|
{
|
|
|
|
MetaScreen *screen;
|
|
|
|
|
|
|
|
/* This is the serial of the last request we made that was reflected
|
2012-04-05 06:22:13 -04:00
|
|
|
* in xserver_stack
|
2009-06-13 16:45:32 -04:00
|
|
|
*/
|
2012-04-05 06:22:13 -04:00
|
|
|
gulong xserver_serial;
|
|
|
|
|
|
|
|
/* A combined stack containing X and Wayland windows but without
|
|
|
|
* any unverified operations applied. */
|
|
|
|
GArray *verified_stack;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
/* This is a queue of requests we've made to change the stacking order,
|
|
|
|
* where we haven't yet gotten a reply back from the server.
|
|
|
|
*/
|
2012-04-05 06:22:13 -04:00
|
|
|
GQueue *unverified_predictions;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
/* This is how we think the stack is, based on verified_stack, and
|
|
|
|
* on the unverified_predictions we've made subsequent to
|
|
|
|
* verified_stack.
|
2009-06-13 16:45:32 -04:00
|
|
|
*/
|
|
|
|
GArray *predicted_stack;
|
2009-06-14 08:04:28 -04:00
|
|
|
|
|
|
|
/* Idle function used to sync the compositor's view of the window
|
|
|
|
* stack up with our best guess before a frame is drawn.
|
|
|
|
*/
|
2009-09-25 15:47:22 -04:00
|
|
|
guint sync_stack_later;
|
2009-06-13 16:45:32 -04:00
|
|
|
};
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
static inline const char *
|
|
|
|
get_window_desc (MetaStackTracker *tracker,
|
|
|
|
guint64 window)
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
return meta_display_describe_stack_id (tracker->screen->display, window);
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
static void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_op_dump (MetaStackTracker *tracker,
|
|
|
|
MetaStackOp *op,
|
|
|
|
const char *prefix,
|
|
|
|
const char *suffix)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
const char *window_desc = get_window_desc (tracker, op->any.window);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
switch (op->any.type)
|
|
|
|
{
|
|
|
|
case STACK_OP_ADD:
|
2012-04-05 06:22:13 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, "%sADD(%s; %ld)%s",
|
2014-09-08 21:20:14 -04:00
|
|
|
prefix, window_desc, op->any.serial, suffix);
|
2009-06-13 16:45:32 -04:00
|
|
|
break;
|
|
|
|
case STACK_OP_REMOVE:
|
2012-04-05 06:22:13 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, "%sREMOVE(%s; %ld)%s",
|
2014-09-08 21:20:14 -04:00
|
|
|
prefix, window_desc, op->any.serial, suffix);
|
2009-06-13 16:45:32 -04:00
|
|
|
break;
|
|
|
|
case STACK_OP_RAISE_ABOVE:
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
|
|
|
meta_topic (META_DEBUG_STACK, "%sRAISE_ABOVE(%s, %s; %ld)%s",
|
|
|
|
prefix,
|
2014-09-08 21:20:14 -04:00
|
|
|
window_desc,
|
|
|
|
get_window_desc (tracker, op->raise_above.sibling),
|
2012-04-05 06:22:13 -04:00
|
|
|
op->any.serial,
|
|
|
|
suffix);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
case STACK_OP_LOWER_BELOW:
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
|
|
|
meta_topic (META_DEBUG_STACK, "%sLOWER_BELOW(%s, %s; %ld)%s",
|
|
|
|
prefix,
|
2014-09-08 21:20:14 -04:00
|
|
|
window_desc,
|
|
|
|
get_window_desc (tracker, op->lower_below.sibling),
|
2012-04-05 06:22:13 -04:00
|
|
|
op->any.serial,
|
|
|
|
suffix);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-08 21:20:14 -04:00
|
|
|
stack_dump (MetaStackTracker *tracker,
|
|
|
|
GArray *stack)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
meta_push_no_msg_prefix ();
|
2014-07-10 16:12:05 -04:00
|
|
|
for (i = 0; i < stack->len; i++)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window = g_array_index (stack, guint64, i);
|
|
|
|
meta_topic (META_DEBUG_STACK, " %s", get_window_desc (tracker, window));
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
2014-07-10 16:12:05 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, "\n");
|
|
|
|
meta_pop_no_msg_prefix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_stack_tracker_dump (MetaStackTracker *tracker)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
meta_topic (META_DEBUG_STACK, "MetaStackTracker state (screen=%d)\n", tracker->screen->number);
|
|
|
|
meta_push_no_msg_prefix ();
|
|
|
|
meta_topic (META_DEBUG_STACK, " xserver_serial: %ld\n", tracker->xserver_serial);
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, " verified_stack: ");
|
2014-09-08 21:20:14 -04:00
|
|
|
stack_dump (tracker, tracker->verified_stack);
|
2014-07-10 16:12:05 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, " unverified_predictions: [");
|
2012-04-05 06:22:13 -04:00
|
|
|
for (l = tracker->unverified_predictions->head; l; l = l->next)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = l->data;
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_op_dump (tracker, op, "", l->next ? ", " : "");
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
meta_topic (META_DEBUG_STACK, "]\n");
|
2012-04-05 06:22:13 -04:00
|
|
|
if (tracker->predicted_stack)
|
|
|
|
{
|
|
|
|
meta_topic (META_DEBUG_STACK, "\n predicted_stack: ");
|
2014-09-08 21:20:14 -04:00
|
|
|
stack_dump (tracker, tracker->predicted_stack);
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
meta_pop_no_msg_prefix ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_stack_op_free (MetaStackOp *op)
|
|
|
|
{
|
|
|
|
g_slice_free (MetaStackOp, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-08 21:20:14 -04:00
|
|
|
find_window (GArray *window_stack,
|
|
|
|
guint64 window)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
for (i = 0; i < window_stack->len; i++)
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 current = g_array_index (window_stack, guint64, i);
|
|
|
|
if (current == window)
|
|
|
|
return i;
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-06-14 08:04:28 -04:00
|
|
|
/* Returns TRUE if stack was changed */
|
|
|
|
static gboolean
|
2014-09-09 13:41:27 -04:00
|
|
|
move_window_above (GArray *stack,
|
|
|
|
guint64 window,
|
|
|
|
int old_pos,
|
|
|
|
int above_pos,
|
|
|
|
ApplyFlags apply_flags)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
int i;
|
2014-09-09 13:41:27 -04:00
|
|
|
gboolean can_restack_this_window =
|
|
|
|
(apply_flags & NO_RESTACK_X_WINDOWS) == 0 || !META_STACK_ID_IS_X11 (window);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
if (old_pos < above_pos)
|
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
if ((apply_flags & IGNORE_NOOP_X_RESTACK) != 0)
|
|
|
|
{
|
|
|
|
gboolean found_x_window = FALSE;
|
|
|
|
for (i = old_pos + 1; i <= above_pos; i++)
|
|
|
|
if (META_STACK_ID_IS_X11 (g_array_index (stack, guint64, i)))
|
|
|
|
found_x_window = TRUE;
|
|
|
|
|
|
|
|
if (!found_x_window)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
for (i = old_pos; i < above_pos; i++)
|
2014-09-09 13:41:27 -04:00
|
|
|
{
|
|
|
|
if (!can_restack_this_window &&
|
|
|
|
META_STACK_ID_IS_X11 (g_array_index (stack, guint64, i + 1)))
|
|
|
|
break;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
g_array_index (stack, guint64, i) =
|
|
|
|
g_array_index (stack, guint64, i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_index (stack, guint64, i) = window;
|
2009-06-14 08:04:28 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
return i != old_pos;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
else if (old_pos > above_pos + 1)
|
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
if ((apply_flags & IGNORE_NOOP_X_RESTACK) != 0)
|
|
|
|
{
|
|
|
|
gboolean found_x_window = FALSE;
|
|
|
|
for (i = above_pos + 1; i < old_pos; i++)
|
|
|
|
if (META_STACK_ID_IS_X11 (g_array_index (stack, guint64, i)))
|
|
|
|
found_x_window = TRUE;
|
|
|
|
|
|
|
|
if (!found_x_window)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
for (i = old_pos; i > above_pos + 1; i--)
|
2014-09-09 13:41:27 -04:00
|
|
|
{
|
|
|
|
if (!can_restack_this_window &&
|
|
|
|
META_STACK_ID_IS_X11 (g_array_index (stack, guint64, i - 1)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
g_array_index (stack, guint64, i) =
|
|
|
|
g_array_index (stack, guint64, i - 1);
|
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
g_array_index (stack, guint64, i) = window;
|
2009-06-14 08:04:28 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
return i != old_pos;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
2009-06-14 08:04:28 -04:00
|
|
|
else
|
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2009-06-14 08:04:28 -04:00
|
|
|
/* Returns TRUE if stack was changed */
|
|
|
|
static gboolean
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_op_apply (MetaStackTracker *tracker,
|
|
|
|
MetaStackOp *op,
|
2014-09-09 13:41:27 -04:00
|
|
|
GArray *stack,
|
|
|
|
ApplyFlags apply_flags)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
switch (op->any.type)
|
|
|
|
{
|
|
|
|
case STACK_OP_ADD:
|
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (op->add.window) &&
|
|
|
|
(apply_flags & NO_RESTACK_X_WINDOWS) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
int old_pos = find_window (stack, op->add.window);
|
2009-06-13 16:45:32 -04:00
|
|
|
if (old_pos >= 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_ADD: window %s already in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->add.window));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_array_append_val (stack, op->add.window);
|
2009-06-14 08:04:28 -04:00
|
|
|
return TRUE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
case STACK_OP_REMOVE:
|
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (op->remove.window) &&
|
|
|
|
(apply_flags & NO_RESTACK_X_WINDOWS) != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
int old_pos = find_window (stack, op->remove.window);
|
2009-06-13 16:45:32 -04:00
|
|
|
if (old_pos < 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_REMOVE: window %s not in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->remove.window));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_array_remove_index (stack, old_pos);
|
2009-06-14 08:04:28 -04:00
|
|
|
return TRUE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
case STACK_OP_RAISE_ABOVE:
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
int old_pos = find_window (stack, op->raise_above.window);
|
2009-06-13 16:45:32 -04:00
|
|
|
int above_pos;
|
|
|
|
if (old_pos < 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_RAISE_ABOVE: window %s not in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->raise_above.window));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
if (op->raise_above.sibling)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
above_pos = find_window (stack, op->raise_above.sibling);
|
2009-06-13 16:45:32 -04:00
|
|
|
if (above_pos < 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_RAISE_ABOVE: sibling window %s not in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->raise_above.sibling));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
above_pos = -1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
return move_window_above (stack, op->raise_above.window, old_pos, above_pos,
|
|
|
|
apply_flags);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
case STACK_OP_LOWER_BELOW:
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
int old_pos = find_window (stack, op->lower_below.window);
|
2009-06-13 16:45:32 -04:00
|
|
|
int above_pos;
|
|
|
|
if (old_pos < 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_LOWER_BELOW: window %s not in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->lower_below.window));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
if (op->lower_below.sibling)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
int below_pos = find_window (stack, op->lower_below.sibling);
|
2009-06-13 16:45:32 -04:00
|
|
|
if (below_pos < 0)
|
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
g_warning ("STACK_OP_LOWER_BELOW: sibling window %s not in stack",
|
2014-09-08 21:20:14 -04:00
|
|
|
get_window_desc (tracker, op->lower_below.sibling));
|
2009-06-14 08:04:28 -04:00
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
above_pos = below_pos - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
above_pos = stack->len - 1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
return move_window_above (stack, op->lower_below.window, old_pos, above_pos,
|
|
|
|
apply_flags);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
}
|
2009-06-14 08:04:28 -04:00
|
|
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return FALSE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static GArray *
|
2012-04-05 06:22:13 -04:00
|
|
|
copy_stack (GArray *stack)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
GArray *copy = g_array_sized_new (FALSE, FALSE, sizeof (guint64), stack->len);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
g_array_set_size (copy, stack->len);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
memcpy (copy->data, stack->data, sizeof (guint64) * stack->len);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
|
|
|
return copy;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
static void
|
2014-09-09 13:41:27 -04:00
|
|
|
query_xserver_stack (MetaStackTracker *tracker)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
MetaScreen *screen = tracker->screen;
|
2009-06-13 16:45:32 -04:00
|
|
|
Window ignored1, ignored2;
|
|
|
|
Window *children;
|
|
|
|
guint n_children;
|
2012-04-05 06:22:13 -04:00
|
|
|
guint i;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
tracker->xserver_serial = XNextRequest (screen->display->xdisplay);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
XQueryTree (screen->display->xdisplay,
|
|
|
|
screen->xroot,
|
|
|
|
&ignored1, &ignored2, &children, &n_children);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
tracker->verified_stack = g_array_sized_new (FALSE, FALSE, sizeof (guint64), n_children);
|
|
|
|
g_array_set_size (tracker->verified_stack, n_children);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
|
|
|
for (i = 0; i < n_children; i++)
|
2014-09-09 13:41:27 -04:00
|
|
|
g_array_index (tracker->verified_stack, guint64, i) = children[i];
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
XFree (children);
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaStackTracker *
|
|
|
|
meta_stack_tracker_new (MetaScreen *screen)
|
|
|
|
{
|
|
|
|
MetaStackTracker *tracker;
|
|
|
|
|
|
|
|
tracker = g_new0 (MetaStackTracker, 1);
|
|
|
|
tracker->screen = screen;
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
query_xserver_stack (tracker);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
tracker->unverified_predictions = g_queue_new ();
|
|
|
|
|
|
|
|
meta_stack_tracker_dump (tracker);
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
return tracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stack_tracker_free (MetaStackTracker *tracker)
|
|
|
|
{
|
2009-09-25 15:47:22 -04:00
|
|
|
if (tracker->sync_stack_later)
|
|
|
|
meta_later_remove (tracker->sync_stack_later);
|
2009-06-14 08:04:28 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
g_array_free (tracker->verified_stack, TRUE);
|
2009-06-13 16:45:32 -04:00
|
|
|
if (tracker->predicted_stack)
|
|
|
|
g_array_free (tracker->predicted_stack, TRUE);
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
g_queue_foreach (tracker->unverified_predictions, (GFunc)meta_stack_op_free, NULL);
|
|
|
|
g_queue_free (tracker->unverified_predictions);
|
|
|
|
tracker->unverified_predictions = NULL;
|
2012-03-23 03:59:11 -04:00
|
|
|
|
|
|
|
g_free (tracker);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-05 06:22:13 -04:00
|
|
|
stack_tracker_apply_prediction (MetaStackTracker *tracker,
|
|
|
|
MetaStackOp *op)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-05-07 12:25:58 -04:00
|
|
|
gboolean free_at_end = FALSE;
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
/* If this is a wayland operation then it's implicitly verified so
|
|
|
|
* we can apply it immediately so long as it doesn't depend on any
|
|
|
|
* unverified X operations...
|
|
|
|
*/
|
2014-09-08 21:20:14 -04:00
|
|
|
if (!META_STACK_ID_IS_X11 (op->any.window) &&
|
2012-04-05 06:22:13 -04:00
|
|
|
tracker->unverified_predictions->length == 0)
|
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
if (meta_stack_op_apply (tracker, op, tracker->verified_stack, APPLY_DEFAULT))
|
2012-04-05 06:22:13 -04:00
|
|
|
meta_stack_tracker_queue_sync_stack (tracker);
|
2014-05-07 12:25:58 -04:00
|
|
|
|
|
|
|
free_at_end = TRUE;
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_op_dump (tracker, op, "Predicting: ", "\n");
|
2012-04-05 06:22:13 -04:00
|
|
|
g_queue_push_tail (tracker->unverified_predictions, op);
|
|
|
|
}
|
|
|
|
|
2009-06-14 08:04:28 -04:00
|
|
|
if (!tracker->predicted_stack ||
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_stack_op_apply (tracker, op, tracker->predicted_stack, APPLY_DEFAULT))
|
2009-06-14 08:04:28 -04:00
|
|
|
meta_stack_tracker_queue_sync_stack (tracker);
|
|
|
|
|
2014-05-07 12:25:58 -04:00
|
|
|
if (free_at_end)
|
|
|
|
meta_stack_op_free (op);
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
meta_stack_tracker_dump (tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_add (MetaStackTracker *tracker,
|
|
|
|
guint64 window,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = g_slice_new (MetaStackOp);
|
|
|
|
|
|
|
|
op->any.type = STACK_OP_ADD;
|
|
|
|
op->any.serial = serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op->any.window = window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
stack_tracker_apply_prediction (tracker, op);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_remove (MetaStackTracker *tracker,
|
|
|
|
guint64 window,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = g_slice_new (MetaStackOp);
|
|
|
|
|
|
|
|
op->any.type = STACK_OP_REMOVE;
|
|
|
|
op->any.serial = serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op->any.window = window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
stack_tracker_apply_prediction (tracker, op);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_restack_windows (MetaStackTracker *tracker,
|
|
|
|
const guint64 *windows,
|
|
|
|
int n_windows,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
int i;
|
2012-04-05 06:22:13 -04:00
|
|
|
int n_x_windows = 0;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
/* XRestackWindows() isn't actually a X requests - it's broken down
|
|
|
|
* by XLib into a series of XConfigureWindow(StackMode=below); we
|
2012-04-05 06:22:13 -04:00
|
|
|
* mirror that here.
|
|
|
|
*
|
|
|
|
* Since there may be a mixture of X and wayland windows in the
|
|
|
|
* stack it's ambiguous which operations we should associate with an
|
|
|
|
* X serial number. One thing we do know though is that there will
|
|
|
|
* be (n_x_window - 1) X requests made.
|
2009-06-13 16:45:32 -04:00
|
|
|
*
|
|
|
|
* Aside: Having a separate StackOp for this would be possible to
|
|
|
|
* get some extra efficiency in memory allocation and in applying
|
|
|
|
* the op, at the expense of a code complexity. Implementation hint
|
|
|
|
* for that - keep op->restack_window.n_complete, and when receiving
|
|
|
|
* events with intermediate serials, set n_complete rather than
|
|
|
|
* removing the op from the queue.
|
|
|
|
*/
|
2014-09-08 21:20:14 -04:00
|
|
|
if (n_windows && META_STACK_ID_IS_X11 (windows[0]))
|
2012-04-05 06:22:13 -04:00
|
|
|
n_x_windows++;
|
2009-06-13 16:45:32 -04:00
|
|
|
for (i = 0; i < n_windows - 1; i++)
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 lower = windows[i + 1];
|
2012-04-05 06:22:13 -04:00
|
|
|
gboolean involves_x = FALSE;
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (lower))
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
|
|
|
n_x_windows++;
|
|
|
|
|
|
|
|
/* Since the first X window is a reference point we only
|
|
|
|
* assoicate a serial number with the operations involving
|
|
|
|
* later X windows. */
|
|
|
|
if (n_x_windows > 1)
|
|
|
|
involves_x = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_lower_below (tracker, lower, windows[i],
|
2012-04-05 06:22:13 -04:00
|
|
|
involves_x ? serial++ : 0);
|
|
|
|
}
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_raise_above (MetaStackTracker *tracker,
|
|
|
|
guint64 window,
|
|
|
|
guint64 sibling,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = g_slice_new (MetaStackOp);
|
|
|
|
|
|
|
|
op->any.type = STACK_OP_RAISE_ABOVE;
|
|
|
|
op->any.serial = serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op->any.window = window;
|
|
|
|
op->raise_above.sibling = sibling;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
stack_tracker_apply_prediction (tracker, op);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_lower_below (MetaStackTracker *tracker,
|
|
|
|
guint64 window,
|
|
|
|
guint64 sibling,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = g_slice_new (MetaStackOp);
|
|
|
|
|
|
|
|
op->any.type = STACK_OP_LOWER_BELOW;
|
|
|
|
op->any.serial = serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op->any.window = window;
|
|
|
|
op->lower_below.sibling = sibling;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
stack_tracker_apply_prediction (tracker, op);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_lower (MetaStackTracker *tracker,
|
|
|
|
guint64 window,
|
|
|
|
gulong serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_stack_tracker_record_raise_above (tracker, window, None, serial);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
static void
|
|
|
|
stack_tracker_event_received (MetaStackTracker *tracker,
|
|
|
|
MetaStackOp *op)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
gboolean need_sync = FALSE;
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
/* If the event is older than our initial query, then it's
|
|
|
|
* already included in our tree. Just ignore it. */
|
|
|
|
if (op->any.serial < tracker->xserver_serial)
|
|
|
|
return;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_stack_op_dump (tracker, op, "Stack op event received: ", "\n");
|
2009-06-13 16:45:32 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
/* First we apply any operations that we have queued up that depended
|
|
|
|
* on X operations *older* than what we received .. those operations
|
|
|
|
* must have been ignored by the X server, so we just apply the
|
|
|
|
* operations we have as best as possible while not moving windows.
|
|
|
|
*/
|
2012-04-05 06:22:13 -04:00
|
|
|
while (tracker->unverified_predictions->head)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
MetaStackOp *queued_op = tracker->unverified_predictions->head->data;
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
if (queued_op->any.serial >= op->any.serial)
|
2009-06-13 16:45:32 -04:00
|
|
|
break;
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_stack_op_apply (tracker, queued_op, tracker->verified_stack,
|
|
|
|
NO_RESTACK_X_WINDOWS);
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
g_queue_pop_head (tracker->unverified_predictions);
|
2009-06-13 16:45:32 -04:00
|
|
|
meta_stack_op_free (queued_op);
|
2014-09-09 13:41:27 -04:00
|
|
|
need_sync = TRUE;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
/* Then we apply the received event. If it's a spontaneous event
|
|
|
|
* based on stacking we didn't trigger, this is the only handling. If we
|
|
|
|
* triggered it, we do the X restacking here, and then any residual
|
|
|
|
* local-only Wayland stacking below.
|
2012-04-05 06:22:13 -04:00
|
|
|
*/
|
2014-09-09 13:41:27 -04:00
|
|
|
if (meta_stack_op_apply (tracker, op, tracker->verified_stack,
|
|
|
|
IGNORE_NOOP_X_RESTACK))
|
|
|
|
need_sync = TRUE;
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
/* What is left to process is the prediction corresponding to the event
|
|
|
|
* (if any), and then any subsequent Wayland-only events we can just
|
|
|
|
* go ahead and do now.
|
|
|
|
*/
|
|
|
|
while (tracker->unverified_predictions->head)
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
2014-09-09 13:41:27 -04:00
|
|
|
MetaStackOp *queued_op = tracker->unverified_predictions->head->data;
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
if (queued_op->any.serial > op->any.serial)
|
|
|
|
break;
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_stack_op_apply (tracker, queued_op, tracker->verified_stack,
|
|
|
|
NO_RESTACK_X_WINDOWS);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
g_queue_pop_head (tracker->unverified_predictions);
|
|
|
|
meta_stack_op_free (queued_op);
|
|
|
|
need_sync = TRUE;
|
2012-04-05 06:22:13 -04:00
|
|
|
}
|
|
|
|
|
2014-09-09 13:41:27 -04:00
|
|
|
if (need_sync)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2010-11-13 14:07:07 -05:00
|
|
|
if (tracker->predicted_stack)
|
|
|
|
{
|
|
|
|
g_array_free (tracker->predicted_stack, TRUE);
|
|
|
|
tracker->predicted_stack = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
meta_stack_tracker_queue_sync_stack (tracker);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
meta_stack_tracker_dump (tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stack_tracker_create_event (MetaStackTracker *tracker,
|
|
|
|
XCreateWindowEvent *event)
|
|
|
|
{
|
|
|
|
MetaStackOp op;
|
|
|
|
|
|
|
|
op.any.type = STACK_OP_ADD;
|
|
|
|
op.any.serial = event->serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op.add.window = event->window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
stack_tracker_event_received (tracker, &op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stack_tracker_destroy_event (MetaStackTracker *tracker,
|
|
|
|
XDestroyWindowEvent *event)
|
|
|
|
{
|
|
|
|
MetaStackOp op;
|
|
|
|
|
|
|
|
op.any.type = STACK_OP_REMOVE;
|
|
|
|
op.any.serial = event->serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op.remove.window = event->window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
stack_tracker_event_received (tracker, &op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stack_tracker_reparent_event (MetaStackTracker *tracker,
|
|
|
|
XReparentEvent *event)
|
|
|
|
{
|
|
|
|
if (event->parent == event->event)
|
|
|
|
{
|
|
|
|
MetaStackOp op;
|
|
|
|
|
|
|
|
op.any.type = STACK_OP_ADD;
|
|
|
|
op.any.serial = event->serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op.add.window = event->window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
stack_tracker_event_received (tracker, &op);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MetaStackOp op;
|
|
|
|
|
|
|
|
op.any.type = STACK_OP_REMOVE;
|
|
|
|
op.any.serial = event->serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op.remove.window = event->window;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
stack_tracker_event_received (tracker, &op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_stack_tracker_configure_event (MetaStackTracker *tracker,
|
|
|
|
XConfigureEvent *event)
|
|
|
|
{
|
|
|
|
MetaStackOp op;
|
|
|
|
|
|
|
|
op.any.type = STACK_OP_RAISE_ABOVE;
|
|
|
|
op.any.serial = event->serial;
|
2014-09-08 21:20:14 -04:00
|
|
|
op.raise_above.window = event->window;
|
|
|
|
op.raise_above.sibling = event->above;
|
2009-06-13 16:45:32 -04:00
|
|
|
|
|
|
|
stack_tracker_event_received (tracker, &op);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_stack_tracker_get_stack:
|
|
|
|
* @tracker: a #MetaStackTracker
|
|
|
|
* @windows: location to store list of windows, or %NULL
|
|
|
|
* @n_windows: location to store count of windows, or %NULL
|
|
|
|
*
|
2013-02-15 13:42:08 -05:00
|
|
|
* @windows will contain the most current view we have of the stacking order
|
2009-06-13 16:45:32 -04:00
|
|
|
* of the children of the root window. The returned array contains
|
|
|
|
* everything: InputOnly windows, override-redirect windows,
|
|
|
|
* hidden windows, etc. Some of these will correspond to MetaWindow
|
|
|
|
* objects, others won't.
|
|
|
|
*
|
|
|
|
* Assuming that no other clients have made requests that change
|
|
|
|
* the stacking order since we last received a notification, the
|
|
|
|
* returned list of windows is exactly that you'd get as the
|
|
|
|
* children when calling XQueryTree() on the root window.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_stack_tracker_get_stack (MetaStackTracker *tracker,
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 **windows,
|
2009-06-13 16:45:32 -04:00
|
|
|
int *n_windows)
|
|
|
|
{
|
|
|
|
GArray *stack;
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
if (tracker->unverified_predictions->length == 0)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
2012-04-05 06:22:13 -04:00
|
|
|
stack = tracker->verified_stack;
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tracker->predicted_stack == NULL)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
tracker->predicted_stack = copy_stack (tracker->verified_stack);
|
|
|
|
for (l = tracker->unverified_predictions->head; l; l = l->next)
|
2009-06-13 16:45:32 -04:00
|
|
|
{
|
|
|
|
MetaStackOp *op = l->data;
|
2014-09-09 13:41:27 -04:00
|
|
|
meta_stack_op_apply (tracker, op, tracker->predicted_stack, APPLY_DEFAULT);
|
2009-06-13 16:45:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stack = tracker->predicted_stack;
|
|
|
|
}
|
|
|
|
|
2012-04-05 06:22:13 -04:00
|
|
|
meta_topic (META_DEBUG_STACK, "Get Stack\n");
|
|
|
|
meta_stack_tracker_dump (tracker);
|
|
|
|
|
2009-06-13 16:45:32 -04:00
|
|
|
if (windows)
|
2014-09-08 21:20:14 -04:00
|
|
|
*windows = (guint64 *)stack->data;
|
2009-06-13 16:45:32 -04:00
|
|
|
if (n_windows)
|
|
|
|
*n_windows = stack->len;
|
|
|
|
}
|
2009-06-14 08:04:28 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_stack_tracker_sync_stack:
|
|
|
|
* @tracker: a #MetaStackTracker
|
|
|
|
*
|
|
|
|
* Informs the compositor of the current stacking order of windows,
|
|
|
|
* based on the predicted view maintained by the #MetaStackTracker.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_stack_tracker_sync_stack (MetaStackTracker *tracker)
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 *windows;
|
2009-06-14 08:04:28 -04:00
|
|
|
GList *meta_windows;
|
|
|
|
int n_windows;
|
|
|
|
int i;
|
|
|
|
|
2009-09-25 15:47:22 -04:00
|
|
|
if (tracker->sync_stack_later)
|
2009-06-14 08:04:28 -04:00
|
|
|
{
|
2009-09-25 15:47:22 -04:00
|
|
|
meta_later_remove (tracker->sync_stack_later);
|
|
|
|
tracker->sync_stack_later = 0;
|
2009-06-14 08:04:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
meta_stack_tracker_get_stack (tracker, &windows, &n_windows);
|
|
|
|
|
|
|
|
meta_windows = NULL;
|
|
|
|
for (i = 0; i < n_windows; i++)
|
|
|
|
{
|
2014-09-08 21:20:14 -04:00
|
|
|
guint64 window = windows[i];
|
2012-04-05 06:22:13 -04:00
|
|
|
|
2014-09-08 21:20:14 -04:00
|
|
|
if (META_STACK_ID_IS_X11 (window))
|
2012-04-05 06:22:13 -04:00
|
|
|
{
|
|
|
|
MetaWindow *meta_window =
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_display_lookup_x_window (tracker->screen->display, (Window)window);
|
2012-04-05 06:22:13 -04:00
|
|
|
|
|
|
|
/* When mapping back from xwindow to MetaWindow we have to be a bit careful;
|
|
|
|
* children of the root could include unmapped windows created by toolkits
|
|
|
|
* for internal purposes, including ones that we have registered in our
|
|
|
|
* XID => window table. (Wine uses a toplevel for _NET_WM_USER_TIME_WINDOW;
|
|
|
|
* see window-prop.c:reload_net_wm_user_time_window() for registration.)
|
|
|
|
*/
|
|
|
|
if (meta_window &&
|
2014-09-08 21:20:14 -04:00
|
|
|
((Window)window == meta_window->xwindow ||
|
|
|
|
(meta_window->frame && (Window)window == meta_window->frame->xwindow)))
|
2012-04-05 06:22:13 -04:00
|
|
|
meta_windows = g_list_prepend (meta_windows, meta_window);
|
|
|
|
}
|
|
|
|
else
|
2014-09-08 21:20:14 -04:00
|
|
|
meta_windows = g_list_prepend (meta_windows,
|
|
|
|
meta_display_lookup_stamp (tracker->screen->display, window));
|
2009-06-14 08:04:28 -04:00
|
|
|
}
|
|
|
|
|
2014-03-18 17:06:42 -04:00
|
|
|
meta_compositor_sync_stack (tracker->screen->display->compositor,
|
|
|
|
meta_windows);
|
2009-06-14 08:04:28 -04:00
|
|
|
g_list_free (meta_windows);
|
|
|
|
|
|
|
|
meta_screen_restacked (tracker->screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-09-25 15:47:22 -04:00
|
|
|
stack_tracker_sync_stack_later (gpointer data)
|
2009-06-14 08:04:28 -04:00
|
|
|
{
|
|
|
|
meta_stack_tracker_sync_stack (data);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_stack_tracker_queue_sync_stack:
|
|
|
|
* @tracker: a #MetaStackTracker
|
|
|
|
*
|
|
|
|
* Queue informing the compositor of the new stacking order before the
|
|
|
|
* next redraw. (See meta_stack_tracker_sync_stack()). This is called
|
|
|
|
* internally when the stack of X windows changes, but also needs be
|
|
|
|
* called directly when we an undecorated window is first shown or
|
|
|
|
* withdrawn since the compositor's stacking order (which contains only
|
|
|
|
* the windows that have a corresponding MetaWindow) will change without
|
|
|
|
* any change to the stacking order of the X windows, if we are creating
|
|
|
|
* or destroying MetaWindows.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_stack_tracker_queue_sync_stack (MetaStackTracker *tracker)
|
|
|
|
{
|
2009-09-25 15:47:22 -04:00
|
|
|
if (tracker->sync_stack_later == 0)
|
2009-06-14 08:04:28 -04:00
|
|
|
{
|
2013-03-14 16:55:49 -04:00
|
|
|
tracker->sync_stack_later = meta_later_add (META_LATER_SYNC_STACK,
|
2009-09-25 15:47:22 -04:00
|
|
|
stack_tracker_sync_stack_later,
|
2009-06-14 08:04:28 -04:00
|
|
|
tracker, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|