Initial revision
[wmaker-crm.git] / src / screen.c
blob9f3ab87b41e901df48b981bf76eb67301b10251c
1 /* screen.c - screen management
2 *
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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,
20 * USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 #ifdef SHAPE
32 #include <X11/extensions/shape.h>
33 #endif
35 #include <wraster.h>
37 #include "WindowMaker.h"
38 #include "def_pixmaps.h"
39 #include "screen.h"
40 #include "texture.h"
41 #include "pixmap.h"
42 #include "menu.h"
43 #include "funcs.h"
44 #include "actions.h"
45 #include "properties.h"
46 #include "dock.h"
47 #include "resources.h"
48 #include "workspace.h"
49 #include "session.h"
50 #include "balloon.h"
52 #include <proplist.h>
54 #include "defaults.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;
74 /**** Local ****/
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;
88 static void
89 make_keys()
91 if (dApplications!=NULL)
92 return;
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.
108 * Returns:
109 * Nothing, unless something really evil happens...
111 * Side effects:
112 * CantManageScreen is set to 1;
113 *----------------------------------------------------------------------
115 static int
116 alreadyRunningError(Display *dpy, XErrorEvent *error)
118 CantManageScreen = 1;
119 return -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.
130 * Returns:
131 * Nothing
133 * Side effects:
134 * Allocates shared pixmaps for the screen. These pixmaps should
135 * not be freed by anybody.
136 *----------------------------------------------------------------------
138 static void
139 allocButtonPixmaps(WScreen *scr)
141 WPixmap *pix;
143 /* create predefined pixmaps */
144 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
145 if (pix)
146 pix->shared = 1;
147 scr->b_pixmaps[WBUT_CLOSE] = pix;
149 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
150 if (pix)
151 pix->shared = 1;
152 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
154 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
155 if (pix)
156 pix->shared = 1;
157 scr->b_pixmaps[WBUT_ICONIFY] = pix;
159 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
160 if (pix)
161 pix->shared = 1;
162 scr->b_pixmaps[WBUT_KILL] = pix;
167 static void
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);
179 static WPixmap*
180 make3Dots(WScreen *scr)
182 WPixmap *wpix;
183 GC gc2, gc;
184 XGCValues gcv;
185 Pixmap pix, mask;
187 gc = scr->copy_gc;
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);
200 gcv.foreground = 0;
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);
210 XFreeGC(dpy, gc2);
212 wpix = wPixmapCreate(scr, pix, mask);
213 wpix->shared = 1;
215 return wpix;
219 static void
220 allocGCs(WScreen *scr)
222 XGCValues gcv;
223 XColor color;
224 unsigned long mtextcolor;
225 int gcm;
227 scr->stipple_bitmap =
228 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
229 STIPPLE_HEIGHT);
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;
243 gcv.line_width = 1;
244 gcv.line_style = LineDoubleDash;
245 gcv.fill_style = FillSolid;
246 gcv.dash_offset = 0;
247 gcv.dashes = 4;
248 gcv.graphics_exposures = False;
250 gcm = GCFunction | GCGraphicsExposures;
251 gcm |= GCForeground | GCBackground;
252 gcm |= GCLineWidth | GCLineStyle;
253 gcm |= GCFillStyle;
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);
283 /* frame GC */
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);
294 /* line GC */
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. */
300 gcv.foreground = 17;
302 gcv.function = GXxor;
303 gcv.subwindow_mode = IncludeInferiors;
304 gcv.line_width = 1;
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;
313 /* copy GC */
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);
324 /* icon title GC */
325 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
327 /* clip title GC */
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);
343 static void
344 createPixmaps(WScreen *scr)
346 WPixmap *pix;
347 WMPixmap *wmpix;
348 RImage *image;
349 Pixmap p, m;
351 /* load pixmaps */
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);
357 if (pix!=NULL)
358 pix->shared = 1;
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);
367 if (pix!=NULL)
368 pix->shared = 1;
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);
376 if (pix!=NULL)
377 pix->shared = 1;
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);
385 if (pix!=NULL)
386 pix->shared = 1;
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);
394 if (pix!=NULL)
395 pix->shared = 1;
396 scr->menu_shade_indicator = pix;
399 image = wDefaultGetImage(scr, "Logo", "WMPanel");
401 if (!image) {
402 wwarning(_("could not load logo image for panels"));
403 } else {
404 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
405 wwarning(_("error making logo image for panel:%s"), RErrorString);
406 } else {
407 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
408 image->width, image->height,
409 scr->depth);
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.
432 * Returns:
433 * Nothing
435 * Side effects:
436 * Windows are created and some colors are allocated for the
437 * window background.
438 *----------------------------------------------------------------------
440 static void
441 createInternalWindows(WScreen *scr)
443 int vmask;
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;
455 else
456 attribs.background_pixel = scr->light_pixel;
457 vmask |= CWColormap;
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,
467 vmask, &attribs);
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;
487 vmask |= CWColormap;
488 attribs.colormap = scr->w_colormap;
489 scr->dock_shadow =
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;
500 scr->clip_balloon =
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 *----------------------------------------------------------------------
513 * wScreenInit--
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.
518 * Returns:
519 * The WScreen descriptor for the screen.
521 * Side effects:
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 *----------------------------------------------------------------------
529 WScreen*
530 wScreenInit(int screen_number)
532 WScreen *scr;
533 XIconSize icon_size[1];
534 RContextAttributes rattr;
535 extern int wVisualID;
536 long event_mask;
537 WMColor *color;
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);
561 XSync(dpy, False);
562 XSetErrorHandler(oldHandler);
564 if (CantManageScreen) {
565 free(scr);
566 return NULL;
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;
578 if (wVisualID>=0) {
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 RErrorString);
586 wAbort(False);
587 } else {
588 char **formats;
589 int i = 0;
591 formats = RSupportedFileFormats();
592 if (formats) {
593 for (i=0; formats[i]!=NULL; i++) {
594 if (strcmp(formats[i], "TIFF")==0) {
595 scr->flags.supports_tiff = 1;
596 break;
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,
613 scr->rcontext);
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);
624 XColor xcol;
625 /* frame boder color */
626 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
627 scr->frame_border_pixel = xcol.pixel;
630 /* create GCs with default values */
631 allocGCs(scr);
633 /* read defaults for this screen */
634 wReadDefaults(scr, WDWindowMaker->dictionary);
636 /* create initial workspace */
637 wWorkspaceNew(scr);
639 createInternalWindows(scr);
641 /* create shared pixmaps */
642 createPixmaps(scr);
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);
656 #ifdef BALLOON_TEXT
657 /* initialize balloon text stuff */
658 wBalloonInitialize(scr);
659 #endif
661 /* kluge to load menu configurations at startup */
662 OpenRootMenu(scr, -10000, -10000, False);
663 wMenuUnmap(scr->root_menu);
665 return scr;
669 void
670 wScreenRestoreState(WScreen *scr)
672 proplist_t state;
673 char *path;
675 make_keys();
677 if (wScreenCount == 1)
678 path = wdefaultspathfordomain("WMState");
679 else {
680 char buf[16];
681 sprintf(buf, "WMState.%i", scr->screen);
682 path = wdefaultspathfordomain(buf);
684 scr->session_state = PLGetProplistWithPath(path);
685 free(path);
686 if (!scr->session_state && wScreenCount>1) {
687 char buf[16];
688 sprintf(buf, "WMState.%i", scr->screen);
689 path = wdefaultspathfordomain(buf);
690 scr->session_state = PLGetProplistWithPath(path);
691 free(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);
709 void
710 wScreenSaveState(WScreen *scr)
712 WWorkspaceState wstate;
713 WWindow *wwin;
714 char *str;
715 proplist_t path, old_state, foo;
718 make_keys();
721 * Save current workspace, so can go back to it upon restart.
723 wstate.workspace = scr->current_workspace;
726 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
727 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
728 (unsigned char *) &wstate,
729 sizeof(WWorkspaceState)/sizeof(int));
731 /* save state of windows */
732 wwin = scr->focused_window;
733 while (wwin) {
734 wWindowSaveState(wwin);
735 wwin = wwin->prev;
738 old_state = scr->session_state;
739 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
741 PLSetStringCmpHook(NULL);
743 /* save dock state to file */
744 if (!wPreferences.flags.nodock) {
745 wDockSaveState(scr);
746 } else {
747 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
748 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
751 if (!wPreferences.flags.noclip) {
752 wClipSaveState(scr);
753 } else {
754 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
755 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
759 wWorkspaceSaveState(scr, old_state);
761 if (wPreferences.save_session_on_exit) {
762 wSessionSaveState(scr);
763 } else {
764 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
765 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
767 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
768 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
772 /* clean up */
773 PLSetStringCmpHook(StringCompareHook);
775 wMenuSaveState(scr);
777 if (wScreenCount == 1)
778 str = wdefaultspathfordomain("WMState");
779 else {
780 char buf[16];
781 sprintf(buf, "WMState.%i", scr->screen);
782 str = wdefaultspathfordomain(buf);
784 path = PLMakeString(str);
785 free(str);
786 PLSetFilename(scr->session_state, path);
787 PLSave(scr->session_state, YES);
788 PLRelease(path);
789 PLRelease(old_state);
795 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
797 int moved = 0;
798 int tol_w, tol_h;
800 if (width > 20)
801 tol_w = width/2;
802 else
803 tol_w = 20;
805 if (height > 20)
806 tol_h = height/2;
807 else
808 tol_h = 20;
810 if (*x+width < 10)
811 *x = -tol_w, moved = 1;
812 else if (*x >= scr->scr_width - 10)
813 *x = scr->scr_width - tol_w - 1, moved = 1;
815 if (*y < -height + 10)
816 *y = -tol_h, moved = 1;
817 else if (*y >= scr->scr_height - 10)
818 *y = scr->scr_height - tol_h - 1, moved = 1;
820 return moved;