fixed cosmetic bug in geom. dpy window for 8bpp
[wmaker-crm.git] / src / workspace.c
blobf61387ce97470b77e204e5d6aa0321bc3e891cb9
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 data = wmalloc(sizeof(WorkspaceNameData));
312 w = WMWidthOfString(scr->workspace_name_font, name, len);
313 h = WMFontHeight(scr->workspace_name_font);
315 switch (wPreferences.workspace_name_display_position) {
316 case WD_CENTER:
317 px = (scr->scr_width - (w+4))/2;
318 py = (scr->scr_height - (h+4))/2;
319 break;
320 case WD_TOP:
321 px = (scr->scr_width - (w+4))/2;
322 py = 0;
323 break;
324 case WD_BOTTOM:
325 px = (scr->scr_width - (w+4))/2;
326 py = scr->scr_height - h;
327 break;
328 case WD_TOPLEFT:
329 px = 0;
330 py = 0;
331 break;
332 case WD_TOPRIGHT:
333 px = scr->scr_width - w;
334 py = 0;
335 break;
336 case WD_BOTTOMLEFT:
337 px = 0;
338 py = scr->scr_height - h;
339 break;
340 case WD_BOTTOMRIGHT:
341 px = scr->scr_width - w;
342 py = scr->scr_height - h;
343 break;
345 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
346 XMoveWindow(dpy, scr->workspace_name, px, py);
348 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
349 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
351 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
352 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
354 XSetForeground(dpy, scr->mono_gc, 0);
355 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
357 XSetForeground(dpy, scr->mono_gc, 1);
358 for (x = 0; x <= 4; x++) {
359 for (y = 0; y <= 4; y++) {
360 WMDrawString(scr->wmscreen, mask, scr->mono_gc,
361 scr->workspace_name_font, x, y, name, len);
365 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
366 WMDrawString(scr->wmscreen, text, scr->draw_gc, scr->workspace_name_font,
367 2, 2, scr->workspaces[workspace]->name,
368 strlen(scr->workspaces[workspace]->name));
369 #ifdef SHAPE
370 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
371 ShapeSet);
372 #endif
373 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
374 XClearWindow(dpy, scr->workspace_name);
376 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
378 XFreePixmap(dpy, text);
379 XFreePixmap(dpy, mask);
381 if (!data->text) {
382 XMapRaised(dpy, scr->workspace_name);
383 XFlush(dpy);
385 goto erro;
388 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py,
389 data->text->width, data->text->height);
391 if (!ximg) {
392 goto erro;
395 XMapRaised(dpy, scr->workspace_name);
396 XFlush(dpy);
398 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
399 RDestroyXImage(scr->rcontext, ximg);
401 if (!data->back) {
402 goto erro;
405 data->count = 10;
407 /* set a timeout for the effect */
408 data->timeout = time(NULL) + 2 +
409 (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY*data->count)/1000;
411 scr->workspace_name_data = data;
414 return;
416 erro:
417 if (scr->workspace_name_timer)
418 WMDeleteTimerHandler(scr->workspace_name_timer);
420 if (data->text)
421 RDestroyImage(data->text);
422 if (data->back)
423 RDestroyImage(data->back);
424 free(data);
426 scr->workspace_name_data = NULL;
428 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
429 10*WORKSPACE_NAME_FADE_DELAY,
430 hideWorkpaceName, scr);
434 void
435 wWorkspaceChange(WScreen *scr, int workspace)
437 if (scr->flags.startup || scr->flags.startup2) {
438 return;
441 if (workspace != scr->current_workspace) {
442 wWorkspaceForceChange(scr, workspace);
443 } /*else {
444 showWorkspaceName(scr, workspace);
449 void
450 wWorkspaceRelativeChange(WScreen *scr, int amount)
452 int w;
454 w = scr->current_workspace + amount;
456 if (amount < 0) {
458 if (w >= 0)
459 wWorkspaceChange(scr, w);
460 else if (wPreferences.ws_cycle)
461 wWorkspaceChange(scr, scr->workspace_count + w);
463 } else if (amount > 0) {
465 if (w < scr->workspace_count)
466 wWorkspaceChange(scr, w);
467 else if (wPreferences.ws_advance)
468 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
469 else if (wPreferences.ws_cycle)
470 wWorkspaceChange(scr, w % scr->workspace_count);
476 void
477 wWorkspaceForceChange(WScreen *scr, int workspace)
479 WWindow *tmp, *foc=NULL, *foc2=NULL;
481 if (workspace >= MAX_WORKSPACES || workspace < 0)
482 return;
484 SendHelperMessage(scr, 'C', workspace+1, NULL);
486 if (workspace > scr->workspace_count-1) {
487 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
490 wClipUpdateForWorkspaceChange(scr, workspace);
492 scr->current_workspace = workspace;
494 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
496 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
498 if ((tmp = scr->focused_window)!= NULL) {
499 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
500 foc = tmp;
501 /* foc2 = tmp; will fix annoyance with gnome panel
502 * but will create annoyance for every other application
505 while (tmp) {
506 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
507 /* unmap windows not on this workspace */
508 if ((tmp->flags.mapped||tmp->flags.shaded)
509 && !IS_OMNIPRESENT(tmp)
510 && !tmp->flags.changing_workspace) {
512 wWindowUnmap(tmp);
514 /* also unmap miniwindows not on this workspace */
515 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
516 && tmp->icon) {
517 if (!wPreferences.sticky_icons) {
518 XUnmapWindow(dpy, tmp->icon->core->window);
519 tmp->icon->mapped = 0;
520 } else {
521 tmp->icon->mapped = 1;
522 /* Why is this here? -Alfredo */
523 XMapWindow(dpy, tmp->icon->core->window);
526 /* update current workspace of omnipresent windows */
527 if (IS_OMNIPRESENT(tmp)) {
528 WApplication *wapp = wApplicationOf(tmp->main_window);
530 tmp->frame->workspace = workspace;
532 if (wapp) {
533 wapp->last_workspace = workspace;
535 if (!foc2)
536 foc2 = tmp;
538 } else {
539 /* change selected windows' workspace */
540 if (tmp->flags.selected) {
541 wWindowChangeWorkspace(tmp, workspace);
542 if (!tmp->flags.miniaturized && !foc) {
543 foc = tmp;
545 } else {
546 if (!tmp->flags.hidden) {
547 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
548 /* remap windows that are on this workspace */
549 wWindowMap(tmp);
550 if (!foc)
551 foc = tmp;
553 /* Also map miniwindow if not omnipresent */
554 if (!wPreferences.sticky_icons &&
555 tmp->flags.miniaturized &&
556 !IS_OMNIPRESENT(tmp) && tmp->icon) {
557 tmp->icon->mapped = 1;
558 XMapWindow(dpy, tmp->icon->core->window);
563 tmp = tmp->prev;
566 if (!foc)
567 foc = foc2;
569 if (scr->focused_window->flags.mapped && !foc) {
570 foc = scr->focused_window;
572 if (wPreferences.focus_mode == WKF_CLICK) {
573 wSetFocusTo(scr, foc);
574 } else {
575 unsigned int mask;
576 int foo;
577 Window bar, win;
578 WWindow *tmp;
580 tmp = NULL;
581 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
582 &foo, &foo, &foo, &foo, &mask)) {
583 tmp = wWindowFor(win);
585 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
586 wSetFocusTo(scr, foc);
587 } else {
588 wSetFocusTo(scr, tmp);
593 /* We need to always arrange icons when changing workspace, even if
594 * no autoarrange icons, because else the icons in different workspaces
595 * can be superposed.
596 * This can be avoided if appicons are also workspace specific.
598 if (!wPreferences.sticky_icons)
599 wArrangeIcons(scr, False);
601 if (scr->dock)
602 wAppIconPaint(scr->dock->icon_array[0]);
604 if (scr->clip_icon) {
605 if (scr->workspaces[workspace]->clip->auto_collapse ||
606 scr->workspaces[workspace]->clip->auto_raise_lower) {
607 /* to handle enter notify. This will also */
608 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
609 XMapWindow(dpy, scr->clip_icon->icon->core->window);
610 } else {
611 wClipIconPaint(scr->clip_icon);
615 if (!scr->flags.startup2)
616 showWorkspaceName(scr, workspace);
618 #ifdef GNOME_STUFF
619 wGNOMEUpdateCurrentWorkspaceHint(scr);
620 #endif
621 #ifdef KWM_HINTS
622 wKWMUpdateCurrentWorkspaceHint(scr);
623 #endif
624 /* XSync(dpy, False); */
628 static void
629 switchWSCommand(WMenu *menu, WMenuEntry *entry)
631 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
636 static void
637 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
639 wWorkspaceDelete(menu->frame->screen_ptr,
640 menu->frame->screen_ptr->workspace_count-1);
645 static void
646 newWSCommand(WMenu *menu, WMenuEntry *foo)
648 int ws;
650 ws = wWorkspaceNew(menu->frame->screen_ptr);
651 /* autochange workspace*/
652 if (ws>=0)
653 wWorkspaceChange(menu->frame->screen_ptr, ws);
657 if (ws<9) {
658 int kcode;
659 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
660 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
661 entry->rtext =
662 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
668 static char*
669 cropline(char *line)
671 char *start, *end;
673 if (strlen(line)==0)
674 return line;
676 start = line;
677 end = &(line[strlen(line)])-1;
678 while (isspace(*line) && *line!=0) line++;
679 while (isspace(*end) && end!=line) {
680 *end=0;
681 end--;
683 return line;
687 void
688 wWorkspaceRename(WScreen *scr, int workspace, char *name)
690 char buf[MAX_WORKSPACENAME_WIDTH+1];
691 char *tmp;
693 if (workspace >= scr->workspace_count)
694 return;
696 /* trim white spaces */
697 tmp = cropline(name);
699 if (strlen(tmp)==0) {
700 sprintf(buf, _("Workspace %i"), workspace+1);
701 } else {
702 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
704 buf[MAX_WORKSPACENAME_WIDTH] = 0;
706 /* update workspace */
707 free(scr->workspaces[workspace]->name);
708 scr->workspaces[workspace]->name = wstrdup(buf);
710 if (scr->clip_ws_menu) {
711 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
712 free(scr->clip_ws_menu->entries[workspace+2]->text);
713 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
714 wMenuRealize(scr->clip_ws_menu);
717 if (scr->workspace_menu) {
718 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
719 free(scr->workspace_menu->entries[workspace+2]->text);
720 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
721 wMenuRealize(scr->workspace_menu);
725 UpdateSwitchMenuWorkspace(scr, workspace);
727 if (scr->clip_icon)
728 wClipIconPaint(scr->clip_icon);
730 #ifdef GNOME_STUFF
731 wGNOMEUpdateWorkspaceNamesHint(scr);
732 #endif
733 #ifdef KWM_HINTS
734 wKWMUpdateWorkspaceNameHint(scr, workspace);
735 #endif
741 /* callback for when menu entry is edited */
742 static void
743 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
745 char *tmp;
747 tmp = entry->text;
748 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
752 WMenu*
753 wWorkspaceMenuMake(WScreen *scr, Bool titled)
755 WMenu *wsmenu;
757 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
758 if (!wsmenu) {
759 wwarning(_("could not create Workspace menu"));
760 return NULL;
763 /* callback to be called when an entry is edited */
764 wsmenu->on_edit = onMenuEntryEdited;
766 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
767 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
769 return wsmenu;
774 void
775 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
777 int i;
778 long ws;
779 char title[MAX_WORKSPACENAME_WIDTH+1];
780 WMenuEntry *entry;
781 int tmp;
783 if (!menu)
784 return;
786 if (menu->entry_no < scr->workspace_count+2) {
787 /* new workspace(s) added */
788 i = scr->workspace_count-(menu->entry_no-2);
789 ws = menu->entry_no - 2;
790 while (i>0) {
791 strcpy(title, scr->workspaces[ws]->name);
793 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
794 entry->flags.indicator = 1;
795 entry->flags.editable = 1;
797 i--;
798 ws++;
800 } else if (menu->entry_no > scr->workspace_count+2) {
801 /* removed workspace(s) */
802 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
803 wMenuRemoveItem(menu, i);
806 wMenuRealize(menu);
808 for (i=0; i<scr->workspace_count; i++) {
809 menu->entries[i+2]->flags.indicator_on = 0;
811 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
813 /* don't let user destroy current workspace */
814 if (scr->current_workspace == scr->workspace_count-1) {
815 wMenuSetEnabled(menu, 1, False);
816 } else {
817 wMenuSetEnabled(menu, 1, True);
820 tmp = menu->frame->top_width + 5;
821 /* if menu got unreachable, bring it to a visible place */
822 if (menu->frame_x < tmp - (int)menu->frame->core->width)
823 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
825 wMenuPaint(menu);
829 void
830 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
832 proplist_t parr, pstr;
833 proplist_t wks_state, old_wks_state;
834 proplist_t foo, bar;
835 int i;
837 make_keys();
839 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
840 parr = PLMakeArrayFromElements(NULL);
841 for (i=0; i < scr->workspace_count; i++) {
842 pstr = PLMakeString(scr->workspaces[i]->name);
843 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
844 PLRelease(pstr);
845 if (!wPreferences.flags.noclip) {
846 pstr = wClipSaveWorkspaceState(scr, i);
847 PLInsertDictionaryEntry(wks_state, dClip, pstr);
848 PLRelease(pstr);
849 } else if (old_wks_state!=NULL) {
850 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
851 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
852 PLInsertDictionaryEntry(wks_state, dClip, bar);
856 PLAppendArrayElement(parr, wks_state);
857 PLRelease(wks_state);
859 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
860 PLRelease(parr);
864 void
865 wWorkspaceRestoreState(WScreen *scr)
867 proplist_t parr, pstr, wks_state;
868 proplist_t clip_state;
869 int i, j, wscount;
871 make_keys();
873 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
875 if (!parr)
876 return;
878 wscount = scr->workspace_count;
879 for (i=0; i < PLGetNumberOfElements(parr); i++) {
880 wks_state = PLGetArrayElement(parr, i);
881 if (PLIsDictionary(wks_state))
882 pstr = PLGetDictionaryEntry(wks_state, dName);
883 else
884 pstr = wks_state;
885 if (i >= scr->workspace_count)
886 wWorkspaceNew(scr);
887 if (scr->workspace_menu) {
888 free(scr->workspace_menu->entries[i+2]->text);
889 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
890 scr->workspace_menu->flags.realized = 0;
892 free(scr->workspaces[i]->name);
893 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
894 if (!wPreferences.flags.noclip) {
895 clip_state = PLGetDictionaryEntry(wks_state, dClip);
896 if (scr->workspaces[i]->clip)
897 wDockDestroy(scr->workspaces[i]->clip);
898 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
899 WM_CLIP);
900 if (i>0)
901 wDockHideIcons(scr->workspaces[i]->clip);
903 /* We set the global icons here, because scr->workspaces[i]->clip
904 * was not valid in wDockRestoreState().
905 * There we only set icon->omnipresent to know which icons we
906 * need to set here.
908 for (j=0; j<scr->workspaces[i]->clip->max_icons; j++) {
909 WAppIcon *aicon = scr->workspaces[i]->clip->icon_array[j];
911 if (aicon && aicon->omnipresent) {
912 aicon->omnipresent = 0;
913 wClipMakeIconOmnipresent(aicon, True);
914 XMapWindow(dpy, aicon->icon->core->window);
918 #ifdef KWM_HINTS
919 wKWMUpdateWorkspaceNameHint(scr, i);
920 #endif
922 #ifdef GNOME_STUFF
923 wGNOMEUpdateWorkspaceNamesHint(scr);
924 #endif