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 | |
parent | 7d793fc6a8d7aa07a7636df2e96054c4a8e2c6a8 (diff) | |
download | fluxbox_lack-ad63de0281bc32180b8f4e70f2570fbae4a0487a.zip fluxbox_lack-ad63de0281bc32180b8f4e70f2570fbae4a0487a.tar.bz2 |
head specific strut
Diffstat (limited to 'src')
-rw-r--r-- | src/HeadArea.cc | 87 | ||||
-rw-r--r-- | src/HeadArea.hh | 48 |
2 files changed, 135 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 | |||
diff --git a/src/HeadArea.hh b/src/HeadArea.hh new file mode 100644 index 0000000..116acf2 --- /dev/null +++ b/src/HeadArea.hh | |||
@@ -0,0 +1,48 @@ | |||
1 | // HeadArea.hh 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 | #ifndef HEADAREA_HH | ||
23 | #define HEADAREA_HH | ||
24 | |||
25 | #include <memory> | ||
26 | #include <list> | ||
27 | |||
28 | #include "FbTk/NotCopyable.hh" | ||
29 | |||
30 | class Strut; | ||
31 | |||
32 | class HeadArea: private FbTk::NotCopyable { | ||
33 | public: | ||
34 | HeadArea(); | ||
35 | |||
36 | Strut *requestStrut(int head, int left, int right, int top, int bottom, Strut* next = 0); | ||
37 | void clearStrut(Strut *str); | ||
38 | bool updateAvailableWorkspaceArea(); | ||
39 | const Strut *availableWorkspaceArea() const { | ||
40 | return m_available_workspace_area.get(); | ||
41 | } | ||
42 | |||
43 | private: | ||
44 | std::auto_ptr<Strut> m_available_workspace_area; | ||
45 | std::list<Strut*> m_strutlist; | ||
46 | }; | ||
47 | |||
48 | #endif // HEADAREA_HH | ||