diff options
Diffstat (limited to 'src/ColSmartPlacement.cc')
-rw-r--r-- | src/ColSmartPlacement.cc | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/ColSmartPlacement.cc b/src/ColSmartPlacement.cc new file mode 100644 index 0000000..abb74d7 --- /dev/null +++ b/src/ColSmartPlacement.cc | |||
@@ -0,0 +1,136 @@ | |||
1 | // ColSmartPlacement.cc | ||
2 | // Copyright (c) 2006 Fluxbox Team (fluxgen at fluxbox 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 | // $Id$ | ||
23 | |||
24 | #include "ColSmartPlacement.hh" | ||
25 | |||
26 | #include "Screen.hh" | ||
27 | #include "ScreenPlacement.hh" | ||
28 | #include "Window.hh" | ||
29 | |||
30 | bool ColSmartPlacement::placeWindow(const std::vector<FluxboxWindow *> &windowlist, | ||
31 | const FluxboxWindow &win, | ||
32 | int &place_x, int &place_y) { | ||
33 | |||
34 | // xinerama head constraints | ||
35 | int head = (signed) win.screen().getCurrHead(); | ||
36 | int head_left = (signed) win.screen().maxLeft(head); | ||
37 | int head_right = (signed) win.screen().maxRight(head); | ||
38 | int head_top = (signed) win.screen().maxTop(head); | ||
39 | int head_bot = (signed) win.screen().maxBottom(head); | ||
40 | |||
41 | bool placed = false; | ||
42 | int next_x, next_y; | ||
43 | const ScreenPlacement &screen_placement = | ||
44 | dynamic_cast<const ScreenPlacement &>(win.screen().placementStrategy()); | ||
45 | |||
46 | bool top_bot = screen_placement.colDirection() == ScreenPlacement::TOPBOTTOM; | ||
47 | bool left_right = screen_placement.rowDirection() == ScreenPlacement::LEFTRIGHT; | ||
48 | |||
49 | int test_x; | ||
50 | |||
51 | int win_w = win.width() + win.fbWindow().borderWidth()*2; | ||
52 | int win_h = win.height() + win.fbWindow().borderWidth()*2; | ||
53 | |||
54 | if (left_right) | ||
55 | test_x = head_left; | ||
56 | else | ||
57 | test_x = head_right - win_w; | ||
58 | |||
59 | int change_y = 1; | ||
60 | if (screen_placement.colDirection() == ScreenPlacement::BOTTOMTOP) | ||
61 | change_y = -1; | ||
62 | |||
63 | while (!placed && | ||
64 | (left_right ? test_x + win_w <= head_right | ||
65 | : test_x >= head_left)) { | ||
66 | |||
67 | if (left_right) | ||
68 | next_x = head_right; // it will get shrunk | ||
69 | else | ||
70 | next_x = head_left-1; | ||
71 | |||
72 | int test_y; | ||
73 | if (top_bot) | ||
74 | test_y = head_top; | ||
75 | else | ||
76 | test_y = head_bot - win_h; | ||
77 | |||
78 | while (!placed && | ||
79 | (top_bot ? test_y + win_h <= head_bot | ||
80 | : test_y >= head_top)) { | ||
81 | placed = true; | ||
82 | |||
83 | next_y = test_y + change_y; | ||
84 | |||
85 | std::vector<FluxboxWindow *>::const_iterator it = | ||
86 | windowlist.begin(); | ||
87 | std::vector<FluxboxWindow *>::const_iterator it_end = | ||
88 | windowlist.end(); | ||
89 | for (; it != it_end && placed; ++it) { | ||
90 | int curr_x = (*it)->x(); | ||
91 | int curr_y = (*it)->y(); | ||
92 | int curr_w = (*it)->width() + (*it)->fbWindow().borderWidth()*2; | ||
93 | int curr_h = (*it)->height() + (*it)->fbWindow().borderWidth()*2; | ||
94 | |||
95 | if (curr_x < test_x + win_w && | ||
96 | curr_x + curr_w > test_x && | ||
97 | curr_y < test_y + win_h && | ||
98 | curr_y + curr_h > test_y) { | ||
99 | // this window is in the way | ||
100 | placed = false; | ||
101 | |||
102 | // we find the next y that we can go to (a window will be in the way | ||
103 | // all the way to its bottom) | ||
104 | if (top_bot) { | ||
105 | if (curr_y + curr_h > next_y) | ||
106 | next_y = curr_y + curr_h; | ||
107 | } else { | ||
108 | if (curr_y - win_h < next_y) | ||
109 | next_y = curr_y - win_h; | ||
110 | } | ||
111 | |||
112 | // but we can only go to the nearest x, since that is where the | ||
113 | // next time current windows in the way will change | ||
114 | if (left_right) { | ||
115 | if (curr_x + curr_w < next_x) | ||
116 | next_x = curr_x + curr_w; | ||
117 | } else { | ||
118 | if (curr_x - win_w > next_x) | ||
119 | next_x = curr_x - win_w; | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | if (placed) { | ||
125 | place_x = test_x; | ||
126 | place_y = test_y; | ||
127 | } | ||
128 | |||
129 | test_y = next_y; | ||
130 | } // end while | ||
131 | |||
132 | test_x = next_x; | ||
133 | } // end while | ||
134 | |||
135 | return placed; | ||
136 | } | ||