diff options
author | fluxgen <fluxgen> | 2004-09-11 13:27:10 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2004-09-11 13:27:10 (GMT) |
commit | ad63de0281bc32180b8f4e70f2570fbae4a0487a (patch) | |
tree | a049ca1b1bd5b34541b651417d68b207304aef87 /src/HeadArea.cc | |
parent | 7d793fc6a8d7aa07a7636df2e96054c4a8e2c6a8 (diff) | |
download | fluxbox-ad63de0281bc32180b8f4e70f2570fbae4a0487a.zip fluxbox-ad63de0281bc32180b8f4e70f2570fbae4a0487a.tar.bz2 |
head specific strut
Diffstat (limited to 'src/HeadArea.cc')
-rw-r--r-- | src/HeadArea.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/HeadArea.cc b/src/HeadArea.cc new file mode 100644 index 0000000..67f08ff --- /dev/null +++ b/src/HeadArea.cc | |||
@@ -0,0 +1,87 @@ | |||
1 | // HeadArea.cc for Fluxbox Window Manager | ||
2 | // Copyright (c) 2004 Mathieu De Zutter (mathieu at dezutter.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 = 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 | 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 | |||