- made deiconification not automatically focus window in sloppy focus
[wmaker-crm.git] / src / workspace.c
blob025bdffface129ae881771ec7e5b0c4ac23ee22a
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>
36 #include "WindowMaker.h"
37 #include "wcore.h"
38 #include "framewin.h"
39 #include "window.h"
40 #include "icon.h"
41 #include "funcs.h"
42 #include "menu.h"
43 #include "application.h"
44 #include "dock.h"
45 #include "actions.h"
46 #include "workspace.h"
47 #include "appicon.h"
48 #ifdef GNOME_STUFF
49 #include "gnome.h"
50 #endif
51 #ifdef KWM_HINTS
52 #include "kwm.h"
53 #endif
55 #include <proplist.h>
58 extern WPreferences wPreferences;
59 extern XContext wWinContext;
62 static proplist_t dWorkspaces=NULL;
63 static proplist_t dClip, dName;
66 static void
67 make_keys()
69 if (dWorkspaces!=NULL)
70 return;
72 dWorkspaces = PLMakeString("Workspaces");
73 dName = PLMakeString("Name");
74 dClip = PLMakeString("Clip");
78 void
79 wWorkspaceMake(WScreen *scr, int count)
81 while (count>0) {
82 wWorkspaceNew(scr);
83 count--;
88 int
89 wWorkspaceNew(WScreen *scr)
91 WWorkspace *wspace, **list;
92 int i;
94 if (scr->workspace_count < MAX_WORKSPACES) {
95 scr->workspace_count++;
97 wspace = wmalloc(sizeof(WWorkspace));
98 wspace->name = NULL;
100 #ifdef KWM_HINTS
101 if (scr->flags.kwm_syncing_count) {
102 wspace->name = wKWMGetWorkspaceName(scr, scr->workspace_count-1);
104 #endif
105 if (!wspace->name) {
106 wspace->name = wmalloc(strlen(_("Workspace %i"))+8);
107 sprintf(wspace->name, _("Workspace %i"), scr->workspace_count);
111 if (!wPreferences.flags.noclip) {
112 wspace->clip = wDockCreate(scr, WM_CLIP);
113 } else
114 wspace->clip = NULL;
116 list = wmalloc(sizeof(WWorkspace*)*scr->workspace_count);
118 for (i=0; i<scr->workspace_count-1; i++) {
119 list[i] = scr->workspaces[i];
121 list[i] = wspace;
122 free(scr->workspaces);
123 scr->workspaces = list;
125 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
126 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
127 #ifdef GNOME_STUFF
128 wGNOMEUpdateWorkspaceHints(scr);
129 #endif
130 #ifdef KWM_HINTS
131 if (!scr->flags.kwm_syncing_count) {
132 wKWMUpdateWorkspaceCountHint(scr);
133 wKWMUpdateWorkspaceNameHint(scr, scr->workspace_count-1);
135 #ifdef not_used
136 wKWMSetUsableAreaHint(scr, scr->workspace_count-1);
137 #endif
138 #endif
139 XFlush(dpy);
141 return scr->workspace_count-1;
143 return -1;
148 Bool
149 wWorkspaceDelete(WScreen *scr, int workspace)
151 WWindow *tmp;
152 WWorkspace **list;
153 int i, j;
156 if (workspace<=0)
157 return False;
159 /* verify if workspace is in use by some window */
160 tmp = scr->focused_window;
161 while (tmp) {
162 if (!IS_OMNIPRESENT(tmp) && tmp->frame->workspace==workspace)
163 return False;
164 tmp = tmp->prev;
167 if (!wPreferences.flags.noclip) {
168 wDockDestroy(scr->workspaces[workspace]->clip);
169 scr->workspaces[workspace]->clip = NULL;
172 list = wmalloc(sizeof(WWorkspace*)*(scr->workspace_count-1));
173 j = 0;
174 for (i=0; i<scr->workspace_count; i++) {
175 if (i!=workspace)
176 list[j++] = scr->workspaces[i];
177 else {
178 if (scr->workspaces[i]->name)
179 free(scr->workspaces[i]->name);
180 free(scr->workspaces[i]);
183 free(scr->workspaces);
184 scr->workspaces = list;
186 scr->workspace_count--;
189 /* update menu */
190 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
191 /* clip workspace menu */
192 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
194 /* update also window menu */
195 if (scr->workspace_submenu) {
196 WMenu *menu = scr->workspace_submenu;
198 i = menu->entry_no;
199 while (i>scr->workspace_count)
200 wMenuRemoveItem(menu, --i);
201 wMenuRealize(menu);
203 /* and clip menu */
204 if (scr->clip_submenu) {
205 WMenu *menu = scr->clip_submenu;
207 i = menu->entry_no;
208 while (i>scr->workspace_count)
209 wMenuRemoveItem(menu, --i);
210 wMenuRealize(menu);
213 #ifdef GNOME_STUFF
214 wGNOMEUpdateWorkspaceHints(scr);
215 #endif
216 #ifdef KWM_HINTS
217 wKWMUpdateWorkspaceCountHint(scr);
218 #endif
220 if (scr->current_workspace >= scr->workspace_count)
221 wWorkspaceChange(scr, scr->workspace_count-1);
223 return True;
227 typedef struct WorkspaceNameData {
228 int count;
229 RImage *back;
230 RImage *text;
231 } WorkspaceNameData;
235 static void
236 hideWorkpaceName(void *data)
238 WScreen *scr = (WScreen*)data;
240 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0) {
241 XUnmapWindow(dpy, scr->workspace_name);
243 if (scr->workspace_name_data) {
244 RDestroyImage(scr->workspace_name_data->back);
245 RDestroyImage(scr->workspace_name_data->text);
246 free(scr->workspace_name_data);
248 scr->workspace_name_data = NULL;
250 scr->workspace_name_timer = NULL;
251 } else {
252 RImage *img = RCloneImage(scr->workspace_name_data->back);
253 Pixmap pix;
255 scr->workspace_name_timer =
256 WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY, hideWorkpaceName,
257 scr);
259 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
260 scr->workspace_name_data->count*255/10);
262 RConvertImage(scr->rcontext, img, &pix);
264 RDestroyImage(img);
266 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
267 XClearWindow(dpy, scr->workspace_name);
268 XFreePixmap(dpy, pix);
269 XFlush(dpy);
271 scr->workspace_name_data->count--;
277 static void
278 showWorkspaceName(WScreen *scr, int workspace)
280 WorkspaceNameData *data;
281 RXImage *ximg;
282 Pixmap text, mask;
283 int w, h;
284 char *name = scr->workspaces[workspace]->name;
285 int len = strlen(name);
286 int x, y;
288 if (scr->workspace_name_timer) {
289 WMDeleteTimerHandler(scr->workspace_name_timer);
290 XUnmapWindow(dpy, scr->workspace_name);
291 XFlush(dpy);
293 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY,
294 hideWorkpaceName, scr);
296 if (scr->workspace_name_data) {
297 RDestroyImage(scr->workspace_name_data->back);
298 RDestroyImage(scr->workspace_name_data->text);
299 free(scr->workspace_name_data);
302 #ifndef I18N_MB
303 XSetFont(dpy, scr->mono_gc, scr->workspace_name_font->font->fid);
304 XSetFont(dpy, scr->draw_gc, scr->workspace_name_font->font->fid);
305 #endif
307 data = wmalloc(sizeof(WorkspaceNameData));
309 w = wTextWidth(scr->workspace_name_font->font, name, len);
310 h = scr->workspace_name_font->height;
312 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
313 XMoveWindow(dpy, scr->workspace_name, (scr->scr_width - (w+4))/2, 0);
315 (scr->scr_height - (h+4))/2);
318 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
319 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
321 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
322 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
324 XSetForeground(dpy, scr->mono_gc, 0);
325 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
327 XSetForeground(dpy, scr->mono_gc, 1);
328 for (x = 0; x <= 4; x++) {
329 for (y = 0; y <= 4; y++) {
330 wDrawString(mask, scr->workspace_name_font, scr->mono_gc,
331 x, scr->workspace_name_font->y + y, name, len);
335 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
336 wDrawString(text, scr->workspace_name_font, scr->draw_gc,
337 2, scr->workspace_name_font->y + 2,
338 scr->workspaces[workspace]->name,
339 strlen(scr->workspaces[workspace]->name));
340 #ifdef SHAPE
341 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
342 ShapeSet);
343 #endif
344 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
345 XClearWindow(dpy, scr->workspace_name);
347 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
349 XFreePixmap(dpy, text);
350 XFreePixmap(dpy, mask);
352 if (!data->text) {
353 XMapRaised(dpy, scr->workspace_name);
354 XFlush(dpy);
356 goto erro;
359 ximg = RGetXImage(scr->rcontext, scr->root_win,
360 (scr->scr_width - data->text->width)/2,
361 (scr->scr_height - data->text->height)/2,
362 data->text->width, data->text->height);
364 if (!ximg) {
365 goto erro;
368 XMapRaised(dpy, scr->workspace_name);
369 XFlush(dpy);
371 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
372 RDestroyXImage(scr->rcontext, ximg);
374 if (!data->back) {
375 goto erro;
378 data->count = 10;
380 scr->workspace_name_data = data;
382 return;
384 erro:
385 if (scr->workspace_name_timer)
386 WMDeleteTimerHandler(scr->workspace_name_timer);
388 if (data->text)
389 RDestroyImage(data->text);
390 if (data->back)
391 RDestroyImage(data->back);
392 free(data);
394 scr->workspace_name_data = NULL;
396 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
397 10*WORKSPACE_NAME_FADE_DELAY,
398 hideWorkpaceName, scr);
402 void
403 wWorkspaceChange(WScreen *scr, int workspace)
405 if (scr->flags.startup || scr->flags.startup2) {
406 return;
409 if (workspace != scr->current_workspace) {
410 wWorkspaceForceChange(scr, workspace);
411 } else {
412 if (!wPreferences.no_workspace_name_display)
413 showWorkspaceName(scr, workspace);
418 void
419 wWorkspaceRelativeChange(WScreen *scr, int amount)
421 int w;
423 w = scr->current_workspace + amount;
425 if (amount < 0) {
427 if (w >= 0)
428 wWorkspaceChange(scr, w);
429 else if (wPreferences.ws_cycle)
430 wWorkspaceChange(scr, scr->workspace_count + w);
432 } else if (amount > 0) {
434 if (w < scr->workspace_count)
435 wWorkspaceChange(scr, w);
436 else if (wPreferences.ws_advance)
437 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
438 else if (wPreferences.ws_cycle)
439 wWorkspaceChange(scr, w % scr->workspace_count);
445 void
446 wWorkspaceForceChange(WScreen *scr, int workspace)
448 WWindow *tmp, *foc=NULL, *foc2=NULL;
450 if (workspace >= MAX_WORKSPACES || workspace < 0)
451 return;
453 SendHelperMessage(scr, 'C', workspace+1, NULL);
455 if (workspace > scr->workspace_count-1) {
456 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
459 wClipUpdateForWorkspaceChange(scr, workspace);
461 scr->current_workspace = workspace;
463 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
465 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
467 if ((tmp = scr->focused_window)!= NULL) {
468 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
469 foc = tmp;
471 while (tmp) {
472 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
473 /* unmap windows not on this workspace */
474 if ((tmp->flags.mapped||tmp->flags.shaded)
475 && !IS_OMNIPRESENT(tmp)
476 && !tmp->flags.changing_workspace) {
478 wWindowUnmap(tmp);
480 /* also unmap miniwindows not on this workspace */
481 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
482 && tmp->icon) {
483 if (!wPreferences.sticky_icons) {
484 XUnmapWindow(dpy, tmp->icon->core->window);
485 tmp->icon->mapped = 0;
486 } else {
487 tmp->icon->mapped = 1;
488 /* Why is this here? -Alfredo */
489 XMapWindow(dpy, tmp->icon->core->window);
492 /* update current workspace of omnipresent windows */
493 if (IS_OMNIPRESENT(tmp)) {
494 WApplication *wapp = wApplicationOf(tmp->main_window);
496 tmp->frame->workspace = workspace;
498 if (wapp) {
499 wapp->last_workspace = workspace;
501 if (!foc2)
502 foc2 = tmp;
504 } else {
505 /* change selected windows' workspace */
506 if (tmp->flags.selected) {
507 wWindowChangeWorkspace(tmp, workspace);
508 if (!tmp->flags.miniaturized && !foc) {
509 foc = tmp;
511 } else {
512 if (!tmp->flags.hidden) {
513 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
514 /* remap windows that are on this workspace */
515 wWindowMap(tmp);
516 if (!foc)
517 foc = tmp;
519 /* Also map miniwindow if not omnipresent */
520 if (!wPreferences.sticky_icons &&
521 tmp->flags.miniaturized &&
522 !IS_OMNIPRESENT(tmp) && tmp->icon) {
523 tmp->icon->mapped = 1;
524 XMapWindow(dpy, tmp->icon->core->window);
529 tmp = tmp->prev;
532 if (!foc)
533 foc = foc2;
535 if (scr->focused_window->flags.mapped && !foc) {
536 foc = scr->focused_window;
538 if (wPreferences.focus_mode == WKF_CLICK) {
539 wSetFocusTo(scr, foc);
540 } else {
541 unsigned int mask;
542 int foo;
543 Window bar, win;
544 WWindow *tmp;
546 tmp = NULL;
547 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
548 &foo, &foo, &foo, &foo, &mask)) {
549 tmp = wWindowFor(win);
551 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
552 wSetFocusTo(scr, foc);
553 } else {
554 wSetFocusTo(scr, tmp);
559 /* We need to always arrange icons when changing workspace, even if
560 * no autoarrange icons, because else the icons in different workspaces
561 * can be superposed.
562 * This can be avoided if appicons are also workspace specific.
564 if (!wPreferences.sticky_icons)
565 wArrangeIcons(scr, False);
567 if (scr->dock)
568 wAppIconPaint(scr->dock->icon_array[0]);
569 if (scr->clip_icon) {
570 if (scr->workspaces[workspace]->clip->auto_collapse ||
571 scr->workspaces[workspace]->clip->auto_raise_lower) {
572 /* to handle enter notify. This will also */
573 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
574 XMapWindow(dpy, scr->clip_icon->icon->core->window);
575 } else {
576 wClipIconPaint(scr->clip_icon);
580 if (!wPreferences.no_workspace_name_display)
581 showWorkspaceName(scr, workspace);
583 #ifdef GNOME_STUFF
584 wGNOMEUpdateCurrentWorkspaceHint(scr);
585 #endif
586 #ifdef KWM_HINTS
587 wKWMUpdateCurrentWorkspaceHint(scr);
588 #endif
589 /* XSync(dpy, False); */
593 static void
594 switchWSCommand(WMenu *menu, WMenuEntry *entry)
596 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
601 static void
602 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
604 wWorkspaceDelete(menu->frame->screen_ptr,
605 menu->frame->screen_ptr->workspace_count-1);
610 static void
611 newWSCommand(WMenu *menu, WMenuEntry *foo)
613 int ws;
615 ws = wWorkspaceNew(menu->frame->screen_ptr);
616 /* autochange workspace*/
617 if (ws>=0)
618 wWorkspaceChange(menu->frame->screen_ptr, ws);
622 if (ws<9) {
623 int kcode;
624 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
625 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
626 entry->rtext =
627 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
633 static char*
634 cropline(char *line)
636 char *start, *end;
638 if (strlen(line)==0)
639 return line;
641 start = line;
642 end = &(line[strlen(line)])-1;
643 while (isspace(*line) && *line!=0) line++;
644 while (isspace(*end) && end!=line) {
645 *end=0;
646 end--;
648 return line;
652 void
653 wWorkspaceRename(WScreen *scr, int workspace, char *name)
655 char buf[MAX_WORKSPACENAME_WIDTH+1];
656 char *tmp;
658 if (workspace >= scr->workspace_count)
659 return;
661 /* trim white spaces */
662 tmp = cropline(name);
664 if (strlen(tmp)==0) {
665 sprintf(buf, _("Workspace %i"), workspace+1);
666 } else {
667 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
669 buf[MAX_WORKSPACENAME_WIDTH] = 0;
671 /* update workspace */
672 free(scr->workspaces[workspace]->name);
673 scr->workspaces[workspace]->name = wstrdup(buf);
675 if (scr->clip_ws_menu) {
676 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
677 free(scr->clip_ws_menu->entries[workspace+2]->text);
678 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
679 wMenuRealize(scr->clip_ws_menu);
682 if (scr->workspace_menu) {
683 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
684 free(scr->workspace_menu->entries[workspace+2]->text);
685 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
686 wMenuRealize(scr->workspace_menu);
690 UpdateSwitchMenuWorkspace(scr, workspace);
692 if (scr->clip_icon)
693 wClipIconPaint(scr->clip_icon);
695 #ifdef GNOME_STUFF
696 wGNOMEUpdateWorkspaceNamesHint(scr);
697 #endif
698 #ifdef KWM_HINTS
699 wKWMUpdateWorkspaceNameHint(scr, workspace);
700 #endif
706 /* callback for when menu entry is edited */
707 static void
708 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
710 char *tmp;
712 tmp = entry->text;
713 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
717 WMenu*
718 wWorkspaceMenuMake(WScreen *scr, Bool titled)
720 WMenu *wsmenu;
722 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
723 if (!wsmenu) {
724 wwarning(_("could not create Workspace menu"));
725 return NULL;
728 /* callback to be called when an entry is edited */
729 wsmenu->on_edit = onMenuEntryEdited;
731 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
732 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
734 return wsmenu;
739 void
740 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
742 int i;
743 long ws;
744 char title[MAX_WORKSPACENAME_WIDTH+1];
745 WMenuEntry *entry;
746 int tmp;
748 if (!menu)
749 return;
751 if (menu->entry_no < scr->workspace_count+2) {
752 /* new workspace(s) added */
753 i = scr->workspace_count-(menu->entry_no-2);
754 ws = menu->entry_no - 2;
755 while (i>0) {
756 strcpy(title, scr->workspaces[ws]->name);
758 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
759 entry->flags.indicator = 1;
760 entry->flags.editable = 1;
762 i--;
763 ws++;
765 } else if (menu->entry_no > scr->workspace_count+2) {
766 /* removed workspace(s) */
767 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
768 wMenuRemoveItem(menu, i);
771 wMenuRealize(menu);
773 for (i=0; i<scr->workspace_count; i++) {
774 menu->entries[i+2]->flags.indicator_on = 0;
776 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
778 /* don't let user destroy current workspace */
779 if (scr->current_workspace == scr->workspace_count-1) {
780 wMenuSetEnabled(menu, 1, False);
781 } else {
782 wMenuSetEnabled(menu, 1, True);
785 tmp = menu->frame->top_width + 5;
786 /* if menu got unreachable, bring it to a visible place */
787 if (menu->frame_x < tmp - (int)menu->frame->core->width)
788 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
790 wMenuPaint(menu);
794 void
795 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
797 proplist_t parr, pstr;
798 proplist_t wks_state, old_wks_state;
799 proplist_t foo, bar;
800 int i;
802 make_keys();
804 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
805 parr = PLMakeArrayFromElements(NULL);
806 for (i=0; i < scr->workspace_count; i++) {
807 pstr = PLMakeString(scr->workspaces[i]->name);
808 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
809 PLRelease(pstr);
810 if (!wPreferences.flags.noclip) {
811 pstr = wClipSaveWorkspaceState(scr, i);
812 PLInsertDictionaryEntry(wks_state, dClip, pstr);
813 PLRelease(pstr);
814 } else if (old_wks_state!=NULL) {
815 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
816 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
817 PLInsertDictionaryEntry(wks_state, dClip, bar);
821 PLAppendArrayElement(parr, wks_state);
822 PLRelease(wks_state);
824 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
825 PLRelease(parr);
829 void
830 wWorkspaceRestoreState(WScreen *scr)
832 proplist_t parr, pstr, wks_state;
833 proplist_t clip_state;
834 int i, wscount;
836 make_keys();
838 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
840 if (!parr)
841 return;
843 wscount = scr->workspace_count;
844 for (i=0; i < PLGetNumberOfElements(parr); i++) {
845 wks_state = PLGetArrayElement(parr, i);
846 if (PLIsDictionary(wks_state))
847 pstr = PLGetDictionaryEntry(wks_state, dName);
848 else
849 pstr = wks_state;
850 if (i >= scr->workspace_count)
851 wWorkspaceNew(scr);
852 if (scr->workspace_menu) {
853 free(scr->workspace_menu->entries[i+2]->text);
854 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
855 scr->workspace_menu->flags.realized = 0;
857 free(scr->workspaces[i]->name);
858 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
859 if (!wPreferences.flags.noclip) {
860 clip_state = PLGetDictionaryEntry(wks_state, dClip);
861 if (scr->workspaces[i]->clip)
862 wDockDestroy(scr->workspaces[i]->clip);
863 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
864 WM_CLIP);
865 if (i>0)
866 wDockHideIcons(scr->workspaces[i]->clip);
868 #ifdef KWM_HINTS
869 wKWMUpdateWorkspaceNameHint(scr, i);
870 #endif
872 #ifdef GNOME_STUFF
873 wGNOMEUpdateWorkspaceNamesHint(scr);
874 #endif