show workspace name when changing workspace
[wmaker-crm.git] / src / workspace.c
blob22b673fcdb2b298f897efb9ca8f762997227dba4
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;
241 if (!scr->workspace_name_data || scr->workspace_name_data->count == 0) {
242 XUnmapWindow(dpy, scr->workspace_name);
244 if (scr->workspace_name_data) {
245 RDestroyImage(scr->workspace_name_data->back);
246 RDestroyImage(scr->workspace_name_data->text);
247 free(scr->workspace_name_data);
249 scr->workspace_name_data = NULL;
251 scr->workspace_name_timer = NULL;
252 } else {
253 RImage *img = RCloneImage(scr->workspace_name_data->back);
254 Pixmap pix;
256 RCombineImagesWithOpaqueness(img, scr->workspace_name_data->text,
257 scr->workspace_name_data->count*255/10);
259 RConvertImage(scr->rcontext, img, &pix);
261 RDestroyImage(img);
263 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, pix);
264 XClearWindow(dpy, scr->workspace_name);
265 XFreePixmap(dpy, pix);
266 XFlush(dpy);
268 scr->workspace_name_data->count--;
270 scr->workspace_name_timer = WMAddTimerHandler(40, hideWorkpaceName,
271 scr);
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);
294 if (scr->workspace_name_data) {
295 RDestroyImage(scr->workspace_name_data->back);
296 RDestroyImage(scr->workspace_name_data->text);
297 free(scr->workspace_name_data);
300 #ifndef I18N_MB
301 XSetFont(dpy, scr->mono_gc, scr->workspace_name_font->font->fid);
302 XSetFont(dpy, scr->draw_gc, scr->workspace_name_font->font->fid);
303 #endif
305 data = wmalloc(sizeof(WorkspaceNameData));
307 w = wTextWidth(scr->workspace_name_font->font, name, len);
308 h = scr->workspace_name_font->height;
310 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
311 XMoveWindow(dpy, scr->workspace_name, (scr->scr_width - (w+4))/2,
312 (scr->scr_height - (h+4))/2);
314 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
315 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
317 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
318 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
320 XSetForeground(dpy, scr->mono_gc, 0);
321 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
323 XSetForeground(dpy, scr->mono_gc, 1);
324 for (x = 0; x <= 4; x++) {
325 for (y = 0; y <= 4; y++) {
326 wDrawString(mask, scr->workspace_name_font, scr->mono_gc,
327 x, scr->workspace_name_font->y + y, name, len);
331 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
332 wDrawString(text, scr->workspace_name_font, scr->draw_gc,
333 2, scr->workspace_name_font->y + 2,
334 scr->workspaces[workspace]->name,
335 strlen(scr->workspaces[workspace]->name));
336 #ifdef SHAPE
337 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
338 ShapeSet);
339 #endif
340 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
341 XClearWindow(dpy, scr->workspace_name);
343 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
345 XFreePixmap(dpy, text);
346 XFreePixmap(dpy, mask);
348 if (!data->text) {
349 XMapRaised(dpy, scr->workspace_name);
350 XFlush(dpy);
352 goto erro;
355 ximg = RGetXImage(scr->rcontext, scr->root_win,
356 (scr->scr_width - data->text->width)/2,
357 (scr->scr_height - data->text->height)/2,
358 data->text->width, data->text->height);
360 if (!ximg) {
361 goto erro;
364 XMapRaised(dpy, scr->workspace_name);
365 XFlush(dpy);
367 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
368 RDestroyXImage(scr->rcontext, ximg);
370 if (!data->back) {
371 goto erro;
374 data->count = 10;
376 scr->workspace_name_data = data;
378 scr->workspace_name_timer = WMAddTimerHandler(200, hideWorkpaceName, scr);
380 return;
382 erro:
383 if (data->text)
384 RDestroyImage(data->text);
385 if (data->back)
386 RDestroyImage(data->back);
387 free(data);
389 scr->workspace_name_data = NULL;
391 scr->workspace_name_timer = WMAddTimerHandler(600, hideWorkpaceName, scr);
395 void
396 wWorkspaceChange(WScreen *scr, int workspace)
398 if (scr->flags.startup || scr->flags.startup2) {
399 return;
402 if (workspace != scr->current_workspace) {
403 wWorkspaceForceChange(scr, workspace);
404 } else {
405 showWorkspaceName(scr, workspace);
410 void
411 wWorkspaceRelativeChange(WScreen *scr, int amount)
413 int w;
415 w = scr->current_workspace + amount;
417 if (amount < 0) {
419 if (w >= 0)
420 wWorkspaceChange(scr, w);
421 else if (wPreferences.ws_cycle)
422 wWorkspaceChange(scr, scr->workspace_count + w);
424 } else if (amount > 0) {
426 if (w < scr->workspace_count)
427 wWorkspaceChange(scr, w);
428 else if (wPreferences.ws_advance)
429 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
430 else if (wPreferences.ws_cycle)
431 wWorkspaceChange(scr, w % scr->workspace_count);
437 void
438 wWorkspaceForceChange(WScreen *scr, int workspace)
440 WWindow *tmp, *foc=NULL, *foc2=NULL;
442 if (workspace >= MAX_WORKSPACES || workspace < 0)
443 return;
445 SendHelperMessage(scr, 'C', workspace+1, NULL);
447 if (workspace > scr->workspace_count-1) {
448 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
451 wClipUpdateForWorkspaceChange(scr, workspace);
453 scr->current_workspace = workspace;
455 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
457 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
459 if ((tmp = scr->focused_window)!= NULL) {
460 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
461 foc = tmp;
463 while (tmp) {
464 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
465 /* unmap windows not on this workspace */
466 if ((tmp->flags.mapped||tmp->flags.shaded)
467 && !IS_OMNIPRESENT(tmp)
468 && !tmp->flags.changing_workspace) {
470 wWindowUnmap(tmp);
472 /* also unmap miniwindows not on this workspace */
473 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
474 && tmp->icon) {
475 if (!wPreferences.sticky_icons) {
476 XUnmapWindow(dpy, tmp->icon->core->window);
477 tmp->icon->mapped = 0;
478 } else {
479 tmp->icon->mapped = 1;
480 /* Why is this here? -Alfredo */
481 XMapWindow(dpy, tmp->icon->core->window);
484 /* update current workspace of omnipresent windows */
485 if (IS_OMNIPRESENT(tmp)) {
486 WApplication *wapp = wApplicationOf(tmp->main_window);
488 tmp->frame->workspace = workspace;
490 if (wapp) {
491 wapp->last_workspace = workspace;
493 if (!foc2)
494 foc2 = tmp;
496 } else {
497 /* change selected windows' workspace */
498 if (tmp->flags.selected) {
499 wWindowChangeWorkspace(tmp, workspace);
500 if (!tmp->flags.miniaturized && !foc) {
501 foc = tmp;
503 } else {
504 if (!tmp->flags.hidden) {
505 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
506 /* remap windows that are on this workspace */
507 wWindowMap(tmp);
508 if (!foc)
509 foc = tmp;
511 /* Also map miniwindow if not omnipresent */
512 if (!wPreferences.sticky_icons &&
513 tmp->flags.miniaturized &&
514 !IS_OMNIPRESENT(tmp) && tmp->icon) {
515 tmp->icon->mapped = 1;
516 XMapWindow(dpy, tmp->icon->core->window);
521 tmp = tmp->prev;
524 if (!foc)
525 foc = foc2;
527 if (scr->focused_window->flags.mapped && !foc) {
528 foc = scr->focused_window;
530 if (wPreferences.focus_mode == WKF_CLICK) {
531 wSetFocusTo(scr, foc);
532 } else {
533 unsigned int mask;
534 int foo;
535 Window bar, win;
536 WWindow *tmp;
538 tmp = NULL;
539 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
540 &foo, &foo, &foo, &foo, &mask)) {
541 tmp = wWindowFor(win);
543 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
544 wSetFocusTo(scr, foc);
545 } else {
546 wSetFocusTo(scr, tmp);
551 /* We need to always arrange icons when changing workspace, even if
552 * no autoarrange icons, because else the icons in different workspaces
553 * can be superposed.
554 * This can be avoided if appicons are also workspace specific.
556 if (!wPreferences.sticky_icons)
557 wArrangeIcons(scr, False);
559 if (scr->dock)
560 wAppIconPaint(scr->dock->icon_array[0]);
561 if (scr->clip_icon) {
562 if (scr->workspaces[workspace]->clip->auto_collapse ||
563 scr->workspaces[workspace]->clip->auto_raise_lower) {
564 /* to handle enter notify. This will also */
565 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
566 XMapWindow(dpy, scr->clip_icon->icon->core->window);
567 } else {
568 wClipIconPaint(scr->clip_icon);
572 showWorkspaceName(scr, workspace);
574 #ifdef GNOME_STUFF
575 wGNOMEUpdateCurrentWorkspaceHint(scr);
576 #endif
577 #ifdef KWM_HINTS
578 wKWMUpdateCurrentWorkspaceHint(scr);
579 #endif
580 /* XSync(dpy, False); */
584 static void
585 switchWSCommand(WMenu *menu, WMenuEntry *entry)
587 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
592 static void
593 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
595 wWorkspaceDelete(menu->frame->screen_ptr,
596 menu->frame->screen_ptr->workspace_count-1);
601 static void
602 newWSCommand(WMenu *menu, WMenuEntry *foo)
604 int ws;
606 ws = wWorkspaceNew(menu->frame->screen_ptr);
607 /* autochange workspace*/
608 if (ws>=0)
609 wWorkspaceChange(menu->frame->screen_ptr, ws);
613 if (ws<9) {
614 int kcode;
615 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
616 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
617 entry->rtext =
618 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
624 static char*
625 cropline(char *line)
627 char *start, *end;
629 if (strlen(line)==0)
630 return line;
632 start = line;
633 end = &(line[strlen(line)])-1;
634 while (isspace(*line) && *line!=0) line++;
635 while (isspace(*end) && end!=line) {
636 *end=0;
637 end--;
639 return line;
643 void
644 wWorkspaceRename(WScreen *scr, int workspace, char *name)
646 char buf[MAX_WORKSPACENAME_WIDTH+1];
647 char *tmp;
649 if (workspace >= scr->workspace_count)
650 return;
652 /* trim white spaces */
653 tmp = cropline(name);
655 if (strlen(tmp)==0) {
656 sprintf(buf, _("Workspace %i"), workspace+1);
657 } else {
658 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
660 buf[MAX_WORKSPACENAME_WIDTH] = 0;
662 /* update workspace */
663 free(scr->workspaces[workspace]->name);
664 scr->workspaces[workspace]->name = wstrdup(buf);
666 if (scr->clip_ws_menu) {
667 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
668 free(scr->clip_ws_menu->entries[workspace+2]->text);
669 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
670 wMenuRealize(scr->clip_ws_menu);
673 if (scr->workspace_menu) {
674 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
675 free(scr->workspace_menu->entries[workspace+2]->text);
676 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
677 wMenuRealize(scr->workspace_menu);
681 UpdateSwitchMenuWorkspace(scr, workspace);
683 if (scr->clip_icon)
684 wClipIconPaint(scr->clip_icon);
686 #ifdef GNOME_STUFF
687 wGNOMEUpdateWorkspaceNamesHint(scr);
688 #endif
689 #ifdef KWM_HINTS
690 wKWMUpdateWorkspaceNameHint(scr, workspace);
691 #endif
697 /* callback for when menu entry is edited */
698 static void
699 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
701 char *tmp;
703 tmp = entry->text;
704 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
708 WMenu*
709 wWorkspaceMenuMake(WScreen *scr, Bool titled)
711 WMenu *wsmenu;
713 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
714 if (!wsmenu) {
715 wwarning(_("could not create Workspace menu"));
716 return NULL;
719 /* callback to be called when an entry is edited */
720 wsmenu->on_edit = onMenuEntryEdited;
722 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
723 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
725 return wsmenu;
730 void
731 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
733 int i;
734 long ws;
735 char title[MAX_WORKSPACENAME_WIDTH+1];
736 WMenuEntry *entry;
737 int tmp;
739 if (!menu)
740 return;
742 if (menu->entry_no < scr->workspace_count+2) {
743 /* new workspace(s) added */
744 i = scr->workspace_count-(menu->entry_no-2);
745 ws = menu->entry_no - 2;
746 while (i>0) {
747 strcpy(title, scr->workspaces[ws]->name);
749 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
750 entry->flags.indicator = 1;
751 entry->flags.editable = 1;
753 i--;
754 ws++;
756 } else if (menu->entry_no > scr->workspace_count+2) {
757 /* removed workspace(s) */
758 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
759 wMenuRemoveItem(menu, i);
762 wMenuRealize(menu);
764 for (i=0; i<scr->workspace_count; i++) {
765 menu->entries[i+2]->flags.indicator_on = 0;
767 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
769 /* don't let user destroy current workspace */
770 if (scr->current_workspace == scr->workspace_count-1) {
771 wMenuSetEnabled(menu, 1, False);
772 } else {
773 wMenuSetEnabled(menu, 1, True);
776 tmp = menu->frame->top_width + 5;
777 /* if menu got unreachable, bring it to a visible place */
778 if (menu->frame_x < tmp - (int)menu->frame->core->width)
779 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
781 wMenuPaint(menu);
785 void
786 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
788 proplist_t parr, pstr;
789 proplist_t wks_state, old_wks_state;
790 proplist_t foo, bar;
791 int i;
793 make_keys();
795 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
796 parr = PLMakeArrayFromElements(NULL);
797 for (i=0; i < scr->workspace_count; i++) {
798 pstr = PLMakeString(scr->workspaces[i]->name);
799 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
800 PLRelease(pstr);
801 if (!wPreferences.flags.noclip) {
802 pstr = wClipSaveWorkspaceState(scr, i);
803 PLInsertDictionaryEntry(wks_state, dClip, pstr);
804 PLRelease(pstr);
805 } else if (old_wks_state!=NULL) {
806 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
807 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
808 PLInsertDictionaryEntry(wks_state, dClip, bar);
812 PLAppendArrayElement(parr, wks_state);
813 PLRelease(wks_state);
815 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
816 PLRelease(parr);
820 void
821 wWorkspaceRestoreState(WScreen *scr)
823 proplist_t parr, pstr, wks_state;
824 proplist_t clip_state;
825 int i, wscount;
827 make_keys();
829 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
831 if (!parr)
832 return;
834 wscount = scr->workspace_count;
835 for (i=0; i < PLGetNumberOfElements(parr); i++) {
836 wks_state = PLGetArrayElement(parr, i);
837 if (PLIsDictionary(wks_state))
838 pstr = PLGetDictionaryEntry(wks_state, dName);
839 else
840 pstr = wks_state;
841 if (i >= scr->workspace_count)
842 wWorkspaceNew(scr);
843 if (scr->workspace_menu) {
844 free(scr->workspace_menu->entries[i+2]->text);
845 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
846 scr->workspace_menu->flags.realized = 0;
848 free(scr->workspaces[i]->name);
849 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
850 if (!wPreferences.flags.noclip) {
851 clip_state = PLGetDictionaryEntry(wks_state, dClip);
852 if (scr->workspaces[i]->clip)
853 wDockDestroy(scr->workspaces[i]->clip);
854 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
855 WM_CLIP);
856 if (i>0)
857 wDockHideIcons(scr->workspaces[i]->clip);
859 #ifdef KWM_HINTS
860 wKWMUpdateWorkspaceNameHint(scr, i);
861 #endif
863 #ifdef GNOME_STUFF
864 wGNOMEUpdateWorkspaceNamesHint(scr);
865 #endif