many bug fixes, finished some delegate code, updated menu file bug from EXEC
[wmaker-crm.git] / src / workspace.c
blobbfeffe237cd771bf7fb7d600976580565b4451b5
1 /* workspace.c- Workspace management
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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>
37 #include "WindowMaker.h"
38 #include "wcore.h"
39 #include "framewin.h"
40 #include "window.h"
41 #include "icon.h"
42 #include "funcs.h"
43 #include "menu.h"
44 #include "application.h"
45 #include "dock.h"
46 #include "actions.h"
47 #include "workspace.h"
48 #include "appicon.h"
49 #ifdef GNOME_STUFF
50 #include "gnome.h"
51 #endif
52 #ifdef KWM_HINTS
53 #include "kwm.h"
54 #endif
56 #include <proplist.h>
59 extern WPreferences wPreferences;
60 extern XContext wWinContext;
63 static proplist_t dWorkspaces=NULL;
64 static proplist_t dClip, dName;
67 static void
68 make_keys()
70 if (dWorkspaces!=NULL)
71 return;
73 dWorkspaces = PLMakeString("Workspaces");
74 dName = PLMakeString("Name");
75 dClip = PLMakeString("Clip");
79 void
80 wWorkspaceMake(WScreen *scr, int count)
82 while (count>0) {
83 wWorkspaceNew(scr);
84 count--;
89 int
90 wWorkspaceNew(WScreen *scr)
92 WWorkspace *wspace, **list;
93 int i;
95 if (scr->workspace_count < MAX_WORKSPACES) {
96 scr->workspace_count++;
98 wspace = wmalloc(sizeof(WWorkspace));
99 wspace->name = NULL;
101 #ifdef KWM_HINTS
102 if (scr->flags.kwm_syncing_count) {
103 wspace->name = wKWMGetWorkspaceName(scr, scr->workspace_count-1);
105 #endif
106 if (!wspace->name) {
107 wspace->name = wmalloc(strlen(_("Workspace %i"))+8);
108 sprintf(wspace->name, _("Workspace %i"), scr->workspace_count);
112 if (!wPreferences.flags.noclip) {
113 wspace->clip = wDockCreate(scr, WM_CLIP);
114 } else
115 wspace->clip = NULL;
117 list = wmalloc(sizeof(WWorkspace*)*scr->workspace_count);
119 for (i=0; i<scr->workspace_count-1; i++) {
120 list[i] = scr->workspaces[i];
122 list[i] = wspace;
123 free(scr->workspaces);
124 scr->workspaces = list;
126 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
127 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
128 #ifdef GNOME_STUFF
129 wGNOMEUpdateWorkspaceHints(scr);
130 #endif
131 #ifdef KWM_HINTS
132 if (!scr->flags.kwm_syncing_count) {
133 wKWMUpdateWorkspaceCountHint(scr);
134 wKWMUpdateWorkspaceNameHint(scr, scr->workspace_count-1);
136 #ifdef not_used
137 wKWMSetUsableAreaHint(scr, scr->workspace_count-1);
138 #endif
139 #endif
140 XFlush(dpy);
142 return scr->workspace_count-1;
144 return -1;
149 Bool
150 wWorkspaceDelete(WScreen *scr, int workspace)
152 WWindow *tmp;
153 WWorkspace **list;
154 int i, j;
157 if (workspace<=0)
158 return False;
160 /* verify if workspace is in use by some window */
161 tmp = scr->focused_window;
162 while (tmp) {
163 if (!IS_OMNIPRESENT(tmp) && tmp->frame->workspace==workspace)
164 return False;
165 tmp = tmp->prev;
168 if (!wPreferences.flags.noclip) {
169 wDockDestroy(scr->workspaces[workspace]->clip);
170 scr->workspaces[workspace]->clip = NULL;
173 list = wmalloc(sizeof(WWorkspace*)*(scr->workspace_count-1));
174 j = 0;
175 for (i=0; i<scr->workspace_count; i++) {
176 if (i!=workspace)
177 list[j++] = scr->workspaces[i];
178 else {
179 if (scr->workspaces[i]->name)
180 free(scr->workspaces[i]->name);
181 free(scr->workspaces[i]);
184 free(scr->workspaces);
185 scr->workspaces = list;
187 scr->workspace_count--;
190 /* update menu */
191 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
192 /* clip workspace menu */
193 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
195 /* update also window menu */
196 if (scr->workspace_submenu) {
197 WMenu *menu = scr->workspace_submenu;
199 i = menu->entry_no;
200 while (i>scr->workspace_count)
201 wMenuRemoveItem(menu, --i);
202 wMenuRealize(menu);
204 /* and clip menu */
205 if (scr->clip_submenu) {
206 WMenu *menu = scr->clip_submenu;
208 i = menu->entry_no;
209 while (i>scr->workspace_count)
210 wMenuRemoveItem(menu, --i);
211 wMenuRealize(menu);
214 #ifdef GNOME_STUFF
215 wGNOMEUpdateWorkspaceHints(scr);
216 #endif
217 #ifdef KWM_HINTS
218 wKWMUpdateWorkspaceCountHint(scr);
219 #endif
221 if (scr->current_workspace >= scr->workspace_count)
222 wWorkspaceChange(scr, scr->workspace_count-1);
224 return True;
228 typedef struct WorkspaceNameData {
229 int count;
230 RImage *back;
231 RImage *text;
232 time_t timeout;
233 } WorkspaceNameData;
237 static void
238 hideWorkpaceName(void *data)
240 WScreen *scr = (WScreen*)data;
242 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0
243 || time(NULL) > scr->workspace_name_data->timeout) {
244 XUnmapWindow(dpy, scr->workspace_name);
246 if (scr->workspace_name_data) {
247 RDestroyImage(scr->workspace_name_data->back);
248 RDestroyImage(scr->workspace_name_data->text);
249 free(scr->workspace_name_data);
251 scr->workspace_name_data = NULL;
253 scr->workspace_name_timer = NULL;
254 } else {
255 RImage *img = RCloneImage(scr->workspace_name_data->back);
256 Pixmap pix;
258 scr->workspace_name_timer =
259 WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkpaceName,
260 scr);
262 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
263 scr->workspace_name_data->count*255/10);
265 RConvertImage(scr->rcontext, img, &pix);
267 RDestroyImage(img);
269 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
270 XClearWindow(dpy, scr->workspace_name);
271 XFreePixmap(dpy, pix);
272 XFlush(dpy);
274 scr->workspace_name_data->count--;
280 static void
281 showWorkspaceName(WScreen *scr, int workspace)
283 WorkspaceNameData *data;
284 RXImage *ximg;
285 Pixmap text, mask;
286 int w, h;
287 int px, py;
288 char *name = scr->workspaces[workspace]->name;
289 int len = strlen(name);
290 int x, y;
292 if (wPreferences.workspace_name_display_position == WD_NONE
293 || scr->workspace_count < 2)
294 return;
296 if (scr->workspace_name_timer) {
297 WMDeleteTimerHandler(scr->workspace_name_timer);
298 XUnmapWindow(dpy, scr->workspace_name);
299 XFlush(dpy);
301 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY,
302 hideWorkpaceName, scr);
304 if (scr->workspace_name_data) {
305 RDestroyImage(scr->workspace_name_data->back);
306 RDestroyImage(scr->workspace_name_data->text);
307 free(scr->workspace_name_data);
310 #ifndef I18N_MB
311 XSetFont(dpy, scr->mono_gc, scr->workspace_name_font->font->fid);
312 XSetFont(dpy, scr->draw_gc, scr->workspace_name_font->font->fid);
313 #endif
315 data = wmalloc(sizeof(WorkspaceNameData));
317 w = wTextWidth(scr->workspace_name_font->font, name, len);
318 h = scr->workspace_name_font->height;
320 switch (wPreferences.workspace_name_display_position) {
321 case WD_CENTER:
322 px = (scr->scr_width - (w+4))/2;
323 py = (scr->scr_height - (h+4))/2;
324 break;
325 case WD_TOP:
326 px = (scr->scr_width - (w+4))/2;
327 py = 0;
328 break;
329 case WD_BOTTOM:
330 px = (scr->scr_width - (w+4))/2;
331 py = scr->scr_height - h;
332 break;
333 case WD_TOPLEFT:
334 px = 0;
335 py = 0;
336 break;
337 case WD_TOPRIGHT:
338 px = scr->scr_width - w;
339 py = 0;
340 break;
341 case WD_BOTTOMLEFT:
342 px = 0;
343 py = scr->scr_height - h;
344 break;
345 case WD_BOTTOMRIGHT:
346 px = scr->scr_width - w;
347 py = scr->scr_height - h;
348 break;
350 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
351 XMoveWindow(dpy, scr->workspace_name, px, py);
353 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
354 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
356 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
357 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
359 XSetForeground(dpy, scr->mono_gc, 0);
360 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
362 XSetForeground(dpy, scr->mono_gc, 1);
363 for (x = 0; x <= 4; x++) {
364 for (y = 0; y <= 4; y++) {
365 wDrawString(mask, scr->workspace_name_font, scr->mono_gc,
366 x, scr->workspace_name_font->y + y, name, len);
370 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
371 wDrawString(text, scr->workspace_name_font, scr->draw_gc,
372 2, scr->workspace_name_font->y + 2,
373 scr->workspaces[workspace]->name,
374 strlen(scr->workspaces[workspace]->name));
375 #ifdef SHAPE
376 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
377 ShapeSet);
378 #endif
379 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
380 XClearWindow(dpy, scr->workspace_name);
382 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
384 XFreePixmap(dpy, text);
385 XFreePixmap(dpy, mask);
387 if (!data->text) {
388 XMapRaised(dpy, scr->workspace_name);
389 XFlush(dpy);
391 goto erro;
394 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py,
395 data->text->width, data->text->height);
397 if (!ximg) {
398 goto erro;
401 XMapRaised(dpy, scr->workspace_name);
402 XFlush(dpy);
404 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
405 RDestroyXImage(scr->rcontext, ximg);
407 if (!data->back) {
408 goto erro;
411 data->count = 10;
413 /* set a timeout for the effect */
414 data->timeout = time(NULL) + 2 +
415 (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY*data->count)/1000;
417 scr->workspace_name_data = data;
420 return;
422 erro:
423 if (scr->workspace_name_timer)
424 WMDeleteTimerHandler(scr->workspace_name_timer);
426 if (data->text)
427 RDestroyImage(data->text);
428 if (data->back)
429 RDestroyImage(data->back);
430 free(data);
432 scr->workspace_name_data = NULL;
434 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
435 10*WORKSPACE_NAME_FADE_DELAY,
436 hideWorkpaceName, scr);
440 void
441 wWorkspaceChange(WScreen *scr, int workspace)
443 if (scr->flags.startup || scr->flags.startup2) {
444 return;
447 if (workspace != scr->current_workspace) {
448 wWorkspaceForceChange(scr, workspace);
449 } /*else {
450 showWorkspaceName(scr, workspace);
455 void
456 wWorkspaceRelativeChange(WScreen *scr, int amount)
458 int w;
460 w = scr->current_workspace + amount;
462 if (amount < 0) {
464 if (w >= 0)
465 wWorkspaceChange(scr, w);
466 else if (wPreferences.ws_cycle)
467 wWorkspaceChange(scr, scr->workspace_count + w);
469 } else if (amount > 0) {
471 if (w < scr->workspace_count)
472 wWorkspaceChange(scr, w);
473 else if (wPreferences.ws_advance)
474 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
475 else if (wPreferences.ws_cycle)
476 wWorkspaceChange(scr, w % scr->workspace_count);
482 void
483 wWorkspaceForceChange(WScreen *scr, int workspace)
485 WWindow *tmp, *foc=NULL, *foc2=NULL;
487 if (workspace >= MAX_WORKSPACES || workspace < 0)
488 return;
490 SendHelperMessage(scr, 'C', workspace+1, NULL);
492 if (workspace > scr->workspace_count-1) {
493 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
496 wClipUpdateForWorkspaceChange(scr, workspace);
498 scr->current_workspace = workspace;
500 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
502 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
504 if ((tmp = scr->focused_window)!= NULL) {
505 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
506 foc = tmp;
507 /* foc2 = tmp; will fix annoyance with gnome panel
508 * but will create annoyance for every other application
511 while (tmp) {
512 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
513 /* unmap windows not on this workspace */
514 if ((tmp->flags.mapped||tmp->flags.shaded)
515 && !IS_OMNIPRESENT(tmp)
516 && !tmp->flags.changing_workspace) {
518 wWindowUnmap(tmp);
520 /* also unmap miniwindows not on this workspace */
521 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
522 && tmp->icon) {
523 if (!wPreferences.sticky_icons) {
524 XUnmapWindow(dpy, tmp->icon->core->window);
525 tmp->icon->mapped = 0;
526 } else {
527 tmp->icon->mapped = 1;
528 /* Why is this here? -Alfredo */
529 XMapWindow(dpy, tmp->icon->core->window);
532 /* update current workspace of omnipresent windows */
533 if (IS_OMNIPRESENT(tmp)) {
534 WApplication *wapp = wApplicationOf(tmp->main_window);
536 tmp->frame->workspace = workspace;
538 if (wapp) {
539 wapp->last_workspace = workspace;
541 if (!foc2)
542 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)
557 foc = tmp;
559 /* Also map miniwindow if not omnipresent */
560 if (!wPreferences.sticky_icons &&
561 tmp->flags.miniaturized &&
562 !IS_OMNIPRESENT(tmp) && tmp->icon) {
563 tmp->icon->mapped = 1;
564 XMapWindow(dpy, tmp->icon->core->window);
569 tmp = tmp->prev;
572 if (!foc)
573 foc = foc2;
575 if (scr->focused_window->flags.mapped && !foc) {
576 foc = scr->focused_window;
578 if (wPreferences.focus_mode == WKF_CLICK) {
579 wSetFocusTo(scr, foc);
580 } else {
581 unsigned int mask;
582 int foo;
583 Window bar, win;
584 WWindow *tmp;
586 tmp = NULL;
587 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
588 &foo, &foo, &foo, &foo, &mask)) {
589 tmp = wWindowFor(win);
591 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
592 wSetFocusTo(scr, foc);
593 } else {
594 wSetFocusTo(scr, tmp);
599 /* We need to always arrange icons when changing workspace, even if
600 * no autoarrange icons, because else the icons in different workspaces
601 * can be superposed.
602 * This can be avoided if appicons are also workspace specific.
604 if (!wPreferences.sticky_icons)
605 wArrangeIcons(scr, False);
607 if (scr->dock)
608 wAppIconPaint(scr->dock->icon_array[0]);
610 if (scr->clip_icon) {
611 if (scr->workspaces[workspace]->clip->auto_collapse ||
612 scr->workspaces[workspace]->clip->auto_raise_lower) {
613 /* to handle enter notify. This will also */
614 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
615 XMapWindow(dpy, scr->clip_icon->icon->core->window);
616 } else {
617 wClipIconPaint(scr->clip_icon);
621 if (!scr->flags.startup2)
622 showWorkspaceName(scr, workspace);
624 #ifdef GNOME_STUFF
625 wGNOMEUpdateCurrentWorkspaceHint(scr);
626 #endif
627 #ifdef KWM_HINTS
628 wKWMUpdateCurrentWorkspaceHint(scr);
629 #endif
630 /* XSync(dpy, False); */
634 static void
635 switchWSCommand(WMenu *menu, WMenuEntry *entry)
637 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
642 static void
643 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
645 wWorkspaceDelete(menu->frame->screen_ptr,
646 menu->frame->screen_ptr->workspace_count-1);
651 static void
652 newWSCommand(WMenu *menu, WMenuEntry *foo)
654 int ws;
656 ws = wWorkspaceNew(menu->frame->screen_ptr);
657 /* autochange workspace*/
658 if (ws>=0)
659 wWorkspaceChange(menu->frame->screen_ptr, ws);
663 if (ws<9) {
664 int kcode;
665 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
666 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
667 entry->rtext =
668 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
674 static char*
675 cropline(char *line)
677 char *start, *end;
679 if (strlen(line)==0)
680 return line;
682 start = line;
683 end = &(line[strlen(line)])-1;
684 while (isspace(*line) && *line!=0) line++;
685 while (isspace(*end) && end!=line) {
686 *end=0;
687 end--;
689 return line;
693 void
694 wWorkspaceRename(WScreen *scr, int workspace, char *name)
696 char buf[MAX_WORKSPACENAME_WIDTH+1];
697 char *tmp;
699 if (workspace >= scr->workspace_count)
700 return;
702 /* trim white spaces */
703 tmp = cropline(name);
705 if (strlen(tmp)==0) {
706 sprintf(buf, _("Workspace %i"), workspace+1);
707 } else {
708 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
710 buf[MAX_WORKSPACENAME_WIDTH] = 0;
712 /* update workspace */
713 free(scr->workspaces[workspace]->name);
714 scr->workspaces[workspace]->name = wstrdup(buf);
716 if (scr->clip_ws_menu) {
717 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
718 free(scr->clip_ws_menu->entries[workspace+2]->text);
719 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
720 wMenuRealize(scr->clip_ws_menu);
723 if (scr->workspace_menu) {
724 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
725 free(scr->workspace_menu->entries[workspace+2]->text);
726 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
727 wMenuRealize(scr->workspace_menu);
731 UpdateSwitchMenuWorkspace(scr, workspace);
733 if (scr->clip_icon)
734 wClipIconPaint(scr->clip_icon);
736 #ifdef GNOME_STUFF
737 wGNOMEUpdateWorkspaceNamesHint(scr);
738 #endif
739 #ifdef KWM_HINTS
740 wKWMUpdateWorkspaceNameHint(scr, workspace);
741 #endif
747 /* callback for when menu entry is edited */
748 static void
749 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
751 char *tmp;
753 tmp = entry->text;
754 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
758 WMenu*
759 wWorkspaceMenuMake(WScreen *scr, Bool titled)
761 WMenu *wsmenu;
763 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
764 if (!wsmenu) {
765 wwarning(_("could not create Workspace menu"));
766 return NULL;
769 /* callback to be called when an entry is edited */
770 wsmenu->on_edit = onMenuEntryEdited;
772 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
773 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
775 return wsmenu;
780 void
781 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
783 int i;
784 long ws;
785 char title[MAX_WORKSPACENAME_WIDTH+1];
786 WMenuEntry *entry;
787 int tmp;
789 if (!menu)
790 return;
792 if (menu->entry_no < scr->workspace_count+2) {
793 /* new workspace(s) added */
794 i = scr->workspace_count-(menu->entry_no-2);
795 ws = menu->entry_no - 2;
796 while (i>0) {
797 strcpy(title, scr->workspaces[ws]->name);
799 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
800 entry->flags.indicator = 1;
801 entry->flags.editable = 1;
803 i--;
804 ws++;
806 } else if (menu->entry_no > scr->workspace_count+2) {
807 /* removed workspace(s) */
808 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
809 wMenuRemoveItem(menu, i);
812 wMenuRealize(menu);
814 for (i=0; i<scr->workspace_count; i++) {
815 menu->entries[i+2]->flags.indicator_on = 0;
817 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
819 /* don't let user destroy current workspace */
820 if (scr->current_workspace == scr->workspace_count-1) {
821 wMenuSetEnabled(menu, 1, False);
822 } else {
823 wMenuSetEnabled(menu, 1, True);
826 tmp = menu->frame->top_width + 5;
827 /* if menu got unreachable, bring it to a visible place */
828 if (menu->frame_x < tmp - (int)menu->frame->core->width)
829 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
831 wMenuPaint(menu);
835 void
836 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
838 proplist_t parr, pstr;
839 proplist_t wks_state, old_wks_state;
840 proplist_t foo, bar;
841 int i;
843 make_keys();
845 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
846 parr = PLMakeArrayFromElements(NULL);
847 for (i=0; i < scr->workspace_count; i++) {
848 pstr = PLMakeString(scr->workspaces[i]->name);
849 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
850 PLRelease(pstr);
851 if (!wPreferences.flags.noclip) {
852 pstr = wClipSaveWorkspaceState(scr, i);
853 PLInsertDictionaryEntry(wks_state, dClip, pstr);
854 PLRelease(pstr);
855 } else if (old_wks_state!=NULL) {
856 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
857 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
858 PLInsertDictionaryEntry(wks_state, dClip, bar);
862 PLAppendArrayElement(parr, wks_state);
863 PLRelease(wks_state);
865 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
866 PLRelease(parr);
870 void
871 wWorkspaceRestoreState(WScreen *scr)
873 proplist_t parr, pstr, wks_state;
874 proplist_t clip_state;
875 int i, j, wscount;
877 make_keys();
879 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
881 if (!parr)
882 return;
884 wscount = scr->workspace_count;
885 for (i=0; i < PLGetNumberOfElements(parr); i++) {
886 wks_state = PLGetArrayElement(parr, i);
887 if (PLIsDictionary(wks_state))
888 pstr = PLGetDictionaryEntry(wks_state, dName);
889 else
890 pstr = wks_state;
891 if (i >= scr->workspace_count)
892 wWorkspaceNew(scr);
893 if (scr->workspace_menu) {
894 free(scr->workspace_menu->entries[i+2]->text);
895 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
896 scr->workspace_menu->flags.realized = 0;
898 free(scr->workspaces[i]->name);
899 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
900 if (!wPreferences.flags.noclip) {
901 clip_state = PLGetDictionaryEntry(wks_state, dClip);
902 if (scr->workspaces[i]->clip)
903 wDockDestroy(scr->workspaces[i]->clip);
904 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
905 WM_CLIP);
906 if (i>0)
907 wDockHideIcons(scr->workspaces[i]->clip);
909 /* We set the global icons here, because scr->workspaces[i]->clip
910 * was not valid in wDockRestoreState().
911 * There we only set icon->omnipresent to know which icons we
912 * need to set here.
914 for (j=0; j<scr->workspaces[i]->clip->max_icons; j++) {
915 WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j];
917 if (aicon && aicon->omnipresent) {
918 aicon->omnipresent = 0;
919 wClipMakeIconOmnipresent(aicon, True);
920 XMapWindow(dpy, aicon->icon->core->window);
924 #ifdef KWM_HINTS
925 wKWMUpdateWorkspaceNameHint(scr, i);
926 #endif
928 #ifdef GNOME_STUFF
929 wGNOMEUpdateWorkspaceNamesHint(scr);
930 #endif