summaryrefslogtreecommitdiff
path: root/src/RowSmartPlacement.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/RowSmartPlacement.cc')
-rw-r--r--src/RowSmartPlacement.cc155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/RowSmartPlacement.cc b/src/RowSmartPlacement.cc
new file mode 100644
index 0000000..eb2956b
--- /dev/null
+++ b/src/RowSmartPlacement.cc
@@ -0,0 +1,155 @@
1// RowSmartPlacement.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 "RowSmartPlacement.hh"
25
26#include "Window.hh"
27#include "Screen.hh"
28#include "ScreenPlacement.hh"
29
30bool RowSmartPlacement::placeWindow(const std::vector<FluxboxWindow *> &windowlist,
31 const FluxboxWindow &win,
32 int &place_x, int &place_y) {
33
34 bool placed = false;
35 int next_x, next_y;
36
37 // view (screen + head) constraints
38 int head = (signed) win.screen().getCurrHead();
39 int head_left = (signed) win.screen().maxLeft(head);
40 int head_right = (signed) win.screen().maxRight(head);
41 int head_top = (signed) win.screen().maxTop(head);
42 int head_bot = (signed) win.screen().maxBottom(head);
43
44 const ScreenPlacement &screen_placement =
45 dynamic_cast<const ScreenPlacement &>(win.screen().placementStrategy());
46
47 bool top_bot =
48 screen_placement.colDirection() == ScreenPlacement::TOPBOTTOM;
49 bool left_right =
50 screen_placement.rowDirection() == ScreenPlacement::LEFTRIGHT;
51
52 int change_x = 1, change_y = 1;
53
54 if (screen_placement.colDirection() == ScreenPlacement::BOTTOMTOP)
55 change_y = -1;
56
57 if (screen_placement.rowDirection() == ScreenPlacement::RIGHTLEFT)
58 change_x = -1;
59
60
61
62
63 int win_h = win.height() + win.fbWindow().borderWidth()*2;
64 int win_w = win.width() + win.fbWindow().borderWidth()*2;
65 int test_y;
66 if (top_bot)
67 test_y = head_top;
68 else
69 test_y = head_bot - win_h;
70
71 while (!placed &&
72 (top_bot ? test_y + win_h <= head_bot
73 : test_y >= head_top)) {
74
75 int test_x;
76 if (left_right)
77 test_x = head_left;
78 else
79 test_x = head_right - win_w;
80
81 // The trick here is that we set it to the furthest away one,
82 // then the code brings it back down to the safest one that
83 // we can go to (i.e. the next untested area)
84 if (top_bot)
85 next_y = head_bot; // will be shrunk
86 else
87 next_y = head_top-1;
88
89 while (!placed &&
90 (left_right ? test_x + win_w <= head_right
91 : test_x >= head_left)) {
92
93 placed = true;
94
95 next_x = test_x + change_x;
96
97 std::vector<FluxboxWindow *>::const_iterator win_it =
98 windowlist.begin();
99 std::vector<FluxboxWindow *>::const_iterator win_it_end =
100 windowlist.end();
101
102 for (; win_it != win_it_end && placed; ++win_it) {
103 FluxboxWindow &window = **win_it;
104
105 int curr_x = window.x();
106 int curr_y = window.y();
107 int curr_w = window.width() + window.fbWindow().borderWidth()*2;
108 int curr_h = window.height() + window.fbWindow().borderWidth()*2;
109
110 if (curr_x < test_x + win_w &&
111 curr_x + curr_w > test_x &&
112 curr_y < test_y + win_h &&
113 curr_y + curr_h > test_y) {
114 // this window is in the way
115 placed = false;
116
117 // we find the next x that we can go to (a window will be in the way
118 // all the way to its far side)
119 if (left_right) {
120 if (curr_x + curr_w > next_x)
121 next_x = curr_x + curr_w;
122 } else {
123 if (curr_x - win_w < next_x)
124 next_x = curr_x - win_w;
125 }
126
127 // but we can only go to the nearest y, since that is where the
128 // next time current windows in the way will change
129 if (top_bot) {
130 if (curr_y + curr_h < next_y)
131 next_y = curr_y + curr_h;
132 } else {
133 if (curr_y - win_h > next_y)
134 next_y = curr_y - win_h;
135 }
136 }
137 }
138
139
140 if (placed) {
141 place_x = test_x;
142 place_y = test_y;
143
144 break;
145 }
146
147 test_x = next_x;
148 } // end while
149
150 test_y = next_y;
151 } // end while
152
153
154 return placed;
155}