summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathias <mathias>2006-04-19 05:18:10 (GMT)
committermathias <mathias>2006-04-19 05:18:10 (GMT)
commitc92942270aedbac763b98d934dad292f0becd915 (patch)
treeaa64fbfdc768f6112d968cc4b4c1a5c017e86005
parent38a96263ade32c7dba9d24d431836220232d6637 (diff)
downloadfluxbox_lack-c92942270aedbac763b98d934dad292f0becd915.zip
fluxbox_lack-c92942270aedbac763b98d934dad292f0becd915.tar.bz2
windows keep relative positions in ArrangeWindows, based on distance to new 'cell' center
-rw-r--r--ChangeLog2
-rw-r--r--src/WorkspaceCmd.cc69
2 files changed, 48 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index da8e420..d3aeba7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
1(Format: Year/Month/Day) 1(Format: Year/Month/Day)
2Changes for 0.9.16: 2Changes for 0.9.16:
3*06/04/19: 3*06/04/19:
4 * Windows keep relative position in ArrangeWindows (Mathias)
5 WorkspaceCmd.cc
4 * Made fbgm more pure bourne-compatibel (Mathias) 6 * Made fbgm more pure bourne-compatibel (Mathias)
5 fluxbox-generate_menu.in 7 fluxbox-generate_menu.in
6*06/04/18: 8*06/04/18:
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index 9951e0e..f98db1a 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -53,9 +53,9 @@ void NextWindowCmd::execute() {
53 if (mods == 0) // can't stacked cycle unless there is a mod to grab 53 if (mods == 0) // can't stacked cycle unless there is a mod to grab
54 screen->focusControl().nextFocus(m_option | FocusControl::CYCLELINEAR); 54 screen->focusControl().nextFocus(m_option | FocusControl::CYCLELINEAR);
55 else { 55 else {
56 // if stacked cycling, then set a watch for 56 // if stacked cycling, then set a watch for
57 // the release of exactly these modifiers 57 // the release of exactly these modifiers
58 if (!fb->watchingScreen() && 58 if (!fb->watchingScreen() &&
59 !(m_option & FocusControl::CYCLELINEAR)) 59 !(m_option & FocusControl::CYCLELINEAR))
60 Fluxbox::instance()->watchKeyRelease(*screen, mods); 60 Fluxbox::instance()->watchKeyRelease(*screen, mods);
61 screen->focusControl().nextFocus(m_option); 61 screen->focusControl().nextFocus(m_option);
@@ -76,9 +76,9 @@ void PrevWindowCmd::execute() {
76 if (mods == 0) // can't stacked cycle unless there is a mod to grab 76 if (mods == 0) // can't stacked cycle unless there is a mod to grab
77 screen->focusControl().prevFocus(m_option | FocusControl::CYCLELINEAR); 77 screen->focusControl().prevFocus(m_option | FocusControl::CYCLELINEAR);
78 else { 78 else {
79 // if stacked cycling, then set a watch for 79 // if stacked cycling, then set a watch for
80 // the release of exactly these modifiers 80 // the release of exactly these modifiers
81 if (!fb->watchingScreen() 81 if (!fb->watchingScreen()
82 && !(m_option & FocusControl::CYCLELINEAR)) 82 && !(m_option & FocusControl::CYCLELINEAR))
83 Fluxbox::instance()->watchKeyRelease(*screen, mods); 83 Fluxbox::instance()->watchKeyRelease(*screen, mods);
84 screen->focusControl().prevFocus(m_option); 84 screen->focusControl().prevFocus(m_option);
@@ -145,17 +145,17 @@ void ArrangeWindowsCmd::execute() {
145 145
146 Workspace *space = screen->currentWorkspace(); 146 Workspace *space = screen->currentWorkspace();
147 size_t win_count = space->windowList().size(); 147 size_t win_count = space->windowList().size();
148 148
149 if (win_count == 0) 149 if (win_count == 0)
150 return; 150 return;
151 151
152 // TODO: choice between 152 // TODO: choice between
153 // - arrange using all windows on all heads 153 // - arrange using all windows on all heads
154 // - arrange for each head 154 // - arrange for each head
155 // - only on current head 155 // - only on current head
156 const int head = screen->getCurrHead(); 156 const int head = screen->getCurrHead();
157 Workspace::Windows::iterator win; 157 Workspace::Windows::iterator win;
158 158
159 Workspace::Windows normal_windows; 159 Workspace::Windows normal_windows;
160 Workspace::Windows shaded_windows; 160 Workspace::Windows shaded_windows;
161 for(win = space->windowList().begin(); win != space->windowList().end(); win++) { 161 for(win = space->windowList().begin(); win != space->windowList().end(); win++) {
@@ -173,20 +173,20 @@ void ArrangeWindowsCmd::execute() {
173 return; 173 return;
174 174
175 win_count = normal_windows.size(); 175 win_count = normal_windows.size();
176 176
177 const unsigned int max_width = screen->maxRight(head) - screen->maxLeft(head); 177 const unsigned int max_width = screen->maxRight(head) - screen->maxLeft(head);
178 unsigned int max_height = screen->maxBottom(head) - screen->maxTop(head); 178 unsigned int max_height = screen->maxBottom(head) - screen->maxTop(head);
179 179
180 // try to get the same number of rows as columns. 180 // try to get the same number of rows as columns.
181 unsigned int rows = int(sqrt((float)win_count)); // truncate to lower 181 unsigned int cols = int(sqrt((float)win_count)); // truncate to lower
182 unsigned int cols = int(0.99 + float(win_count) / float(rows)); 182 unsigned int rows = int(0.99 + float(win_count) / float(cols));
183 if (max_width<max_height) { // rotate 183 if (max_width<max_height) { // rotate
184 std::swap(cols, rows); 184 std::swap(cols, rows);
185 } 185 }
186 186
187 unsigned int x_offs = screen->maxLeft(head); // window position offset in x 187 unsigned int x_offs = screen->maxLeft(head); // window position offset in x
188 unsigned int y_offs = screen->maxTop(head); // window position offset in y 188 unsigned int y_offs = screen->maxTop(head); // window position offset in y
189 unsigned int window = 0; // current window 189 // unsigned int window = 0; // current window
190 const unsigned int cal_width = max_width/cols; // calculated width ratio (width of every window) 190 const unsigned int cal_width = max_width/cols; // calculated width ratio (width of every window)
191 unsigned int i; 191 unsigned int i;
192 unsigned int j; 192 unsigned int j;
@@ -200,7 +200,7 @@ void ArrangeWindowsCmd::execute() {
200 (*win)->move(x_offs, y_offs); 200 (*win)->move(x_offs, y_offs);
201 else 201 else
202 (*win)->move(screen->maxRight(head) - (*win)->frame().width(), y_offs); 202 (*win)->move(screen->maxRight(head) - (*win)->frame().width(), y_offs);
203 203
204 y_offs += (*win)->frame().height(); 204 y_offs += (*win)->frame().height();
205 } 205 }
206 206
@@ -208,18 +208,41 @@ void ArrangeWindowsCmd::execute() {
208 // with really little space left for the normal windows? how to handle 208 // with really little space left for the normal windows? how to handle
209 // this? 209 // this?
210 if (!shaded_windows.empty()) 210 if (!shaded_windows.empty())
211 max_height -= i * (*shaded_windows.begin())->frame().height(); 211 max_height -= i * (*shaded_windows.begin())->frame().height();
212 212
213 const unsigned int cal_height = max_height/rows; // height ratio (height of every window) 213 const unsigned int cal_height = max_height/rows; // height ratio (height of every window)
214 // Resizes and sets windows positions in columns and rows. 214 // Resizes and sets windows positions in columns and rows.
215 for (i = 0; i < rows; ++i) { 215 for (i = 0; i < rows; ++i) {
216 x_offs = screen->maxLeft(head); 216 x_offs = screen->maxLeft(head);
217 for (j = 0; j < cols && window < win_count; ++j, ++window) { 217 for (j = 0; j < cols && normal_windows.size() > 0; ++j) {
218 if (window!=(win_count-1)) { 218
219 normal_windows[window]->moveResize(x_offs, y_offs, cal_width, cal_height); 219
220 } else { // the last window gets everything that is left. 220 int cell_center_x = x_offs + (x_offs + cal_width) / 2;
221 normal_windows[window]->moveResize(x_offs, y_offs, screen->maxRight(head)-x_offs, cal_height); 221 int cell_center_y = y_offs + (y_offs + cal_height) / 2;
222 } 222 unsigned int closest_dist = ~0;
223
224 Workspace::Windows::iterator closest = normal_windows.end();
225 for (win = normal_windows.begin(); win != normal_windows.end(); win++) {
226
227 int win_center_x = (*win)->frame().x() + ((*win)->frame().x() + (*win)->frame().width() / 2);
228 int win_center_y = (*win)->frame().y() + ((*win)->frame().y() + (*win)->frame().height() / 2);
229 unsigned int dist = (win_center_x - cell_center_x) * (win_center_x - cell_center_x) +
230 (win_center_y - cell_center_y) * (win_center_y - cell_center_y);
231
232 if (dist < closest_dist) {
233 closest = win;
234 closest_dist = dist;
235 }
236 }
237
238 if (normal_windows.size() > 1) {
239 (*closest)->moveResize(x_offs, y_offs, cal_width, cal_height);
240 } else { // the last window gets everything that is left.
241 (*closest)->moveResize(x_offs, y_offs, screen->maxRight(head)-x_offs, cal_height);
242 }
243
244 normal_windows.erase(closest);
245
223 // next x offset 246 // next x offset
224 x_offs += cal_width; 247 x_offs += cal_width;
225 } 248 }