Initial update from my source tree. For 0.52.0
[wmaker-crm.git] / src / screen.c
blob5264ae83098f4104b55e3c13b65277deacff57f4
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
35 #ifdef KEEP_XKB_LOCK_STATUS
36 #include <X11/XKBlib.h>
37 #endif /* KEEP_XKB_LOCK_STATUS */
39 #include <wraster.h>
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
43 #include "screen.h"
44 #include "texture.h"
45 #include "pixmap.h"
46 #include "menu.h"
47 #include "funcs.h"
48 #include "actions.h"
49 #include "properties.h"
50 #include "dock.h"
51 #include "resources.h"
52 #include "workspace.h"
53 #include "session.h"
54 #include "balloon.h"
55 #ifdef KWM_HINTS
56 # include "kwm.h"
57 #endif
58 #ifdef GNOME_STUFF
59 # include "gnome.h"
60 #endif
61 #ifdef OLWM_HINTS
62 # include "openlook.h"
63 #endif
65 #include <proplist.h>
67 #include "defaults.h"
70 #ifdef LITE
71 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
72 |SubstructureNotifyMask|PointerMotionMask \
73 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
74 #else
75 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
76 |SubstructureNotifyMask|PointerMotionMask \
77 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
78 |KeyPressMask|KeyReleaseMask)
79 #endif
81 /**** Global variables ****/
83 extern Cursor wCursor[WCUR_LAST];
84 extern WPreferences wPreferences;
85 extern Atom _XA_WINDOWMAKER_STATE;
86 extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
89 extern int wScreenCount;
91 extern WDDomain *WDWindowMaker;
94 /**** Local ****/
96 #define STIPPLE_WIDTH 2
97 #define STIPPLE_HEIGHT 2
98 static char STIPPLE_DATA[] = {0x02, 0x01};
100 static int CantManageScreen = 0;
102 static proplist_t dApplications = NULL;
103 static proplist_t dWorkspace;
104 static proplist_t dDock;
105 static proplist_t dClip;
108 static void
109 make_keys()
111 if (dApplications!=NULL)
112 return;
114 dApplications = PLMakeString("Applications");
115 dWorkspace = PLMakeString("Workspace");
116 dDock = PLMakeString("Dock");
117 dClip = PLMakeString("Clip");
122 *----------------------------------------------------------------------
123 * alreadyRunningError--
124 * X error handler used to catch errors when trying to do
125 * XSelectInput() on the root window. These errors probably mean that
126 * there already is some other window manager running.
128 * Returns:
129 * Nothing, unless something really evil happens...
131 * Side effects:
132 * CantManageScreen is set to 1;
133 *----------------------------------------------------------------------
135 static int
136 alreadyRunningError(Display *dpy, XErrorEvent *error)
138 CantManageScreen = 1;
139 return -1;
144 *----------------------------------------------------------------------
145 * allocButtonPixmaps--
146 * Allocate pixmaps used on window operation buttons (those in the
147 * titlebar). The pixmaps are linked to the program. If XPM is supported
148 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
150 * Returns:
151 * Nothing
153 * Side effects:
154 * Allocates shared pixmaps for the screen. These pixmaps should
155 * not be freed by anybody.
156 *----------------------------------------------------------------------
158 static void
159 allocButtonPixmaps(WScreen *scr)
161 WPixmap *pix;
163 /* create predefined pixmaps */
164 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
165 if (pix)
166 pix->shared = 1;
167 scr->b_pixmaps[WBUT_CLOSE] = pix;
169 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
170 if (pix)
171 pix->shared = 1;
172 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
174 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
175 if (pix)
176 pix->shared = 1;
177 scr->b_pixmaps[WBUT_ICONIFY] = pix;
179 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
180 if (pix)
181 pix->shared = 1;
182 scr->b_pixmaps[WBUT_KILL] = pix;
187 static void
188 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
190 XSetForeground(dpy, gc, scr->black_pixel);
191 XDrawLine(dpy, d, gc, x, y, x+1, y);
192 XDrawPoint(dpy, d, gc, x, y+1);
193 XSetForeground(dpy, gc, scr->white_pixel);
194 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
195 XDrawPoint(dpy, d, gc, x+1, y+1);
199 static WPixmap*
200 make3Dots(WScreen *scr)
202 WPixmap *wpix;
203 GC gc2, gc;
204 XGCValues gcv;
205 Pixmap pix, mask;
207 gc = scr->copy_gc;
208 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
209 wPreferences.icon_size, scr->w_depth);
210 XSetForeground(dpy, gc, scr->black_pixel);
211 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
212 wPreferences.icon_size);
213 XSetForeground(dpy, gc, scr->white_pixel);
214 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
215 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
216 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
218 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
219 wPreferences.icon_size, 1);
220 gcv.foreground = 0;
221 gcv.graphics_exposures = False;
222 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
223 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
224 wPreferences.icon_size);
225 XSetForeground(dpy, gc2, 1);
226 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
227 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
228 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
230 XFreeGC(dpy, gc2);
232 wpix = wPixmapCreate(scr, pix, mask);
233 wpix->shared = 1;
235 return wpix;
239 static void
240 allocGCs(WScreen *scr)
242 XGCValues gcv;
243 XColor color;
244 unsigned long mtextcolor;
245 int gcm;
247 scr->stipple_bitmap =
248 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
249 STIPPLE_HEIGHT);
251 gcv.stipple = scr->stipple_bitmap;
252 gcv.foreground = scr->white_pixel;
253 gcv.fill_style = FillStippled;
254 gcv.graphics_exposures = False;
255 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
256 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
259 /* selected icon border GCs */
260 gcv.function = GXcopy;
261 gcv.foreground = scr->white_pixel;
262 gcv.background = scr->black_pixel;
263 gcv.line_width = 1;
264 gcv.line_style = LineDoubleDash;
265 gcv.fill_style = FillSolid;
266 gcv.dash_offset = 0;
267 gcv.dashes = 4;
268 gcv.graphics_exposures = False;
270 gcm = GCFunction | GCGraphicsExposures;
271 gcm |= GCForeground | GCBackground;
272 gcm |= GCLineWidth | GCLineStyle;
273 gcm |= GCFillStyle;
274 gcm |= GCDashOffset | GCDashList;
276 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
278 gcm = GCForeground|GCGraphicsExposures;
280 scr->menu_title_pixel[0] = scr->white_pixel;
281 gcv.foreground = scr->white_pixel;
282 gcv.graphics_exposures = False;
283 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
285 scr->mtext_pixel = scr->black_pixel;
286 mtextcolor = gcv.foreground = scr->black_pixel;
287 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
289 /* selected menu entry GC */
290 gcm = GCForeground|GCBackground|GCGraphicsExposures;
291 gcv.foreground = scr->white_pixel;
292 gcv.background = scr->white_pixel;
293 gcv.graphics_exposures = False;
294 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
296 /* disabled menu entry GC */
297 scr->dtext_pixel = scr->black_pixel;
298 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
299 gcv.stipple = scr->stipple_bitmap;
300 gcv.graphics_exposures = False;
301 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
303 /* frame GC */
304 wGetColor(scr, DEF_FRAME_COLOR, &color);
305 gcv.function = GXxor;
306 /* this will raise the probability of the XORed color being different
307 * of the original color in PseudoColor when not all color cells are
308 * initialized */
309 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
310 gcv.plane_mask = (1<<(scr->depth-1))|1;
311 else
312 gcv.plane_mask = AllPlanes;
313 gcv.foreground = color.pixel;
314 if (gcv.foreground == 0)
315 gcv.foreground = 1;
316 gcv.line_width = DEF_FRAME_THICKNESS;
317 gcv.subwindow_mode = IncludeInferiors;
318 gcv.graphics_exposures = False;
319 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
320 |GCFunction|GCSubwindowMode|GCLineWidth
321 |GCPlaneMask, &gcv);
323 /* line GC */
324 gcv.foreground = color.pixel;
326 if (gcv.foreground == 0)
327 /* XOR:ing with a zero is not going to be of much use, so
328 in that case, we somewhat arbitrarily xor with 17 instead. */
329 gcv.foreground = 17;
331 gcv.function = GXxor;
332 gcv.subwindow_mode = IncludeInferiors;
333 gcv.line_width = 1;
334 gcv.cap_style = CapRound;
335 gcv.graphics_exposures = False;
336 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
337 |GCGraphicsExposures;
338 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
340 scr->line_pixel = gcv.foreground;
342 /* copy GC */
343 gcv.foreground = scr->white_pixel;
344 gcv.background = scr->black_pixel;
345 gcv.graphics_exposures = False;
346 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
347 |GCGraphicsExposures, &gcv);
349 /* window title text GC */
350 gcv.graphics_exposures = False;
351 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
353 /* icon title GC */
354 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
356 /* clip title GC */
357 scr->clip_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
359 /* move/size display GC */
360 gcv.graphics_exposures = False;
361 gcm = GCGraphicsExposures;
362 scr->info_text_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
364 /* misc drawing GC */
365 gcv.graphics_exposures = False;
366 gcm = GCGraphicsExposures;
367 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
372 static void
373 createPixmaps(WScreen *scr)
375 WPixmap *pix;
376 WMPixmap *wmpix;
377 RImage *image;
378 Pixmap p, m;
380 /* load pixmaps */
381 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
382 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
383 MENU_RADIO_INDICATOR_XBM_SIZE,
384 MENU_RADIO_INDICATOR_XBM_SIZE,
385 scr->black_pixel, scr->white_pixel);
386 if (pix!=NULL)
387 pix->shared = 1;
388 scr->menu_radio_indicator = pix;
391 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
392 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
393 MENU_CHECK_INDICATOR_XBM_SIZE,
394 MENU_CHECK_INDICATOR_XBM_SIZE,
395 scr->black_pixel, scr->white_pixel);
396 if (pix!=NULL)
397 pix->shared = 1;
398 scr->menu_check_indicator = pix;
400 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
401 (char*)MENU_MINI_INDICATOR_XBM_DATA,
402 MENU_MINI_INDICATOR_XBM_SIZE,
403 MENU_MINI_INDICATOR_XBM_SIZE,
404 scr->black_pixel, scr->white_pixel);
405 if (pix!=NULL)
406 pix->shared = 1;
407 scr->menu_mini_indicator = pix;
409 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
410 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
411 MENU_HIDE_INDICATOR_XBM_SIZE,
412 MENU_HIDE_INDICATOR_XBM_SIZE,
413 scr->black_pixel, scr->white_pixel);
414 if (pix!=NULL)
415 pix->shared = 1;
416 scr->menu_hide_indicator = pix;
418 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
419 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
420 MENU_SHADE_INDICATOR_XBM_SIZE,
421 MENU_SHADE_INDICATOR_XBM_SIZE,
422 scr->black_pixel, scr->white_pixel);
423 if (pix!=NULL)
424 pix->shared = 1;
425 scr->menu_shade_indicator = pix;
428 image = wDefaultGetImage(scr, "Logo", "WMPanel");
430 if (!image) {
431 wwarning(_("could not load logo image for panels: %s"),
432 RMessageForError(RErrorCode));
433 } else {
434 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
435 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
436 } else {
437 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
438 image->width, image->height,
439 scr->depth);
440 WMSetApplicationIconImage(scr->wmscreen, wmpix);
441 WMReleasePixmap(wmpix);
443 RDestroyImage(image);
446 if (!wPreferences.flags.nodock || !wPreferences.flags.noclip) {
447 scr->dock_dots = make3Dots(scr);
450 /* titlebar button pixmaps */
451 allocButtonPixmaps(scr);
456 *----------------------------------------------------------------------
457 * createInternalWindows--
458 * Creates some windows used internally by the program. One to
459 * receive input focus when no other window can get it and another
460 * to display window geometry information during window resize/move.
462 * Returns:
463 * Nothing
465 * Side effects:
466 * Windows are created and some colors are allocated for the
467 * window background.
468 *----------------------------------------------------------------------
470 static void
471 createInternalWindows(WScreen *scr)
473 int vmask;
474 XSetWindowAttributes attribs;
476 /* window for displaying geometry information during resizes and moves */
477 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
478 attribs.border_pixel = 0;
479 attribs.save_under = True;
480 attribs.override_redirect = True;
481 attribs.cursor = wCursor[WCUR_DEFAULT];
482 attribs.background_pixmap = None;
483 if (scr->resizebar_texture[0])
484 attribs.background_pixel = scr->resizebar_texture[0]->normal.pixel;
485 else
486 attribs.background_pixel = scr->light_pixel;
487 vmask |= CWColormap;
488 attribs.colormap = scr->w_colormap;
490 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
491 &scr->geometry_display_height);
492 scr->geometry_display =
493 XCreateWindow(dpy, scr->root_win, 1, 1,
494 scr->geometry_display_width,
495 scr->geometry_display_height,
496 1, scr->w_depth, CopyFromParent, scr->w_visual,
497 vmask, &attribs);
499 /* InputOnly window to get the focus when no other window can get it */
500 vmask = CWEventMask|CWOverrideRedirect;
501 attribs.event_mask = KeyPressMask|FocusChangeMask;
502 attribs.override_redirect = True;
503 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
504 InputOnly,CopyFromParent, vmask, &attribs);
505 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
506 XMapWindow(dpy, scr->no_focus_win);
508 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
510 /* shadow window for dock buttons */
511 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
512 attribs.border_pixel = 0;
513 attribs.save_under = True;
514 attribs.override_redirect = True;
515 attribs.background_pixmap = None;
516 attribs.background_pixel = scr->white_pixel;
517 vmask |= CWColormap;
518 attribs.colormap = scr->w_colormap;
519 scr->dock_shadow =
520 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
521 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
522 scr->w_visual, vmask, &attribs);
524 /* workspace name balloon for clip */
525 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
526 |CWBorderPixel;
527 attribs.save_under = True;
528 attribs.override_redirect = True;
529 attribs.colormap = scr->w_colormap;
530 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
531 attribs.border_pixel = 0; /* do not care */
532 scr->clip_balloon =
533 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
534 CopyFromParent, scr->w_visual, vmask, &attribs);
537 /* for our window manager info notice board */
538 scr->info_window =
539 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, CopyFromParent,
540 CopyFromParent, CopyFromParent, CWOverrideRedirect,
541 &attribs);
544 * If the window is clicked without having ButtonPress selected, the
545 * resulting event will have event.xbutton.window == root.
547 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
551 #if 0
552 static Bool
553 aquireManagerSelection(WScreen *scr)
555 char buffer[32];
556 XEvent ev;
557 Time timestamp;
559 sprintf(buffer, "WM_S%i", scr->screen);
560 scr->managerAtom = XInternAtom(dpy, buffer, False);
562 /* for race-conditions... */
563 XGrabServer(dpy);
565 /* if there is another manager running, don't try to replace it
566 * (for now, at least) */
567 if (XGetSelectionOwner(dpy, scr->managerAtom) != None) {
568 XUngrabServer(dpy);
569 return False;
572 /* become the manager for this screen */
574 scr->managerWindow = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 1, 1,
575 0, 0, 0);
577 XSelectInput(dpy, scr->managerWindow, PropertyChangeMask);
578 /* get a timestamp */
579 XChangeProperty(dpy, scr->managerWindow, scr->managerAtom,
580 XA_INTEGER, 32, PropModeAppend, NULL, 0);
581 while (1) {
582 XWindowEvent(dpy, scr->managerWindow, &ev);
583 if (ev.type == PropertyNotify) {
584 timestamp = ev.xproperty.time;
585 break;
588 XSelectInput(dpy, scr->managerWindow, NoEvents);
589 XDeleteProperty(dpy, scr->managerWindow, scr->managerAtom);
591 XSetSelectionOwner(dpy, scr->managerAtom, scr->managerWindow, CurrentTime);
593 XUngrabServer(dpy);
595 /* announce our arrival */
597 ev.xclient.type = ClientMessage;
598 ev.xclient.message_type = XInternAtom(dpy, "MANAGER", False);
599 ev.xclient.destination = scr->root_win;
600 ev.xclient.format = 32;
601 ev.xclient.data.l[0] = timestamp;
602 ev.xclient.data.l[1] = scr->managerAtom;
603 ev.xclient.data.l[2] = scr->managerWindow;
604 ev.xclient.data.l[3] = 0;
605 ev.xclient.data.l[4] = 0;
607 XSendEvent(dpy, scr->root_win, False, StructureNotify, &ev);
608 XSync(dpy, False);
610 return True;
612 #endif
615 *----------------------------------------------------------------------
616 * wScreenInit--
617 * Initializes the window manager for the given screen and
618 * allocates a WScreen descriptor for it. Many resources are allocated
619 * for the screen and the root window is setup appropriately.
621 * Returns:
622 * The WScreen descriptor for the screen.
624 * Side effects:
625 * Many resources are allocated and the IconSize property is
626 * set on the root window.
627 * The program can be aborted if some fatal error occurs.
629 * TODO: User specifiable visual.
630 *----------------------------------------------------------------------
632 WScreen*
633 wScreenInit(int screen_number)
635 WScreen *scr;
636 XIconSize icon_size[1];
637 RContextAttributes rattr;
638 extern int wVisualID;
639 long event_mask;
640 WMColor *color;
641 XErrorHandler oldHandler;
643 scr = wmalloc(sizeof(WScreen));
644 memset(scr, 0, sizeof(WScreen));
646 /* initialize globals */
647 scr->screen = screen_number;
648 scr->root_win = RootWindow(dpy, screen_number);
649 scr->depth = DefaultDepth(dpy, screen_number);
650 scr->colormap = DefaultColormap(dpy, screen_number);
652 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
653 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
655 scr->usableArea.x2 = scr->scr_width;
656 scr->usableArea.y2 = scr->scr_height;
657 scr->totalUsableArea.x2 = scr->scr_width;
658 scr->totalUsableArea.y2 = scr->scr_height;
660 #if 0
661 if (!aquireManagerSelection(scr)) {
662 free(scr);
664 return NULL;
666 #endif
667 CantManageScreen = 0;
668 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
670 event_mask = EVENT_MASK;
672 if (wPreferences.disable_root_mouse) {
673 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
676 XSelectInput(dpy, scr->root_win, event_mask);
678 #ifdef KEEP_XKB_LOCK_STATUS
679 XkbSelectEvents(dpy,XkbUseCoreKbd,XkbIndicatorStateNotifyMask,
680 XkbIndicatorStateNotifyMask);
681 #endif /* KEEP_XKB_LOCK_STATUS */
683 XSync(dpy, False);
684 XSetErrorHandler(oldHandler);
686 if (CantManageScreen) {
687 free(scr);
688 return NULL;
691 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_DEFAULT]);
693 /* screen descriptor for raster graphic library */
694 rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
695 rattr.render_mode = wPreferences.no_dithering?RM_MATCH:RM_DITHER;
696 rattr.colors_per_channel = wPreferences.cmap_size;
697 if (rattr.colors_per_channel<2)
698 rattr.colors_per_channel = 2;
700 if (wVisualID>=0) {
701 rattr.flags |= RC_VisualID;
702 rattr.visualid = wVisualID;
704 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
705 if (!scr->rcontext) {
706 wwarning(_("could not initialize graphics library context: %s"),
707 RMessageForError(RErrorCode));
708 wAbort(False);
709 } else {
710 char **formats;
711 int i = 0;
713 formats = RSupportedFileFormats();
714 if (formats) {
715 for (i=0; formats[i]!=NULL; i++) {
716 if (strcmp(formats[i], "TIFF")==0) {
717 scr->flags.supports_tiff = 1;
718 break;
724 scr->w_win = scr->rcontext->drawable;
725 scr->w_visual = scr->rcontext->visual;
726 scr->w_depth = scr->rcontext->depth;
727 scr->w_colormap = scr->rcontext->cmap;
729 scr->black_pixel = scr->rcontext->black;
730 scr->white_pixel = scr->rcontext->white;
732 /* create screen descriptor for WINGs */
733 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
734 scr->rcontext);
736 if (!scr->wmscreen) {
737 wfatal(_("could not do initialization of WINGs widget set"));
739 return NULL;
742 color = WMGrayColor(scr->wmscreen);
743 scr->light_pixel = WMColorPixel(color);
744 WMReleaseColor(color);
746 color = WMDarkGrayColor(scr->wmscreen);
747 scr->dark_pixel = WMColorPixel(color);
748 WMReleaseColor(color);
751 XColor xcol;
752 /* frame boder color */
753 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
754 scr->frame_border_pixel = xcol.pixel;
757 /* create GCs with default values */
758 allocGCs(scr);
760 /* read defaults for this screen */
761 wReadDefaults(scr, WDWindowMaker->dictionary);
763 createInternalWindows(scr);
765 #ifdef KWM_HINTS
766 wKWMInitStuff(scr);
767 #endif
769 #ifdef GNOME_STUFF
770 wGNOMEInitStuff(scr);
771 #endif
773 #ifdef OLWM_HINTS
774 wOLWMInitStuff(scr);
775 #endif
777 /* create initial workspace */
778 wWorkspaceNew(scr);
780 /* create shared pixmaps */
781 createPixmaps(scr);
783 /* set icon sizes we can accept from clients */
784 icon_size[0].min_width = 8;
785 icon_size[0].min_height = 8;
786 icon_size[0].max_width = wPreferences.icon_size-4;
787 icon_size[0].max_height = wPreferences.icon_size-4;
788 icon_size[0].width_inc = 1;
789 icon_size[0].height_inc = 1;
790 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
792 /* setup WindowMaker protocols property in the root window*/
793 PropSetWMakerProtocols(scr->root_win);
795 /* setup our noticeboard */
796 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
797 XA_WINDOW, 32, PropModeReplace,
798 (unsigned char*)&scr->info_window, 1);
799 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
800 XA_WINDOW, 32, PropModeReplace,
801 (unsigned char*)&scr->info_window, 1);
804 #ifdef BALLOON_TEXT
805 /* initialize balloon text stuff */
806 wBalloonInitialize(scr);
807 #endif
809 wScreenUpdateUsableArea(scr);
811 #ifndef LITE
812 /* kluge to load menu configurations at startup */
813 OpenRootMenu(scr, -10000, -10000, False);
814 wMenuUnmap(scr->root_menu);
815 #endif
817 return scr;
821 void
822 wScreenUpdateUsableArea(WScreen *scr)
824 #ifdef GNOME_STUFF
825 WReservedArea *area;
826 #endif
828 scr->totalUsableArea = scr->usableArea;
831 if (scr->dock && (!scr->dock->lowered
832 || wPreferences.no_window_over_dock)) {
834 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
836 if (scr->dock->on_right_side) {
837 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
838 scr->scr_width - offset);
839 } else {
840 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
844 if (wPreferences.no_window_over_icons) {
845 if (wPreferences.icon_yard & IY_VERT) {
847 if (!(wPreferences.icon_yard & IY_RIGHT)) {
848 scr->totalUsableArea.x1 += wPreferences.icon_size;
849 } else {
850 scr->totalUsableArea.x2 -= wPreferences.icon_size;
852 } else {
854 if (wPreferences.icon_yard & IY_TOP) {
855 scr->totalUsableArea.y1 += wPreferences.icon_size;
856 } else {
857 scr->totalUsableArea.y2 -= wPreferences.icon_size;
862 #ifdef KWM_HINTS
864 WArea area;
866 if (wKWMGetUsableArea(scr, &area)) {
867 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
868 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
869 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
870 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
873 #endif
875 #ifdef GNOME_STUFF
876 area = scr->reservedAreas;
878 while (area) {
879 int th, bh;
880 int lw, rw;
881 int w, h;
883 w = area->area.x2 - area->area.x1;
884 h = area->area.y2 - area->area.y1;
886 th = area->area.y1;
887 bh = scr->scr_height - area->area.y2;
888 lw = area->area.x1;
889 rw = scr->scr_width - area->area.x2;
891 if (WMIN(th, bh) < WMIN(lw, rw)) {
892 /* horizontal */
893 if (th < bh) {
894 /* on top */
895 if (scr->totalUsableArea.y1 < area->area.y2)
896 scr->totalUsableArea.y1 = area->area.y2;
897 } else {
898 /* on bottom */
899 if (scr->totalUsableArea.y2 > area->area.y1)
900 scr->totalUsableArea.y2 = area->area.y1;
902 } else {
903 /* vertical */
904 if (lw < rw) {
905 /* on left */
906 if (scr->totalUsableArea.x1 < area->area.x2)
907 scr->totalUsableArea.x1 = area->area.x2;
908 } else {
909 /* on right */
910 if (scr->totalUsableArea.x2 > area->area.x1)
911 scr->totalUsableArea.x2 = area->area.x1;
915 area = area->next;
917 #endif /* GNOME_STUFF */
919 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
920 scr->totalUsableArea.x2 = scr->usableArea.x2;
921 scr->totalUsableArea.x1 = scr->usableArea.x1;
923 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
924 scr->totalUsableArea.y2 = scr->usableArea.y2;
925 scr->totalUsableArea.y1 = scr->usableArea.y1;
928 #ifdef not_used
929 #ifdef KWM_HINTS
931 int i;
933 for (i = 0; i < scr->workspace_count; i++) {
934 wKWMSetUsableAreaHint(scr, i);
937 #endif
938 #endif
942 void
943 wScreenRestoreState(WScreen *scr)
945 proplist_t state;
946 char *path;
948 make_keys();
950 if (wScreenCount == 1)
951 path = wdefaultspathfordomain("WMState");
952 else {
953 char buf[16];
954 sprintf(buf, "WMState.%i", scr->screen);
955 path = wdefaultspathfordomain(buf);
957 scr->session_state = PLGetProplistWithPath(path);
958 free(path);
959 if (!scr->session_state && wScreenCount>1) {
960 char buf[16];
961 sprintf(buf, "WMState.%i", scr->screen);
962 path = wdefaultspathfordomain(buf);
963 scr->session_state = PLGetProplistWithPath(path);
964 free(path);
967 if (!wPreferences.flags.noclip) {
968 state = PLGetDictionaryEntry(scr->session_state, dClip);
969 scr->clip_icon = wClipRestoreState(scr, state);
972 wWorkspaceRestoreState(scr);
974 if (!wPreferences.flags.nodock) {
975 state = PLGetDictionaryEntry(scr->session_state, dDock);
976 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
979 wScreenUpdateUsableArea(scr);
983 void
984 wScreenSaveState(WScreen *scr)
986 WWorkspaceState wstate;
987 WWindow *wwin;
988 char *str;
989 proplist_t path, old_state, foo;
990 CARD32 data[2];
993 make_keys();
996 * Save current workspace, so can go back to it upon restart.
998 wstate.workspace = scr->current_workspace;
1000 data[0] = wstate.flags;
1001 data[1] = wstate.workspace;
1003 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
1004 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1005 (unsigned char *) data, 2);
1007 /* save state of windows */
1008 wwin = scr->focused_window;
1009 while (wwin) {
1010 wWindowSaveState(wwin);
1011 wwin = wwin->prev;
1015 if (wPreferences.flags.noupdates)
1016 return;
1019 old_state = scr->session_state;
1020 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
1022 PLSetStringCmpHook(NULL);
1024 /* save dock state to file */
1025 if (!wPreferences.flags.nodock) {
1026 wDockSaveState(scr);
1027 } else {
1028 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
1029 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
1032 if (!wPreferences.flags.noclip) {
1033 wClipSaveState(scr);
1034 } else {
1035 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
1036 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
1040 wWorkspaceSaveState(scr, old_state);
1042 if (wPreferences.save_session_on_exit) {
1043 wSessionSaveState(scr);
1044 } else {
1045 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
1046 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
1048 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
1049 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
1053 /* clean up */
1054 PLSetStringCmpHook(StringCompareHook);
1056 wMenuSaveState(scr);
1058 if (wScreenCount == 1)
1059 str = wdefaultspathfordomain("WMState");
1060 else {
1061 char buf[16];
1062 sprintf(buf, "WMState.%i", scr->screen);
1063 str = wdefaultspathfordomain(buf);
1065 path = PLMakeString(str);
1066 free(str);
1067 PLSetFilename(scr->session_state, path);
1068 if (!PLSave(scr->session_state, YES)) {
1069 wwarning(_("could not save session state in %s"), PLGetString(path));
1071 PLRelease(path);
1072 PLRelease(old_state);
1078 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1080 int moved = 0;
1081 int tol_w, tol_h;
1083 if (width > 20)
1084 tol_w = width/2;
1085 else
1086 tol_w = 20;
1088 if (height > 20)
1089 tol_h = height/2;
1090 else
1091 tol_h = 20;
1093 if (*x+width < 10)
1094 *x = -tol_w, moved = 1;
1095 else if (*x >= scr->scr_width - 10)
1096 *x = scr->scr_width - tol_w - 1, moved = 1;
1098 if (*y < -height + 10)
1099 *y = -tol_h, moved = 1;
1100 else if (*y >= scr->scr_height - 10)
1101 *y = scr->scr_height - tol_h - 1, moved = 1;
1103 return moved;