1 /* workspace.c- Workspace management
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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,
25 #include <X11/Xutil.h>
27 #include <X11/extensions/shape.h>
39 #include "WindowMaker.h"
45 #include "application.h"
48 #include "workspace.h"
53 #define MAX_SHORTCUT_LENGTH 32
54 #define WORKSPACE_NAME_DISPLAY_PADDING 32
56 extern int ignore_wks_change
;
57 extern WPreferences wPreferences
;
58 extern XContext wWinContext
;
59 extern XContext wVEdgeContext
;
61 extern void ProcessPendingEvents();
63 static WMPropList
*dWorkspaces
= NULL
;
64 static WMPropList
*dClip
, *dName
;
66 static void make_keys()
68 if (dWorkspaces
!= NULL
)
71 dWorkspaces
= WMCreatePLString("Workspaces");
72 dName
= WMCreatePLString("Name");
73 dClip
= WMCreatePLString("Clip");
76 void wWorkspaceMake(WScreen
* scr
, int count
)
84 int wWorkspaceNew(WScreen
* scr
)
86 WWorkspace
*wspace
, **list
;
89 if (scr
->workspace_count
< MAX_WORKSPACES
) {
90 scr
->workspace_count
++;
92 wspace
= wmalloc(sizeof(WWorkspace
));
96 wspace
->name
= wmalloc(strlen(_("Workspace %i")) + 8);
97 sprintf(wspace
->name
, _("Workspace %i"), scr
->workspace_count
);
100 if (!wPreferences
.flags
.noclip
) {
101 wspace
->clip
= wDockCreate(scr
, WM_CLIP
);
105 list
= wmalloc(sizeof(WWorkspace
*) * scr
->workspace_count
);
107 for (i
= 0; i
< scr
->workspace_count
- 1; i
++) {
108 list
[i
] = scr
->workspaces
[i
];
112 wfree(scr
->workspaces
);
113 scr
->workspaces
= list
;
115 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
116 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
117 wNETWMUpdateDesktop(scr
);
118 WMPostNotificationName(WMNWorkspaceCreated
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
121 return scr
->workspace_count
- 1;
127 Bool
wWorkspaceDelete(WScreen
* scr
, int workspace
)
136 /* verify if workspace is in use by some window */
137 tmp
= scr
->focused_window
;
139 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
== workspace
)
144 if (!wPreferences
.flags
.noclip
) {
145 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
146 scr
->workspaces
[workspace
]->clip
= NULL
;
149 list
= wmalloc(sizeof(WWorkspace
*) * (scr
->workspace_count
- 1));
151 for (i
= 0; i
< scr
->workspace_count
; i
++) {
152 if (i
!= workspace
) {
153 list
[j
++] = scr
->workspaces
[i
];
155 if (scr
->workspaces
[i
]->name
)
156 wfree(scr
->workspaces
[i
]->name
);
157 wfree(scr
->workspaces
[i
]);
160 wfree(scr
->workspaces
);
161 scr
->workspaces
= list
;
163 scr
->workspace_count
--;
166 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
167 /* clip workspace menu */
168 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
170 /* update also window menu */
171 if (scr
->workspace_submenu
) {
172 WMenu
*menu
= scr
->workspace_submenu
;
175 while (i
> scr
->workspace_count
)
176 wMenuRemoveItem(menu
, --i
);
180 if (scr
->clip_submenu
) {
181 WMenu
*menu
= scr
->clip_submenu
;
184 while (i
> scr
->workspace_count
)
185 wMenuRemoveItem(menu
, --i
);
188 wNETWMUpdateDesktop(scr
);
189 WMPostNotificationName(WMNWorkspaceDestroyed
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
191 if (scr
->current_workspace
>= scr
->workspace_count
)
192 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
197 typedef struct WorkspaceNameData
{
204 static void hideWorkspaceName(void *data
)
206 WScreen
*scr
= (WScreen
*) data
;
208 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
209 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
210 XUnmapWindow(dpy
, scr
->workspace_name
);
212 if (scr
->workspace_name_data
) {
213 RReleaseImage(scr
->workspace_name_data
->back
);
214 RReleaseImage(scr
->workspace_name_data
->text
);
215 wfree(scr
->workspace_name_data
);
217 scr
->workspace_name_data
= NULL
;
219 scr
->workspace_name_timer
= NULL
;
221 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
224 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
226 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
227 scr
->workspace_name_data
->count
* 255 / 10);
229 RConvertImage(scr
->rcontext
, img
, &pix
);
233 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
234 XClearWindow(dpy
, scr
->workspace_name
);
235 XFreePixmap(dpy
, pix
);
238 scr
->workspace_name_data
->count
--;
242 static void showWorkspaceName(WScreen
* scr
, int workspace
)
244 WorkspaceNameData
*data
;
249 char *name
= scr
->workspaces
[workspace
]->name
;
250 int len
= strlen(name
);
258 if (wPreferences
.workspace_name_display_position
== WD_NONE
|| scr
->workspace_count
< 2) {
262 if (scr
->workspace_name_timer
) {
263 WMDeleteTimerHandler(scr
->workspace_name_timer
);
264 XUnmapWindow(dpy
, scr
->workspace_name
);
267 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
, hideWorkspaceName
, scr
);
269 if (scr
->workspace_name_data
) {
270 RReleaseImage(scr
->workspace_name_data
->back
);
271 RReleaseImage(scr
->workspace_name_data
->text
);
272 wfree(scr
->workspace_name_data
);
275 data
= wmalloc(sizeof(WorkspaceNameData
));
278 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
279 h
= WMFontHeight(scr
->workspace_name_font
);
282 head
= wGetHeadForPointerLocation(scr
);
283 rect
= wGetRectForHead(scr
, head
);
284 if (scr
->xine_info
.count
) {
285 xx
= rect
.pos
.x
+ (scr
->xine_info
.screens
[head
].size
.width
- (w
+ 4)) / 2;
286 yy
= rect
.pos
.y
+ (scr
->xine_info
.screens
[head
].size
.height
- (h
+ 4)) / 2;
289 xx
= (scr
->scr_width
- (w
+ 4)) / 2;
290 yy
= (scr
->scr_height
- (h
+ 4)) / 2;
294 switch (wPreferences
.workspace_name_display_position
) {
299 px
= (scr
->scr_width
- (w
+ 4)) / 2;
301 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
307 px
= (scr
->scr_width
- (w
+ 4)) / 2;
309 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
312 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
313 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
316 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
317 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
320 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
321 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
324 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
325 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
333 px
= (scr
->scr_width
- (w
+ 4)) / 2;
334 py
= (scr
->scr_height
- (h
+ 4)) / 2;
338 XResizeWindow(dpy
, scr
->workspace_name
, w
+ 4, h
+ 4);
339 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
341 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, scr
->w_depth
);
342 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, 1);
344 /*XSetForeground(dpy, scr->mono_gc, 0);
345 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
347 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
349 for (x
= 0; x
<= 4; x
++) {
350 for (y
= 0; y
<= 4; y
++) {
351 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, x
, y
, name
, len
);
355 XSetForeground(dpy
, scr
->mono_gc
, 1);
356 XSetBackground(dpy
, scr
->mono_gc
, 0);
358 XCopyPlane(dpy
, text
, mask
, scr
->mono_gc
, 0, 0, w
+ 4, h
+ 4, 0, 0, 1 << (scr
->w_depth
- 1));
360 /*XSetForeground(dpy, scr->mono_gc, 1); */
361 XSetBackground(dpy
, scr
->mono_gc
, 1);
363 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
365 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, 2, 2, name
, len
);
368 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
370 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
371 XClearWindow(dpy
, scr
->workspace_name
);
373 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
375 XFreePixmap(dpy
, text
);
376 XFreePixmap(dpy
, mask
);
379 XMapRaised(dpy
, scr
->workspace_name
);
385 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
, data
->text
->width
, data
->text
->height
);
387 if (!ximg
|| !ximg
->image
) {
391 XMapRaised(dpy
, scr
->workspace_name
);
394 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
395 RDestroyXImage(scr
->rcontext
, ximg
);
403 /* set a timeout for the effect */
404 data
->timeout
= time(NULL
) + 2 + (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
* data
->count
) / 1000;
406 scr
->workspace_name_data
= data
;
411 if (scr
->workspace_name_timer
)
412 WMDeleteTimerHandler(scr
->workspace_name_timer
);
415 RReleaseImage(data
->text
);
417 RReleaseImage(data
->back
);
420 scr
->workspace_name_data
= NULL
;
422 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
423 10 * WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
426 void wWorkspaceChange(WScreen
*scr
, int workspace
)
428 if (scr
->flags
.startup
|| scr
->flags
.startup2
|| scr
->flags
.ignore_focus_events
)
431 if (workspace
!= scr
->current_workspace
)
432 wWorkspaceForceChange(scr
, workspace
);
435 void wWorkspaceRelativeChange(WScreen
* scr
, int amount
)
439 /* While the deiconify animation is going on the window is
440 * still "flying" to its final position and we don't want to
441 * change workspace before the animation finishes, otherwise
442 * the window will land in the new workspace */
443 if (ignore_wks_change
)
446 w
= scr
->current_workspace
+ amount
;
450 wWorkspaceChange(scr
, w
);
451 } else if (wPreferences
.ws_cycle
) {
452 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
454 } else if (amount
> 0) {
455 if (w
< scr
->workspace_count
) {
456 wWorkspaceChange(scr
, w
);
457 } else if (wPreferences
.ws_advance
) {
458 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
- 1));
459 } else if (wPreferences
.ws_cycle
) {
460 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
465 void wWorkspaceForceChange(WScreen
* scr
, int workspace
)
467 WWindow
*tmp
, *foc
= NULL
, *foc2
= NULL
;
469 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
472 SendHelperMessage(scr
, 'C', workspace
+ 1, NULL
);
474 if (workspace
> scr
->workspace_count
- 1) {
475 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
478 wClipUpdateForWorkspaceChange(scr
, workspace
);
480 scr
->current_workspace
= workspace
;
482 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
484 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
486 if ((tmp
= scr
->focused_window
) != NULL
) {
487 if ((IS_OMNIPRESENT(tmp
) && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
488 !WFLAGP(tmp
, no_focusable
)) || tmp
->flags
.changing_workspace
) {
492 /* foc2 = tmp; will fix annoyance with gnome panel
493 * but will create annoyance for every other application
496 if (tmp
->frame
->workspace
!= workspace
&& !tmp
->flags
.selected
) {
497 /* unmap windows not on this workspace */
498 if ((tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
499 !IS_OMNIPRESENT(tmp
) && !tmp
->flags
.changing_workspace
) {
502 /* also unmap miniwindows not on this workspace */
503 if (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
504 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
505 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
506 tmp
->icon
->mapped
= 0;
508 /* update current workspace of omnipresent windows */
509 if (IS_OMNIPRESENT(tmp
)) {
510 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
512 tmp
->frame
->workspace
= workspace
;
515 wapp
->last_workspace
= workspace
;
517 if (!foc2
&& (tmp
->flags
.mapped
|| tmp
->flags
.shaded
)) {
522 /* change selected windows' workspace */
523 if (tmp
->flags
.selected
) {
524 wWindowChangeWorkspace(tmp
, workspace
);
525 if (!tmp
->flags
.miniaturized
&& !foc
) {
529 if (!tmp
->flags
.hidden
) {
530 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
531 /* remap windows that are on this workspace */
533 if (!foc
&& !WFLAGP(tmp
, no_focusable
)) {
537 /* Also map miniwindow if not omnipresent */
538 if (!wPreferences
.sticky_icons
&&
539 tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
540 tmp
->icon
->mapped
= 1;
541 XMapWindow(dpy
, tmp
->icon
->core
->window
);
549 /* Gobble up events unleashed by our mapping & unmapping.
550 * These may trigger various grab-initiated focus &
551 * crossing events. However, we don't care about them,
552 * and ignore their focus implications altogether to avoid
555 scr
->flags
.ignore_focus_events
= 1;
556 ProcessPendingEvents();
557 scr
->flags
.ignore_focus_events
= 0;
562 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
563 foc
= scr
->focused_window
;
565 if (wPreferences
.focus_mode
== WKF_CLICK
) {
566 wSetFocusTo(scr
, foc
);
574 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
)) {
575 tmp
= wWindowFor(win
);
578 /* If there's a window under the pointer, focus it.
579 * (we ate all other focus events above, so it's
580 * certainly not focused). Otherwise focus last
581 * focused, or the root (depending on sloppiness)
583 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
584 wSetFocusTo(scr
, foc
);
586 wSetFocusTo(scr
, tmp
);
591 /* We need to always arrange icons when changing workspace, even if
592 * no autoarrange icons, because else the icons in different workspaces
594 * This can be avoided if appicons are also workspace specific.
596 if (!wPreferences
.sticky_icons
)
597 wArrangeIcons(scr
, False
);
600 wAppIconPaint(scr
->dock
->icon_array
[0]);
602 if (scr
->clip_icon
) {
603 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
604 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
605 /* to handle enter notify. This will also */
606 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
607 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
609 wClipIconPaint(scr
->clip_icon
);
612 wScreenUpdateUsableArea(scr
);
613 wNETWMUpdateDesktop(scr
);
614 showWorkspaceName(scr
, workspace
);
616 WMPostNotificationName(WMNWorkspaceChanged
, scr
, (void *)(uintptr_t) workspace
);
618 /* XSync(dpy, False); */
621 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
623 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
626 static void deleteWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
628 wWorkspaceDelete(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->workspace_count
- 1);
631 static void newWSCommand(WMenu
* menu
, WMenuEntry
* foo
)
635 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
636 /* autochange workspace */
638 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
643 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
644 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
646 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
651 static char *cropline(char *line
)
655 if (strlen(line
) == 0)
659 end
= &(line
[strlen(line
)]) - 1;
660 while (isspace(*line
) && *line
!= 0)
662 while (isspace(*end
) && end
!= line
) {
669 void wWorkspaceRename(WScreen
* scr
, int workspace
, char *name
)
671 char buf
[MAX_WORKSPACENAME_WIDTH
+ 1];
674 if (workspace
>= scr
->workspace_count
)
677 /* trim white spaces */
678 tmp
= cropline(name
);
680 if (strlen(tmp
) == 0) {
681 snprintf(buf
, sizeof(buf
), _("Workspace %i"), workspace
+ 1);
683 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
685 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
687 /* update workspace */
688 wfree(scr
->workspaces
[workspace
]->name
);
689 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
691 if (scr
->clip_ws_menu
) {
692 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
693 wfree(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
);
694 scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
695 wMenuRealize(scr
->clip_ws_menu
);
698 if (scr
->workspace_menu
) {
699 if (strcmp(scr
->workspace_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
700 wfree(scr
->workspace_menu
->entries
[workspace
+ 2]->text
);
701 scr
->workspace_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
702 wMenuRealize(scr
->workspace_menu
);
707 wClipIconPaint(scr
->clip_icon
);
709 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) workspace
);
712 /* callback for when menu entry is edited */
713 static void onMenuEntryEdited(WMenu
* menu
, WMenuEntry
* entry
)
718 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
721 WMenu
*wWorkspaceMenuMake(WScreen
* scr
, Bool titled
)
725 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
727 wwarning(_("could not create Workspace menu"));
731 /* callback to be called when an entry is edited */
732 wsmenu
->on_edit
= onMenuEntryEdited
;
734 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
735 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
740 void wWorkspaceMenuUpdate(WScreen
* scr
, WMenu
* menu
)
744 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
751 if (menu
->entry_no
< scr
->workspace_count
+ 2) {
752 /* new workspace(s) added */
753 i
= scr
->workspace_count
- (menu
->entry_no
- 2);
754 ws
= menu
->entry_no
- 2;
756 strncpy(title
, scr
->workspaces
[ws
]->name
, MAX_WORKSPACENAME_WIDTH
);
758 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)ws
);
759 entry
->flags
.indicator
= 1;
760 entry
->flags
.editable
= 1;
765 } else if (menu
->entry_no
> scr
->workspace_count
+ 2) {
766 /* removed workspace(s) */
767 for (i
= menu
->entry_no
- 1; i
>= scr
->workspace_count
+ 2; i
--) {
768 wMenuRemoveItem(menu
, i
);
773 for (i
= 0; i
< scr
->workspace_count
; i
++) {
774 menu
->entries
[i
+ 2]->flags
.indicator_on
= 0;
776 menu
->entries
[scr
->current_workspace
+ 2]->flags
.indicator_on
= 1;
778 /* don't let user destroy current workspace */
779 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
780 wMenuSetEnabled(menu
, 1, False
);
782 wMenuSetEnabled(menu
, 1, True
);
785 tmp
= menu
->frame
->top_width
+ 5;
786 /* if menu got unreachable, bring it to a visible place */
787 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
788 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
793 void wWorkspaceSaveState(WScreen
* scr
, WMPropList
* old_state
)
795 WMPropList
*parr
, *pstr
, *wks_state
, *old_wks_state
, *foo
, *bar
;
800 old_wks_state
= WMGetFromPLDictionary(old_state
, dWorkspaces
);
801 parr
= WMCreatePLArray(NULL
);
802 for (i
= 0; i
< scr
->workspace_count
; i
++) {
803 pstr
= WMCreatePLString(scr
->workspaces
[i
]->name
);
804 wks_state
= WMCreatePLDictionary(dName
, pstr
, NULL
);
805 WMReleasePropList(pstr
);
806 if (!wPreferences
.flags
.noclip
) {
807 pstr
= wClipSaveWorkspaceState(scr
, i
);
808 WMPutInPLDictionary(wks_state
, dClip
, pstr
);
809 WMReleasePropList(pstr
);
810 } else if (old_wks_state
!= NULL
) {
811 if ((foo
= WMGetFromPLArray(old_wks_state
, i
)) != NULL
) {
812 if ((bar
= WMGetFromPLDictionary(foo
, dClip
)) != NULL
) {
813 WMPutInPLDictionary(wks_state
, dClip
, bar
);
817 WMAddToPLArray(parr
, wks_state
);
818 WMReleasePropList(wks_state
);
820 WMPutInPLDictionary(scr
->session_state
, dWorkspaces
, parr
);
821 WMReleasePropList(parr
);
824 void wWorkspaceRestoreState(WScreen
* scr
)
826 WMPropList
*parr
, *pstr
, *wks_state
, *clip_state
;
831 if (scr
->session_state
== NULL
)
834 parr
= WMGetFromPLDictionary(scr
->session_state
, dWorkspaces
);
839 wscount
= scr
->workspace_count
;
840 for (i
= 0; i
< WMIN(WMGetPropListItemCount(parr
), MAX_WORKSPACES
); i
++) {
841 wks_state
= WMGetFromPLArray(parr
, i
);
842 if (WMIsPLDictionary(wks_state
))
843 pstr
= WMGetFromPLDictionary(wks_state
, dName
);
846 if (i
>= scr
->workspace_count
)
848 if (scr
->workspace_menu
) {
849 wfree(scr
->workspace_menu
->entries
[i
+ 2]->text
);
850 scr
->workspace_menu
->entries
[i
+ 2]->text
= wstrdup(WMGetFromPLString(pstr
));
851 scr
->workspace_menu
->flags
.realized
= 0;
853 wfree(scr
->workspaces
[i
]->name
);
854 scr
->workspaces
[i
]->name
= wstrdup(WMGetFromPLString(pstr
));
855 if (!wPreferences
.flags
.noclip
) {
856 int added_omnipresent_icons
= 0;
857 clip_state
= WMGetFromPLDictionary(wks_state
, dClip
);
858 if (scr
->workspaces
[i
]->clip
)
859 wDockDestroy(scr
->workspaces
[i
]->clip
);
860 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
, WM_CLIP
);
862 wDockHideIcons(scr
->workspaces
[i
]->clip
);
864 /* We set the global icons here, because scr->workspaces[i]->clip
865 * was not valid in wDockRestoreState().
866 * There we only set icon->omnipresent to know which icons we
869 for (j
= 0; j
< scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
870 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
873 if (!aicon
|| !aicon
->omnipresent
)
875 aicon
->omnipresent
= 0;
876 if (wClipMakeIconOmnipresent(aicon
, True
) != WO_SUCCESS
)
881 /* Move this appicon from workspace i to workspace 0 */
882 scr
->workspaces
[i
]->clip
->icon_array
[j
] = NULL
;
883 scr
->workspaces
[i
]->clip
->icon_count
--;
885 added_omnipresent_icons
++;
886 /* If there are too many omnipresent appicons, we are in trouble */
887 assert(scr
->workspaces
[0]->clip
->icon_count
+ added_omnipresent_icons
888 <= scr
->workspaces
[0]->clip
->max_icons
);
889 /* Find first free spot on workspace 0 */
890 for (k
= 0; k
< scr
->workspaces
[0]->clip
->max_icons
; k
++)
891 if (scr
->workspaces
[0]->clip
->icon_array
[k
] == NULL
)
893 scr
->workspaces
[0]->clip
->icon_array
[k
] = aicon
;
894 aicon
->dock
= scr
->workspaces
[0]->clip
;
896 scr
->workspaces
[0]->clip
->icon_count
+= added_omnipresent_icons
;
899 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) i
);