changed indentation to use spaces only
[wmaker-crm.git] / src / workspace.c
blob961354aca76d4fa7dad919d85bc0633c44fe2425
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 <unistd.h>
33 #include <ctype.h>
34 #include <string.h>
35 #include <time.h>
36 #include <sys/time.h>
38 #include "WindowMaker.h"
39 #include "wcore.h"
40 #include "framewin.h"
41 #include "window.h"
42 #include "icon.h"
43 #include "funcs.h"
44 #include "menu.h"
45 #include "application.h"
46 #include "dock.h"
47 #include "actions.h"
48 #include "workspace.h"
49 #include "appicon.h"
50 #ifdef KWM_HINTS
51 #include "kwm.h"
52 #endif
53 #ifdef NETWM_HINTS
54 #include "wmspec.h"
55 #endif
57 #include "xinerama.h"
60 extern WPreferences wPreferences;
61 extern XContext wWinContext;
62 extern XContext wVEdgeContext;
64 extern void ProcessPendingEvents();
66 static WMPropList *dWorkspaces=NULL;
67 static WMPropList *dClip, *dName;
69 #ifdef VIRTUAL_DESKTOP
70 static BOOL initVDesk = False;
71 #endif
74 static void
75 make_keys()
77 if (dWorkspaces!=NULL)
78 return;
80 dWorkspaces = WMCreatePLString("Workspaces");
81 dName = WMCreatePLString("Name");
82 dClip = WMCreatePLString("Clip");
86 void
87 wWorkspaceMake(WScreen *scr, int count)
89 while (count>0) {
90 wWorkspaceNew(scr);
91 count--;
96 int
97 wWorkspaceNew(WScreen *scr)
99 WWorkspace *wspace, **list;
100 int i;
102 if (scr->workspace_count < MAX_WORKSPACES) {
103 scr->workspace_count++;
105 wspace = wmalloc(sizeof(WWorkspace));
106 wspace->name = NULL;
108 #ifdef KWM_HINTS
109 if (scr->flags.kwm_syncing_count) {
110 wspace->name = wKWMGetWorkspaceName(scr, scr->workspace_count-1);
112 #endif
113 if (!wspace->name) {
114 wspace->name = wmalloc(strlen(_("Workspace %i"))+8);
115 sprintf(wspace->name, _("Workspace %i"), scr->workspace_count);
119 if (!wPreferences.flags.noclip) {
120 wspace->clip = wDockCreate(scr, WM_CLIP);
121 } else
122 wspace->clip = NULL;
124 list = wmalloc(sizeof(WWorkspace*)*scr->workspace_count);
126 for (i=0; i<scr->workspace_count-1; i++) {
127 list[i] = scr->workspaces[i];
129 list[i] = wspace;
130 if (scr->workspaces)
131 wfree(scr->workspaces);
132 scr->workspaces = list;
134 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
135 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
136 #ifdef VIRTUAL_DESKTOP
137 wspace->view_x = wspace->view_y = 0;
138 wspace->height = scr->scr_height;
139 wspace->width = scr->scr_width;
140 #endif
141 #ifdef NETWM_HINTS
142 wNETWMUpdateDesktop(scr);
143 #endif
145 WMPostNotificationName(WMNWorkspaceCreated, scr,
146 (void*)(scr->workspace_count-1));
147 XFlush(dpy);
149 return scr->workspace_count-1;
152 return -1;
156 Bool
157 wWorkspaceDelete(WScreen *scr, int workspace)
159 WWindow *tmp;
160 WWorkspace **list;
161 int i, j;
163 if (workspace<=0)
164 return False;
166 /* verify if workspace is in use by some window */
167 tmp = scr->focused_window;
168 while (tmp) {
169 if (!IS_OMNIPRESENT(tmp) && tmp->frame->workspace==workspace)
170 return False;
171 tmp = tmp->prev;
174 if (!wPreferences.flags.noclip) {
175 wDockDestroy(scr->workspaces[workspace]->clip);
176 scr->workspaces[workspace]->clip = NULL;
179 list = wmalloc(sizeof(WWorkspace*)*(scr->workspace_count-1));
180 j = 0;
181 for (i=0; i<scr->workspace_count; i++) {
182 if (i!=workspace) {
183 list[j++] = scr->workspaces[i];
184 } else {
185 if (scr->workspaces[i]->name)
186 wfree(scr->workspaces[i]->name);
187 wfree(scr->workspaces[i]);
190 wfree(scr->workspaces);
191 scr->workspaces = list;
193 scr->workspace_count--;
196 /* update menu */
197 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
198 /* clip workspace menu */
199 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
201 /* update also window menu */
202 if (scr->workspace_submenu) {
203 WMenu *menu = scr->workspace_submenu;
205 i = menu->entry_no;
206 while (i>scr->workspace_count)
207 wMenuRemoveItem(menu, --i);
208 wMenuRealize(menu);
210 /* and clip menu */
211 if (scr->clip_submenu) {
212 WMenu *menu = scr->clip_submenu;
214 i = menu->entry_no;
215 while (i>scr->workspace_count)
216 wMenuRemoveItem(menu, --i);
217 wMenuRealize(menu);
220 #ifdef NETWM_HINTS
221 wNETWMUpdateDesktop(scr);
222 #endif
224 WMPostNotificationName(WMNWorkspaceDestroyed, scr,
225 (void*)(scr->workspace_count-1));
227 if (scr->current_workspace >= scr->workspace_count)
228 wWorkspaceChange(scr, scr->workspace_count-1);
230 return True;
234 typedef struct WorkspaceNameData {
235 int count;
236 RImage *back;
237 RImage *text;
238 time_t timeout;
239 } WorkspaceNameData;
242 static void
243 hideWorkspaceName(void *data)
245 WScreen *scr = (WScreen*)data;
247 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0
248 || time(NULL) > scr->workspace_name_data->timeout) {
249 XUnmapWindow(dpy, scr->workspace_name);
251 if (scr->workspace_name_data) {
252 RReleaseImage(scr->workspace_name_data->back);
253 RReleaseImage(scr->workspace_name_data->text);
254 wfree(scr->workspace_name_data);
256 scr->workspace_name_data = NULL;
258 scr->workspace_name_timer = NULL;
259 } else {
260 RImage *img = RCloneImage(scr->workspace_name_data->back);
261 Pixmap pix;
263 scr->workspace_name_timer =
264 WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
266 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
267 scr->workspace_name_data->count*255/10);
269 RConvertImage(scr->rcontext, img, &pix);
271 RReleaseImage(img);
273 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
274 XClearWindow(dpy, scr->workspace_name);
275 XFreePixmap(dpy, pix);
276 XFlush(dpy);
278 scr->workspace_name_data->count--;
283 static void
284 showWorkspaceName(WScreen *scr, int workspace)
286 WorkspaceNameData *data;
287 RXImage *ximg;
288 Pixmap text, mask;
289 int w, h;
290 int px, py;
291 char *name = scr->workspaces[workspace]->name;
292 int len = strlen(name);
293 int x, y;
295 if (wPreferences.workspace_name_display_position == WD_NONE ||
296 scr->workspace_count < 2) {
297 return;
300 if (scr->workspace_name_timer) {
301 WMDeleteTimerHandler(scr->workspace_name_timer);
302 XUnmapWindow(dpy, scr->workspace_name);
303 XFlush(dpy);
305 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY,
306 hideWorkspaceName, scr);
308 if (scr->workspace_name_data) {
309 RReleaseImage(scr->workspace_name_data->back);
310 RReleaseImage(scr->workspace_name_data->text);
311 wfree(scr->workspace_name_data);
314 data = wmalloc(sizeof(WorkspaceNameData));
315 data->back = NULL;
317 w = WMWidthOfString(scr->workspace_name_font, name, len);
318 h = WMFontHeight(scr->workspace_name_font);
320 switch (wPreferences.workspace_name_display_position) {
321 case WD_TOP:
322 px = (scr->scr_width - (w+4))/2;
323 py = 0;
324 break;
325 case WD_BOTTOM:
326 px = (scr->scr_width - (w+4))/2;
327 py = scr->scr_height - (h+4);
328 break;
329 case WD_TOPLEFT:
330 px = 0;
331 py = 0;
332 break;
333 case WD_TOPRIGHT:
334 px = scr->scr_width - (w+4);
335 py = 0;
336 break;
337 case WD_BOTTOMLEFT:
338 px = 0;
339 py = scr->scr_height - (h+4);
340 break;
341 case WD_BOTTOMRIGHT:
342 px = scr->scr_width - (w+4);
343 py = scr->scr_height - (h+4);
344 break;
345 case WD_CENTER:
346 default:
347 px = (scr->scr_width - (w+4))/2;
348 py = (scr->scr_height - (h+4))/2;
349 break;
351 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
352 XMoveWindow(dpy, scr->workspace_name, px, py);
354 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
355 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
357 /*XSetForeground(dpy, scr->mono_gc, 0);
358 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);*/
360 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w+4, h+4);
362 for (x = 0; x <= 4; x++) {
363 for (y = 0; y <= 4; y++) {
364 WMDrawString(scr->wmscreen, text, scr->white,
365 scr->workspace_name_font, x, y, name, len);
369 XSetForeground(dpy, scr->mono_gc, 1);
370 XSetBackground(dpy, scr->mono_gc, 0);
372 XCopyPlane(dpy, text, mask, scr->mono_gc, 0, 0, w+4, h+4, 0, 0, 1<<(scr->w_depth-1));
374 /*XSetForeground(dpy, scr->mono_gc, 1);*/
375 XSetBackground(dpy, scr->mono_gc, 1);
377 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w+4, h+4);
379 WMDrawString(scr->wmscreen, text, scr->white, scr->workspace_name_font,
380 2, 2, name, len);
382 #ifdef SHAPE
383 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
384 ShapeSet);
385 #endif
386 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
387 XClearWindow(dpy, scr->workspace_name);
389 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
391 XFreePixmap(dpy, text);
392 XFreePixmap(dpy, mask);
394 if (!data->text) {
395 XMapRaised(dpy, scr->workspace_name);
396 XFlush(dpy);
398 goto erro;
401 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py,
402 data->text->width, data->text->height);
404 if (!ximg || !ximg->image) {
405 goto erro;
408 XMapRaised(dpy, scr->workspace_name);
409 XFlush(dpy);
411 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
412 RDestroyXImage(scr->rcontext, ximg);
414 if (!data->back) {
415 goto erro;
418 data->count = 10;
420 /* set a timeout for the effect */
421 data->timeout = time(NULL) + 2 +
422 (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY*data->count)/1000;
424 scr->workspace_name_data = data;
427 return;
429 erro:
430 if (scr->workspace_name_timer)
431 WMDeleteTimerHandler(scr->workspace_name_timer);
433 if (data->text)
434 RReleaseImage(data->text);
435 if (data->back)
436 RReleaseImage(data->back);
437 wfree(data);
439 scr->workspace_name_data = NULL;
441 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
442 10*WORKSPACE_NAME_FADE_DELAY,
443 hideWorkspaceName, scr);
447 void
448 wWorkspaceChange(WScreen *scr, int workspace)
450 if (scr->flags.startup || scr->flags.startup2) {
451 return;
454 if (workspace != scr->current_workspace) {
455 wWorkspaceForceChange(scr, workspace);
456 } /*else {
457 showWorkspaceName(scr, workspace);
462 void
463 wWorkspaceRelativeChange(WScreen *scr, int amount)
465 int w;
467 w = scr->current_workspace + amount;
469 if (amount < 0) {
470 if (w >= 0) {
471 wWorkspaceChange(scr, w);
472 } else if (wPreferences.ws_cycle) {
473 wWorkspaceChange(scr, scr->workspace_count + w);
475 } else if (amount > 0) {
476 if (w < scr->workspace_count) {
477 wWorkspaceChange(scr, w);
478 } else if (wPreferences.ws_advance) {
479 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
480 } else if (wPreferences.ws_cycle) {
481 wWorkspaceChange(scr, w % scr->workspace_count);
487 void
488 wWorkspaceForceChange(WScreen *scr, int workspace)
490 WWindow *tmp, *foc=NULL, *foc2=NULL;
492 if (workspace >= MAX_WORKSPACES || workspace < 0)
493 return;
495 SendHelperMessage(scr, 'C', workspace+1, NULL);
497 if (workspace > scr->workspace_count-1) {
498 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
501 wClipUpdateForWorkspaceChange(scr, workspace);
503 scr->current_workspace = workspace;
505 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
507 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
509 if ((tmp = scr->focused_window)!= NULL) {
510 if ((IS_OMNIPRESENT(tmp) && (tmp->flags.mapped || tmp->flags.shaded) &&
511 !WFLAGP(tmp, no_focusable)) || tmp->flags.changing_workspace) {
512 foc = tmp;
515 /* foc2 = tmp; will fix annoyance with gnome panel
516 * but will create annoyance for every other application
518 while (tmp) {
519 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
520 /* unmap windows not on this workspace */
521 if ((tmp->flags.mapped||tmp->flags.shaded) &&
522 !IS_OMNIPRESENT(tmp) && !tmp->flags.changing_workspace) {
523 wWindowUnmap(tmp);
525 /* also unmap miniwindows not on this workspace */
526 if (!wPreferences.sticky_icons && tmp->flags.miniaturized &&
527 tmp->icon && !IS_OMNIPRESENT(tmp)) {
528 XUnmapWindow(dpy, tmp->icon->core->window);
529 tmp->icon->mapped = 0;
531 /* update current workspace of omnipresent windows */
532 if (IS_OMNIPRESENT(tmp)) {
533 WApplication *wapp = wApplicationOf(tmp->main_window);
535 tmp->frame->workspace = workspace;
537 if (wapp) {
538 wapp->last_workspace = workspace;
540 if (!foc2 && (tmp->flags.mapped || tmp->flags.shaded)) {
541 foc2 = tmp;
544 } else {
545 /* change selected windows' workspace */
546 if (tmp->flags.selected) {
547 wWindowChangeWorkspace(tmp, workspace);
548 if (!tmp->flags.miniaturized && !foc) {
549 foc = tmp;
551 } else {
552 if (!tmp->flags.hidden) {
553 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
554 /* remap windows that are on this workspace */
555 wWindowMap(tmp);
556 if (!foc && !WFLAGP(tmp, no_focusable)) {
557 foc = tmp;
560 /* Also map miniwindow if not omnipresent */
561 if (!wPreferences.sticky_icons &&
562 tmp->flags.miniaturized &&
563 !IS_OMNIPRESENT(tmp) && tmp->icon) {
564 tmp->icon->mapped = 1;
565 XMapWindow(dpy, tmp->icon->core->window);
570 tmp = tmp->prev;
573 /* Gobble up events unleashed by our mapping & unmapping.
574 * These may trigger various grab-initiated focus &
575 * crossing events. However, we don't care about them,
576 * and ignore their focus implications altogether to avoid
577 * flicker.
579 scr->flags.ignore_focus_events = 1;
580 ProcessPendingEvents();
581 scr->flags.ignore_focus_events = 0;
583 if (!foc)
584 foc = foc2;
586 if (scr->focused_window->flags.mapped && !foc) {
587 foc = scr->focused_window;
589 if (wPreferences.focus_mode == WKF_CLICK) {
590 wSetFocusTo(scr, foc);
591 } else {
592 unsigned int mask;
593 int foo;
594 Window bar, win;
595 WWindow *tmp;
597 tmp = NULL;
598 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
599 &foo, &foo, &foo, &foo, &mask)) {
600 tmp = wWindowFor(win);
603 /* If there's a window under the pointer, focus it.
604 * (we ate all other focus events above, so it's
605 * certainly not focused). Otherwise focus last
606 * focused, or the root (depending on sloppiness)
608 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
609 wSetFocusTo(scr, foc);
610 } else {
611 wSetFocusTo(scr, tmp);
616 /* We need to always arrange icons when changing workspace, even if
617 * no autoarrange icons, because else the icons in different workspaces
618 * can be superposed.
619 * This can be avoided if appicons are also workspace specific.
621 if (!wPreferences.sticky_icons)
622 wArrangeIcons(scr, False);
624 if (scr->dock)
625 wAppIconPaint(scr->dock->icon_array[0]);
627 if (scr->clip_icon) {
628 if (scr->workspaces[workspace]->clip->auto_collapse ||
629 scr->workspaces[workspace]->clip->auto_raise_lower) {
630 /* to handle enter notify. This will also */
631 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
632 XMapWindow(dpy, scr->clip_icon->icon->core->window);
633 } else {
634 wClipIconPaint(scr->clip_icon);
638 #if defined KWM_HINTS || defined NETWM_HINTS
639 wScreenUpdateUsableArea(scr);
640 #endif
641 #ifdef NETWM_HINTS
642 wNETWMUpdateDesktop(scr);
643 #endif
645 showWorkspaceName(scr, workspace);
647 WMPostNotificationName(WMNWorkspaceChanged, scr, (void*)workspace);
649 /* XSync(dpy, False); */
653 #ifdef VIRTUAL_DESKTOP
655 /* TODO:
657 * 1) Allow border around each window so the scrolling
658 * won't just stop at the border.
659 * 2) Make pager.
663 #define vec_sub(a, b) wmkpoint((a).x-(b).x, (a).y-(b).y)
664 #define vec_add(a, b) wmkpoint((a).x+(b).x, (a).y+(b).y)
665 #define vec_inc(a, b) do { (a).x+=(b).x; (a).y+=(b).y; } while(0)
666 #define vec_dot(a, b) ((a).x*(b).x + (a).y*(b).y)
667 #define vec_scale(a, s) wmkpoint((a).x*s, (a).y*s)
668 #define vec_scale2(a, s, t) wmkpoint((a).x*s, (a).y*t)
670 #ifndef HAS_BORDER
671 #define HAS_BORDER(w) (!(WFLAGP((w), no_border)))
672 #endif
674 #ifndef IS_VSTUCK
675 #define IS_VSTUCK(w) (WFLAGP((w), virtual_stick))
676 #endif
678 #define updateMinimum(l,p,ml,mp) do { if (cmp(l) && (l)<(ml)) { (ml)=(l); (mp)=(p); }; } while(0)
680 static Bool cmp_gez(int i) { return (i >= 0); }
682 static Bool cmp_gz(int i) { return (i > 0); }
685 static WMPoint
686 getClosestEdge(WScreen * scr, WMPoint direction, Bool (*cmp)(int))
688 WMPoint closest = wmkpoint(0, 0);
689 int closest_len = INT_MAX;
690 WWindow * wwin;
692 for (wwin=scr->focused_window; wwin; wwin=wwin->prev) {
693 if (wwin->frame->workspace == scr->current_workspace) {
694 if (!wwin->flags.miniaturized &&
695 !IS_VSTUCK(wwin) &&
696 !wwin->flags.hidden) {
697 int border = 2*HAS_BORDER(wwin);
698 int len;
699 int x1,x2,y1,y2;
700 int head = wGetHeadForWindow(wwin);
701 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
702 WMPoint p;
704 x1 = wwin->frame_x - area.x1;
705 y1 = wwin->frame_y - area.y1;
706 x2 = wwin->frame_x + wwin->frame->core->width + border - area.x2;
707 y2 = wwin->frame_y + wwin->frame->core->height + border - area.y2;
709 p = wmkpoint(x1,y1);
710 len = vec_dot(direction, p);
711 updateMinimum(len, p, closest_len, closest);
713 p = wmkpoint(x1,y2);
714 len = vec_dot(direction, p);
715 updateMinimum(len, p, closest_len, closest);
717 p = wmkpoint(x2,y1);
718 len = vec_dot(direction, p);
719 updateMinimum(len, p, closest_len, closest);
721 p = wmkpoint(x2,y2);
722 len = vec_dot(direction, p);
723 updateMinimum(len, p, closest_len, closest);
728 return closest;
732 void
733 wWorkspaceKeyboardMoveDesktop(WScreen *scr, WMPoint direction)
735 int x, y;
736 WMPoint edge = getClosestEdge(scr, direction, cmp_gz);
737 int len = vec_dot(edge, direction);
738 WMPoint step = vec_scale(direction, len);
739 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
740 wWorkspaceSetViewPort(scr, scr->current_workspace, x+step.x, y+step.y);
744 extern Cursor wCursor[WCUR_LAST];
747 static void
748 vdMouseMoveDesktop(XEvent *event, WMPoint direction)
750 static int lock = False;
751 if (lock) return;
752 lock = True;
754 Bool done = False;
755 Bool moved = True;
756 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
757 WMPoint old_pos = wmkpoint(event->xcrossing.x_root, event->xcrossing.y_root);
758 WMPoint step;
759 int x, y;
760 int resisted = 0;
762 if (XGrabPointer(dpy, event->xcrossing.window, False,
763 PointerMotionMask, GrabModeAsync, GrabModeAsync,
764 scr->root_win, wCursor[WCUR_EMPTY],
765 CurrentTime) != GrabSuccess) {
767 /* if the grab fails, do it the old fashioned way */
768 step = vec_scale2(direction, wPreferences.vedge_hscrollspeed,
769 wPreferences.vedge_vscrollspeed);
770 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
771 if (wWorkspaceSetViewPort(scr, scr->current_workspace,
772 x+step.x, y+step.y)) {
773 step = vec_scale(direction, wPreferences.vedge_thickness + 1);
774 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0,
775 event->xcrossing.x_root - step.x,
776 event->xcrossing.y_root - step.y);
778 goto exit;
780 XSync(dpy, True);
782 if (old_pos.x < 0)
783 old_pos.x = 0;
784 if (old_pos.y < 0)
785 old_pos.y = 0;
786 if (old_pos.x > scr->scr_width)
787 old_pos.x = scr->scr_width;
788 if (old_pos.y > scr->scr_height)
789 old_pos.y = scr->scr_height;
791 while (!done) {
792 XEvent ev;
793 if (moved) {
794 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0,
795 scr->scr_width/2, scr->scr_height/2);
796 moved = False;
798 WMMaskEvent(dpy, PointerMotionMask, &ev);
800 switch (ev.type) {
801 case MotionNotify:
803 int step_len;
804 step = wmkpoint(ev.xmotion.x_root-scr->scr_width/2,
805 ev.xmotion.y_root-scr->scr_height/2);
806 step_len = vec_dot(step, direction);
807 if (step_len < 0) {
808 done = True;
809 break;
812 if (step_len > 0) {
813 Bool do_move = True;
814 int resist = wPreferences.vedge_resistance;
815 WMPoint closest;
816 int closest_len = INT_MAX;
817 if (resist) {
818 closest = getClosestEdge(scr, direction, cmp_gez);
819 closest_len = vec_dot(direction, closest);
822 if (!closest_len) {
823 resisted += step_len;
824 do_move = resisted >= resist;
825 if (do_move) {
826 closest_len = INT_MAX;
827 step_len = resisted - resist;
828 resisted = 0;
831 if (do_move) {
832 if (closest_len <= wPreferences.vedge_attraction) {
833 step = vec_scale(direction, closest_len);
834 } else {
835 step = vec_scale(direction, step_len);
838 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
839 wWorkspaceSetViewPort(scr, scr->current_workspace,
840 x+step.x, y+step.y);
841 moved = True;
845 break;
849 step = vec_add(old_pos, vec_scale(direction, -1));
850 XWarpPointer(dpy, None, scr->root_win, 0,0,0,0, step.x, step.y);
851 XUngrabPointer(dpy, CurrentTime);
853 exit:
854 lock = False;
858 static void
859 vdHandleEnter_u(XEvent *event) {
860 vdMouseMoveDesktop(event, VEC_UP);
864 static void
865 vdHandleEnter_d(XEvent *event) {
866 vdMouseMoveDesktop(event, VEC_DOWN);
870 static void
871 vdHandleEnter_l(XEvent *event) {
872 vdMouseMoveDesktop(event, VEC_LEFT);
876 static void
877 vdHandleEnter_r(XEvent *event) {
878 vdMouseMoveDesktop(event, VEC_RIGHT);
882 static void
883 wWorkspaceMapEdge(WScreen *scr)
885 int i;
886 if (wPreferences.vedge_thickness && initVDesk) {
887 for (i=0; i<scr->virtual_nr_edges; ++i) {
888 XMapWindow(dpy, scr->virtual_edges[i]);
894 static void
895 wWorkspaceUnmapEdge(WScreen *scr)
897 int i;
898 if (wPreferences.vedge_thickness && initVDesk) {
899 for (i=0; i<scr->virtual_nr_edges; ++i) {
900 XUnmapWindow(dpy, scr->virtual_edges[i]);
906 #define LEFT_EDGE 0x01
907 #define RIGHT_EDGE 0x02
908 #define TOP_EDGE 0x04
909 #define BOTTOM_EDGE 0x08
910 #define ALL_EDGES 0x0F
912 void
913 wWorkspaceManageEdge(WScreen *scr)
915 if (!initVDesk && wPreferences.vedge_thickness) {
916 int i, j, w;
917 int vmask;
918 XSetWindowAttributes attribs;
920 int heads = wXineramaHeads(scr);
921 int *hasEdges = (int*)wmalloc(sizeof(int)*heads);
923 int thickness = wPreferences.vedge_thickness;
924 int nr_edges = 0;
925 int max_edges = 4*heads;
926 int head;
927 Window * edges = (Window *)wmalloc(sizeof(Window)*max_edges);
929 initVDesk = True;
931 for (i=0; i<heads; ++i)
932 hasEdges[i] = ALL_EDGES;
933 for (i=0; i<heads; ++i) {
934 WMRect i_rect = wGetRectForHead(scr, i);
935 for (j=i+1; j<heads; ++j) {
936 WMRect j_rect = wGetRectForHead(scr, j);
938 int vlen = (WMIN(i_rect.pos.y + i_rect.size.height,
939 j_rect.pos.y + j_rect.size.height) -
940 WMAX(i_rect.pos.y, j_rect.pos.y));
942 int hlen = (WMIN(i_rect.pos.x + i_rect.size.width,
943 j_rect.pos.x + j_rect.size.width) -
944 WMAX( i_rect.pos.x, j_rect.pos.x));
946 if (vlen > 0 && hlen == 0) { /* horz alignment, vert edges touch */
947 if (i_rect.pos.x < j_rect.pos.x) { /* i left of j */
948 hasEdges[i] &= ~RIGHT_EDGE;
949 hasEdges[j] &= ~LEFT_EDGE;
950 } else { /* j left of i */
951 hasEdges[j] &= ~RIGHT_EDGE;
952 hasEdges[i] &= ~LEFT_EDGE;
954 } else if (vlen == 0 && hlen > 0) { /* vert alignment, horz edges touch */
955 if (i_rect.pos.y < j_rect.pos.y) { /* i top of j */
956 hasEdges[i] &= ~BOTTOM_EDGE;
957 hasEdges[j] &= ~TOP_EDGE;
958 } else { /* j top of i */
959 hasEdges[j] &= ~BOTTOM_EDGE;
960 hasEdges[i] &= ~TOP_EDGE;
966 for (w = 0; w < scr->workspace_count; w++) {
967 /* puts("reset workspace"); */
968 wWorkspaceSetViewPort(scr, w, 0, 0);
971 vmask = CWEventMask|CWOverrideRedirect;
972 attribs.event_mask = (EnterWindowMask | LeaveWindowMask | VisibilityChangeMask);
973 attribs.override_redirect = True;
975 for (head=0; head<wXineramaHeads(scr); ++head) {
976 WMRect rect = wGetRectForHead(scr, head);
978 if (hasEdges[head] & TOP_EDGE) {
979 edges[nr_edges] =
980 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
981 rect.size.width, thickness, 0,
982 CopyFromParent, InputOnly, CopyFromParent,
983 vmask, &attribs);
984 XSaveContext(dpy, edges[nr_edges], wVEdgeContext,
985 (XPointer)vdHandleEnter_u);
986 ++nr_edges;
989 if (hasEdges[head] & BOTTOM_EDGE) {
990 edges[nr_edges] =
991 XCreateWindow(dpy, scr->root_win, rect.pos.x,
992 rect.pos.y+rect.size.height-thickness,
993 rect.size.width, thickness, 0,
994 CopyFromParent, InputOnly, CopyFromParent,
995 vmask, &attribs);
996 XSaveContext(dpy, edges[nr_edges], wVEdgeContext,
997 (XPointer)vdHandleEnter_d);
998 ++nr_edges;
1001 if (hasEdges[head] & LEFT_EDGE) {
1002 edges[nr_edges] =
1003 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
1004 thickness, rect.pos.y+rect.size.height, 0,
1005 CopyFromParent, InputOnly, CopyFromParent,
1006 vmask, &attribs);
1007 XSaveContext(dpy, edges[nr_edges], wVEdgeContext,
1008 (XPointer)vdHandleEnter_l);
1009 ++nr_edges;
1012 if (hasEdges[head] & RIGHT_EDGE) {
1013 edges[nr_edges] =
1014 XCreateWindow(dpy, scr->root_win,
1015 rect.pos.x + rect.size.width - thickness, rect.pos.y,
1016 thickness, rect.size.height, 0,
1017 CopyFromParent, InputOnly, CopyFromParent, vmask,
1018 &attribs);
1019 XSaveContext(dpy, edges[nr_edges], wVEdgeContext,
1020 (XPointer)vdHandleEnter_r);
1021 ++nr_edges;
1025 scr->virtual_nr_edges = nr_edges;
1026 scr->virtual_edges = edges;
1028 wWorkspaceMapEdge(scr);
1029 wWorkspaceRaiseEdge(scr);
1031 wfree(hasEdges);
1036 void
1037 wWorkspaceUpdateEdge(WScreen *scr)
1039 if (!initVDesk && wPreferences.vedge_thickness) {
1040 wWorkspaceManageEdge(scr);
1041 } else if (initVDesk) {
1042 if (wPreferences.vedge_thickness) {
1043 wWorkspaceMapEdge(scr);
1044 } else {
1045 wWorkspaceUnmapEdge(scr);
1051 void
1052 wWorkspaceDestroyEdge(WScreen *scr)
1054 if (!initVDesk) {
1055 int i;
1057 for (i=0; i<scr->virtual_nr_edges; ++i) {
1058 XDeleteContext(dpy, scr->virtual_edges[i], wVEdgeContext);
1059 XDestroyWindow(dpy, scr->virtual_edges[i]);
1062 wfree(scr->virtual_edges);
1063 scr->virtual_edges = NULL;
1064 scr->virtual_nr_edges = 0;
1066 initVDesk = False;
1071 void
1072 wWorkspaceRaiseEdge(WScreen *scr)
1074 static int toggle = 0;
1075 int i;
1077 if (wPreferences.vedge_thickness && initVDesk) {
1078 if (toggle) {
1079 for (i=0; i<scr->virtual_nr_edges; ++i) {
1080 XRaiseWindow(dpy, scr->virtual_edges[i]);
1082 } else {
1083 for (i=scr->virtual_nr_edges-1; i>=0; --i) {
1084 XRaiseWindow(dpy, scr->virtual_edges[i]);
1088 toggle ^= 1;
1092 void
1093 wWorkspaceLowerEdge(WScreen *scr)
1095 int i;
1096 if (wPreferences.vedge_thickness && initVDesk) {
1097 for (i=0; i<scr->virtual_nr_edges; ++i) {
1098 XLowerWindow(dpy, scr->virtual_edges[i]);
1104 void
1105 wWorkspaceResizeViewPort(WScreen *scr, int workspace)
1107 int x, y;
1108 wWorkspaceGetViewPosition(scr, scr->current_workspace, &x, &y);
1109 wWorkspaceSetViewPort(scr, scr->current_workspace, x, y);
1113 void
1114 updateWorkspaceGeometry(WScreen *scr, int workspace, int *view_x, int *view_y)
1116 int most_left, most_right, most_top, most_bottom;
1117 WWindow *wwin;
1119 int heads = wXineramaHeads(scr);
1120 typedef int strut_t[4];
1121 strut_t * strut = (strut_t*)wmalloc(heads*sizeof(strut_t));
1122 int head, i;
1124 for (head=0; head<heads; ++head) {
1125 WMRect rect = wGetRectForHead(scr, head);
1126 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1127 strut[head][0] = area.x1 - rect.pos.x;
1128 strut[head][1] = rect.pos.x + rect.size.width - area.x2;
1129 strut[head][2] = area.y1 - rect.pos.y;
1130 strut[head][3] = rect.pos.y + rect.size.height - area.y2;
1133 /* adjust workspace layout */
1134 wwin = scr->focused_window;
1135 most_right = 0;
1136 most_bottom = 0;
1137 most_left = scr->scr_width;
1138 most_top = scr->scr_height;
1139 for(;wwin; wwin = wwin->prev) {
1140 if (wwin->frame->workspace == workspace) {
1141 if (!wwin->flags.miniaturized && !IS_VSTUCK(wwin) &&
1142 !wwin->flags.hidden) {
1144 head = wGetHeadForWindow(wwin);
1146 i = wwin->frame_x - strut[head][0];
1147 if (i < most_left) /* record positions, should this be cached? */
1148 most_left = i;
1149 i = wwin->frame_x + wwin->frame->core->width + strut[head][1];
1150 if (HAS_BORDER(wwin))
1151 i+=2;
1152 if (i > most_right)
1153 most_right = i;
1154 i = wwin->frame_y - strut[head][2];
1155 if (i < most_top)
1156 most_top = i;
1157 i = wwin->frame_y + wwin->frame->core->height + strut[head][3];
1158 if (HAS_BORDER(wwin))
1159 i+=2;
1160 if (i > most_bottom) {
1161 most_bottom = i;
1167 if (most_left > 0) most_left = 0;
1168 if (most_top > 0) most_top = 0;
1170 scr->workspaces[workspace]->width = WMAX(most_right, scr->scr_width) - WMIN(most_left, 0);
1171 scr->workspaces[workspace]->height = WMAX(most_bottom, scr->scr_height) - WMIN(most_top, 0);
1173 *view_x += -most_left - scr->workspaces[workspace]->view_x;
1174 scr->workspaces[workspace]->view_x = -most_left;
1176 *view_y += -most_top - scr->workspaces[workspace]->view_y;
1177 scr->workspaces[workspace]->view_y = -most_top;
1179 wfree(strut);
1183 typedef struct _delay_configure {
1184 WWindow *wwin;
1185 int delay_count;
1186 } _delay_configure;
1189 void
1190 sendConfigureNotify (_delay_configure *delay)
1192 WWindow *wwin;
1194 delay->delay_count--;
1195 if (!delay->delay_count) {
1196 for (wwin = delay->wwin; wwin; wwin = wwin->prev) {
1197 wWindowSynthConfigureNotify(wwin);
1203 Bool
1204 wWorkspaceSetViewPort(WScreen *scr, int workspace, int view_x, int view_y)
1206 Bool adjust_flag = False;
1207 int diff_x, diff_y;
1208 static _delay_configure delay_configure = {NULL, 0};
1209 WWorkspace *wptr;
1210 WWindow *wwin;
1212 wptr = scr->workspaces[workspace];
1214 /*printf("wWorkspaceSetViewPort %d %d\n", view_x, view_y);*/
1216 updateWorkspaceGeometry(scr, workspace, &view_x, &view_y);
1218 if (view_x + scr->scr_width > wptr->width) {
1219 /* puts("right edge of vdesk"); */
1220 view_x = wptr->width - scr->scr_width;
1222 if (view_x < 0) {
1223 /* puts("left edge of vdesk"); */
1224 view_x = 0;
1226 if (view_y + scr->scr_height > wptr->height) {
1227 /* puts("right edge of vdesk"); */
1228 view_y = wptr->height - scr->scr_height;
1230 if (view_y < 0) {
1231 /* puts("left edge of vdesk"); */
1232 view_y = 0;
1235 diff_x = wptr->view_x - view_x;
1236 diff_y = wptr->view_y - view_y;
1237 if (!diff_x && !diff_y)
1238 return False;
1240 wptr->view_x = view_x;
1241 wptr->view_y = view_y;
1243 #ifdef NETWM_HINTS
1244 wNETWMUpdateDesktop(scr);
1245 #endif
1247 for (wwin = scr->focused_window; wwin; wwin = wwin->prev) {
1248 if (wwin->frame->workspace == workspace && !IS_VSTUCK(wwin)) {
1249 wWindowMove(wwin, wwin->frame_x + diff_x, wwin->frame_y + diff_y);
1250 adjust_flag = True;
1253 if (1) { /* if delay*/
1254 delay_configure.delay_count++;
1255 delay_configure.wwin = scr->focused_window;
1256 WMAddTimerHandler(200, (WMCallback *)sendConfigureNotify, &delay_configure);
1259 return adjust_flag;
1263 void
1264 wWorkspaceGetViewPosition(WScreen *scr, int workspace, int *x, int *y)
1266 *x = scr->workspaces[workspace]->view_x;
1267 *y = scr->workspaces[workspace]->view_y;
1269 #endif
1272 static void
1273 switchWSCommand(WMenu *menu, WMenuEntry *entry)
1275 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
1279 static void
1280 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
1282 wWorkspaceDelete(menu->frame->screen_ptr,
1283 menu->frame->screen_ptr->workspace_count-1);
1287 static void
1288 newWSCommand(WMenu *menu, WMenuEntry *foo)
1290 int ws;
1292 ws = wWorkspaceNew(menu->frame->screen_ptr);
1293 /* autochange workspace*/
1294 if (ws>=0)
1295 wWorkspaceChange(menu->frame->screen_ptr, ws);
1299 if (ws<9) {
1300 int kcode;
1301 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
1302 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
1303 entry->rtext =
1304 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
1310 static char*
1311 cropline(char *line)
1313 char *start, *end;
1315 if (strlen(line)==0)
1316 return line;
1318 start = line;
1319 end = &(line[strlen(line)])-1;
1320 while (isspace(*line) && *line!=0) line++;
1321 while (isspace(*end) && end!=line) {
1322 *end=0;
1323 end--;
1325 return line;
1329 void
1330 wWorkspaceRename(WScreen *scr, int workspace, char *name)
1332 char buf[MAX_WORKSPACENAME_WIDTH+1];
1333 char *tmp;
1335 if (workspace >= scr->workspace_count)
1336 return;
1338 /* trim white spaces */
1339 tmp = cropline(name);
1341 if (strlen(tmp)==0) {
1342 sprintf(buf, _("Workspace %i"), workspace+1);
1343 } else {
1344 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
1346 buf[MAX_WORKSPACENAME_WIDTH] = 0;
1348 /* update workspace */
1349 wfree(scr->workspaces[workspace]->name);
1350 scr->workspaces[workspace]->name = wstrdup(buf);
1352 if (scr->clip_ws_menu) {
1353 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
1354 wfree(scr->clip_ws_menu->entries[workspace+2]->text);
1355 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
1356 wMenuRealize(scr->clip_ws_menu);
1359 if (scr->workspace_menu) {
1360 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
1361 wfree(scr->workspace_menu->entries[workspace+2]->text);
1362 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
1363 wMenuRealize(scr->workspace_menu);
1367 if (scr->clip_icon)
1368 wClipIconPaint(scr->clip_icon);
1370 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)workspace);
1376 /* callback for when menu entry is edited */
1377 static void
1378 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
1380 char *tmp;
1382 tmp = entry->text;
1383 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
1387 WMenu*
1388 wWorkspaceMenuMake(WScreen *scr, Bool titled)
1390 WMenu *wsmenu;
1392 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
1393 if (!wsmenu) {
1394 wwarning(_("could not create Workspace menu"));
1395 return NULL;
1398 /* callback to be called when an entry is edited */
1399 wsmenu->on_edit = onMenuEntryEdited;
1401 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
1402 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
1404 return wsmenu;
1409 void
1410 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
1412 int i;
1413 long ws;
1414 char title[MAX_WORKSPACENAME_WIDTH+1];
1415 WMenuEntry *entry;
1416 int tmp;
1418 if (!menu)
1419 return;
1421 if (menu->entry_no < scr->workspace_count+2) {
1422 /* new workspace(s) added */
1423 i = scr->workspace_count-(menu->entry_no-2);
1424 ws = menu->entry_no - 2;
1425 while (i>0) {
1426 strcpy(title, scr->workspaces[ws]->name);
1428 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
1429 entry->flags.indicator = 1;
1430 entry->flags.editable = 1;
1432 i--;
1433 ws++;
1435 } else if (menu->entry_no > scr->workspace_count+2) {
1436 /* removed workspace(s) */
1437 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
1438 wMenuRemoveItem(menu, i);
1441 wMenuRealize(menu);
1443 for (i=0; i<scr->workspace_count; i++) {
1444 menu->entries[i+2]->flags.indicator_on = 0;
1446 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
1448 /* don't let user destroy current workspace */
1449 if (scr->current_workspace == scr->workspace_count-1) {
1450 wMenuSetEnabled(menu, 1, False);
1451 } else {
1452 wMenuSetEnabled(menu, 1, True);
1455 tmp = menu->frame->top_width + 5;
1456 /* if menu got unreachable, bring it to a visible place */
1457 if (menu->frame_x < tmp - (int)menu->frame->core->width)
1458 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
1460 wMenuPaint(menu);
1464 void
1465 wWorkspaceSaveState(WScreen *scr, WMPropList *old_state)
1467 WMPropList *parr, *pstr, *wks_state, *old_wks_state, *foo, *bar;
1468 int i;
1470 make_keys();
1472 old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
1473 parr = WMCreatePLArray(NULL);
1474 for (i=0; i < scr->workspace_count; i++) {
1475 pstr = WMCreatePLString(scr->workspaces[i]->name);
1476 wks_state = WMCreatePLDictionary(dName, pstr, NULL);
1477 WMReleasePropList(pstr);
1478 if (!wPreferences.flags.noclip) {
1479 pstr = wClipSaveWorkspaceState(scr, i);
1480 WMPutInPLDictionary(wks_state, dClip, pstr);
1481 WMReleasePropList(pstr);
1482 } else if (old_wks_state!=NULL) {
1483 if ((foo = WMGetFromPLArray(old_wks_state, i))!=NULL) {
1484 if ((bar = WMGetFromPLDictionary(foo, dClip))!=NULL) {
1485 WMPutInPLDictionary(wks_state, dClip, bar);
1489 WMAddToPLArray(parr, wks_state);
1490 WMReleasePropList(wks_state);
1492 WMPutInPLDictionary(scr->session_state, dWorkspaces, parr);
1493 WMReleasePropList(parr);
1497 void
1498 wWorkspaceRestoreState(WScreen *scr)
1500 WMPropList *parr, *pstr, *wks_state, *clip_state;
1501 int i, j, wscount;
1503 make_keys();
1505 if (scr->session_state == NULL)
1506 return;
1508 parr = WMGetFromPLDictionary(scr->session_state, dWorkspaces);
1510 if (!parr)
1511 return;
1513 wscount = scr->workspace_count;
1514 for (i=0; i < WMIN(WMGetPropListItemCount(parr), MAX_WORKSPACES); i++) {
1515 wks_state = WMGetFromPLArray(parr, i);
1516 if (WMIsPLDictionary(wks_state))
1517 pstr = WMGetFromPLDictionary(wks_state, dName);
1518 else
1519 pstr = wks_state;
1520 if (i >= scr->workspace_count)
1521 wWorkspaceNew(scr);
1522 if (scr->workspace_menu) {
1523 wfree(scr->workspace_menu->entries[i+2]->text);
1524 scr->workspace_menu->entries[i+2]->text = wstrdup(WMGetFromPLString(pstr));
1525 scr->workspace_menu->flags.realized = 0;
1527 wfree(scr->workspaces[i]->name);
1528 scr->workspaces[i]->name = wstrdup(WMGetFromPLString(pstr));
1529 if (!wPreferences.flags.noclip) {
1530 clip_state = WMGetFromPLDictionary(wks_state, dClip);
1531 if (scr->workspaces[i]->clip)
1532 wDockDestroy(scr->workspaces[i]->clip);
1533 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
1534 WM_CLIP);
1535 if (i>0)
1536 wDockHideIcons(scr->workspaces[i]->clip);
1538 /* We set the global icons here, because scr->workspaces[i]->clip
1539 * was not valid in wDockRestoreState().
1540 * There we only set icon->omnipresent to know which icons we
1541 * need to set here.
1543 for (j=0; j<scr->workspaces[i]->clip->max_icons; j++) {
1544 WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j];
1546 if (aicon && aicon->omnipresent) {
1547 aicon->omnipresent = 0;
1548 wClipMakeIconOmnipresent(aicon, True);
1549 XMapWindow(dpy, aicon->icon->core->window);
1554 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void*)i);