0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / src / screen.c
blob75725e9fe0d830f402166114184d98c4afe2a0b0
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 #include <X11/Xatom.h>
32 #ifdef SHAPE
33 #include <X11/extensions/shape.h>
34 #endif
36 #include <wraster.h>
38 #include "WindowMaker.h"
39 #include "def_pixmaps.h"
40 #include "screen.h"
41 #include "texture.h"
42 #include "pixmap.h"
43 #include "menu.h"
44 #include "funcs.h"
45 #include "actions.h"
46 #include "properties.h"
47 #include "dock.h"
48 #include "resources.h"
49 #include "workspace.h"
50 #include "session.h"
51 #include "balloon.h"
52 #ifdef KWM_HINTS
53 # include "kwm.h"
54 #endif
55 #ifdef GNOME_STUFF
56 # include "gnome.h"
57 #endif
58 #ifdef OLWM_HINTS
59 # include "openlook.h"
60 #endif
62 #include <proplist.h>
64 #include "defaults.h"
67 #ifdef LITE
68 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
69 |SubstructureNotifyMask|PointerMotionMask \
70 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
71 #else
72 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
73 |SubstructureNotifyMask|PointerMotionMask \
74 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
75 |KeyPressMask|KeyReleaseMask)
76 #endif
78 /**** Global variables ****/
80 extern Cursor wCursor[WCUR_LAST];
81 extern WPreferences wPreferences;
82 extern Atom _XA_WINDOWMAKER_STATE;
83 extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
86 extern int wScreenCount;
88 extern WDDomain *WDWindowMaker;
91 /**** Local ****/
93 #define STIPPLE_WIDTH 2
94 #define STIPPLE_HEIGHT 2
95 static char STIPPLE_DATA[] = {0x02, 0x01};
97 static int CantManageScreen = 0;
99 static proplist_t dApplications = NULL;
100 static proplist_t dWorkspace;
101 static proplist_t dDock;
102 static proplist_t dClip;
105 static void
106 make_keys()
108 if (dApplications!=NULL)
109 return;
111 dApplications = PLMakeString("Applications");
112 dWorkspace = PLMakeString("Workspace");
113 dDock = PLMakeString("Dock");
114 dClip = PLMakeString("Clip");
119 *----------------------------------------------------------------------
120 * alreadyRunningError--
121 * X error handler used to catch errors when trying to do
122 * XSelectInput() on the root window. These errors probably mean that
123 * there already is some other window manager running.
125 * Returns:
126 * Nothing, unless something really evil happens...
128 * Side effects:
129 * CantManageScreen is set to 1;
130 *----------------------------------------------------------------------
132 static int
133 alreadyRunningError(Display *dpy, XErrorEvent *error)
135 CantManageScreen = 1;
136 return -1;
141 *----------------------------------------------------------------------
142 * allocButtonPixmaps--
143 * Allocate pixmaps used on window operation buttons (those in the
144 * titlebar). The pixmaps are linked to the program. If XPM is supported
145 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
147 * Returns:
148 * Nothing
150 * Side effects:
151 * Allocates shared pixmaps for the screen. These pixmaps should
152 * not be freed by anybody.
153 *----------------------------------------------------------------------
155 static void
156 allocButtonPixmaps(WScreen *scr)
158 WPixmap *pix;
160 /* create predefined pixmaps */
161 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
162 if (pix)
163 pix->shared = 1;
164 scr->b_pixmaps[WBUT_CLOSE] = pix;
166 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
167 if (pix)
168 pix->shared = 1;
169 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
171 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
172 if (pix)
173 pix->shared = 1;
174 scr->b_pixmaps[WBUT_ICONIFY] = pix;
176 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
177 if (pix)
178 pix->shared = 1;
179 scr->b_pixmaps[WBUT_KILL] = pix;
184 static void
185 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
187 XSetForeground(dpy, gc, scr->black_pixel);
188 XDrawLine(dpy, d, gc, x, y, x+1, y);
189 XDrawPoint(dpy, d, gc, x, y+1);
190 XSetForeground(dpy, gc, scr->white_pixel);
191 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
192 XDrawPoint(dpy, d, gc, x+1, y+1);
196 static WPixmap*
197 make3Dots(WScreen *scr)
199 WPixmap *wpix;
200 GC gc2, gc;
201 XGCValues gcv;
202 Pixmap pix, mask;
204 gc = scr->copy_gc;
205 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
206 wPreferences.icon_size, scr->w_depth);
207 XSetForeground(dpy, gc, scr->black_pixel);
208 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
209 wPreferences.icon_size);
210 XSetForeground(dpy, gc, scr->white_pixel);
211 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
212 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
213 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
215 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
216 wPreferences.icon_size, 1);
217 gcv.foreground = 0;
218 gcv.graphics_exposures = False;
219 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
220 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
221 wPreferences.icon_size);
222 XSetForeground(dpy, gc2, 1);
223 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
224 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
225 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
227 XFreeGC(dpy, gc2);
229 wpix = wPixmapCreate(scr, pix, mask);
230 wpix->shared = 1;
232 return wpix;
236 static void
237 allocGCs(WScreen *scr)
239 XGCValues gcv;
240 XColor color;
241 unsigned long mtextcolor;
242 int gcm;
244 scr->stipple_bitmap =
245 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
246 STIPPLE_HEIGHT);
248 gcv.stipple = scr->stipple_bitmap;
249 gcv.foreground = scr->white_pixel;
250 gcv.fill_style = FillStippled;
251 gcv.graphics_exposures = False;
252 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
253 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
256 /* selected icon border GCs */
257 gcv.function = GXcopy;
258 gcv.foreground = scr->white_pixel;
259 gcv.background = scr->black_pixel;
260 gcv.line_width = 1;
261 gcv.line_style = LineDoubleDash;
262 gcv.fill_style = FillSolid;
263 gcv.dash_offset = 0;
264 gcv.dashes = 4;
265 gcv.graphics_exposures = False;
267 gcm = GCFunction | GCGraphicsExposures;
268 gcm |= GCForeground | GCBackground;
269 gcm |= GCLineWidth | GCLineStyle;
270 gcm |= GCFillStyle;
271 gcm |= GCDashOffset | GCDashList;
273 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
275 gcm = GCForeground|GCGraphicsExposures;
277 scr->menu_title_pixel[0] = scr->white_pixel;
278 gcv.foreground = scr->white_pixel;
279 gcv.graphics_exposures = False;
280 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
282 scr->mtext_pixel = scr->black_pixel;
283 mtextcolor = gcv.foreground = scr->black_pixel;
284 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
286 /* selected menu entry GC */
287 gcm = GCForeground|GCBackground|GCGraphicsExposures;
288 gcv.foreground = scr->white_pixel;
289 gcv.background = scr->white_pixel;
290 gcv.graphics_exposures = False;
291 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
293 /* disabled menu entry GC */
294 scr->dtext_pixel = scr->black_pixel;
295 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
296 gcv.stipple = scr->stipple_bitmap;
297 gcv.graphics_exposures = False;
298 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
300 /* frame GC */
301 wGetColor(scr, DEF_FRAME_COLOR, &color);
302 gcv.function = GXxor;
303 /* this will raise the probability of the XORed color being different
304 * of the original color in PseudoColor when not all color cells are
305 * initialized */
306 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
307 gcv.plane_mask = (1<<(scr->depth-1))|1;
308 else
309 gcv.plane_mask = AllPlanes;
310 gcv.foreground = color.pixel;
311 if (gcv.foreground == 0)
312 gcv.foreground = 1;
313 gcv.line_width = DEF_FRAME_THICKNESS;
314 gcv.subwindow_mode = IncludeInferiors;
315 gcv.graphics_exposures = False;
316 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
317 |GCFunction|GCSubwindowMode|GCLineWidth
318 |GCPlaneMask, &gcv);
320 /* line GC */
321 gcv.foreground = color.pixel;
323 if (gcv.foreground == 0)
324 /* XOR:ing with a zero is not going to be of much use, so
325 in that case, we somewhat arbitrarily xor with 17 instead. */
326 gcv.foreground = 17;
328 gcv.function = GXxor;
329 gcv.subwindow_mode = IncludeInferiors;
330 gcv.line_width = 1;
331 gcv.cap_style = CapRound;
332 gcv.graphics_exposures = False;
333 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
334 |GCGraphicsExposures;
335 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
337 scr->line_pixel = gcv.foreground;
339 /* copy GC */
340 gcv.foreground = scr->white_pixel;
341 gcv.background = scr->black_pixel;
342 gcv.graphics_exposures = False;
343 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
344 |GCGraphicsExposures, &gcv);
346 /* window title text GC */
347 gcv.graphics_exposures = False;
348 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
350 /* icon title GC */
351 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
353 /* clip title GC */
354 scr->clip_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
356 /* move/size display GC */
357 gcv.graphics_exposures = False;
358 gcm = GCGraphicsExposures;
359 scr->info_text_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
361 /* misc drawing GC */
362 gcv.graphics_exposures = False;
363 gcm = GCGraphicsExposures;
364 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
369 static void
370 createPixmaps(WScreen *scr)
372 WPixmap *pix;
373 WMPixmap *wmpix;
374 RImage *image;
375 Pixmap p, m;
377 /* load pixmaps */
378 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
379 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
380 MENU_RADIO_INDICATOR_XBM_SIZE,
381 MENU_RADIO_INDICATOR_XBM_SIZE,
382 scr->black_pixel, scr->white_pixel);
383 if (pix!=NULL)
384 pix->shared = 1;
385 scr->menu_radio_indicator = pix;
388 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
389 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
390 MENU_CHECK_INDICATOR_XBM_SIZE,
391 MENU_CHECK_INDICATOR_XBM_SIZE,
392 scr->black_pixel, scr->white_pixel);
393 if (pix!=NULL)
394 pix->shared = 1;
395 scr->menu_check_indicator = pix;
397 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
398 (char*)MENU_MINI_INDICATOR_XBM_DATA,
399 MENU_MINI_INDICATOR_XBM_SIZE,
400 MENU_MINI_INDICATOR_XBM_SIZE,
401 scr->black_pixel, scr->white_pixel);
402 if (pix!=NULL)
403 pix->shared = 1;
404 scr->menu_mini_indicator = pix;
406 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
407 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
408 MENU_HIDE_INDICATOR_XBM_SIZE,
409 MENU_HIDE_INDICATOR_XBM_SIZE,
410 scr->black_pixel, scr->white_pixel);
411 if (pix!=NULL)
412 pix->shared = 1;
413 scr->menu_hide_indicator = pix;
415 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
416 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
417 MENU_SHADE_INDICATOR_XBM_SIZE,
418 MENU_SHADE_INDICATOR_XBM_SIZE,
419 scr->black_pixel, scr->white_pixel);
420 if (pix!=NULL)
421 pix->shared = 1;
422 scr->menu_shade_indicator = pix;
425 image = wDefaultGetImage(scr, "Logo", "WMPanel");
427 if (!image) {
428 wwarning(_("could not load logo image for panels"));
429 } else {
430 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
431 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
432 } else {
433 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
434 image->width, image->height,
435 scr->depth);
436 WMSetApplicationIconImage(scr->wmscreen, wmpix);
437 WMReleasePixmap(wmpix);
439 RDestroyImage(image);
442 if (!wPreferences.flags.nodock || !wPreferences.flags.noclip) {
443 scr->dock_dots = make3Dots(scr);
446 /* titlebar button pixmaps */
447 allocButtonPixmaps(scr);
452 *----------------------------------------------------------------------
453 * createInternalWindows--
454 * Creates some windows used internally by the program. One to
455 * receive input focus when no other window can get it and another
456 * to display window geometry information during window resize/move.
458 * Returns:
459 * Nothing
461 * Side effects:
462 * Windows are created and some colors are allocated for the
463 * window background.
464 *----------------------------------------------------------------------
466 static void
467 createInternalWindows(WScreen *scr)
469 int vmask;
470 XSetWindowAttributes attribs;
472 /* window for displaying geometry information during resizes and moves */
473 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
474 attribs.border_pixel = 0;
475 attribs.save_under = True;
476 attribs.override_redirect = True;
477 attribs.cursor = wCursor[WCUR_DEFAULT];
478 attribs.background_pixmap = None;
479 if (scr->resizebar_texture[0])
480 attribs.background_pixel = scr->resizebar_texture[0]->normal.pixel;
481 else
482 attribs.background_pixel = scr->light_pixel;
483 vmask |= CWColormap;
484 attribs.colormap = scr->w_colormap;
486 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
487 &scr->geometry_display_height);
488 scr->geometry_display =
489 XCreateWindow(dpy, scr->root_win, 1, 1,
490 scr->geometry_display_width,
491 scr->geometry_display_height,
492 1, scr->w_depth, CopyFromParent, scr->w_visual,
493 vmask, &attribs);
495 /* InputOnly window to get the focus when no other window can get it */
496 vmask = CWEventMask|CWOverrideRedirect;
497 attribs.event_mask = KeyPressMask|FocusChangeMask;
498 attribs.override_redirect = True;
499 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
500 InputOnly,CopyFromParent, vmask, &attribs);
501 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
502 XMapWindow(dpy, scr->no_focus_win);
504 XSetInputFocus (dpy, scr->no_focus_win, RevertToParent, CurrentTime);
506 /* shadow window for dock buttons */
507 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
508 attribs.border_pixel = 0;
509 attribs.save_under = True;
510 attribs.override_redirect = True;
511 attribs.background_pixmap = None;
512 attribs.background_pixel = scr->white_pixel;
513 vmask |= CWColormap;
514 attribs.colormap = scr->w_colormap;
515 scr->dock_shadow =
516 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
517 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
518 scr->w_visual, vmask, &attribs);
520 /* workspace name balloon for clip */
521 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
522 |CWBorderPixel;
523 attribs.save_under = True;
524 attribs.override_redirect = True;
525 attribs.colormap = scr->w_colormap;
526 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
527 attribs.border_pixel = 0; /* do not care */
528 scr->clip_balloon =
529 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
530 CopyFromParent, scr->w_visual, vmask, &attribs);
532 /* for our window manager info notice board */
533 scr->info_window =
534 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, CopyFromParent,
535 CopyFromParent, CopyFromParent, 0, NULL);
538 * If the window is clicked without having ButtonPress selected, the
539 * resulting event will have event.xbutton.window == root.
541 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
545 #if 0
546 static Bool
547 aquireManagerSelection(WScreen *scr)
549 char buffer[32];
550 XEvent ev;
551 Time timestamp;
553 sprintf(buffer, "WM_S%i", scr->screen);
554 scr->managerAtom = XInternAtom(dpy, buffer, False);
556 /* for race-conditions... */
557 XGrabServer(dpy);
559 /* if there is another manager running, don't try to replace it
560 * (for now, at least) */
561 if (XGetSelectionOwner(dpy, scr->managerAtom) != None) {
562 XUngrabServer(dpy);
563 return False;
566 /* become the manager for this screen */
568 scr->managerWindow = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 1, 1,
569 0, 0, 0);
571 XSelectInput(dpy, scr->managerWindow, PropertyChangeMask);
572 /* get a timestamp */
573 XChangeProperty(dpy, scr->managerWindow, scr->managerAtom,
574 XA_INTEGER, 32, PropModeAppend, NULL, 0);
575 while (1) {
576 XWindowEvent(dpy, scr->managerWindow, &ev);
577 if (ev.type == PropertyNotify) {
578 timestamp = ev.xproperty.time;
579 break;
582 XSelectInput(dpy, scr->managerWindow, NoEvents);
583 XDeleteProperty(dpy, scr->managerWindow, scr->managerAtom);
585 XSetSelectionOwner(dpy, scr->managerAtom, scr->managerWindow, CurrentTime);
587 XUngrabServer(dpy);
589 /* announce our arrival */
591 ev.xclient.type = ClientMessage;
592 ev.xclient.message_type = XInternAtom(dpy, "MANAGER", False);
593 ev.xclient.destination = scr->root_win;
594 ev.xclient.format = 32;
595 ev.xclient.data.l[0] = timestamp;
596 ev.xclient.data.l[1] = scr->managerAtom;
597 ev.xclient.data.l[2] = scr->managerWindow;
598 ev.xclient.data.l[3] = 0;
599 ev.xclient.data.l[4] = 0;
601 XSendEvent(dpy, scr->root_win, False, StructureNotify, &ev);
602 XSync(dpy, False);
604 return True;
606 #endif
609 *----------------------------------------------------------------------
610 * wScreenInit--
611 * Initializes the window manager for the given screen and
612 * allocates a WScreen descriptor for it. Many resources are allocated
613 * for the screen and the root window is setup appropriately.
615 * Returns:
616 * The WScreen descriptor for the screen.
618 * Side effects:
619 * Many resources are allocated and the IconSize property is
620 * set on the root window.
621 * The program can be aborted if some fatal error occurs.
623 * TODO: User specifiable visual.
624 *----------------------------------------------------------------------
626 WScreen*
627 wScreenInit(int screen_number)
629 WScreen *scr;
630 XIconSize icon_size[1];
631 RContextAttributes rattr;
632 extern int wVisualID;
633 long event_mask;
634 WMColor *color;
635 XErrorHandler oldHandler;
637 scr = wmalloc(sizeof(WScreen));
638 memset(scr, 0, sizeof(WScreen));
640 /* initialize globals */
641 scr->screen = screen_number;
642 scr->root_win = RootWindow(dpy, screen_number);
643 scr->depth = DefaultDepth(dpy, screen_number);
644 scr->colormap = DefaultColormap(dpy, screen_number);
646 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
647 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
649 scr->usableArea.x2 = scr->scr_width;
650 scr->usableArea.y2 = scr->scr_height;
651 scr->totalUsableArea.x2 = scr->scr_width;
652 scr->totalUsableArea.y2 = scr->scr_height;
654 #if 0
655 if (!aquireManagerSelection(scr)) {
656 free(scr);
658 return NULL;
660 #endif
661 CantManageScreen = 0;
662 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
664 event_mask = EVENT_MASK;
666 if (wPreferences.disable_root_mouse) {
667 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
670 XSelectInput(dpy, scr->root_win, event_mask);
672 XSync(dpy, False);
673 XSetErrorHandler(oldHandler);
675 if (CantManageScreen) {
676 free(scr);
677 return NULL;
680 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_DEFAULT]);
682 /* screen descriptor for raster graphic library */
683 rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
684 rattr.render_mode = wPreferences.no_dithering?RM_MATCH:RM_DITHER;
685 rattr.colors_per_channel = wPreferences.cmap_size;
686 if (rattr.colors_per_channel<2)
687 rattr.colors_per_channel = 2;
689 if (wVisualID>=0) {
690 rattr.flags |= RC_VisualID;
691 rattr.visualid = wVisualID;
693 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
694 if (!scr->rcontext) {
695 wwarning(_("could not initialize graphics library context: %s"),
696 RMessageForError(RErrorCode));
697 wAbort(False);
698 } else {
699 char **formats;
700 int i = 0;
702 formats = RSupportedFileFormats();
703 if (formats) {
704 for (i=0; formats[i]!=NULL; i++) {
705 if (strcmp(formats[i], "TIFF")==0) {
706 scr->flags.supports_tiff = 1;
707 break;
713 scr->w_win = scr->rcontext->drawable;
714 scr->w_visual = scr->rcontext->visual;
715 scr->w_depth = scr->rcontext->depth;
716 scr->w_colormap = scr->rcontext->cmap;
718 scr->black_pixel = scr->rcontext->black;
719 scr->white_pixel = scr->rcontext->white;
721 /* create screen descriptor for WINGs */
722 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
723 scr->rcontext);
725 if (!scr->wmscreen) {
726 wfatal(_("could not do initialization of WINGs widget set"));
728 return NULL;
731 color = WMGrayColor(scr->wmscreen);
732 scr->light_pixel = WMColorPixel(color);
733 WMReleaseColor(color);
735 color = WMDarkGrayColor(scr->wmscreen);
736 scr->dark_pixel = WMColorPixel(color);
737 WMReleaseColor(color);
740 XColor xcol;
741 /* frame boder color */
742 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
743 scr->frame_border_pixel = xcol.pixel;
746 /* create GCs with default values */
747 allocGCs(scr);
749 /* read defaults for this screen */
750 wReadDefaults(scr, WDWindowMaker->dictionary);
752 createInternalWindows(scr);
754 #ifdef KWM_HINTS
755 wKWMInitStuff(scr);
756 #endif
758 #ifdef GNOME_STUFF
759 wGNOMEInitStuff(scr);
760 #endif
762 #ifdef OLWM_HINTS
763 wOLWMInitStuff(scr);
764 #endif
766 /* create initial workspace */
767 wWorkspaceNew(scr);
769 /* create shared pixmaps */
770 createPixmaps(scr);
772 /* set icon sizes we can accept from clients */
773 icon_size[0].min_width = 8;
774 icon_size[0].min_height = 8;
775 icon_size[0].max_width = wPreferences.icon_size-4;
776 icon_size[0].max_height = wPreferences.icon_size-4;
777 icon_size[0].width_inc = 1;
778 icon_size[0].height_inc = 1;
779 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
781 /* setup WindowMaker protocols property in the root window*/
782 PropSetWMakerProtocols(scr->root_win);
784 /* setup our noticeboard */
785 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
786 XA_WINDOW, 32, PropModeReplace,
787 (unsigned char*)&scr->info_window, 1);
788 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
789 XA_WINDOW, 32, PropModeReplace,
790 (unsigned char*)&scr->info_window, 1);
793 #ifdef BALLOON_TEXT
794 /* initialize balloon text stuff */
795 wBalloonInitialize(scr);
796 #endif
798 wScreenUpdateUsableArea(scr);
800 #ifndef LITE
801 /* kluge to load menu configurations at startup */
802 OpenRootMenu(scr, -10000, -10000, False);
803 wMenuUnmap(scr->root_menu);
804 #endif
806 return scr;
810 void
811 wScreenUpdateUsableArea(WScreen *scr)
813 #ifdef GNOME_STUFF
814 WReservedArea *area;
815 #endif
817 scr->totalUsableArea = scr->usableArea;
820 if (scr->dock && (!scr->dock->lowered
821 || wPreferences.no_window_over_dock)) {
823 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
825 if (scr->dock->on_right_side) {
826 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
827 scr->scr_width - offset);
828 } else {
829 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
833 if (wPreferences.no_window_over_icons) {
834 if (wPreferences.icon_yard & IY_VERT) {
836 if (!(wPreferences.icon_yard & IY_RIGHT)) {
837 scr->totalUsableArea.x1 += wPreferences.icon_size;
838 } else {
839 scr->totalUsableArea.x2 -= wPreferences.icon_size;
841 } else {
843 if (wPreferences.icon_yard & IY_TOP) {
844 scr->totalUsableArea.y1 += wPreferences.icon_size;
845 } else {
846 scr->totalUsableArea.y2 -= wPreferences.icon_size;
851 #ifdef KWM_HINTS
853 WArea area;
855 if (wKWMGetUsableArea(scr, &area)) {
856 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
857 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
858 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
859 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
862 #endif
864 #ifdef GNOME_STUFF
865 area = scr->reservedAreas;
867 while (area) {
868 int th, bh;
869 int lw, rw;
870 int w, h;
872 w = area->area.x2 - area->area.x1;
873 h = area->area.y2 - area->area.y1;
875 th = area->area.y1;
876 bh = scr->scr_height - area->area.y2;
877 lw = area->area.x1;
878 rw = scr->scr_width - area->area.x2;
880 if (WMIN(th, bh) < WMIN(lw, rw)) {
881 /* horizontal */
882 if (th < bh) {
883 /* on top */
884 if (scr->totalUsableArea.y1 < area->area.y2)
885 scr->totalUsableArea.y1 = area->area.y2;
886 } else {
887 /* on bottom */
888 if (scr->totalUsableArea.y2 > area->area.y1)
889 scr->totalUsableArea.y2 = area->area.y1;
891 } else {
892 /* vertical */
893 if (lw < rw) {
894 /* on left */
895 if (scr->totalUsableArea.x1 < area->area.x2)
896 scr->totalUsableArea.x1 = area->area.x2;
897 } else {
898 /* on right */
899 if (scr->totalUsableArea.x2 > area->area.x1)
900 scr->totalUsableArea.x2 = area->area.x1;
904 area = area->next;
906 #endif /* GNOME_STUFF */
908 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
909 scr->totalUsableArea.x2 = scr->usableArea.x2;
910 scr->totalUsableArea.x1 = scr->usableArea.x1;
912 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
913 scr->totalUsableArea.y2 = scr->usableArea.y2;
914 scr->totalUsableArea.y1 = scr->usableArea.y1;
917 #ifdef not_used
918 #ifdef KWM_HINTS
920 int i;
922 for (i = 0; i < scr->workspace_count; i++) {
923 wKWMSetUsableAreaHint(scr, i);
926 #endif
927 #endif
931 void
932 wScreenRestoreState(WScreen *scr)
934 proplist_t state;
935 char *path;
937 make_keys();
939 if (wScreenCount == 1)
940 path = wdefaultspathfordomain("WMState");
941 else {
942 char buf[16];
943 sprintf(buf, "WMState.%i", scr->screen);
944 path = wdefaultspathfordomain(buf);
946 scr->session_state = PLGetProplistWithPath(path);
947 free(path);
948 if (!scr->session_state && wScreenCount>1) {
949 char buf[16];
950 sprintf(buf, "WMState.%i", scr->screen);
951 path = wdefaultspathfordomain(buf);
952 scr->session_state = PLGetProplistWithPath(path);
953 free(path);
956 if (!wPreferences.flags.noclip) {
957 state = PLGetDictionaryEntry(scr->session_state, dClip);
958 scr->clip_icon = wClipRestoreState(scr, state);
961 wWorkspaceRestoreState(scr);
963 if (!wPreferences.flags.nodock) {
964 state = PLGetDictionaryEntry(scr->session_state, dDock);
965 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
968 wScreenUpdateUsableArea(scr);
972 void
973 wScreenSaveState(WScreen *scr)
975 WWorkspaceState wstate;
976 WWindow *wwin;
977 char *str;
978 proplist_t path, old_state, foo;
979 CARD32 data[2];
982 make_keys();
985 * Save current workspace, so can go back to it upon restart.
987 wstate.workspace = scr->current_workspace;
989 data[0] = wstate.flags;
990 data[1] = wstate.workspace;
992 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
993 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
994 (unsigned char *) data, 2);
996 /* save state of windows */
997 wwin = scr->focused_window;
998 while (wwin) {
999 wWindowSaveState(wwin);
1000 wwin = wwin->prev;
1004 if (wPreferences.flags.noupdates)
1005 return;
1008 old_state = scr->session_state;
1009 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
1011 PLSetStringCmpHook(NULL);
1013 /* save dock state to file */
1014 if (!wPreferences.flags.nodock) {
1015 wDockSaveState(scr);
1016 } else {
1017 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
1018 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
1021 if (!wPreferences.flags.noclip) {
1022 wClipSaveState(scr);
1023 } else {
1024 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
1025 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
1029 wWorkspaceSaveState(scr, old_state);
1031 if (wPreferences.save_session_on_exit) {
1032 wSessionSaveState(scr);
1033 } else {
1034 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
1035 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
1037 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
1038 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
1042 /* clean up */
1043 PLSetStringCmpHook(StringCompareHook);
1045 wMenuSaveState(scr);
1047 if (wScreenCount == 1)
1048 str = wdefaultspathfordomain("WMState");
1049 else {
1050 char buf[16];
1051 sprintf(buf, "WMState.%i", scr->screen);
1052 str = wdefaultspathfordomain(buf);
1054 path = PLMakeString(str);
1055 free(str);
1056 PLSetFilename(scr->session_state, path);
1057 if (!PLSave(scr->session_state, YES)) {
1058 wwarning(_("could not save session state in %s"), PLGetString(path));
1060 PLRelease(path);
1061 PLRelease(old_state);
1067 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1069 int moved = 0;
1070 int tol_w, tol_h;
1072 if (width > 20)
1073 tol_w = width/2;
1074 else
1075 tol_w = 20;
1077 if (height > 20)
1078 tol_h = height/2;
1079 else
1080 tol_h = 20;
1082 if (*x+width < 10)
1083 *x = -tol_w, moved = 1;
1084 else if (*x >= scr->scr_width - 10)
1085 *x = scr->scr_width - tol_w - 1, moved = 1;
1087 if (*y < -height + 10)
1088 *y = -tol_h, moved = 1;
1089 else if (*y >= scr->scr_height - 10)
1090 *y = scr->scr_height - tol_h - 1, moved = 1;
1092 return moved;