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 wfree(scr
->workspaces
);
128 scr
->workspaces
= list
;
130 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
131 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
132 #ifdef VIRTUAL_DESKTOP
133 wspace
->view_x
= wspace
->view_y
= 0;
134 wspace
->height
= scr
->scr_height
;
135 wspace
->width
= scr
->scr_width
;
138 wGNOMEUpdateWorkspaceHints(scr
);
141 if (!scr
->flags
.kwm_syncing_count
) {
142 wKWMUpdateWorkspaceCountHint(scr
);
143 wKWMUpdateWorkspaceNameHint(scr
, scr
->workspace_count
-1);
146 wKWMSetUsableAreaHint(scr
, scr
->workspace_count
-1);
151 return scr
->workspace_count
-1;
159 wWorkspaceDelete(WScreen
*scr
, int workspace
)
169 /* verify if workspace is in use by some window */
170 tmp
= scr
->focused_window
;
172 if (!IS_OMNIPRESENT(tmp
) && tmp
->frame
->workspace
==workspace
)
177 if (!wPreferences
.flags
.noclip
) {
178 wDockDestroy(scr
->workspaces
[workspace
]->clip
);
179 scr
->workspaces
[workspace
]->clip
= NULL
;
182 list
= wmalloc(sizeof(WWorkspace
*)*(scr
->workspace_count
-1));
184 for (i
=0; i
<scr
->workspace_count
; i
++) {
186 list
[j
++] = scr
->workspaces
[i
];
188 if (scr
->workspaces
[i
]->name
)
189 wfree(scr
->workspaces
[i
]->name
);
190 wfree(scr
->workspaces
[i
]);
193 wfree(scr
->workspaces
);
194 scr
->workspaces
= list
;
196 scr
->workspace_count
--;
200 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
201 /* clip workspace menu */
202 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
204 /* update also window menu */
205 if (scr
->workspace_submenu
) {
206 WMenu
*menu
= scr
->workspace_submenu
;
209 while (i
>scr
->workspace_count
)
210 wMenuRemoveItem(menu
, --i
);
214 if (scr
->clip_submenu
) {
215 WMenu
*menu
= scr
->clip_submenu
;
218 while (i
>scr
->workspace_count
)
219 wMenuRemoveItem(menu
, --i
);
224 wGNOMEUpdateWorkspaceHints(scr
);
227 wKWMUpdateWorkspaceCountHint(scr
);
230 if (scr
->current_workspace
>= scr
->workspace_count
)
231 wWorkspaceChange(scr
, scr
->workspace_count
-1);
237 typedef struct WorkspaceNameData
{
247 hideWorkpaceName(void *data
)
249 WScreen
*scr
= (WScreen
*)data
;
251 if (!scr
->workspace_name_data
|| scr
->workspace_name_data
->count
== 0
252 || time(NULL
) > scr
->workspace_name_data
->timeout
) {
253 XUnmapWindow(dpy
, scr
->workspace_name
);
255 if (scr
->workspace_name_data
) {
256 RDestroyImage(scr
->workspace_name_data
->back
);
257 RDestroyImage(scr
->workspace_name_data
->text
);
258 wfree(scr
->workspace_name_data
);
260 scr
->workspace_name_data
= NULL
;
262 scr
->workspace_name_timer
= NULL
;
264 RImage
*img
= RCloneImage(scr
->workspace_name_data
->back
);
267 scr
->workspace_name_timer
=
268 WMAddTimerHandler(WORKSPACE_NAME_FADE_DELAY
, hideWorkpaceName
,
271 RCombineImagesWithOpaqueness(img
, scr
->workspace_name_data
->text
,
272 scr
->workspace_name_data
->count
*255/10);
274 RConvertImage(scr
->rcontext
, img
, &pix
);
278 XSetWindowBackgroundPixmap(dpy
, scr
->workspace_name
, pix
);
279 XClearWindow(dpy
, scr
->workspace_name
);
280 XFreePixmap(dpy
, pix
);
283 scr
->workspace_name_data
->count
--;
290 showWorkspaceName(WScreen
*scr
, int workspace
)
292 WorkspaceNameData
*data
;
297 char *name
= scr
->workspaces
[workspace
]->name
;
298 int len
= strlen(name
);
301 if (wPreferences
.workspace_name_display_position
== WD_NONE
302 || scr
->workspace_count
< 2)
305 if (scr
->workspace_name_timer
) {
306 WMDeleteTimerHandler(scr
->workspace_name_timer
);
307 XUnmapWindow(dpy
, scr
->workspace_name
);
310 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
,
311 hideWorkpaceName
, scr
);
313 if (scr
->workspace_name_data
) {
314 RDestroyImage(scr
->workspace_name_data
->back
);
315 RDestroyImage(scr
->workspace_name_data
->text
);
316 wfree(scr
->workspace_name_data
);
319 data
= wmalloc(sizeof(WorkspaceNameData
));
321 w
= WMWidthOfString(scr
->workspace_name_font
, name
, len
);
322 h
= WMFontHeight(scr
->workspace_name_font
);
324 switch (wPreferences
.workspace_name_display_position
) {
326 px
= (scr
->scr_width
- (w
+4))/2;
330 px
= (scr
->scr_width
- (w
+4))/2;
331 py
= scr
->scr_height
- (h
+4);
338 px
= scr
->scr_width
- (w
+4);
343 py
= scr
->scr_height
- (h
+4);
346 px
= scr
->scr_width
- (w
+4);
347 py
= scr
->scr_height
- (h
+4);
351 px
= (scr
->scr_width
- (w
+4))/2;
352 py
= (scr
->scr_height
- (h
+4))/2;
355 XResizeWindow(dpy
, scr
->workspace_name
, w
+4, h
+4);
356 XMoveWindow(dpy
, scr
->workspace_name
, px
, py
);
358 text
= XCreatePixmap(dpy
, scr
->w_win
, w
+4, h
+4, scr
->w_depth
);
359 mask
= XCreatePixmap(dpy
, scr
->w_win
, w
+4, h
+4, 1);
361 XSetForeground(dpy
, scr
->draw_gc
, scr
->black_pixel
);
362 XFillRectangle(dpy
, text
, scr
->draw_gc
, 0, 0, w
+4, h
+4);
364 XSetForeground(dpy
, scr
->mono_gc
, 0);
365 XFillRectangle(dpy
, mask
, scr
->mono_gc
, 0, 0, w
+4, h
+4);
367 XSetForeground(dpy
, scr
->mono_gc
, 1);
368 for (x
= 0; x
<= 4; x
++) {
369 for (y
= 0; y
<= 4; y
++) {
370 WMDrawString(scr
->wmscreen
, mask
, scr
->mono_gc
,
371 scr
->workspace_name_font
, x
, y
, name
, len
);
375 XSetForeground(dpy
, scr
->draw_gc
, scr
->white_pixel
);
376 WMDrawString(scr
->wmscreen
, text
, scr
->draw_gc
, scr
->workspace_name_font
,
377 2, 2, scr
->workspaces
[workspace
]->name
,
378 strlen(scr
->workspaces
[workspace
]->name
));
380 XShapeCombineMask(dpy
, scr
->workspace_name
, ShapeBounding
, 0, 0, mask
,
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
,
399 data
->text
->width
, data
->text
->height
);
401 if (!ximg
|| !ximg
->image
) {
405 XMapRaised(dpy
, scr
->workspace_name
);
408 data
->back
= RCreateImageFromXImage(scr
->rcontext
, ximg
->image
, NULL
);
409 RDestroyXImage(scr
->rcontext
, ximg
);
417 /* set a timeout for the effect */
418 data
->timeout
= time(NULL
) + 2 +
419 (WORKSPACE_NAME_DELAY
+ WORKSPACE_NAME_FADE_DELAY
*data
->count
)/1000;
421 scr
->workspace_name_data
= data
;
427 if (scr
->workspace_name_timer
)
428 WMDeleteTimerHandler(scr
->workspace_name_timer
);
431 RDestroyImage(data
->text
);
433 RDestroyImage(data
->back
);
436 scr
->workspace_name_data
= NULL
;
438 scr
->workspace_name_timer
= WMAddTimerHandler(WORKSPACE_NAME_DELAY
+
439 10*WORKSPACE_NAME_FADE_DELAY
,
440 hideWorkpaceName
, scr
);
445 wWorkspaceChange(WScreen
*scr
, int workspace
)
447 if (scr
->flags
.startup
|| scr
->flags
.startup2
) {
451 if (workspace
!= scr
->current_workspace
) {
452 wWorkspaceForceChange(scr
, workspace
);
454 showWorkspaceName(scr, workspace);
460 wWorkspaceRelativeChange(WScreen
*scr
, int amount
)
464 w
= scr
->current_workspace
+ amount
;
469 wWorkspaceChange(scr
, w
);
470 else if (wPreferences
.ws_cycle
)
471 wWorkspaceChange(scr
, scr
->workspace_count
+ w
);
473 } else if (amount
> 0) {
475 if (w
< scr
->workspace_count
)
476 wWorkspaceChange(scr
, w
);
477 else if (wPreferences
.ws_advance
)
478 wWorkspaceChange(scr
, WMIN(w
, MAX_WORKSPACES
-1));
479 else if (wPreferences
.ws_cycle
)
480 wWorkspaceChange(scr
, w
% scr
->workspace_count
);
487 wWorkspaceForceChange(WScreen
*scr
, int workspace
)
489 WWindow
*tmp
, *foc
=NULL
, *foc2
=NULL
;
491 if (workspace
>= MAX_WORKSPACES
|| workspace
< 0)
494 SendHelperMessage(scr
, 'C', workspace
+1, NULL
);
496 if (workspace
> scr
->workspace_count
-1) {
497 wWorkspaceMake(scr
, workspace
- scr
->workspace_count
+ 1);
500 wClipUpdateForWorkspaceChange(scr
, workspace
);
502 scr
->current_workspace
= workspace
;
504 wWorkspaceMenuUpdate(scr
, scr
->workspace_menu
);
506 wWorkspaceMenuUpdate(scr
, scr
->clip_ws_menu
);
508 if ((tmp
= scr
->focused_window
)!= NULL
) {
509 if ((IS_OMNIPRESENT(tmp
) && !WFLAGP(tmp
, skip_window_list
))
510 || tmp
->flags
.changing_workspace
) {
514 /* foc2 = tmp; will fix annoyance with gnome panel
515 * 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
)
523 && !tmp
->flags
.changing_workspace
) {
527 /* also unmap miniwindows not on this workspace */
528 if (tmp
->flags
.miniaturized
&& !IS_OMNIPRESENT(tmp
)
530 if (!wPreferences
.sticky_icons
) {
531 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
532 tmp
->icon
->mapped
= 0;
536 tmp
->icon
->mapped
= 1;
537 /* Why is this here? -Alfredo */
538 XMapWindow(dpy
, tmp
->icon
->core
->window
);
542 /* update current workspace of omnipresent windows */
543 if (IS_OMNIPRESENT(tmp
)) {
544 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
546 tmp
->frame
->workspace
= workspace
;
549 wapp
->last_workspace
= workspace
;
555 /* change selected windows' workspace */
556 if (tmp
->flags
.selected
) {
557 wWindowChangeWorkspace(tmp
, workspace
);
558 if (!tmp
->flags
.miniaturized
&& !foc
) {
562 if (!tmp
->flags
.hidden
) {
563 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
564 /* remap windows that are on this workspace */
566 if (!foc
&& !WFLAGP(tmp
, skip_window_list
))
569 /* Also map miniwindow if not omnipresent */
570 if (!wPreferences
.sticky_icons
&&
571 tmp
->flags
.miniaturized
&&
572 !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
573 tmp
->icon
->mapped
= 1;
574 XMapWindow(dpy
, tmp
->icon
->core
->window
);
585 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
586 foc
= scr
->focused_window
;
588 if (wPreferences
.focus_mode
== WKF_CLICK
) {
589 wSetFocusTo(scr
, foc
);
597 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
598 &foo
, &foo
, &foo
, &foo
, &mask
)) {
599 tmp
= wWindowFor(win
);
601 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
602 wSetFocusTo(scr
, foc
);
604 wSetFocusTo(scr
, tmp
);
609 /* We need to always arrange icons when changing workspace, even if
610 * no autoarrange icons, because else the icons in different workspaces
612 * This can be avoided if appicons are also workspace specific.
614 if (!wPreferences
.sticky_icons
)
615 wArrangeIcons(scr
, False
);
618 wAppIconPaint(scr
->dock
->icon_array
[0]);
620 if (scr
->clip_icon
) {
621 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
622 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
623 /* to handle enter notify. This will also */
624 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
625 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
627 wClipIconPaint(scr
->clip_icon
);
631 showWorkspaceName(scr
, workspace
);
634 wGNOMEUpdateCurrentWorkspaceHint(scr
);
637 wKWMUpdateCurrentWorkspaceHint(scr
);
639 /* XSync(dpy, False); */
642 #ifdef VIRTUAL_DESKTOP
644 * 1) Allow border around each window so the scrolling
645 * won't just stop at the border.
649 void wWorkspaceManageEdge(WScreen
*scr
)
653 XSetWindowAttributes attribs
;
655 /* puts("wWorkspaceManageEdge()"); */
656 if (wPreferences
.vedge_thickness
) {
658 for (w
= 0; w
< scr
->workspace_count
; w
++) {
659 /* puts("reset workspace"); */
660 wWorkspaceSetViewPort(scr
, w
, 0, 0);
663 vmask
= CWEventMask
|CWOverrideRedirect
;
664 attribs
.event_mask
= (EnterWindowMask
| LeaveWindowMask
| VisibilityChangeMask
);
665 attribs
.override_redirect
= True
;
666 scr
->virtual_edge_u
=
667 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
668 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
669 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
670 scr
->virtual_edge_d
=
671 XCreateWindow(dpy
, scr
->root_win
, 0, scr
->scr_height
-wPreferences
.vedge_thickness
,
672 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
673 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
674 scr
->virtual_edge_l
=
675 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
676 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
677 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
678 scr
->virtual_edge_r
=
679 XCreateWindow(dpy
, scr
->root_win
, scr
->scr_width
-wPreferences
.vedge_thickness
, 0,
680 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
681 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
682 XMapWindow(dpy
, scr
->virtual_edge_u
);
683 XMapWindow(dpy
, scr
->virtual_edge_d
);
684 XMapWindow(dpy
, scr
->virtual_edge_l
);
685 XMapWindow(dpy
, scr
->virtual_edge_r
);
686 wWorkspaceRaiseEdge(scr
);
690 void wWorkspaceRaiseEdge(WScreen
*scr
)
693 if (wPreferences
.vedge_thickness
&& initVDesk
) {
694 XRaiseWindow(dpy
, scr
->virtual_edge_u
);
695 XRaiseWindow(dpy
, scr
->virtual_edge_d
);
696 XRaiseWindow(dpy
, scr
->virtual_edge_l
);
697 XRaiseWindow(dpy
, scr
->virtual_edge_r
);
701 void wWorkspaceLowerEdge(WScreen
*scr
)
704 if (wPreferences
.vedge_thickness
&& initVDesk
) {
705 XLowerWindow(dpy
, scr
->virtual_edge_u
);
706 XLowerWindow(dpy
, scr
->virtual_edge_d
);
707 XLowerWindow(dpy
, scr
->virtual_edge_l
);
708 XLowerWindow(dpy
, scr
->virtual_edge_r
);
712 void wWorkspaceResizeViewPort(WScreen
*scr
, int workspace
, int width
, int height
)
714 scr
->workspaces
[workspace
]->width
= WMAX(width
,scr
->scr_width
);
715 scr
->workspaces
[workspace
]->height
= WMAX(height
,scr
->scr_height
);
718 void updateWorkspaceGeometry(WScreen
*scr
, int workspace
, int *view_x
, int *view_y
) {
719 int most_left
, most_right
, most_top
, most_bottom
;
722 /* adjust workspace layout */
723 wwin
= scr
->focused_window
;
724 most_right
= scr
->scr_width
;
725 most_bottom
= scr
->scr_height
;
728 for(;wwin
; wwin
= wwin
->prev
) {
729 if (wwin
->frame
->workspace
== workspace
) {
730 if (!wwin
->flags
.miniaturized
731 && !wwin
->flags
.hidden
) {
732 if (wwin
->frame_x
< most_left
) { /* record positions, should this be cached? */
733 most_left
= wwin
->frame_x
;
735 if ((int)wwin
->frame_x
+ (int)wwin
->frame
->core
->width
> most_right
) {
736 most_right
= wwin
->frame_x
+ wwin
->frame
->core
->width
;
738 if (wwin
->frame_y
< most_top
) {
739 most_top
= wwin
->frame_y
;
741 if (wwin
->frame_y
+ wwin
->frame
->core
->height
> most_bottom
) {
742 most_bottom
= wwin
->frame_y
+ wwin
->frame
->core
->height
;
748 scr
->workspaces
[workspace
]->width
= WMAX(most_right
, scr
->scr_width
) - WMIN(most_left
, 0);
749 scr
->workspaces
[workspace
]->height
= WMAX(most_bottom
, scr
->scr_height
) - WMIN(most_top
, 0);
751 *view_x
+= -most_left
- scr
->workspaces
[workspace
]->view_x
;
752 scr
->workspaces
[workspace
]->view_x
= -most_left
;
754 *view_y
+= -most_top
- scr
->workspaces
[workspace
]->view_y
;
755 scr
->workspaces
[workspace
]->view_y
= -most_top
;
759 typedef struct _delay_configure
{
764 void _sendConfigureNotify (_delay_configure
*delay
) {
767 delay
->delay_count
--;
768 if (!delay
->delay_count
) {
769 for (wwin
= delay
->wwin
; wwin
; wwin
= wwin
->prev
) {
770 wWindowSynthConfigureNotify(wwin
);
775 Bool
wWorkspaceSetViewPort(WScreen
*scr
, int workspace
, int view_x
, int view_y
)
777 Bool adjust_flag
= False
;
779 static _delay_configure delay_configure
= {NULL
, 0};
782 /*printf("wWorkspaceSetViewPort %d %d\n", view_x, view_y);*/
784 updateWorkspaceGeometry(scr
, workspace
, &view_x
, &view_y
);
786 if (view_x
+ scr
->scr_width
> scr
->workspaces
[workspace
]->width
) {
787 /* puts("right edge of vdesk"); */
788 view_x
= scr
->workspaces
[workspace
]->width
- scr
->scr_width
;
791 /* puts("left edge of vdesk"); */
794 if (view_y
+ scr
->scr_height
> scr
->workspaces
[workspace
]->height
) {
795 /* puts("right edge of vdesk"); */
796 view_y
= scr
->workspaces
[workspace
]->height
- scr
->scr_height
;
799 /* puts("left edge of vdesk"); */
803 diff_x
= scr
->workspaces
[workspace
]->view_x
- view_x
;
804 diff_y
= scr
->workspaces
[workspace
]->view_y
- view_y
;
805 if (!diff_x
&& !diff_y
)
808 scr
->workspaces
[workspace
]->view_x
= view_x
;
809 scr
->workspaces
[workspace
]->view_y
= view_y
;
812 for (wwin
= scr
->focused_window
; wwin
; wwin
= wwin
->prev
) {
813 if (wwin
->frame
->workspace
== workspace
) {
814 wWindowMove(wwin
, wwin
->frame_x
+ diff_x
, wwin
->frame_y
+ diff_y
);
817 if (1) { /* if delay*/
818 delay_configure
.delay_count
++;
819 delay_configure
.wwin
= scr
->focused_window
;
820 WMAddTimerHandler(200, (WMCallback
*)_sendConfigureNotify
, &delay_configure
);
826 void wWorkspaceGetViewPosition(WScreen
*scr
, int workspace
, int *view_x
, int *view_y
) {
827 if (view_x
) *view_x
= scr
->workspaces
[workspace
]->view_x
;
828 if (view_y
) *view_y
= scr
->workspaces
[workspace
]->view_y
;
834 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
836 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
842 deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
844 wWorkspaceDelete(menu
->frame
->screen_ptr
,
845 menu
->frame
->screen_ptr
->workspace_count
-1);
851 newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
855 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
856 /* autochange workspace*/
858 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
864 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
865 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
867 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
882 end
= &(line
[strlen(line
)])-1;
883 while (isspace(*line
) && *line
!=0) line
++;
884 while (isspace(*end
) && end
!=line
) {
893 wWorkspaceRename(WScreen
*scr
, int workspace
, char *name
)
895 char buf
[MAX_WORKSPACENAME_WIDTH
+1];
898 if (workspace
>= scr
->workspace_count
)
901 /* trim white spaces */
902 tmp
= cropline(name
);
904 if (strlen(tmp
)==0) {
905 sprintf(buf
, _("Workspace %i"), workspace
+1);
907 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
909 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
911 /* update workspace */
912 wfree(scr
->workspaces
[workspace
]->name
);
913 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
915 if (scr
->clip_ws_menu
) {
916 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
917 wfree(scr
->clip_ws_menu
->entries
[workspace
+2]->text
);
918 scr
->clip_ws_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
919 wMenuRealize(scr
->clip_ws_menu
);
922 if (scr
->workspace_menu
) {
923 if (strcmp(scr
->workspace_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
924 wfree(scr
->workspace_menu
->entries
[workspace
+2]->text
);
925 scr
->workspace_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
926 wMenuRealize(scr
->workspace_menu
);
930 UpdateSwitchMenuWorkspace(scr
, workspace
);
933 wClipIconPaint(scr
->clip_icon
);
936 wGNOMEUpdateWorkspaceNamesHint(scr
);
939 wKWMUpdateWorkspaceNameHint(scr
, workspace
);
946 /* callback for when menu entry is edited */
948 onMenuEntryEdited(WMenu
*menu
, WMenuEntry
*entry
)
953 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
958 wWorkspaceMenuMake(WScreen
*scr
, Bool titled
)
962 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
964 wwarning(_("could not create Workspace menu"));
968 /* callback to be called when an entry is edited */
969 wsmenu
->on_edit
= onMenuEntryEdited
;
971 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
972 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
980 wWorkspaceMenuUpdate(WScreen
*scr
, WMenu
*menu
)
984 char title
[MAX_WORKSPACENAME_WIDTH
+1];
991 if (menu
->entry_no
< scr
->workspace_count
+2) {
992 /* new workspace(s) added */
993 i
= scr
->workspace_count
-(menu
->entry_no
-2);
994 ws
= menu
->entry_no
- 2;
996 strcpy(title
, scr
->workspaces
[ws
]->name
);
998 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)ws
);
999 entry
->flags
.indicator
= 1;
1000 entry
->flags
.editable
= 1;
1005 } else if (menu
->entry_no
> scr
->workspace_count
+2) {
1006 /* removed workspace(s) */
1007 for (i
= menu
->entry_no
-1; i
>= scr
->workspace_count
+2; i
--) {
1008 wMenuRemoveItem(menu
, i
);
1013 for (i
=0; i
<scr
->workspace_count
; i
++) {
1014 menu
->entries
[i
+2]->flags
.indicator_on
= 0;
1016 menu
->entries
[scr
->current_workspace
+2]->flags
.indicator_on
= 1;
1018 /* don't let user destroy current workspace */
1019 if (scr
->current_workspace
== scr
->workspace_count
-1) {
1020 wMenuSetEnabled(menu
, 1, False
);
1022 wMenuSetEnabled(menu
, 1, True
);
1025 tmp
= menu
->frame
->top_width
+ 5;
1026 /* if menu got unreachable, bring it to a visible place */
1027 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
1028 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
1035 wWorkspaceSaveState(WScreen
*scr
, proplist_t old_state
)
1037 proplist_t parr
, pstr
;
1038 proplist_t wks_state
, old_wks_state
;
1039 proplist_t foo
, bar
;
1044 old_wks_state
= PLGetDictionaryEntry(old_state
, dWorkspaces
);
1045 parr
= PLMakeArrayFromElements(NULL
);
1046 for (i
=0; i
< scr
->workspace_count
; i
++) {
1047 pstr
= PLMakeString(scr
->workspaces
[i
]->name
);
1048 wks_state
= PLMakeDictionaryFromEntries(dName
, pstr
, NULL
);
1050 if (!wPreferences
.flags
.noclip
) {
1051 pstr
= wClipSaveWorkspaceState(scr
, i
);
1052 PLInsertDictionaryEntry(wks_state
, dClip
, pstr
);
1054 } else if (old_wks_state
!=NULL
) {
1055 if ((foo
= PLGetArrayElement(old_wks_state
, i
))!=NULL
) {
1056 if ((bar
= PLGetDictionaryEntry(foo
, dClip
))!=NULL
) {
1057 PLInsertDictionaryEntry(wks_state
, dClip
, bar
);
1061 PLAppendArrayElement(parr
, wks_state
);
1062 PLRelease(wks_state
);
1064 PLInsertDictionaryEntry(scr
->session_state
, dWorkspaces
, parr
);
1070 wWorkspaceRestoreState(WScreen
*scr
)
1072 proplist_t parr
, pstr
, wks_state
;
1073 proplist_t clip_state
;
1078 parr
= PLGetDictionaryEntry(scr
->session_state
, dWorkspaces
);
1083 wscount
= scr
->workspace_count
;
1084 for (i
=0; i
< WMIN(PLGetNumberOfElements(parr
), MAX_WORKSPACES
); i
++) {
1085 wks_state
= PLGetArrayElement(parr
, i
);
1086 if (PLIsDictionary(wks_state
))
1087 pstr
= PLGetDictionaryEntry(wks_state
, dName
);
1090 if (i
>= scr
->workspace_count
)
1092 if (scr
->workspace_menu
) {
1093 wfree(scr
->workspace_menu
->entries
[i
+2]->text
);
1094 scr
->workspace_menu
->entries
[i
+2]->text
= wstrdup(PLGetString(pstr
));
1095 scr
->workspace_menu
->flags
.realized
= 0;
1097 wfree(scr
->workspaces
[i
]->name
);
1098 scr
->workspaces
[i
]->name
= wstrdup(PLGetString(pstr
));
1099 if (!wPreferences
.flags
.noclip
) {
1100 clip_state
= PLGetDictionaryEntry(wks_state
, dClip
);
1101 if (scr
->workspaces
[i
]->clip
)
1102 wDockDestroy(scr
->workspaces
[i
]->clip
);
1103 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
,
1106 wDockHideIcons(scr
->workspaces
[i
]->clip
);
1108 /* We set the global icons here, because scr->workspaces[i]->clip
1109 * was not valid in wDockRestoreState().
1110 * There we only set icon->omnipresent to know which icons we
1113 for (j
=0; j
<scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
1114 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
1116 if (aicon
&& aicon
->omnipresent
) {
1117 aicon
->omnipresent
= 0;
1118 wClipMakeIconOmnipresent(aicon
, True
);
1119 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1124 wKWMUpdateWorkspaceNameHint(scr
, i
);
1128 wGNOMEUpdateWorkspaceNamesHint(scr
);