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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <X11/Xutil.h>
26 #include <X11/extensions/shape.h>
38 #include "WindowMaker.h"
44 #include "application.h"
47 #include "workspace.h"
52 #define MAX_SHORTCUT_LENGTH 32
53 #define WORKSPACE_NAME_DISPLAY_PADDING 32
55 extern int ignore_wks_change
;
56 extern WPreferences wPreferences
;
57 extern XContext wVEdgeContext
;
58 extern void ProcessPendingEvents();
60 static WMPropList
*dWorkspaces
= NULL
;
61 static WMPropList
*dClip
, *dName
;
63 static void make_keys(void)
65 if (dWorkspaces
!= NULL
)
68 dWorkspaces
= WMCreatePLString("Workspaces");
69 dName
= WMCreatePLString("Name");
70 dClip
= WMCreatePLString("Clip");
73 void wWorkspaceMake(WScreen
* scr
, int count
)
81 int wWorkspaceNew(WScreen
* scr
)
83 WWorkspace
*wspace
, **list
;
86 if (scr
->workspace_count
< MAX_WORKSPACES
) {
87 scr
->workspace_count
++;
89 wspace
= wmalloc(sizeof(WWorkspace
));
93 wspace
->name
= wmalloc(strlen(_("Workspace %i")) + 8);
94 sprintf(wspace
->name
, _("Workspace %i"), scr
->workspace_count
);
97 if (!wPreferences
.flags
.noclip
) {
98 wspace
->clip
= wDockCreate(scr
, WM_CLIP
);
102 list
= wmalloc(sizeof(WWorkspace
*) * scr
->workspace_count
);
104 for (i
= 0; i
< scr
->workspace_count
- 1; i
++) {
105 list
[i
] = scr
->workspaces
[i
];
109 wfree(scr
->workspaces
);
110 scr
->workspaces
= list
;
112 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
113 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
114 wNETWMUpdateDesktop(scr
);
115 WMPostNotificationName(WMNWorkspaceCreated
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
118 return scr
->workspace_count
- 1;
124 Bool
wWorkspaceDelete(WScreen
* scr
, int workspace
)
133 /* verify if workspace is in use by some window */
134 tmp
= scr
->focused_window
;
136 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
== workspace
)
141 if (!wPreferences
.flags
.noclip
) {
142 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
143 scr
->workspaces
[workspace
]->clip
= NULL
;
146 list
= wmalloc(sizeof(WWorkspace
*) * (scr
->workspace_count
- 1));
148 for (i
= 0; i
< scr
->workspace_count
; i
++) {
149 if (i
!= workspace
) {
150 list
[j
++] = scr
->workspaces
[i
];
152 if (scr
->workspaces
[i
]->name
)
153 wfree(scr
->workspaces
[i
]->name
);
154 wfree(scr
->workspaces
[i
]);
157 wfree(scr
->workspaces
);
158 scr
->workspaces
= list
;
160 scr
->workspace_count
--;
163 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
164 /* clip workspace menu */
165 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
167 /* update also window menu */
168 if (scr
->workspace_submenu
) {
169 WMenu
*menu
= scr
->workspace_submenu
;
172 while (i
> scr
->workspace_count
)
173 wMenuRemoveItem(menu
, --i
);
177 if (scr
->clip_submenu
) {
178 WMenu
*menu
= scr
->clip_submenu
;
181 while (i
> scr
->workspace_count
)
182 wMenuRemoveItem(menu
, --i
);
185 wNETWMUpdateDesktop(scr
);
186 WMPostNotificationName(WMNWorkspaceDestroyed
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
188 if (scr
->current_workspace
>= scr
->workspace_count
)
189 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
194 typedef struct WorkspaceNameData
{
201 static void hideWorkspaceName(void *data
)
203 WScreen
*scr
= (WScreen
*) data
;
205 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
206 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
207 XUnmapWindow(dpy
, scr
->workspace_name
);
209 if (scr
->workspace_name_data
) {
210 RReleaseImage(scr
->workspace_name_data
->back
);
211 RReleaseImage(scr
->workspace_name_data
->text
);
212 wfree(scr
->workspace_name_data
);
214 scr
->workspace_name_data
= NULL
;
216 scr
->workspace_name_timer
= NULL
;
218 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
221 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
223 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
224 scr
->workspace_name_data
->count
* 255 / 10);
226 RConvertImage(scr
->rcontext
, img
, &pix
);
230 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
231 XClearWindow(dpy
, scr
->workspace_name
);
232 XFreePixmap(dpy
, pix
);
235 scr
->workspace_name_data
->count
--;
239 static void showWorkspaceName(WScreen
* scr
, int workspace
)
241 WorkspaceNameData
*data
;
246 char *name
= scr
->workspaces
[workspace
]->name
;
247 int len
= strlen(name
);
255 if (wPreferences
.workspace_name_display_position
== WD_NONE
|| scr
->workspace_count
< 2) {
259 if (scr
->workspace_name_timer
) {
260 WMDeleteTimerHandler(scr
->workspace_name_timer
);
261 XUnmapWindow(dpy
, scr
->workspace_name
);
264 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
, hideWorkspaceName
, scr
);
266 if (scr
->workspace_name_data
) {
267 RReleaseImage(scr
->workspace_name_data
->back
);
268 RReleaseImage(scr
->workspace_name_data
->text
);
269 wfree(scr
->workspace_name_data
);
272 data
= wmalloc(sizeof(WorkspaceNameData
));
275 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
276 h
= WMFontHeight(scr
->workspace_name_font
);
279 head
= wGetHeadForPointerLocation(scr
);
280 rect
= wGetRectForHead(scr
, head
);
281 if (scr
->xine_info
.count
) {
282 xx
= rect
.pos
.x
+ (scr
->xine_info
.screens
[head
].size
.width
- (w
+ 4)) / 2;
283 yy
= rect
.pos
.y
+ (scr
->xine_info
.screens
[head
].size
.height
- (h
+ 4)) / 2;
286 xx
= (scr
->scr_width
- (w
+ 4)) / 2;
287 yy
= (scr
->scr_height
- (h
+ 4)) / 2;
291 switch (wPreferences
.workspace_name_display_position
) {
296 px
= (scr
->scr_width
- (w
+ 4)) / 2;
298 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
304 px
= (scr
->scr_width
- (w
+ 4)) / 2;
306 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
309 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
310 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
313 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
314 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
317 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
318 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
321 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
322 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
330 px
= (scr
->scr_width
- (w
+ 4)) / 2;
331 py
= (scr
->scr_height
- (h
+ 4)) / 2;
335 XResizeWindow(dpy
, scr
->workspace_name
, w
+ 4, h
+ 4);
336 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
338 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, scr
->w_depth
);
339 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, 1);
341 /*XSetForeground(dpy, scr->mono_gc, 0);
342 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
344 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
346 for (x
= 0; x
<= 4; x
++) {
347 for (y
= 0; y
<= 4; y
++) {
348 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, x
, y
, name
, len
);
352 XSetForeground(dpy
, scr
->mono_gc
, 1);
353 XSetBackground(dpy
, scr
->mono_gc
, 0);
355 XCopyPlane(dpy
, text
, mask
, scr
->mono_gc
, 0, 0, w
+ 4, h
+ 4, 0, 0, 1 << (scr
->w_depth
- 1));
357 /*XSetForeground(dpy, scr->mono_gc, 1); */
358 XSetBackground(dpy
, scr
->mono_gc
, 1);
360 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
362 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, 2, 2, name
, len
);
365 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
367 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
368 XClearWindow(dpy
, scr
->workspace_name
);
370 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
372 XFreePixmap(dpy
, text
);
373 XFreePixmap(dpy
, mask
);
376 XMapRaised(dpy
, scr
->workspace_name
);
382 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
, data
->text
->width
, data
->text
->height
);
384 if (!ximg
|| !ximg
->image
) {
388 XMapRaised(dpy
, scr
->workspace_name
);
391 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
392 RDestroyXImage(scr
->rcontext
, ximg
);
400 /* set a timeout for the effect */
401 data
->timeout
= time(NULL
) + 2 + (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
* data
->count
) / 1000;
403 scr
->workspace_name_data
= data
;
408 if (scr
->workspace_name_timer
)
409 WMDeleteTimerHandler(scr
->workspace_name_timer
);
412 RReleaseImage(data
->text
);
414 RReleaseImage(data
->back
);
417 scr
->workspace_name_data
= NULL
;
419 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
420 10 * WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
423 void wWorkspaceChange(WScreen
*scr
, int workspace
)
425 if (scr
->flags
.startup
|| scr
->flags
.startup2
|| scr
->flags
.ignore_focus_events
)
428 if (workspace
!= scr
->current_workspace
)
429 wWorkspaceForceChange(scr
, workspace
);
432 void wWorkspaceRelativeChange(WScreen
* scr
, int amount
)
436 /* While the deiconify animation is going on the window is
437 * still "flying" to its final position and we don't want to
438 * change workspace before the animation finishes, otherwise
439 * the window will land in the new workspace */
440 if (ignore_wks_change
)
443 w
= scr
->current_workspace
+ amount
;
447 wWorkspaceChange(scr
, w
);
448 } else if (wPreferences
.ws_cycle
) {
449 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
451 } else if (amount
> 0) {
452 if (w
< scr
->workspace_count
) {
453 wWorkspaceChange(scr
, w
);
454 } else if (wPreferences
.ws_advance
) {
455 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
- 1));
456 } else if (wPreferences
.ws_cycle
) {
457 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
462 void wWorkspaceForceChange(WScreen
* scr
, int workspace
)
464 WWindow
*tmp
, *foc
= NULL
, *foc2
= NULL
;
466 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
469 SendHelperMessage(scr
, 'C', workspace
+ 1, NULL
);
471 if (workspace
> scr
->workspace_count
- 1) {
472 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
475 wClipUpdateForWorkspaceChange(scr
, workspace
);
477 scr
->current_workspace
= workspace
;
479 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
481 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
483 if ((tmp
= scr
->focused_window
) != NULL
) {
484 if ((IS_OMNIPRESENT(tmp
) && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
485 !WFLAGP(tmp
, no_focusable
)) || tmp
->flags
.changing_workspace
) {
489 /* foc2 = tmp; will fix annoyance with gnome panel
490 * but will create annoyance for every other application
493 if (tmp
->frame
->workspace
!= workspace
&& !tmp
->flags
.selected
) {
494 /* unmap windows not on this workspace */
495 if ((tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
496 !IS_OMNIPRESENT(tmp
) && !tmp
->flags
.changing_workspace
) {
499 /* also unmap miniwindows not on this workspace */
500 if (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
501 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
502 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
503 tmp
->icon
->mapped
= 0;
505 /* update current workspace of omnipresent windows */
506 if (IS_OMNIPRESENT(tmp
)) {
507 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
509 tmp
->frame
->workspace
= workspace
;
512 wapp
->last_workspace
= workspace
;
514 if (!foc2
&& (tmp
->flags
.mapped
|| tmp
->flags
.shaded
)) {
519 /* change selected windows' workspace */
520 if (tmp
->flags
.selected
) {
521 wWindowChangeWorkspace(tmp
, workspace
);
522 if (!tmp
->flags
.miniaturized
&& !foc
) {
526 if (!tmp
->flags
.hidden
) {
527 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
528 /* remap windows that are on this workspace */
530 if (!foc
&& !WFLAGP(tmp
, no_focusable
)) {
534 /* Also map miniwindow if not omnipresent */
535 if (!wPreferences
.sticky_icons
&&
536 tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
537 tmp
->icon
->mapped
= 1;
538 XMapWindow(dpy
, tmp
->icon
->core
->window
);
546 /* Gobble up events unleashed by our mapping & unmapping.
547 * These may trigger various grab-initiated focus &
548 * crossing events. However, we don't care about them,
549 * and ignore their focus implications altogether to avoid
552 scr
->flags
.ignore_focus_events
= 1;
553 ProcessPendingEvents();
554 scr
->flags
.ignore_focus_events
= 0;
559 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
560 foc
= scr
->focused_window
;
562 if (wPreferences
.focus_mode
== WKF_CLICK
) {
563 wSetFocusTo(scr
, foc
);
571 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
)) {
572 tmp
= wWindowFor(win
);
575 /* If there's a window under the pointer, focus it.
576 * (we ate all other focus events above, so it's
577 * certainly not focused). Otherwise focus last
578 * focused, or the root (depending on sloppiness)
580 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
581 wSetFocusTo(scr
, foc
);
583 wSetFocusTo(scr
, tmp
);
588 /* We need to always arrange icons when changing workspace, even if
589 * no autoarrange icons, because else the icons in different workspaces
591 * This can be avoided if appicons are also workspace specific.
593 if (!wPreferences
.sticky_icons
)
594 wArrangeIcons(scr
, False
);
597 wAppIconPaint(scr
->dock
->icon_array
[0], False
);
599 if (scr
->clip_icon
) {
600 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
601 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
602 /* to handle enter notify. This will also */
603 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
604 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
606 wClipIconPaint(scr
->clip_icon
);
609 wScreenUpdateUsableArea(scr
);
610 wNETWMUpdateDesktop(scr
);
611 showWorkspaceName(scr
, workspace
);
613 WMPostNotificationName(WMNWorkspaceChanged
, scr
, (void *)(uintptr_t) workspace
);
615 /* XSync(dpy, False); */
618 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
620 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
623 static void deleteWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
625 wWorkspaceDelete(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->workspace_count
- 1);
628 static void newWSCommand(WMenu
* menu
, WMenuEntry
* foo
)
632 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
633 /* autochange workspace */
635 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
640 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
641 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
643 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
648 void wWorkspaceRename(WScreen
* scr
, int workspace
, char *name
)
650 char buf
[MAX_WORKSPACENAME_WIDTH
+ 1];
653 if (workspace
>= scr
->workspace_count
)
656 /* trim white spaces */
657 tmp
= wtrimspace(name
);
659 if (strlen(tmp
) == 0) {
660 snprintf(buf
, sizeof(buf
), _("Workspace %i"), workspace
+ 1);
662 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
664 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
667 /* update workspace */
668 wfree(scr
->workspaces
[workspace
]->name
);
669 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
671 if (scr
->clip_ws_menu
) {
672 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
673 wfree(scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
);
674 scr
->clip_ws_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
675 wMenuRealize(scr
->clip_ws_menu
);
678 if (scr
->workspace_menu
) {
679 if (strcmp(scr
->workspace_menu
->entries
[workspace
+ 2]->text
, buf
) != 0) {
680 wfree(scr
->workspace_menu
->entries
[workspace
+ 2]->text
);
681 scr
->workspace_menu
->entries
[workspace
+ 2]->text
= wstrdup(buf
);
682 wMenuRealize(scr
->workspace_menu
);
687 wClipIconPaint(scr
->clip_icon
);
689 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) workspace
);
692 /* callback for when menu entry is edited */
693 static void onMenuEntryEdited(WMenu
* menu
, WMenuEntry
* entry
)
698 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
701 WMenu
*wWorkspaceMenuMake(WScreen
* scr
, Bool titled
)
705 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
707 wwarning(_("could not create Workspace menu"));
711 /* callback to be called when an entry is edited */
712 wsmenu
->on_edit
= onMenuEntryEdited
;
714 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
715 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
720 void wWorkspaceMenuUpdate(WScreen
* scr
, WMenu
* menu
)
724 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
731 if (menu
->entry_no
< scr
->workspace_count
+ 2) {
732 /* new workspace(s) added */
733 i
= scr
->workspace_count
- (menu
->entry_no
- 2);
734 ws
= menu
->entry_no
- 2;
736 wstrlcpy(title
, scr
->workspaces
[ws
]->name
, MAX_WORKSPACENAME_WIDTH
);
738 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)ws
);
739 entry
->flags
.indicator
= 1;
740 entry
->flags
.editable
= 1;
745 } else if (menu
->entry_no
> scr
->workspace_count
+ 2) {
746 /* removed workspace(s) */
747 for (i
= menu
->entry_no
- 1; i
>= scr
->workspace_count
+ 2; i
--) {
748 wMenuRemoveItem(menu
, i
);
753 for (i
= 0; i
< scr
->workspace_count
; i
++) {
754 menu
->entries
[i
+ 2]->flags
.indicator_on
= 0;
756 menu
->entries
[scr
->current_workspace
+ 2]->flags
.indicator_on
= 1;
758 /* don't let user destroy current workspace */
759 if (scr
->current_workspace
== scr
->workspace_count
- 1) {
760 wMenuSetEnabled(menu
, 1, False
);
762 wMenuSetEnabled(menu
, 1, True
);
765 tmp
= menu
->frame
->top_width
+ 5;
766 /* if menu got unreachable, bring it to a visible place */
767 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
768 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
773 void wWorkspaceSaveState(WScreen
* scr
, WMPropList
* old_state
)
775 WMPropList
*parr
, *pstr
, *wks_state
, *old_wks_state
, *foo
, *bar
;
780 old_wks_state
= WMGetFromPLDictionary(old_state
, dWorkspaces
);
781 parr
= WMCreatePLArray(NULL
);
782 for (i
= 0; i
< scr
->workspace_count
; i
++) {
783 pstr
= WMCreatePLString(scr
->workspaces
[i
]->name
);
784 wks_state
= WMCreatePLDictionary(dName
, pstr
, NULL
);
785 WMReleasePropList(pstr
);
786 if (!wPreferences
.flags
.noclip
) {
787 pstr
= wClipSaveWorkspaceState(scr
, i
);
788 WMPutInPLDictionary(wks_state
, dClip
, pstr
);
789 WMReleasePropList(pstr
);
790 } else if (old_wks_state
!= NULL
) {
791 if ((foo
= WMGetFromPLArray(old_wks_state
, i
)) != NULL
) {
792 if ((bar
= WMGetFromPLDictionary(foo
, dClip
)) != NULL
) {
793 WMPutInPLDictionary(wks_state
, dClip
, bar
);
797 WMAddToPLArray(parr
, wks_state
);
798 WMReleasePropList(wks_state
);
800 WMPutInPLDictionary(scr
->session_state
, dWorkspaces
, parr
);
801 WMReleasePropList(parr
);
804 void wWorkspaceRestoreState(WScreen
* scr
)
806 WMPropList
*parr
, *pstr
, *wks_state
, *clip_state
;
811 if (scr
->session_state
== NULL
)
814 parr
= WMGetFromPLDictionary(scr
->session_state
, dWorkspaces
);
819 for (i
= 0; i
< WMIN(WMGetPropListItemCount(parr
), MAX_WORKSPACES
); i
++) {
820 wks_state
= WMGetFromPLArray(parr
, i
);
821 if (WMIsPLDictionary(wks_state
))
822 pstr
= WMGetFromPLDictionary(wks_state
, dName
);
825 if (i
>= scr
->workspace_count
)
827 if (scr
->workspace_menu
) {
828 wfree(scr
->workspace_menu
->entries
[i
+ 2]->text
);
829 scr
->workspace_menu
->entries
[i
+ 2]->text
= wstrdup(WMGetFromPLString(pstr
));
830 scr
->workspace_menu
->flags
.realized
= 0;
832 wfree(scr
->workspaces
[i
]->name
);
833 scr
->workspaces
[i
]->name
= wstrdup(WMGetFromPLString(pstr
));
834 if (!wPreferences
.flags
.noclip
) {
835 int added_omnipresent_icons
= 0;
836 clip_state
= WMGetFromPLDictionary(wks_state
, dClip
);
837 if (scr
->workspaces
[i
]->clip
)
838 wDockDestroy(scr
->workspaces
[i
]->clip
);
839 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
, WM_CLIP
);
841 wDockHideIcons(scr
->workspaces
[i
]->clip
);
843 /* We set the global icons here, because scr->workspaces[i]->clip
844 * was not valid in wDockRestoreState().
845 * There we only set icon->omnipresent to know which icons we
848 for (j
= 0; j
< scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
849 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
852 if (!aicon
|| !aicon
->omnipresent
)
854 aicon
->omnipresent
= 0;
855 if (wClipMakeIconOmnipresent(aicon
, True
) != WO_SUCCESS
)
860 /* Move this appicon from workspace i to workspace 0 */
861 scr
->workspaces
[i
]->clip
->icon_array
[j
] = NULL
;
862 scr
->workspaces
[i
]->clip
->icon_count
--;
864 added_omnipresent_icons
++;
865 /* If there are too many omnipresent appicons, we are in trouble */
866 assert(scr
->workspaces
[0]->clip
->icon_count
+ added_omnipresent_icons
867 <= scr
->workspaces
[0]->clip
->max_icons
);
868 /* Find first free spot on workspace 0 */
869 for (k
= 0; k
< scr
->workspaces
[0]->clip
->max_icons
; k
++)
870 if (scr
->workspaces
[0]->clip
->icon_array
[k
] == NULL
)
872 scr
->workspaces
[0]->clip
->icon_array
[k
] = aicon
;
873 aicon
->dock
= scr
->workspaces
[0]->clip
;
875 scr
->workspaces
[0]->clip
->icon_count
+= added_omnipresent_icons
;
878 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) i
);
882 /* Returns the workspace number for a given workspace name */
883 int wGetWorkspaceNumber(WScreen
* scr
, char * value
)
887 if (sscanf(value
, "%i", &w
) != 1) {
889 for (i
= 0; i
< scr
->workspace_count
; i
++) {
890 if (strcmp(scr
->workspaces
[i
]->name
, value
) == 0) {