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 RReleaseImage(scr
->workspace_name_data
->back
);
257 RReleaseImage(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 RReleaseImage(scr
->workspace_name_data
->back
);
315 RReleaseImage(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 RReleaseImage(data
->text
);
433 RReleaseImage(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 (!wPreferences
.sticky_icons
&& tmp
->flags
.miniaturized
&&
529 tmp
->icon
&& !IS_OMNIPRESENT(tmp
)) {
531 XUnmapWindow(dpy
, tmp
->icon
->core
->window
);
532 tmp
->icon
->mapped
= 0;
534 /* update current workspace of omnipresent windows */
535 if (IS_OMNIPRESENT(tmp
)) {
536 WApplication
*wapp
= wApplicationOf(tmp
->main_window
);
538 tmp
->frame
->workspace
= workspace
;
541 wapp
->last_workspace
= workspace
;
547 /* change selected windows' workspace */
548 if (tmp
->flags
.selected
) {
549 wWindowChangeWorkspace(tmp
, workspace
);
550 if (!tmp
->flags
.miniaturized
&& !foc
) {
554 if (!tmp
->flags
.hidden
) {
555 if (!(tmp
->flags
.mapped
|| tmp
->flags
.miniaturized
)) {
556 /* remap windows that are on this workspace */
558 if (!foc
&& !WFLAGP(tmp
, skip_window_list
))
561 /* Also map miniwindow if not omnipresent */
562 if (!wPreferences
.sticky_icons
&&
563 tmp
->flags
.miniaturized
&&
564 !IS_OMNIPRESENT(tmp
) && tmp
->icon
) {
565 tmp
->icon
->mapped
= 1;
566 XMapWindow(dpy
, tmp
->icon
->core
->window
);
577 if (scr
->focused_window
->flags
.mapped
&& !foc
) {
578 foc
= scr
->focused_window
;
580 if (wPreferences
.focus_mode
== WKF_CLICK
) {
581 wSetFocusTo(scr
, foc
);
589 if (XQueryPointer(dpy
, scr
->root_win
, &bar
, &win
,
590 &foo
, &foo
, &foo
, &foo
, &mask
)) {
591 tmp
= wWindowFor(win
);
593 if (!tmp
&& wPreferences
.focus_mode
== WKF_SLOPPY
) {
594 wSetFocusTo(scr
, foc
);
596 wSetFocusTo(scr
, tmp
);
601 /* We need to always arrange icons when changing workspace, even if
602 * no autoarrange icons, because else the icons in different workspaces
604 * This can be avoided if appicons are also workspace specific.
606 if (!wPreferences
.sticky_icons
)
607 wArrangeIcons(scr
, False
);
610 wAppIconPaint(scr
->dock
->icon_array
[0]);
612 if (scr
->clip_icon
) {
613 if (scr
->workspaces
[workspace
]->clip
->auto_collapse
||
614 scr
->workspaces
[workspace
]->clip
->auto_raise_lower
) {
615 /* to handle enter notify. This will also */
616 XUnmapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
617 XMapWindow(dpy
, scr
->clip_icon
->icon
->core
->window
);
619 wClipIconPaint(scr
->clip_icon
);
623 showWorkspaceName(scr
, workspace
);
626 wGNOMEUpdateCurrentWorkspaceHint(scr
);
629 wKWMUpdateCurrentWorkspaceHint(scr
);
631 /* XSync(dpy, False); */
634 #ifdef VIRTUAL_DESKTOP
636 * 1) Allow border around each window so the scrolling
637 * won't just stop at the border.
641 void wWorkspaceManageEdge(WScreen
*scr
)
645 XSetWindowAttributes attribs
;
647 /* puts("wWorkspaceManageEdge()"); */
648 if (wPreferences
.vedge_thickness
) {
650 for (w
= 0; w
< scr
->workspace_count
; w
++) {
651 /* puts("reset workspace"); */
652 wWorkspaceSetViewPort(scr
, w
, 0, 0);
655 vmask
= CWEventMask
|CWOverrideRedirect
;
656 attribs
.event_mask
= (EnterWindowMask
| LeaveWindowMask
| VisibilityChangeMask
);
657 attribs
.override_redirect
= True
;
658 scr
->virtual_edge_u
=
659 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
660 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
661 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
662 scr
->virtual_edge_d
=
663 XCreateWindow(dpy
, scr
->root_win
, 0, scr
->scr_height
-wPreferences
.vedge_thickness
,
664 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
665 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
666 scr
->virtual_edge_l
=
667 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
668 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
669 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
670 scr
->virtual_edge_r
=
671 XCreateWindow(dpy
, scr
->root_win
, scr
->scr_width
-wPreferences
.vedge_thickness
, 0,
672 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
673 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
674 XMapWindow(dpy
, scr
->virtual_edge_u
);
675 XMapWindow(dpy
, scr
->virtual_edge_d
);
676 XMapWindow(dpy
, scr
->virtual_edge_l
);
677 XMapWindow(dpy
, scr
->virtual_edge_r
);
678 wWorkspaceRaiseEdge(scr
);
682 void wWorkspaceRaiseEdge(WScreen
*scr
)
685 if (wPreferences
.vedge_thickness
&& initVDesk
) {
686 XRaiseWindow(dpy
, scr
->virtual_edge_u
);
687 XRaiseWindow(dpy
, scr
->virtual_edge_d
);
688 XRaiseWindow(dpy
, scr
->virtual_edge_l
);
689 XRaiseWindow(dpy
, scr
->virtual_edge_r
);
693 void wWorkspaceLowerEdge(WScreen
*scr
)
696 if (wPreferences
.vedge_thickness
&& initVDesk
) {
697 XLowerWindow(dpy
, scr
->virtual_edge_u
);
698 XLowerWindow(dpy
, scr
->virtual_edge_d
);
699 XLowerWindow(dpy
, scr
->virtual_edge_l
);
700 XLowerWindow(dpy
, scr
->virtual_edge_r
);
704 void wWorkspaceResizeViewPort(WScreen
*scr
, int workspace
, int width
, int height
)
706 scr
->workspaces
[workspace
]->width
= WMAX(width
,scr
->scr_width
);
707 scr
->workspaces
[workspace
]->height
= WMAX(height
,scr
->scr_height
);
710 void updateWorkspaceGeometry(WScreen
*scr
, int workspace
, int *view_x
, int *view_y
) {
711 int most_left
, most_right
, most_top
, most_bottom
;
714 /* adjust workspace layout */
715 wwin
= scr
->focused_window
;
716 most_right
= scr
->scr_width
;
717 most_bottom
= scr
->scr_height
;
720 for(;wwin
; wwin
= wwin
->prev
) {
721 if (wwin
->frame
->workspace
== workspace
) {
722 if (!wwin
->flags
.miniaturized
723 && !wwin
->flags
.hidden
) {
724 if (wwin
->frame_x
< most_left
) { /* record positions, should this be cached? */
725 most_left
= wwin
->frame_x
;
727 if ((int)wwin
->frame_x
+ (int)wwin
->frame
->core
->width
> most_right
) {
728 most_right
= wwin
->frame_x
+ wwin
->frame
->core
->width
;
730 if (wwin
->frame_y
< most_top
) {
731 most_top
= wwin
->frame_y
;
733 if (wwin
->frame_y
+ wwin
->frame
->core
->height
> most_bottom
) {
734 most_bottom
= wwin
->frame_y
+ wwin
->frame
->core
->height
;
740 scr
->workspaces
[workspace
]->width
= WMAX(most_right
, scr
->scr_width
) - WMIN(most_left
, 0);
741 scr
->workspaces
[workspace
]->height
= WMAX(most_bottom
, scr
->scr_height
) - WMIN(most_top
, 0);
743 *view_x
+= -most_left
- scr
->workspaces
[workspace
]->view_x
;
744 scr
->workspaces
[workspace
]->view_x
= -most_left
;
746 *view_y
+= -most_top
- scr
->workspaces
[workspace
]->view_y
;
747 scr
->workspaces
[workspace
]->view_y
= -most_top
;
751 typedef struct _delay_configure
{
756 void _sendConfigureNotify (_delay_configure
*delay
) {
759 delay
->delay_count
--;
760 if (!delay
->delay_count
) {
761 for (wwin
= delay
->wwin
; wwin
; wwin
= wwin
->prev
) {
762 wWindowSynthConfigureNotify(wwin
);
767 Bool
wWorkspaceSetViewPort(WScreen
*scr
, int workspace
, int view_x
, int view_y
)
769 Bool adjust_flag
= False
;
771 static _delay_configure delay_configure
= {NULL
, 0};
774 /*printf("wWorkspaceSetViewPort %d %d\n", view_x, view_y);*/
776 updateWorkspaceGeometry(scr
, workspace
, &view_x
, &view_y
);
778 if (view_x
+ scr
->scr_width
> scr
->workspaces
[workspace
]->width
) {
779 /* puts("right edge of vdesk"); */
780 view_x
= scr
->workspaces
[workspace
]->width
- scr
->scr_width
;
783 /* puts("left edge of vdesk"); */
786 if (view_y
+ scr
->scr_height
> scr
->workspaces
[workspace
]->height
) {
787 /* puts("right edge of vdesk"); */
788 view_y
= scr
->workspaces
[workspace
]->height
- scr
->scr_height
;
791 /* puts("left edge of vdesk"); */
795 diff_x
= scr
->workspaces
[workspace
]->view_x
- view_x
;
796 diff_y
= scr
->workspaces
[workspace
]->view_y
- view_y
;
797 if (!diff_x
&& !diff_y
)
800 scr
->workspaces
[workspace
]->view_x
= view_x
;
801 scr
->workspaces
[workspace
]->view_y
= view_y
;
804 for (wwin
= scr
->focused_window
; wwin
; wwin
= wwin
->prev
) {
805 if (wwin
->frame
->workspace
== workspace
) {
806 wWindowMove(wwin
, wwin
->frame_x
+ diff_x
, wwin
->frame_y
+ diff_y
);
809 if (1) { /* if delay*/
810 delay_configure
.delay_count
++;
811 delay_configure
.wwin
= scr
->focused_window
;
812 WMAddTimerHandler(200, (WMCallback
*)_sendConfigureNotify
, &delay_configure
);
818 void wWorkspaceGetViewPosition(WScreen
*scr
, int workspace
, int *view_x
, int *view_y
) {
819 if (view_x
) *view_x
= scr
->workspaces
[workspace
]->view_x
;
820 if (view_y
) *view_y
= scr
->workspaces
[workspace
]->view_y
;
826 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
828 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
834 deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
836 wWorkspaceDelete(menu
->frame
->screen_ptr
,
837 menu
->frame
->screen_ptr
->workspace_count
-1);
843 newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
847 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
848 /* autochange workspace*/
850 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
856 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
857 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
859 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
874 end
= &(line
[strlen(line
)])-1;
875 while (isspace(*line
) && *line
!=0) line
++;
876 while (isspace(*end
) && end
!=line
) {
885 wWorkspaceRename(WScreen
*scr
, int workspace
, char *name
)
887 char buf
[MAX_WORKSPACENAME_WIDTH
+1];
890 if (workspace
>= scr
->workspace_count
)
893 /* trim white spaces */
894 tmp
= cropline(name
);
896 if (strlen(tmp
)==0) {
897 sprintf(buf
, _("Workspace %i"), workspace
+1);
899 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
901 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
903 /* update workspace */
904 wfree(scr
->workspaces
[workspace
]->name
);
905 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
907 if (scr
->clip_ws_menu
) {
908 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
909 wfree(scr
->clip_ws_menu
->entries
[workspace
+2]->text
);
910 scr
->clip_ws_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
911 wMenuRealize(scr
->clip_ws_menu
);
914 if (scr
->workspace_menu
) {
915 if (strcmp(scr
->workspace_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
916 wfree(scr
->workspace_menu
->entries
[workspace
+2]->text
);
917 scr
->workspace_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
918 wMenuRealize(scr
->workspace_menu
);
922 UpdateSwitchMenuWorkspace(scr
, workspace
);
925 wClipIconPaint(scr
->clip_icon
);
928 wGNOMEUpdateWorkspaceNamesHint(scr
);
931 wKWMUpdateWorkspaceNameHint(scr
, workspace
);
938 /* callback for when menu entry is edited */
940 onMenuEntryEdited(WMenu
*menu
, WMenuEntry
*entry
)
945 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
950 wWorkspaceMenuMake(WScreen
*scr
, Bool titled
)
954 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
956 wwarning(_("could not create Workspace menu"));
960 /* callback to be called when an entry is edited */
961 wsmenu
->on_edit
= onMenuEntryEdited
;
963 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
964 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
972 wWorkspaceMenuUpdate(WScreen
*scr
, WMenu
*menu
)
976 char title
[MAX_WORKSPACENAME_WIDTH
+1];
983 if (menu
->entry_no
< scr
->workspace_count
+2) {
984 /* new workspace(s) added */
985 i
= scr
->workspace_count
-(menu
->entry_no
-2);
986 ws
= menu
->entry_no
- 2;
988 strcpy(title
, scr
->workspaces
[ws
]->name
);
990 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)ws
);
991 entry
->flags
.indicator
= 1;
992 entry
->flags
.editable
= 1;
997 } else if (menu
->entry_no
> scr
->workspace_count
+2) {
998 /* removed workspace(s) */
999 for (i
= menu
->entry_no
-1; i
>= scr
->workspace_count
+2; i
--) {
1000 wMenuRemoveItem(menu
, i
);
1005 for (i
=0; i
<scr
->workspace_count
; i
++) {
1006 menu
->entries
[i
+2]->flags
.indicator_on
= 0;
1008 menu
->entries
[scr
->current_workspace
+2]->flags
.indicator_on
= 1;
1010 /* don't let user destroy current workspace */
1011 if (scr
->current_workspace
== scr
->workspace_count
-1) {
1012 wMenuSetEnabled(menu
, 1, False
);
1014 wMenuSetEnabled(menu
, 1, True
);
1017 tmp
= menu
->frame
->top_width
+ 5;
1018 /* if menu got unreachable, bring it to a visible place */
1019 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
1020 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
1027 wWorkspaceSaveState(WScreen
*scr
, proplist_t old_state
)
1029 proplist_t parr
, pstr
;
1030 proplist_t wks_state
, old_wks_state
;
1031 proplist_t foo
, bar
;
1036 old_wks_state
= PLGetDictionaryEntry(old_state
, dWorkspaces
);
1037 parr
= PLMakeArrayFromElements(NULL
);
1038 for (i
=0; i
< scr
->workspace_count
; i
++) {
1039 pstr
= PLMakeString(scr
->workspaces
[i
]->name
);
1040 wks_state
= PLMakeDictionaryFromEntries(dName
, pstr
, NULL
);
1042 if (!wPreferences
.flags
.noclip
) {
1043 pstr
= wClipSaveWorkspaceState(scr
, i
);
1044 PLInsertDictionaryEntry(wks_state
, dClip
, pstr
);
1046 } else if (old_wks_state
!=NULL
) {
1047 if ((foo
= PLGetArrayElement(old_wks_state
, i
))!=NULL
) {
1048 if ((bar
= PLGetDictionaryEntry(foo
, dClip
))!=NULL
) {
1049 PLInsertDictionaryEntry(wks_state
, dClip
, bar
);
1053 PLAppendArrayElement(parr
, wks_state
);
1054 PLRelease(wks_state
);
1056 PLInsertDictionaryEntry(scr
->session_state
, dWorkspaces
, parr
);
1062 wWorkspaceRestoreState(WScreen
*scr
)
1064 proplist_t parr
, pstr
, wks_state
;
1065 proplist_t clip_state
;
1070 parr
= PLGetDictionaryEntry(scr
->session_state
, dWorkspaces
);
1075 wscount
= scr
->workspace_count
;
1076 for (i
=0; i
< WMIN(PLGetNumberOfElements(parr
), MAX_WORKSPACES
); i
++) {
1077 wks_state
= PLGetArrayElement(parr
, i
);
1078 if (PLIsDictionary(wks_state
))
1079 pstr
= PLGetDictionaryEntry(wks_state
, dName
);
1082 if (i
>= scr
->workspace_count
)
1084 if (scr
->workspace_menu
) {
1085 wfree(scr
->workspace_menu
->entries
[i
+2]->text
);
1086 scr
->workspace_menu
->entries
[i
+2]->text
= wstrdup(PLGetString(pstr
));
1087 scr
->workspace_menu
->flags
.realized
= 0;
1089 wfree(scr
->workspaces
[i
]->name
);
1090 scr
->workspaces
[i
]->name
= wstrdup(PLGetString(pstr
));
1091 if (!wPreferences
.flags
.noclip
) {
1092 clip_state
= PLGetDictionaryEntry(wks_state
, dClip
);
1093 if (scr
->workspaces
[i
]->clip
)
1094 wDockDestroy(scr
->workspaces
[i
]->clip
);
1095 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
,
1098 wDockHideIcons(scr
->workspaces
[i
]->clip
);
1100 /* We set the global icons here, because scr->workspaces[i]->clip
1101 * was not valid in wDockRestoreState().
1102 * There we only set icon->omnipresent to know which icons we
1105 for (j
=0; j
<scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
1106 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
1108 if (aicon
&& aicon
->omnipresent
) {
1109 aicon
->omnipresent
= 0;
1110 wClipMakeIconOmnipresent(aicon
, True
);
1111 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1116 wKWMUpdateWorkspaceNameHint(scr
, i
);
1120 wGNOMEUpdateWorkspaceNamesHint(scr
);