added contrib/ directory, updated WPrefs and wmsetbg for smoothed
[wmaker-crm.git] / src / workspace.c
blob608c6eb9e9021610399ccd5b5d6fd7731d62f5bb
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 foc2 = tmp; /* for gnome stuff.. used to be foc = tmp */
507 while (tmp) {
508 if (tmp->frame->workspace!=workspace && !tmp->flags.selected) {
509 /* unmap windows not on this workspace */
510 if ((tmp->flags.mapped||tmp->flags.shaded)
511 && !IS_OMNIPRESENT(tmp)
512 && !tmp->flags.changing_workspace) {
514 wWindowUnmap(tmp);
516 /* also unmap miniwindows not on this workspace */
517 if (tmp->flags.miniaturized && !IS_OMNIPRESENT(tmp)
518 && tmp->icon) {
519 if (!wPreferences.sticky_icons) {
520 XUnmapWindow(dpy, tmp->icon->core->window);
521 tmp->icon->mapped = 0;
522 } else {
523 tmp->icon->mapped = 1;
524 /* Why is this here? -Alfredo */
525 XMapWindow(dpy, tmp->icon->core->window);
528 /* update current workspace of omnipresent windows */
529 if (IS_OMNIPRESENT(tmp)) {
530 WApplication *wapp = wApplicationOf(tmp->main_window);
532 tmp->frame->workspace = workspace;
534 if (wapp) {
535 wapp->last_workspace = workspace;
537 if (!foc2)
538 foc2 = tmp;
540 } else {
541 /* change selected windows' workspace */
542 if (tmp->flags.selected) {
543 wWindowChangeWorkspace(tmp, workspace);
544 if (!tmp->flags.miniaturized && !foc) {
545 foc = tmp;
547 } else {
548 if (!tmp->flags.hidden) {
549 if (!(tmp->flags.mapped || tmp->flags.miniaturized)) {
550 /* remap windows that are on this workspace */
551 wWindowMap(tmp);
552 if (!foc)
553 foc = tmp;
555 /* Also map miniwindow if not omnipresent */
556 if (!wPreferences.sticky_icons &&
557 tmp->flags.miniaturized &&
558 !IS_OMNIPRESENT(tmp) && tmp->icon) {
559 tmp->icon->mapped = 1;
560 XMapWindow(dpy, tmp->icon->core->window);
565 tmp = tmp->prev;
568 if (!foc)
569 foc = foc2;
571 if (scr->focused_window->flags.mapped && !foc) {
572 foc = scr->focused_window;
574 if (wPreferences.focus_mode == WKF_CLICK) {
575 wSetFocusTo(scr, foc);
576 } else {
577 unsigned int mask;
578 int foo;
579 Window bar, win;
580 WWindow *tmp;
582 tmp = NULL;
583 if (XQueryPointer(dpy, scr->root_win, &bar, &win,
584 &foo, &foo, &foo, &foo, &mask)) {
585 tmp = wWindowFor(win);
587 if (!tmp && wPreferences.focus_mode == WKF_SLOPPY) {
588 wSetFocusTo(scr, foc);
589 } else {
590 wSetFocusTo(scr, tmp);
595 /* We need to always arrange icons when changing workspace, even if
596 * no autoarrange icons, because else the icons in different workspaces
597 * can be superposed.
598 * This can be avoided if appicons are also workspace specific.
600 if (!wPreferences.sticky_icons)
601 wArrangeIcons(scr, False);
603 if (scr->dock)
604 wAppIconPaint(scr->dock->icon_array[0]);
605 if (scr->clip_icon) {
606 if (scr->workspaces[workspace]->clip->auto_collapse ||
607 scr->workspaces[workspace]->clip->auto_raise_lower) {
608 /* to handle enter notify. This will also */
609 XUnmapWindow(dpy, scr->clip_icon->icon->core->window);
610 XMapWindow(dpy, scr->clip_icon->icon->core->window);
611 } else {
612 wClipIconPaint(scr->clip_icon);
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, 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 #ifdef KWM_HINTS
904 wKWMUpdateWorkspaceNameHint(scr, i);
905 #endif
907 #ifdef GNOME_STUFF
908 wGNOMEUpdateWorkspaceNamesHint(scr);
909 #endif