1
// HeadArea.cc for Fluxbox Window Manager
2
// Copyright (c) 2004 - 2005 Mathieu De Zutter (mathieu at dezutter dot org)
4
// Permission is hereby granted, free of charge, to any person obtaining a
5
// copy of this software and associated documentation files (the "Software"),
6
// to deal in the Software without restriction, including without limitation
7
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
// and/or sell copies of the Software, and to permit persons to whom the
9
// Software is furnished to do so, subject to the following conditions:
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
// DEALINGS IN THE SOFTWARE.
22
#include "HeadArea.hh"
28
HeadArea::HeadArea() : m_available_workspace_area(new Strut(0,0,0,0,0)) {
31
Strut *HeadArea::requestStrut(int head, int left, int right, int top, int bottom, Strut* next) {
32
Strut *str = new Strut(head, left, right, top, bottom, next);
33
m_strutlist.push_back(str);
37
void HeadArea::clearStrut(Strut *str) {
40
// find strut and erase it
41
std::list<Strut *>::iterator pos = std::find(m_strutlist.begin(),
44
if (pos == m_strutlist.end()) {
45
std::cerr << "clearStrut() failed because the strut was not found" << std::endl;
49
m_strutlist.erase(pos);
53
/// helper class for for_each in HeadArea::updateAvailableWorkspaceArea()
57
MaxArea(Strut &max_area):m_available_workspace_area(max_area) { }
58
void operator ()(const Strut *str) {
59
static int left, right, bottom, top;
60
left = std::max(m_available_workspace_area.left(), str->left());
61
right = std::max(m_available_workspace_area.right(), str->right());
62
bottom = std::max(m_available_workspace_area.bottom(), str->bottom());
63
top = std::max(m_available_workspace_area.top(), str->top());
64
m_available_workspace_area = Strut(0, left, right, top, bottom);
67
Strut &m_available_workspace_area;
70
} // end anonymous namespace
72
bool HeadArea::updateAvailableWorkspaceArea() {
73
// find max of left, right, top and bottom and set avaible workspace area
76
Strut oldarea = *(m_available_workspace_area.get());
77
m_available_workspace_area.reset(new Strut(0, 0, 0, 0, 0));
80
std::for_each(m_strutlist.begin(),
82
MaxArea(*m_available_workspace_area.get()));
84
// only notify if the area changed
85
return !(oldarea == *(m_available_workspace_area.get()));