| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "window_manager/stacking_manager.h" | 5 #include "window_manager/stacking_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "window_manager/atom_cache.h" | 10 #include "window_manager/atom_cache.h" |
| 11 #include "window_manager/util.h" | 11 #include "window_manager/util.h" |
| 12 #include "window_manager/window.h" | 12 #include "window_manager/window.h" |
| 13 #include "window_manager/x_connection.h" | 13 #include "window_manager/x_connection.h" |
| 14 | 14 |
| 15 using std::set; | 15 using std::map; |
| 16 using std::string; | 16 using std::string; |
| 17 using std::tr1::shared_ptr; | 17 using std::tr1::shared_ptr; |
| 18 using window_manager::util::FindWithDefault; | 18 using window_manager::util::FindWithDefault; |
| 19 using window_manager::util::XidStr; |
| 19 | 20 |
| 20 namespace window_manager { | 21 namespace window_manager { |
| 21 | 22 |
| 22 StackingManager::StackingManager(XConnection* xconn, | 23 StackingManager::StackingManager(XConnection* xconn, |
| 23 Compositor* compositor, | 24 Compositor* compositor, |
| 24 AtomCache* atom_cache) | 25 AtomCache* atom_cache) |
| 25 : xconn_(xconn) { | 26 : xconn_(xconn) { |
| 26 XWindow root = xconn_->GetRootWindow(); | 27 XWindow root = xconn_->GetRootWindow(); |
| 27 | 28 |
| 28 for (int i = kNumLayers - 1; i >= 0; --i) { | 29 for (int i = kNumLayers - 1; i >= 0; --i) { |
| 29 Layer layer = static_cast<Layer>(i); | 30 Layer layer = static_cast<Layer>(i); |
| 30 string name = StringPrintf("%s layer", LayerToName(layer)); | 31 string name = StringPrintf("%s layer", LayerToName(layer)); |
| 31 | 32 |
| 32 XWindow xid = xconn_->CreateWindow(root, -1, -1, 1, 1, true, true, 0); | 33 XWindow xid = xconn_->CreateWindow(root, -1, -1, 1, 1, true, true, 0); |
| 33 xconn_->SetStringProperty(xid, atom_cache->GetXAtom(ATOM_WM_NAME), name); | 34 xconn_->SetStringProperty(xid, atom_cache->GetXAtom(ATOM_WM_NAME), name); |
| 34 xconn_->SetStringProperty( | 35 xconn_->SetStringProperty( |
| 35 xid, atom_cache->GetXAtom(ATOM_NET_WM_NAME), name); | 36 xid, atom_cache->GetXAtom(ATOM_NET_WM_NAME), name); |
| 36 layer_to_xid_[layer] = xid; | 37 layer_to_xid_[layer] = xid; |
| 37 xids_.insert(xid); | 38 xid_to_layer_[xid] = layer; |
| 38 | 39 |
| 39 shared_ptr<Compositor::Actor> actor(compositor->CreateGroup()); | 40 shared_ptr<Compositor::Actor> actor(compositor->CreateGroup()); |
| 40 actor->SetName(name); | 41 actor->SetName(StringPrintf("%s %s", name.c_str(), XidStr(xid).c_str())); |
| 41 actor->SetVisibility(false); | 42 actor->SetVisibility(false); |
| 42 compositor->GetDefaultStage()->AddActor(actor.get()); | 43 compositor->GetDefaultStage()->AddActor(actor.get()); |
| 43 actor->RaiseToTop(); | 44 actor->RaiseToTop(); |
| 44 layer_to_actor_[layer] = actor; | 45 layer_to_actor_[layer] = actor; |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 | 48 |
| 48 StackingManager::~StackingManager() { | 49 StackingManager::~StackingManager() { |
| 49 for (set<XWindow>::const_iterator it = xids_.begin(); it != xids_.end(); ++it) | 50 for (map<XWindow, Layer>::const_iterator it = xid_to_layer_.begin(); |
| 50 xconn_->DestroyWindow(*it); | 51 it != xid_to_layer_.end(); ++it) |
| 52 xconn_->DestroyWindow(it->first); |
| 51 } | 53 } |
| 52 | 54 |
| 53 bool StackingManager::StackWindowAtTopOfLayer(Window* win, Layer layer) { | 55 bool StackingManager::StackWindowAtTopOfLayer(Window* win, Layer layer) { |
| 54 DCHECK(win); | 56 DCHECK(win); |
| 55 | 57 |
| 56 Compositor::Actor* layer_actor = GetActorForLayer(layer); | 58 Compositor::Actor* layer_actor = GetActorForLayer(layer); |
| 57 | 59 |
| 58 // Find the next-lowest layer so we can stack the window's shadow | 60 // Find the next-lowest layer so we can stack the window's shadow |
| 59 // directly above it. | 61 // directly above it. |
| 60 // TODO: This won't work for the bottom layer; write additional code to | 62 // TODO: This won't work for the bottom layer; write additional code to |
| (...skipping 28 matching lines...) Expand all Loading... |
| 89 if (above) | 91 if (above) |
| 90 win->StackCompositedAbove(sibling->actor(), lower_layer_actor, true); | 92 win->StackCompositedAbove(sibling->actor(), lower_layer_actor, true); |
| 91 else | 93 else |
| 92 win->StackCompositedBelow(sibling->actor(), lower_layer_actor, true); | 94 win->StackCompositedBelow(sibling->actor(), lower_layer_actor, true); |
| 93 | 95 |
| 94 return above ? | 96 return above ? |
| 95 win->StackClientAbove(sibling->xid()) : | 97 win->StackClientAbove(sibling->xid()) : |
| 96 win->StackClientBelow(sibling->xid()); | 98 win->StackClientBelow(sibling->xid()); |
| 97 } | 99 } |
| 98 | 100 |
| 101 Compositor::Actor* StackingManager::GetActorIfLayerXid(XWindow xid) { |
| 102 map<XWindow, Layer>::const_iterator it = xid_to_layer_.find(xid); |
| 103 if (it == xid_to_layer_.end()) |
| 104 return NULL; |
| 105 return GetActorForLayer(it->second); |
| 106 } |
| 107 |
| 99 // static | 108 // static |
| 100 const char* StackingManager::LayerToName(Layer layer) { | 109 const char* StackingManager::LayerToName(Layer layer) { |
| 101 switch (layer) { | 110 switch (layer) { |
| 102 case LAYER_DEBUGGING: return "debugging"; | 111 case LAYER_DEBUGGING: return "debugging"; |
| 103 case LAYER_HOTKEY_OVERLAY: return "hotkey overlay"; | 112 case LAYER_HOTKEY_OVERLAY: return "hotkey overlay"; |
| 104 case LAYER_FULLSCREEN_PANEL: return "fullscreen panel"; | 113 case LAYER_FULLSCREEN_PANEL: return "fullscreen panel"; |
| 105 case LAYER_DRAGGED_PANEL: return "dragged panel"; | 114 case LAYER_DRAGGED_PANEL: return "dragged panel"; |
| 106 case LAYER_ACTIVE_TRANSIENT_WINDOW: return "active transient window"; | 115 case LAYER_ACTIVE_TRANSIENT_WINDOW: return "active transient window"; |
| 107 case LAYER_PANEL_BAR_INPUT_WINDOW: return "panel bar input window"; | 116 case LAYER_PANEL_BAR_INPUT_WINDOW: return "panel bar input window"; |
| 108 case LAYER_STATIONARY_PANEL_IN_BAR: return "static panel in bar"; | 117 case LAYER_STATIONARY_PANEL_IN_BAR: return "static panel in bar"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 return layer_actor.get(); | 132 return layer_actor.get(); |
| 124 } | 133 } |
| 125 | 134 |
| 126 XWindow StackingManager::GetXidForLayer(Layer layer) { | 135 XWindow StackingManager::GetXidForLayer(Layer layer) { |
| 127 XWindow xid = FindWithDefault(layer_to_xid_, layer, static_cast<XWindow>(0)); | 136 XWindow xid = FindWithDefault(layer_to_xid_, layer, static_cast<XWindow>(0)); |
| 128 CHECK(xid) << "Invalid layer " << layer; | 137 CHECK(xid) << "Invalid layer " << layer; |
| 129 return xid; | 138 return xid; |
| 130 } | 139 } |
| 131 | 140 |
| 132 } // namespace window_manager | 141 } // namespace window_manager |
| OLD | NEW |