- API change in WINGs for WMDraw*String().
[wmaker-crm.git] / src / screen.c
blobca3735cda3c94b456d94621e3c7b33d843b6e59e
1 /* screen.c - screen management
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 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 #include "geomview.h"
56 #ifdef KWM_HINTS
57 # include "kwm.h"
58 #endif
59 #ifdef GNOME_STUFF
60 # include "gnome.h"
61 #endif
62 #ifdef OLWM_HINTS
63 # include "openlook.h"
64 #endif
66 #include "xinerama.h"
68 #include <WINGs/WUtil.h>
70 #include "defaults.h"
73 #ifdef LITE
74 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
75 |SubstructureNotifyMask|PointerMotionMask \
76 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
77 #else
78 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
79 |SubstructureNotifyMask|PointerMotionMask \
80 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
81 |KeyPressMask|KeyReleaseMask)
82 #endif
84 /**** Global variables ****/
86 extern Cursor wCursor[WCUR_LAST];
87 extern WPreferences wPreferences;
88 extern Atom _XA_WINDOWMAKER_STATE;
89 extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
92 extern int wScreenCount;
94 #ifdef KEEP_XKB_LOCK_STATUS
95 extern int wXkbSupported;
96 #endif
98 extern WDDomain *WDWindowMaker;
101 /**** Local ****/
103 #define STIPPLE_WIDTH 2
104 #define STIPPLE_HEIGHT 2
105 static char STIPPLE_DATA[] = {0x02, 0x01};
107 static int CantManageScreen = 0;
109 static WMPropList *dApplications = NULL;
110 static WMPropList *dWorkspace;
111 static WMPropList *dDock;
112 static WMPropList *dClip;
115 static void
116 make_keys()
118 if (dApplications!=NULL)
119 return;
121 dApplications = WMCreatePLString("Applications");
122 dWorkspace = WMCreatePLString("Workspace");
123 dDock = WMCreatePLString("Dock");
124 dClip = WMCreatePLString("Clip");
129 *----------------------------------------------------------------------
130 * alreadyRunningError--
131 * X error handler used to catch errors when trying to do
132 * XSelectInput() on the root window. These errors probably mean that
133 * there already is some other window manager running.
135 * Returns:
136 * Nothing, unless something really evil happens...
138 * Side effects:
139 * CantManageScreen is set to 1;
140 *----------------------------------------------------------------------
142 static int
143 alreadyRunningError(Display *dpy, XErrorEvent *error)
145 CantManageScreen = 1;
146 return -1;
151 *----------------------------------------------------------------------
152 * allocButtonPixmaps--
153 * Allocate pixmaps used on window operation buttons (those in the
154 * titlebar). The pixmaps are linked to the program. If XPM is supported
155 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
157 * Returns:
158 * Nothing
160 * Side effects:
161 * Allocates shared pixmaps for the screen. These pixmaps should
162 * not be freed by anybody.
163 *----------------------------------------------------------------------
165 static void
166 allocButtonPixmaps(WScreen *scr)
168 WPixmap *pix;
170 /* create predefined pixmaps */
171 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
172 if (pix)
173 pix->shared = 1;
174 scr->b_pixmaps[WBUT_CLOSE] = pix;
176 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
177 if (pix)
178 pix->shared = 1;
179 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
181 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
182 if (pix)
183 pix->shared = 1;
184 scr->b_pixmaps[WBUT_ICONIFY] = pix;
185 #ifdef XKB_BUTTON_HINT
186 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
187 if (pix)
188 pix->shared = 1;
189 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
190 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
191 if (pix)
192 pix->shared = 1;
193 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
194 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
195 if (pix)
196 pix->shared = 1;
197 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
198 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
199 if (pix)
200 pix->shared = 1;
201 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
202 #endif
205 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
206 if (pix)
207 pix->shared = 1;
208 scr->b_pixmaps[WBUT_KILL] = pix;
212 static void
213 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
215 XSetForeground(dpy, gc, scr->black_pixel);
216 XDrawLine(dpy, d, gc, x, y, x+1, y);
217 XDrawPoint(dpy, d, gc, x, y+1);
218 XSetForeground(dpy, gc, scr->white_pixel);
219 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
220 XDrawPoint(dpy, d, gc, x+1, y+1);
224 static WPixmap*
225 make3Dots(WScreen *scr)
227 WPixmap *wpix;
228 GC gc2, gc;
229 XGCValues gcv;
230 Pixmap pix, mask;
232 gc = scr->copy_gc;
233 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
234 wPreferences.icon_size, scr->w_depth);
235 XSetForeground(dpy, gc, scr->black_pixel);
236 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
237 wPreferences.icon_size);
238 XSetForeground(dpy, gc, scr->white_pixel);
239 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
240 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
241 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
243 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
244 wPreferences.icon_size, 1);
245 gcv.foreground = 0;
246 gcv.graphics_exposures = False;
247 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
248 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
249 wPreferences.icon_size);
250 XSetForeground(dpy, gc2, 1);
251 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
252 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
253 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
255 XFreeGC(dpy, gc2);
257 wpix = wPixmapCreate(scr, pix, mask);
258 wpix->shared = 1;
260 return wpix;
264 static void
265 allocGCs(WScreen *scr)
267 XGCValues gcv;
268 XColor color;
269 unsigned long mtextcolor;
270 int gcm;
272 scr->stipple_bitmap =
273 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
274 STIPPLE_HEIGHT);
276 gcv.stipple = scr->stipple_bitmap;
277 gcv.foreground = scr->white_pixel;
278 gcv.fill_style = FillStippled;
279 gcv.graphics_exposures = False;
280 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
281 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
284 /* selected icon border GCs */
285 gcv.function = GXcopy;
286 gcv.foreground = scr->white_pixel;
287 gcv.background = scr->black_pixel;
288 gcv.line_width = 1;
289 gcv.line_style = LineDoubleDash;
290 gcv.fill_style = FillSolid;
291 gcv.dash_offset = 0;
292 gcv.dashes = 4;
293 gcv.graphics_exposures = False;
295 gcm = GCFunction | GCGraphicsExposures;
296 gcm |= GCForeground | GCBackground;
297 gcm |= GCLineWidth | GCLineStyle;
298 gcm |= GCFillStyle;
299 gcm |= GCDashOffset | GCDashList;
301 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
303 gcm = GCForeground|GCGraphicsExposures;
305 scr->menu_title_pixel[0] = scr->white_pixel;
306 gcv.foreground = scr->white_pixel;
307 gcv.graphics_exposures = False;
308 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
310 scr->mtext_pixel = scr->black_pixel;
311 mtextcolor = gcv.foreground = scr->black_pixel;
312 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
314 /* selected menu entry GC */
315 gcm = GCForeground|GCBackground|GCGraphicsExposures;
316 gcv.foreground = scr->white_pixel;
317 gcv.background = scr->white_pixel;
318 gcv.graphics_exposures = False;
319 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
321 /* disabled menu entry GC */
322 scr->dtext_pixel = scr->black_pixel;
323 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
324 gcv.stipple = scr->stipple_bitmap;
325 gcv.graphics_exposures = False;
326 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
328 /* frame GC */
329 wGetColor(scr, DEF_FRAME_COLOR, &color);
330 gcv.function = GXxor;
331 /* this will raise the probability of the XORed color being different
332 * of the original color in PseudoColor when not all color cells are
333 * initialized */
334 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
335 gcv.plane_mask = (1<<(scr->depth-1))|1;
336 else
337 gcv.plane_mask = AllPlanes;
338 gcv.foreground = color.pixel;
339 if (gcv.foreground == 0)
340 gcv.foreground = 1;
341 gcv.line_width = DEF_FRAME_THICKNESS;
342 gcv.subwindow_mode = IncludeInferiors;
343 gcv.graphics_exposures = False;
344 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
345 |GCFunction|GCSubwindowMode|GCLineWidth
346 |GCPlaneMask, &gcv);
348 /* line GC */
349 gcv.foreground = color.pixel;
351 if (gcv.foreground == 0)
352 /* XOR:ing with a zero is not going to be of much use, so
353 in that case, we somewhat arbitrarily xor with 17 instead. */
354 gcv.foreground = 17;
356 gcv.function = GXxor;
357 gcv.subwindow_mode = IncludeInferiors;
358 gcv.line_width = 1;
359 gcv.cap_style = CapRound;
360 gcv.graphics_exposures = False;
361 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
362 |GCGraphicsExposures;
363 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
365 scr->line_pixel = gcv.foreground;
367 /* copy GC */
368 gcv.foreground = scr->white_pixel;
369 gcv.background = scr->black_pixel;
370 gcv.graphics_exposures = False;
371 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
372 |GCGraphicsExposures, &gcv);
374 /* window title text GC */
375 gcv.graphics_exposures = False;
376 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
378 /* clip title GC */
379 scr->clip_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
381 /* move/size display GC */
382 gcv.graphics_exposures = False;
383 gcm = GCGraphicsExposures;
384 scr->info_text_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
386 /* misc drawing GC */
387 gcv.graphics_exposures = False;
388 gcm = GCGraphicsExposures;
389 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
391 assert (scr->stipple_bitmap!=None);
394 /* mono GC */
395 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
400 static void
401 createPixmaps(WScreen *scr)
403 WPixmap *pix;
404 RImage *image;
406 /* load pixmaps */
407 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
408 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
409 MENU_RADIO_INDICATOR_XBM_SIZE,
410 MENU_RADIO_INDICATOR_XBM_SIZE,
411 scr->black_pixel, scr->white_pixel);
412 if (pix!=NULL)
413 pix->shared = 1;
414 scr->menu_radio_indicator = pix;
417 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
418 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
419 MENU_CHECK_INDICATOR_XBM_SIZE,
420 MENU_CHECK_INDICATOR_XBM_SIZE,
421 scr->black_pixel, scr->white_pixel);
422 if (pix!=NULL)
423 pix->shared = 1;
424 scr->menu_check_indicator = pix;
426 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
427 (char*)MENU_MINI_INDICATOR_XBM_DATA,
428 MENU_MINI_INDICATOR_XBM_SIZE,
429 MENU_MINI_INDICATOR_XBM_SIZE,
430 scr->black_pixel, scr->white_pixel);
431 if (pix!=NULL)
432 pix->shared = 1;
433 scr->menu_mini_indicator = pix;
435 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
436 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
437 MENU_HIDE_INDICATOR_XBM_SIZE,
438 MENU_HIDE_INDICATOR_XBM_SIZE,
439 scr->black_pixel, scr->white_pixel);
440 if (pix!=NULL)
441 pix->shared = 1;
442 scr->menu_hide_indicator = pix;
444 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
445 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
446 MENU_SHADE_INDICATOR_XBM_SIZE,
447 MENU_SHADE_INDICATOR_XBM_SIZE,
448 scr->black_pixel, scr->white_pixel);
449 if (pix!=NULL)
450 pix->shared = 1;
451 scr->menu_shade_indicator = pix;
454 image = wDefaultGetImage(scr, "Logo", "WMPanel");
456 if (!image) {
457 wwarning(_("could not load logo image for panels: %s"),
458 RMessageForError(RErrorCode));
459 } else {
460 WMSetApplicationIconImage(scr->wmscreen, image);
461 RReleaseImage(image);
464 scr->dock_dots = make3Dots(scr);
466 /* titlebar button pixmaps */
467 allocButtonPixmaps(scr);
472 *----------------------------------------------------------------------
473 * createInternalWindows--
474 * Creates some windows used internally by the program. One to
475 * receive input focus when no other window can get it and another
476 * to display window geometry information during window resize/move.
478 * Returns:
479 * Nothing
481 * Side effects:
482 * Windows are created and some colors are allocated for the
483 * window background.
484 *----------------------------------------------------------------------
486 static void
487 createInternalWindows(WScreen *scr)
489 int vmask;
490 XSetWindowAttributes attribs;
492 /* InputOnly window to get the focus when no other window can get it */
493 vmask = CWEventMask|CWOverrideRedirect;
494 attribs.event_mask = KeyPressMask|FocusChangeMask;
495 attribs.override_redirect = True;
496 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
497 InputOnly,CopyFromParent, vmask, &attribs);
498 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
499 XMapWindow(dpy, scr->no_focus_win);
501 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
503 /* shadow window for dock buttons */
504 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
505 attribs.border_pixel = scr->black_pixel;
506 attribs.save_under = True;
507 attribs.override_redirect = True;
508 attribs.background_pixmap = None;
509 attribs.background_pixel = scr->white_pixel;
510 attribs.cursor = wCursor[WCUR_DEFAULT];
511 vmask |= CWColormap;
512 attribs.colormap = scr->w_colormap;
513 scr->dock_shadow =
514 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
515 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
516 scr->w_visual, vmask, &attribs);
518 /* workspace name balloon for clip */
519 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
520 |CWBorderPixel;
521 attribs.save_under = True;
522 attribs.override_redirect = True;
523 attribs.colormap = scr->w_colormap;
524 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
525 attribs.border_pixel = 0; /* do not care */
526 scr->clip_balloon =
527 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
528 CopyFromParent, scr->w_visual, vmask, &attribs);
531 /* workspace name */
532 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
533 |CWBorderPixel;
534 attribs.save_under = True;
535 attribs.override_redirect = True;
536 attribs.colormap = scr->w_colormap;
537 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
538 attribs.border_pixel = 0; /* do not care */
539 scr->workspace_name =
540 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
541 CopyFromParent, scr->w_visual, vmask, &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 snprintf(buffer, sizeof(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 scr->stacking_list = WMCreateTreeBag();
648 /* initialize globals */
649 scr->screen = screen_number;
650 scr->root_win = RootWindow(dpy, screen_number);
651 scr->depth = DefaultDepth(dpy, screen_number);
652 scr->colormap = DefaultColormap(dpy, screen_number);
654 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
655 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
657 scr->usableArea.x2 = scr->scr_width;
658 scr->usableArea.y2 = scr->scr_height;
659 scr->totalUsableArea.x2 = scr->scr_width;
660 scr->totalUsableArea.y2 = scr->scr_height;
662 scr->fakeGroupLeaders = WMCreateArray(16);
664 #if 0
665 if (!aquireManagerSelection(scr)) {
666 wfree(scr);
668 return NULL;
670 #endif
671 CantManageScreen = 0;
672 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
674 event_mask = EVENT_MASK;
676 if (wPreferences.disable_root_mouse) {
677 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
680 XSelectInput(dpy, scr->root_win, event_mask);
682 #ifdef KEEP_XKB_LOCK_STATUS
683 /* Only GroupLock doesn't work correctly in my system since right-alt
684 * can change mode while holding it too - ]d
686 if (wXkbSupported) {
687 XkbSelectEvents(dpy,XkbUseCoreKbd,
688 XkbStateNotifyMask,
689 XkbStateNotifyMask);
691 #endif /* KEEP_XKB_LOCK_STATUS */
693 XSync(dpy, False);
694 XSetErrorHandler(oldHandler);
696 if (CantManageScreen) {
697 wfree(scr);
698 return NULL;
701 #ifdef XINERAMA
702 wInitXinerama(scr);
703 #endif
706 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_ROOT]);
708 /* screen descriptor for raster graphic library */
709 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
710 rattr.render_mode = wPreferences.no_dithering
711 ? RBestMatchRendering
712 : RDitheredRendering;
714 /* if the std colormap stuff works ok, this will be ignored */
715 rattr.colors_per_channel = wPreferences.cmap_size;
716 if (rattr.colors_per_channel<2)
717 rattr.colors_per_channel = 2;
720 /* will only be accounted for in PseudoColor */
721 if (wPreferences.flags.create_stdcmap) {
722 rattr.standard_colormap_mode = RCreateStdColormap;
723 } else {
724 rattr.standard_colormap_mode = RUseStdColormap;
727 if (wVisualID>=0) {
728 rattr.flags |= RC_VisualID;
729 rattr.visualid = wVisualID;
732 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
734 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
735 wwarning(RMessageForError(RErrorCode));
737 rattr.flags &= ~RC_StandardColormap;
738 rattr.standard_colormap_mode = RUseStdColormap;
740 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
743 if (!scr->rcontext) {
744 wwarning(_("could not initialize graphics library context: %s"),
745 RMessageForError(RErrorCode));
746 wAbort(False);
747 } else {
748 char **formats;
749 int i = 0;
751 formats = RSupportedFileFormats();
752 if (formats) {
753 for (i=0; formats[i]!=NULL; i++) {
754 if (strcmp(formats[i], "TIFF")==0) {
755 scr->flags.supports_tiff = 1;
756 break;
762 scr->w_win = scr->rcontext->drawable;
763 scr->w_visual = scr->rcontext->visual;
764 scr->w_depth = scr->rcontext->depth;
765 scr->w_colormap = scr->rcontext->cmap;
767 scr->black_pixel = scr->rcontext->black;
768 scr->white_pixel = scr->rcontext->white;
770 /* create screen descriptor for WINGs */
771 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
772 scr->rcontext);
774 if (!scr->wmscreen) {
775 wfatal(_("could not do initialization of WINGs widget set"));
777 return NULL;
780 color = WMGrayColor(scr->wmscreen);
781 scr->light_pixel = WMColorPixel(color);
782 WMReleaseColor(color);
784 color = WMDarkGrayColor(scr->wmscreen);
785 scr->dark_pixel = WMColorPixel(color);
786 WMReleaseColor(color);
789 XColor xcol;
790 /* frame boder color */
791 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
792 scr->frame_border_pixel = xcol.pixel;
795 /* create GCs with default values */
796 allocGCs(scr);
799 /* for our window manager info notice board. Need to
800 * create before reading the defaults, because it will be used there.
802 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10,
803 0, 0, 0);
805 /* read defaults for this screen */
806 wReadDefaults(scr, WDWindowMaker->dictionary);
808 createInternalWindows(scr);
810 #ifdef KWM_HINTS
811 wKWMInitStuff(scr);
812 #endif
814 #ifdef GNOME_STUFF
815 wGNOMEInitStuff(scr);
816 #endif
818 #ifdef OLWM_HINTS
819 wOLWMInitStuff(scr);
820 #endif
822 /* create initial workspace */
823 wWorkspaceNew(scr);
825 /* create shared pixmaps */
826 createPixmaps(scr);
828 /* set icon sizes we can accept from clients */
829 icon_size[0].min_width = 8;
830 icon_size[0].min_height = 8;
831 icon_size[0].max_width = wPreferences.icon_size-4;
832 icon_size[0].max_height = wPreferences.icon_size-4;
833 icon_size[0].width_inc = 1;
834 icon_size[0].height_inc = 1;
835 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
837 /* setup WindowMaker protocols property in the root window*/
838 PropSetWMakerProtocols(scr->root_win);
840 /* setup our noticeboard */
841 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
842 XA_WINDOW, 32, PropModeReplace,
843 (unsigned char*)&scr->info_window, 1);
844 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
845 XA_WINDOW, 32, PropModeReplace,
846 (unsigned char*)&scr->info_window, 1);
849 #ifdef BALLOON_TEXT
850 /* initialize balloon text stuff */
851 wBalloonInitialize(scr);
852 #endif
854 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
857 scr->gview = WCreateGeometryView(scr->wmscreen);
858 WMRealizeWidget(scr->gview);
860 wScreenUpdateUsableArea(scr);
862 return scr;
867 static WArea subtractRectangle(WArea area, WArea rect)
869 WArea result = area;
875 void
876 wScreenUpdateUsableArea(WScreen *scr)
878 WReservedArea *area;
880 scr->totalUsableArea = scr->usableArea;
883 if (scr->dock && (!scr->dock->lowered
884 || wPreferences.no_window_over_dock)) {
886 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
888 if (scr->dock->on_right_side) {
889 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
890 scr->scr_width - offset);
891 } else {
892 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
896 if (wPreferences.no_window_over_icons) {
897 if (wPreferences.icon_yard & IY_VERT) {
899 if (!(wPreferences.icon_yard & IY_RIGHT)) {
900 scr->totalUsableArea.x1 += wPreferences.icon_size;
901 } else {
902 scr->totalUsableArea.x2 -= wPreferences.icon_size;
904 } else {
906 if (wPreferences.icon_yard & IY_TOP) {
907 scr->totalUsableArea.y1 += wPreferences.icon_size;
908 } else {
909 scr->totalUsableArea.y2 -= wPreferences.icon_size;
914 #ifdef KWM_HINTS
916 WArea area;
918 if (wKWMGetUsableArea(scr, &area)) {
919 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
920 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
921 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
922 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
925 #endif
927 #ifdef GNOME_STUFF
928 area = scr->reservedAreas;
930 while (area) {
931 int th, bh;
932 int lw, rw;
933 int w, h;
935 w = area->area.x2 - area->area.x1;
936 h = area->area.y2 - area->area.y1;
938 th = area->area.y1;
939 bh = scr->scr_height - area->area.y2;
940 lw = area->area.x1;
941 rw = scr->scr_width - area->area.x2;
943 if (WMIN(th, bh) <= WMIN(lw, rw)) {
944 /* horizontal */
945 if (th < bh) {
946 /* on top */
947 if (scr->totalUsableArea.y1 < area->area.y2)
948 scr->totalUsableArea.y1 = area->area.y2;
949 } else {
950 /* on bottom */
951 if (scr->totalUsableArea.y2 > area->area.y1)
952 scr->totalUsableArea.y2 = area->area.y1;
954 } else {
955 /* vertical */
956 if (lw < rw) {
957 /* on left */
958 if (scr->totalUsableArea.x1 < area->area.x2)
959 scr->totalUsableArea.x1 = area->area.x2;
960 } else {
961 /* on right */
962 if (scr->totalUsableArea.x2 > area->area.x1)
963 scr->totalUsableArea.x2 = area->area.x1;
967 area = area->next;
969 #endif /* GNOME_STUFF */
971 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
972 scr->totalUsableArea.x2 = scr->usableArea.x2;
973 scr->totalUsableArea.x1 = scr->usableArea.x1;
975 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
976 scr->totalUsableArea.y2 = scr->usableArea.y2;
977 scr->totalUsableArea.y1 = scr->usableArea.y1;
980 #ifdef not_used
981 #ifdef KWM_HINTS
983 int i;
985 for (i = 0; i < scr->workspace_count; i++) {
986 wKWMSetUsableAreaHint(scr, i);
989 #endif
990 #endif
993 unsigned size = wPreferences.workspace_border_size;
994 unsigned position = wPreferences.workspace_border_position;
996 if (size>0 && position!=WB_NONE) {
997 if (position & WB_LEFTRIGHT) {
998 scr->totalUsableArea.x1 += size;
999 scr->totalUsableArea.x2 -= size;
1001 if (position & WB_TOPBOTTOM) {
1002 scr->totalUsableArea.y1 += size;
1003 scr->totalUsableArea.y2 -= size;
1011 void
1012 wScreenRestoreState(WScreen *scr)
1014 WMPropList *state;
1015 char *path;
1018 #ifndef LITE
1019 OpenRootMenu(scr, -10000, -10000, False);
1020 wMenuUnmap(scr->root_menu);
1021 #endif
1023 make_keys();
1025 if (wScreenCount == 1) {
1026 path = wdefaultspathfordomain("WMState");
1027 } else {
1028 char buf[16];
1029 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
1030 path = wdefaultspathfordomain(buf);
1032 scr->session_state = WMReadPropListFromFile(path);
1033 wfree(path);
1034 if (!scr->session_state && wScreenCount>1) {
1035 path = wdefaultspathfordomain("WMState");
1036 scr->session_state = WMReadPropListFromFile(path);
1037 wfree(path);
1040 if (!wPreferences.flags.noclip && scr->session_state) {
1041 state = WMGetFromPLDictionary(scr->session_state, dClip);
1042 scr->clip_icon = wClipRestoreState(scr, state);
1045 wWorkspaceRestoreState(scr);
1047 #ifdef VIRTUAL_DESKTOP
1049 * * create inputonly windows at the border of screen
1050 * */
1051 wWorkspaceManageEdge(scr);
1052 #endif
1054 if (!wPreferences.flags.nodock && scr->session_state) {
1055 state = WMGetFromPLDictionary(scr->session_state, dDock);
1056 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
1059 wScreenUpdateUsableArea(scr);
1063 void
1064 wScreenSaveState(WScreen *scr)
1066 WWindow *wwin;
1067 char *str;
1068 WMPropList *old_state, *foo;
1069 CARD32 data[2];
1072 make_keys();
1074 /* Save current workspace, so can go back to it upon restart. */
1075 data[0] = scr->current_workspace;
1076 data[1] = WFLAGS_NONE;
1078 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
1079 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1080 (unsigned char *) data, 2);
1082 /* save state of windows */
1083 wwin = scr->focused_window;
1084 while (wwin) {
1085 wWindowSaveState(wwin);
1086 wwin = wwin->prev;
1090 if (wPreferences.flags.noupdates)
1091 return;
1094 old_state = scr->session_state;
1095 scr->session_state = WMCreatePLDictionary(NULL, NULL, NULL);
1097 WMPLSetCaseSensitive(True);
1099 /* save dock state to file */
1100 if (!wPreferences.flags.nodock) {
1101 wDockSaveState(scr, old_state);
1102 } else {
1103 if ((foo = WMGetFromPLDictionary(old_state, dDock))!=NULL) {
1104 WMPutInPLDictionary(scr->session_state, dDock, foo);
1107 if (!wPreferences.flags.noclip) {
1108 wClipSaveState(scr);
1109 } else {
1110 if ((foo = WMGetFromPLDictionary(old_state, dClip))!=NULL) {
1111 WMPutInPLDictionary(scr->session_state, dClip, foo);
1115 wWorkspaceSaveState(scr, old_state);
1117 if (wPreferences.save_session_on_exit) {
1118 wSessionSaveState(scr);
1119 } else {
1120 if ((foo = WMGetFromPLDictionary(old_state, dApplications))!=NULL) {
1121 WMPutInPLDictionary(scr->session_state, dApplications, foo);
1123 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace))!=NULL) {
1124 WMPutInPLDictionary(scr->session_state, dWorkspace, foo);
1128 /* clean up */
1129 WMPLSetCaseSensitive(False);
1131 wMenuSaveState(scr);
1133 if (wScreenCount == 1)
1134 str = wdefaultspathfordomain("WMState");
1135 else {
1136 char buf[16];
1137 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
1138 str = wdefaultspathfordomain(buf);
1140 if (!WMWritePropListToFile(scr->session_state, str, True)) {
1141 wsyserror(_("could not save session state in %s"), str);
1143 wfree(str);
1144 WMReleasePropList(old_state);
1150 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1152 int moved = 0;
1153 int tol_w, tol_h;
1155 if (width > 20)
1156 tol_w = width/2;
1157 else
1158 tol_w = 20;
1160 if (height > 20)
1161 tol_h = height/2;
1162 else
1163 tol_h = 20;
1165 if (*x+width < 10)
1166 *x = -tol_w, moved = 1;
1167 else if (*x >= scr->scr_width - 10)
1168 *x = scr->scr_width - tol_w - 1, moved = 1;
1170 if (*y < -height + 10)
1171 *y = -tol_h, moved = 1;
1172 else if (*y >= scr->scr_height - 10)
1173 *y = scr->scr_height - tol_h - 1, moved = 1;
1175 return moved;