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 wVEdgeContext
;
59 extern void ProcessPendingEvents();
61 static WMPropList
*dWorkspaces
= NULL
;
62 static WMPropList
*dClip
, *dName
;
64 static void make_keys(void)
66 if (dWorkspaces
!= NULL
)
69 dWorkspaces
= WMCreatePLString("Workspaces");
70 dName
= WMCreatePLString("Name");
71 dClip
= WMCreatePLString("Clip");
74 void wWorkspaceMake(WScreen
* scr
, int count
)
82 int wWorkspaceNew(WScreen
* scr
)
84 WWorkspace
*wspace
, **list
;
87 if (scr
->workspace_count
< MAX_WORKSPACES
) {
88 scr
->workspace_count
++;
90 wspace
= wmalloc(sizeof(WWorkspace
));
94 wspace
->name
= wmalloc(strlen(_("Workspace %i")) + 8);
95 sprintf(wspace
->name
, _("Workspace %i"), scr
->workspace_count
);
98 if (!wPreferences
.flags
.noclip
) {
99 wspace
->clip
= wDockCreate(scr
, WM_CLIP
);
103 list
= wmalloc(sizeof(WWorkspace
*) * scr
->workspace_count
);
105 for (i
= 0; i
< scr
->workspace_count
- 1; i
++) {
106 list
[i
] = scr
->workspaces
[i
];
110 wfree(scr
->workspaces
);
111 scr
->workspaces
= list
;
113 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
114 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
115 wNETWMUpdateDesktop(scr
);
116 WMPostNotificationName(WMNWorkspaceCreated
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
119 return scr
->workspace_count
- 1;
125 Bool
wWorkspaceDelete(WScreen
* scr
, int workspace
)
134 /* verify if workspace is in use by some window */
135 tmp
= scr
->focused_window
;
137 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
== workspace
)
142 if (!wPreferences
.flags
.noclip
) {
143 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
144 scr
->workspaces
[workspace
]->clip
= NULL
;
147 list
= wmalloc(sizeof(WWorkspace
*) * (scr
->workspace_count
- 1));
149 for (i
= 0; i
< scr
->workspace_count
; i
++) {
150 if (i
!= workspace
) {
151 list
[j
++] = scr
->workspaces
[i
];
153 if (scr
->workspaces
[i
]->name
)
154 wfree(scr
->workspaces
[i
]->name
);
155 wfree(scr
->workspaces
[i
]);
158 wfree(scr
->workspaces
);
159 scr
->workspaces
= list
;
161 scr
->workspace_count
--;
164 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
165 /* clip workspace menu */
166 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
168 /* update also window menu */
169 if (scr
->workspace_submenu
) {
170 WMenu
*menu
= scr
->workspace_submenu
;
173 while (i
> scr
->workspace_count
)
174 wMenuRemoveItem(menu
, --i
);
178 if (scr
->clip_submenu
) {
179 WMenu
*menu
= scr
->clip_submenu
;
182 while (i
> scr
->workspace_count
)
183 wMenuRemoveItem(menu
, --i
);
186 wNETWMUpdateDesktop(scr
);
187 WMPostNotificationName(WMNWorkspaceDestroyed
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
189 if (scr
->current_workspace
>= scr
->workspace_count
)
190 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
195 typedef struct WorkspaceNameData
{
202 static void hideWorkspaceName(void *data
)
204 WScreen
*scr
= (WScreen
*) data
;
206 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
207 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
208 XUnmapWindow(dpy
, scr
->workspace_name
);
210 if (scr
->workspace_name_data
) {
211 RReleaseImage(scr
->workspace_name_data
->back
);
212 RReleaseImage(scr
->workspace_name_data
->text
);
213 wfree(scr
->workspace_name_data
);
215 scr
->workspace_name_data
= NULL
;
217 scr
->workspace_name_timer
= NULL
;
219 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
222 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
224 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
225 scr
->workspace_name_data
->count
* 255 / 10);
227 RConvertImage(scr
->rcontext
, img
, &pix
);
231 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
232 XClearWindow(dpy
, scr
->workspace_name
);
233 XFreePixmap(dpy
, pix
);
236 scr
->workspace_name_data
->count
--;
240 static void showWorkspaceName(WScreen
* scr
, int workspace
)
242 WorkspaceNameData
*data
;
247 char *name
= scr
->workspaces
[workspace
]->name
;
248 int len
= strlen(name
);
256 if (wPreferences
.workspace_name_display_position
== WD_NONE
|| scr
->workspace_count
< 2) {
260 if (scr
->workspace_name_timer
) {
261 WMDeleteTimerHandler(scr
->workspace_name_timer
);
262 XUnmapWindow(dpy
, scr
->workspace_name
);
265 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
, hideWorkspaceName
, scr
);
267 if (scr
->workspace_name_data
) {
268 RReleaseImage(scr
->workspace_name_data
->back
);
269 RReleaseImage(scr
->workspace_name_data
->text
);
270 wfree(scr
->workspace_name_data
);
273 data
= wmalloc(sizeof(WorkspaceNameData
));
276 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
277 h
= WMFontHeight(scr
->workspace_name_font
);
280 head
= wGetHeadForPointerLocation(scr
);
281 rect
= wGetRectForHead(scr
, head
);
282 if (scr
->xine_info
.count
) {
283 xx
= rect
.pos
.x
+ (scr
->xine_info
.screens
[head
].size
.width
- (w
+ 4)) / 2;
284 yy
= rect
.pos
.y
+ (scr
->xine_info
.screens
[head
].size
.height
- (h
+ 4)) / 2;
287 xx
= (scr
->scr_width
- (w
+ 4)) / 2;
288 yy
= (scr
->scr_height
- (h
+ 4)) / 2;
292 switch (wPreferences
.workspace_name_display_position
) {
297 px
= (scr
->scr_width
- (w
+ 4)) / 2;
299 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
305 px
= (scr
->scr_width
- (w
+ 4)) / 2;
307 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
310 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
311 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
314 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
315 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
318 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
319 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
322 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
323 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
331 px
= (scr
->scr_width
- (w
+ 4)) / 2;
332 py
= (scr
->scr_height
- (h
+ 4)) / 2;
336 XResizeWindow(dpy
, scr
->workspace_name
, w
+ 4, h
+ 4);
337 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
339 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, scr
->w_depth
);
340 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, 1);
342 /*XSetForeground(dpy, scr->mono_gc, 0);
343 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
345 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
347 for (x
= 0; x
<= 4; x
++) {
348 for (y
= 0; y
<= 4; y
++) {
349 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, x
, y
, name
, len
);
353 XSetForeground(dpy
, scr
->mono_gc
, 1);
354 XSetBackground(dpy
, scr
->mono_gc
, 0);
356 XCopyPlane(dpy
, text
, mask
, scr
->mono_gc
, 0, 0, w
+ 4, h
+ 4, 0, 0, 1 << (scr
->w_depth
- 1));
358 /*XSetForeground(dpy, scr->mono_gc, 1); */
359 XSetBackground(dpy
, scr
->mono_gc
, 1);
361 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
363 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, 2, 2, name
, len
);
366 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
368 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
369 XClearWindow(dpy
, scr
->workspace_name
);
371 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
373 XFreePixmap(dpy
, text
);
374 XFreePixmap(dpy
, mask
);
377 XMapRaised(dpy
, scr
->workspace_name
);
383 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
, data
->text
->width
, data
->text
->height
);
385 if (!ximg
|| !ximg
->image
) {
389 XMapRaised(dpy
, scr
->workspace_name
);
392 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
393 RDestroyXImage(scr
->rcontext
, ximg
);
401 /* set a timeout for the effect */
402 data
->timeout
= time(NULL
) + 2 + (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
* data
->count
) / 1000;
404 scr
->workspace_name_data
= data
;
409 if (scr
->workspace_name_timer
)
410 WMDeleteTimerHandler(scr
->workspace_name_timer
);
413 RReleaseImage(data
->text
);
415 RReleaseImage(data
->back
);
418 scr
->workspace_name_data
= NULL
;
420 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
421 10 * WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
424 void wWorkspaceChange(WScreen
*scr
, int workspace
)
426 if (scr
->flags
.startup
|| scr
->flags
.startup2
|| scr
->flags
.ignore_focus_events
)
429 if (workspace
!= scr
->current_workspace
)
430 wWorkspaceForceChange(scr
, workspace
);
433 void wWorkspaceRelativeChange(WScreen
* scr
, int amount
)
437 /* While the deiconify animation is going on the window is
438 * still "flying" to its final position and we don't want to
439 * change workspace before the animation finishes, otherwise
440 * the window will land in the new workspace */
441 if (ignore_wks_change
)
444 w
= scr
->current_workspace
+ amount
;
448 wWorkspaceChange(scr
, w
);
449 } else if (wPreferences
.ws_cycle
) {
450 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
452 } else if (amount
> 0) {
453 if (w
< scr
->workspace_count
) {
454 wWorkspaceChange(scr
, w
);
455 } else if (wPreferences
.ws_advance
) {
456 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
- 1));
457 } else if (wPreferences
.ws_cycle
) {
458 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
463 void wWorkspaceForceChange(WScreen
* scr
, int workspace
)
465 WWindow
*tmp
, *foc
= NULL
, *foc2
= NULL
;
467 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
470 SendHelperMessage(scr
, 'C', workspace
+ 1, NULL
);
472 if (workspace
> scr
->workspace_count
- 1) {
473 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
476 wClipUpdateForWorkspaceChange(scr
, workspace
);
478 scr
->current_workspace
= workspace
;
480 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
482 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
484 if ((tmp
= scr
->focused_window
) != NULL
) {
485 if ((IS_OMNIPRESENT(tmp
) && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
486 !WFLAGP(tmp
, no_focusable
)) || tmp
->flags
.changing_workspace
) {
490 /* foc2 = tmp; will fix annoyance with gnome panel
491 * but will create annoyance for every other application
494 if (tmp
->frame
->workspace
!= workspace
&& !tmp
->flags
.selected
) {
495 /* unmap windows not on this workspace */
496 if ((tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
497 !IS_OMNIPRESENT(tmp
) && !tmp
->flags
.changing_workspace
) {
500 /* also unmap miniwindows not on this workspace */
501 if (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
502 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
503 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
504 tmp
->icon
->mapped
= 0;
506 /* update current workspace of omnipresent windows */
507 if (IS_OMNIPRESENT(tmp
)) {
508 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
510 tmp
->frame
->workspace
= workspace
;
513 wapp
->last_workspace
= workspace
;
515 if (!foc2
&& (tmp
->flags
.mapped
|| tmp
->flags
.shaded
)) {
520 /* change selected windows' workspace */
521 if (tmp
->flags
.selected
) {
522 wWindowChangeWorkspace(tmp
, workspace
);
523 if (!tmp
->flags
.miniaturized
&& !foc
) {
527 if (!tmp
->flags
.hidden
) {
528 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
529 /* remap windows that are on this workspace */
531 if (!foc
&& !WFLAGP(tmp
, no_focusable
)) {
535 /* Also map miniwindow if not omnipresent */
536 if (!wPreferences
.sticky_icons
&&
537 tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
538 tmp
->icon
->mapped
= 1;
539 XMapWindow(dpy
, tmp
->icon
->core
->window
);
547 /* Gobble up events unleashed by our mapping & unmapping.
548 * These may trigger various grab-initiated focus &
549 * crossing events. However, we don't care about them,
550 * and ignore their focus implications altogether to avoid
553 scr
->flags
.ignore_focus_events
= 1;
554 ProcessPendingEvents();
555 scr
->flags
.ignore_focus_events
= 0;
560 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
561 foc
= scr
->focused_window
;
563 if (wPreferences
.focus_mode
== WKF_CLICK
) {
564 wSetFocusTo(scr
, foc
);
572 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
)) {
573 tmp
= wWindowFor(win
);
576 /* If there's a window under the pointer, focus it.
577 * (we ate all other focus events above, so it's
578 * certainly not focused). Otherwise focus last
579 * focused, or the root (depending on sloppiness)
581 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
582 wSetFocusTo(scr
, foc
);
584 wSetFocusTo(scr
, tmp
);
589 /* We need to always arrange icons when changing workspace, even if
590 * no autoarrange icons, because else the icons in different workspaces
592 * This can be avoided if appicons are also workspace specific.
594 if (!wPreferences
.sticky_icons
)
595 wArrangeIcons(scr
, False
);
598 wAppIconPaint(scr
->dock
->icon_array
[0]);
600 if (scr
->clip_icon
) {
601 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
602 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
603 /* to handle enter notify. This will also */
604 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
605 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
607 wClipIconPaint(scr
->clip_icon
);
610 wScreenUpdateUsableArea(scr
);
611 wNETWMUpdateDesktop(scr
);
612 showWorkspaceName(scr
, workspace
);
614 WMPostNotificationName(WMNWorkspaceChanged
, scr
, (void *)(uintptr_t) workspace
);
616 /* XSync(dpy, False); */
619 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
621 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
624 static void deleteWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
626 wWorkspaceDelete(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->workspace_count
- 1);
629 static void newWSCommand(WMenu
* menu
, WMenuEntry
* foo
)
633 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
634 /* autochange workspace */
636 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
641 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
642 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
644 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
649 static char *cropline(char *line
)
653 if (strlen(line
) == 0)
657 end
= &(line
[strlen(line
)]) - 1;
658 while (isspace(*line
) && *line
!= 0)
660 while (isspace(*end
) && end
!= line
) {
667 void wWorkspaceRename(WScreen
* scr
, int workspace
, char *name
)
669 char buf
[MAX_WORKSPACENAME_WIDTH
+ 1];
672 if (workspace
>= scr
->workspace_count
)
675 /* trim white spaces */
676 tmp
= cropline(name
);
678 if (strlen(tmp
) == 0) {
679 snprintf(buf
, sizeof(buf
), _("Workspace %i"), workspace
+ 1);
681 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
683 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
685 /* update workspace */
686 wfree(scr
->workspaces
[workspace
]->name
);
687 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
689 if (scr
->clip_ws_menu
) {
690 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
691 wfree(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
);
692 scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
693 wMenuRealize(scr
->clip_ws_menu
);
696 if (scr
->workspace_menu
) {
697 if (strcmp(scr
->workspace_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
698 wfree(scr
->workspace_menu
->entries
[workspace
+ 2]->text
);
699 scr
->workspace_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
700 wMenuRealize(scr
->workspace_menu
);
705 wClipIconPaint(scr
->clip_icon
);
707 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) workspace
);
710 /* callback for when menu entry is edited */
711 static void onMenuEntryEdited(WMenu
* menu
, WMenuEntry
* entry
)
716 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
719 WMenu
*wWorkspaceMenuMake(WScreen
* scr
, Bool titled
)
723 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
725 wwarning(_("could not create Workspace menu"));
729 /* callback to be called when an entry is edited */
730 wsmenu
->on_edit
= onMenuEntryEdited
;
732 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
733 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
738 void wWorkspaceMenuUpdate(WScreen
* scr
, WMenu
* menu
)
742 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
749 if (menu
->entry_no
< scr
->workspace_count
+ 2) {
750 /* new workspace(s) added */
751 i
= scr
->workspace_count
- (menu
->entry_no
- 2);
752 ws
= menu
->entry_no
- 2;
754 strncpy(title
, scr
->workspaces
[ws
]->name
, MAX_WORKSPACENAME_WIDTH
);
756 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)ws
);
757 entry
->flags
.indicator
= 1;
758 entry
->flags
.editable
= 1;
763 } else if (menu
->entry_no
> scr
->workspace_count
+ 2) {
764 /* removed workspace(s) */
765 for (i
= menu
->entry_no
- 1; i
>= scr
->workspace_count
+ 2; i
--) {
766 wMenuRemoveItem(menu
, i
);
771 for (i
= 0; i
< scr
->workspace_count
; i
++) {
772 menu
->entries
[i
+ 2]->flags
.indicator_on
= 0;
774 menu
->entries
[scr
->current_workspace
+ 2]->flags
.indicator_on
= 1;
776 /* don't let user destroy current workspace */
777 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
778 wMenuSetEnabled(menu
, 1, False
);
780 wMenuSetEnabled(menu
, 1, True
);
783 tmp
= menu
->frame
->top_width
+ 5;
784 /* if menu got unreachable, bring it to a visible place */
785 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
786 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
791 void wWorkspaceSaveState(WScreen
* scr
, WMPropList
* old_state
)
793 WMPropList
*parr
, *pstr
, *wks_state
, *old_wks_state
, *foo
, *bar
;
798 old_wks_state
= WMGetFromPLDictionary(old_state
, dWorkspaces
);
799 parr
= WMCreatePLArray(NULL
);
800 for (i
= 0; i
< scr
->workspace_count
; i
++) {
801 pstr
= WMCreatePLString(scr
->workspaces
[i
]->name
);
802 wks_state
= WMCreatePLDictionary(dName
, pstr
, NULL
);
803 WMReleasePropList(pstr
);
804 if (!wPreferences
.flags
.noclip
) {
805 pstr
= wClipSaveWorkspaceState(scr
, i
);
806 WMPutInPLDictionary(wks_state
, dClip
, pstr
);
807 WMReleasePropList(pstr
);
808 } else if (old_wks_state
!= NULL
) {
809 if ((foo
= WMGetFromPLArray(old_wks_state
, i
)) != NULL
) {
810 if ((bar
= WMGetFromPLDictionary(foo
, dClip
)) != NULL
) {
811 WMPutInPLDictionary(wks_state
, dClip
, bar
);
815 WMAddToPLArray(parr
, wks_state
);
816 WMReleasePropList(wks_state
);
818 WMPutInPLDictionary(scr
->session_state
, dWorkspaces
, parr
);
819 WMReleasePropList(parr
);
822 void wWorkspaceRestoreState(WScreen
* scr
)
824 WMPropList
*parr
, *pstr
, *wks_state
, *clip_state
;
829 if (scr
->session_state
== NULL
)
832 parr
= WMGetFromPLDictionary(scr
->session_state
, dWorkspaces
);
837 wscount
= scr
->workspace_count
;
838 for (i
= 0; i
< WMIN(WMGetPropListItemCount(parr
), MAX_WORKSPACES
); i
++) {
839 wks_state
= WMGetFromPLArray(parr
, i
);
840 if (WMIsPLDictionary(wks_state
))
841 pstr
= WMGetFromPLDictionary(wks_state
, dName
);
844 if (i
>= scr
->workspace_count
)
846 if (scr
->workspace_menu
) {
847 wfree(scr
->workspace_menu
->entries
[i
+ 2]->text
);
848 scr
->workspace_menu
->entries
[i
+ 2]->text
= wstrdup(WMGetFromPLString(pstr
));
849 scr
->workspace_menu
->flags
.realized
= 0;
851 wfree(scr
->workspaces
[i
]->name
);
852 scr
->workspaces
[i
]->name
= wstrdup(WMGetFromPLString(pstr
));
853 if (!wPreferences
.flags
.noclip
) {
854 int added_omnipresent_icons
= 0;
855 clip_state
= WMGetFromPLDictionary(wks_state
, dClip
);
856 if (scr
->workspaces
[i
]->clip
)
857 wDockDestroy(scr
->workspaces
[i
]->clip
);
858 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
, WM_CLIP
);
860 wDockHideIcons(scr
->workspaces
[i
]->clip
);
862 /* We set the global icons here, because scr->workspaces[i]->clip
863 * was not valid in wDockRestoreState().
864 * There we only set icon->omnipresent to know which icons we
867 for (j
= 0; j
< scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
868 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
871 if (!aicon
|| !aicon
->omnipresent
)
873 aicon
->omnipresent
= 0;
874 if (wClipMakeIconOmnipresent(aicon
, True
) != WO_SUCCESS
)
879 /* Move this appicon from workspace i to workspace 0 */
880 scr
->workspaces
[i
]->clip
->icon_array
[j
] = NULL
;
881 scr
->workspaces
[i
]->clip
->icon_count
--;
883 added_omnipresent_icons
++;
884 /* If there are too many omnipresent appicons, we are in trouble */
885 assert(scr
->workspaces
[0]->clip
->icon_count
+ added_omnipresent_icons
886 <= scr
->workspaces
[0]->clip
->max_icons
);
887 /* Find first free spot on workspace 0 */
888 for (k
= 0; k
< scr
->workspaces
[0]->clip
->max_icons
; k
++)
889 if (scr
->workspaces
[0]->clip
->icon_array
[k
] == NULL
)
891 scr
->workspaces
[0]->clip
->icon_array
[k
] = aicon
;
892 aicon
->dock
= scr
->workspaces
[0]->clip
;
894 scr
->workspaces
[0]->clip
->icon_count
+= added_omnipresent_icons
;
897 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) i
);