1
// MultLayers.cc for FbTk - fluxbox toolkit
2
// Copyright (c) 2003 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
3
// and Simon Bowden (rathnor at users.sourceforge.net)
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
// copy of this software and associated documentation files (the "Software"),
7
// to deal in the Software without restriction, including without limitation
8
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
// and/or sell copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following conditions:
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
// DEALINGS IN THE SOFTWARE.
23
// $Id: MultLayers.cc 3864 2005-01-24 18:02:34Z mathias $
25
#include "MultLayers.hh"
27
#include "XLayerItem.hh"
35
MultLayers::MultLayers(int numlayers) :
38
for (int i=0; i < numlayers; ++i)
39
m_layers.push_back(new XLayer(*this, i));
42
MultLayers::~MultLayers() {
43
while (!m_layers.empty()) {
44
delete m_layers.back();
50
XLayerItem *MultLayers::getLowestItemAboveLayer(int layernum) {
51
if (layernum >= static_cast<signed>(m_layers.size()) || layernum <= 0)
54
layernum--; // next one up
56
while (layernum >= 0 && (item = m_layers[layernum]->getLowestItem()) == 0)
62
XLayerItem *MultLayers::getItemBelow(XLayerItem &item) {
63
XLayer &curr_layer = item.getLayer();
65
// assume that the LayerItem does exist in a layer.
66
XLayerItem *ret = curr_layer.getItemBelow(item);
69
int num = curr_layer.getLayerNum()-1;
70
while (num >= 0 && !ret) {
71
ret = m_layers[num]->getItemBelow(item);
79
XLayerItem *MultLayers::getItemAbove(XLayerItem &item) {
80
XLayer &curr_layer = item.getLayer();
82
// assume that the LayerItem does exist in a layer.
83
XLayerItem *ret = curr_layer.getItemAbove(item);
86
ret = getLowestItemAboveLayer(curr_layer.getLayerNum());
92
void MultLayers::addToTop(XLayerItem &item, int layernum) {
95
else if (layernum >= static_cast<signed>(m_layers.size()))
96
layernum = m_layers.size()-1;
98
m_layers[layernum]->insert(item);
103
// raise the whole layer
104
void MultLayers::raise(XLayer &layer) {
105
int layernum = layer.getLayerNum();
106
if (layernum >= static_cast<signed>(m_layers.size() - 1))
110
// not yet implemented
113
// lower the whole layer
114
void MultLayers::lower(XLayer &layer) {
115
int layernum = layer.getLayerNum();
120
// not yet implemented
123
/* raise the item one level */
124
void MultLayers::raiseLayer(XLayerItem &item) {
125
// get the layer it is in
126
XLayer &curr_layer = item.getLayer();
127
moveToLayer(item, curr_layer.getLayerNum()-1);
130
/* raise the item one level */
131
void MultLayers::lowerLayer(XLayerItem &item) {
132
// get the layer it is in
133
XLayer &curr_layer = item.getLayer();
134
moveToLayer(item, curr_layer.getLayerNum()+1);
137
void MultLayers::moveToLayer(XLayerItem &item, int layernum) {
138
// get the layer it is in
139
XLayer &curr_layer = item.getLayer();
141
// do nothing if the item already is in the requested layer
142
if (curr_layer.getLayerNum() == layernum)
145
// clamp layer number
148
else if (layernum >= static_cast<signed>(m_layers.size()))
149
layernum = m_layers.size()-1;
150
// remove item from old layer and insert it into the
151
item.setLayer(*m_layers[layernum]);
154
void MultLayers::restack() {
158
int layernum=0, winnum=0, size = this->size();
160
Window *winlist = new Window[size];
161
for (layernum=0; layernum < static_cast<signed>(m_layers.size()); layernum++) {
163
XLayer::ItemList::iterator it = m_layers[layernum]->getItemList().begin();
164
XLayer::ItemList::iterator it_end = m_layers[layernum]->getItemList().end();
166
// add all windows from each layeritem in each layer
167
for (; it != it_end; ++it) {
168
XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin();
169
XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end();
170
for (; wit != wit_end; ++wit) {
171
if ((*wit)->window())
172
winlist[winnum++] = (*wit)->window();
177
XRestackWindows(FbTk::App::instance()->display(), winlist, winnum);
182
int MultLayers::size() {
184
for (; i < static_cast<signed>(m_layers.size()); i++) {
185
num += m_layers[i]->countWindows();
190
XLayer *MultLayers::getLayer(size_t num) {
191
if (num >= m_layers.size())
193
return m_layers[num];
196
const XLayer *MultLayers::getLayer(size_t num) const {
197
if (num >= m_layers.size())
199
return m_layers[num];