~ubuntu-branches/ubuntu/precise/xfwm4/precise-proposed

1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
1
/*      $Id: workspaces.c 24099 2006-12-13 22:01:17Z olivier $
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
2
1 by Simon Huggins
Import upstream version 4.0.5
3
        This program is free software; you can redistribute it and/or modify
4
        it under the terms of the GNU General Public License as published by
1.1.1 by Simon Huggins
Import upstream version 4.0.6
5
        the Free Software Foundation; either version 2, or (at your option)
6
        any later version.
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
7
1 by Simon Huggins
Import upstream version 4.0.5
8
        This program is distributed in the hope that it will be useful,
9
        but WITHOUT ANY WARRANTY; without even the implied warranty of
10
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
        GNU General Public License for more details.
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
12
1 by Simon Huggins
Import upstream version 4.0.5
13
        You should have received a copy of the GNU General Public License
14
        along with this program; if not, write to the Free Software
15
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
16
1 by Simon Huggins
Import upstream version 4.0.5
17
        oroborus - (c) 2001 Ken Lynch
1.1.5 by Jani Monoses
Import upstream version 4.3.0svn+r20220
18
        xfwm4    - (c) 2002-2006 Olivier Fourdan
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
19
1 by Simon Huggins
Import upstream version 4.0.5
20
 */
