1 /* workspace.c- Workspace management
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 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>
37 #include "WindowMaker.h"
44 #include "application.h"
47 #include "workspace.h"
59 extern WPreferences wPreferences
;
60 extern XContext wWinContext
;
63 static proplist_t dWorkspaces
=NULL
;
64 static proplist_t dClip
, dName
;
66 #ifdef VIRTUAL_DESKTOP
67 static BOOL initVDesk
=False
;
73 if (dWorkspaces
!=NULL
)
76 dWorkspaces
= PLMakeString("Workspaces");
77 dName
= PLMakeString("Name");
78 dClip
= PLMakeString("Clip");
83 wWorkspaceMake(WScreen
*scr
, int count
)
93 wWorkspaceNew(WScreen
*scr
)
95 WWorkspace
*wspace
, **list
;
98 if (scr
->workspace_count
< MAX_WORKSPACES
) {
99 scr
->workspace_count
++;
101 wspace
= wmalloc(sizeof(WWorkspace
));
105 if (scr
->flags
.kwm_syncing_count
) {
106 wspace
->name
= wKWMGetWorkspaceName(scr
, scr
->workspace_count
-1);
110 wspace
->name
= wmalloc(strlen(_("Workspace %i"))+8);
111 sprintf(wspace
->name
, _("Workspace %i"), scr
->workspace_count
);
115 if (!wPreferences
.flags
.noclip
) {
116 wspace
->clip
= wDockCreate(scr
, WM_CLIP
);
120 list
= wmalloc(sizeof(WWorkspace
*)*scr
->workspace_count
);
122 for (i
=0; i
<scr
->workspace_count
-1; i
++) {
123 list
[i
] = scr
->workspaces
[i
];
127 free(scr
->workspaces
);
128 scr
->workspaces
= list
;
130 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
131 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
133 wGNOMEUpdateWorkspaceHints(scr
);
136 if (!scr
->flags
.kwm_syncing_count
) {
137 wKWMUpdateWorkspaceCountHint(scr
);
138 wKWMUpdateWorkspaceNameHint(scr
, scr
->workspace_count
-1);
141 wKWMSetUsableAreaHint(scr
, scr
->workspace_count
-1);
146 return scr
->workspace_count
-1;
154 wWorkspaceDelete(WScreen
*scr
, int workspace
)
164 /* verify if workspace is in use by some window */
165 tmp
= scr
->focused_window
;
167 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
==workspace
)
172 if (!wPreferences
.flags
.noclip
) {
173 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
174 scr
->workspaces
[workspace
]->clip
= NULL
;
177 list
= wmalloc(sizeof(WWorkspace
*)*(scr
->workspace_count
-1));
179 for (i
=0; i
<scr
->workspace_count
; i
++) {
181 list
[j
++] = scr
->workspaces
[i
];
183 if (scr
->workspaces
[i
]->name
)
184 free(scr
->workspaces
[i
]->name
);
185 free(scr
->workspaces
[i
]);
188 free(scr
->workspaces
);
189 scr
->workspaces
= list
;
191 scr
->workspace_count
--;
195 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
196 /* clip workspace menu */
197 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
199 /* update also window menu */
200 if (scr
->workspace_submenu
) {
201 WMenu
*menu
= scr
->workspace_submenu
;
204 while (i
>scr
->workspace_count
)
205 wMenuRemoveItem(menu
, --i
);
209 if (scr
->clip_submenu
) {
210 WMenu
*menu
= scr
->clip_submenu
;
213 while (i
>scr
->workspace_count
)
214 wMenuRemoveItem(menu
, --i
);
219 wGNOMEUpdateWorkspaceHints(scr
);
222 wKWMUpdateWorkspaceCountHint(scr
);
225 if (scr
->current_workspace
>= scr
->workspace_count
)
226 wWorkspaceChange(scr
, scr
->workspace_count
-1);
232 typedef struct WorkspaceNameData
{
242 hideWorkpaceName(void *data
)
244 WScreen
*scr
= (WScreen
*)data
;
246 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
247 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
248 XUnmapWindow(dpy
, scr
->workspace_name
);
250 if (scr
->workspace_name_data
) {
251 RDestroyImage(scr
->workspace_name_data
->back
);
252 RDestroyImage(scr
->workspace_name_data
->text
);
253 free(scr
->workspace_name_data
);
255 scr
->workspace_name_data
= NULL
;
257 scr
->workspace_name_timer
= NULL
;
259 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
262 scr
->workspace_name_timer
=
263 WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkpaceName
,
266 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
267 scr
->workspace_name_data
->count
*255/10);
269 RConvertImage(scr
->rcontext
, img
, &pix
);
273 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
274 XClearWindow(dpy
, scr
->workspace_name
);
275 XFreePixmap(dpy
, pix
);
278 scr
->workspace_name_data
->count
--;
285 showWorkspaceName(WScreen
*scr
, int workspace
)
287 WorkspaceNameData
*data
;
292 char *name
= scr
->workspaces
[workspace
]->name
;
293 int len
= strlen(name
);
296 if (wPreferences
.workspace_name_display_position
== WD_NONE
297 || scr
->workspace_count
< 2)
300 if (scr
->workspace_name_timer
) {
301 WMDeleteTimerHandler(scr
->workspace_name_timer
);
302 XUnmapWindow(dpy
, scr
->workspace_name
);
305 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
,
306 hideWorkpaceName
, scr
);
308 if (scr
->workspace_name_data
) {
309 RDestroyImage(scr
->workspace_name_data
->back
);
310 RDestroyImage(scr
->workspace_name_data
->text
);
311 free(scr
->workspace_name_data
);
314 data
= wmalloc(sizeof(WorkspaceNameData
));
316 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
317 h
= WMFontHeight(scr
->workspace_name_font
);
319 switch (wPreferences
.workspace_name_display_position
) {
321 px
= (scr
->scr_width
- (w
+4))/2;
325 px
= (scr
->scr_width
- (w
+4))/2;
326 py
= scr
->scr_height
- (h
+4);
333 px
= scr
->scr_width
- (w
+4);
338 py
= scr
->scr_height
- (h
+4);
341 px
= scr
->scr_width
- (w
+4);
342 py
= scr
->scr_height
- (h
+4);
346 px
= (scr
->scr_width
- (w
+4))/2;
347 py
= (scr
->scr_height
- (h
+4))/2;
350 XResizeWindow(dpy
, scr
->workspace_name
, w
+4, h
+4);
351 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
353 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+4, h
+4, scr
->w_depth
);
354 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+4, h
+4, 1);
356 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
357 XFillRectangle(dpy
, text
, scr
->draw_gc
, 0, 0, w
+4, h
+4);
359 XSetForeground(dpy
, scr
->mono_gc
, 0);
360 XFillRectangle(dpy
, mask
, scr
->mono_gc
, 0, 0, w
+4, h
+4);
362 XSetForeground(dpy
, scr
->mono_gc
, 1);
363 for (x
= 0; x
<= 4; x
++) {
364 for (y
= 0; y
<= 4; y
++) {
365 WMDrawString(scr
->wmscreen
, mask
, scr
->mono_gc
,
366 scr
->workspace_name_font
, x
, y
, name
, len
);
370 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
371 WMDrawString(scr
->wmscreen
, text
, scr
->draw_gc
, scr
->workspace_name_font
,
372 2, 2, scr
->workspaces
[workspace
]->name
,
373 strlen(scr
->workspaces
[workspace
]->name
));
375 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
,
378 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, text
);
379 XClearWindow(dpy
, scr
->workspace_name
);
381 data
->text
= RCreateImageFromDrawable(scr
->rcontext
, text
, None
);
383 XFreePixmap(dpy
, text
);
384 XFreePixmap(dpy
, mask
);
387 XMapRaised(dpy
, scr
->workspace_name
);
393 ximg
= RGetXImage(scr
->rcontext
, scr
->root_win
, px
, py
,
394 data
->text
->width
, data
->text
->height
);
396 if (!ximg
|| !ximg
->image
) {
400 XMapRaised(dpy
, scr
->workspace_name
);
403 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
404 RDestroyXImage(scr
->rcontext
, ximg
);
412 /* set a timeout for the effect */
413 data
->timeout
= time(NULL
) + 2 +
414 (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
*data
->count
)/1000;
416 scr
->workspace_name_data
= data
;
422 if (scr
->workspace_name_timer
)
423 WMDeleteTimerHandler(scr
->workspace_name_timer
);
426 RDestroyImage(data
->text
);
428 RDestroyImage(data
->back
);
431 scr
->workspace_name_data
= NULL
;
433 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
434 10*WORKSPACE_NAME_FADE_DELAY
,
435 hideWorkpaceName
, scr
);
440 wWorkspaceChange(WScreen
*scr
, int workspace
)
442 if (scr
->flags
.startup
|| scr
->flags
.startup2
) {
446 if (workspace
!= scr
->current_workspace
) {
447 wWorkspaceForceChange(scr
, workspace
);
449 showWorkspaceName(scr, workspace);
455 wWorkspaceRelativeChange(WScreen
*scr
, int amount
)
459 w
= scr
->current_workspace
+ amount
;
464 wWorkspaceChange(scr
, w
);
465 else if (wPreferences
.ws_cycle
)
466 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
468 } else if (amount
> 0) {
470 if (w
< scr
->workspace_count
)
471 wWorkspaceChange(scr
, w
);
472 else if (wPreferences
.ws_advance
)
473 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
-1));
474 else if (wPreferences
.ws_cycle
)
475 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
482 wWorkspaceForceChange(WScreen
*scr
, int workspace
)
484 WWindow
*tmp
, *foc
=NULL
, *foc2
=NULL
;
486 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
489 SendHelperMessage(scr
, 'C', workspace
+1, NULL
);
491 if (workspace
> scr
->workspace_count
-1) {
492 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
495 wClipUpdateForWorkspaceChange(scr
, workspace
);
497 scr
->current_workspace
= workspace
;
499 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
501 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
503 if ((tmp
= scr
->focused_window
)!= NULL
) {
504 if ((IS_OMNIPRESENT(tmp
) && !WFLAGP(tmp
, skip_window_list
))
505 || tmp
->flags
.changing_workspace
) {
509 /* foc2 = tmp; will fix annoyance with gnome panel
510 * but will create annoyance for every other application
514 if (tmp
->frame
->workspace
!=workspace
&& !tmp
->flags
.selected
) {
515 /* unmap windows not on this workspace */
516 if ((tmp
->flags
.mapped
||tmp
->flags
.shaded
)
517 && !IS_OMNIPRESENT(tmp
)
518 && !tmp
->flags
.changing_workspace
) {
522 /* also unmap miniwindows not on this workspace */
523 if (tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
)
525 if (!wPreferences
.sticky_icons
) {
526 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
527 tmp
->icon
->mapped
= 0;
531 tmp
->icon
->mapped
= 1;
532 /* Why is this here? -Alfredo */
533 XMapWindow(dpy
, tmp
->icon
->core
->window
);
537 /* update current workspace of omnipresent windows */
538 if (IS_OMNIPRESENT(tmp
)) {
539 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
541 tmp
->frame
->workspace
= workspace
;
544 wapp
->last_workspace
= workspace
;
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
, skip_window_list
))
564 /* Also map miniwindow if not omnipresent */
565 if (!wPreferences
.sticky_icons
&&
566 tmp
->flags
.miniaturized
&&
567 !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
568 tmp
->icon
->mapped
= 1;
569 XMapWindow(dpy
, tmp
->icon
->core
->window
);
580 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
581 foc
= scr
->focused_window
;
583 if (wPreferences
.focus_mode
== WKF_CLICK
) {
584 wSetFocusTo(scr
, foc
);
592 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
593 &foo
, &foo
, &foo
, &foo
, &mask
)) {
594 tmp
= wWindowFor(win
);
596 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
597 wSetFocusTo(scr
, foc
);
599 wSetFocusTo(scr
, tmp
);
604 /* We need to always arrange icons when changing workspace, even if
605 * no autoarrange icons, because else the icons in different workspaces
607 * This can be avoided if appicons are also workspace specific.
609 if (!wPreferences
.sticky_icons
)
610 wArrangeIcons(scr
, False
);
613 wAppIconPaint(scr
->dock
->icon_array
[0]);
615 if (scr
->clip_icon
) {
616 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
617 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
618 /* to handle enter notify. This will also */
619 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
620 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
622 wClipIconPaint(scr
->clip_icon
);
626 showWorkspaceName(scr
, workspace
);
629 wGNOMEUpdateCurrentWorkspaceHint(scr
);
632 wKWMUpdateCurrentWorkspaceHint(scr
);
634 /* XSync(dpy, False); */
637 #ifdef VIRTUAL_DESKTOP
639 void wWorkspaceManageEdge(WScreen
*scr
) {
642 XSetWindowAttributes attribs
;
645 if (wPreferences
.vedge_thickness
) {
647 for (i
= 0;i
< scr
->workspace_count
; i
++) {
648 puts("reset workspace");
649 scr
->workspaces
[i
]->x
= scr
->workspaces
[i
]->y
= 0;
650 wWorkspaceResizeViewPort(scr
, i
, wPreferences
.vedge_width
, wPreferences
.vedge_height
);
653 vmask
= CWEventMask
|CWOverrideRedirect
;
654 attribs
.event_mask
= (EnterWindowMask
| LeaveWindowMask
| VisibilityChangeMask
);
655 attribs
.override_redirect
= True
;
656 scr
->virtual_edge_u
=
657 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
658 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
659 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
660 scr
->virtual_edge_d
=
661 XCreateWindow(dpy
, scr
->root_win
, 0, scr
->scr_height
-wPreferences
.vedge_thickness
,
662 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
663 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
664 scr
->virtual_edge_l
=
665 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
666 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
667 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
668 scr
->virtual_edge_r
=
669 XCreateWindow(dpy
, scr
->root_win
, scr
->scr_width
-wPreferences
.vedge_thickness
, 0,
670 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
671 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
672 XMapWindow(dpy
, scr
->virtual_edge_u
);
673 XMapWindow(dpy
, scr
->virtual_edge_d
);
674 XMapWindow(dpy
, scr
->virtual_edge_l
);
675 XMapWindow(dpy
, scr
->virtual_edge_r
);
676 wWorkspaceRaiseEdge(scr
);
680 void wWorkspaceRaiseEdge(WScreen
*scr
) {
681 if (wPreferences
.vedge_thickness
&& initVDesk
) {
682 XRaiseWindow(dpy
, scr
->virtual_edge_u
);
683 XRaiseWindow(dpy
, scr
->virtual_edge_d
);
684 XRaiseWindow(dpy
, scr
->virtual_edge_l
);
685 XRaiseWindow(dpy
, scr
->virtual_edge_r
);
689 void wWorkspaceResizeViewPort(WScreen
*scr
, int workspace
, int width
, int height
)
691 if (width
< scr
->scr_width
) return;
692 if (height
< scr
->scr_height
) return;
694 scr
->workspaces
[workspace
]->width
= WMAX(width
,scr
->scr_width
);
695 scr
->workspaces
[workspace
]->height
= WMAX(height
,scr
->scr_height
);
699 void wWorkspaceSetViewPort(WScreen
*scr
, int workspace
, int x
, int y
)
706 if (x
+ scr
->scr_width
> scr
->workspaces
[workspace
]->width
) return;
707 if (y
+ scr
->scr_height
> scr
->workspaces
[workspace
]->height
) return;
709 diff_x
= scr
->workspaces
[workspace
]->x
- x
;
710 diff_y
= scr
->workspaces
[workspace
]->y
- y
;
712 scr
->workspaces
[workspace
]->x
= WMIN(x
, scr
->workspaces
[workspace
]->width
- scr
->scr_width
);
713 scr
->workspaces
[workspace
]->y
= WMIN(y
, scr
->workspaces
[workspace
]->height
- scr
->scr_height
);
715 printf("set view %d %d, %d\n",workspace
, scr
->workspaces
[workspace
]->x
, scr
->workspaces
[workspace
]->y
);
717 wwin
= scr
->focused_window
;
719 if (wwin
->frame
->workspace
== workspace
) {
720 wWindowMove(wwin
, wwin
->frame_x
+ diff_x
, wwin
->frame_y
+ diff_y
);
721 wWindowSynthConfigureNotify(wwin
);
727 void wWorkspaceGetViewPosition(WScreen
*scr
, int workspace
, int *x
, int *y
) {
728 *x
= scr
->workspaces
[workspace
]->x
;
729 *y
= scr
->workspaces
[workspace
]->y
;
735 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
737 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
743 deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
745 wWorkspaceDelete(menu
->frame
->screen_ptr
,
746 menu
->frame
->screen_ptr
->workspace_count
-1);
752 newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
756 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
757 /* autochange workspace*/
759 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
765 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
766 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
768 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
783 end
= &(line
[strlen(line
)])-1;
784 while (isspace(*line
) && *line
!=0) line
++;
785 while (isspace(*end
) && end
!=line
) {
794 wWorkspaceRename(WScreen
*scr
, int workspace
, char *name
)
796 char buf
[MAX_WORKSPACENAME_WIDTH
+1];
799 if (workspace
>= scr
->workspace_count
)
802 /* trim white spaces */
803 tmp
= cropline(name
);
805 if (strlen(tmp
)==0) {
806 sprintf(buf
, _("Workspace %i"), workspace
+1);
808 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
810 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
812 /* update workspace */
813 free(scr
->workspaces
[workspace
]->name
);
814 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
816 if (scr
->clip_ws_menu
) {
817 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
818 free(scr
->clip_ws_menu
->entries
[workspace
+2]->text
);
819 scr
->clip_ws_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
820 wMenuRealize(scr
->clip_ws_menu
);
823 if (scr
->workspace_menu
) {
824 if (strcmp(scr
->workspace_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
825 free(scr
->workspace_menu
->entries
[workspace
+2]->text
);
826 scr
->workspace_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
827 wMenuRealize(scr
->workspace_menu
);
831 UpdateSwitchMenuWorkspace(scr
, workspace
);
834 wClipIconPaint(scr
->clip_icon
);
837 wGNOMEUpdateWorkspaceNamesHint(scr
);
840 wKWMUpdateWorkspaceNameHint(scr
, workspace
);
847 /* callback for when menu entry is edited */
849 onMenuEntryEdited(WMenu
*menu
, WMenuEntry
*entry
)
854 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
859 wWorkspaceMenuMake(WScreen
*scr
, Bool titled
)
863 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
865 wwarning(_("could not create Workspace menu"));
869 /* callback to be called when an entry is edited */
870 wsmenu
->on_edit
= onMenuEntryEdited
;
872 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
873 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
881 wWorkspaceMenuUpdate(WScreen
*scr
, WMenu
*menu
)
885 char title
[MAX_WORKSPACENAME_WIDTH
+1];
892 if (menu
->entry_no
< scr
->workspace_count
+2) {
893 /* new workspace(s) added */
894 i
= scr
->workspace_count
-(menu
->entry_no
-2);
895 ws
= menu
->entry_no
- 2;
897 strcpy(title
, scr
->workspaces
[ws
]->name
);
899 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)ws
);
900 entry
->flags
.indicator
= 1;
901 entry
->flags
.editable
= 1;
906 } else if (menu
->entry_no
> scr
->workspace_count
+2) {
907 /* removed workspace(s) */
908 for (i
= menu
->entry_no
-1; i
>= scr
->workspace_count
+2; i
--) {
909 wMenuRemoveItem(menu
, i
);
914 for (i
=0; i
<scr
->workspace_count
; i
++) {
915 menu
->entries
[i
+2]->flags
.indicator_on
= 0;
917 menu
->entries
[scr
->current_workspace
+2]->flags
.indicator_on
= 1;
919 /* don't let user destroy current workspace */
920 if (scr
->current_workspace
== scr
->workspace_count
-1) {
921 wMenuSetEnabled(menu
, 1, False
);
923 wMenuSetEnabled(menu
, 1, True
);
926 tmp
= menu
->frame
->top_width
+ 5;
927 /* if menu got unreachable, bring it to a visible place */
928 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
929 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
936 wWorkspaceSaveState(WScreen
*scr
, proplist_t old_state
)
938 proplist_t parr
, pstr
;
939 proplist_t wks_state
, old_wks_state
;
945 old_wks_state
= PLGetDictionaryEntry(old_state
, dWorkspaces
);
946 parr
= PLMakeArrayFromElements(NULL
);
947 for (i
=0; i
< scr
->workspace_count
; i
++) {
948 pstr
= PLMakeString(scr
->workspaces
[i
]->name
);
949 wks_state
= PLMakeDictionaryFromEntries(dName
, pstr
, NULL
);
951 if (!wPreferences
.flags
.noclip
) {
952 pstr
= wClipSaveWorkspaceState(scr
, i
);
953 PLInsertDictionaryEntry(wks_state
, dClip
, pstr
);
955 } else if (old_wks_state
!=NULL
) {
956 if ((foo
= PLGetArrayElement(old_wks_state
, i
))!=NULL
) {
957 if ((bar
= PLGetDictionaryEntry(foo
, dClip
))!=NULL
) {
958 PLInsertDictionaryEntry(wks_state
, dClip
, bar
);
962 PLAppendArrayElement(parr
, wks_state
);
963 PLRelease(wks_state
);
965 PLInsertDictionaryEntry(scr
->session_state
, dWorkspaces
, parr
);
971 wWorkspaceRestoreState(WScreen
*scr
)
973 proplist_t parr
, pstr
, wks_state
;
974 proplist_t clip_state
;
979 parr
= PLGetDictionaryEntry(scr
->session_state
, dWorkspaces
);
984 wscount
= scr
->workspace_count
;
985 for (i
=0; i
< WMIN(PLGetNumberOfElements(parr
), MAX_WORKSPACES
); i
++) {
986 wks_state
= PLGetArrayElement(parr
, i
);
987 if (PLIsDictionary(wks_state
))
988 pstr
= PLGetDictionaryEntry(wks_state
, dName
);
991 if (i
>= scr
->workspace_count
)
993 if (scr
->workspace_menu
) {
994 free(scr
->workspace_menu
->entries
[i
+2]->text
);
995 scr
->workspace_menu
->entries
[i
+2]->text
= wstrdup(PLGetString(pstr
));
996 scr
->workspace_menu
->flags
.realized
= 0;
998 free(scr
->workspaces
[i
]->name
);
999 scr
->workspaces
[i
]->name
= wstrdup(PLGetString(pstr
));
1000 if (!wPreferences
.flags
.noclip
) {
1001 clip_state
= PLGetDictionaryEntry(wks_state
, dClip
);
1002 if (scr
->workspaces
[i
]->clip
)
1003 wDockDestroy(scr
->workspaces
[i
]->clip
);
1004 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
,
1007 wDockHideIcons(scr
->workspaces
[i
]->clip
);
1009 /* We set the global icons here, because scr->workspaces[i]->clip
1010 * was not valid in wDockRestoreState().
1011 * There we only set icon->omnipresent to know which icons we
1014 for (j
=0; j
<scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
1015 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
1017 if (aicon
&& aicon
->omnipresent
) {
1018 aicon
->omnipresent
= 0;
1019 wClipMakeIconOmnipresent(aicon
, True
);
1020 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1025 wKWMUpdateWorkspaceNameHint(scr
, i
);
1029 wGNOMEUpdateWorkspaceNamesHint(scr
);