activate XGrabServer again
[wmaker-crm.git] / src / workspace.c
blob1178070565cfd0967f13124c955949f4697c6319
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 WPreferences wPreferences;
58 extern XContext wWinContext;
59 extern XContext wVEdgeContext;
61 extern void ProcessPendingEvents();
63 static WMPropList *dWorkspaces = NULL;
64 static WMPropList *dClip, *dName;
66 static void make_keys()
68 if (dWorkspaces != NULL)
69 return;
71 dWorkspaces = WMCreatePLString("Workspaces");
72 dName = WMCreatePLString("Name");
73 dClip = WMCreatePLString("Clip");
76 void wWorkspaceMake(WScreen * scr, int count)
78 while (count > 0) {
79 wWorkspaceNew(scr);
80 count--;
84 int wWorkspaceNew(WScreen * scr)
86 WWorkspace *wspace, **list;
87 int i;
89 if (scr->workspace_count < MAX_WORKSPACES) {
90 scr->workspace_count++;
92 wspace = wmalloc(sizeof(WWorkspace));
93 wspace->name = NULL;
95 if (!wspace->name) {
96 wspace->name = wmalloc(strlen(_("Workspace %i")) + 8);
97 sprintf(wspace->name, _("Workspace %i"), scr->workspace_count);
100 if (!wPreferences.flags.noclip) {
101 wspace->clip = wDockCreate(scr, WM_CLIP);
102 } else
103 wspace->clip = NULL;
105 list = wmalloc(sizeof(WWorkspace *) * scr->workspace_count);
107 for (i = 0; i < scr->workspace_count - 1; i++) {
108 list[i] = scr->workspaces[i];
110 list[i] = wspace;
111 if (scr->workspaces)
112 wfree(scr->workspaces);
113 scr->workspaces = list;
115 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
116 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
117 #ifdef VIRTUAL_DESKTOP
118 wspace->view_x = wspace->view_y = 0;
119 wspace->height = scr->scr_height;
120 wspace->width = scr->scr_width;
121 #endif
122 wNETWMUpdateDesktop(scr);
123 WMPostNotificationName(WMNWorkspaceCreated, scr, (void *)(uintptr_t) (scr->workspace_count - 1));
124 XFlush(dpy);
126 return scr->workspace_count - 1;
129 return -1;
132 Bool wWorkspaceDelete(WScreen * scr, int workspace)
134 WWindow *tmp;
135 WWorkspace **list;
136 int i, j;
138 if (workspace <= 0)
139 return False;
141 /* verify if workspace is in use by some window */
142 tmp = scr->focused_window;
143 while (tmp) {
144 if (!IS_OMNIPRESENT(tmp) && tmp->frame->workspace == workspace)
145 return False;
146 tmp = tmp->prev;
149 if (!wPreferences.flags.noclip) {
150 wDockDestroy(scr->workspaces[workspace]->clip);
151 scr->workspaces[workspace]->clip = NULL;
154 list = wmalloc(sizeof(WWorkspace *) * (scr->workspace_count - 1));
155 j = 0;
156 for (i = 0; i < scr->workspace_count; i++) {
157 if (i != workspace) {
158 list[j++] = scr->workspaces[i];
159 } else {
160 if (scr->workspaces[i]->name)
161 wfree(scr->workspaces[i]->name);
162 wfree(scr->workspaces[i]);
165 wfree(scr->workspaces);
166 scr->workspaces = list;
168 scr->workspace_count--;
170 /* update menu */
171 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
172 /* clip workspace menu */
173 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
175 /* update also window menu */
176 if (scr->workspace_submenu) {
177 WMenu *menu = scr->workspace_submenu;
179 i = menu->entry_no;
180 while (i > scr->workspace_count)
181 wMenuRemoveItem(menu, --i);
182 wMenuRealize(menu);
184 /* and clip menu */
185 if (scr->clip_submenu) {
186 WMenu *menu = scr->clip_submenu;
188 i = menu->entry_no;
189 while (i > scr->workspace_count)
190 wMenuRemoveItem(menu, --i);
191 wMenuRealize(menu);
193 wNETWMUpdateDesktop(scr);
194 WMPostNotificationName(WMNWorkspaceDestroyed, scr, (void *)(uintptr_t) (scr->workspace_count - 1));
196 if (scr->current_workspace >= scr->workspace_count)
197 wWorkspaceChange(scr, scr->workspace_count - 1);
199 return True;
202 typedef struct WorkspaceNameData {
203 int count;
204 RImage *back;
205 RImage *text;
206 time_t timeout;
207 } WorkspaceNameData;
209 static void hideWorkspaceName(void *data)
211 WScreen *scr = (WScreen *) data;
213 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0
214 || time(NULL) > scr->workspace_name_data->timeout) {
215 XUnmapWindow(dpy, scr->workspace_name);
217 if (scr->workspace_name_data) {
218 RReleaseImage(scr->workspace_name_data->back);
219 RReleaseImage(scr->workspace_name_data->text);
220 wfree(scr->workspace_name_data);
222 scr->workspace_name_data = NULL;
224 scr->workspace_name_timer = NULL;
225 } else {
226 RImage *img = RCloneImage(scr->workspace_name_data->back);
227 Pixmap pix;
229 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
231 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
232 scr->workspace_name_data->count * 255 / 10);
234 RConvertImage(scr->rcontext, img, &pix);
236 RReleaseImage(img);
238 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
239 XClearWindow(dpy, scr->workspace_name);
240 XFreePixmap(dpy, pix);
241 XFlush(dpy);
243 scr->workspace_name_data->count--;
247 static void showWorkspaceName(WScreen * scr, int workspace)
249 WorkspaceNameData *data;
250 RXImage *ximg;
251 Pixmap text, mask;
252 int w, h;
253 int px, py;
254 char *name = scr->workspaces[workspace]->name;
255 int len = strlen(name);
256 int x, y;
257 #ifdef XINERAMA
258 int head;
259 WMRect rect;
260 int xx, yy;
261 #endif
263 if (wPreferences.workspace_name_display_position == WD_NONE || scr->workspace_count < 2) {
264 return;
267 if (scr->workspace_name_timer) {
268 WMDeleteTimerHandler(scr->workspace_name_timer);
269 XUnmapWindow(dpy, scr->workspace_name);
270 XFlush(dpy);
272 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY, hideWorkspaceName, scr);
274 if (scr->workspace_name_data) {
275 RReleaseImage(scr->workspace_name_data->back);
276 RReleaseImage(scr->workspace_name_data->text);
277 wfree(scr->workspace_name_data);
280 data = wmalloc(sizeof(WorkspaceNameData));
281 data->back = NULL;
283 w = WMWidthOfString(scr->workspace_name_font, name, len);
284 h = WMFontHeight(scr->workspace_name_font);
286 #ifdef XINERAMA
287 head = wGetHeadForPointerLocation(scr);
288 rect = wGetRectForHead(scr, head);
289 if (scr->xine_info.count) {
290 xx = rect.pos.x + (scr->xine_info.screens[head].size.width - (w + 4)) / 2;
291 yy = rect.pos.y + (scr->xine_info.screens[head].size.height - (h + 4)) / 2;
293 else {
294 xx = (scr->scr_width - (w + 4)) / 2;
295 yy = (scr->scr_height - (h + 4)) / 2;
297 #endif
299 switch (wPreferences.workspace_name_display_position) {
300 case WD_TOP:
301 #ifdef XINERAMA
302 px = xx;
303 #else
304 px = (scr->scr_width - (w + 4)) / 2;
305 #endif
306 py = WORKSPACE_NAME_DISPLAY_PADDING;
307 break;
308 case WD_BOTTOM:
309 #ifdef XINERAMA
310 px = xx;
311 #else
312 px = (scr->scr_width - (w + 4)) / 2;
313 #endif
314 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
315 break;
316 case WD_TOPLEFT:
317 px = WORKSPACE_NAME_DISPLAY_PADDING;
318 py = WORKSPACE_NAME_DISPLAY_PADDING;
319 break;
320 case WD_TOPRIGHT:
321 px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
322 py = WORKSPACE_NAME_DISPLAY_PADDING;
323 break;
324 case WD_BOTTOMLEFT:
325 px = WORKSPACE_NAME_DISPLAY_PADDING;
326 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
327 break;
328 case WD_BOTTOMRIGHT:
329 px = scr->scr_width - (w + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
330 py = scr->scr_height - (h + 4 + WORKSPACE_NAME_DISPLAY_PADDING);
331 break;
332 case WD_CENTER:
333 default:
334 #ifdef XINERAMA
335 px = xx;
336 py = yy;
337 #else
338 px = (scr->scr_width - (w + 4)) / 2;
339 py = (scr->scr_height - (h + 4)) / 2;
340 #endif
341 break;
343 XResizeWindow(dpy, scr->workspace_name, w + 4, h + 4);
344 XMoveWindow(dpy, scr->workspace_name, px, py);
346 text = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, scr->w_depth);
347 mask = XCreatePixmap(dpy, scr->w_win, w + 4, h + 4, 1);
349 /*XSetForeground(dpy, scr->mono_gc, 0);
350 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
352 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);
354 for (x = 0; x <= 4; x++) {
355 for (y = 0; y <= 4; y++) {
356 WMDrawString(scr->wmscreen, text, scr->white, scr->workspace_name_font, x, y, name, len);
360 XSetForeground(dpy, scr->mono_gc, 1);
361 XSetBackground(dpy, scr->mono_gc, 0);
363 XCopyPlane(dpy, text, mask, scr->mono_gc, 0, 0, w + 4, h + 4, 0, 0, 1 << (scr->w_depth - 1));
365 /*XSetForeground(dpy, scr->mono_gc, 1); */
366 XSetBackground(dpy, scr->mono_gc, 1);
368 XFillRectangle(dpy, text, WMColorGC(scr->black), 0, 0, w + 4, h + 4);
370 WMDrawString(scr->wmscreen, text, scr->white, scr->workspace_name_font, 2, 2, name, len);
372 #ifdef SHAPE
373 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask, ShapeSet);
374 #endif
375 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
376 XClearWindow(dpy, scr->workspace_name);
378 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
380 XFreePixmap(dpy, text);
381 XFreePixmap(dpy, mask);
383 if (!data->text) {
384 XMapRaised(dpy, scr->workspace_name);
385 XFlush(dpy);
387 goto erro;
390 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py, data->text->width, data->text->height);
392 if (!ximg || !ximg->image) {
393 goto erro;
396 XMapRaised(dpy, scr->workspace_name);
397 XFlush(dpy);
399 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
400 RDestroyXImage(scr->rcontext, ximg);
402 if (!data->back) {
403 goto erro;
406 data->count = 10;
408 /* set a timeout for the effect */
409 data->timeout = time(NULL) + 2 + (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY * data->count) / 1000;
411 scr->workspace_name_data = data;
413 return;
415 erro:
416 if (scr->workspace_name_timer)
417 WMDeleteTimerHandler(scr->workspace_name_timer);
419 if (data->text)
420 RReleaseImage(data->text);
421 if (data->back)
422 RReleaseImage(data->back);
423 wfree(data);
425 scr->workspace_name_data = NULL;
427 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
428 10 * WORKSPACE_NAME_FADE_DELAY, hideWorkspaceName, scr);
431 void wWorkspaceChange(WScreen *scr, int workspace)
433 if (scr->flags.startup || scr->flags.startup2 || scr->flags.ignore_focus_events)
434 return;
436 if (workspace != scr->current_workspace)
437 wWorkspaceForceChange(scr, workspace);
440 void wWorkspaceRelativeChange(WScreen * scr, int amount)
442 int w;
444 w = scr->current_workspace + amount;
446 if (amount < 0) {
447 if (w >= 0) {
448 wWorkspaceChange(scr, w);
449 } else if (wPreferences.ws_cycle) {
450 wWorkspaceChange(scr, scr->workspace_count + w);
452 } else if (amount > 0) {
453 if (w < scr->workspace_count) {
454 wWorkspaceChange(scr, w);
455 } else if (wPreferences.ws_advance) {
456 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES - 1));
457 } else if (wPreferences.ws_cycle) {
458 wWorkspaceChange(scr, w % scr->workspace_count);
463 void wWorkspaceForceChange(WScreen * scr, int workspace)
465 WWindow *tmp, *foc = NULL, *foc2 = NULL;
467 if (workspace >= MAX_WORKSPACES || workspace < 0)
468 return;
470 SendHelperMessage(scr, 'C', workspace + 1, NULL);
472 if (workspace > scr->workspace_count - 1) {
473 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
476 wClipUpdateForWorkspaceChange(scr, workspace);
478 scr->current_workspace = workspace;
480 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
482 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
484 if ((tmp = scr->focused_window) != NULL) {
485 if ((IS_OMNIPRESENT(tmp) && (tmp->flags.mapped || tmp->flags.shaded) &&
486 !WFLAGP(tmp, no_focusable)) || tmp->flags.changing_workspace) {
487 foc = tmp;
490 /* foc2 = tmp; will fix annoyance with gnome panel
491 * but will create annoyance for every other application
493 while (tmp) {
494 if (tmp->frame->workspace != workspace && !tmp->flags.selected) {
495 /* unmap windows not on this workspace */
496 if ((tmp->flags.mapped || tmp->flags.shaded) &&
497 !IS_OMNIPRESENT(tmp) && !tmp->flags.changing_workspace) {
498 wWindowUnmap(tmp);
500 /* also unmap miniwindows not on this workspace */
501 if (!wPreferences.sticky_icons && tmp->flags.miniaturized &&
502 tmp->icon && !IS_OMNIPRESENT(tmp)) {
503 XUnmapWindow(dpy, tmp->icon->core->window);
504 tmp->icon->mapped = 0;
506 /* update current workspace of omnipresent windows */
507 if (IS_OMNIPRESENT(tmp)) {
508 WApplication *wapp = wApplicationOf(tmp->main_window);
510 tmp->frame->workspace = workspace;
512 if (wapp) {
513 wapp->last_workspace = workspace;
515 if (!foc2 && (tmp->flags.mapped || tmp->flags.shaded)) {
516 foc2 = tmp;
519 } else {
520 /* change selected windows' workspace */
521 if (tmp->flags.selected) {
522 wWindowChangeWorkspace(tmp, workspace);
523 if (!tmp->flags.miniaturized && !foc) {
524 foc = tmp;
526 } else {
527 if (!tmp->flags.hidden) {
528 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
529 /* remap windows that are on this workspace */
530 wWindowMap(tmp);
531 if (!foc && !WFLAGP(tmp, no_focusable)) {
532 foc = tmp;
535 /* Also map miniwindow if not omnipresent */
536 if (!wPreferences.sticky_icons &&
537 tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp) && tmp->icon) {
538 tmp->icon->mapped = 1;
539 XMapWindow(dpy, tmp->icon->core->window);
544 tmp = tmp->prev;
547 /* Gobble up events unleashed by our mapping & unmapping.
548 * These may trigger various grab-initiated focus &
549 * crossing events. However, we don't care about them,
550 * and ignore their focus implications altogether to avoid
551 * flicker.
553 scr->flags.ignore_focus_events = 1;
554 ProcessPendingEvents();
555 scr->flags.ignore_focus_events = 0;
557 if (!foc)
558 foc = foc2;
560 if (scr->focused_window->flags.mapped && !foc) {
561 foc = scr->focused_window;
563 if (wPreferences.focus_mode == WKF_CLICK) {
564 wSetFocusTo(scr, foc);
565 } else {
566 unsigned int mask;
567 int foo;
568 Window bar, win;
569 WWindow *tmp;
571 tmp = NULL;
572 if (XQueryPointer(dpy, scr->root_win, &bar, &win, &foo, &foo, &foo, &foo, &mask)) {
573 tmp = wWindowFor(win);
576 /* If there's a window under the pointer, focus it.
577 * (we ate all other focus events above, so it's
578 * certainly not focused). Otherwise focus last
579 * focused, or the root (depending on sloppiness)
581 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
582 wSetFocusTo(scr, foc);
583 } else {
584 wSetFocusTo(scr, tmp);
589 /* We need to always arrange icons when changing workspace, even if
590 * no autoarrange icons, because else the icons in different workspaces
591 * can be superposed.
592 * This can be avoided if appicons are also workspace specific.
594 if (!wPreferences.sticky_icons)
595 wArrangeIcons(scr, False);
597 if (scr->dock)
598 wAppIconPaint(scr->dock->icon_array[0]);
600 if (scr->clip_icon) {
601 if (scr->workspaces[workspace]->clip->auto_collapse ||
602 scr->workspaces[workspace]->clip->auto_raise_lower) {
603 /* to handle enter notify. This will also */
604 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
605 XMapWindow(dpy, scr->clip_icon->icon->core->window);
606 } else {
607 wClipIconPaint(scr->clip_icon);
610 wScreenUpdateUsableArea(scr);
611 wNETWMUpdateDesktop(scr);
612 showWorkspaceName(scr, workspace);
614 WMPostNotificationName(WMNWorkspaceChanged, scr, (void *)(uintptr_t) workspace);
616 /* XSync(dpy, False); */
619 #ifdef VIRTUAL_DESKTOP
621 /* TODO:
623 * 1) Allow border around each window so the scrolling
624 * won't just stop at the border.
625 * 2) Make pager.
629 #define vec_sub(a, b) wmkpoint((a).x-(b).x, (a).y-(b).y)
630 #define vec_add(a, b) wmkpoint((a).x+(b).x, (a).y+(b).y)
631 #define vec_inc(a, b) do { (a).x+=(b).x; (a).y+=(b).y; } while(0)
632 #define vec_dot(a, b) ((a).x*(b).x + (a).y*(b).y)
633 #define vec_scale(a, s) wmkpoint((a).x*s, (a).y*s)
634 #define vec_scale2(a, s, t) wmkpoint((a).x*s, (a).y*t)
636 #ifndef HAS_BORDER
637 #define HAS_BORDER(w) (!(WFLAGP((w), no_border)))
638 #endif
640 #ifndef IS_VSTUCK
641 #define IS_VSTUCK(w) (WFLAGP((w), virtual_stick))
642 #endif
644 #define updateMinimum(l,p,ml,mp) do { if (cmp(l) && (l)<(ml)) { (ml)=(l); (mp)=(p); }; } while(0)
646 static Bool cmp_gez(int i)
648 return (i >= 0);
651 static Bool cmp_gz(int i)
653 return (i > 0);
656 static WMPoint getClosestEdge(WScreen * scr, WMPoint direction, Bool(*cmp) (int))
658 WMPoint closest = wmkpoint(0, 0);
659 int closest_len = INT_MAX;
660 WWindow *wwin;
662 for (wwin = scr->focused_window; wwin; wwin = wwin->prev) {
663 if (wwin->frame->workspace == scr->current_workspace) {
664 if (!wwin->flags.miniaturized && !IS_VSTUCK(wwin) && !wwin->flags.hidden) {
665 int border = 2 * HAS_BORDER(wwin);
666 int len;
667 int x1, x2, y1, y2;
668 int head = wGetHeadForWindow(wwin);
669 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
670 WMPoint p;
672 x1 = wwin->frame_x - area.x1;
673 y1 = wwin->frame_y - area.y1;
674 x2 = wwin->frame_x + wwin->frame->core->width + border - area.x2;
675 y2 = wwin->frame_y + wwin->frame->core->height + border - area.y2;
677 p = wmkpoint(x1, y1);
678 len = vec_dot(direction, p);
679 updateMinimum(len, p, closest_len, closest);
681 p = wmkpoint(x1, y2);
682 len = vec_dot(direction, p);
683 updateMinimum(len, p, closest_len, closest);
685 p = wmkpoint(x2, y1);
686 len = vec_dot(direction, p);
687 updateMinimum(len, p, closest_len, closest);
689 p = wmkpoint(x2, y2);
690 len = vec_dot(direction, p);
691 updateMinimum(len, p, closest_len, closest);
696 return closest;
699 static void getViewPosition(WScreen * scr, int workspace, int *x, int *y)
701 *x = scr->workspaces[workspace]->view_x;
702 *y = scr->workspaces[workspace]->view_y;
705 void wWorkspaceKeyboardMoveDesktop(WScreen * scr, WMPoint direction)
707 int x, y;
708 WMPoint edge = getClosestEdge(scr, direction, cmp_gz);
709 int len = vec_dot(edge, direction);
710 WMPoint step = vec_scale(direction, len);
711 getViewPosition(scr, scr->current_workspace, &x, &y);
712 wWorkspaceSetViewport(scr, scr->current_workspace, x + step.x, y + step.y);
715 extern Cursor wCursor[WCUR_LAST];
717 static void vdMouseMoveDesktop(XEvent * event, WMPoint direction)
719 static int lock = False;
720 if (lock)
721 return;
722 lock = True;
724 Bool done = False;
725 Bool moved = True;
726 WScreen *scr = wScreenForRootWindow(event->xcrossing.root);
727 WMPoint old_pos = wmkpoint(event->xcrossing.x_root, event->xcrossing.y_root);
728 WMPoint step;
729 int x, y;
730 int resisted = 0;
732 if (XGrabPointer(dpy, event->xcrossing.window, False,
733 PointerMotionMask, GrabModeAsync, GrabModeAsync,
734 scr->root_win, wCursor[WCUR_EMPTY], CurrentTime) != GrabSuccess) {
736 /* if the grab fails, do it the old fashioned way */
737 step = vec_scale2(direction, wPreferences.vedge_hscrollspeed, wPreferences.vedge_vscrollspeed);
738 getViewPosition(scr, scr->current_workspace, &x, &y);
739 if (wWorkspaceSetViewport(scr, scr->current_workspace, x + step.x, y + step.y)) {
740 step = vec_scale(direction, 2);
741 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0,
742 event->xcrossing.x_root - step.x, event->xcrossing.y_root - step.y);
744 goto exit;
746 XSync(dpy, True);
748 if (old_pos.x < 0)
749 old_pos.x = 0;
750 if (old_pos.y < 0)
751 old_pos.y = 0;
752 if (old_pos.x > scr->scr_width)
753 old_pos.x = scr->scr_width;
754 if (old_pos.y > scr->scr_height)
755 old_pos.y = scr->scr_height;
757 while (!done) {
758 XEvent ev;
759 if (moved) {
760 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0,
761 scr->scr_width / 2, scr->scr_height / 2);
762 moved = False;
764 WMMaskEvent(dpy, PointerMotionMask, &ev);
766 switch (ev.type) {
767 case MotionNotify:
769 int step_len;
770 step = wmkpoint(ev.xmotion.x_root - scr->scr_width / 2,
771 ev.xmotion.y_root - scr->scr_height / 2);
772 step_len = vec_dot(step, direction);
773 if (step_len < 0) {
774 done = True;
775 break;
778 if (step_len > 0) {
779 Bool do_move = True;
780 int resist = wPreferences.vedge_resistance;
781 WMPoint closest;
782 int closest_len = INT_MAX;
783 if (resist) {
784 closest = getClosestEdge(scr, direction, cmp_gez);
785 closest_len = vec_dot(direction, closest);
788 if (!closest_len) {
789 resisted += step_len;
790 do_move = resisted >= resist;
791 if (do_move) {
792 closest_len = INT_MAX;
793 step_len = resisted - resist;
794 resisted = 0;
797 if (do_move) {
798 if (closest_len <= wPreferences.vedge_attraction) {
799 step = vec_scale(direction, closest_len);
800 } else {
801 step = vec_scale(direction, step_len);
804 getViewPosition(scr, scr->current_workspace, &x, &y);
805 wWorkspaceSetViewport(scr, scr->current_workspace,
806 x + step.x, y + step.y);
807 moved = True;
811 break;
815 step = vec_add(old_pos, vec_scale(direction, -1));
816 XWarpPointer(dpy, None, scr->root_win, 0, 0, 0, 0, step.x, step.y);
817 XUngrabPointer(dpy, CurrentTime);
819 exit:
820 lock = False;
823 static void vdHandleEnter_u(XEvent * event)
825 vdMouseMoveDesktop(event, VEC_UP);
828 static void vdHandleEnter_d(XEvent * event)
830 vdMouseMoveDesktop(event, VEC_DOWN);
833 static void vdHandleEnter_l(XEvent * event)
835 vdMouseMoveDesktop(event, VEC_LEFT);
838 static void vdHandleEnter_r(XEvent * event)
840 vdMouseMoveDesktop(event, VEC_RIGHT);
843 #define LEFT_EDGE 0x01
844 #define RIGHT_EDGE 0x02
845 #define TOP_EDGE 0x04
846 #define BOTTOM_EDGE 0x08
847 #define ALL_EDGES 0x0F
849 static void createEdges(WScreen * scr)
851 if (!scr->virtual_edges) {
852 int i, j, w;
853 int vmask;
854 XSetWindowAttributes attribs;
856 int heads = wXineramaHeads(scr);
857 int *hasEdges = (int *)wmalloc(sizeof(int) * heads);
859 int thickness = 1;
860 int nr_edges = 0;
861 int max_edges = 4 * heads;
862 int head;
863 Window *edges = (Window *) wmalloc(sizeof(Window) * max_edges);
865 for (i = 0; i < heads; ++i)
866 hasEdges[i] = ALL_EDGES;
867 for (i = 0; i < heads; ++i) {
868 WMRect i_rect = wGetRectForHead(scr, i);
869 for (j = i + 1; j < heads; ++j) {
870 WMRect j_rect = wGetRectForHead(scr, j);
872 int vlen = (WMIN(i_rect.pos.y + i_rect.size.height,
873 j_rect.pos.y + j_rect.size.height) -
874 WMAX(i_rect.pos.y, j_rect.pos.y));
876 int hlen = (WMIN(i_rect.pos.x + i_rect.size.width,
877 j_rect.pos.x + j_rect.size.width) -
878 WMAX(i_rect.pos.x, j_rect.pos.x));
880 if (vlen > 0 && hlen == 0) { /* horz alignment, vert edges touch */
881 if (i_rect.pos.x < j_rect.pos.x) { /* i left of j */
882 hasEdges[i] &= ~RIGHT_EDGE;
883 hasEdges[j] &= ~LEFT_EDGE;
884 } else { /* j left of i */
885 hasEdges[j] &= ~RIGHT_EDGE;
886 hasEdges[i] &= ~LEFT_EDGE;
888 } else if (vlen == 0 && hlen > 0) { /* vert alignment, horz edges touch */
889 if (i_rect.pos.y < j_rect.pos.y) { /* i top of j */
890 hasEdges[i] &= ~BOTTOM_EDGE;
891 hasEdges[j] &= ~TOP_EDGE;
892 } else { /* j top of i */
893 hasEdges[j] &= ~BOTTOM_EDGE;
894 hasEdges[i] &= ~TOP_EDGE;
900 for (w = 0; w < scr->workspace_count; w++) {
901 /* puts("reset workspace"); */
902 wWorkspaceSetViewport(scr, w, 0, 0);
905 vmask = CWEventMask | CWOverrideRedirect;
906 attribs.event_mask = (EnterWindowMask | LeaveWindowMask | VisibilityChangeMask);
907 attribs.override_redirect = True;
909 for (head = 0; head < wXineramaHeads(scr); ++head) {
910 WMRect rect = wGetRectForHead(scr, head);
912 if (hasEdges[head] & TOP_EDGE) {
913 edges[nr_edges] =
914 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
915 rect.size.width, thickness, 0,
916 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
917 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_u);
918 ++nr_edges;
921 if (hasEdges[head] & BOTTOM_EDGE) {
922 edges[nr_edges] =
923 XCreateWindow(dpy, scr->root_win, rect.pos.x,
924 rect.pos.y + rect.size.height - thickness,
925 rect.size.width, thickness, 0,
926 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
927 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_d);
928 ++nr_edges;
931 if (hasEdges[head] & LEFT_EDGE) {
932 edges[nr_edges] =
933 XCreateWindow(dpy, scr->root_win, rect.pos.x, rect.pos.y,
934 thickness, rect.pos.y + rect.size.height, 0,
935 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
936 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_l);
937 ++nr_edges;
940 if (hasEdges[head] & RIGHT_EDGE) {
941 edges[nr_edges] =
942 XCreateWindow(dpy, scr->root_win,
943 rect.pos.x + rect.size.width - thickness, rect.pos.y,
944 thickness, rect.size.height, 0,
945 CopyFromParent, InputOnly, CopyFromParent, vmask, &attribs);
946 XSaveContext(dpy, edges[nr_edges], wVEdgeContext, (XPointer) vdHandleEnter_r);
947 ++nr_edges;
951 scr->virtual_nr_edges = nr_edges;
952 scr->virtual_edges = edges;
954 for (i = 0; i < scr->virtual_nr_edges; ++i) {
955 XMapWindow(dpy, scr->virtual_edges[i]);
957 wWorkspaceRaiseEdge(scr);
959 wfree(hasEdges);
963 static void destroyEdges(WScreen * scr)
965 if (scr->virtual_edges) {
966 int i;
968 for (i = 0; i < scr->virtual_nr_edges; ++i) {
969 XDeleteContext(dpy, scr->virtual_edges[i], wVEdgeContext);
970 XUnmapWindow(dpy, scr->virtual_edges[i]);
971 XDestroyWindow(dpy, scr->virtual_edges[i]);
974 wfree(scr->virtual_edges);
975 scr->virtual_edges = NULL;
976 scr->virtual_nr_edges = 0;
980 void wWorkspaceUpdateEdge(WScreen * scr)
982 if (wPreferences.vdesk_enable) {
983 createEdges(scr);
984 } else {
985 destroyEdges(scr);
989 void wWorkspaceRaiseEdge(WScreen * scr)
991 static int toggle = 0;
992 int i;
994 if (!scr->virtual_edges)
995 return;
997 if (toggle) {
998 for (i = 0; i < scr->virtual_nr_edges; ++i) {
999 XRaiseWindow(dpy, scr->virtual_edges[i]);
1001 } else {
1002 for (i = scr->virtual_nr_edges - 1; i >= 0; --i) {
1003 XRaiseWindow(dpy, scr->virtual_edges[i]);
1007 toggle ^= 1;
1010 void wWorkspaceLowerEdge(WScreen * scr)
1012 int i;
1013 for (i = 0; i < scr->virtual_nr_edges; ++i) {
1014 XLowerWindow(dpy, scr->virtual_edges[i]);
1018 void wWorkspaceResizeViewport(WScreen * scr, int workspace)
1020 int x, y;
1021 getViewPosition(scr, scr->current_workspace, &x, &y);
1022 wWorkspaceSetViewport(scr, scr->current_workspace, x, y);
1025 void updateWorkspaceGeometry(WScreen * scr, int workspace, int *view_x, int *view_y)
1027 int most_left, most_right, most_top, most_bottom;
1028 WWindow *wwin;
1030 int heads = wXineramaHeads(scr);
1031 typedef int strut_t[4];
1032 strut_t *strut = (strut_t *) wmalloc(heads * sizeof(strut_t));
1033 int head, i;
1035 for (head = 0; head < heads; ++head) {
1036 WMRect rect = wGetRectForHead(scr, head);
1037 WArea area = wGetUsableAreaForHead(scr, head, NULL, False);
1038 strut[head][0] = area.x1 - rect.pos.x;
1039 strut[head][1] = rect.pos.x + rect.size.width - area.x2;
1040 strut[head][2] = area.y1 - rect.pos.y;
1041 strut[head][3] = rect.pos.y + rect.size.height - area.y2;
1044 /* adjust workspace layout */
1045 wwin = scr->focused_window;
1046 most_right = 0;
1047 most_bottom = 0;
1048 most_left = scr->scr_width;
1049 most_top = scr->scr_height;
1050 for (; wwin; wwin = wwin->prev) {
1051 if (wwin->frame->workspace == workspace) {
1052 if (!wwin->flags.miniaturized && !IS_VSTUCK(wwin) && !wwin->flags.hidden) {
1054 head = wGetHeadForWindow(wwin);
1056 i = wwin->frame_x - strut[head][0];
1057 if (i < most_left) /* record positions, should this be cached? */
1058 most_left = i;
1059 i = wwin->frame_x + wwin->frame->core->width + strut[head][1];
1060 if (HAS_BORDER(wwin))
1061 i += 2;
1062 if (i > most_right)
1063 most_right = i;
1064 i = wwin->frame_y - strut[head][2];
1065 if (i < most_top)
1066 most_top = i;
1067 i = wwin->frame_y + wwin->frame->core->height + strut[head][3];
1068 if (HAS_BORDER(wwin))
1069 i += 2;
1070 if (i > most_bottom) {
1071 most_bottom = i;
1077 if (most_left > 0)
1078 most_left = 0;
1079 if (most_top > 0)
1080 most_top = 0;
1082 scr->workspaces[workspace]->width = WMAX(most_right, scr->scr_width) - WMIN(most_left, 0);
1083 scr->workspaces[workspace]->height = WMAX(most_bottom, scr->scr_height) - WMIN(most_top, 0);
1085 *view_x += -most_left - scr->workspaces[workspace]->view_x;
1086 scr->workspaces[workspace]->view_x = -most_left;
1088 *view_y += -most_top - scr->workspaces[workspace]->view_y;
1089 scr->workspaces[workspace]->view_y = -most_top;
1091 wfree(strut);
1094 typedef struct _delay_configure {
1095 WWindow *wwin;
1096 int delay_count;
1097 } _delay_configure;
1099 void sendConfigureNotify(_delay_configure * delay)
1101 WWindow *wwin;
1103 delay->delay_count--;
1104 if (!delay->delay_count) {
1105 for (wwin = delay->wwin; wwin; wwin = wwin->prev) {
1106 wWindowSynthConfigureNotify(wwin);
1111 Bool wWorkspaceSetViewport(WScreen * scr, int workspace, int view_x, int view_y)
1113 Bool adjust_flag = False;
1114 int diff_x, diff_y;
1115 static _delay_configure delay_configure = { NULL, 0 };
1116 WWorkspace *wptr;
1117 WWindow *wwin;
1119 wptr = scr->workspaces[workspace];
1121 /*printf("wWorkspaceSetViewport %d %d\n", view_x, view_y); */
1123 updateWorkspaceGeometry(scr, workspace, &view_x, &view_y);
1125 if (view_x + scr->scr_width > wptr->width) {
1126 /* puts("right edge of vdesk"); */
1127 view_x = wptr->width - scr->scr_width;
1129 if (view_x < 0) {
1130 /* puts("left edge of vdesk"); */
1131 view_x = 0;
1133 if (view_y + scr->scr_height > wptr->height) {
1134 /* puts("right edge of vdesk"); */
1135 view_y = wptr->height - scr->scr_height;
1137 if (view_y < 0) {
1138 /* puts("left edge of vdesk"); */
1139 view_y = 0;
1142 diff_x = wptr->view_x - view_x;
1143 diff_y = wptr->view_y - view_y;
1144 if (!diff_x && !diff_y)
1145 return False;
1147 wptr->view_x = view_x;
1148 wptr->view_y = view_y;
1150 wNETWMUpdateDesktop(scr);
1152 for (wwin = scr->focused_window; wwin; wwin = wwin->prev) {
1153 if (wwin->frame->workspace == workspace && !IS_VSTUCK(wwin)) {
1154 wWindowMove(wwin, wwin->frame_x + diff_x, wwin->frame_y + diff_y);
1155 adjust_flag = True;
1158 if (1) { /* if delay */
1159 delay_configure.delay_count++;
1160 delay_configure.wwin = scr->focused_window;
1161 WMAddTimerHandler(200, (WMCallback *) sendConfigureNotify, &delay_configure);
1164 return adjust_flag;
1167 #endif
1169 static void switchWSCommand(WMenu * menu, WMenuEntry * entry)
1171 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
1174 static void deleteWSCommand(WMenu * menu, WMenuEntry * entry)
1176 wWorkspaceDelete(menu->frame->screen_ptr, menu->frame->screen_ptr->workspace_count - 1);
1179 static void newWSCommand(WMenu * menu, WMenuEntry * foo)
1181 int ws;
1183 ws = wWorkspaceNew(menu->frame->screen_ptr);
1184 /* autochange workspace */
1185 if (ws >= 0)
1186 wWorkspaceChange(menu->frame->screen_ptr, ws);
1189 if (ws<9) {
1190 int kcode;
1191 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
1192 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
1193 entry->rtext =
1194 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
1196 } */
1199 static char *cropline(char *line)
1201 char *start, *end;
1203 if (strlen(line) == 0)
1204 return line;
1206 start = line;
1207 end = &(line[strlen(line)]) - 1;
1208 while (isspace(*line) && *line != 0)
1209 line++;
1210 while (isspace(*end) && end != line) {
1211 *end = 0;
1212 end--;
1214 return line;
1217 void wWorkspaceRename(WScreen * scr, int workspace, char *name)
1219 char buf[MAX_WORKSPACENAME_WIDTH + 1];
1220 char *tmp;
1222 if (workspace >= scr->workspace_count)
1223 return;
1225 /* trim white spaces */
1226 tmp = cropline(name);
1228 if (strlen(tmp) == 0) {
1229 snprintf(buf, sizeof(buf), _("Workspace %i"), workspace + 1);
1230 } else {
1231 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
1233 buf[MAX_WORKSPACENAME_WIDTH] = 0;
1235 /* update workspace */
1236 wfree(scr->workspaces[workspace]->name);
1237 scr->workspaces[workspace]->name = wstrdup(buf);
1239 if (scr->clip_ws_menu) {
1240 if (strcmp(scr->clip_ws_menu->entries[workspace + 2]->text, buf) != 0) {
1241 wfree(scr->clip_ws_menu->entries[workspace + 2]->text);
1242 scr->clip_ws_menu->entries[workspace + 2]->text = wstrdup(buf);
1243 wMenuRealize(scr->clip_ws_menu);
1246 if (scr->workspace_menu) {
1247 if (strcmp(scr->workspace_menu->entries[workspace + 2]->text, buf) != 0) {
1248 wfree(scr->workspace_menu->entries[workspace + 2]->text);
1249 scr->workspace_menu->entries[workspace + 2]->text = wstrdup(buf);
1250 wMenuRealize(scr->workspace_menu);
1254 if (scr->clip_icon)
1255 wClipIconPaint(scr->clip_icon);
1257 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) workspace);
1260 /* callback for when menu entry is edited */
1261 static void onMenuEntryEdited(WMenu * menu, WMenuEntry * entry)
1263 char *tmp;
1265 tmp = entry->text;
1266 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
1269 WMenu *wWorkspaceMenuMake(WScreen * scr, Bool titled)
1271 WMenu *wsmenu;
1273 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
1274 if (!wsmenu) {
1275 wwarning(_("could not create Workspace menu"));
1276 return NULL;
1279 /* callback to be called when an entry is edited */
1280 wsmenu->on_edit = onMenuEntryEdited;
1282 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
1283 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
1285 return wsmenu;
1288 void wWorkspaceMenuUpdate(WScreen * scr, WMenu * menu)
1290 int i;
1291 long ws;
1292 char title[MAX_WORKSPACENAME_WIDTH + 1];
1293 WMenuEntry *entry;
1294 int tmp;
1296 if (!menu)
1297 return;
1299 if (menu->entry_no < scr->workspace_count + 2) {
1300 /* new workspace(s) added */
1301 i = scr->workspace_count - (menu->entry_no - 2);
1302 ws = menu->entry_no - 2;
1303 while (i > 0) {
1304 strncpy(title, scr->workspaces[ws]->name, MAX_WORKSPACENAME_WIDTH);
1306 entry = wMenuAddCallback(menu, title, switchWSCommand, (void *)ws);
1307 entry->flags.indicator = 1;
1308 entry->flags.editable = 1;
1310 i--;
1311 ws++;
1313 } else if (menu->entry_no > scr->workspace_count + 2) {
1314 /* removed workspace(s) */
1315 for (i = menu->entry_no - 1; i >= scr->workspace_count + 2; i--) {
1316 wMenuRemoveItem(menu, i);
1319 wMenuRealize(menu);
1321 for (i = 0; i < scr->workspace_count; i++) {
1322 menu->entries[i + 2]->flags.indicator_on = 0;
1324 menu->entries[scr->current_workspace + 2]->flags.indicator_on = 1;
1326 /* don't let user destroy current workspace */
1327 if (scr->current_workspace == scr->workspace_count - 1) {
1328 wMenuSetEnabled(menu, 1, False);
1329 } else {
1330 wMenuSetEnabled(menu, 1, True);
1333 tmp = menu->frame->top_width + 5;
1334 /* if menu got unreachable, bring it to a visible place */
1335 if (menu->frame_x < tmp - (int)menu->frame->core->width)
1336 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
1338 wMenuPaint(menu);
1341 void wWorkspaceSaveState(WScreen * scr, WMPropList * old_state)
1343 WMPropList *parr, *pstr, *wks_state, *old_wks_state, *foo, *bar;
1344 int i;
1346 make_keys();
1348 old_wks_state = WMGetFromPLDictionary(old_state, dWorkspaces);
1349 parr = WMCreatePLArray(NULL);
1350 for (i = 0; i < scr->workspace_count; i++) {
1351 pstr = WMCreatePLString(scr->workspaces[i]->name);
1352 wks_state = WMCreatePLDictionary(dName, pstr, NULL);
1353 WMReleasePropList(pstr);
1354 if (!wPreferences.flags.noclip) {
1355 pstr = wClipSaveWorkspaceState(scr, i);
1356 WMPutInPLDictionary(wks_state, dClip, pstr);
1357 WMReleasePropList(pstr);
1358 } else if (old_wks_state != NULL) {
1359 if ((foo = WMGetFromPLArray(old_wks_state, i)) != NULL) {
1360 if ((bar = WMGetFromPLDictionary(foo, dClip)) != NULL) {
1361 WMPutInPLDictionary(wks_state, dClip, bar);
1365 WMAddToPLArray(parr, wks_state);
1366 WMReleasePropList(wks_state);
1368 WMPutInPLDictionary(scr->session_state, dWorkspaces, parr);
1369 WMReleasePropList(parr);
1372 void wWorkspaceRestoreState(WScreen * scr)
1374 WMPropList *parr, *pstr, *wks_state, *clip_state;
1375 int i, j, wscount;
1377 make_keys();
1379 if (scr->session_state == NULL)
1380 return;
1382 parr = WMGetFromPLDictionary(scr->session_state, dWorkspaces);
1384 if (!parr)
1385 return;
1387 wscount = scr->workspace_count;
1388 for (i = 0; i < WMIN(WMGetPropListItemCount(parr), MAX_WORKSPACES); i++) {
1389 wks_state = WMGetFromPLArray(parr, i);
1390 if (WMIsPLDictionary(wks_state))
1391 pstr = WMGetFromPLDictionary(wks_state, dName);
1392 else
1393 pstr = wks_state;
1394 if (i >= scr->workspace_count)
1395 wWorkspaceNew(scr);
1396 if (scr->workspace_menu) {
1397 wfree(scr->workspace_menu->entries[i + 2]->text);
1398 scr->workspace_menu->entries[i + 2]->text = wstrdup(WMGetFromPLString(pstr));
1399 scr->workspace_menu->flags.realized = 0;
1401 wfree(scr->workspaces[i]->name);
1402 scr->workspaces[i]->name = wstrdup(WMGetFromPLString(pstr));
1403 if (!wPreferences.flags.noclip) {
1404 int added_omnipresent_icons = 0;
1405 clip_state = WMGetFromPLDictionary(wks_state, dClip);
1406 if (scr->workspaces[i]->clip)
1407 wDockDestroy(scr->workspaces[i]->clip);
1408 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state, WM_CLIP);
1409 if (i > 0)
1410 wDockHideIcons(scr->workspaces[i]->clip);
1412 /* We set the global icons here, because scr->workspaces[i]->clip
1413 * was not valid in wDockRestoreState().
1414 * There we only set icon->omnipresent to know which icons we
1415 * need to set here.
1417 for (j = 0; j < scr->workspaces[i]->clip->max_icons; j++) {
1418 WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j];
1419 int k;
1421 if (!aicon || !aicon->omnipresent)
1422 continue;
1423 aicon->omnipresent = 0;
1424 if (wClipMakeIconOmnipresent(aicon, True) != WO_SUCCESS)
1425 continue;
1426 if (i == 0)
1427 continue;
1429 /* Move this appicon from workspace i to workspace 0 */
1430 scr->workspaces[i]->clip->icon_array[j] = NULL;
1431 scr->workspaces[i]->clip->icon_count--;
1433 added_omnipresent_icons++;
1434 /* If there are too many omnipresent appicons, we are in trouble */
1435 assert(scr->workspaces[0]->clip->icon_count + added_omnipresent_icons
1436 <= scr->workspaces[0]->clip->max_icons);
1437 /* Find first free spot on workspace 0 */
1438 for (k = 0; k < scr->workspaces[0]->clip->max_icons; k++)
1439 if (scr->workspaces[0]->clip->icon_array[k] == NULL)
1440 break;
1441 scr->workspaces[0]->clip->icon_array[k] = aicon;
1442 aicon->dock = scr->workspaces[0]->clip;
1444 scr->workspaces[0]->clip->icon_count += added_omnipresent_icons;
1447 WMPostNotificationName(WMNWorkspaceNameChanged, scr, (void *)(uintptr_t) i);