This update includes the 0.20.3pre3 code
[wmaker-crm.git] / src / screen.c
blobb14b3e454fc52166fc218448f05ddde5c74ddc2e
1 /* screen.c - screen management
2 *
3 * Window Maker 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;
70 extern int wScreenCount;
72 extern WDDomain *WDWindowMaker;
75 /**** Local ****/
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;
89 static void
90 make_keys()
92 if (dApplications!=NULL)
93 return;
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.
109 * Returns:
110 * Nothing, unless something really evil happens...
112 * Side effects:
113 * CantManageScreen is set to 1;
114 *----------------------------------------------------------------------
116 static int
117 alreadyRunningError(Display *dpy, XErrorEvent *error)
119 CantManageScreen = 1;
120 return -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.
131 * Returns:
132 * Nothing
134 * Side effects:
135 * Allocates shared pixmaps for the screen. These pixmaps should
136 * not be freed by anybody.
137 *----------------------------------------------------------------------
139 static void
140 allocButtonPixmaps(WScreen *scr)
142 WPixmap *pix;
144 /* create predefined pixmaps */
145 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
146 if (pix)
147 pix->shared = 1;
148 scr->b_pixmaps[WBUT_CLOSE] = pix;
150 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
151 if (pix)
152 pix->shared = 1;
153 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
155 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
156 if (pix)
157 pix->shared = 1;
158 scr->b_pixmaps[WBUT_ICONIFY] = pix;
160 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
161 if (pix)
162 pix->shared = 1;
163 scr->b_pixmaps[WBUT_KILL] = pix;
168 static void
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);
180 static WPixmap*
181 make3Dots(WScreen *scr)
183 WPixmap *wpix;
184 GC gc2, gc;
185 XGCValues gcv;
186 Pixmap pix, mask;
188 gc = scr->copy_gc;
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);
201 gcv.foreground = 0;
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);
211 XFreeGC(dpy, gc2);
213 wpix = wPixmapCreate(scr, pix, mask);
214 wpix->shared = 1;
216 return wpix;
220 static void
221 allocGCs(WScreen *scr)
223 XGCValues gcv;
224 XColor color;
225 unsigned long mtextcolor;
226 int gcm;
228 scr->stipple_bitmap =
229 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
230 STIPPLE_HEIGHT);
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;
244 gcv.line_width = 1;
245 gcv.line_style = LineDoubleDash;
246 gcv.fill_style = FillSolid;
247 gcv.dash_offset = 0;
248 gcv.dashes = 4;
249 gcv.graphics_exposures = False;
251 gcm = GCFunction | GCGraphicsExposures;
252 gcm |= GCForeground | GCBackground;
253 gcm |= GCLineWidth | GCLineStyle;
254 gcm |= GCFillStyle;
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);
284 /* frame GC */
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
289 * initialized */
290 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
291 gcv.plane_mask = (1<<(scr->depth-1))|1;
292 else
293 gcv.plane_mask = AllPlanes;
294 gcv.foreground = color.pixel;
295 if (gcv.foreground == 0)
296 gcv.foreground = 1;
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
302 |GCPlaneMask, &gcv);
304 /* line GC */
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. */
310 gcv.foreground = 17;
312 gcv.function = GXxor;
313 gcv.subwindow_mode = IncludeInferiors;
314 gcv.line_width = 1;
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;
323 /* copy GC */
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);
334 /* icon title GC */
335 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
337 /* clip title GC */
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);
353 static void
354 createPixmaps(WScreen *scr)
356 WPixmap *pix;
357 WMPixmap *wmpix;
358 RImage *image;
359 Pixmap p, m;
361 /* load pixmaps */
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);
367 if (pix!=NULL)
368 pix->shared = 1;
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);
377 if (pix!=NULL)
378 pix->shared = 1;
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);
386 if (pix!=NULL)
387 pix->shared = 1;
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);
395 if (pix!=NULL)
396 pix->shared = 1;
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);
404 if (pix!=NULL)
405 pix->shared = 1;
406 scr->menu_shade_indicator = pix;
409 image = wDefaultGetImage(scr, "Logo", "WMPanel");
411 if (!image) {
412 wwarning(_("could not load logo image for panels"));
413 } else {
414 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
415 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
416 } else {
417 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
418 image->width, image->height,
419 scr->depth);
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.
442 * Returns:
443 * Nothing
445 * Side effects:
446 * Windows are created and some colors are allocated for the
447 * window background.
448 *----------------------------------------------------------------------
450 static void
451 createInternalWindows(WScreen *scr)
453 int vmask;
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;
465 else
466 attribs.background_pixel = scr->light_pixel;
467 vmask |= CWColormap;
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,
477 vmask, &attribs);
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;
497 vmask |= CWColormap;
498 attribs.colormap = scr->w_colormap;
499 scr->dock_shadow =
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;
510 scr->clip_balloon =
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 *----------------------------------------------------------------------
523 * wScreenInit--
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.
528 * Returns:
529 * The WScreen descriptor for the screen.
531 * Side effects:
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 *----------------------------------------------------------------------
539 WScreen*
540 wScreenInit(int screen_number)
542 WScreen *scr;
543 XIconSize icon_size[1];
544 RContextAttributes rattr;
545 extern int wVisualID;
546 long event_mask;
547 WMColor *color;
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);
571 XSync(dpy, False);
572 XSetErrorHandler(oldHandler);
574 if (CantManageScreen) {
575 free(scr);
576 return NULL;
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;
588 if (wVisualID>=0) {
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));
596 wAbort(False);
597 } else {
598 char **formats;
599 int i = 0;
601 formats = RSupportedFileFormats();
602 if (formats) {
603 for (i=0; formats[i]!=NULL; i++) {
604 if (strcmp(formats[i], "TIFF")==0) {
605 scr->flags.supports_tiff = 1;
606 break;
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,
623 scr->rcontext);
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);
634 XColor xcol;
635 /* frame boder color */
636 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
637 scr->frame_border_pixel = xcol.pixel;
640 /* create GCs with default values */
641 allocGCs(scr);
643 /* read defaults for this screen */
644 wReadDefaults(scr, WDWindowMaker->dictionary);
646 /* create initial workspace */
647 wWorkspaceNew(scr);
649 createInternalWindows(scr);
651 /* create shared pixmaps */
652 createPixmaps(scr);
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);
666 #ifdef BALLOON_TEXT
667 /* initialize balloon text stuff */
668 wBalloonInitialize(scr);
669 #endif
671 /* kluge to load menu configurations at startup */
672 OpenRootMenu(scr, -10000, -10000, False);
673 wMenuUnmap(scr->root_menu);
675 return scr;
679 void
680 wScreenRestoreState(WScreen *scr)
682 proplist_t state;
683 char *path;
685 make_keys();
687 if (wScreenCount == 1)
688 path = wdefaultspathfordomain("WMState");
689 else {
690 char buf[16];
691 sprintf(buf, "WMState.%i", scr->screen);
692 path = wdefaultspathfordomain(buf);
694 scr->session_state = PLGetProplistWithPath(path);
695 free(path);
696 if (!scr->session_state && wScreenCount>1) {
697 char buf[16];
698 sprintf(buf, "WMState.%i", scr->screen);
699 path = wdefaultspathfordomain(buf);
700 scr->session_state = PLGetProplistWithPath(path);
701 free(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);
719 void
720 wScreenSaveState(WScreen *scr)
722 WWorkspaceState wstate;
723 WWindow *wwin;
724 char *str;
725 proplist_t path, old_state, foo;
726 CARD32 data[2];
729 make_keys();
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;
745 while (wwin) {
746 wWindowSaveState(wwin);
747 wwin = wwin->prev;
751 if (wPreferences.flags.noupdates)
752 return;
755 old_state = scr->session_state;
756 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
758 PLSetStringCmpHook(NULL);
760 /* save dock state to file */
761 if (!wPreferences.flags.nodock) {
762 wDockSaveState(scr);
763 } else {
764 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
765 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
768 if (!wPreferences.flags.noclip) {
769 wClipSaveState(scr);
770 } else {
771 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
772 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
776 wWorkspaceSaveState(scr, old_state);
778 if (wPreferences.save_session_on_exit) {
779 wSessionSaveState(scr);
780 } else {
781 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
782 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
784 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
785 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
789 /* clean up */
790 PLSetStringCmpHook(StringCompareHook);
792 wMenuSaveState(scr);
794 if (wScreenCount == 1)
795 str = wdefaultspathfordomain("WMState");
796 else {
797 char buf[16];
798 sprintf(buf, "WMState.%i", scr->screen);
799 str = wdefaultspathfordomain(buf);
801 path = PLMakeString(str);
802 free(str);
803 PLSetFilename(scr->session_state, path);
804 if (!PLSave(scr->session_state, YES)) {
805 wwarning(_("could not save session state in %s"), PLGetString(path));
807 PLRelease(path);
808 PLRelease(old_state);
814 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
816 int moved = 0;
817 int tol_w, tol_h;
819 if (width > 20)
820 tol_w = width/2;
821 else
822 tol_w = 20;
824 if (height > 20)
825 tol_h = height/2;
826 else
827 tol_h = 20;
829 if (*x+width < 10)
830 *x = -tol_w, moved = 1;
831 else if (*x >= scr->scr_width - 10)
832 *x = scr->scr_width - tol_w - 1, moved = 1;
834 if (*y < -height + 10)
835 *y = -tol_h, moved = 1;
836 else if (*y >= scr->scr_height - 10)
837 *y = scr->scr_height - tol_h - 1, moved = 1;
839 return moved;