Code update for Window Maker version 0.50.0
[wmaker-crm.git] / src / screen.c
blob5eb4b72029951899f7e0e140f90af49caee60076
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"
51 #ifdef KWM_HINTS
52 #include "kwm.h"
53 #endif
54 #ifdef GNOME_STUFF
55 #include "gnome.h"
56 #endif
58 #include <proplist.h>
60 #include "defaults.h"
63 #ifdef LITE
64 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
65 |SubstructureNotifyMask|PointerMotionMask \
66 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
67 #else
68 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
69 |SubstructureNotifyMask|PointerMotionMask \
70 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
71 |KeyPressMask|KeyReleaseMask)
72 #endif
74 /**** Global variables ****/
76 extern Cursor wCursor[WCUR_LAST];
77 extern WPreferences wPreferences;
78 extern Atom _XA_WINDOWMAKER_STATE;
81 extern int wScreenCount;
83 extern WDDomain *WDWindowMaker;
86 /**** Local ****/
88 #define STIPPLE_WIDTH 2
89 #define STIPPLE_HEIGHT 2
90 static char STIPPLE_DATA[] = {0x02, 0x01};
92 static int CantManageScreen = 0;
94 static proplist_t dApplications = NULL;
95 static proplist_t dWorkspace;
96 static proplist_t dDock;
97 static proplist_t dClip;
100 static void
101 make_keys()
103 if (dApplications!=NULL)
104 return;
106 dApplications = PLMakeString("Applications");
107 dWorkspace = PLMakeString("Workspace");
108 dDock = PLMakeString("Dock");
109 dClip = PLMakeString("Clip");
114 *----------------------------------------------------------------------
115 * alreadyRunningError--
116 * X error handler used to catch errors when trying to do
117 * XSelectInput() on the root window. These errors probably mean that
118 * there already is some other window manager running.
120 * Returns:
121 * Nothing, unless something really evil happens...
123 * Side effects:
124 * CantManageScreen is set to 1;
125 *----------------------------------------------------------------------
127 static int
128 alreadyRunningError(Display *dpy, XErrorEvent *error)
130 CantManageScreen = 1;
131 return -1;
136 *----------------------------------------------------------------------
137 * allocButtonPixmaps--
138 * Allocate pixmaps used on window operation buttons (those in the
139 * titlebar). The pixmaps are linked to the program. If XPM is supported
140 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
142 * Returns:
143 * Nothing
145 * Side effects:
146 * Allocates shared pixmaps for the screen. These pixmaps should
147 * not be freed by anybody.
148 *----------------------------------------------------------------------
150 static void
151 allocButtonPixmaps(WScreen *scr)
153 WPixmap *pix;
155 /* create predefined pixmaps */
156 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
157 if (pix)
158 pix->shared = 1;
159 scr->b_pixmaps[WBUT_CLOSE] = pix;
161 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
162 if (pix)
163 pix->shared = 1;
164 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
166 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
167 if (pix)
168 pix->shared = 1;
169 scr->b_pixmaps[WBUT_ICONIFY] = pix;
171 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
172 if (pix)
173 pix->shared = 1;
174 scr->b_pixmaps[WBUT_KILL] = pix;
179 static void
180 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
182 XSetForeground(dpy, gc, scr->black_pixel);
183 XDrawLine(dpy, d, gc, x, y, x+1, y);
184 XDrawPoint(dpy, d, gc, x, y+1);
185 XSetForeground(dpy, gc, scr->white_pixel);
186 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
187 XDrawPoint(dpy, d, gc, x+1, y+1);
191 static WPixmap*
192 make3Dots(WScreen *scr)
194 WPixmap *wpix;
195 GC gc2, gc;
196 XGCValues gcv;
197 Pixmap pix, mask;
199 gc = scr->copy_gc;
200 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
201 wPreferences.icon_size, scr->w_depth);
202 XSetForeground(dpy, gc, scr->black_pixel);
203 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
204 wPreferences.icon_size);
205 XSetForeground(dpy, gc, scr->white_pixel);
206 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
207 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
208 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
210 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
211 wPreferences.icon_size, 1);
212 gcv.foreground = 0;
213 gcv.graphics_exposures = False;
214 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
215 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
216 wPreferences.icon_size);
217 XSetForeground(dpy, gc2, 1);
218 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
219 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
220 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
222 XFreeGC(dpy, gc2);
224 wpix = wPixmapCreate(scr, pix, mask);
225 wpix->shared = 1;
227 return wpix;
231 static void
232 allocGCs(WScreen *scr)
234 XGCValues gcv;
235 XColor color;
236 unsigned long mtextcolor;
237 int gcm;
239 scr->stipple_bitmap =
240 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
241 STIPPLE_HEIGHT);
243 gcv.stipple = scr->stipple_bitmap;
244 gcv.foreground = scr->white_pixel;
245 gcv.fill_style = FillStippled;
246 gcv.graphics_exposures = False;
247 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
248 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
251 /* selected icon border GCs */
252 gcv.function = GXcopy;
253 gcv.foreground = scr->white_pixel;
254 gcv.background = scr->black_pixel;
255 gcv.line_width = 1;
256 gcv.line_style = LineDoubleDash;
257 gcv.fill_style = FillSolid;
258 gcv.dash_offset = 0;
259 gcv.dashes = 4;
260 gcv.graphics_exposures = False;
262 gcm = GCFunction | GCGraphicsExposures;
263 gcm |= GCForeground | GCBackground;
264 gcm |= GCLineWidth | GCLineStyle;
265 gcm |= GCFillStyle;
266 gcm |= GCDashOffset | GCDashList;
268 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
270 gcm = GCForeground|GCGraphicsExposures;
272 scr->menu_title_pixel[0] = scr->white_pixel;
273 gcv.foreground = scr->white_pixel;
274 gcv.graphics_exposures = False;
275 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
277 scr->mtext_pixel = scr->black_pixel;
278 mtextcolor = gcv.foreground = scr->black_pixel;
279 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
281 /* selected menu entry GC */
282 gcm = GCForeground|GCBackground|GCGraphicsExposures;
283 gcv.foreground = scr->white_pixel;
284 gcv.background = scr->white_pixel;
285 gcv.graphics_exposures = False;
286 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
288 /* disabled menu entry GC */
289 scr->dtext_pixel = scr->black_pixel;
290 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
291 gcv.stipple = scr->stipple_bitmap;
292 gcv.graphics_exposures = False;
293 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
295 /* frame GC */
296 wGetColor(scr, DEF_FRAME_COLOR, &color);
297 gcv.function = GXxor;
298 /* this will raise the probability of the XORed color being different
299 * of the original color in PseudoColor when not all color cells are
300 * initialized */
301 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
302 gcv.plane_mask = (1<<(scr->depth-1))|1;
303 else
304 gcv.plane_mask = AllPlanes;
305 gcv.foreground = color.pixel;
306 if (gcv.foreground == 0)
307 gcv.foreground = 1;
308 gcv.line_width = DEF_FRAME_THICKNESS;
309 gcv.subwindow_mode = IncludeInferiors;
310 gcv.graphics_exposures = False;
311 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
312 |GCFunction|GCSubwindowMode|GCLineWidth
313 |GCPlaneMask, &gcv);
315 /* line GC */
316 gcv.foreground = color.pixel;
318 if (gcv.foreground == 0)
319 /* XOR:ing with a zero is not going to be of much use, so
320 in that case, we somewhat arbitrarily xor with 17 instead. */
321 gcv.foreground = 17;
323 gcv.function = GXxor;
324 gcv.subwindow_mode = IncludeInferiors;
325 gcv.line_width = 1;
326 gcv.cap_style = CapRound;
327 gcv.graphics_exposures = False;
328 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
329 |GCGraphicsExposures;
330 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
332 scr->line_pixel = gcv.foreground;
334 /* copy GC */
335 gcv.foreground = scr->white_pixel;
336 gcv.background = scr->black_pixel;
337 gcv.graphics_exposures = False;
338 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
339 |GCGraphicsExposures, &gcv);
341 /* window title text GC */
342 gcv.graphics_exposures = False;
343 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
345 /* icon title GC */
346 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
348 /* clip title GC */
349 scr->clip_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
351 /* move/size display GC */
352 gcv.graphics_exposures = False;
353 gcm = GCGraphicsExposures;
354 scr->info_text_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
356 /* misc drawing GC */
357 gcv.graphics_exposures = False;
358 gcm = GCGraphicsExposures;
359 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
364 static void
365 createPixmaps(WScreen *scr)
367 WPixmap *pix;
368 WMPixmap *wmpix;
369 RImage *image;
370 Pixmap p, m;
372 /* load pixmaps */
373 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
374 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
375 MENU_RADIO_INDICATOR_XBM_SIZE,
376 MENU_RADIO_INDICATOR_XBM_SIZE,
377 scr->black_pixel, scr->white_pixel);
378 if (pix!=NULL)
379 pix->shared = 1;
380 scr->menu_radio_indicator = pix;
383 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
384 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
385 MENU_CHECK_INDICATOR_XBM_SIZE,
386 MENU_CHECK_INDICATOR_XBM_SIZE,
387 scr->black_pixel, scr->white_pixel);
388 if (pix!=NULL)
389 pix->shared = 1;
390 scr->menu_check_indicator = pix;
392 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
393 (char*)MENU_MINI_INDICATOR_XBM_DATA,
394 MENU_MINI_INDICATOR_XBM_SIZE,
395 MENU_MINI_INDICATOR_XBM_SIZE,
396 scr->black_pixel, scr->white_pixel);
397 if (pix!=NULL)
398 pix->shared = 1;
399 scr->menu_mini_indicator = pix;
401 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
402 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
403 MENU_HIDE_INDICATOR_XBM_SIZE,
404 MENU_HIDE_INDICATOR_XBM_SIZE,
405 scr->black_pixel, scr->white_pixel);
406 if (pix!=NULL)
407 pix->shared = 1;
408 scr->menu_hide_indicator = pix;
410 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
411 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
412 MENU_SHADE_INDICATOR_XBM_SIZE,
413 MENU_SHADE_INDICATOR_XBM_SIZE,
414 scr->black_pixel, scr->white_pixel);
415 if (pix!=NULL)
416 pix->shared = 1;
417 scr->menu_shade_indicator = pix;
420 image = wDefaultGetImage(scr, "Logo", "WMPanel");
422 if (!image) {
423 wwarning(_("could not load logo image for panels"));
424 } else {
425 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
426 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
427 } else {
428 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
429 image->width, image->height,
430 scr->depth);
431 WMSetApplicationIconImage(scr->wmscreen, wmpix);
432 WMReleasePixmap(wmpix);
434 RDestroyImage(image);
437 if (!wPreferences.flags.nodock || !wPreferences.flags.noclip) {
438 scr->dock_dots = make3Dots(scr);
441 /* titlebar button pixmaps */
442 allocButtonPixmaps(scr);
447 *----------------------------------------------------------------------
448 * createInternalWindows--
449 * Creates some windows used internally by the program. One to
450 * receive input focus when no other window can get it and another
451 * to display window geometry information during window resize/move.
453 * Returns:
454 * Nothing
456 * Side effects:
457 * Windows are created and some colors are allocated for the
458 * window background.
459 *----------------------------------------------------------------------
461 static void
462 createInternalWindows(WScreen *scr)
464 int vmask;
465 XSetWindowAttributes attribs;
467 /* window for displaying geometry information during resizes and moves */
468 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
469 attribs.border_pixel = 0;
470 attribs.save_under = True;
471 attribs.override_redirect = True;
472 attribs.cursor = wCursor[WCUR_DEFAULT];
473 attribs.background_pixmap = None;
474 if (scr->resizebar_texture[0])
475 attribs.background_pixel = scr->resizebar_texture[0]->normal.pixel;
476 else
477 attribs.background_pixel = scr->light_pixel;
478 vmask |= CWColormap;
479 attribs.colormap = scr->w_colormap;
481 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
482 &scr->geometry_display_height);
483 scr->geometry_display =
484 XCreateWindow(dpy, scr->root_win, 1, 1,
485 scr->geometry_display_width,
486 scr->geometry_display_height,
487 1, scr->w_depth, CopyFromParent, scr->w_visual,
488 vmask, &attribs);
490 /* InputOnly window to get the focus when no other window can get it */
491 vmask = CWEventMask|CWOverrideRedirect;
492 attribs.event_mask = KeyPressMask|FocusChangeMask;
493 attribs.override_redirect = True;
494 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
495 InputOnly,CopyFromParent, vmask, &attribs);
496 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
497 XMapWindow(dpy, scr->no_focus_win);
499 XSetInputFocus (dpy, scr->no_focus_win, RevertToParent, CurrentTime);
501 /* shadow window for dock buttons */
502 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
503 attribs.border_pixel = 0;
504 attribs.save_under = True;
505 attribs.override_redirect = True;
506 attribs.background_pixmap = None;
507 attribs.background_pixel = scr->white_pixel;
508 vmask |= CWColormap;
509 attribs.colormap = scr->w_colormap;
510 scr->dock_shadow =
511 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
512 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
513 scr->w_visual, vmask, &attribs);
515 /* workspace name balloon for clip */
516 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap;
517 attribs.save_under = True;
518 attribs.override_redirect = True;
519 attribs.colormap = scr->w_colormap;
520 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
521 scr->clip_balloon =
522 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
523 CopyFromParent, scr->w_visual, vmask, &attribs);
525 * If the window is clicked without having ButtonPress selected, the
526 * resulting event will have event.xbutton.window == root.
528 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
533 *----------------------------------------------------------------------
534 * wScreenInit--
535 * Initializes the window manager for the given screen and
536 * allocates a WScreen descriptor for it. Many resources are allocated
537 * for the screen and the root window is setup appropriately.
539 * Returns:
540 * The WScreen descriptor for the screen.
542 * Side effects:
543 * Many resources are allocated and the IconSize property is
544 * set on the root window.
545 * The program can be aborted if some fatal error occurs.
547 * TODO: User specifiable visual.
548 *----------------------------------------------------------------------
550 WScreen*
551 wScreenInit(int screen_number)
553 WScreen *scr;
554 XIconSize icon_size[1];
555 RContextAttributes rattr;
556 extern int wVisualID;
557 long event_mask;
558 WMColor *color;
559 XErrorHandler oldHandler;
561 scr = wmalloc(sizeof(WScreen));
562 memset(scr, 0, sizeof(WScreen));
564 /* initialize globals */
565 scr->screen = screen_number;
566 scr->root_win = RootWindow(dpy, screen_number);
567 scr->depth = DefaultDepth(dpy, screen_number);
568 scr->colormap = DefaultColormap(dpy, screen_number);
570 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
571 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
573 scr->usableArea.x2 = scr->scr_width;
574 scr->usableArea.y2 = scr->scr_height;
575 scr->totalUsableArea.x2 = scr->scr_width;
576 scr->totalUsableArea.y2 = scr->scr_height;
578 CantManageScreen = 0;
579 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
581 event_mask = EVENT_MASK;
583 if (wPreferences.disable_root_mouse) {
584 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
587 XSelectInput(dpy, scr->root_win, event_mask);
589 XSync(dpy, False);
590 XSetErrorHandler(oldHandler);
592 if (CantManageScreen) {
593 free(scr);
594 return NULL;
597 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_DEFAULT]);
599 /* screen descriptor for raster graphic library */
600 rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
601 rattr.render_mode = wPreferences.no_dithering?RM_MATCH:RM_DITHER;
602 rattr.colors_per_channel = wPreferences.cmap_size;
603 if (rattr.colors_per_channel<2)
604 rattr.colors_per_channel = 2;
606 if (wVisualID>=0) {
607 rattr.flags |= RC_VisualID;
608 rattr.visualid = wVisualID;
610 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
611 if (!scr->rcontext) {
612 wwarning(_("could not initialize graphics library context: %s"),
613 RMessageForError(RErrorCode));
614 wAbort(False);
615 } else {
616 char **formats;
617 int i = 0;
619 formats = RSupportedFileFormats();
620 if (formats) {
621 for (i=0; formats[i]!=NULL; i++) {
622 if (strcmp(formats[i], "TIFF")==0) {
623 scr->flags.supports_tiff = 1;
624 break;
627 RFreeStringList(formats);
631 scr->w_win = scr->rcontext->drawable;
632 scr->w_visual = scr->rcontext->visual;
633 scr->w_depth = scr->rcontext->depth;
634 scr->w_colormap = scr->rcontext->cmap;
636 scr->black_pixel = scr->rcontext->black;
637 scr->white_pixel = scr->rcontext->white;
639 /* create screen descriptor for WINGs */
640 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
641 scr->rcontext);
643 if (!scr->wmscreen) {
644 wfatal(_("could not do initialization of WINGs widget set"));
646 return NULL;
649 color = WMGrayColor(scr->wmscreen);
650 scr->light_pixel = WMColorPixel(color);
651 WMReleaseColor(color);
653 color = WMDarkGrayColor(scr->wmscreen);
654 scr->dark_pixel = WMColorPixel(color);
655 WMReleaseColor(color);
658 XColor xcol;
659 /* frame boder color */
660 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
661 scr->frame_border_pixel = xcol.pixel;
664 /* create GCs with default values */
665 allocGCs(scr);
667 /* read defaults for this screen */
668 wReadDefaults(scr, WDWindowMaker->dictionary);
670 createInternalWindows(scr);
672 #ifdef KWM_HINTS
673 wKWMInitStuff(scr);
674 #endif
676 #ifdef GNOME_STUFF
677 wGNOMEInitStuff(scr);
678 #endif
680 /* create initial workspace */
681 wWorkspaceNew(scr);
683 /* create shared pixmaps */
684 createPixmaps(scr);
686 /* set icon sizes we can accept from clients */
687 icon_size[0].min_width = 8;
688 icon_size[0].min_height = 8;
689 icon_size[0].max_width = wPreferences.icon_size-4;
690 icon_size[0].max_height = wPreferences.icon_size-4;
691 icon_size[0].width_inc = 1;
692 icon_size[0].height_inc = 1;
693 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
695 /* setup WindowMaker protocols property in the root window*/
696 PropSetWMakerProtocols(scr->root_win);
698 #ifdef BALLOON_TEXT
699 /* initialize balloon text stuff */
700 wBalloonInitialize(scr);
701 #endif
703 wScreenUpdateUsableArea(scr);
705 #ifndef LITE
706 /* kluge to load menu configurations at startup */
707 OpenRootMenu(scr, -10000, -10000, False);
708 wMenuUnmap(scr->root_menu);
709 #endif
711 return scr;
715 void
716 wScreenUpdateUsableArea(WScreen *scr)
718 #ifdef GNOME_STUFF
719 WReservedArea *area;
720 #endif
722 scr->totalUsableArea = scr->usableArea;
725 if (scr->dock && (!scr->dock->lowered
726 || wPreferences.no_window_over_dock)) {
728 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
730 if (scr->dock->on_right_side) {
731 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
732 scr->scr_width - offset);
733 } else {
734 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
738 if (wPreferences.no_window_over_icons) {
739 if (wPreferences.icon_yard & IY_VERT) {
741 if (!(wPreferences.icon_yard & IY_RIGHT)) {
742 scr->totalUsableArea.x1 += wPreferences.icon_size;
743 } else {
744 scr->totalUsableArea.x2 -= wPreferences.icon_size;
746 } else {
748 if (wPreferences.icon_yard & IY_TOP) {
749 scr->totalUsableArea.y1 += wPreferences.icon_size;
750 } else {
751 scr->totalUsableArea.y2 -= wPreferences.icon_size;
756 #ifdef KWM_HINTS
758 WArea area;
760 if (wKWMGetUsableArea(scr, &area)) {
761 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
762 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
763 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
764 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
767 #endif
769 #ifdef GNOME_STUFF
770 area = scr->reservedAreas;
772 while (area) {
773 int th, bh;
774 int lw, rw;
775 int w, h;
777 w = area->area.x2 - area->area.x1;
778 h = area->area.y2 - area->area.y1;
780 th = area->area.y1;
781 bh = scr->scr_height - area->area.y2;
782 lw = area->area.x1;
783 rw = scr->scr_width - area->area.x2;
785 if (WMIN(th, bh) < WMIN(lw, rw)) {
786 /* horizontal */
787 if (th < bh) {
788 /* on top */
789 if (scr->totalUsableArea.y1 < area->area.y2)
790 scr->totalUsableArea.y1 = area->area.y2;
791 } else {
792 /* on bottom */
793 if (scr->totalUsableArea.y2 > area->area.y1)
794 scr->totalUsableArea.y2 = area->area.y1;
796 } else {
797 /* vertical */
798 if (lw < rw) {
799 /* on left */
800 if (scr->totalUsableArea.x1 < area->area.x2)
801 scr->totalUsableArea.x1 = area->area.x2;
802 } else {
803 /* on right */
804 if (scr->totalUsableArea.x2 > area->area.x1)
805 scr->totalUsableArea.x2 = area->area.x1;
809 area = area->next;
811 #endif /* GNOME_STUFF */
813 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
814 scr->totalUsableArea.x2 = scr->usableArea.x2;
815 scr->totalUsableArea.x1 = scr->usableArea.x1;
817 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
818 scr->totalUsableArea.y2 = scr->usableArea.y2;
819 scr->totalUsableArea.y1 = scr->usableArea.y1;
822 #ifdef KWM_HINTS
824 int i;
826 for (i = 0; i < scr->workspace_count; i++) {
827 wKWMSetUsableAreaHint(scr, i);
830 #endif
834 void
835 wScreenRestoreState(WScreen *scr)
837 proplist_t state;
838 char *path;
840 make_keys();
842 if (wScreenCount == 1)
843 path = wdefaultspathfordomain("WMState");
844 else {
845 char buf[16];
846 sprintf(buf, "WMState.%i", scr->screen);
847 path = wdefaultspathfordomain(buf);
849 scr->session_state = PLGetProplistWithPath(path);
850 free(path);
851 if (!scr->session_state && wScreenCount>1) {
852 char buf[16];
853 sprintf(buf, "WMState.%i", scr->screen);
854 path = wdefaultspathfordomain(buf);
855 scr->session_state = PLGetProplistWithPath(path);
856 free(path);
859 if (!wPreferences.flags.noclip) {
860 state = PLGetDictionaryEntry(scr->session_state, dClip);
861 scr->clip_icon = wClipRestoreState(scr, state);
864 wWorkspaceRestoreState(scr);
866 if (!wPreferences.flags.nodock) {
867 state = PLGetDictionaryEntry(scr->session_state, dDock);
868 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
871 wScreenUpdateUsableArea(scr);
875 void
876 wScreenSaveState(WScreen *scr)
878 WWorkspaceState wstate;
879 WWindow *wwin;
880 char *str;
881 proplist_t path, old_state, foo;
882 CARD32 data[2];
885 make_keys();
888 * Save current workspace, so can go back to it upon restart.
890 wstate.workspace = scr->current_workspace;
892 data[0] = wstate.flags;
893 data[1] = wstate.workspace;
895 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
896 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
897 (unsigned char *) data, 2);
899 /* save state of windows */
900 wwin = scr->focused_window;
901 while (wwin) {
902 wWindowSaveState(wwin);
903 wwin = wwin->prev;
907 if (wPreferences.flags.noupdates)
908 return;
911 old_state = scr->session_state;
912 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
914 PLSetStringCmpHook(NULL);
916 /* save dock state to file */
917 if (!wPreferences.flags.nodock) {
918 wDockSaveState(scr);
919 } else {
920 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
921 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
924 if (!wPreferences.flags.noclip) {
925 wClipSaveState(scr);
926 } else {
927 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
928 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
932 wWorkspaceSaveState(scr, old_state);
934 if (wPreferences.save_session_on_exit) {
935 wSessionSaveState(scr);
936 } else {
937 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
938 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
940 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
941 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
945 /* clean up */
946 PLSetStringCmpHook(StringCompareHook);
948 wMenuSaveState(scr);
950 if (wScreenCount == 1)
951 str = wdefaultspathfordomain("WMState");
952 else {
953 char buf[16];
954 sprintf(buf, "WMState.%i", scr->screen);
955 str = wdefaultspathfordomain(buf);
957 path = PLMakeString(str);
958 free(str);
959 PLSetFilename(scr->session_state, path);
960 if (!PLSave(scr->session_state, YES)) {
961 wwarning(_("could not save session state in %s"), PLGetString(path));
963 PLRelease(path);
964 PLRelease(old_state);
970 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
972 int moved = 0;
973 int tol_w, tol_h;
975 if (width > 20)
976 tol_w = width/2;
977 else
978 tol_w = 20;
980 if (height > 20)
981 tol_h = height/2;
982 else
983 tol_h = 20;
985 if (*x+width < 10)
986 *x = -tol_w, moved = 1;
987 else if (*x >= scr->scr_width - 10)
988 *x = scr->scr_width - tol_w - 1, moved = 1;
990 if (*y < -height + 10)
991 *y = -tol_h, moved = 1;
992 else if (*y >= scr->scr_height - 10)
993 *y = scr->scr_height - tol_h - 1, moved = 1;
995 return moved;