Made the secure textfield give some feedback about what is happening.
[wmaker-crm.git] / src / workspace.c
blob5e0003e6a913a63bff26e3924bbb65761f4cfdb2
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 int px, py;
285 char *name = scr->workspaces[workspace]->name;
286 int len = strlen(name);
287 int x, y;
289 if (wPreferences.workspace_name_display_position == WD_NONE)
290 return;
292 if (scr->workspace_name_timer) {
293 WMDeleteTimerHandler(scr->workspace_name_timer);
294 XUnmapWindow(dpy, scr->workspace_name);
295 XFlush(dpy);
297 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY,
298 hideWorkpaceName, scr);
300 if (scr->workspace_name_data) {
301 RDestroyImage(scr->workspace_name_data->back);
302 RDestroyImage(scr->workspace_name_data->text);
303 free(scr->workspace_name_data);
306 #ifndef I18N_MB
307 XSetFont(dpy, scr->mono_gc, scr->workspace_name_font->font->fid);
308 XSetFont(dpy, scr->draw_gc, scr->workspace_name_font->font->fid);
309 #endif
311 data = wmalloc(sizeof(WorkspaceNameData));
313 w = wTextWidth(scr->workspace_name_font->font, name, len);
314 h = scr->workspace_name_font->height;
316 switch (wPreferences.workspace_name_display_position) {
317 case WD_CENTER:
318 px = (scr->scr_width - (w+4))/2;
319 py = (scr->scr_height - (h+4))/2;
320 break;
321 case WD_TOP:
322 px = (scr->scr_width - (w+4))/2;
323 py = 0;
324 break;
325 case WD_BOTTOM:
326 px = (scr->scr_width - (w+4))/2;
327 py = scr->scr_height - h;
328 break;
329 case WD_TOPLEFT:
330 px = 0;
331 py = 0;
332 break;
333 case WD_TOPRIGHT:
334 px = scr->scr_width - w;
335 py = 0;
336 break;
337 case WD_BOTTOMLEFT:
338 px = 0;
339 py = scr->scr_height - h;
340 break;
341 case WD_BOTTOMRIGHT:
342 px = scr->scr_width - w;
343 py = scr->scr_height - h;
344 break;
346 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
347 XMoveWindow(dpy, scr->workspace_name, px, py);
349 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
350 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
352 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
353 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
355 XSetForeground(dpy, scr->mono_gc, 0);
356 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
358 XSetForeground(dpy, scr->mono_gc, 1);
359 for (x = 0; x <= 4; x++) {
360 for (y = 0; y <= 4; y++) {
361 wDrawString(mask, scr->workspace_name_font, scr->mono_gc,
362 x, scr->workspace_name_font->y + y, name, len);
366 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
367 wDrawString(text, scr->workspace_name_font, scr->draw_gc,
368 2, scr->workspace_name_font->y + 2,
369 scr->workspaces[workspace]->name,
370 strlen(scr->workspaces[workspace]->name));
371 #ifdef SHAPE
372 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
373 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,
391 data->text->width, data->text->height);
393 if (!ximg) {
394 goto erro;
397 XMapRaised(dpy, scr->workspace_name);
398 XFlush(dpy);
400 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
401 RDestroyXImage(scr->rcontext, ximg);
403 if (!data->back) {
404 goto erro;
407 data->count = 10;
409 scr->workspace_name_data = data;
411 return;
413 erro:
414 if (scr->workspace_name_timer)
415 WMDeleteTimerHandler(scr->workspace_name_timer);
417 if (data->text)
418 RDestroyImage(data->text);
419 if (data->back)
420 RDestroyImage(data->back);
421 free(data);
423 scr->workspace_name_data = NULL;
425 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
426 10*WORKSPACE_NAME_FADE_DELAY,
427 hideWorkpaceName, scr);
431 void
432 wWorkspaceChange(WScreen *scr, int workspace)
434 if (scr->flags.startup || scr->flags.startup2) {
435 return;
438 if (workspace != scr->current_workspace) {
439 wWorkspaceForceChange(scr, workspace);
440 } else {
441 showWorkspaceName(scr, workspace);
446 void
447 wWorkspaceRelativeChange(WScreen *scr, int amount)
449 int w;
451 w = scr->current_workspace + amount;
453 if (amount < 0) {
455 if (w >= 0)
456 wWorkspaceChange(scr, w);
457 else if (wPreferences.ws_cycle)
458 wWorkspaceChange(scr, scr->workspace_count + w);
460 } else if (amount > 0) {
462 if (w < scr->workspace_count)
463 wWorkspaceChange(scr, w);
464 else if (wPreferences.ws_advance)
465 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
466 else if (wPreferences.ws_cycle)
467 wWorkspaceChange(scr, w % scr->workspace_count);
473 void
474 wWorkspaceForceChange(WScreen *scr, int workspace)
476 WWindow *tmp, *foc=NULL, *foc2=NULL;
478 if (workspace >= MAX_WORKSPACES || workspace < 0)
479 return;
481 SendHelperMessage(scr, 'C', workspace+1, NULL);
483 if (workspace > scr->workspace_count-1) {
484 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
487 wClipUpdateForWorkspaceChange(scr, workspace);
489 scr->current_workspace = workspace;
491 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
493 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
495 if ((tmp = scr->focused_window)!= NULL) {
496 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
497 foc = tmp;
499 while (tmp) {
500 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
501 /* unmap windows not on this workspace */
502 if ((tmp->flags.mapped||tmp->flags.shaded)
503 && !IS_OMNIPRESENT(tmp)
504 && !tmp->flags.changing_workspace) {
506 wWindowUnmap(tmp);
508 /* also unmap miniwindows not on this workspace */
509 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
510 && tmp->icon) {
511 if (!wPreferences.sticky_icons) {
512 XUnmapWindow(dpy, tmp->icon->core->window);
513 tmp->icon->mapped = 0;
514 } else {
515 tmp->icon->mapped = 1;
516 /* Why is this here? -Alfredo */
517 XMapWindow(dpy, tmp->icon->core->window);
520 /* update current workspace of omnipresent windows */
521 if (IS_OMNIPRESENT(tmp)) {
522 WApplication *wapp = wApplicationOf(tmp->main_window);
524 tmp->frame->workspace = workspace;
526 if (wapp) {
527 wapp->last_workspace = workspace;
529 if (!foc2)
530 foc2 = tmp;
532 } else {
533 /* change selected windows' workspace */
534 if (tmp->flags.selected) {
535 wWindowChangeWorkspace(tmp, workspace);
536 if (!tmp->flags.miniaturized && !foc) {
537 foc = tmp;
539 } else {
540 if (!tmp->flags.hidden) {
541 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
542 /* remap windows that are on this workspace */
543 wWindowMap(tmp);
544 if (!foc)
545 foc = tmp;
547 /* Also map miniwindow if not omnipresent */
548 if (!wPreferences.sticky_icons &&
549 tmp->flags.miniaturized &&
550 !IS_OMNIPRESENT(tmp) && tmp->icon) {
551 tmp->icon->mapped = 1;
552 XMapWindow(dpy, tmp->icon->core->window);
557 tmp = tmp->prev;
560 if (!foc)
561 foc = foc2;
563 if (scr->focused_window->flags.mapped && !foc) {
564 foc = scr->focused_window;
566 if (wPreferences.focus_mode == WKF_CLICK) {
567 wSetFocusTo(scr, foc);
568 } else {
569 unsigned int mask;
570 int foo;
571 Window bar, win;
572 WWindow *tmp;
574 tmp = NULL;
575 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
576 &foo, &foo, &foo, &foo, &mask)) {
577 tmp = wWindowFor(win);
579 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
580 wSetFocusTo(scr, foc);
581 } else {
582 wSetFocusTo(scr, tmp);
587 /* We need to always arrange icons when changing workspace, even if
588 * no autoarrange icons, because else the icons in different workspaces
589 * can be superposed.
590 * This can be avoided if appicons are also workspace specific.
592 if (!wPreferences.sticky_icons)
593 wArrangeIcons(scr, False);
595 if (scr->dock)
596 wAppIconPaint(scr->dock->icon_array[0]);
597 if (scr->clip_icon) {
598 if (scr->workspaces[workspace]->clip->auto_collapse ||
599 scr->workspaces[workspace]->clip->auto_raise_lower) {
600 /* to handle enter notify. This will also */
601 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
602 XMapWindow(dpy, scr->clip_icon->icon->core->window);
603 } else {
604 wClipIconPaint(scr->clip_icon);
608 showWorkspaceName(scr, workspace);
610 #ifdef GNOME_STUFF
611 wGNOMEUpdateCurrentWorkspaceHint(scr);
612 #endif
613 #ifdef KWM_HINTS
614 wKWMUpdateCurrentWorkspaceHint(scr);
615 #endif
616 /* XSync(dpy, False); */
620 static void
621 switchWSCommand(WMenu *menu, WMenuEntry *entry)
623 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
628 static void
629 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
631 wWorkspaceDelete(menu->frame->screen_ptr,
632 menu->frame->screen_ptr->workspace_count-1);
637 static void
638 newWSCommand(WMenu *menu, WMenuEntry *foo)
640 int ws;
642 ws = wWorkspaceNew(menu->frame->screen_ptr);
643 /* autochange workspace*/
644 if (ws>=0)
645 wWorkspaceChange(menu->frame->screen_ptr, ws);
649 if (ws<9) {
650 int kcode;
651 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
652 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
653 entry->rtext =
654 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
660 static char*
661 cropline(char *line)
663 char *start, *end;
665 if (strlen(line)==0)
666 return line;
668 start = line;
669 end = &(line[strlen(line)])-1;
670 while (isspace(*line) && *line!=0) line++;
671 while (isspace(*end) && end!=line) {
672 *end=0;
673 end--;
675 return line;
679 void
680 wWorkspaceRename(WScreen *scr, int workspace, char *name)
682 char buf[MAX_WORKSPACENAME_WIDTH+1];
683 char *tmp;
685 if (workspace >= scr->workspace_count)
686 return;
688 /* trim white spaces */
689 tmp = cropline(name);
691 if (strlen(tmp)==0) {
692 sprintf(buf, _("Workspace %i"), workspace+1);
693 } else {
694 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
696 buf[MAX_WORKSPACENAME_WIDTH] = 0;
698 /* update workspace */
699 free(scr->workspaces[workspace]->name);
700 scr->workspaces[workspace]->name = wstrdup(buf);
702 if (scr->clip_ws_menu) {
703 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
704 free(scr->clip_ws_menu->entries[workspace+2]->text);
705 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
706 wMenuRealize(scr->clip_ws_menu);
709 if (scr->workspace_menu) {
710 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
711 free(scr->workspace_menu->entries[workspace+2]->text);
712 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
713 wMenuRealize(scr->workspace_menu);
717 UpdateSwitchMenuWorkspace(scr, workspace);
719 if (scr->clip_icon)
720 wClipIconPaint(scr->clip_icon);
722 #ifdef GNOME_STUFF
723 wGNOMEUpdateWorkspaceNamesHint(scr);
724 #endif
725 #ifdef KWM_HINTS
726 wKWMUpdateWorkspaceNameHint(scr, workspace);
727 #endif
733 /* callback for when menu entry is edited */
734 static void
735 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
737 char *tmp;
739 tmp = entry->text;
740 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
744 WMenu*
745 wWorkspaceMenuMake(WScreen *scr, Bool titled)
747 WMenu *wsmenu;
749 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
750 if (!wsmenu) {
751 wwarning(_("could not create Workspace menu"));
752 return NULL;
755 /* callback to be called when an entry is edited */
756 wsmenu->on_edit = onMenuEntryEdited;
758 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
759 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
761 return wsmenu;
766 void
767 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
769 int i;
770 long ws;
771 char title[MAX_WORKSPACENAME_WIDTH+1];
772 WMenuEntry *entry;
773 int tmp;
775 if (!menu)
776 return;
778 if (menu->entry_no < scr->workspace_count+2) {
779 /* new workspace(s) added */
780 i = scr->workspace_count-(menu->entry_no-2);
781 ws = menu->entry_no - 2;
782 while (i>0) {
783 strcpy(title, scr->workspaces[ws]->name);
785 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
786 entry->flags.indicator = 1;
787 entry->flags.editable = 1;
789 i--;
790 ws++;
792 } else if (menu->entry_no > scr->workspace_count+2) {
793 /* removed workspace(s) */
794 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
795 wMenuRemoveItem(menu, i);
798 wMenuRealize(menu);
800 for (i=0; i<scr->workspace_count; i++) {
801 menu->entries[i+2]->flags.indicator_on = 0;
803 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
805 /* don't let user destroy current workspace */
806 if (scr->current_workspace == scr->workspace_count-1) {
807 wMenuSetEnabled(menu, 1, False);
808 } else {
809 wMenuSetEnabled(menu, 1, True);
812 tmp = menu->frame->top_width + 5;
813 /* if menu got unreachable, bring it to a visible place */
814 if (menu->frame_x < tmp - (int)menu->frame->core->width)
815 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
817 wMenuPaint(menu);
821 void
822 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
824 proplist_t parr, pstr;
825 proplist_t wks_state, old_wks_state;
826 proplist_t foo, bar;
827 int i;
829 make_keys();
831 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
832 parr = PLMakeArrayFromElements(NULL);
833 for (i=0; i < scr->workspace_count; i++) {
834 pstr = PLMakeString(scr->workspaces[i]->name);
835 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
836 PLRelease(pstr);
837 if (!wPreferences.flags.noclip) {
838 pstr = wClipSaveWorkspaceState(scr, i);
839 PLInsertDictionaryEntry(wks_state, dClip, pstr);
840 PLRelease(pstr);
841 } else if (old_wks_state!=NULL) {
842 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
843 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
844 PLInsertDictionaryEntry(wks_state, dClip, bar);
848 PLAppendArrayElement(parr, wks_state);
849 PLRelease(wks_state);
851 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
852 PLRelease(parr);
856 void
857 wWorkspaceRestoreState(WScreen *scr)
859 proplist_t parr, pstr, wks_state;
860 proplist_t clip_state;
861 int i, wscount;
863 make_keys();
865 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
867 if (!parr)
868 return;
870 wscount = scr->workspace_count;
871 for (i=0; i < PLGetNumberOfElements(parr); i++) {
872 wks_state = PLGetArrayElement(parr, i);
873 if (PLIsDictionary(wks_state))
874 pstr = PLGetDictionaryEntry(wks_state, dName);
875 else
876 pstr = wks_state;
877 if (i >= scr->workspace_count)
878 wWorkspaceNew(scr);
879 if (scr->workspace_menu) {
880 free(scr->workspace_menu->entries[i+2]->text);
881 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
882 scr->workspace_menu->flags.realized = 0;
884 free(scr->workspaces[i]->name);
885 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
886 if (!wPreferences.flags.noclip) {
887 clip_state = PLGetDictionaryEntry(wks_state, dClip);
888 if (scr->workspaces[i]->clip)
889 wDockDestroy(scr->workspaces[i]->clip);
890 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
891 WM_CLIP);
892 if (i>0)
893 wDockHideIcons(scr->workspaces[i]->clip);
895 #ifdef KWM_HINTS
896 wKWMUpdateWorkspaceNameHint(scr, i);
897 #endif
899 #ifdef GNOME_STUFF
900 wGNOMEUpdateWorkspaceNamesHint(scr);
901 #endif