21
22
#ifdef HAVE_CONFIG_H
23
#include <config.h>
24
#endif
25
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
26
#include <X11/X.h>
1 by Simon Huggins
Import upstream version 4.0.5
27
#include <X11/Xlib.h>
28
#include <X11/Xutil.h>
29
#include <X11/Xmd.h>
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
30
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
31
#include <glib.h>
32
#include <gdk/gdk.h>
1 by Simon Huggins
Import upstream version 4.0.5
33
#include <gtk/gtk.h>
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
34
#include <libxfce4util/libxfce4util.h>
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
35
36
#include "display.h"
37
#include "screen.h"
1 by Simon Huggins
Import upstream version 4.0.5
38
#include "misc.h"
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
39
#include "transients.h"
1 by Simon Huggins
Import upstream version 4.0.5
40
#include "workspaces.h"
41
#include "settings.h"
42
#include "client.h"
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
43
#include "focus.h"
44
#include "stacking.h"
1 by Simon Huggins
Import upstream version 4.0.5
45
#include "hints.h"
46
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
47
static void
48
workspaceGetPosition (ScreenInfo *screen_info, int n, int * row, int * col)
49
{
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
50
    NetWmDesktopLayout l;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
51
    int major_length, minor_length, tmp;
52
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
53
    l = screen_info->desktop_layout;
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
54
    if (l.orientation == NET_WM_ORIENTATION_HORZ)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
55
    {
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
56
        major_length = l.cols;
57
        minor_length = l.rows;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
58
    }
59
    else
60
    {
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
61
        major_length = l.rows;
62
        minor_length = l.cols;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
63
    }
64
65
    *row = n / major_length;
66
    *col = n % major_length;
67
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
68
    switch (l.start)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
69
    {
70
        case NET_WM_TOPRIGHT:
71
            *col = major_length - *col - 1;
72
            break;
73
        case NET_WM_BOTTOMLEFT:
74
            *row = minor_length - *row - 1;
75
            break;
76
        case NET_WM_BOTTOMRIGHT:
77
            *col = major_length - *col - 1;
78
            *row = minor_length - *row - 1;
79
            break;
80
        default:
81
            break;
82
    }
83
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
84
    if (l.orientation == NET_WM_ORIENTATION_VERT)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
85
    {
86
        tmp = *row;
87
        *row = *col;
88
        *col = tmp;
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
89
        if ((l.start == NET_WM_TOPRIGHT) || (l.start == NET_WM_BOTTOMLEFT))
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
90
        {
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
91
            *row = l.rows - *row - 1;
92
            *col = l.cols - *col - 1;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
93
        }
94
    }
95
}
96
97
static int
98
workspaceGetNumber (ScreenInfo *screen_info, int row, int col)
99
{
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
100
    NetWmDesktopLayout l;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
101
    int major_length, minor_length, n, tmp;
102
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
103
    l = screen_info->desktop_layout;
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
104
    if (l.orientation == NET_WM_ORIENTATION_HORZ)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
105
    {
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
106
        major_length = l.cols;
107
        minor_length = l.rows;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
108
    }
109
    else
110
    {
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
111
        major_length = l.rows;
112
        minor_length = l.cols;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
113
    }
114
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
115
    if (l.orientation == NET_WM_ORIENTATION_VERT)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
116
    {
117
        tmp = row;
118
        row = col;
119
        col = tmp;
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
120
        if ((l.start == NET_WM_TOPRIGHT) || (l.start == NET_WM_BOTTOMLEFT))
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
121
        {
122
            row = minor_length - row - 1;
123
            col = major_length - col - 1;
124
        }
125
    }
126
1.1.3 by Jani Monoses
Import upstream version 4.3.0svn+r19872
127
    switch (l.start)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
128
    {
129
        case NET_WM_TOPRIGHT:
130
            col = major_length - col - 1;
131
            break;
132
        case NET_WM_BOTTOMLEFT:
133
            row = minor_length - row - 1;
134
            break;
135
        case NET_WM_BOTTOMRIGHT:
136
            col = major_length - col - 1;
137
            row = minor_length - row - 1;
138
            break;
139
        default:
140
            break;
141
    }
142
143
    n = (row * major_length) + col;
144
    return n;
145
}
146
147
static int
148
modify_with_wrap (int value, int by, int limit, gboolean wrap)
149
{
150
    if (by >= limit) by = limit - 1;
151
    value += by;
152
    if (value >= limit)
153
    {
154
        if (!wrap)
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
155
        {
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
156
            value = limit - 1;
157
        }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
158
        else
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
159
        {
160
            value = value % limit;
161
        }
162
    }
163
    else if (value < 0)
164
    {
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
165
        if (!wrap)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
166
        {
167
            value = 0;
168
        }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
169
        else
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
170
        {
171
            value = (value + limit) % limit;
172
        }
173
    }
174
    return value;
175
}
176
177
/* returns TRUE if the workspace was changed, FALSE otherwise */
178
gboolean
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
179
workspaceMove (ScreenInfo *screen_info, int rowmod, int colmod, Client * c, Time timestamp)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
180
{
181
    int row, col, newrow, newcol, previous_ws, n;
182
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
183
    workspaceGetPosition (screen_info, screen_info->current_ws, &row, &col);
184
    newrow = modify_with_wrap (row, rowmod, screen_info->desktop_layout.rows, screen_info->params->wrap_layout);
185
    newcol = modify_with_wrap (col, colmod, screen_info->desktop_layout.cols, screen_info->params->wrap_layout);
186
    n = workspaceGetNumber (screen_info, newrow, newcol);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
187
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
188
    if (n == screen_info->current_ws)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
189
    {
190
        return FALSE;
191
    }
192
193
    previous_ws = screen_info->current_ws;
194
    if ((n >= 0) && (n < screen_info->workspace_count))
195
    {
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
196
        workspaceSwitch (screen_info, n, c, TRUE, timestamp);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
197
    }
198
    else if (screen_info->params->wrap_layout)
199
    {
200
        if (colmod < 0)
201
        {
202
           n = screen_info->workspace_count - 1;
203
        }
204
        else
205
        {
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
206
            if (colmod > 0)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
207
            {
208
                newcol = 0;
209
            }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
210
            else if (rowmod > 0)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
211
            {
212
                newrow = 0;
213
            }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
214
            else if (rowmod < 0)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
215
            {
216
                newrow--;
217
            }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
218
            else
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
219
            {
220
                return FALSE;
221
            }
222
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
223
            n = workspaceGetNumber (screen_info, newrow, newcol);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
224
        }
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
225
        workspaceSwitch (screen_info, n, c, TRUE, timestamp);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
226
    }
227
228
    return (screen_info->current_ws != previous_ws);
229
}
230
1 by Simon Huggins
Import upstream version 4.0.5
231
void
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
232
workspaceSwitch (ScreenInfo *screen_info, int new_ws, Client * c2, gboolean update_focus, Time timestamp)
1 by Simon Huggins
Import upstream version 4.0.5
233
{
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
234
    DisplayInfo *display_info;
235
    Client *c, *new_focus;
1 by Simon Huggins
Import upstream version 4.0.5
236
    Client *previous;
237
    GList *index;
238
    GList *list_hide;
239
    Window dr, window;
240
    int rx, ry, wx, wy;
241
    unsigned int mask;
242
    unsigned long data[1];
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
243
1 by Simon Huggins
Import upstream version 4.0.5
244
    TRACE ("entering workspaceSwitch");
245
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
246
    display_info = screen_info->display_info;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
247
    if ((new_ws == screen_info->current_ws) && (screen_info->params->toggle_workspaces))
248
    {
249
        new_ws = screen_info->previous_ws;
250
    }
251
252
    if (new_ws == screen_info->current_ws)
253
    {
254
        return;
255
    }
256
257
    if (screen_info->params->wrap_cycle)
258
    {
259
        if (new_ws > screen_info->workspace_count - 1)
260
        {
261
            new_ws = 0;
262
        }
263
        if (new_ws < 0)
264
        {
265
            new_ws = screen_info->workspace_count - 1;
266
        }
267
    }
268
    else if ((new_ws > screen_info->workspace_count - 1) || (new_ws < 0))
269
    {
270
        return;
271
    }
272
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
273
    myScreenGrabPointer (screen_info, EnterWindowMask, None, timestamp);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
274
275
    screen_info->previous_ws = screen_info->current_ws;
276
    screen_info->current_ws = new_ws;
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
277
278
    new_focus = NULL;
279
    list_hide = NULL;
280
    previous  = NULL;
281
    c = clientGetFocus ();
282
1 by Simon Huggins
Import upstream version 4.0.5
283
    if (c2)
284
    {
285
        clientSetWorkspace (c2, new_ws, FALSE);
286
    }
287
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
288
    if (c)
289
    {
290
        if (c->type & WINDOW_REGULAR_FOCUSABLE)
291
        {
292
            previous = c;
293
        }
294
        if (c2 == c)
295
        {
296
            new_focus = c2;
297
        }
298
    }
299
300
    /* First pass: Show, from top to bottom */
301
    for (index = g_list_last(screen_info->windows_stack); index; index = g_list_previous (index))
302
    {
303
        c = (Client *) index->data;
304
        if (FLAG_TEST (c->flags, CLIENT_FLAG_STICKY))
305
        {
306
            clientSetWorkspace (c, new_ws, TRUE);
307
        }
308
        else if (c->win_workspace == new_ws)
309
        {
310
            if (!FLAG_TEST (c->flags, CLIENT_FLAG_ICONIFIED) && !FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
311
            {
312
                if (!clientIsTransientOrModal (c) || !clientTransientOrModalHasAncestor (c, new_ws))
313
                {
314
                    clientShow (c, FALSE);
315
                }
316
            }
317
        }
318
    }
319
320
    /* Second pass: Hide from bottom to top */
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
321
    for (index = screen_info->windows_stack; index; index = g_list_next (index))
1 by Simon Huggins
Import upstream version 4.0.5
322
    {
323
        c = (Client *) index->data;
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
324
        
325
        if (c->win_workspace != new_ws)
1 by Simon Huggins
Import upstream version 4.0.5
326
        {
327
            if (c == previous)
328
            {
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
329
                FLAG_SET (previous->xfwm_flags, XFWM_FLAG_FOCUS);
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
330
                clientSetFocus (screen_info, NULL, timestamp, FOCUS_IGNORE_MODAL);
1 by Simon Huggins
Import upstream version 4.0.5
331
            }
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
332
            if (FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE) && !FLAG_TEST (c->flags, CLIENT_FLAG_STICKY))
1 by Simon Huggins
Import upstream version 4.0.5
333
            {
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
334
                if (!clientIsTransientOrModal (c) || !clientTransientOrModalHasAncestor (c, new_ws))
335
                {
336
                    clientHide (c, new_ws, FALSE);
337
                }
1 by Simon Huggins
Import upstream version 4.0.5
338
            }
339
        }
340
    }
341
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
342
    /* Third pass: Check for focus, from top to bottom */
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
343
    for (index = g_list_last(screen_info->windows_stack); index; index = g_list_previous (index))
1 by Simon Huggins
Import upstream version 4.0.5
344
    {
345
        c = (Client *) index->data;
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
346
        
347
        if (FLAG_TEST (c->flags, CLIENT_FLAG_STICKY))
1 by Simon Huggins
Import upstream version 4.0.5
348
        {
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
349
            if ((!new_focus) && (c == previous) && clientSelectMask (c, 0, WINDOW_REGULAR_FOCUSABLE))
1 by Simon Huggins
Import upstream version 4.0.5
350
            {
351
                new_focus = c;
352
            }
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
353
            FLAG_UNSET (c->xfwm_flags, XFWM_FLAG_FOCUS);
1 by Simon Huggins
Import upstream version 4.0.5
354
        }
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
355
        else if (c->win_workspace == new_ws)
1 by Simon Huggins
Import upstream version 4.0.5
356
        {
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
357
            if ((!new_focus) && FLAG_TEST (c->xfwm_flags, XFWM_FLAG_FOCUS))
1 by Simon Huggins
Import upstream version 4.0.5
358
            {
359
                new_focus = c;
360
            }
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
361
            FLAG_UNSET (c->xfwm_flags, XFWM_FLAG_FOCUS);
1 by Simon Huggins
Import upstream version 4.0.5
362
        }
363
    }
364
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
365
    setHint (display_info, screen_info->xroot, WIN_WORKSPACE, new_ws);
1 by Simon Huggins
Import upstream version 4.0.5
366
    data[0] = new_ws;
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
367
    XChangeProperty (myScreenGetXDisplay (screen_info), screen_info->xroot,
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
368
                     display_info->atoms[NET_CURRENT_DESKTOP], XA_CARDINAL, 32,
369
                     PropModeReplace, (unsigned char *) data, 1);
370
    if (!(screen_info->params->click_to_focus))
1 by Simon Huggins
Import upstream version 4.0.5
371
    {
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
372
        if (!(c2) && (XQueryPointer (myScreenGetXDisplay (screen_info), screen_info->xroot, &dr, &window, &rx, &ry, &wx, &wy, &mask)))
1 by Simon Huggins
Import upstream version 4.0.5
373
        {
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
374
            c = clientAtPosition (screen_info, rx, ry, NULL);
1 by Simon Huggins
Import upstream version 4.0.5
375
            if (c)
376
            {
377
                new_focus = c;
378
            }
379
        }
380
    }
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
381
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
382
    if (update_focus)
383
    {
384
        if (new_focus)
385
        {
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
386
            clientSetFocus (screen_info, new_focus, timestamp, NO_FOCUS_FLAG);
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
387
        }
388
        else
389
        {
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
390
            clientFocusTop (screen_info, WIN_LAYER_NORMAL, timestamp);
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
391
        }
392
    }
393
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
394
    myScreenUngrabPointer (screen_info, timestamp);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
395
}
396
397
void
1.1.8 by Jani Monoses
Import upstream version 4.3.90.1svn+r21146
398
workspaceSetNames (ScreenInfo * screen_info, gchar **names, int items)
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
399
{
400
    if (screen_info->workspace_names)
401
    {
1.1.7 by Jani Monoses
Import upstream version 4.3.0svn+r20625
402
        g_strfreev (screen_info->workspace_names);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
403
    }
404
405
    screen_info->workspace_names = names;
1.1.7 by Jani Monoses
Import upstream version 4.3.0svn+r20625
406
    screen_info->workspace_names_items = items;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
407
}
408
409
void
410
workspaceSetCount (ScreenInfo * screen_info, int count)
411
{
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
412
    DisplayInfo *display_info;
1 by Simon Huggins
Import upstream version 4.0.5
413
    Client *c;
414
    int i;
415
416
    TRACE ("entering workspaceSetCount");
417
418
    if (count < 1)
419
    {
420
        count = 1;
421
    }
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
422
    if (count == screen_info->workspace_count)
1 by Simon Huggins
Import upstream version 4.0.5
423
    {
424
        return;
425
    }
426
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
427
    display_info = screen_info->display_info;
428
    setHint (display_info, screen_info->xroot, WIN_WORKSPACE_COUNT, count);
429
    setHint (display_info, screen_info->xroot, NET_NUMBER_OF_DESKTOPS, count);
430
    screen_info->workspace_count = count;
1 by Simon Huggins
Import upstream version 4.0.5
431
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
432
    for (c = screen_info->clients, i = 0; i < screen_info->client_count; c = c->next, i++)
1 by Simon Huggins
Import upstream version 4.0.5
433
    {
434
        if (c->win_workspace > count - 1)
435
        {
436
            clientSetWorkspace (c, count - 1, TRUE);
437
        }
438
    }
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
439
    if (screen_info->current_ws > count - 1)
440
    {
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
441
        workspaceSwitch (screen_info, count - 1, NULL, TRUE, myDisplayGetCurrentTime (display_info));
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
442
    }
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
443
    setNetWorkarea (display_info, screen_info->xroot, screen_info->workspace_count,
1.1.11 by Jani Monoses
Import upstream version 4.3.90.2
444
                    screen_info->width, screen_info->height, screen_info->margins);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
445
    /* Recompute the layout based on the (changed) number of desktops */
1.1.16 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r24167
446
    getDesktopLayout (display_info, screen_info->xroot, screen_info->workspace_count,
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
447
                     &screen_info->desktop_layout);
448
}
449
450
void
451
workspaceUpdateArea (ScreenInfo *screen_info)
452
{
1.1.10 by Jani Monoses
Import upstream version 4.3.90.1svn+r21712
453
    DisplayInfo *display_info;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
454
    Client *c;
1 by Simon Huggins
Import upstream version 4.0.5
455
    int prev_top;
456
    int prev_left;
457
    int prev_right;
458
    int prev_bottom;
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
459
    int i;
1 by Simon Huggins
Import upstream version 4.0.5
460
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
461
    g_return_if_fail (screen_info != NULL);
462
    g_return_if_fail (screen_info->margins != NULL);
463
    g_return_if_fail (screen_info->gnome_margins != NULL);
1 by Simon Huggins
Import upstream version 4.0.5
464
465
    TRACE ("entering workspaceUpdateArea");
466
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
467
    display_info = screen_info->display_info;
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
468
    prev_top = screen_info->margins[STRUTS_TOP];
469
    prev_left = screen_info->margins[STRUTS_LEFT];
470
    prev_right = screen_info->margins[STRUTS_RIGHT];
471
    prev_bottom = screen_info->margins[STRUTS_BOTTOM];
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
472
473
    for (i = 0; i < 4; i++)
474
    {
475
        screen_info->margins[i] = screen_info->gnome_margins[i];
476
    }
477
478
    for (c = screen_info->clients, i = 0; i < screen_info->client_count; c = c->next, i++)
479
    {
480
        if (FLAG_TEST (c->flags, CLIENT_FLAG_HAS_STRUT)
481
            && FLAG_TEST (c->xfwm_flags, XFWM_FLAG_VISIBLE))
482
        {
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
483
            screen_info->margins[STRUTS_TOP]    = MAX (screen_info->margins[STRUTS_TOP],    c->struts[STRUTS_TOP]);
484
            screen_info->margins[STRUTS_LEFT]   = MAX (screen_info->margins[STRUTS_LEFT],   c->struts[STRUTS_LEFT]);
485
            screen_info->margins[STRUTS_RIGHT]  = MAX (screen_info->margins[STRUTS_RIGHT],  c->struts[STRUTS_RIGHT]);
486
            screen_info->margins[STRUTS_BOTTOM] = MAX (screen_info->margins[STRUTS_BOTTOM], c->struts[STRUTS_BOTTOM]);
1.1.2 by Yves-Alexis Perez
Import upstream version 4.2.3.2
487
        }
488
    }
489
1.1.15 by Gauvain Pocentek
Import upstream version 4.3.99.2svn+r23785
490
    if ((prev_top != screen_info->margins[STRUTS_TOP]) || (prev_left != screen_info->margins[STRUTS_LEFT])
491
        || (prev_right != screen_info->margins[STRUTS_RIGHT])
492
        || (prev_bottom != screen_info->margins[STRUTS_BOTTOM]))
1 by Simon Huggins
Import upstream version 4.0.5
493
    {
494
        TRACE ("Margins have changed, updating net_workarea");
1.1.12 by Jani Monoses
Import upstream version 4.3.99.1svn+r23137
495
        setNetWorkarea (display_info, screen_info->xroot, screen_info->workspace_count,
1.1.11 by Jani Monoses
Import upstream version 4.3.90.2
496
                        screen_info->width, screen_info->height, screen_info->margins);
1.1.5 by Jani Monoses
Import upstream version 4.3.0svn+r20220
497
        /* Also prevent windows from being off screen, just like when screen is resized */
498
        clientScreenResize(screen_info);
1 by Simon Huggins
Import upstream version 4.0.5
499
    }
500
}