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
);
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 wfree(scr
->workspaces
[i
]->name
);
185 wfree(scr
->workspaces
[i
]);
188 wfree(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 wfree(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 wfree(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
)
643 XSetWindowAttributes attribs
;
645 puts("wWorkspaceManageEdge()");
646 if (wPreferences
.vedge_thickness
) {
648 for (w
= 0; w
< scr
->workspace_count
; w
++) {
649 puts("reset workspace");
650 wWorkspaceResizeViewPort(scr
, w
, wPreferences
.vedge_maxwidth
, wPreferences
.vedge_maxheight
);
651 wWorkspaceSetViewPort(scr
, w
, 0, 0);
654 vmask
= CWEventMask
|CWOverrideRedirect
;
655 attribs
.event_mask
= (EnterWindowMask
| LeaveWindowMask
| VisibilityChangeMask
);
656 attribs
.override_redirect
= True
;
657 scr
->virtual_edge_u
=
658 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
659 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
660 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
661 scr
->virtual_edge_d
=
662 XCreateWindow(dpy
, scr
->root_win
, 0, scr
->scr_height
-wPreferences
.vedge_thickness
,
663 scr
->scr_width
, wPreferences
.vedge_thickness
, 0,
664 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
665 scr
->virtual_edge_l
=
666 XCreateWindow(dpy
, scr
->root_win
, 0, 0,
667 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
668 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
669 scr
->virtual_edge_r
=
670 XCreateWindow(dpy
, scr
->root_win
, scr
->scr_width
-wPreferences
.vedge_thickness
, 0,
671 wPreferences
.vedge_thickness
, scr
->scr_height
, 0,
672 CopyFromParent
, InputOnly
, CopyFromParent
, vmask
, &attribs
);
673 XMapWindow(dpy
, scr
->virtual_edge_u
);
674 XMapWindow(dpy
, scr
->virtual_edge_d
);
675 XMapWindow(dpy
, scr
->virtual_edge_l
);
676 XMapWindow(dpy
, scr
->virtual_edge_r
);
677 wWorkspaceRaiseEdge(scr
);
681 void wWorkspaceRaiseEdge(WScreen
*scr
)
683 if (wPreferences
.vedge_thickness
&& initVDesk
) {
684 XRaiseWindow(dpy
, scr
->virtual_edge_u
);
685 XRaiseWindow(dpy
, scr
->virtual_edge_d
);
686 XRaiseWindow(dpy
, scr
->virtual_edge_l
);
687 XRaiseWindow(dpy
, scr
->virtual_edge_r
);
691 void wWorkspaceResizeViewPort(WScreen
*scr
, int workspace
, int width
, int height
)
693 scr
->workspaces
[workspace
]->width
= WMAX(width
,scr
->scr_width
);
694 scr
->workspaces
[workspace
]->height
= WMAX(height
,scr
->scr_height
);
698 void wWorkspaceAdjustViewPort(WScreen
*scr
, int workspace
, int view_x
, int view_y
)
702 int lay_left
, lay_right
, lay_top
, lay_bottom
;
705 lay_left
= lay_top
= 0;
706 lay_right
= scr
->scr_width
;
707 lay_bottom
= scr
->scr_height
;
709 diff_x
= scr
->workspaces
[workspace
]->view_x
- view_x
;
710 diff_y
= scr
->workspaces
[workspace
]->view_y
- view_y
;
712 if (!diff_x
&& !diff_y
) return;
714 wwin
= scr
->focused_window
;
716 if (wwin
->frame_x
< lay_left
) { /* record positions */
717 lay_left
= wwin
->frame_x
;
718 } else if (wwin
->frame_x
+ wwin
->frame
->core
->width
> lay_right
) {
719 lay_right
= wwin
->frame_x
+ wwin
->frame
->core
->width
;
722 if (wwin
->frame_y
< lay_top
) {
723 lay_top
= wwin
->frame_y
;
724 } else if (wwin
->frame_y
+ wwin
->frame
->core
->height
> lay_bottom
) {
725 lay_top
= wwin
->frame_y
+ wwin
->frame
->core
->height
;
729 if (wwin
->frame
->workspace
== workspace
) {
730 wWindowMove(wwin
, wwin
->frame_x
+ diff_x
, wwin
->frame_y
+ diff_y
);
731 wWindowSynthConfigureNotify(wwin
);
736 if (scr
->workspaces
[workspace
]->view_x
< 0) {
737 scr
->workspaces
[workspace
]->width
-= view_x
;
738 scr
->workspaces
[workspace
]->view_x
= 0;
739 } else if (scr
->workspaces
[workspace
]->view_x
> scr
->workspaces
[workspace
]->width
- scr
->scr_width
) {
740 scr
->workspaces
[workspace
]->width
= scr
->workspaces
[workspace
]->view_x
+ scr
->scr_width
;
743 if (scr
->workspaces
[workspace
]->view_x
> lay_left
) {
744 /* should do lay_left + some very big edge here so users can have their own blank area*/
745 scr
->workspaces
[workspace
]->width
-= scr
->workspaces
[workspace
]->view_x
- lay_left
;
746 scr
->workspaces
[workspace
]->view_x
= lay_left
;
748 if (scr
->workspaces
[workspace
]->view_x
+ scr
->scr_width
> lay_right
) {
749 scr
->workspaces
[workspace
]->width
-= scr
->workspaces
[workspace
]->view_x
+ scr
->scr_width
- lay_right
;
752 if (scr
->workspaces
[workspace
]->view_y
< 0) {
753 scr
->workspaces
[workspace
]->height
-= view_y
;
754 scr
->workspaces
[workspace
]->view_y
= 0;
755 } else if (scr
->workspaces
[workspace
]->view_y
> scr
->workspaces
[workspace
]->height
- scr
->scr_height
) {
756 scr
->workspaces
[workspace
]->height
= scr
->workspaces
[workspace
]->view_y
+ scr
->scr_height
;
759 if (scr
->workspaces
[workspace
]->view_y
> lay_top
) {
760 /* should do lay_left + some very big edge here so users can have their own blank area*/
761 scr
->workspaces
[workspace
]->height
-= scr
->workspaces
[workspace
]->view_y
- lay_top
;
762 scr
->workspaces
[workspace
]->view_y
= lay_top
;
764 if (scr
->workspaces
[workspace
]->view_y
+ scr
->scr_height
> lay_bottom
) {
765 scr
->workspaces
[workspace
]->height
-= scr
->workspaces
[workspace
]->view_y
+ scr
->scr_height
- lay_left
;
768 scr
->workspaces
[workspace
]->view_x
= WMIN(view_x
, scr
->workspaces
[workspace
]->width
- scr
->scr_width
);
769 scr
->workspaces
[workspace
]->view_y
= WMIN(view_y
, scr
->workspaces
[workspace
]->height
- scr
->scr_height
);
773 printf("set view %d %d, %d\n",
774 workspace, scr->workspaces[workspace]->view_x, scr->workspaces[workspace]->view_y);
779 void wWorkspaceSetViewPort(WScreen
*scr
, int workspace
, int view_x
, int view_y
)
782 if (view_x
< 0) view_x
= 0;
783 else if (view_x
> scr
->workspaces
[workspace
]->width
- scr
->scr_width
)
784 view_x
= scr
->workspaces
[workspace
]->width
- scr
->scr_width
;
786 if (view_y
< 0) view_y
= 0;
787 else if (view_y
> scr
->workspaces
[workspace
]->width
- scr
->scr_height
)
788 view_y
= scr
->workspaces
[workspace
]->width
- scr
->scr_height
;
790 wWorkspaceAdjustViewPort(scr
, workspace
, view_x
, view_y
);
793 void wWorkspaceGetViewPosition(WScreen
*scr
, int workspace
, int *view_x
, int *view_y
) {
794 if (view_x
) *view_x
= scr
->workspaces
[workspace
]->view_x
;
795 if (view_y
) *view_y
= scr
->workspaces
[workspace
]->view_y
;
801 switchWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
803 wWorkspaceChange(menu
->frame
->screen_ptr
, (long)entry
->clientdata
);
809 deleteWSCommand(WMenu
*menu
, WMenuEntry
*entry
)
811 wWorkspaceDelete(menu
->frame
->screen_ptr
,
812 menu
->frame
->screen_ptr
->workspace_count
-1);
818 newWSCommand(WMenu
*menu
, WMenuEntry
*foo
)
822 ws
= wWorkspaceNew(menu
->frame
->screen_ptr
);
823 /* autochange workspace*/
825 wWorkspaceChange(menu
->frame
->screen_ptr
, ws
);
831 if (wKeyBindings[WKBD_WORKSPACE1+ws]) {
832 kcode = wKeyBindings[WKBD_WORKSPACE1+ws]->keycode;
834 wstrdup(XKeysymToString(XKeycodeToKeysym(dpy, kcode, 0)));
849 end
= &(line
[strlen(line
)])-1;
850 while (isspace(*line
) && *line
!=0) line
++;
851 while (isspace(*end
) && end
!=line
) {
860 wWorkspaceRename(WScreen
*scr
, int workspace
, char *name
)
862 char buf
[MAX_WORKSPACENAME_WIDTH
+1];
865 if (workspace
>= scr
->workspace_count
)
868 /* trim white spaces */
869 tmp
= cropline(name
);
871 if (strlen(tmp
)==0) {
872 sprintf(buf
, _("Workspace %i"), workspace
+1);
874 strncpy(buf
, tmp
, MAX_WORKSPACENAME_WIDTH
);
876 buf
[MAX_WORKSPACENAME_WIDTH
] = 0;
878 /* update workspace */
879 wfree(scr
->workspaces
[workspace
]->name
);
880 scr
->workspaces
[workspace
]->name
= wstrdup(buf
);
882 if (scr
->clip_ws_menu
) {
883 if (strcmp(scr
->clip_ws_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
884 wfree(scr
->clip_ws_menu
->entries
[workspace
+2]->text
);
885 scr
->clip_ws_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
886 wMenuRealize(scr
->clip_ws_menu
);
889 if (scr
->workspace_menu
) {
890 if (strcmp(scr
->workspace_menu
->entries
[workspace
+2]->text
, buf
)!=0) {
891 wfree(scr
->workspace_menu
->entries
[workspace
+2]->text
);
892 scr
->workspace_menu
->entries
[workspace
+2]->text
= wstrdup(buf
);
893 wMenuRealize(scr
->workspace_menu
);
897 UpdateSwitchMenuWorkspace(scr
, workspace
);
900 wClipIconPaint(scr
->clip_icon
);
903 wGNOMEUpdateWorkspaceNamesHint(scr
);
906 wKWMUpdateWorkspaceNameHint(scr
, workspace
);
913 /* callback for when menu entry is edited */
915 onMenuEntryEdited(WMenu
*menu
, WMenuEntry
*entry
)
920 wWorkspaceRename(menu
->frame
->screen_ptr
, (long)entry
->clientdata
, tmp
);
925 wWorkspaceMenuMake(WScreen
*scr
, Bool titled
)
929 wsmenu
= wMenuCreate(scr
, titled
? _("Workspaces") : NULL
, False
);
931 wwarning(_("could not create Workspace menu"));
935 /* callback to be called when an entry is edited */
936 wsmenu
->on_edit
= onMenuEntryEdited
;
938 wMenuAddCallback(wsmenu
, _("New"), newWSCommand
, NULL
);
939 wMenuAddCallback(wsmenu
, _("Destroy Last"), deleteWSCommand
, NULL
);
947 wWorkspaceMenuUpdate(WScreen
*scr
, WMenu
*menu
)
951 char title
[MAX_WORKSPACENAME_WIDTH
+1];
958 if (menu
->entry_no
< scr
->workspace_count
+2) {
959 /* new workspace(s) added */
960 i
= scr
->workspace_count
-(menu
->entry_no
-2);
961 ws
= menu
->entry_no
- 2;
963 strcpy(title
, scr
->workspaces
[ws
]->name
);
965 entry
= wMenuAddCallback(menu
, title
, switchWSCommand
, (void*)ws
);
966 entry
->flags
.indicator
= 1;
967 entry
->flags
.editable
= 1;
972 } else if (menu
->entry_no
> scr
->workspace_count
+2) {
973 /* removed workspace(s) */
974 for (i
= menu
->entry_no
-1; i
>= scr
->workspace_count
+2; i
--) {
975 wMenuRemoveItem(menu
, i
);
980 for (i
=0; i
<scr
->workspace_count
; i
++) {
981 menu
->entries
[i
+2]->flags
.indicator_on
= 0;
983 menu
->entries
[scr
->current_workspace
+2]->flags
.indicator_on
= 1;
985 /* don't let user destroy current workspace */
986 if (scr
->current_workspace
== scr
->workspace_count
-1) {
987 wMenuSetEnabled(menu
, 1, False
);
989 wMenuSetEnabled(menu
, 1, True
);
992 tmp
= menu
->frame
->top_width
+ 5;
993 /* if menu got unreachable, bring it to a visible place */
994 if (menu
->frame_x
< tmp
- (int)menu
->frame
->core
->width
)
995 wMenuMove(menu
, tmp
- (int)menu
->frame
->core
->width
, menu
->frame_y
, False
);
1002 wWorkspaceSaveState(WScreen
*scr
, proplist_t old_state
)
1004 proplist_t parr
, pstr
;
1005 proplist_t wks_state
, old_wks_state
;
1006 proplist_t foo
, bar
;
1011 old_wks_state
= PLGetDictionaryEntry(old_state
, dWorkspaces
);
1012 parr
= PLMakeArrayFromElements(NULL
);
1013 for (i
=0; i
< scr
->workspace_count
; i
++) {
1014 pstr
= PLMakeString(scr
->workspaces
[i
]->name
);
1015 wks_state
= PLMakeDictionaryFromEntries(dName
, pstr
, NULL
);
1017 if (!wPreferences
.flags
.noclip
) {
1018 pstr
= wClipSaveWorkspaceState(scr
, i
);
1019 PLInsertDictionaryEntry(wks_state
, dClip
, pstr
);
1021 } else if (old_wks_state
!=NULL
) {
1022 if ((foo
= PLGetArrayElement(old_wks_state
, i
))!=NULL
) {
1023 if ((bar
= PLGetDictionaryEntry(foo
, dClip
))!=NULL
) {
1024 PLInsertDictionaryEntry(wks_state
, dClip
, bar
);
1028 PLAppendArrayElement(parr
, wks_state
);
1029 PLRelease(wks_state
);
1031 PLInsertDictionaryEntry(scr
->session_state
, dWorkspaces
, parr
);
1037 wWorkspaceRestoreState(WScreen
*scr
)
1039 proplist_t parr
, pstr
, wks_state
;
1040 proplist_t clip_state
;
1045 parr
= PLGetDictionaryEntry(scr
->session_state
, dWorkspaces
);
1050 wscount
= scr
->workspace_count
;
1051 for (i
=0; i
< WMIN(PLGetNumberOfElements(parr
), MAX_WORKSPACES
); i
++) {
1052 wks_state
= PLGetArrayElement(parr
, i
);
1053 if (PLIsDictionary(wks_state
))
1054 pstr
= PLGetDictionaryEntry(wks_state
, dName
);
1057 if (i
>= scr
->workspace_count
)
1059 if (scr
->workspace_menu
) {
1060 wfree(scr
->workspace_menu
->entries
[i
+2]->text
);
1061 scr
->workspace_menu
->entries
[i
+2]->text
= wstrdup(PLGetString(pstr
));
1062 scr
->workspace_menu
->flags
.realized
= 0;
1064 wfree(scr
->workspaces
[i
]->name
);
1065 scr
->workspaces
[i
]->name
= wstrdup(PLGetString(pstr
));
1066 if (!wPreferences
.flags
.noclip
) {
1067 clip_state
= PLGetDictionaryEntry(wks_state
, dClip
);
1068 if (scr
->workspaces
[i
]->clip
)
1069 wDockDestroy(scr
->workspaces
[i
]->clip
);
1070 scr
->workspaces
[i
]->clip
= wDockRestoreState(scr
, clip_state
,
1073 wDockHideIcons(scr
->workspaces
[i
]->clip
);
1075 /* We set the global icons here, because scr->workspaces[i]->clip
1076 * was not valid in wDockRestoreState().
1077 * There we only set icon->omnipresent to know which icons we
1080 for (j
=0; j
<scr
->workspaces
[i
]->clip
->max_icons
; j
++) {
1081 WAppIcon
*aicon
= scr
->workspaces
[i
]->clip
->icon_array
[j
];
1083 if (aicon
&& aicon
->omnipresent
) {
1084 aicon
->omnipresent
= 0;
1085 wClipMakeIconOmnipresent(aicon
, True
);
1086 XMapWindow(dpy
, aicon
->icon
->core
->window
);
1091 wKWMUpdateWorkspaceNameHint(scr
, i
);
1095 wGNOMEUpdateWorkspaceNamesHint(scr
);