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
;
69 extern int wScreenCount
;
71 extern WDDomain
*WDWindowMaker
;
76 #define STIPPLE_WIDTH 2
77 #define STIPPLE_HEIGHT 2
78 static char STIPPLE_DATA
[] = {0x02, 0x01};
80 static int CantManageScreen
= 0;
82 static proplist_t dApplications
= NULL
;
83 static proplist_t dWorkspace
;
84 static proplist_t dDock
;
85 static proplist_t dClip
;
91 if (dApplications
!=NULL
)
94 dApplications
= PLMakeString("Applications");
95 dWorkspace
= PLMakeString("Workspace");
96 dDock
= PLMakeString("Dock");
97 dClip
= PLMakeString("Clip");
102 *----------------------------------------------------------------------
103 * alreadyRunningError--
104 * X error handler used to catch errors when trying to do
105 * XSelectInput() on the root window. These errors probably mean that
106 * there already is some other window manager running.
109 * Nothing, unless something really evil happens...
112 * CantManageScreen is set to 1;
113 *----------------------------------------------------------------------
116 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
118 CantManageScreen
= 1;
124 *----------------------------------------------------------------------
125 * allocButtonPixmaps--
126 * Allocate pixmaps used on window operation buttons (those in the
127 * titlebar). The pixmaps are linked to the program. If XPM is supported
128 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
134 * Allocates shared pixmaps for the screen. These pixmaps should
135 * not be freed by anybody.
136 *----------------------------------------------------------------------
139 allocButtonPixmaps(WScreen
*scr
)
143 /* create predefined pixmaps */
144 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
147 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
149 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
152 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
154 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
157 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
159 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
162 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
168 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
170 XSetForeground(dpy
, gc
, scr
->black_pixel
);
171 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
172 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
173 XSetForeground(dpy
, gc
, scr
->white_pixel
);
174 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
175 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
180 make3Dots(WScreen
*scr
)
188 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
189 wPreferences
.icon_size
, scr
->w_depth
);
190 XSetForeground(dpy
, gc
, scr
->black_pixel
);
191 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
192 wPreferences
.icon_size
);
193 XSetForeground(dpy
, gc
, scr
->white_pixel
);
194 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
195 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
196 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
198 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
199 wPreferences
.icon_size
, 1);
201 gcv
.graphics_exposures
= False
;
202 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
203 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
204 wPreferences
.icon_size
);
205 XSetForeground(dpy
, gc2
, 1);
206 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
207 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
208 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
212 wpix
= wPixmapCreate(scr
, pix
, mask
);
220 allocGCs(WScreen
*scr
)
224 unsigned long mtextcolor
;
227 scr
->stipple_bitmap
=
228 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
231 gcv
.stipple
= scr
->stipple_bitmap
;
232 gcv
.foreground
= scr
->white_pixel
;
233 gcv
.fill_style
= FillStippled
;
234 gcv
.graphics_exposures
= False
;
235 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
236 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
239 /* selected icon border GCs */
240 gcv
.function
= GXcopy
;
241 gcv
.foreground
= scr
->white_pixel
;
242 gcv
.background
= scr
->black_pixel
;
244 gcv
.line_style
= LineDoubleDash
;
245 gcv
.fill_style
= FillSolid
;
248 gcv
.graphics_exposures
= False
;
250 gcm
= GCFunction
| GCGraphicsExposures
;
251 gcm
|= GCForeground
| GCBackground
;
252 gcm
|= GCLineWidth
| GCLineStyle
;
254 gcm
|= GCDashOffset
| GCDashList
;
256 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
258 gcm
= GCForeground
|GCGraphicsExposures
;
260 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
261 gcv
.foreground
= scr
->white_pixel
;
262 gcv
.graphics_exposures
= False
;
263 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
265 scr
->mtext_pixel
= scr
->black_pixel
;
266 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
267 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
269 /* selected menu entry GC */
270 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
271 gcv
.foreground
= scr
->white_pixel
;
272 gcv
.background
= scr
->white_pixel
;
273 gcv
.graphics_exposures
= False
;
274 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
276 /* disabled menu entry GC */
277 scr
->dtext_pixel
= scr
->black_pixel
;
278 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
279 gcv
.stipple
= scr
->stipple_bitmap
;
280 gcv
.graphics_exposures
= False
;
281 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
284 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
286 gcv
.foreground
= color
.pixel
;
287 gcv
.function
= GXxor
;
288 gcv
.line_width
= DEF_FRAME_THICKNESS
;
289 gcv
.subwindow_mode
= IncludeInferiors
;
290 gcv
.graphics_exposures
= False
;
291 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
292 |GCFunction
|GCSubwindowMode
|GCLineWidth
, &gcv
);
295 gcv
.foreground
= color
.pixel
;
297 if (gcv
.foreground
== 0)
298 /* XOR:ing with a zero is not going to be of much use, so
299 in that case, we somewhat arbitrarily xor with 17 instead. */
302 gcv
.function
= GXxor
;
303 gcv
.subwindow_mode
= IncludeInferiors
;
305 gcv
.cap_style
= CapRound
;
306 gcv
.graphics_exposures
= False
;
307 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
308 |GCGraphicsExposures
;
309 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
311 scr
->line_pixel
= gcv
.foreground
;
314 gcv
.foreground
= scr
->white_pixel
;
315 gcv
.background
= scr
->black_pixel
;
316 gcv
.graphics_exposures
= False
;
317 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
318 |GCGraphicsExposures
, &gcv
);
320 /* window title text GC */
321 gcv
.graphics_exposures
= False
;
322 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
325 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
328 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
330 /* move/size display GC */
331 gcv
.graphics_exposures
= False
;
332 gcm
= GCGraphicsExposures
;
333 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
335 /* misc drawing GC */
336 gcv
.graphics_exposures
= False
;
337 gcm
= GCGraphicsExposures
;
338 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
344 createPixmaps(WScreen
*scr
)
352 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
353 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
354 MENU_RADIO_INDICATOR_XBM_SIZE
,
355 MENU_RADIO_INDICATOR_XBM_SIZE
,
356 scr
->black_pixel
, scr
->white_pixel
);
359 scr
->menu_radio_indicator
= pix
;
362 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
363 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
364 MENU_CHECK_INDICATOR_XBM_SIZE
,
365 MENU_CHECK_INDICATOR_XBM_SIZE
,
366 scr
->black_pixel
, scr
->white_pixel
);
369 scr
->menu_check_indicator
= pix
;
371 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
372 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
373 MENU_MINI_INDICATOR_XBM_SIZE
,
374 MENU_MINI_INDICATOR_XBM_SIZE
,
375 scr
->black_pixel
, scr
->white_pixel
);
378 scr
->menu_mini_indicator
= pix
;
380 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
381 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
382 MENU_HIDE_INDICATOR_XBM_SIZE
,
383 MENU_HIDE_INDICATOR_XBM_SIZE
,
384 scr
->black_pixel
, scr
->white_pixel
);
387 scr
->menu_hide_indicator
= pix
;
389 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
390 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
391 MENU_SHADE_INDICATOR_XBM_SIZE
,
392 MENU_SHADE_INDICATOR_XBM_SIZE
,
393 scr
->black_pixel
, scr
->white_pixel
);
396 scr
->menu_shade_indicator
= pix
;
399 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
402 wwarning(_("could not load logo image for panels"));
404 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
405 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
407 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
408 image
->width
, image
->height
,
410 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
411 WMReleasePixmap(wmpix
);
413 RDestroyImage(image
);
416 if (!wPreferences
.flags
.nodock
|| !wPreferences
.flags
.noclip
) {
417 scr
->dock_dots
= make3Dots(scr
);
420 /* titlebar button pixmaps */
421 allocButtonPixmaps(scr
);
426 *----------------------------------------------------------------------
427 * createInternalWindows--
428 * Creates some windows used internally by the program. One to
429 * receive input focus when no other window can get it and another
430 * to display window geometry information during window resize/move.
436 * Windows are created and some colors are allocated for the
438 *----------------------------------------------------------------------
441 createInternalWindows(WScreen
*scr
)
444 XSetWindowAttributes attribs
;
446 /* window for displaying geometry information during resizes and moves */
447 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
448 attribs
.border_pixel
= 0;
449 attribs
.save_under
= True
;
450 attribs
.override_redirect
= True
;
451 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
452 attribs
.background_pixmap
= None
;
453 if (scr
->resizebar_texture
[0])
454 attribs
.background_pixel
= scr
->resizebar_texture
[0]->normal
.pixel
;
456 attribs
.background_pixel
= scr
->light_pixel
;
458 attribs
.colormap
= scr
->w_colormap
;
460 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
461 &scr
->geometry_display_height
);
462 scr
->geometry_display
=
463 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
464 scr
->geometry_display_width
,
465 scr
->geometry_display_height
,
466 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
469 /* InputOnly window to get the focus when no other window can get it */
470 vmask
= CWEventMask
|CWOverrideRedirect
;
471 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
472 attribs
.override_redirect
= True
;
473 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
474 InputOnly
,CopyFromParent
, vmask
, &attribs
);
475 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
476 XMapWindow(dpy
, scr
->no_focus_win
);
478 XSetInputFocus (dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
480 /* shadow window for dock buttons */
481 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
482 attribs
.border_pixel
= 0;
483 attribs
.save_under
= True
;
484 attribs
.override_redirect
= True
;
485 attribs
.background_pixmap
= None
;
486 attribs
.background_pixel
= scr
->white_pixel
;
488 attribs
.colormap
= scr
->w_colormap
;
490 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
491 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
492 scr
->w_visual
, vmask
, &attribs
);
494 /* workspace name balloon for clip */
495 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
;
496 attribs
.save_under
= True
;
497 attribs
.override_redirect
= True
;
498 attribs
.colormap
= scr
->w_colormap
;
499 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
501 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
502 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
504 * If the window is clicked without having ButtonPress selected, the
505 * resulting event will have event.xbutton.window == root.
507 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
512 *----------------------------------------------------------------------
514 * Initializes the window manager for the given screen and
515 * allocates a WScreen descriptor for it. Many resources are allocated
516 * for the screen and the root window is setup appropriately.
519 * The WScreen descriptor for the screen.
522 * Many resources are allocated and the IconSize property is
523 * set on the root window.
524 * The program can be aborted if some fatal error occurs.
526 * TODO: User specifiable visual.
527 *----------------------------------------------------------------------
530 wScreenInit(int screen_number
)
533 XIconSize icon_size
[1];
534 RContextAttributes rattr
;
535 extern int wVisualID
;
538 XErrorHandler oldHandler
;
540 scr
= wmalloc(sizeof(WScreen
));
541 memset(scr
, 0, sizeof(WScreen
));
543 /* initialize globals */
544 scr
->screen
= screen_number
;
545 scr
->root_win
= RootWindow(dpy
, screen_number
);
546 scr
->depth
= DefaultDepth(dpy
, screen_number
);
547 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
549 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
550 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
552 CantManageScreen
= 0;
553 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
555 event_mask
= EVENT_MASK
;
557 if (wPreferences
.disable_root_mouse
)
558 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
559 XSelectInput(dpy
, scr
->root_win
, event_mask
);
562 XSetErrorHandler(oldHandler
);
564 if (CantManageScreen
) {
569 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
571 /* screen descriptor for raster graphic library */
572 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
573 rattr
.render_mode
= wPreferences
.no_dithering
?RM_MATCH
:RM_DITHER
;
574 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
575 if (rattr
.colors_per_channel
<2)
576 rattr
.colors_per_channel
= 2;
579 rattr
.flags
|= RC_VisualID
;
580 rattr
.visualid
= wVisualID
;
582 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
583 if (!scr
->rcontext
) {
584 wwarning(_("could not initialize graphics library context: %s"),
585 RMessageForError(RErrorCode
));
591 formats
= RSupportedFileFormats();
593 for (i
=0; formats
[i
]!=NULL
; i
++) {
594 if (strcmp(formats
[i
], "TIFF")==0) {
595 scr
->flags
.supports_tiff
= 1;
599 RFreeStringList(formats
);
603 scr
->w_win
= scr
->rcontext
->drawable
;
604 scr
->w_visual
= scr
->rcontext
->visual
;
605 scr
->w_depth
= scr
->rcontext
->depth
;
606 scr
->w_colormap
= scr
->rcontext
->cmap
;
608 scr
->black_pixel
= scr
->rcontext
->black
;
609 scr
->white_pixel
= scr
->rcontext
->white
;
611 /* create screen descriptor for WINGs */
612 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
615 color
= WMGrayColor(scr
->wmscreen
);
616 scr
->light_pixel
= WMColorPixel(color
);
617 WMReleaseColor(color
);
619 color
= WMDarkGrayColor(scr
->wmscreen
);
620 scr
->dark_pixel
= WMColorPixel(color
);
621 WMReleaseColor(color
);
625 /* frame boder color */
626 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
627 scr
->frame_border_pixel
= xcol
.pixel
;
630 /* create GCs with default values */
633 /* read defaults for this screen */
634 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
636 /* create initial workspace */
639 createInternalWindows(scr
);
641 /* create shared pixmaps */
644 /* set icon sizes we can accept from clients */
645 icon_size
[0].min_width
= 8;
646 icon_size
[0].min_height
= 8;
647 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
648 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
649 icon_size
[0].width_inc
= 1;
650 icon_size
[0].height_inc
= 1;
651 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
653 /* setup WindowMaker protocols property in the root window*/
654 PropSetWMakerProtocols(scr
->root_win
);
657 /* initialize balloon text stuff */
658 wBalloonInitialize(scr
);
661 /* kluge to load menu configurations at startup */
662 OpenRootMenu(scr
, -10000, -10000, False
);
663 wMenuUnmap(scr
->root_menu
);
670 wScreenRestoreState(WScreen
*scr
)
677 if (wScreenCount
== 1)
678 path
= wdefaultspathfordomain("WMState");
681 sprintf(buf
, "WMState.%i", scr
->screen
);
682 path
= wdefaultspathfordomain(buf
);
684 scr
->session_state
= PLGetProplistWithPath(path
);
686 if (!scr
->session_state
&& wScreenCount
>1) {
688 sprintf(buf
, "WMState.%i", scr
->screen
);
689 path
= wdefaultspathfordomain(buf
);
690 scr
->session_state
= PLGetProplistWithPath(path
);
694 if (!wPreferences
.flags
.noclip
) {
695 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
696 scr
->clip_icon
= wClipRestoreState(scr
, state
);
699 wWorkspaceRestoreState(scr
);
701 if (!wPreferences
.flags
.nodock
) {
702 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
703 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
710 wScreenSaveState(WScreen
*scr
)
712 WWorkspaceState wstate
;
715 proplist_t path
, old_state
, foo
;
722 * Save current workspace, so can go back to it upon restart.
724 wstate
.workspace
= scr
->current_workspace
;
726 data
[0] = wstate
.flags
;
727 data
[1] = wstate
.workspace
;
729 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
730 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
731 (unsigned char *) data
, 2);
733 /* save state of windows */
734 wwin
= scr
->focused_window
;
736 wWindowSaveState(wwin
);
740 old_state
= scr
->session_state
;
741 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
743 PLSetStringCmpHook(NULL
);
745 /* save dock state to file */
746 if (!wPreferences
.flags
.nodock
) {
749 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
750 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
753 if (!wPreferences
.flags
.noclip
) {
756 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
757 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
761 wWorkspaceSaveState(scr
, old_state
);
763 if (wPreferences
.save_session_on_exit
) {
764 wSessionSaveState(scr
);
766 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
767 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
769 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
770 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
775 PLSetStringCmpHook(StringCompareHook
);
779 if (wScreenCount
== 1)
780 str
= wdefaultspathfordomain("WMState");
783 sprintf(buf
, "WMState.%i", scr
->screen
);
784 str
= wdefaultspathfordomain(buf
);
786 path
= PLMakeString(str
);
788 PLSetFilename(scr
->session_state
, path
);
789 PLSave(scr
->session_state
, YES
);
791 PLRelease(old_state
);
797 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
813 *x
= -tol_w
, moved
= 1;
814 else if (*x
>= scr
->scr_width
- 10)
815 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
817 if (*y
< -height
+ 10)
818 *y
= -tol_h
, moved
= 1;
819 else if (*y
>= scr
->scr_height
- 10)
820 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;