blob: 7c24ed3b0c13c20209681bb9bf1971f849dfd28d [file] [log] [blame]
// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <set>
#include <tr1/memory>
#include <gtest/gtest_prod.h> // for FRIEND_TEST() macro
#include "window_manager/clutter_interface.h"
extern "C" {
#include <X11/Xlib.h>
typedef ::Window XWindow;
namespace chromeos {
class Window;
class XConnection;
// Used to stack X11 client windows and Clutter actors. StackingManager creates
// a window and an actor to use as reference points for each logical stacking
// layer and provides methods to move windows and actors between layers.
class StackingManager {
// The layer reference points will be created at the top of the current stack
// of X windows and children of the default Clutter stage.
StackingManager(XConnection* xconn, ClutterInterface* clutter);
// Layers into which windows can be stacked, in top-to-bottom order.
enum Layer {
// Debugging objects that should be positioned above everything else.
// Hotkey overlay images.
// A collapsed panel as it's being dragged. This is a separate layer so
// that the panel's shadow will be cast over stationary collapsed panels.
// Stationary collapsed panels (more specifically, their titlebars)
// across the bottom of the screen.
// The panel bar itself.
// An expanded panel as it's being dragged.
// Stationary expanded panels.
// Window representing a Chrome tab as it's being dragged out of the
// tab summary window.
// Tab summary popup displayed when hovering over a window in overview
// mode.
// Toplevel windows, along with their transient windows and input
// windows.
// The background image.
// Is the passed-in X window one of our internal windows?
bool IsInternalWindow(XWindow xid) {
return (xids_.find(xid) != xids_.end());
// Stack a window (both its X window and its Clutter actor) at the top of the
// passed-in layer. Its shadow will be stacked at the bottom of the layer so
// as to not appear above the windows' siblings. Returns false if the X
// request fails.
bool StackWindowAtTopOfLayer(Window* win, Layer layer);
// Stack an X window at the top of the passed-in layer. This is useful for X
// windows that don't have Window objects associated with them (e.g. input
// windows). Returns false if the X request fails.
bool StackXidAtTopOfLayer(XWindow xid, Layer layer);
// Stack a Clutter actor at the top of the passed-in layer.
void StackActorAtTopOfLayer(ClutterInterface::Actor* actor, Layer layer);
FRIEND_TEST(LayoutManagerTest, InitialWindowStacking); // uses 'layer_to_*'
// Get a layer's name.
static const char* LayerToName(Layer layer);
XConnection* xconn_; // not owned
// Maps from layers to the corresponding X or Clutter reference points.
// The reference points are stacked at the top of their corresponding
// layer (in other words, the Stack*AtTopOfLayer() methods will stack
// windows and actors directly beneath the corresponding reference
// points).
std::map<Layer, XWindow> layer_to_xid_;
std::map<Layer, std::tr1::shared_ptr<ClutterInterface::Actor> >
// Set we can use for quick lookup of whether an X window belongs to us.
std::set<XWindow> xids_;
} // namespace chromeos