bug fixes
[wmaker-crm.git] / src / workspace.c
blob1db9e48e3aa01b249a901657d141e1898e4f14fb
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 return;
295 if (scr->workspace_name_timer) {
296 WMDeleteTimerHandler(scr->workspace_name_timer);
297 XUnmapWindow(dpy, scr->workspace_name);
298 XFlush(dpy);
300 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY,
301 hideWorkpaceName, scr);
303 if (scr->workspace_name_data) {
304 RDestroyImage(scr->workspace_name_data->back);
305 RDestroyImage(scr->workspace_name_data->text);
306 free(scr->workspace_name_data);
309 #ifndef I18N_MB
310 XSetFont(dpy, scr->mono_gc, scr->workspace_name_font->font->fid);
311 XSetFont(dpy, scr->draw_gc, scr->workspace_name_font->font->fid);
312 #endif
314 data = wmalloc(sizeof(WorkspaceNameData));
316 w = wTextWidth(scr->workspace_name_font->font, name, len);
317 h = scr->workspace_name_font->height;
319 switch (wPreferences.workspace_name_display_position) {
320 case WD_CENTER:
321 px = (scr->scr_width - (w+4))/2;
322 py = (scr->scr_height - (h+4))/2;
323 break;
324 case WD_TOP:
325 px = (scr->scr_width - (w+4))/2;
326 py = 0;
327 break;
328 case WD_BOTTOM:
329 px = (scr->scr_width - (w+4))/2;
330 py = scr->scr_height - h;
331 break;
332 case WD_TOPLEFT:
333 px = 0;
334 py = 0;
335 break;
336 case WD_TOPRIGHT:
337 px = scr->scr_width - w;
338 py = 0;
339 break;
340 case WD_BOTTOMLEFT:
341 px = 0;
342 py = scr->scr_height - h;
343 break;
344 case WD_BOTTOMRIGHT:
345 px = scr->scr_width - w;
346 py = scr->scr_height - h;
347 break;
349 XResizeWindow(dpy, scr->workspace_name, w+4, h+4);
350 XMoveWindow(dpy, scr->workspace_name, px, py);
352 text = XCreatePixmap(dpy, scr->w_win, w+4, h+4, scr->w_depth);
353 mask = XCreatePixmap(dpy, scr->w_win, w+4, h+4, 1);
355 XSetForeground(dpy, scr->draw_gc, scr->black_pixel);
356 XFillRectangle(dpy, text, scr->draw_gc, 0, 0, w+4, h+4);
358 XSetForeground(dpy, scr->mono_gc, 0);
359 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4);
361 XSetForeground(dpy, scr->mono_gc, 1);
362 for (x = 0; x <= 4; x++) {
363 for (y = 0; y <= 4; y++) {
364 wDrawString(mask, scr->workspace_name_font, scr->mono_gc,
365 x, scr->workspace_name_font->y + y, name, len);
369 XSetForeground(dpy, scr->draw_gc, scr->white_pixel);
370 wDrawString(text, scr->workspace_name_font, scr->draw_gc,
371 2, scr->workspace_name_font->y + 2,
372 scr->workspaces[workspace]->name,
373 strlen(scr->workspaces[workspace]->name));
374 #ifdef SHAPE
375 XShapeCombineMask(dpy, scr->workspace_name, ShapeBounding, 0, 0, mask,
376 ShapeSet);
377 #endif
378 XSetWindowBackgroundPixmap(dpy, scr->workspace_name, text);
379 XClearWindow(dpy, scr->workspace_name);
381 data->text = RCreateImageFromDrawable(scr->rcontext, text, None);
383 XFreePixmap(dpy, text);
384 XFreePixmap(dpy, mask);
386 if (!data->text) {
387 XMapRaised(dpy, scr->workspace_name);
388 XFlush(dpy);
390 goto erro;
393 ximg = RGetXImage(scr->rcontext, scr->root_win, px, py,
394 data->text->width, data->text->height);
396 if (!ximg) {
397 goto erro;
400 XMapRaised(dpy, scr->workspace_name);
401 XFlush(dpy);
403 data->back = RCreateImageFromXImage(scr->rcontext, ximg->image, NULL);
404 RDestroyXImage(scr->rcontext, ximg);
406 if (!data->back) {
407 goto erro;
410 data->count = 10;
412 /* set a timeout for the effect */
413 data->timeout = time(NULL) + 2 +
414 (WORKSPACE_NAME_DELAY + WORKSPACE_NAME_FADE_DELAY*data->count)/1000;
416 scr->workspace_name_data = data;
419 return;
421 erro:
422 if (scr->workspace_name_timer)
423 WMDeleteTimerHandler(scr->workspace_name_timer);
425 if (data->text)
426 RDestroyImage(data->text);
427 if (data->back)
428 RDestroyImage(data->back);
429 free(data);
431 scr->workspace_name_data = NULL;
433 scr->workspace_name_timer = WMAddTimerHandler(WORKSPACE_NAME_DELAY +
434 10*WORKSPACE_NAME_FADE_DELAY,
435 hideWorkpaceName, scr);
439 void
440 wWorkspaceChange(WScreen *scr, int workspace)
442 if (scr->flags.startup || scr->flags.startup2) {
443 return;
446 if (workspace != scr->current_workspace) {
447 wWorkspaceForceChange(scr, workspace);
448 } /*else {
449 showWorkspaceName(scr, workspace);
454 void
455 wWorkspaceRelativeChange(WScreen *scr, int amount)
457 int w;
459 w = scr->current_workspace + amount;
461 if (amount < 0) {
463 if (w >= 0)
464 wWorkspaceChange(scr, w);
465 else if (wPreferences.ws_cycle)
466 wWorkspaceChange(scr, scr->workspace_count + w);
468 } else if (amount > 0) {
470 if (w < scr->workspace_count)
471 wWorkspaceChange(scr, w);
472 else if (wPreferences.ws_advance)
473 wWorkspaceChange(scr, WMIN(w, MAX_WORKSPACES-1));
474 else if (wPreferences.ws_cycle)
475 wWorkspaceChange(scr, w % scr->workspace_count);
481 void
482 wWorkspaceForceChange(WScreen *scr, int workspace)
484 WWindow *tmp, *foc=NULL, *foc2=NULL;
486 if (workspace >= MAX_WORKSPACES || workspace < 0)
487 return;
489 SendHelperMessage(scr, 'C', workspace+1, NULL);
491 if (workspace > scr->workspace_count-1) {
492 wWorkspaceMake(scr, workspace - scr->workspace_count + 1);
495 wClipUpdateForWorkspaceChange(scr, workspace);
497 scr->current_workspace = workspace;
499 wWorkspaceMenuUpdate(scr, scr->workspace_menu);
501 wWorkspaceMenuUpdate(scr, scr->clip_ws_menu);
503 if ((tmp = scr->focused_window)!= NULL) {
504 if (IS_OMNIPRESENT(tmp) || tmp->flags.changing_workspace)
505 foc = tmp;
506 /* foc2 = tmp; will fix annoyance with gnome panel
507 * but will create annoyance for every other application
510 while (tmp) {
511 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
512 /* unmap windows not on this workspace */
513 if ((tmp->flags.mapped||tmp->flags.shaded)
514 && !IS_OMNIPRESENT(tmp)
515 && !tmp->flags.changing_workspace) {
517 wWindowUnmap(tmp);
519 /* also unmap miniwindows not on this workspace */
520 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
521 && tmp->icon) {
522 if (!wPreferences.sticky_icons) {
523 XUnmapWindow(dpy, tmp->icon->core->window);
524 tmp->icon->mapped = 0;
525 } else {
526 tmp->icon->mapped = 1;
527 /* Why is this here? -Alfredo */
528 XMapWindow(dpy, tmp->icon->core->window);
531 /* update current workspace of omnipresent windows */
532 if (IS_OMNIPRESENT(tmp)) {
533 WApplication *wapp = wApplicationOf(tmp->main_window);
535 tmp->frame->workspace = workspace;
537 if (wapp) {
538 wapp->last_workspace = workspace;
540 if (!foc2)
541 foc2 = tmp;
543 } else {
544 /* change selected windows' workspace */
545 if (tmp->flags.selected) {
546 wWindowChangeWorkspace(tmp, workspace);
547 if (!tmp->flags.miniaturized && !foc) {
548 foc = tmp;
550 } else {
551 if (!tmp->flags.hidden) {
552 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
553 /* remap windows that are on this workspace */
554 wWindowMap(tmp);
555 if (!foc)
556 foc = tmp;
558 /* Also map miniwindow if not omnipresent */
559 if (!wPreferences.sticky_icons &&
560 tmp->flags.miniaturized &&
561 !IS_OMNIPRESENT(tmp) && tmp->icon) {
562 tmp->icon->mapped = 1;
563 XMapWindow(dpy, tmp->icon->core->window);
568 tmp = tmp->prev;
571 if (!foc)
572 foc = foc2;
574 if (scr->focused_window->flags.mapped && !foc) {
575 foc = scr->focused_window;
577 if (wPreferences.focus_mode == WKF_CLICK) {
578 wSetFocusTo(scr, foc);
579 } else {
580 unsigned int mask;
581 int foo;
582 Window bar, win;
583 WWindow *tmp;
585 tmp = NULL;
586 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
587 &foo, &foo, &foo, &foo, &mask)) {
588 tmp = wWindowFor(win);
590 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
591 wSetFocusTo(scr, foc);
592 } else {
593 wSetFocusTo(scr, tmp);
598 /* We need to always arrange icons when changing workspace, even if
599 * no autoarrange icons, because else the icons in different workspaces
600 * can be superposed.
601 * This can be avoided if appicons are also workspace specific.
603 if (!wPreferences.sticky_icons)
604 wArrangeIcons(scr, False);
606 if (scr->dock)
607 wAppIconPaint(scr->dock->icon_array[0]);
608 if (scr->clip_icon) {
609 if (scr->workspaces[workspace]->clip->auto_collapse ||
610 scr->workspaces[workspace]->clip->auto_raise_lower) {
611 /* to handle enter notify. This will also */
612 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
613 XMapWindow(dpy, scr->clip_icon->icon->core->window);
614 } else {
615 wClipIconPaint(scr->clip_icon);
619 showWorkspaceName(scr, workspace);
621 #ifdef GNOME_STUFF
622 wGNOMEUpdateCurrentWorkspaceHint(scr);
623 #endif
624 #ifdef KWM_HINTS
625 wKWMUpdateCurrentWorkspaceHint(scr);
626 #endif
627 /* XSync(dpy, False); */
631 static void
632 switchWSCommand(WMenu *menu, WMenuEntry *entry)
634 wWorkspaceChange(menu->frame->screen_ptr, (long)entry->clientdata);
639 static void
640 deleteWSCommand(WMenu *menu, WMenuEntry *entry)
642 wWorkspaceDelete(menu->frame->screen_ptr,
643 menu->frame->screen_ptr->workspace_count-1);
648 static void
649 newWSCommand(WMenu *menu, WMenuEntry *foo)
651 int ws;
653 ws = wWorkspaceNew(menu->frame->screen_ptr);
654 /* autochange workspace*/
655 if (ws>=0)
656 wWorkspaceChange(menu->frame->screen_ptr, ws);
660 if (ws<9) {
661 int kcode;
662 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
663 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
664 entry->rtext =
665 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
671 static char*
672 cropline(char *line)
674 char *start, *end;
676 if (strlen(line)==0)
677 return line;
679 start = line;
680 end = &(line[strlen(line)])-1;
681 while (isspace(*line) && *line!=0) line++;
682 while (isspace(*end) && end!=line) {
683 *end=0;
684 end--;
686 return line;
690 void
691 wWorkspaceRename(WScreen *scr, int workspace, char *name)
693 char buf[MAX_WORKSPACENAME_WIDTH+1];
694 char *tmp;
696 if (workspace >= scr->workspace_count)
697 return;
699 /* trim white spaces */
700 tmp = cropline(name);
702 if (strlen(tmp)==0) {
703 sprintf(buf, _("Workspace %i"), workspace+1);
704 } else {
705 strncpy(buf, tmp, MAX_WORKSPACENAME_WIDTH);
707 buf[MAX_WORKSPACENAME_WIDTH] = 0;
709 /* update workspace */
710 free(scr->workspaces[workspace]->name);
711 scr->workspaces[workspace]->name = wstrdup(buf);
713 if (scr->clip_ws_menu) {
714 if (strcmp(scr->clip_ws_menu->entries[workspace+2]->text, buf)!=0) {
715 free(scr->clip_ws_menu->entries[workspace+2]->text);
716 scr->clip_ws_menu->entries[workspace+2]->text = wstrdup(buf);
717 wMenuRealize(scr->clip_ws_menu);
720 if (scr->workspace_menu) {
721 if (strcmp(scr->workspace_menu->entries[workspace+2]->text, buf)!=0) {
722 free(scr->workspace_menu->entries[workspace+2]->text);
723 scr->workspace_menu->entries[workspace+2]->text = wstrdup(buf);
724 wMenuRealize(scr->workspace_menu);
728 UpdateSwitchMenuWorkspace(scr, workspace);
730 if (scr->clip_icon)
731 wClipIconPaint(scr->clip_icon);
733 #ifdef GNOME_STUFF
734 wGNOMEUpdateWorkspaceNamesHint(scr);
735 #endif
736 #ifdef KWM_HINTS
737 wKWMUpdateWorkspaceNameHint(scr, workspace);
738 #endif
744 /* callback for when menu entry is edited */
745 static void
746 onMenuEntryEdited(WMenu *menu, WMenuEntry *entry)
748 char *tmp;
750 tmp = entry->text;
751 wWorkspaceRename(menu->frame->screen_ptr, (long)entry->clientdata, tmp);
755 WMenu*
756 wWorkspaceMenuMake(WScreen *scr, Bool titled)
758 WMenu *wsmenu;
760 wsmenu = wMenuCreate(scr, titled ? _("Workspaces") : NULL, False);
761 if (!wsmenu) {
762 wwarning(_("could not create Workspace menu"));
763 return NULL;
766 /* callback to be called when an entry is edited */
767 wsmenu->on_edit = onMenuEntryEdited;
769 wMenuAddCallback(wsmenu, _("New"), newWSCommand, NULL);
770 wMenuAddCallback(wsmenu, _("Destroy Last"), deleteWSCommand, NULL);
772 return wsmenu;
777 void
778 wWorkspaceMenuUpdate(WScreen *scr, WMenu *menu)
780 int i;
781 long ws;
782 char title[MAX_WORKSPACENAME_WIDTH+1];
783 WMenuEntry *entry;
784 int tmp;
786 if (!menu)
787 return;
789 if (menu->entry_no < scr->workspace_count+2) {
790 /* new workspace(s) added */
791 i = scr->workspace_count-(menu->entry_no-2);
792 ws = menu->entry_no - 2;
793 while (i>0) {
794 strcpy(title, scr->workspaces[ws]->name);
796 entry = wMenuAddCallback(menu, title, switchWSCommand, (void*)ws);
797 entry->flags.indicator = 1;
798 entry->flags.editable = 1;
800 i--;
801 ws++;
803 } else if (menu->entry_no > scr->workspace_count+2) {
804 /* removed workspace(s) */
805 for (i = menu->entry_no-1; i >= scr->workspace_count+2; i--) {
806 wMenuRemoveItem(menu, i);
809 wMenuRealize(menu);
811 for (i=0; i<scr->workspace_count; i++) {
812 menu->entries[i+2]->flags.indicator_on = 0;
814 menu->entries[scr->current_workspace+2]->flags.indicator_on = 1;
816 /* don't let user destroy current workspace */
817 if (scr->current_workspace == scr->workspace_count-1) {
818 wMenuSetEnabled(menu, 1, False);
819 } else {
820 wMenuSetEnabled(menu, 1, True);
823 tmp = menu->frame->top_width + 5;
824 /* if menu got unreachable, bring it to a visible place */
825 if (menu->frame_x < tmp - (int)menu->frame->core->width)
826 wMenuMove(menu, tmp - (int)menu->frame->core->width, menu->frame_y, False);
828 wMenuPaint(menu);
832 void
833 wWorkspaceSaveState(WScreen *scr, proplist_t old_state)
835 proplist_t parr, pstr;
836 proplist_t wks_state, old_wks_state;
837 proplist_t foo, bar;
838 int i;
840 make_keys();
842 old_wks_state = PLGetDictionaryEntry(old_state, dWorkspaces);
843 parr = PLMakeArrayFromElements(NULL);
844 for (i=0; i < scr->workspace_count; i++) {
845 pstr = PLMakeString(scr->workspaces[i]->name);
846 wks_state = PLMakeDictionaryFromEntries(dName, pstr, NULL);
847 PLRelease(pstr);
848 if (!wPreferences.flags.noclip) {
849 pstr = wClipSaveWorkspaceState(scr, i);
850 PLInsertDictionaryEntry(wks_state, dClip, pstr);
851 PLRelease(pstr);
852 } else if (old_wks_state!=NULL) {
853 if ((foo = PLGetArrayElement(old_wks_state, i))!=NULL) {
854 if ((bar = PLGetDictionaryEntry(foo, dClip))!=NULL) {
855 PLInsertDictionaryEntry(wks_state, dClip, bar);
859 PLAppendArrayElement(parr, wks_state);
860 PLRelease(wks_state);
862 PLInsertDictionaryEntry(scr->session_state, dWorkspaces, parr);
863 PLRelease(parr);
867 void
868 wWorkspaceRestoreState(WScreen *scr)
870 proplist_t parr, pstr, wks_state;
871 proplist_t clip_state;
872 int i, wscount;
874 make_keys();
876 parr = PLGetDictionaryEntry(scr->session_state, dWorkspaces);
878 if (!parr)
879 return;
881 wscount = scr->workspace_count;
882 for (i=0; i < PLGetNumberOfElements(parr); i++) {
883 wks_state = PLGetArrayElement(parr, i);
884 if (PLIsDictionary(wks_state))
885 pstr = PLGetDictionaryEntry(wks_state, dName);
886 else
887 pstr = wks_state;
888 if (i >= scr->workspace_count)
889 wWorkspaceNew(scr);
890 if (scr->workspace_menu) {
891 free(scr->workspace_menu->entries[i+2]->text);
892 scr->workspace_menu->entries[i+2]->text = wstrdup(PLGetString(pstr));
893 scr->workspace_menu->flags.realized = 0;
895 free(scr->workspaces[i]->name);
896 scr->workspaces[i]->name = wstrdup(PLGetString(pstr));
897 if (!wPreferences.flags.noclip) {
898 clip_state = PLGetDictionaryEntry(wks_state, dClip);
899 if (scr->workspaces[i]->clip)
900 wDockDestroy(scr->workspaces[i]->clip);
901 scr->workspaces[i]->clip = wDockRestoreState(scr, clip_state,
902 WM_CLIP);
903 if (i>0)
904 wDockHideIcons(scr->workspaces[i]->clip);
906 #ifdef KWM_HINTS
907 wKWMUpdateWorkspaceNameHint(scr, i);
908 #endif
910 #ifdef GNOME_STUFF
911 wGNOMEUpdateWorkspaceNamesHint(scr);
912 #endif