~kamstrup/winwrangler/winwrangler-0.2

« back to all changes in this revision

Viewing changes to src/ww-layout-tile.c

  • Committer: "Mikkel Kamstrup Erlandsen"
  • Date: 2008-03-03 23:49:40 UTC
  • Revision ID: mikkel.kamstrup@gmail.com-20080303234940-gjc6spmyl2h36s97
Rewrite tile layout to take struts (panels and such) into account.

Fix segfault in -tray

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
   -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- 
3
3
 */
4
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>
7
 
 * 
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.
12
 
 * 
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.
17
 
 * 
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.
 
7
 *
 
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.
 
12
 *  
 
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.
 
17
 *
 
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/>.
23
20
 */
24
21
 
 
22
 
25
23
#ifdef HAVE_CONFIG_H
26
24
#  include <config.h>
27
25
#endif
75
73
        return result;
76
74
}
77
75
 
 
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. */
 
81
void
 
82
calculate_bounds (WnckScreen *screen, GList *struts, int *x, int *y, int *bottom_right, int *bottom)
 
83
{
 
84
        GList           *next;
 
85
        WnckWindow  *win;
 
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;
 
89
        
 
90
        edge_l = 0;
 
91
        edge_t = 0;
 
92
        edge_r = wnck_screen_get_width (screen);
 
93
        edge_b = wnck_screen_get_height (screen);
 
94
        
 
95
        screen_w = edge_r;
 
96
        screen_h = edge_b;
 
97
        
 
98
        for (next = struts; next; next = next->next)
 
99
        {       
 
100
                win = WNCK_WINDOW (next->data);
 
101
                wnck_window_get_geometry (win, &wx, &wy, &ww, &wh);
 
102
                
 
103
                /* Left side strut */
 
104
                if (is_high(ww, wh) && wx == 0) {
 
105
                        edge_l = MAX(edge_l, ww);
 
106
                }
 
107
                
 
108
                /* Top struct */
 
109
                else if (is_broad(ww, wh) && wy == 0) {
 
110
                        edge_t = MAX (edge_t, wh);
 
111
                }
 
112
                
 
113
                /* Right side strut */
 
114
                else if (is_high(ww, wh) && (wx+ww) == screen_w) {
 
115
                        edge_r = MIN(edge_r, wx);
 
116
                }
 
117
                
 
118
                /* Bottom struct */
 
119
                else if (is_broad(ww, wh) && (wy+wh) == screen_h) {
 
120
                        edge_b = MIN (edge_b, wy);
 
121
                }
 
122
                
 
123
                else {
 
124
                        g_warning ("Desktop layout contains floating element at "
 
125
                                           "(%d, %d)@%dx%d", wx, wy, ww, wh);
 
126
                }
 
127
        }
 
128
        
 
129
        g_debug ("Calculated desktop bounds (%d, %d), (%d, %d)",
 
130
                         edge_l, edge_t, edge_r, edge_b);
 
131
        
 
132
        *x = edge_l;
 
133
        *y = edge_t;
 
134
        *bottom_right = edge_r;
 
135
        *bottom = edge_b;
 
136
}
 
137
 
78
138
/**
79
139
 * ww_layout_tile
80
140
 * @screen: The screen to work on
87
147
void
88
148
ww_layout_tile (WnckScreen      *screen,
89
149
                                GList           *windows,
 
150
                                GList           *struts,
90
151
                                WnckWindow      *active,
91
152
                                GError          **error)
92
153
{
93
154
        GList   *next;
94
155
        int             *dim;
95
156
        int             cell_w, cell_h;
96
 
        int             screen_w, screen_h;
 
157
        int             edge_l, edge_t, edge_r, edge_b;
97
158
        
98
159
        dim = get_grid_size (windows);
99
 
        g_debug ("Grid is %dx%d\n", dim[0], dim[1]);
100
 
        
101
 
        screen_w = wnck_screen_get_width (screen);
102
 
        screen_h = wnck_screen_get_height (screen);
103
 
        
104
 
        cell_w = screen_w / dim[0];
105
 
        cell_h = screen_h / dim[1];
 
160
        
 
161
        calculate_bounds (screen, struts, &edge_l, &edge_t, &edge_r, &edge_b);
 
162
        
 
163
        cell_w = (edge_r - edge_l) / dim[0];
 
164
        cell_h = (edge_b - edge_t) / dim[1];
 
165
 
 
166
        g_debug ("Grid is %dx%d, with cell size %dx%d\n",
 
167
                         dim[0], dim[1], cell_w, cell_h);
106
168
        
107
169
        int row = 0, col = 0;
108
170
        for (next = windows; next; next = next->next)
109
171
        {
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,
 
174
                                 cell_w, cell_h);
 
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,
113
178
                                                                  cell_w, cell_h);
114
179
                
115
180
                col++;
 
181
                
 
182
                /* Check if we should start a new row */
116
183
                if (col == dim[0])
117
184
                {
118
185
                        col = 0;
119
186
                        row++;
 
187
                        
120
188
                }               
121
189
        }
122
190