1 /* screen.c - screen 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,
30 #include <X11/Xutil.h>
32 #include <X11/extensions/shape.h>
37 #include "WindowMaker.h"
38 #include "def_pixmaps.h"
45 #include "properties.h"
47 #include "resources.h"
48 #include "workspace.h"
57 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
58 |SubstructureNotifyMask|PointerMotionMask \
59 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
60 |KeyPressMask|KeyReleaseMask)
63 /**** Global variables ****/
65 extern Cursor wCursor
[WCUR_LAST
];
66 extern WPreferences wPreferences
;
67 extern Atom _XA_WINDOWMAKER_STATE
;
70 extern int wScreenCount
;
72 extern WDDomain
*WDWindowMaker
;
77 #define STIPPLE_WIDTH 2
78 #define STIPPLE_HEIGHT 2
79 static char STIPPLE_DATA
[] = {0x02, 0x01};
81 static int CantManageScreen
= 0;
83 static proplist_t dApplications
= NULL
;
84 static proplist_t dWorkspace
;
85 static proplist_t dDock
;
86 static proplist_t dClip
;
92 if (dApplications
!=NULL
)
95 dApplications
= PLMakeString("Applications");
96 dWorkspace
= PLMakeString("Workspace");
97 dDock
= PLMakeString("Dock");
98 dClip
= PLMakeString("Clip");
103 *----------------------------------------------------------------------
104 * alreadyRunningError--
105 * X error handler used to catch errors when trying to do
106 * XSelectInput() on the root window. These errors probably mean that
107 * there already is some other window manager running.
110 * Nothing, unless something really evil happens...
113 * CantManageScreen is set to 1;
114 *----------------------------------------------------------------------
117 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
119 CantManageScreen
= 1;
125 *----------------------------------------------------------------------
126 * allocButtonPixmaps--
127 * Allocate pixmaps used on window operation buttons (those in the
128 * titlebar). The pixmaps are linked to the program. If XPM is supported
129 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
135 * Allocates shared pixmaps for the screen. These pixmaps should
136 * not be freed by anybody.
137 *----------------------------------------------------------------------
140 allocButtonPixmaps(WScreen
*scr
)
144 /* create predefined pixmaps */
145 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
148 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
150 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
153 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
155 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
158 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
160 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
163 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
169 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
171 XSetForeground(dpy
, gc
, scr
->black_pixel
);
172 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
173 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
174 XSetForeground(dpy
, gc
, scr
->white_pixel
);
175 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
176 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
181 make3Dots(WScreen
*scr
)
189 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
190 wPreferences
.icon_size
, scr
->w_depth
);
191 XSetForeground(dpy
, gc
, scr
->black_pixel
);
192 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
193 wPreferences
.icon_size
);
194 XSetForeground(dpy
, gc
, scr
->white_pixel
);
195 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
196 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
197 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
199 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
200 wPreferences
.icon_size
, 1);
202 gcv
.graphics_exposures
= False
;
203 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
204 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
205 wPreferences
.icon_size
);
206 XSetForeground(dpy
, gc2
, 1);
207 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
208 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
209 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
213 wpix
= wPixmapCreate(scr
, pix
, mask
);
221 allocGCs(WScreen
*scr
)
225 unsigned long mtextcolor
;
228 scr
->stipple_bitmap
=
229 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
232 gcv
.stipple
= scr
->stipple_bitmap
;
233 gcv
.foreground
= scr
->white_pixel
;
234 gcv
.fill_style
= FillStippled
;
235 gcv
.graphics_exposures
= False
;
236 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
237 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
240 /* selected icon border GCs */
241 gcv
.function
= GXcopy
;
242 gcv
.foreground
= scr
->white_pixel
;
243 gcv
.background
= scr
->black_pixel
;
245 gcv
.line_style
= LineDoubleDash
;
246 gcv
.fill_style
= FillSolid
;
249 gcv
.graphics_exposures
= False
;
251 gcm
= GCFunction
| GCGraphicsExposures
;
252 gcm
|= GCForeground
| GCBackground
;
253 gcm
|= GCLineWidth
| GCLineStyle
;
255 gcm
|= GCDashOffset
| GCDashList
;
257 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
259 gcm
= GCForeground
|GCGraphicsExposures
;
261 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
262 gcv
.foreground
= scr
->white_pixel
;
263 gcv
.graphics_exposures
= False
;
264 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
266 scr
->mtext_pixel
= scr
->black_pixel
;
267 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
268 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
270 /* selected menu entry GC */
271 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
272 gcv
.foreground
= scr
->white_pixel
;
273 gcv
.background
= scr
->white_pixel
;
274 gcv
.graphics_exposures
= False
;
275 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
277 /* disabled menu entry GC */
278 scr
->dtext_pixel
= scr
->black_pixel
;
279 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
280 gcv
.stipple
= scr
->stipple_bitmap
;
281 gcv
.graphics_exposures
= False
;
282 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
285 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
286 gcv
.function
= GXxor
;
287 /* this will raise the probability of the XORed color being different
288 * of the original color in PseudoColor when not all color cells are
290 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
291 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
293 gcv
.plane_mask
= AllPlanes
;
294 gcv
.foreground
= color
.pixel
;
295 if (gcv
.foreground
== 0)
297 gcv
.line_width
= DEF_FRAME_THICKNESS
;
298 gcv
.subwindow_mode
= IncludeInferiors
;
299 gcv
.graphics_exposures
= False
;
300 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
301 |GCFunction
|GCSubwindowMode
|GCLineWidth
305 gcv
.foreground
= color
.pixel
;
307 if (gcv
.foreground
== 0)
308 /* XOR:ing with a zero is not going to be of much use, so
309 in that case, we somewhat arbitrarily xor with 17 instead. */
312 gcv
.function
= GXxor
;
313 gcv
.subwindow_mode
= IncludeInferiors
;
315 gcv
.cap_style
= CapRound
;
316 gcv
.graphics_exposures
= False
;
317 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
318 |GCGraphicsExposures
;
319 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
321 scr
->line_pixel
= gcv
.foreground
;
324 gcv
.foreground
= scr
->white_pixel
;
325 gcv
.background
= scr
->black_pixel
;
326 gcv
.graphics_exposures
= False
;
327 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
328 |GCGraphicsExposures
, &gcv
);
330 /* window title text GC */
331 gcv
.graphics_exposures
= False
;
332 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
335 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
338 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
340 /* move/size display GC */
341 gcv
.graphics_exposures
= False
;
342 gcm
= GCGraphicsExposures
;
343 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
345 /* misc drawing GC */
346 gcv
.graphics_exposures
= False
;
347 gcm
= GCGraphicsExposures
;
348 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
354 createPixmaps(WScreen
*scr
)
362 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
363 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
364 MENU_RADIO_INDICATOR_XBM_SIZE
,
365 MENU_RADIO_INDICATOR_XBM_SIZE
,
366 scr
->black_pixel
, scr
->white_pixel
);
369 scr
->menu_radio_indicator
= pix
;
372 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
373 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
374 MENU_CHECK_INDICATOR_XBM_SIZE
,
375 MENU_CHECK_INDICATOR_XBM_SIZE
,
376 scr
->black_pixel
, scr
->white_pixel
);
379 scr
->menu_check_indicator
= pix
;
381 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
382 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
383 MENU_MINI_INDICATOR_XBM_SIZE
,
384 MENU_MINI_INDICATOR_XBM_SIZE
,
385 scr
->black_pixel
, scr
->white_pixel
);
388 scr
->menu_mini_indicator
= pix
;
390 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
391 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
392 MENU_HIDE_INDICATOR_XBM_SIZE
,
393 MENU_HIDE_INDICATOR_XBM_SIZE
,
394 scr
->black_pixel
, scr
->white_pixel
);
397 scr
->menu_hide_indicator
= pix
;
399 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
400 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
401 MENU_SHADE_INDICATOR_XBM_SIZE
,
402 MENU_SHADE_INDICATOR_XBM_SIZE
,
403 scr
->black_pixel
, scr
->white_pixel
);
406 scr
->menu_shade_indicator
= pix
;
409 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
412 wwarning(_("could not load logo image for panels"));
414 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
415 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
417 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
418 image
->width
, image
->height
,
420 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
421 WMReleasePixmap(wmpix
);
423 RDestroyImage(image
);
426 if (!wPreferences
.flags
.nodock
|| !wPreferences
.flags
.noclip
) {
427 scr
->dock_dots
= make3Dots(scr
);
430 /* titlebar button pixmaps */
431 allocButtonPixmaps(scr
);
436 *----------------------------------------------------------------------
437 * createInternalWindows--
438 * Creates some windows used internally by the program. One to
439 * receive input focus when no other window can get it and another
440 * to display window geometry information during window resize/move.
446 * Windows are created and some colors are allocated for the
448 *----------------------------------------------------------------------
451 createInternalWindows(WScreen
*scr
)
454 XSetWindowAttributes attribs
;
456 /* window for displaying geometry information during resizes and moves */
457 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
458 attribs
.border_pixel
= 0;
459 attribs
.save_under
= True
;
460 attribs
.override_redirect
= True
;
461 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
462 attribs
.background_pixmap
= None
;
463 if (scr
->resizebar_texture
[0])
464 attribs
.background_pixel
= scr
->resizebar_texture
[0]->normal
.pixel
;
466 attribs
.background_pixel
= scr
->light_pixel
;
468 attribs
.colormap
= scr
->w_colormap
;
470 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
471 &scr
->geometry_display_height
);
472 scr
->geometry_display
=
473 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
474 scr
->geometry_display_width
,
475 scr
->geometry_display_height
,
476 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
479 /* InputOnly window to get the focus when no other window can get it */
480 vmask
= CWEventMask
|CWOverrideRedirect
;
481 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
482 attribs
.override_redirect
= True
;
483 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
484 InputOnly
,CopyFromParent
, vmask
, &attribs
);
485 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
486 XMapWindow(dpy
, scr
->no_focus_win
);
488 XSetInputFocus (dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
490 /* shadow window for dock buttons */
491 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
492 attribs
.border_pixel
= 0;
493 attribs
.save_under
= True
;
494 attribs
.override_redirect
= True
;
495 attribs
.background_pixmap
= None
;
496 attribs
.background_pixel
= scr
->white_pixel
;
498 attribs
.colormap
= scr
->w_colormap
;
500 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
501 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
502 scr
->w_visual
, vmask
, &attribs
);
504 /* workspace name balloon for clip */
505 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
;
506 attribs
.save_under
= True
;
507 attribs
.override_redirect
= True
;
508 attribs
.colormap
= scr
->w_colormap
;
509 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
511 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
512 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
514 * If the window is clicked without having ButtonPress selected, the
515 * resulting event will have event.xbutton.window == root.
517 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
522 *----------------------------------------------------------------------
524 * Initializes the window manager for the given screen and
525 * allocates a WScreen descriptor for it. Many resources are allocated
526 * for the screen and the root window is setup appropriately.
529 * The WScreen descriptor for the screen.
532 * Many resources are allocated and the IconSize property is
533 * set on the root window.
534 * The program can be aborted if some fatal error occurs.
536 * TODO: User specifiable visual.
537 *----------------------------------------------------------------------
540 wScreenInit(int screen_number
)
543 XIconSize icon_size
[1];
544 RContextAttributes rattr
;
545 extern int wVisualID
;
548 XErrorHandler oldHandler
;
550 scr
= wmalloc(sizeof(WScreen
));
551 memset(scr
, 0, sizeof(WScreen
));
553 /* initialize globals */
554 scr
->screen
= screen_number
;
555 scr
->root_win
= RootWindow(dpy
, screen_number
);
556 scr
->depth
= DefaultDepth(dpy
, screen_number
);
557 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
559 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
560 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
562 CantManageScreen
= 0;
563 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
565 event_mask
= EVENT_MASK
;
567 if (wPreferences
.disable_root_mouse
)
568 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
569 XSelectInput(dpy
, scr
->root_win
, event_mask
);
572 XSetErrorHandler(oldHandler
);
574 if (CantManageScreen
) {
579 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
581 /* screen descriptor for raster graphic library */
582 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
583 rattr
.render_mode
= wPreferences
.no_dithering
?RM_MATCH
:RM_DITHER
;
584 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
585 if (rattr
.colors_per_channel
<2)
586 rattr
.colors_per_channel
= 2;
589 rattr
.flags
|= RC_VisualID
;
590 rattr
.visualid
= wVisualID
;
592 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
593 if (!scr
->rcontext
) {
594 wwarning(_("could not initialize graphics library context: %s"),
595 RMessageForError(RErrorCode
));
601 formats
= RSupportedFileFormats();
603 for (i
=0; formats
[i
]!=NULL
; i
++) {
604 if (strcmp(formats
[i
], "TIFF")==0) {
605 scr
->flags
.supports_tiff
= 1;
609 RFreeStringList(formats
);
613 scr
->w_win
= scr
->rcontext
->drawable
;
614 scr
->w_visual
= scr
->rcontext
->visual
;
615 scr
->w_depth
= scr
->rcontext
->depth
;
616 scr
->w_colormap
= scr
->rcontext
->cmap
;
618 scr
->black_pixel
= scr
->rcontext
->black
;
619 scr
->white_pixel
= scr
->rcontext
->white
;
621 /* create screen descriptor for WINGs */
622 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
625 color
= WMGrayColor(scr
->wmscreen
);
626 scr
->light_pixel
= WMColorPixel(color
);
627 WMReleaseColor(color
);
629 color
= WMDarkGrayColor(scr
->wmscreen
);
630 scr
->dark_pixel
= WMColorPixel(color
);
631 WMReleaseColor(color
);
635 /* frame boder color */
636 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
637 scr
->frame_border_pixel
= xcol
.pixel
;
640 /* create GCs with default values */
643 /* read defaults for this screen */
644 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
646 /* create initial workspace */
649 createInternalWindows(scr
);
651 /* create shared pixmaps */
654 /* set icon sizes we can accept from clients */
655 icon_size
[0].min_width
= 8;
656 icon_size
[0].min_height
= 8;
657 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
658 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
659 icon_size
[0].width_inc
= 1;
660 icon_size
[0].height_inc
= 1;
661 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
663 /* setup WindowMaker protocols property in the root window*/
664 PropSetWMakerProtocols(scr
->root_win
);
667 /* initialize balloon text stuff */
668 wBalloonInitialize(scr
);
671 /* kluge to load menu configurations at startup */
672 OpenRootMenu(scr
, -10000, -10000, False
);
673 wMenuUnmap(scr
->root_menu
);
680 wScreenRestoreState(WScreen
*scr
)
687 if (wScreenCount
== 1)
688 path
= wdefaultspathfordomain("WMState");
691 sprintf(buf
, "WMState.%i", scr
->screen
);
692 path
= wdefaultspathfordomain(buf
);
694 scr
->session_state
= PLGetProplistWithPath(path
);
696 if (!scr
->session_state
&& wScreenCount
>1) {
698 sprintf(buf
, "WMState.%i", scr
->screen
);
699 path
= wdefaultspathfordomain(buf
);
700 scr
->session_state
= PLGetProplistWithPath(path
);
704 if (!wPreferences
.flags
.noclip
) {
705 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
706 scr
->clip_icon
= wClipRestoreState(scr
, state
);
709 wWorkspaceRestoreState(scr
);
711 if (!wPreferences
.flags
.nodock
) {
712 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
713 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
720 wScreenSaveState(WScreen
*scr
)
722 WWorkspaceState wstate
;
725 proplist_t path
, old_state
, foo
;
732 * Save current workspace, so can go back to it upon restart.
734 wstate
.workspace
= scr
->current_workspace
;
736 data
[0] = wstate
.flags
;
737 data
[1] = wstate
.workspace
;
739 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
740 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
741 (unsigned char *) data
, 2);
743 /* save state of windows */
744 wwin
= scr
->focused_window
;
746 wWindowSaveState(wwin
);
750 old_state
= scr
->session_state
;
751 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
753 PLSetStringCmpHook(NULL
);
755 /* save dock state to file */
756 if (!wPreferences
.flags
.nodock
) {
759 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
760 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
763 if (!wPreferences
.flags
.noclip
) {
766 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
767 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
771 wWorkspaceSaveState(scr
, old_state
);
773 if (wPreferences
.save_session_on_exit
) {
774 wSessionSaveState(scr
);
776 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
777 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
779 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
780 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
785 PLSetStringCmpHook(StringCompareHook
);
789 if (wScreenCount
== 1)
790 str
= wdefaultspathfordomain("WMState");
793 sprintf(buf
, "WMState.%i", scr
->screen
);
794 str
= wdefaultspathfordomain(buf
);
796 path
= PLMakeString(str
);
798 PLSetFilename(scr
->session_state
, path
);
799 PLSave(scr
->session_state
, YES
);
801 PLRelease(old_state
);
807 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
823 *x
= -tol_w
, moved
= 1;
824 else if (*x
>= scr
->scr_width
- 10)
825 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
827 if (*y
< -height
+ 10)
828 *y
= -tol_h
, moved
= 1;
829 else if (*y
>= scr
->scr_height
- 10)
830 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;