~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/HeadArea.cc

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2008-07-01 10:38:14 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701103814-khx2b6il152x9p93
Tags: 1.0.0+deb1-8
* x-dev has been removed from build-depends (out-of-date package).
* Standards-Version bumped to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// HeadArea.cc for Fluxbox Window Manager
2
 
// Copyright (c) 2004 - 2005 Mathieu De Zutter (mathieu at dezutter dot org)
3
 
//
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:
10
 
//
11
 
// The above copyright notice and this permission notice shall be included in
12
 
// all copies or substantial portions of the Software.
13
 
//
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.
21
 
 
22
 
#include "HeadArea.hh"
23
 
#include "Strut.hh"
24
 
 
25
 
#include <algorithm>
26
 
#include <iostream>
27
 
 
28
 
HeadArea::HeadArea() : m_available_workspace_area(new Strut(0,0,0,0,0)) {
29
 
}
30
 
 
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);
34
 
    return str;
35
 
}
36
 
 
37
 
void HeadArea::clearStrut(Strut *str) {
38
 
    if (str == 0)
39
 
        return;
40
 
    // find strut and erase it
41
 
    std::list<Strut *>::iterator pos = std::find(m_strutlist.begin(),
42
 
                                                 m_strutlist.end(),
43
 
                                                 str);
44
 
    if (pos == m_strutlist.end()) {
45
 
        std::cerr << "clearStrut() failed because the strut was not found" << std::endl;
46
 
        return;
47
 
    }
48
 
 
49
 
    m_strutlist.erase(pos);
50
 
    delete str;
51
 
}
52
 
 
53
 
/// helper class for for_each in HeadArea::updateAvailableWorkspaceArea()
54
 
namespace {
55
 
class MaxArea {
56
 
public:
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);
65
 
    }
66
 
private:
67
 
    Strut &m_available_workspace_area;
68
 
};
69
 
 
70
 
} // end anonymous namespace
71
 
 
72
 
bool HeadArea::updateAvailableWorkspaceArea() {
73
 
    // find max of left, right, top and bottom and set avaible workspace area
74
 
 
75
 
    // clear old area
76
 
    Strut oldarea = *(m_available_workspace_area.get());
77
 
    m_available_workspace_area.reset(new Strut(0, 0, 0, 0, 0));
78
 
    
79
 
    // calculate max area
80
 
    std::for_each(m_strutlist.begin(),
81
 
             m_strutlist.end(),
82
 
             MaxArea(*m_available_workspace_area.get()));
83
 
 
84
 
    // only notify if the area changed
85
 
    return !(oldarea == *(m_available_workspace_area.get()));
86
 
}
87