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"
56 #define MC_DESTROY_LAST 1
57 #define MC_LAST_USED 2
58 /* index of the first workspace menu entry */
59 #define MC_WORKSPACE1 3
61 #define WORKSPACE_NAME_DISPLAY_PADDING 32
63 static WMPropList
*dWorkspaces
= NULL
;
64 static WMPropList
*dClip
, *dName
;
66 static void make_keys(void)
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
));
97 static const char *new_name
= NULL
;
98 static size_t name_length
;
100 if (new_name
== NULL
) {
101 new_name
= _("Workspace %i");
102 name_length
= strlen(new_name
) + 8;
104 wspace
->name
= wmalloc(name_length
);
105 snprintf(wspace
->name
, name_length
, new_name
, scr
->workspace_count
);
108 if (!wPreferences
.flags
.noclip
)
109 wspace
->clip
= wDockCreate(scr
, WM_CLIP
, NULL
);
111 list
= wmalloc(sizeof(WWorkspace
*) * scr
->workspace_count
);
113 for (i
= 0; i
< scr
->workspace_count
- 1; i
++)
114 list
[i
] = scr
->workspaces
[i
];
118 wfree(scr
->workspaces
);
120 scr
->workspaces
= list
;
122 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
123 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
124 wNETWMUpdateDesktop(scr
);
125 WMPostNotificationName(WMNWorkspaceCreated
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
128 return scr
->workspace_count
- 1;
134 Bool
wWorkspaceDelete(WScreen
* scr
, int workspace
)
143 /* verify if workspace is in use by some window */
144 tmp
= scr
->focused_window
;
146 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
== workspace
) {
148 snprintf(buf
, sizeof(buf
), _("Workspace \"%s\" in use; cannot delete"),
149 scr
->workspaces
[workspace
]->name
);
150 wMessageDialog(scr
, _("Error"), buf
, _("OK"), NULL
, NULL
);
156 if (!wPreferences
.flags
.noclip
) {
157 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
158 scr
->workspaces
[workspace
]->clip
= NULL
;
161 list
= wmalloc(sizeof(WWorkspace
*) * (scr
->workspace_count
- 1));
163 for (i
= 0; i
< scr
->workspace_count
; i
++) {
164 if (i
!= workspace
) {
165 list
[j
++] = scr
->workspaces
[i
];
167 if (scr
->workspaces
[i
]->name
)
168 wfree(scr
->workspaces
[i
]->name
);
169 if (scr
->workspaces
[i
]->map
)
170 RReleaseImage(scr
->workspaces
[i
]->map
);
171 wfree(scr
->workspaces
[i
]);
174 wfree(scr
->workspaces
);
175 scr
->workspaces
= list
;
177 scr
->workspace_count
--;
180 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
181 /* clip workspace menu */
182 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
184 /* update also window menu */
185 if (scr
->workspace_submenu
) {
186 WMenu
*menu
= scr
->workspace_submenu
;
189 while (i
> scr
->workspace_count
)
190 wMenuRemoveItem(menu
, --i
);
194 if (scr
->clip_submenu
) {
195 WMenu
*menu
= scr
->clip_submenu
;
198 while (i
> scr
->workspace_count
)
199 wMenuRemoveItem(menu
, --i
);
202 wNETWMUpdateDesktop(scr
);
203 WMPostNotificationName(WMNWorkspaceDestroyed
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
205 if (scr
->current_workspace
>= scr
->workspace_count
)
206 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
207 if (scr
->last_workspace
>= scr
->workspace_count
)
208 scr
->last_workspace
= 0;
213 typedef struct WorkspaceNameData
{
220 static void hideWorkspaceName(void *data
)
222 WScreen
*scr
= (WScreen
*) data
;
224 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
225 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
226 XUnmapWindow(dpy
, scr
->workspace_name
);
228 if (scr
->workspace_name_data
) {
229 RReleaseImage(scr
->workspace_name_data
->back
);
230 RReleaseImage(scr
->workspace_name_data
->text
);
231 wfree(scr
->workspace_name_data
);
233 scr
->workspace_name_data
= NULL
;
235 scr
->workspace_name_timer
= NULL
;
237 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
240 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
242 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
243 scr
->workspace_name_data
->count
* 255 / 10);
245 RConvertImage(scr
->rcontext
, img
, &pix
);
249 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
250 XClearWindow(dpy
, scr
->workspace_name
);
251 XFreePixmap(dpy
, pix
);
254 scr
->workspace_name_data
->count
--;
258 static void showWorkspaceName(WScreen
* scr
, int workspace
)
260 WorkspaceNameData
*data
;
265 char *name
= scr
->workspaces
[workspace
]->name
;
266 int len
= strlen(name
);
274 if (wPreferences
.workspace_name_display_position
== WD_NONE
|| scr
->workspace_count
< 2)
277 if (scr
->workspace_name_timer
) {
278 WMDeleteTimerHandler(scr
->workspace_name_timer
);
279 XUnmapWindow(dpy
, scr
->workspace_name
);
282 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
, hideWorkspaceName
, scr
);
284 if (scr
->workspace_name_data
) {
285 RReleaseImage(scr
->workspace_name_data
->back
);
286 RReleaseImage(scr
->workspace_name_data
->text
);
287 wfree(scr
->workspace_name_data
);
290 data
= wmalloc(sizeof(WorkspaceNameData
));
293 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
294 h
= WMFontHeight(scr
->workspace_name_font
);
297 head
= wGetHeadForPointerLocation(scr
);
298 rect
= wGetRectForHead(scr
, head
);
299 if (scr
->xine_info
.count
) {
300 xx
= rect
.pos
.x
+ (scr
->xine_info
.screens
[head
].size
.width
- (w
+ 4)) / 2;
301 yy
= rect
.pos
.y
+ (scr
->xine_info
.screens
[head
].size
.height
- (h
+ 4)) / 2;
304 xx
= (scr
->scr_width
- (w
+ 4)) / 2;
305 yy
= (scr
->scr_height
- (h
+ 4)) / 2;
309 switch (wPreferences
.workspace_name_display_position
) {
314 px
= (scr
->scr_width
- (w
+ 4)) / 2;
316 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
322 px
= (scr
->scr_width
- (w
+ 4)) / 2;
324 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
327 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
328 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
331 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
332 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
335 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
336 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
339 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
340 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
348 px
= (scr
->scr_width
- (w
+ 4)) / 2;
349 py
= (scr
->scr_height
- (h
+ 4)) / 2;
353 XResizeWindow(dpy
, scr
->workspace_name
, w
+ 4, h
+ 4);
354 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
356 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, scr
->w_depth
);
357 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, 1);
359 /*XSetForeground(dpy, scr->mono_gc, 0);
360 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
362 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
364 for (x
= 0; x
<= 4; x
++)
365 for (y
= 0; y
<= 4; y
++)
366 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, x
, y
, name
, len
);
368 XSetForeground(dpy
, scr
->mono_gc
, 1);
369 XSetBackground(dpy
, scr
->mono_gc
, 0);
371 XCopyPlane(dpy
, text
, mask
, scr
->mono_gc
, 0, 0, w
+ 4, h
+ 4, 0, 0, 1 << (scr
->w_depth
- 1));
373 /*XSetForeground(dpy, scr->mono_gc, 1); */
374 XSetBackground(dpy
, scr
->mono_gc
, 1);
376 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
378 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, 2, 2, name
, len
);
381 if (w_global
.xext
.shape
.supported
)
382 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
384 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
385 XClearWindow(dpy
, scr
->workspace_name
);
387 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
389 XFreePixmap(dpy
, text
);
390 XFreePixmap(dpy
, mask
);
393 XMapRaised(dpy
, scr
->workspace_name
);
399 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
, data
->text
->width
, data
->text
->height
);
403 XMapRaised(dpy
, scr
->workspace_name
);
406 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
407 RDestroyXImage(scr
->rcontext
, ximg
);
415 /* set a timeout for the effect */
416 data
->timeout
= time(NULL
) + 2 + (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
* data
->count
) / 1000;
418 scr
->workspace_name_data
= data
;
423 if (scr
->workspace_name_timer
)
424 WMDeleteTimerHandler(scr
->workspace_name_timer
);
427 RReleaseImage(data
->text
);
429 RReleaseImage(data
->back
);
432 scr
->workspace_name_data
= NULL
;
434 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
435 10 * WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
438 void wWorkspaceChange(WScreen
*scr
, int workspace
)
440 if (scr
->flags
.startup
|| scr
->flags
.startup2
|| scr
->flags
.ignore_focus_events
)
443 if (workspace
!= scr
->current_workspace
)
444 wWorkspaceForceChange(scr
, workspace
);
447 void wWorkspaceRelativeChange(WScreen
* scr
, int amount
)
451 /* While the deiconify animation is going on the window is
452 * still "flying" to its final position and we don't want to
453 * change workspace before the animation finishes, otherwise
454 * the window will land in the new workspace */
455 if (w_global
.ignore_workspace_change
)
458 w
= scr
->current_workspace
+ amount
;
462 wWorkspaceChange(scr
, w
);
463 } else if (wPreferences
.ws_cycle
) {
464 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
466 } else if (amount
> 0) {
467 if (w
< scr
->workspace_count
) {
468 wWorkspaceChange(scr
, w
);
469 } else if (wPreferences
.ws_advance
) {
470 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
- 1));
471 } else if (wPreferences
.ws_cycle
) {
472 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
477 void wWorkspaceForceChange(WScreen
* scr
, int workspace
)
479 WWindow
*tmp
, *foc
= NULL
, *foc2
= NULL
;
481 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
484 if (wPreferences
.enable_workspace_pager
&& !w_global
.process_workspacemap_event
)
485 wWorkspaceMapUpdate(scr
);
487 SendHelperMessage(scr
, 'C', workspace
+ 1, NULL
);
489 if (workspace
> scr
->workspace_count
- 1)
490 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
492 wClipUpdateForWorkspaceChange(scr
, workspace
);
494 scr
->last_workspace
= scr
->current_workspace
;
495 scr
->current_workspace
= workspace
;
497 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
499 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
501 tmp
= scr
->focused_window
;
504 int toUnmapSize
, toUnmapCount
;
506 if ((IS_OMNIPRESENT(tmp
) && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
507 !WFLAGP(tmp
, no_focusable
)) || tmp
->flags
.changing_workspace
) {
513 toUnmap
= wmalloc(toUnmapSize
* sizeof(WWindow
*));
515 /* foc2 = tmp; will fix annoyance with gnome panel
516 * but will create annoyance for every other application
519 if (tmp
->frame
->workspace
!= workspace
&& !tmp
->flags
.selected
) {
520 /* unmap windows not on this workspace */
521 if ((tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
522 !IS_OMNIPRESENT(tmp
) && !tmp
->flags
.changing_workspace
) {
523 if (toUnmapCount
== toUnmapSize
)
526 toUnmap
= wrealloc(toUnmap
, toUnmapSize
* sizeof(WWindow
*));
528 toUnmap
[toUnmapCount
++] = tmp
;
530 /* also unmap miniwindows not on this workspace */
531 if (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
532 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
533 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
534 tmp
->icon
->mapped
= 0;
536 /* update current workspace of omnipresent windows */
537 if (IS_OMNIPRESENT(tmp
)) {
538 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
540 tmp
->frame
->workspace
= workspace
;
543 wapp
->last_workspace
= workspace
;
545 if (!foc2
&& (tmp
->flags
.mapped
|| tmp
->flags
.shaded
)) {
550 /* change selected windows' workspace */
551 if (tmp
->flags
.selected
) {
552 wWindowChangeWorkspace(tmp
, workspace
);
553 if (!tmp
->flags
.miniaturized
&& !foc
) {
557 if (!tmp
->flags
.hidden
) {
558 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
559 /* remap windows that are on this workspace */
561 if (!foc
&& !WFLAGP(tmp
, no_focusable
)) {
565 /* Also map miniwindow if not omnipresent */
566 if (!wPreferences
.sticky_icons
&&
567 tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
568 tmp
->icon
->mapped
= 1;
569 XMapWindow(dpy
, tmp
->icon
->core
->window
);
577 while (toUnmapCount
> 0)
579 wWindowUnmap(toUnmap
[--toUnmapCount
]);
583 /* Gobble up events unleashed by our mapping & unmapping.
584 * These may trigger various grab-initiated focus &
585 * crossing events. However, we don't care about them,
586 * and ignore their focus implications altogether to avoid
589 scr
->flags
.ignore_focus_events
= 1;
590 ProcessPendingEvents();
591 scr
->flags
.ignore_focus_events
= 0;
597 * Check that the window we want to focus still exists, because the application owning it
598 * could decide to unmap/destroy it in response to unmap any of its other window following
599 * the workspace change, this happening during our 'ProcessPendingEvents' loop.
606 for (parse
= scr
->focused_window
; parse
!= NULL
; parse
= parse
->prev
) {
616 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
617 foc
= scr
->focused_window
;
619 if (wPreferences
.focus_mode
== WKF_CLICK
) {
620 wSetFocusTo(scr
, foc
);
628 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
)) {
629 tmp
= wWindowFor(win
);
632 /* If there's a window under the pointer, focus it.
633 * (we ate all other focus events above, so it's
634 * certainly not focused). Otherwise focus last
635 * focused, or the root (depending on sloppiness)
637 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
638 wSetFocusTo(scr
, foc
);
640 wSetFocusTo(scr
, tmp
);
645 /* We need to always arrange icons when changing workspace, even if
646 * no autoarrange icons, because else the icons in different workspaces
648 * This can be avoided if appicons are also workspace specific.
650 if (!wPreferences
.sticky_icons
)
651 wArrangeIcons(scr
, False
);
654 wAppIconPaint(scr
->dock
->icon_array
[0]);
656 if (!wPreferences
.flags
.noclip
&& (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
657 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
)) {
658 /* to handle enter notify. This will also */
659 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
660 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
662 else if (scr
->clip_icon
!= NULL
) {
663 wClipIconPaint(scr
->clip_icon
);
665 wScreenUpdateUsableArea(scr
);
666 wNETWMUpdateDesktop(scr
);
667 showWorkspaceName(scr
, workspace
);
669 WMPostNotificationName(WMNWorkspaceChanged
, scr
, (void *)(uintptr_t) workspace
);
671 /* XSync(dpy, False); */
674 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
676 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
679 static void lastWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
681 /* Parameter not used, but tell the compiler that it is ok */
684 wWorkspaceChange(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->last_workspace
);
687 static void deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
689 /* Parameter not used, but tell the compiler that it is ok */
692 wWorkspaceDelete(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->workspace_count
- 1);
695 static void newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
699 /* Parameter not used, but tell the compiler that it is ok */
702 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
704 /* autochange workspace */
706 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
709 void wWorkspaceRename(WScreen
*scr
, int workspace
, const char *name
)
711 char buf
[MAX_WORKSPACENAME_WIDTH
+ 1];
714 if (workspace
>= scr
->workspace_count
)
717 /* trim white spaces */
718 tmp
= wtrimspace(name
);
720 if (strlen(tmp
) == 0) {
721 snprintf(buf
, sizeof(buf
), _("Workspace %i"), workspace
+ 1);
723 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
725 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
728 /* update workspace */
729 wfree(scr
->workspaces
[workspace
]->name
);
730 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
732 if (scr
->clip_ws_menu
) {
733 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
, buf
) != 0) {
734 wfree(scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
);
735 scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
= wstrdup(buf
);
736 wMenuRealize(scr
->clip_ws_menu
);
739 if (scr
->workspace_menu
) {
740 if (strcmp(scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
, buf
) != 0) {
741 wfree(scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
);
742 scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
= wstrdup(buf
);
743 wMenuRealize(scr
->workspace_menu
);
748 wClipIconPaint(scr
->clip_icon
);
750 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) workspace
);
753 /* callback for when menu entry is edited */
754 static void onMenuEntryEdited(WMenu
* menu
, WMenuEntry
* entry
)
759 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
762 WMenu
*wWorkspaceMenuMake(WScreen
* scr
, Bool titled
)
767 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
769 wwarning(_("could not create Workspace menu"));
773 /* callback to be called when an entry is edited */
774 wsmenu
->on_edit
= onMenuEntryEdited
;
776 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
777 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
779 entry
= wMenuAddCallback(wsmenu
, _("Last Used"), lastWSCommand
, NULL
);
780 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_LASTWORKSPACE
]);
785 void wWorkspaceMenuUpdate(WScreen
* scr
, WMenu
* menu
)
789 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
796 if (menu
->entry_no
< scr
->workspace_count
+ MC_WORKSPACE1
) {
797 /* new workspace(s) added */
798 i
= scr
->workspace_count
- (menu
->entry_no
- MC_WORKSPACE1
);
799 ws
= menu
->entry_no
- MC_WORKSPACE1
;
801 wstrlcpy(title
, scr
->workspaces
[ws
]->name
, MAX_WORKSPACENAME_WIDTH
);
803 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)ws
);
804 entry
->flags
.indicator
= 1;
805 entry
->flags
.editable
= 1;
810 } else if (menu
->entry_no
> scr
->workspace_count
+ MC_WORKSPACE1
) {
811 /* removed workspace(s) */
812 for (i
= menu
->entry_no
- 1; i
>= scr
->workspace_count
+ MC_WORKSPACE1
; i
--)
813 wMenuRemoveItem(menu
, i
);
816 for (i
= 0; i
< scr
->workspace_count
; i
++) {
817 /* workspace shortcut labels */
818 if (i
/ 10 == scr
->current_workspace
/ 10)
819 menu
->entries
[i
+ MC_WORKSPACE1
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_WORKSPACE1
+ (i
% 10)]);
821 menu
->entries
[i
+ MC_WORKSPACE1
]->rtext
= NULL
;
823 menu
->entries
[i
+ MC_WORKSPACE1
]->flags
.indicator_on
= 0;
825 menu
->entries
[scr
->current_workspace
+ MC_WORKSPACE1
]->flags
.indicator_on
= 1;
828 /* don't let user destroy current workspace */
829 if (scr
->current_workspace
== scr
->workspace_count
- 1)
830 wMenuSetEnabled(menu
, MC_DESTROY_LAST
, False
);
832 wMenuSetEnabled(menu
, MC_DESTROY_LAST
, True
);
834 /* back to last workspace */
835 if (scr
->workspace_count
&& scr
->last_workspace
!= scr
->current_workspace
)
836 wMenuSetEnabled(menu
, MC_LAST_USED
, True
);
838 wMenuSetEnabled(menu
, MC_LAST_USED
, False
);
840 tmp
= menu
->frame
->top_width
+ 5;
841 /* if menu got unreachable, bring it to a visible place */
842 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
843 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
848 void wWorkspaceSaveState(WScreen
* scr
, WMPropList
* old_state
)
850 WMPropList
*parr
, *pstr
, *wks_state
, *old_wks_state
, *foo
, *bar
;
855 old_wks_state
= WMGetFromPLDictionary(old_state
, dWorkspaces
);
856 parr
= WMCreatePLArray(NULL
);
857 for (i
= 0; i
< scr
->workspace_count
; i
++) {
858 pstr
= WMCreatePLString(scr
->workspaces
[i
]->name
);
859 wks_state
= WMCreatePLDictionary(dName
, pstr
, NULL
);
860 WMReleasePropList(pstr
);
861 if (!wPreferences
.flags
.noclip
) {
862 pstr
= wClipSaveWorkspaceState(scr
, i
);
863 WMPutInPLDictionary(wks_state
, dClip
, pstr
);
864 WMReleasePropList(pstr
);
865 } else if (old_wks_state
!= NULL
) {
866 foo
= WMGetFromPLArray(old_wks_state
, i
);
868 bar
= WMGetFromPLDictionary(foo
, dClip
);
870 WMPutInPLDictionary(wks_state
, dClip
, bar
);
873 WMAddToPLArray(parr
, wks_state
);
874 WMReleasePropList(wks_state
);
876 WMPutInPLDictionary(scr
->session_state
, dWorkspaces
, parr
);
877 WMReleasePropList(parr
);
880 void wWorkspaceRestoreState(WScreen
*scr
)
882 WMPropList
*parr
, *pstr
, *wks_state
, *clip_state
;
887 if (scr
->session_state
== NULL
)
890 parr
= WMGetFromPLDictionary(scr
->session_state
, dWorkspaces
);
895 for (i
= 0; i
< WMIN(WMGetPropListItemCount(parr
), MAX_WORKSPACES
); i
++) {
896 wks_state
= WMGetFromPLArray(parr
, i
);
897 if (WMIsPLDictionary(wks_state
))
898 pstr
= WMGetFromPLDictionary(wks_state
, dName
);
902 if (i
>= scr
->workspace_count
)
905 if (scr
->workspace_menu
) {
906 wfree(scr
->workspace_menu
->entries
[i
+ MC_WORKSPACE1
]->text
);
907 scr
->workspace_menu
->entries
[i
+ MC_WORKSPACE1
]->text
= wstrdup(WMGetFromPLString(pstr
));
908 scr
->workspace_menu
->flags
.realized
= 0;
911 wfree(scr
->workspaces
[i
]->name
);
912 scr
->workspaces
[i
]->name
= wstrdup(WMGetFromPLString(pstr
));
913 if (!wPreferences
.flags
.noclip
) {
914 int added_omnipresent_icons
= 0;
916 clip_state
= WMGetFromPLDictionary(wks_state
, dClip
);
917 if (scr
->workspaces
[i
]->clip
)
918 wDockDestroy(scr
->workspaces
[i
]->clip
);
920 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
, WM_CLIP
);
922 wDockHideIcons(scr
->workspaces
[i
]->clip
);
924 /* We set the global icons here, because scr->workspaces[i]->clip
925 * was not valid in wDockRestoreState().
926 * There we only set icon->omnipresent to know which icons we
929 for (j
= 0; j
< scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
930 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
933 if (!aicon
|| !aicon
->omnipresent
)
935 aicon
->omnipresent
= 0;
936 if (wClipMakeIconOmnipresent(aicon
, True
) != WO_SUCCESS
)
941 /* Move this appicon from workspace i to workspace 0 */
942 scr
->workspaces
[i
]->clip
->icon_array
[j
] = NULL
;
943 scr
->workspaces
[i
]->clip
->icon_count
--;
945 added_omnipresent_icons
++;
946 /* If there are too many omnipresent appicons, we are in trouble */
947 assert(scr
->workspaces
[0]->clip
->icon_count
+ added_omnipresent_icons
948 <= scr
->workspaces
[0]->clip
->max_icons
);
949 /* Find first free spot on workspace 0 */
950 for (k
= 0; k
< scr
->workspaces
[0]->clip
->max_icons
; k
++)
951 if (scr
->workspaces
[0]->clip
->icon_array
[k
] == NULL
)
953 scr
->workspaces
[0]->clip
->icon_array
[k
] = aicon
;
954 aicon
->dock
= scr
->workspaces
[0]->clip
;
956 scr
->workspaces
[0]->clip
->icon_count
+= added_omnipresent_icons
;
959 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) i
);
963 /* Returns the workspace number for a given workspace name */
964 int wGetWorkspaceNumber(WScreen
*scr
, const char *value
)
968 if (sscanf(value
, "%i", &w
) != 1) {
970 for (i
= 0; i
< scr
->workspace_count
; i
++) {
971 if (strcmp(scr
->workspaces
[i
]->name
, value
) == 0) {