2
2
-*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
5
* ww-layout-tile.c (winwrangler)
5
* This file is part of WinWrangler.
6
6
* Copyright (C) Mikkel Kamstrup Erlandsen 2008 <mikkel.kamstrup@gmail.com>
8
* ww-layout-expand.c is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
13
* ww-layout-expand.c is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with callbacks.c. If not, write to:
20
* The Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor
22
* Boston, MA 02110-1301, USA.
8
* WinWrangler is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* WinWrangler is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
25
23
#ifdef HAVE_CONFIG_H
26
24
# include <config.h>
76
#define is_high(w, h) (h > w)
77
#define is_broad(w, h) (w > h)
78
/* Calculate the maximal rect within a set of blocking windows.
79
* For simplicity this method assumes that all struts are along the screen
80
* edges and expand over the entire screen edge. Ie a standard panel setup. */
82
calculate_bounds (WnckScreen *screen, GList *struts, int *x, int *y, int *bottom_right, int *bottom)
86
int wx, wy, ww, wh; /* current window geom */
87
int edge_l, edge_t, edge_b, edge_r;
88
int screen_w, screen_h;
92
edge_r = wnck_screen_get_width (screen);
93
edge_b = wnck_screen_get_height (screen);
98
for (next = struts; next; next = next->next)
100
win = WNCK_WINDOW (next->data);
101
wnck_window_get_geometry (win, &wx, &wy, &ww, &wh);
103
/* Left side strut */
104
if (is_high(ww, wh) && wx == 0) {
105
edge_l = MAX(edge_l, ww);
109
else if (is_broad(ww, wh) && wy == 0) {
110
edge_t = MAX (edge_t, wh);
113
/* Right side strut */
114
else if (is_high(ww, wh) && (wx+ww) == screen_w) {
115
edge_r = MIN(edge_r, wx);
119
else if (is_broad(ww, wh) && (wy+wh) == screen_h) {
120
edge_b = MIN (edge_b, wy);
124
g_warning ("Desktop layout contains floating element at "
125
"(%d, %d)@%dx%d", wx, wy, ww, wh);
129
g_debug ("Calculated desktop bounds (%d, %d), (%d, %d)",
130
edge_l, edge_t, edge_r, edge_b);
134
*bottom_right = edge_r;
80
140
* @screen: The screen to work on
88
148
ww_layout_tile (WnckScreen *screen,
90
151
WnckWindow *active,
95
156
int cell_w, cell_h;
96
int screen_w, screen_h;
157
int edge_l, edge_t, edge_r, edge_b;
98
159
dim = get_grid_size (windows);
99
g_debug ("Grid is %dx%d\n", dim[0], dim[1]);
101
screen_w = wnck_screen_get_width (screen);
102
screen_h = wnck_screen_get_height (screen);
104
cell_w = screen_w / dim[0];
105
cell_h = screen_h / dim[1];
161
calculate_bounds (screen, struts, &edge_l, &edge_t, &edge_r, &edge_b);
163
cell_w = (edge_r - edge_l) / dim[0];
164
cell_h = (edge_b - edge_t) / dim[1];
166
g_debug ("Grid is %dx%d, with cell size %dx%d\n",
167
dim[0], dim[1], cell_w, cell_h);
107
169
int row = 0, col = 0;
108
170
for (next = windows; next; next = next->next)
110
wnck_window_set_geometry (next->data, WNCK_WINDOW_GRAVITY_CURRENT,
172
g_debug ("set_geom(%d, %d, %d, %d)",
173
col*cell_w + edge_l, row*cell_h + edge_t,
175
wnck_window_set_geometry (next->data, WNCK_WINDOW_GRAVITY_STATIC,
111
176
WW_MOVERESIZE_FLAGS,
112
col*cell_w, row*cell_h,
177
col*cell_w + edge_l, row*cell_h + edge_t,
182
/* Check if we should start a new row */
116
183
if (col == dim[0])