Small fix for wmaker nightly build script
[wmaker-crm.git] / src / workspace.c
blob7374633af3d690038dccdbbc9f03be39aeb57eeb
1 /* workspace.c- Workspace management
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
22 #include "wconfig.h"
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #ifdef SHAPE
27 #include <X11/extensions/shape.h>
28 #endif
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <stdint.h>
33 #include <unistd.h>
34 #include <ctype.h>
35 #include <string.h>
36 #include <time.h>
37 #include <sys/time.h>
39 #include "WindowMaker.h"
40 #include "wcore.h"
41 #include "framewin.h"
42 #include "window.h"
43 #include "icon.h"
44 #include "funcs.h"
45 #include "menu.h"
46 #include "application.h"
47 #include "dock.h"
48 #include "actions.h"
49 #include "workspace.h"
50 #include "appicon.h"
51 #include "wmspec.h"
52 #include "xinerama.h"
54 #define MAX_SHORTCUT_LENGTH 32
55 #define WORKSPACE_NAME_DISPLAY_PADDING 32
57 extern int ignore_wks_change;
58 extern WPreferences wPreferences;
59 extern XContext wWinContext;
60 extern XContext wVEdgeContext;
62 extern void ProcessPendingEvents();
64 static WMPropList *dWorkspaces = NULL;
65 static WMPropList *dClip, *dName;
67 static void make_keys()
69 if (dWorkspaces != NULL)
70 return;
72 dWorkspaces = WMCreatePLString("Workspaces");
73 dName = WMCreatePLString("Name");
74 dClip = WMCreatePLString("Clip");
77 void wWorkspaceMake(WScreen * scr, int count)
79 while (count > 0) {
80 wWorkspaceNew(scr);
81 count--;
85 int wWorkspaceNew(WScreen * scr)
87 WWorkspace *wspace, **list;
88 int i;
90 if (scr->workspace_count < MAX_WORKSPACES) {
91 scr->workspace_count++;
93 wspace = wmalloc(sizeof(WWorkspace));
94 wspace->name = NULL;
96 if (!wspace->name) {
97 wspace->name = wmalloc(strlen(_("Workspace %i")) + 8);
98 sprintf(wspace->name, _("Workspace %i"), scr->workspace_count);
101 if (!wPreferences.flags.noclip) {
102 wspace->clip = wDockCreate(scr, WM_CLIP);
103 } else
104 wspace->clip = NULL;
106 list = wmalloc(sizeof(WWorkspace *) * scr->workspace_count);
108 for (i = 0; i < scr->workspace_count - 1; i++) {
109 list[i] = scr->workspaces[i];
111 list[i] = wspace;
112 if (scr->workspaces)
113 wfree(scr->workspaces);
114 scr->workspaces = list;
116 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
117 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
118 #ifdef VIRTUAL_DESKTOP
119 wspace->view_x = wspace->view_y = 0;
120 wspace->height = scr->scr_height;
121 wspace->width = scr->scr_width;
122 #endif
123 wNETWMUpdateDesktop(scr);
124 WMPostNotificationName(WMNWorkspaceCreated, scr, (void *)(uintptr_t) (scr->workspace_count - 1));
125 XFlush(dpy);
127 return scr->workspace_count - 1;
130 return -1;
133 Bool wWorkspaceDelete(WScreen * scr, int workspace)
135 WWindow *tmp;
136 WWorkspace **list;
137 int i, j;
139 if (workspace <= 0)
140 return False;
142 /* verify if workspace is in use by some window */
143 tmp = scr->focused_window;
144 while (tmp) {
145 if (!IS_OMNIPRESENT(tmp) && tmp->frame->workspace == workspace)
146 return False;
147 tmp = tmp->prev;
150 if (!wPreferences.flags.noclip) {
151 wDockDestroy(scr->workspaces[workspace]->clip);
152 scr->workspaces[workspace]->clip = NULL;
155 list = wmalloc(sizeof(WWorkspace *) * (scr->workspace_count - 1));
156 j = 0;
157 for (i = 0; i < scr->workspace_count; i++) {
158 if (i != workspace) {
159 list[j++] = scr->workspaces[i];
160 } else {
161 if (scr->workspaces[i]->name)
162 wfree(scr->workspaces[i]->name);
163 wfree(scr->workspaces[i]);
166 wfree(scr->workspaces);
167 scr->workspaces = list;
169 scr->workspace_count--;
171 /* update menu */
172 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
173 /* clip workspace menu */
174 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
176 /* update also window menu */
177 if (scr->workspace_submenu) {
178 WMenu *menu = scr->workspace_submenu;
180 i = menu->entry_no;
181 while (i > scr->workspace_count)
182 wMenuRemoveItem(menu, --i);
183 wMenuRealize(menu);
185 /* and clip menu */
186 if (scr->clip_submenu) {
187 WMenu *menu = scr->clip_submenu;
189 i = menu->entry_no;
190 while (i > scr->workspace_count)
191 wMenuRemoveItem(menu, --i);
192 wMenuRealize(menu);
194 wNETWMUpdateDesktop(scr);
195 WMPostNotificationName(WMNWorkspaceDestroyed, scr, (void *)(uintptr_t) (scr->workspace_count - 1));
197 if (scr->current_workspace >= scr->workspace_count)
198 wWorkspaceChange(scr, scr->workspace_count - 1);
200 return True;
203 typedef struct WorkspaceNameData {
204 int count;
205 RImage *back;
206 RImage *text;
207 time_t timeout;
208 } WorkspaceNameData;
210 static void hideWorkspaceName(void *data)
212 WScreen *scr = (WScreen *) data;
214 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0
215 || time(NULL) > scr->workspace_name_data->timeout) {
216 XUnmapWindow(dpy, scr->workspace_name);
218 if (scr->workspace_name_data) {
219 RReleaseImage(scr->workspace_name_data->back);
220 RReleaseImage(scr->workspace_name_data->text);
221 wfree(scr->workspace_name_data);
223 scr->workspace_name_data = NULL;
225 scr->workspace_name_timer = NULL;
226 } else {
227 RImage *img = RCloneImage(scr->workspace_name_data->back);
228 Pixmap pix;
230 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
232 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
233 scr->workspace_name_data->count * 255 / 10);
235 RConvertImage(scr->rcontext, img, &pix);
237 RReleaseImage(img);
239 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
240 XClearWindow(dpy, scr->workspace_name);
241 XFreePixmap(dpy, pix);
242 XFlush(dpy);
244 scr->workspace_name_data->count--;
248 static void showWorkspaceName(WScreen * scr, int workspace)
250 WorkspaceNameData *data;
251 RXImage *ximg;
252 Pixmap text, mask;
253 int w, h;
254 int px, py;
255 char *name = scr->workspaces[workspace]->name;
256 int len = strlen(name);
257 int x, y;
258 #ifdef XINERAMA
259 int head;
260 WMRect rect;
261 int xx, yy;
262 #endif
264 if (wPreferences.workspace_name_display_position == WD_NONE || scr->workspace_count < 2) {
265 return;
268 if (scr->workspace_name_timer) {
269 WMDeleteTimerHandler(scr->workspace_name_timer);
270 XUnmapWindow(dpy, scr->workspace_name);
271 XFlush(dpy);
273 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY, hideWorkspaceName, scr);
275 if (scr->workspace_name_data) {
276 RReleaseImage(scr->workspace_name_data->back);
277 RReleaseImage(scr->workspace_name_data->text);
278 wfree(scr->workspace_name_data);
281 data = wmalloc(sizeof(WorkspaceNameData));
282 data->back = NULL;
284 w = WMWidthOfString(scr->workspace_name_font, name, len);
285 h = WMFontHeight(scr->workspace_name_font);
287 #ifdef XINERAMA
288 head = wGetHeadForPointerLocation(scr);
289 rect = wGetRectForHead(scr, head);
290 if (scr->xine_info.count) {
291 xx = rect.pos.x + (scr->xine_info.screens[head].size.width - (w + 4)) / 2;
292 yy = rect.pos.y + (scr->xine_info.screens[head].size.height - (h + 4)) / 2;
294 else {
295 xx = (scr->scr_width - (w + 4)) / 2;
296 yy = (scr->scr_height - (h + 4)) / 2;
298 #endif
300 switch (wPreferences.workspace_name_display_position) {
301 case WD_TOP:
302 #ifdef XINERAMA
303 px = xx;
304 #else
305 px = (scr->scr_width - (w + 4)) / 2;
306 #endif
307 py = WORKSPACE_NAME_DISPLAY_PADDING;
308 break;
309 case WD_BOTTOM:
310 #ifdef XINERAMA
311 px = xx;
312 #else
313 px = (scr->scr_width - (w + 4)) / 2;
314 #endif
315 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
316 break;
317 case WD_TOPLEFT:
318 px = WORKSPACE_NAME_DISPLAY_PADDING;
319 py = WORKSPACE_NAME_DISPLAY_PADDING;
320 break;
321 case WD_TOPRIGHT:
322 px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
323 py = WORKSPACE_NAME_DISPLAY_PADDING;
324 break;
325 case WD_BOTTOMLEFT:
326 px = WORKSPACE_NAME_DISPLAY_PADDING;
327 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
328 break;
329 case WD_BOTTOMRIGHT:
330 px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
331 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
332 break;
333 case WD_CENTER:
334 default:
335 #ifdef XINERAMA
336 px = xx;
337 py = yy;
338 #else
339 px = (scr->scr_width - (w + 4)) / 2;
340 py = (scr->scr_height - (h + 4)) / 2;
341 #endif
342 break;
344 XResizeWindow(dpy, scr->workspace_name, w + 4, h + 4);
345 XMoveWindow(dpy, scr->workspace_name, px, py);
347 text = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, scr->w_depth);
348 mask = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, 1);
350 /*XSetForeground(dpy, scr->mono_gc, 0);
351 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
353 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);
355 for (x = 0; x <= 4; x++) {
356 for (y = 0; y <= 4; y++) {
357 WMDrawString(scr->wmscreen, text, scr->white, scr->workspace_name_font, x, y, name, len);
361 XSetForeground(dpy, scr->mono_gc, 1);
362 XSetBackground(dpy, scr->mono_gc, 0);
364 XCopyPlane(dpy, text, mask, scr->mono_gc, 0, 0, w + 4, h + 4, 0, 0, 1 << (scr->w_depth - 1));
366 /*XSetForeground(dpy, scr->mono_gc, 1); */
367 XSetBackground(dpy, scr->mono_gc, 1);
369 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);
371 WMDrawString(scr->wmscreen, text, scr->white, scr->workspace_name_font, 2, 2, name, len);
373 #ifdef SHAPE
374 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask, ShapeSet);
375 #endif
376 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
377 XClearWindow(dpy, scr->workspace_name);
379 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
381 XFreePixmap(dpy, text);
382 XFreePixmap(dpy, mask);
384 if (!data->text) {
385 XMapRaised(dpy, scr->workspace_name);
386 XFlush(dpy);
388 goto erro;
391 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py, data->text->width, data->text->height);
393 if (!ximg || !ximg->image) {
394 goto erro;
397 XMapRaised(dpy, scr->workspace_name);
398 XFlush(dpy);
400 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
401 RDestroyXImage(scr->rcontext, ximg);
403 if (!data->back) {
404 goto erro;
407 data->count = 10;
409 /* set a timeout for the effect */
410 data->timeout = time(NULL) + 2 + (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY * data->count) / 1000;
412 scr->workspace_name_data = data;
414 return;
416 erro:
417 if (scr->workspace_name_timer)
418 WMDeleteTimerHandler(scr->workspace_name_timer);
420 if (data->text)
421 RReleaseImage(data->text);
422 if (data->back)
423 RReleaseImage(data->back);
424 wfree(data);
426 scr->workspace_name_data = NULL;
428 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
429 10 * WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
432 void wWorkspaceChange(WScreen *scr, int workspace)
434 if (scr->flags.startup || scr->flags.startup2 || scr->flags.ignore_focus_events)
435 return;
437 if (workspace != scr->current_workspace)
438 wWorkspaceForceChange(scr, workspace);
441 void wWorkspaceRelativeChange(WScreen * scr, int amount)
443 int w;
445 /* While the deiconify animation is going on the window is
446 * still "flying" to its final position and we don't want to
447 * change workspace before the animation finishes, otherwise
448 * the window will land in the new workspace */
449 if (ignore_wks_change)
450 return;
452 w = scr->current_workspace + amount;
454 if (amount < 0) {
455 if (w >= 0) {
456 wWorkspaceChange(scr, w);
457 } else if (wPreferences.ws_cycle) {
458 wWorkspaceChange(scr, scr->workspace_count + w);
460 } else if (amount > 0) {
461 if (w < scr->workspace_count) {
462 wWorkspaceChange(scr, w);
463 } else if (wPreferences.ws_advance) {
464 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES - 1));
465 } else if (wPreferences.ws_cycle) {
466 wWorkspaceChange(scr, w % scr->workspace_count);
471 void wWorkspaceForceChange(WScreen * scr, int workspace)
473 WWindow *tmp, *foc = NULL, *foc2 = NULL;
475 if (workspace >= MAX_WORKSPACES || workspace < 0)
476 return;
478 SendHelperMessage(scr, 'C', workspace + 1, NULL);
480 if (workspace > scr->workspace_count - 1) {
481 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
484 wClipUpdateForWorkspaceChange(scr, workspace);
486 scr->current_workspace = workspace;
488 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
490 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
492 if ((tmp = scr->focused_window) != NULL) {
493 if ((IS_OMNIPRESENT(tmp) && (tmp->flags.mapped || tmp->flags.shaded) &&
494 !WFLAGP(tmp, no_focusable)) || tmp->flags.changing_workspace) {
495 foc = tmp;
498 /* foc2 = tmp; will fix annoyance with gnome panel
499 * but will create annoyance for every other application
501 while (tmp) {
502 if (tmp->frame->workspace != workspace && !tmp->flags.selected) {
503 /* unmap windows not on this workspace */
504 if ((tmp->flags.mapped || tmp->flags.shaded) &&
505 !IS_OMNIPRESENT(tmp) && !tmp->flags.changing_workspace) {
506 wWindowUnmap(tmp);
508 /* also unmap miniwindows not on this workspace */
509 if (!wPreferences.sticky_icons && tmp->flags.miniaturized &&
510 tmp->icon && !IS_OMNIPRESENT(tmp)) {
511 XUnmapWindow(dpy, tmp->icon->core->window);
512 tmp->icon->mapped = 0;
514 /* update current workspace of omnipresent windows */
515 if (IS_OMNIPRESENT(tmp)) {
516 WApplication *wapp = wApplicationOf(tmp->main_window);
518 tmp->frame->workspace = workspace;
520 if (wapp) {
521 wapp->last_workspace = workspace;
523 if (!foc2 && (tmp->flags.mapped || tmp->flags.shaded)) {
524 foc2 = tmp;
527 } else {
528 /* change selected windows' workspace */
529 if (tmp->flags.selected) {
530 wWindowChangeWorkspace(tmp, workspace);
531 if (!tmp->flags.miniaturized && !foc) {
532 foc = tmp;
534 } else {
535 if (!tmp->flags.hidden) {
536 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
537 /* remap windows that are on this workspace */
538 wWindowMap(tmp);
539 if (!foc && !WFLAGP(tmp, no_focusable)) {
540 foc = tmp;
543 /* Also map miniwindow if not omnipresent */
544 if (!wPreferences.sticky_icons &&
545 tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp) && tmp->icon) {
546 tmp->icon->mapped = 1;
547 XMapWindow(dpy, tmp->icon->core->window);
552 tmp = tmp->prev;
555 /* Gobble up events unleashed by our mapping & unmapping.
556 * These may trigger various grab-initiated focus &
557 * crossing events. However, we don't care about them,
558 * and ignore their focus implications altogether to avoid
559 * flicker.
561 scr->flags.ignore_focus_events = 1;
562 ProcessPendingEvents();
563 scr->flags.ignore_focus_events = 0;
565 if (!foc)
566 foc = foc2;
568 if (scr->focused_window->flags.mapped && !foc) {
569 foc = scr->focused_window;
571 if (wPreferences.focus_mode == WKF_CLICK) {
572 wSetFocusTo(scr, foc);
573 } else {
574 unsigned int mask;
575 int foo;
576 Window bar, win;
577 WWindow *tmp;
579 tmp = NULL;
580 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask)) {
581 tmp = wWindowFor(win);
584 /* If there's a window under the pointer, focus it.
585 * (we ate all other focus events above, so it's
586 * certainly not focused). Otherwise focus last
587 * focused, or the root (depending on sloppiness)
589 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
590 wSetFocusTo(scr, foc);
591 } else {
592 wSetFocusTo(scr, tmp);
597 /* We need to always arrange icons when changing workspace, even if
598 * no autoarrange icons, because else the icons in different workspaces
599 * can be superposed.
600 * This can be avoided if appicons are also workspace specific.
602 if (!wPreferences.sticky_icons)
603 wArrangeIcons(scr, False);
605 if (scr->dock)
606 wAppIconPaint(scr->dock->icon_array[0]);
608 if (scr->clip_icon) {
609 if (scr->workspaces[workspace]->clip->auto_collapse ||
610 scr->workspaces[workspace]->clip->auto_raise_lower) {
611 /* to handle enter notify. This will also */
612 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
613 XMapWindow(dpy, scr->clip_icon->icon->core->window);
614 } else {
615 wClipIconPaint(scr->clip_icon);
618 wScreenUpdateUsableArea(scr);
619 wNETWMUpdateDesktop(scr);
620 showWorkspaceName(scr, workspace);
622 WMPostNotificationName(WMNWorkspaceChanged, scr, (void *)(uintptr_t) workspace);
624 /* XSync(dpy, False); */
627 #ifdef VIRTUAL_DESKTOP
629 /* TODO:
631 * 1) Allow border around each window so the scrolling
632 * won't just stop at the border.
633 * 2) Make pager.
637 #define vec_sub(a, b) wmkpoint((a).x-(b).x, (a).y-(b).y)
638 #define vec_add(a, b) wmkpoint((a).x+(b).x, (a).y+(b).y)
639 #define vec_inc(a, b) do { (a).x+=(b).x; (a).y+=(b).y; } while(0)
640 #define vec_dot(a, b) ((a).x*(b).x + (a).y*(b).y)
641 #define vec_scale(a, s) wmkpoint((a).x*s, (a).y*s)
642 #define vec_scale2(a, s, t) wmkpoint((a).x*s, (a).y*t)
644 #ifndef HAS_BORDER
645 #define HAS_BORDER(w) (!(WFLAGP((w), no_border)))
646 #endif
648 #ifndef IS_VSTUCK
649 #define IS_VSTUCK(w) (WFLAGP((w), virtual_stick))
650 #endif
652 #define updateMinimum(l,p,ml,mp) do { if (cmp(l) && (l)<(ml)) { (ml)=(l); (mp)=(p); }; } while(0)
654 static Bool cmp_gez(int i)
656 return (i >= 0);
659 static Bool cmp_gz(int i)
661 return (i > 0);
664 static WMPoint getClosestEdge(WScreen * scr, WMPoint direction, Bool(*cmp) (int))
666 WMPoint closest = wmkpoint(0, 0);
667 int closest_len = INT_MAX;
668 WWindow *wwin;
670 for (wwin = scr->focused_window; wwin; wwin = wwin->prev) {
671 if (wwin->frame->workspace == scr->current_workspace) {
672 if (!wwin->flags.miniaturized && !IS_VSTUCK(wwin) && !wwin->flags.hidden) {
673 int border = 2 * HAS_BORDER(wwin);
674 int len;
675 int x1, x2, y1, y2;
676 int head = wGetHeadForWindow(wwin);
677 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
678 WMPoint p;
680 x1 = wwin->frame_x - area.x1;
681 y1 = wwin->frame_y - area.y1;
682 x2 = wwin->frame_x + wwin->frame->core->width + border - area.x2;
683 y2 = wwin->frame_y + wwin->frame->core->height + border - area.y2;
685 p = wmkpoint(x1, y1);
686 len = vec_dot(direction, p);
687 updateMinimum(len, p, closest_len, closest);
689 p = wmkpoint(x1, y2);
690 len = vec_dot(direction, p);
691 updateMinimum(len, p, closest_len, closest);
693 p = wmkpoint(x2, y1);
694 len = vec_dot(direction, p);
695 updateMinimum(len, p, closest_len, closest);
697 p = wmkpoint(x2, y2);
698 len = vec_dot(direction, p);
699 updateMinimum(len, p, closest_len, closest);
704 return closest;
707 static void getViewPosition(WScreen * scr, int workspace, int *x, int *y)
709 *x = scr->workspaces[workspace]->view_x;
710 *y = scr->workspaces[workspace]->view_y;
713 void wWorkspaceKeyboardMoveDesktop(WScreen * scr, WMPoint direction)
715 int x, y;
716 WMPoint edge = getClosestEdge(scr, direction, cmp_gz);
717 int len = vec_dot(edge, direction);
718 WMPoint step = vec_scale(direction, len);
719 getViewPosition(scr, scr->current_workspace, &x, &y);
720 wWorkspaceSetViewport(scr, scr->current_workspace, x + step.x, y + step.y);
723 extern Cursor wCursor[WCUR_LAST];
725 static void vdMouseMoveDesktop(XEvent * event, WMPoint direction)
727 static int lock = False;
728 if (lock)
729 return;
730 lock = True;
732 Bool done = False;
733 Bool moved = True;
734 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
735 WMPoint old_pos = wmkpoint(event->xcrossing.x_root, event->xcrossing.y_root);
736 WMPoint step;
737 int x, y;
738 int resisted = 0;
740 if (XGrabPointer(dpy, event->xcrossing.window, False,
741 PointerMotionMask, GrabModeAsync, GrabModeAsync,
742 scr->root_win, wCursor[WCUR_EMPTY], CurrentTime) != GrabSuccess) {
744 /* if the grab fails, do it the old fashioned way */
745 step = vec_scale2(direction, wPreferences.vedge_hscrollspeed, wPreferences.vedge_vscrollspeed);
746 getViewPosition(scr, scr->current_workspace, &x, &y);
747 if (wWorkspaceSetViewport(scr, scr->current_workspace, x + step.x, y + step.y)) {
748 step = vec_scale(direction, 2);
749 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0,
750 event->xcrossing.x_root - step.x, event->xcrossing.y_root - step.y);
752 goto exit;
754 XSync(dpy, True);
756 if (old_pos.x < 0)
757 old_pos.x = 0;
758 if (old_pos.y < 0)
759 old_pos.y = 0;
760 if (old_pos.x > scr->scr_width)
761 old_pos.x = scr->scr_width;
762 if (old_pos.y > scr->scr_height)
763 old_pos.y = scr->scr_height;
765 while (!done) {
766 XEvent ev;
767 if (moved) {
768 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0,
769 scr->scr_width / 2, scr->scr_height / 2);
770 moved = False;
772 WMMaskEvent(dpy, PointerMotionMask, &ev);
774 switch (ev.type) {
775 case MotionNotify:
777 int step_len;
778 step = wmkpoint(ev.xmotion.x_root - scr->scr_width / 2,
779 ev.xmotion.y_root - scr->scr_height / 2);
780 step_len = vec_dot(step, direction);
781 if (step_len < 0) {
782 done = True;
783 break;
786 if (step_len > 0) {
787 Bool do_move = True;
788 int resist = wPreferences.vedge_resistance;
789 WMPoint closest;
790 int closest_len = INT_MAX;
791 if (resist) {
792 closest = getClosestEdge(scr, direction, cmp_gez);
793 closest_len = vec_dot(direction, closest);
796 if (!closest_len) {
797 resisted += step_len;
798 do_move = resisted >= resist;
799 if (do_move) {
800 closest_len = INT_MAX;
801 step_len = resisted - resist;
802 resisted = 0;
805 if (do_move) {
806 if (closest_len <= wPreferences.vedge_attraction) {
807 step = vec_scale(direction, closest_len);
808 } else {
809 step = vec_scale(direction, step_len);
812 getViewPosition(scr, scr->current_workspace, &x, &y);
813 wWorkspaceSetViewport(scr, scr->current_workspace,
814 x + step.x, y + step.y);
815 moved = True;
819 break;
823 step = vec_add(old_pos, vec_scale(direction, -1));
824 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0, step.x, step.y);
825 XUngrabPointer(dpy, CurrentTime);
827 exit:
828 lock = False;
831 static void vdHandleEnter_u(XEvent * event)
833 vdMouseMoveDesktop(event, VEC_UP);
836 static void vdHandleEnter_d(XEvent * event)
838 vdMouseMoveDesktop(event, VEC_DOWN);
841 static void vdHandleEnter_l(XEvent * event)
843 vdMouseMoveDesktop(event, VEC_LEFT);
846 static void vdHandleEnter_r(XEvent * event)
848 vdMouseMoveDesktop(event, VEC_RIGHT);
851 #define LEFT_EDGE 0x01
852 #define RIGHT_EDGE 0x02
853 #define TOP_EDGE 0x04
854 #define BOTTOM_EDGE 0x08
855 #define ALL_EDGES 0x0F
857 static void createEdges(WScreen * scr)
859 if (!scr->virtual_edges) {
860 int i, j, w;
861 int vmask;
862 XSetWindowAttributes attribs;
864 int heads = wXineramaHeads(scr);
865 int *hasEdges = (int *)wmalloc(sizeof(int) * heads);
867 int thickness = 1;
868 int nr_edges = 0;
869 int max_edges = 4 * heads;
870 int head;
871 Window *edges = (Window *) wmalloc(sizeof(Window) * max_edges);
873 for (i = 0; i < heads; ++i)
874 hasEdges[i] = ALL_EDGES;
875 for (i = 0; i < heads; ++i) {
876 WMRect i_rect = wGetRectForHead(scr, i);
877 for (j = i + 1; j < heads; ++j) {
878 WMRect j_rect = wGetRectForHead(scr, j);
880 int vlen = (WMIN(i_rect.pos.y + i_rect.size.height,
881 j_rect.pos.y + j_rect.size.height) -
882 WMAX(i_rect.pos.y, j_rect.pos.y));
884 int hlen = (WMIN(i_rect.pos.x + i_rect.size.width,
885 j_rect.pos.x + j_rect.size.width) -
886 WMAX(i_rect.pos.x, j_rect.pos.x));
888 if (vlen > 0 && hlen == 0) { /* horz alignment, vert edges touch */
889 if (i_rect.pos.x < j_rect.pos.x) { /* i left of j */
890 hasEdges[i] &= ~RIGHT_EDGE;
891 hasEdges[j] &= ~LEFT_EDGE;
892 } else { /* j left of i */
893 hasEdges[j] &= ~RIGHT_EDGE;
894 hasEdges[i] &= ~LEFT_EDGE;
896 } else if (vlen == 0 && hlen > 0) { /* vert alignment, horz edges touch */
897 if (i_rect.pos.y < j_rect.pos.y) { /* i top of j */
898 hasEdges[i] &= ~BOTTOM_EDGE;
899 hasEdges[j] &= ~TOP_EDGE;
900 } else { /* j top of i */
901 hasEdges[j] &= ~BOTTOM_EDGE;
902 hasEdges[i] &= ~TOP_EDGE;
908 for (w = 0; w < scr->workspace_count; w++) {
909 /* puts("reset workspace"); */
910 wWorkspaceSetViewport(scr, w, 0, 0);
913 vmask = CWEventMask | CWOverrideRedirect;
914 attribs.event_mask = (EnterWindowMask | LeaveWindowMask | VisibilityChangeMask);
915 attribs.override_redirect = True;
917 for (head = 0; head < wXineramaHeads(scr); ++head) {
918 WMRect rect = wGetRectForHead(scr, head);
920 if (hasEdges[head] & TOP_EDGE) {
921 edges[nr_edges] =
922 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
923 rect.size.width, thickness, 0,
924 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
925 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_u);
926 ++nr_edges;
929 if (hasEdges[head] & BOTTOM_EDGE) {
930 edges[nr_edges] =
931 XCreateWindow(dpy, scr->root_win, rect.pos.x,
932 rect.pos.y + rect.size.height - thickness,
933 rect.size.width, thickness, 0,
934 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
935 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_d);
936 ++nr_edges;
939 if (hasEdges[head] & LEFT_EDGE) {
940 edges[nr_edges] =
941 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
942 thickness, rect.pos.y + rect.size.height, 0,
943 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
944 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_l);
945 ++nr_edges;
948 if (hasEdges[head] & RIGHT_EDGE) {
949 edges[nr_edges] =
950 XCreateWindow(dpy, scr->root_win,
951 rect.pos.x + rect.size.width - thickness, rect.pos.y,
952 thickness, rect.size.height, 0,
953 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
954 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_r);
955 ++nr_edges;
959 scr->virtual_nr_edges = nr_edges;
960 scr->virtual_edges = edges;
962 for (i = 0; i < scr->virtual_nr_edges; ++i) {
963 XMapWindow(dpy, scr->virtual_edges[i]);
965 wWorkspaceRaiseEdge(scr);
967 wfree(hasEdges);
971 static void destroyEdges(WScreen * scr)
973 if (scr->virtual_edges) {
974 int i;
976 for (i = 0; i < scr->virtual_nr_edges; ++i) {
977 XDeleteContext(dpy, scr->virtual_edges[i], wVEdgeContext);
978 XUnmapWindow(dpy, scr->virtual_edges[i]);
979 XDestroyWindow(dpy, scr->virtual_edges[i]);
982 wfree(scr->virtual_edges);
983 scr->virtual_edges = NULL;
984 scr->virtual_nr_edges = 0;
988 void wWorkspaceUpdateEdge(WScreen * scr)
990 if (wPreferences.vdesk_enable) {
991 createEdges(scr);
992 } else {
993 destroyEdges(scr);
997 void wWorkspaceRaiseEdge(WScreen * scr)
999 static int toggle = 0;
1000 int i;
1002 if (!scr->virtual_edges)
1003 return;
1005 if (toggle) {
1006 for (i = 0; i < scr->virtual_nr_edges; ++i) {
1007 XRaiseWindow(dpy, scr->virtual_edges[i]);
1009 } else {
1010 for (i = scr->virtual_nr_edges - 1; i >= 0; --i) {
1011 XRaiseWindow(dpy, scr->virtual_edges[i]);
1015 toggle ^= 1;
1018 void wWorkspaceLowerEdge(WScreen * scr)
1020 int i;
1021 for (i = 0; i < scr->virtual_nr_edges; ++i) {
1022 XLowerWindow(dpy, scr->virtual_edges[i]);
1026 void wWorkspaceResizeViewport(WScreen * scr, int workspace)
1028 int x, y;
1029 getViewPosition(scr, scr->current_workspace, &x, &y);
1030 wWorkspaceSetViewport(scr, scr->current_workspace, x, y);
1033 void updateWorkspaceGeometry(WScreen * scr, int workspace, int *view_x, int *view_y)
1035 int most_left, most_right, most_top, most_bottom;
1036 WWindow *wwin;
1038 int heads = wXineramaHeads(scr);
1039 typedef int strut_t[4];
1040 strut_t *strut = (strut_t *) wmalloc(heads * sizeof(strut_t));
1041 int head, i;
1043 for (head = 0; head < heads; ++head) {
1044 WMRect rect = wGetRectForHead(scr, head);
1045 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1046 strut[head][0] = area.x1 - rect.pos.x;
1047 strut[head][1] = rect.pos.x + rect.size.width - area.x2;
1048 strut[head][2] = area.y1 - rect.pos.y;
1049 strut[head][3] = rect.pos.y + rect.size.height - area.y2;
1052 /* adjust workspace layout */
1053 wwin = scr->focused_window;
1054 most_right = 0;
1055 most_bottom = 0;
1056 most_left = scr->scr_width;
1057 most_top = scr->scr_height;
1058 for (; wwin; wwin = wwin->prev) {
1059 if (wwin->frame->workspace == workspace) {
1060 if (!wwin->flags.miniaturized && !IS_VSTUCK(wwin) && !wwin->flags.hidden) {
1062 head = wGetHeadForWindow(wwin);
1064 i = wwin->frame_x - strut[head][0];
1065 if (i < most_left) /* record positions, should this be cached? */
1066 most_left = i;
1067 i = wwin->frame_x + wwin->frame->core->width + strut[head][1];
1068 if (HAS_BORDER(wwin))
1069 i += 2;
1070 if (i > most_right)
1071 most_right = i;
1072 i = wwin->frame_y - strut[head][2];
1073 if (i < most_top)
1074 most_top = i;
1075 i = wwin->frame_y + wwin->frame->core->height + strut[head][3];
1076 if (HAS_BORDER(wwin))
1077 i += 2;
1078 if (i > most_bottom) {
1079 most_bottom = i;
1085 if (most_left > 0)
1086 most_left = 0;
1087 if (most_top > 0)
1088 most_top = 0;
1090 scr->workspaces[workspace]->width = WMAX(most_right, scr->scr_width) - WMIN(most_left, 0);
1091 scr->workspaces[workspace]->height = WMAX(most_bottom, scr->scr_height) - WMIN(most_top, 0);
1093 *view_x += -most_left - scr->workspaces[workspace]->view_x;
1094 scr->workspaces[workspace]->view_x = -most_left;
1096 *view_y += -most_top - scr->workspaces[workspace]->view_y;
1097 scr->workspaces[workspace]->view_y = -most_top;
1099 wfree(strut);
1102 typedef struct _delay_configure {
1103 WWindow *wwin;
1104 int delay_count;
1105 } _delay_configure;
1107 void sendConfigureNotify(_delay_configure * delay)
1109 WWindow *wwin;
1111 delay->delay_count--;
1112 if (!delay->delay_count) {
1113 for (wwin = delay->wwin; wwin; wwin = wwin->prev) {
1114 wWindowSynthConfigureNotify(wwin);
1119 Bool wWorkspaceSetViewport(WScreen * scr, int workspace, int view_x, int view_y)
1121 Bool adjust_flag = False;
1122 int diff_x, diff_y;
1123 static _delay_configure delay_configure = { NULL, 0 };
1124 WWorkspace *wptr;
1125 WWindow *wwin;
1127 wptr = scr->workspaces[workspace];
1129 /*printf("wWorkspaceSetViewport %d %d\n", view_x, view_y); */
1131 updateWorkspaceGeometry(scr, workspace, &view_x, &view_y);
1133 if (view_x + scr->scr_width > wptr->width) {
1134 /* puts("right edge of vdesk"); */
1135 view_x = wptr->width - scr->scr_width;
1137 if (view_x < 0) {
1138 /* puts("left edge of vdesk"); */
1139 view_x = 0;
1141 if (view_y + scr->scr_height > wptr->height) {
1142 /* puts("right edge of vdesk"); */
1143 view_y = wptr->height - scr->scr_height;
1145 if (view_y < 0) {
1146 /* puts("left edge of vdesk"); */
1147 view_y = 0;
1150 diff_x = wptr->view_x - view_x;
1151 diff_y = wptr->view_y - view_y;
1152 if (!diff_x && !diff_y)
1153 return False;
1155 wptr->view_x = view_x;
1156 wptr->view_y = view_y;
1158 wNETWMUpdateDesktop(scr);
1160 for (wwin = scr->focused_window; wwin; wwin = wwin->prev) {
1161 if (wwin->frame->workspace == workspace && !IS_VSTUCK(wwin)) {
1162 wWindowMove(wwin, wwin->frame_x + diff_x, wwin->frame_y + diff_y);
1163 adjust_flag = True;
1166 if (1) { /* if delay */
1167 delay_configure.delay_count++;
1168 delay_configure.wwin = scr->focused_window;
1169 WMAddTimerHandler(200, (WMCallback *) sendConfigureNotify, &delay_configure);
1172 return adjust_flag;
1175 #endif
1177 static void switchWSCommand(WMenu * menu, WMenuEntry * entry)
1179 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
1182 static void deleteWSCommand(WMenu * menu, WMenuEntry * entry)
1184 wWorkspaceDelete(menu->frame->screen_ptr, menu->frame->screen_ptr->workspace_count - 1);
1187 static void newWSCommand(WMenu * menu, WMenuEntry * foo)
1189 int ws;
1191 ws = wWorkspaceNew(menu->frame->screen_ptr);
1192 /* autochange workspace */
1193 if (ws >= 0)
1194 wWorkspaceChange(menu->frame->screen_ptr, ws);
1197 if (ws<9) {
1198 int kcode;
1199 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
1200 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
1201 entry->rtext =
1202 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
1204 } */
1207 static char *cropline(char *line)
1209 char *start, *end;
1211 if (strlen(line) == 0)
1212 return line;
1214 start = line;
1215 end = &(line[strlen(line)]) - 1;
1216 while (isspace(*line) && *line != 0)
1217 line++;
1218 while (isspace(*end) && end != line) {
1219 *end = 0;
1220 end--;
1222 return line;
1225 void wWorkspaceRename(WScreen * scr, int workspace, char *name)
1227 char buf[MAX_WORKSPACENAME_WIDTH + 1];
1228 char *tmp;
1230 if (workspace >= scr->workspace_count)
1231 return;
1233 /* trim white spaces */
1234 tmp = cropline(name);
1236 if (strlen(tmp) == 0) {
1237 snprintf(buf, sizeof(buf), _("Workspace %i"), workspace + 1);
1238 } else {
1239 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
1241 buf[MAX_WORKSPACENAME_WIDTH] = 0;
1243 /* update workspace */
1244 wfree(scr->workspaces[workspace]->name);
1245 scr->workspaces[workspace]->name = wstrdup(buf);
1247 if (scr->clip_ws_menu) {
1248 if (strcmp(scr->clip_ws_menu->entries[workspace + 2]->text, buf) != 0) {
1249 wfree(scr->clip_ws_menu->entries[workspace + 2]->text);
1250 scr->clip_ws_menu->entries[workspace + 2]->text = wstrdup(buf);
1251 wMenuRealize(scr->clip_ws_menu);
1254 if (scr->workspace_menu) {
1255 if (strcmp(scr->workspace_menu->entries[workspace + 2]->text, buf) != 0) {
1256 wfree(scr->workspace_menu->entries[workspace + 2]->text);
1257 scr->workspace_menu->entries[workspace + 2]->text = wstrdup(buf);
1258 wMenuRealize(scr->workspace_menu);
1262 if (scr->clip_icon)
1263 wClipIconPaint(scr->clip_icon);
1265 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) workspace);
1268 /* callback for when menu entry is edited */
1269 static void onMenuEntryEdited(WMenu * menu, WMenuEntry * entry)
1271 char *tmp;
1273 tmp = entry->text;
1274 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
1277 WMenu *wWorkspaceMenuMake(WScreen * scr, Bool titled)
1279 WMenu *wsmenu;
1281 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
1282 if (!wsmenu) {
1283 wwarning(_("could not create Workspace menu"));
1284 return NULL;
1287 /* callback to be called when an entry is edited */
1288 wsmenu->on_edit = onMenuEntryEdited;
1290 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
1291 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
1293 return wsmenu;
1296 void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
1298 int i;
1299 long ws;
1300 char title[MAX_WORKSPACENAME_WIDTH + 1];
1301 WMenuEntry *entry;
1302 int tmp;
1304 if (!menu)
1305 return;
1307 if (menu->entry_no < scr->workspace_count + 2) {
1308 /* new workspace(s) added */
1309 i = scr->workspace_count - (menu->entry_no - 2);
1310 ws = menu->entry_no - 2;
1311 while (i > 0) {
1312 strncpy(title, scr->workspaces[ws]->name, MAX_WORKSPACENAME_WIDTH);
1314 entry = wMenuAddCallback(menu, title, switchWSCommand, (void *)ws);
1315 entry->flags.indicator = 1;
1316 entry->flags.editable = 1;
1318 i--;
1319 ws++;
1321 } else if (menu->entry_no > scr->workspace_count + 2) {
1322 /* removed workspace(s) */
1323 for (i = menu->entry_no - 1; i >= scr->workspace_count + 2; i--) {
1324 wMenuRemoveItem(menu, i);
1327 wMenuRealize(menu);
1329 for (i = 0; i < scr->workspace_count; i++) {
1330 menu->entries[i + 2]->flags.indicator_on = 0;
1332 menu->entries[scr->current_workspace + 2]->flags.indicator_on = 1;
1334 /* don't let user destroy current workspace */
1335 if (scr->current_workspace == scr->workspace_count - 1) {
1336 wMenuSetEnabled(menu, 1, False);
1337 } else {
1338 wMenuSetEnabled(menu, 1, True);
1341 tmp = menu->frame->top_width + 5;
1342 /* if menu got unreachable, bring it to a visible place */
1343 if (menu->frame_x < tmp - (int)menu->frame->core->width)
1344 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
1346 wMenuPaint(menu);
1349 void wWorkspaceSaveState(WScreen * scr, WMPropList * old_state)
1351 WMPropList *parr, *pstr, *wks_state, *old_wks_state, *foo, *bar;
1352 int i;
1354 make_keys();
1356 old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
1357 parr = WMCreatePLArray(NULL);
1358 for (i = 0; i < scr->workspace_count; i++) {
1359 pstr = WMCreatePLString(scr->workspaces[i]->name);
1360 wks_state = WMCreatePLDictionary(dName, pstr, NULL);
1361 WMReleasePropList(pstr);
1362 if (!wPreferences.flags.noclip) {
1363 pstr = wClipSaveWorkspaceState(scr, i);
1364 WMPutInPLDictionary(wks_state, dClip, pstr);
1365 WMReleasePropList(pstr);
1366 } else if (old_wks_state != NULL) {
1367 if ((foo = WMGetFromPLArray(old_wks_state, i)) != NULL) {
1368 if ((bar = WMGetFromPLDictionary(foo, dClip)) != NULL) {
1369 WMPutInPLDictionary(wks_state, dClip, bar);
1373 WMAddToPLArray(parr, wks_state);
1374 WMReleasePropList(wks_state);
1376 WMPutInPLDictionary(scr->session_state, dWorkspaces, parr);
1377 WMReleasePropList(parr);
1380 void wWorkspaceRestoreState(WScreen * scr)
1382 WMPropList *parr, *pstr, *wks_state, *clip_state;
1383 int i, j, wscount;
1385 make_keys();
1387 if (scr->session_state == NULL)
1388 return;
1390 parr = WMGetFromPLDictionary(scr->session_state, dWorkspaces);
1392 if (!parr)
1393 return;
1395 wscount = scr->workspace_count;
1396 for (i = 0; i < WMIN(WMGetPropListItemCount(parr), MAX_WORKSPACES); i++) {
1397 wks_state = WMGetFromPLArray(parr, i);
1398 if (WMIsPLDictionary(wks_state))
1399 pstr = WMGetFromPLDictionary(wks_state, dName);
1400 else
1401 pstr = wks_state;
1402 if (i >= scr->workspace_count)
1403 wWorkspaceNew(scr);
1404 if (scr->workspace_menu) {
1405 wfree(scr->workspace_menu->entries[i + 2]->text);
1406 scr->workspace_menu->entries[i + 2]->text = wstrdup(WMGetFromPLString(pstr));
1407 scr->workspace_menu->flags.realized = 0;
1409 wfree(scr->workspaces[i]->name);
1410 scr->workspaces[i]->name = wstrdup(WMGetFromPLString(pstr));
1411 if (!wPreferences.flags.noclip) {
1412 int added_omnipresent_icons = 0;
1413 clip_state = WMGetFromPLDictionary(wks_state, dClip);
1414 if (scr->workspaces[i]->clip)
1415 wDockDestroy(scr->workspaces[i]->clip);
1416 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state, WM_CLIP);
1417 if (i > 0)
1418 wDockHideIcons(scr->workspaces[i]->clip);
1420 /* We set the global icons here, because scr->workspaces[i]->clip
1421 * was not valid in wDockRestoreState().
1422 * There we only set icon->omnipresent to know which icons we
1423 * need to set here.
1425 for (j = 0; j < scr->workspaces[i]->clip->max_icons; j++) {
1426 WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j];
1427 int k;
1429 if (!aicon || !aicon->omnipresent)
1430 continue;
1431 aicon->omnipresent = 0;
1432 if (wClipMakeIconOmnipresent(aicon, True) != WO_SUCCESS)
1433 continue;
1434 if (i == 0)
1435 continue;
1437 /* Move this appicon from workspace i to workspace 0 */
1438 scr->workspaces[i]->clip->icon_array[j] = NULL;
1439 scr->workspaces[i]->clip->icon_count--;
1441 added_omnipresent_icons++;
1442 /* If there are too many omnipresent appicons, we are in trouble */
1443 assert(scr->workspaces[0]->clip->icon_count + added_omnipresent_icons
1444 <= scr->workspaces[0]->clip->max_icons);
1445 /* Find first free spot on workspace 0 */
1446 for (k = 0; k < scr->workspaces[0]->clip->max_icons; k++)
1447 if (scr->workspaces[0]->clip->icon_array[k] == NULL)
1448 break;
1449 scr->workspaces[0]->clip->icon_array[k] = aicon;
1450 aicon->dock = scr->workspaces[0]->clip;
1452 scr->workspaces[0]->clip->icon_count += added_omnipresent_icons;
1455 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) i);