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"
55 #define MC_DESTROY_LAST 1
56 #define MC_LAST_USED 2
57 /* index of the first workspace menu entry */
58 #define MC_WORKSPACE1 3
60 #define WORKSPACE_NAME_DISPLAY_PADDING 32
62 static WMPropList
*dWorkspaces
= NULL
;
63 static WMPropList
*dClip
, *dName
;
65 static void make_keys(void)
67 if (dWorkspaces
!= NULL
)
70 dWorkspaces
= WMCreatePLString("Workspaces");
71 dName
= WMCreatePLString("Name");
72 dClip
= WMCreatePLString("Clip");
75 void wWorkspaceMake(WScreen
* scr
, int count
)
83 int wWorkspaceNew(WScreen
*scr
)
85 WWorkspace
*wspace
, **list
;
88 if (scr
->workspace_count
< MAX_WORKSPACES
) {
89 scr
->workspace_count
++;
91 wspace
= wmalloc(sizeof(WWorkspace
));
96 static const char *new_name
= NULL
;
97 static size_t name_length
;
99 if (new_name
== NULL
) {
100 new_name
= _("Workspace %i");
101 name_length
= strlen(new_name
) + 8;
103 wspace
->name
= wmalloc(name_length
);
104 snprintf(wspace
->name
, name_length
, new_name
, scr
->workspace_count
);
107 if (!wPreferences
.flags
.noclip
)
108 wspace
->clip
= wDockCreate(scr
, WM_CLIP
, NULL
);
110 list
= wmalloc(sizeof(WWorkspace
*) * scr
->workspace_count
);
112 for (i
= 0; i
< scr
->workspace_count
- 1; i
++)
113 list
[i
] = scr
->workspaces
[i
];
117 wfree(scr
->workspaces
);
119 scr
->workspaces
= list
;
121 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
122 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
123 wNETWMUpdateDesktop(scr
);
124 WMPostNotificationName(WMNWorkspaceCreated
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
127 return scr
->workspace_count
- 1;
133 Bool
wWorkspaceDelete(WScreen
* scr
, int workspace
)
142 /* verify if workspace is in use by some window */
143 tmp
= scr
->focused_window
;
145 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
== workspace
) {
147 snprintf(buf
, sizeof(buf
), _("Workspace \"%s\" in use; cannot delete"),
148 scr
->workspaces
[workspace
]->name
);
149 wMessageDialog(scr
, _("Error"), buf
, _("OK"), NULL
, NULL
);
155 if (!wPreferences
.flags
.noclip
) {
156 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
157 scr
->workspaces
[workspace
]->clip
= NULL
;
160 list
= wmalloc(sizeof(WWorkspace
*) * (scr
->workspace_count
- 1));
162 for (i
= 0; i
< scr
->workspace_count
; i
++) {
163 if (i
!= workspace
) {
164 list
[j
++] = scr
->workspaces
[i
];
166 if (scr
->workspaces
[i
]->name
)
167 wfree(scr
->workspaces
[i
]->name
);
168 if (scr
->workspaces
[i
]->map
)
169 RReleaseImage(scr
->workspaces
[i
]->map
);
170 wfree(scr
->workspaces
[i
]);
173 wfree(scr
->workspaces
);
174 scr
->workspaces
= list
;
176 scr
->workspace_count
--;
179 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
180 /* clip workspace menu */
181 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
183 /* update also window menu */
184 if (scr
->workspace_submenu
) {
185 WMenu
*menu
= scr
->workspace_submenu
;
188 while (i
> scr
->workspace_count
)
189 wMenuRemoveItem(menu
, --i
);
193 if (scr
->clip_submenu
) {
194 WMenu
*menu
= scr
->clip_submenu
;
197 while (i
> scr
->workspace_count
)
198 wMenuRemoveItem(menu
, --i
);
201 wNETWMUpdateDesktop(scr
);
202 WMPostNotificationName(WMNWorkspaceDestroyed
, scr
, (void *)(uintptr_t) (scr
->workspace_count
- 1));
204 if (scr
->current_workspace
>= scr
->workspace_count
)
205 wWorkspaceChange(scr
, scr
->workspace_count
- 1);
206 if (scr
->last_workspace
>= scr
->workspace_count
)
207 scr
->last_workspace
= 0;
212 typedef struct WorkspaceNameData
{
219 static void hideWorkspaceName(void *data
)
221 WScreen
*scr
= (WScreen
*) data
;
223 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
224 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
225 XUnmapWindow(dpy
, scr
->workspace_name
);
227 if (scr
->workspace_name_data
) {
228 RReleaseImage(scr
->workspace_name_data
->back
);
229 RReleaseImage(scr
->workspace_name_data
->text
);
230 wfree(scr
->workspace_name_data
);
232 scr
->workspace_name_data
= NULL
;
234 scr
->workspace_name_timer
= NULL
;
236 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
239 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
241 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
242 scr
->workspace_name_data
->count
* 255 / 10);
244 RConvertImage(scr
->rcontext
, img
, &pix
);
248 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
249 XClearWindow(dpy
, scr
->workspace_name
);
250 XFreePixmap(dpy
, pix
);
253 scr
->workspace_name_data
->count
--;
257 static void showWorkspaceName(WScreen
* scr
, int workspace
)
259 WorkspaceNameData
*data
;
264 char *name
= scr
->workspaces
[workspace
]->name
;
265 int len
= strlen(name
);
273 if (wPreferences
.workspace_name_display_position
== WD_NONE
|| scr
->workspace_count
< 2)
276 if (scr
->workspace_name_timer
) {
277 WMDeleteTimerHandler(scr
->workspace_name_timer
);
278 XUnmapWindow(dpy
, scr
->workspace_name
);
281 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
, hideWorkspaceName
, scr
);
283 if (scr
->workspace_name_data
) {
284 RReleaseImage(scr
->workspace_name_data
->back
);
285 RReleaseImage(scr
->workspace_name_data
->text
);
286 wfree(scr
->workspace_name_data
);
289 data
= wmalloc(sizeof(WorkspaceNameData
));
292 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
293 h
= WMFontHeight(scr
->workspace_name_font
);
296 head
= wGetHeadForPointerLocation(scr
);
297 rect
= wGetRectForHead(scr
, head
);
298 if (scr
->xine_info
.count
) {
299 xx
= rect
.pos
.x
+ (scr
->xine_info
.screens
[head
].size
.width
- (w
+ 4)) / 2;
300 yy
= rect
.pos
.y
+ (scr
->xine_info
.screens
[head
].size
.height
- (h
+ 4)) / 2;
303 xx
= (scr
->scr_width
- (w
+ 4)) / 2;
304 yy
= (scr
->scr_height
- (h
+ 4)) / 2;
308 switch (wPreferences
.workspace_name_display_position
) {
313 px
= (scr
->scr_width
- (w
+ 4)) / 2;
315 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
321 px
= (scr
->scr_width
- (w
+ 4)) / 2;
323 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
326 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
327 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
330 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
331 py
= WORKSPACE_NAME_DISPLAY_PADDING
;
334 px
= WORKSPACE_NAME_DISPLAY_PADDING
;
335 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
338 px
= scr
->scr_width
- (w
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
339 py
= scr
->scr_height
- (h
+ 4 + WORKSPACE_NAME_DISPLAY_PADDING
);
347 px
= (scr
->scr_width
- (w
+ 4)) / 2;
348 py
= (scr
->scr_height
- (h
+ 4)) / 2;
352 XResizeWindow(dpy
, scr
->workspace_name
, w
+ 4, h
+ 4);
353 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
355 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, scr
->w_depth
);
356 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+ 4, h
+ 4, 1);
358 /*XSetForeground(dpy, scr->mono_gc, 0);
359 XFillRectangle(dpy, mask, scr->mono_gc, 0, 0, w+4, h+4); */
361 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
363 for (x
= 0; x
<= 4; x
++)
364 for (y
= 0; y
<= 4; y
++)
365 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, x
, y
, name
, len
);
367 XSetForeground(dpy
, scr
->mono_gc
, 1);
368 XSetBackground(dpy
, scr
->mono_gc
, 0);
370 XCopyPlane(dpy
, text
, mask
, scr
->mono_gc
, 0, 0, w
+ 4, h
+ 4, 0, 0, 1 << (scr
->w_depth
- 1));
372 /*XSetForeground(dpy, scr->mono_gc, 1); */
373 XSetBackground(dpy
, scr
->mono_gc
, 1);
375 XFillRectangle(dpy
, text
, WMColorGC(scr
->black
), 0, 0, w
+ 4, h
+ 4);
377 WMDrawString(scr
->wmscreen
, text
, scr
->white
, scr
->workspace_name_font
, 2, 2, name
, len
);
380 if (w_global
.xext
.shape
.supported
)
381 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
, ShapeSet
);
383 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
384 XClearWindow(dpy
, scr
->workspace_name
);
386 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
388 XFreePixmap(dpy
, text
);
389 XFreePixmap(dpy
, mask
);
392 XMapRaised(dpy
, scr
->workspace_name
);
398 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
, data
->text
->width
, data
->text
->height
);
402 XMapRaised(dpy
, scr
->workspace_name
);
405 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
406 RDestroyXImage(scr
->rcontext
, ximg
);
414 /* set a timeout for the effect */
415 data
->timeout
= time(NULL
) + 2 + (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
* data
->count
) / 1000;
417 scr
->workspace_name_data
= data
;
422 if (scr
->workspace_name_timer
)
423 WMDeleteTimerHandler(scr
->workspace_name_timer
);
426 RReleaseImage(data
->text
);
428 RReleaseImage(data
->back
);
431 scr
->workspace_name_data
= NULL
;
433 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
434 10 * WORKSPACE_NAME_FADE_DELAY
, hideWorkspaceName
, scr
);
437 void wWorkspaceChange(WScreen
*scr
, int workspace
)
439 if (scr
->flags
.startup
|| scr
->flags
.startup2
|| scr
->flags
.ignore_focus_events
)
442 if (workspace
!= scr
->current_workspace
)
443 wWorkspaceForceChange(scr
, workspace
);
446 void wWorkspaceRelativeChange(WScreen
* scr
, int amount
)
450 /* While the deiconify animation is going on the window is
451 * still "flying" to its final position and we don't want to
452 * change workspace before the animation finishes, otherwise
453 * the window will land in the new workspace */
454 if (w_global
.ignore_workspace_change
)
457 w
= scr
->current_workspace
+ amount
;
461 wWorkspaceChange(scr
, w
);
462 } else if (wPreferences
.ws_cycle
) {
463 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
465 } else if (amount
> 0) {
466 if (w
< scr
->workspace_count
) {
467 wWorkspaceChange(scr
, w
);
468 } else if (wPreferences
.ws_advance
) {
469 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
- 1));
470 } else if (wPreferences
.ws_cycle
) {
471 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
476 void wWorkspaceForceChange(WScreen
* scr
, int workspace
)
478 WWindow
*tmp
, *foc
= NULL
, *foc2
= NULL
;
480 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
483 if (wPreferences
.enable_workspace_pager
&& !w_global
.process_workspacemap_event
)
484 wWorkspaceMapUpdate(scr
);
486 SendHelperMessage(scr
, 'C', workspace
+ 1, NULL
);
488 if (workspace
> scr
->workspace_count
- 1)
489 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
491 wClipUpdateForWorkspaceChange(scr
, workspace
);
493 scr
->last_workspace
= scr
->current_workspace
;
494 scr
->current_workspace
= workspace
;
496 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
498 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
500 tmp
= scr
->focused_window
;
503 int toUnmapSize
, toUnmapCount
;
505 if ((IS_OMNIPRESENT(tmp
) && (tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
506 !WFLAGP(tmp
, no_focusable
)) || tmp
->flags
.changing_workspace
) {
512 toUnmap
= wmalloc(toUnmapSize
* sizeof(WWindow
*));
514 /* foc2 = tmp; will fix annoyance with gnome panel
515 * but will create annoyance for every other application
518 if (tmp
->frame
->workspace
!= workspace
&& !tmp
->flags
.selected
) {
519 /* unmap windows not on this workspace */
520 if ((tmp
->flags
.mapped
|| tmp
->flags
.shaded
) &&
521 !IS_OMNIPRESENT(tmp
) && !tmp
->flags
.changing_workspace
) {
522 if (toUnmapCount
== toUnmapSize
)
525 toUnmap
= wrealloc(toUnmap
, toUnmapSize
* sizeof(WWindow
*));
527 toUnmap
[toUnmapCount
++] = tmp
;
529 /* also unmap miniwindows not on this workspace */
530 if (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
531 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
532 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
533 tmp
->icon
->mapped
= 0;
535 /* update current workspace of omnipresent windows */
536 if (IS_OMNIPRESENT(tmp
)) {
537 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
539 tmp
->frame
->workspace
= workspace
;
542 wapp
->last_workspace
= workspace
;
544 if (!foc2
&& (tmp
->flags
.mapped
|| tmp
->flags
.shaded
)) {
549 /* change selected windows' workspace */
550 if (tmp
->flags
.selected
) {
551 wWindowChangeWorkspace(tmp
, workspace
);
552 if (!tmp
->flags
.miniaturized
&& !foc
) {
556 if (!tmp
->flags
.hidden
) {
557 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
558 /* remap windows that are on this workspace */
560 if (!foc
&& !WFLAGP(tmp
, no_focusable
)) {
564 /* Also map miniwindow if not omnipresent */
565 if (!wPreferences
.sticky_icons
&&
566 tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
567 tmp
->icon
->mapped
= 1;
568 XMapWindow(dpy
, tmp
->icon
->core
->window
);
576 while (toUnmapCount
> 0)
578 wWindowUnmap(toUnmap
[--toUnmapCount
]);
582 /* Gobble up events unleashed by our mapping & unmapping.
583 * These may trigger various grab-initiated focus &
584 * crossing events. However, we don't care about them,
585 * and ignore their focus implications altogether to avoid
588 scr
->flags
.ignore_focus_events
= 1;
589 ProcessPendingEvents();
590 scr
->flags
.ignore_focus_events
= 0;
596 * Check that the window we want to focus still exists, because the application owning it
597 * could decide to unmap/destroy it in response to unmap any of its other window following
598 * the workspace change, this happening during our 'ProcessPendingEvents' loop.
605 for (parse
= scr
->focused_window
; parse
!= NULL
; parse
= parse
->prev
) {
615 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
616 foc
= scr
->focused_window
;
618 if (wPreferences
.focus_mode
== WKF_CLICK
) {
619 wSetFocusTo(scr
, foc
);
627 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
, &foo
, &foo
, &foo
, &foo
, &mask
)) {
628 tmp
= wWindowFor(win
);
631 /* If there's a window under the pointer, focus it.
632 * (we ate all other focus events above, so it's
633 * certainly not focused). Otherwise focus last
634 * focused, or the root (depending on sloppiness)
636 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
637 wSetFocusTo(scr
, foc
);
639 wSetFocusTo(scr
, tmp
);
644 /* We need to always arrange icons when changing workspace, even if
645 * no autoarrange icons, because else the icons in different workspaces
647 * This can be avoided if appicons are also workspace specific.
649 if (!wPreferences
.sticky_icons
)
650 wArrangeIcons(scr
, False
);
653 wAppIconPaint(scr
->dock
->icon_array
[0]);
655 if (!wPreferences
.flags
.noclip
&& (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
656 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
)) {
657 /* to handle enter notify. This will also */
658 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
659 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
661 else if (scr
->clip_icon
!= NULL
) {
662 wClipIconPaint(scr
->clip_icon
);
664 wScreenUpdateUsableArea(scr
);
665 wNETWMUpdateDesktop(scr
);
666 showWorkspaceName(scr
, workspace
);
668 WMPostNotificationName(WMNWorkspaceChanged
, scr
, (void *)(uintptr_t) workspace
);
670 /* XSync(dpy, False); */
673 static void switchWSCommand(WMenu
* menu
, WMenuEntry
* entry
)
675 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
678 static void lastWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
680 /* Parameter not used, but tell the compiler that it is ok */
683 wWorkspaceChange(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->last_workspace
);
686 static void deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
688 /* Parameter not used, but tell the compiler that it is ok */
691 wWorkspaceDelete(menu
->frame
->screen_ptr
, menu
->frame
->screen_ptr
->workspace_count
- 1);
694 static void newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
698 /* Parameter not used, but tell the compiler that it is ok */
701 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
703 /* autochange workspace */
705 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
708 void wWorkspaceRename(WScreen
*scr
, int workspace
, const char *name
)
710 char buf
[MAX_WORKSPACENAME_WIDTH
+ 1];
713 if (workspace
>= scr
->workspace_count
)
716 /* trim white spaces */
717 tmp
= wtrimspace(name
);
719 if (strlen(tmp
) == 0) {
720 snprintf(buf
, sizeof(buf
), _("Workspace %i"), workspace
+ 1);
722 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
724 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
727 /* update workspace */
728 wfree(scr
->workspaces
[workspace
]->name
);
729 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
731 if (scr
->clip_ws_menu
) {
732 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
, buf
) != 0) {
733 wfree(scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
);
734 scr
->clip_ws_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
= wstrdup(buf
);
735 wMenuRealize(scr
->clip_ws_menu
);
738 if (scr
->workspace_menu
) {
739 if (strcmp(scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
, buf
) != 0) {
740 wfree(scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
);
741 scr
->workspace_menu
->entries
[workspace
+ MC_WORKSPACE1
]->text
= wstrdup(buf
);
742 wMenuRealize(scr
->workspace_menu
);
747 wClipIconPaint(scr
->clip_icon
);
749 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) workspace
);
752 /* callback for when menu entry is edited */
753 static void onMenuEntryEdited(WMenu
* menu
, WMenuEntry
* entry
)
758 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
761 WMenu
*wWorkspaceMenuMake(WScreen
* scr
, Bool titled
)
766 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
768 wwarning(_("could not create Workspace menu"));
772 /* callback to be called when an entry is edited */
773 wsmenu
->on_edit
= onMenuEntryEdited
;
775 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
776 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
778 entry
= wMenuAddCallback(wsmenu
, _("Last Used"), lastWSCommand
, NULL
);
779 entry
->rtext
= GetShortcutKey(wKeyBindings
[WKBD_LASTWORKSPACE
]);
784 void wWorkspaceMenuUpdate(WScreen
* scr
, WMenu
* menu
)
788 char title
[MAX_WORKSPACENAME_WIDTH
+ 1];
795 if (menu
->entry_no
< scr
->workspace_count
+ MC_WORKSPACE1
) {
796 /* new workspace(s) added */
797 i
= scr
->workspace_count
- (menu
->entry_no
- MC_WORKSPACE1
);
798 ws
= menu
->entry_no
- MC_WORKSPACE1
;
800 wstrlcpy(title
, scr
->workspaces
[ws
]->name
, MAX_WORKSPACENAME_WIDTH
);
802 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void *)ws
);
803 entry
->flags
.indicator
= 1;
804 entry
->flags
.editable
= 1;
809 } else if (menu
->entry_no
> scr
->workspace_count
+ MC_WORKSPACE1
) {
810 /* removed workspace(s) */
811 for (i
= menu
->entry_no
- 1; i
>= scr
->workspace_count
+ MC_WORKSPACE1
; i
--)
812 wMenuRemoveItem(menu
, i
);
815 for (i
= 0; i
< scr
->workspace_count
; i
++) {
816 /* workspace shortcut labels */
817 if (i
/ 10 == scr
->current_workspace
/ 10)
818 menu
->entries
[i
+ MC_WORKSPACE1
]->rtext
= GetShortcutKey(wKeyBindings
[WKBD_WORKSPACE1
+ (i
% 10)]);
820 menu
->entries
[i
+ MC_WORKSPACE1
]->rtext
= NULL
;
822 menu
->entries
[i
+ MC_WORKSPACE1
]->flags
.indicator_on
= 0;
824 menu
->entries
[scr
->current_workspace
+ MC_WORKSPACE1
]->flags
.indicator_on
= 1;
827 /* don't let user destroy current workspace */
828 if (scr
->current_workspace
== scr
->workspace_count
- 1)
829 wMenuSetEnabled(menu
, MC_DESTROY_LAST
, False
);
831 wMenuSetEnabled(menu
, MC_DESTROY_LAST
, True
);
833 /* back to last workspace */
834 if (scr
->workspace_count
&& scr
->last_workspace
!= scr
->current_workspace
)
835 wMenuSetEnabled(menu
, MC_LAST_USED
, True
);
837 wMenuSetEnabled(menu
, MC_LAST_USED
, False
);
839 tmp
= menu
->frame
->top_width
+ 5;
840 /* if menu got unreachable, bring it to a visible place */
841 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
842 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
847 void wWorkspaceSaveState(WScreen
* scr
, WMPropList
* old_state
)
849 WMPropList
*parr
, *pstr
, *wks_state
, *old_wks_state
, *foo
, *bar
;
854 old_wks_state
= WMGetFromPLDictionary(old_state
, dWorkspaces
);
855 parr
= WMCreatePLArray(NULL
);
856 for (i
= 0; i
< scr
->workspace_count
; i
++) {
857 pstr
= WMCreatePLString(scr
->workspaces
[i
]->name
);
858 wks_state
= WMCreatePLDictionary(dName
, pstr
, NULL
);
859 WMReleasePropList(pstr
);
860 if (!wPreferences
.flags
.noclip
) {
861 pstr
= wClipSaveWorkspaceState(scr
, i
);
862 WMPutInPLDictionary(wks_state
, dClip
, pstr
);
863 WMReleasePropList(pstr
);
864 } else if (old_wks_state
!= NULL
) {
865 foo
= WMGetFromPLArray(old_wks_state
, i
);
867 bar
= WMGetFromPLDictionary(foo
, dClip
);
869 WMPutInPLDictionary(wks_state
, dClip
, bar
);
872 WMAddToPLArray(parr
, wks_state
);
873 WMReleasePropList(wks_state
);
875 WMPutInPLDictionary(scr
->session_state
, dWorkspaces
, parr
);
876 WMReleasePropList(parr
);
879 void wWorkspaceRestoreState(WScreen
*scr
)
881 WMPropList
*parr
, *pstr
, *wks_state
, *clip_state
;
886 if (scr
->session_state
== NULL
)
889 parr
= WMGetFromPLDictionary(scr
->session_state
, dWorkspaces
);
894 for (i
= 0; i
< WMIN(WMGetPropListItemCount(parr
), MAX_WORKSPACES
); i
++) {
895 wks_state
= WMGetFromPLArray(parr
, i
);
896 if (WMIsPLDictionary(wks_state
))
897 pstr
= WMGetFromPLDictionary(wks_state
, dName
);
901 if (i
>= scr
->workspace_count
)
904 if (scr
->workspace_menu
) {
905 wfree(scr
->workspace_menu
->entries
[i
+ MC_WORKSPACE1
]->text
);
906 scr
->workspace_menu
->entries
[i
+ MC_WORKSPACE1
]->text
= wstrdup(WMGetFromPLString(pstr
));
907 scr
->workspace_menu
->flags
.realized
= 0;
910 wfree(scr
->workspaces
[i
]->name
);
911 scr
->workspaces
[i
]->name
= wstrdup(WMGetFromPLString(pstr
));
912 if (!wPreferences
.flags
.noclip
) {
913 int added_omnipresent_icons
= 0;
915 clip_state
= WMGetFromPLDictionary(wks_state
, dClip
);
916 if (scr
->workspaces
[i
]->clip
)
917 wDockDestroy(scr
->workspaces
[i
]->clip
);
919 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
, WM_CLIP
);
921 wDockHideIcons(scr
->workspaces
[i
]->clip
);
923 /* We set the global icons here, because scr->workspaces[i]->clip
924 * was not valid in wDockRestoreState().
925 * There we only set icon->omnipresent to know which icons we
928 for (j
= 0; j
< scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
929 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
932 if (!aicon
|| !aicon
->omnipresent
)
934 aicon
->omnipresent
= 0;
935 if (wClipMakeIconOmnipresent(aicon
, True
) != WO_SUCCESS
)
940 /* Move this appicon from workspace i to workspace 0 */
941 scr
->workspaces
[i
]->clip
->icon_array
[j
] = NULL
;
942 scr
->workspaces
[i
]->clip
->icon_count
--;
944 added_omnipresent_icons
++;
945 /* If there are too many omnipresent appicons, we are in trouble */
946 assert(scr
->workspaces
[0]->clip
->icon_count
+ added_omnipresent_icons
947 <= scr
->workspaces
[0]->clip
->max_icons
);
948 /* Find first free spot on workspace 0 */
949 for (k
= 0; k
< scr
->workspaces
[0]->clip
->max_icons
; k
++)
950 if (scr
->workspaces
[0]->clip
->icon_array
[k
] == NULL
)
952 scr
->workspaces
[0]->clip
->icon_array
[k
] = aicon
;
953 aicon
->dock
= scr
->workspaces
[0]->clip
;
955 scr
->workspaces
[0]->clip
->icon_count
+= added_omnipresent_icons
;
958 WMPostNotificationName(WMNWorkspaceNameChanged
, scr
, (void *)(uintptr_t) i
);
962 /* Returns the workspace number for a given workspace name */
963 int wGetWorkspaceNumber(WScreen
*scr
, const char *value
)
967 if (sscanf(value
, "%i", &w
) != 1) {
969 for (i
= 0; i
< scr
->workspace_count
; i
++) {
970 if (strcmp(scr
->workspaces
[i
]->name
, value
) == 0) {