- added standard colormap support
[wmaker-crm.git] / src / screen.c
blob334f618deaa0fc35eb1490b9ceea01e911349016
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 #ifdef KEEP_XKB_LOCK_STATUS
92 extern int wXkbSupported;
93 #endif
95 extern WDDomain *WDWindowMaker;
98 /**** Local ****/
100 #define STIPPLE_WIDTH 2
101 #define STIPPLE_HEIGHT 2
102 static char STIPPLE_DATA[] = {0x02, 0x01};
104 static int CantManageScreen = 0;
106 static proplist_t dApplications = NULL;
107 static proplist_t dWorkspace;
108 static proplist_t dDock;
109 static proplist_t dClip;
112 static void
113 make_keys()
115 if (dApplications!=NULL)
116 return;
118 dApplications = PLMakeString("Applications");
119 dWorkspace = PLMakeString("Workspace");
120 dDock = PLMakeString("Dock");
121 dClip = PLMakeString("Clip");
126 *----------------------------------------------------------------------
127 * alreadyRunningError--
128 * X error handler used to catch errors when trying to do
129 * XSelectInput() on the root window. These errors probably mean that
130 * there already is some other window manager running.
132 * Returns:
133 * Nothing, unless something really evil happens...
135 * Side effects:
136 * CantManageScreen is set to 1;
137 *----------------------------------------------------------------------
139 static int
140 alreadyRunningError(Display *dpy, XErrorEvent *error)
142 CantManageScreen = 1;
143 return -1;
148 *----------------------------------------------------------------------
149 * allocButtonPixmaps--
150 * Allocate pixmaps used on window operation buttons (those in the
151 * titlebar). The pixmaps are linked to the program. If XPM is supported
152 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
154 * Returns:
155 * Nothing
157 * Side effects:
158 * Allocates shared pixmaps for the screen. These pixmaps should
159 * not be freed by anybody.
160 *----------------------------------------------------------------------
162 static void
163 allocButtonPixmaps(WScreen *scr)
165 WPixmap *pix;
167 /* create predefined pixmaps */
168 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
169 if (pix)
170 pix->shared = 1;
171 scr->b_pixmaps[WBUT_CLOSE] = pix;
173 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
174 if (pix)
175 pix->shared = 1;
176 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
178 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
179 if (pix)
180 pix->shared = 1;
181 scr->b_pixmaps[WBUT_ICONIFY] = pix;
182 #ifdef XKB_BUTTON_HINT
183 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
184 if (pix)
185 pix->shared = 1;
186 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
187 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
188 if (pix)
189 pix->shared = 1;
190 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
191 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
192 if (pix)
193 pix->shared = 1;
194 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
195 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
196 if (pix)
197 pix->shared = 1;
198 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
199 #endif
202 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
203 if (pix)
204 pix->shared = 1;
205 scr->b_pixmaps[WBUT_KILL] = pix;
209 static void
210 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
212 XSetForeground(dpy, gc, scr->black_pixel);
213 XDrawLine(dpy, d, gc, x, y, x+1, y);
214 XDrawPoint(dpy, d, gc, x, y+1);
215 XSetForeground(dpy, gc, scr->white_pixel);
216 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
217 XDrawPoint(dpy, d, gc, x+1, y+1);
221 static WPixmap*
222 make3Dots(WScreen *scr)
224 WPixmap *wpix;
225 GC gc2, gc;
226 XGCValues gcv;
227 Pixmap pix, mask;
229 gc = scr->copy_gc;
230 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
231 wPreferences.icon_size, scr->w_depth);
232 XSetForeground(dpy, gc, scr->black_pixel);
233 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
234 wPreferences.icon_size);
235 XSetForeground(dpy, gc, scr->white_pixel);
236 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
237 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
238 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
240 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
241 wPreferences.icon_size, 1);
242 gcv.foreground = 0;
243 gcv.graphics_exposures = False;
244 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
245 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
246 wPreferences.icon_size);
247 XSetForeground(dpy, gc2, 1);
248 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
249 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
250 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
252 XFreeGC(dpy, gc2);
254 wpix = wPixmapCreate(scr, pix, mask);
255 wpix->shared = 1;
257 return wpix;
261 static void
262 allocGCs(WScreen *scr)
264 XGCValues gcv;
265 XColor color;
266 unsigned long mtextcolor;
267 int gcm;
269 scr->stipple_bitmap =
270 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
271 STIPPLE_HEIGHT);
273 gcv.stipple = scr->stipple_bitmap;
274 gcv.foreground = scr->white_pixel;
275 gcv.fill_style = FillStippled;
276 gcv.graphics_exposures = False;
277 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
278 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
281 /* selected icon border GCs */
282 gcv.function = GXcopy;
283 gcv.foreground = scr->white_pixel;
284 gcv.background = scr->black_pixel;
285 gcv.line_width = 1;
286 gcv.line_style = LineDoubleDash;
287 gcv.fill_style = FillSolid;
288 gcv.dash_offset = 0;
289 gcv.dashes = 4;
290 gcv.graphics_exposures = False;
292 gcm = GCFunction | GCGraphicsExposures;
293 gcm |= GCForeground | GCBackground;
294 gcm |= GCLineWidth | GCLineStyle;
295 gcm |= GCFillStyle;
296 gcm |= GCDashOffset | GCDashList;
298 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
300 gcm = GCForeground|GCGraphicsExposures;
302 scr->menu_title_pixel[0] = scr->white_pixel;
303 gcv.foreground = scr->white_pixel;
304 gcv.graphics_exposures = False;
305 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
307 scr->mtext_pixel = scr->black_pixel;
308 mtextcolor = gcv.foreground = scr->black_pixel;
309 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
311 /* selected menu entry GC */
312 gcm = GCForeground|GCBackground|GCGraphicsExposures;
313 gcv.foreground = scr->white_pixel;
314 gcv.background = scr->white_pixel;
315 gcv.graphics_exposures = False;
316 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
318 /* disabled menu entry GC */
319 scr->dtext_pixel = scr->black_pixel;
320 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
321 gcv.stipple = scr->stipple_bitmap;
322 gcv.graphics_exposures = False;
323 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
325 /* frame GC */
326 wGetColor(scr, DEF_FRAME_COLOR, &color);
327 gcv.function = GXxor;
328 /* this will raise the probability of the XORed color being different
329 * of the original color in PseudoColor when not all color cells are
330 * initialized */
331 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
332 gcv.plane_mask = (1<<(scr->depth-1))|1;
333 else
334 gcv.plane_mask = AllPlanes;
335 gcv.foreground = color.pixel;
336 if (gcv.foreground == 0)
337 gcv.foreground = 1;
338 gcv.line_width = DEF_FRAME_THICKNESS;
339 gcv.subwindow_mode = IncludeInferiors;
340 gcv.graphics_exposures = False;
341 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
342 |GCFunction|GCSubwindowMode|GCLineWidth
343 |GCPlaneMask, &gcv);
345 /* line GC */
346 gcv.foreground = color.pixel;
348 if (gcv.foreground == 0)
349 /* XOR:ing with a zero is not going to be of much use, so
350 in that case, we somewhat arbitrarily xor with 17 instead. */
351 gcv.foreground = 17;
353 gcv.function = GXxor;
354 gcv.subwindow_mode = IncludeInferiors;
355 gcv.line_width = 1;
356 gcv.cap_style = CapRound;
357 gcv.graphics_exposures = False;
358 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
359 |GCGraphicsExposures;
360 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
362 scr->line_pixel = gcv.foreground;
364 /* copy GC */
365 gcv.foreground = scr->white_pixel;
366 gcv.background = scr->black_pixel;
367 gcv.graphics_exposures = False;
368 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
369 |GCGraphicsExposures, &gcv);
371 /* window title text GC */
372 gcv.graphics_exposures = False;
373 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
375 /* icon title GC */
376 scr->icon_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 WMPixmap *wmpix;
405 RImage *image;
406 Pixmap p, m;
408 /* load pixmaps */
409 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
410 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
411 MENU_RADIO_INDICATOR_XBM_SIZE,
412 MENU_RADIO_INDICATOR_XBM_SIZE,
413 scr->black_pixel, scr->white_pixel);
414 if (pix!=NULL)
415 pix->shared = 1;
416 scr->menu_radio_indicator = pix;
419 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
420 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
421 MENU_CHECK_INDICATOR_XBM_SIZE,
422 MENU_CHECK_INDICATOR_XBM_SIZE,
423 scr->black_pixel, scr->white_pixel);
424 if (pix!=NULL)
425 pix->shared = 1;
426 scr->menu_check_indicator = pix;
428 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
429 (char*)MENU_MINI_INDICATOR_XBM_DATA,
430 MENU_MINI_INDICATOR_XBM_SIZE,
431 MENU_MINI_INDICATOR_XBM_SIZE,
432 scr->black_pixel, scr->white_pixel);
433 if (pix!=NULL)
434 pix->shared = 1;
435 scr->menu_mini_indicator = pix;
437 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
438 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
439 MENU_HIDE_INDICATOR_XBM_SIZE,
440 MENU_HIDE_INDICATOR_XBM_SIZE,
441 scr->black_pixel, scr->white_pixel);
442 if (pix!=NULL)
443 pix->shared = 1;
444 scr->menu_hide_indicator = pix;
446 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
447 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
448 MENU_SHADE_INDICATOR_XBM_SIZE,
449 MENU_SHADE_INDICATOR_XBM_SIZE,
450 scr->black_pixel, scr->white_pixel);
451 if (pix!=NULL)
452 pix->shared = 1;
453 scr->menu_shade_indicator = pix;
456 image = wDefaultGetImage(scr, "Logo", "WMPanel");
458 if (!image) {
459 wwarning(_("could not load logo image for panels: %s"),
460 RMessageForError(RErrorCode));
461 } else {
462 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
463 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
464 } else {
465 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
466 image->width, image->height,
467 scr->depth);
468 WMSetApplicationIconImage(scr->wmscreen, wmpix);
469 WMReleasePixmap(wmpix);
471 RDestroyImage(image);
474 scr->dock_dots = make3Dots(scr);
476 /* titlebar button pixmaps */
477 allocButtonPixmaps(scr);
482 *----------------------------------------------------------------------
483 * createInternalWindows--
484 * Creates some windows used internally by the program. One to
485 * receive input focus when no other window can get it and another
486 * to display window geometry information during window resize/move.
488 * Returns:
489 * Nothing
491 * Side effects:
492 * Windows are created and some colors are allocated for the
493 * window background.
494 *----------------------------------------------------------------------
496 static void
497 createInternalWindows(WScreen *scr)
499 int vmask;
500 XSetWindowAttributes attribs;
502 /* window for displaying geometry information during resizes and moves */
503 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
504 attribs.border_pixel = scr->black_pixel;
505 attribs.save_under = True;
506 attribs.override_redirect = True;
507 attribs.cursor = wCursor[WCUR_DEFAULT];
508 attribs.background_pixmap = None;
509 if (scr->widget_texture)
510 attribs.background_pixel = scr->widget_texture->normal.pixel;
511 else
512 attribs.background_pixel = scr->light_pixel;
513 vmask |= CWColormap;
514 attribs.colormap = scr->w_colormap;
516 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
517 &scr->geometry_display_height);
518 scr->geometry_display =
519 XCreateWindow(dpy, scr->root_win, 1, 1,
520 scr->geometry_display_width,
521 scr->geometry_display_height,
522 1, scr->w_depth, CopyFromParent, scr->w_visual,
523 vmask, &attribs);
525 /* InputOnly window to get the focus when no other window can get it */
526 vmask = CWEventMask|CWOverrideRedirect;
527 attribs.event_mask = KeyPressMask|FocusChangeMask;
528 attribs.override_redirect = True;
529 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
530 InputOnly,CopyFromParent, vmask, &attribs);
531 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
532 XMapWindow(dpy, scr->no_focus_win);
534 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
536 /* shadow window for dock buttons */
537 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
538 attribs.border_pixel = scr->black_pixel;
539 attribs.save_under = True;
540 attribs.override_redirect = True;
541 attribs.background_pixmap = None;
542 attribs.background_pixel = scr->white_pixel;
543 vmask |= CWColormap;
544 attribs.colormap = scr->w_colormap;
545 scr->dock_shadow =
546 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
547 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
548 scr->w_visual, vmask, &attribs);
550 /* workspace name balloon for clip */
551 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
552 |CWBorderPixel;
553 attribs.save_under = True;
554 attribs.override_redirect = True;
555 attribs.colormap = scr->w_colormap;
556 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
557 attribs.border_pixel = 0; /* do not care */
558 scr->clip_balloon =
559 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
560 CopyFromParent, scr->w_visual, vmask, &attribs);
563 /* workspace name */
564 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
565 |CWBorderPixel;
566 attribs.save_under = True;
567 attribs.override_redirect = True;
568 attribs.colormap = scr->w_colormap;
569 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
570 attribs.border_pixel = 0; /* do not care */
571 scr->workspace_name =
572 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
573 CopyFromParent, scr->w_visual, vmask, &attribs);
576 /* for our window manager info notice board */
577 scr->info_window =
578 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, CopyFromParent,
579 CopyFromParent, CopyFromParent, CWOverrideRedirect,
580 &attribs);
583 * If the window is clicked without having ButtonPress selected, the
584 * resulting event will have event.xbutton.window == root.
586 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
590 #if 0
591 static Bool
592 aquireManagerSelection(WScreen *scr)
594 char buffer[32];
595 XEvent ev;
596 Time timestamp;
598 sprintf(buffer, "WM_S%i", scr->screen);
599 scr->managerAtom = XInternAtom(dpy, buffer, False);
601 /* for race-conditions... */
602 XGrabServer(dpy);
604 /* if there is another manager running, don't try to replace it
605 * (for now, at least) */
606 if (XGetSelectionOwner(dpy, scr->managerAtom) != None) {
607 XUngrabServer(dpy);
608 return False;
611 /* become the manager for this screen */
613 scr->managerWindow = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 1, 1,
614 0, 0, 0);
616 XSelectInput(dpy, scr->managerWindow, PropertyChangeMask);
617 /* get a timestamp */
618 XChangeProperty(dpy, scr->managerWindow, scr->managerAtom,
619 XA_INTEGER, 32, PropModeAppend, NULL, 0);
620 while (1) {
621 XWindowEvent(dpy, scr->managerWindow, &ev);
622 if (ev.type == PropertyNotify) {
623 timestamp = ev.xproperty.time;
624 break;
627 XSelectInput(dpy, scr->managerWindow, NoEvents);
628 XDeleteProperty(dpy, scr->managerWindow, scr->managerAtom);
630 XSetSelectionOwner(dpy, scr->managerAtom, scr->managerWindow, CurrentTime);
632 XUngrabServer(dpy);
634 /* announce our arrival */
636 ev.xclient.type = ClientMessage;
637 ev.xclient.message_type = XInternAtom(dpy, "MANAGER", False);
638 ev.xclient.destination = scr->root_win;
639 ev.xclient.format = 32;
640 ev.xclient.data.l[0] = timestamp;
641 ev.xclient.data.l[1] = scr->managerAtom;
642 ev.xclient.data.l[2] = scr->managerWindow;
643 ev.xclient.data.l[3] = 0;
644 ev.xclient.data.l[4] = 0;
646 XSendEvent(dpy, scr->root_win, False, StructureNotify, &ev);
647 XSync(dpy, False);
649 return True;
651 #endif
654 *----------------------------------------------------------------------
655 * wScreenInit--
656 * Initializes the window manager for the given screen and
657 * allocates a WScreen descriptor for it. Many resources are allocated
658 * for the screen and the root window is setup appropriately.
660 * Returns:
661 * The WScreen descriptor for the screen.
663 * Side effects:
664 * Many resources are allocated and the IconSize property is
665 * set on the root window.
666 * The program can be aborted if some fatal error occurs.
668 * TODO: User specifiable visual.
669 *----------------------------------------------------------------------
671 WScreen*
672 wScreenInit(int screen_number)
674 WScreen *scr;
675 XIconSize icon_size[1];
676 RContextAttributes rattr;
677 extern int wVisualID;
678 long event_mask;
679 WMColor *color;
680 XErrorHandler oldHandler;
682 scr = wmalloc(sizeof(WScreen));
683 memset(scr, 0, sizeof(WScreen));
685 /* initialize globals */
686 scr->screen = screen_number;
687 scr->root_win = RootWindow(dpy, screen_number);
688 scr->depth = DefaultDepth(dpy, screen_number);
689 scr->colormap = DefaultColormap(dpy, screen_number);
691 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
692 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
694 scr->usableArea.x2 = scr->scr_width;
695 scr->usableArea.y2 = scr->scr_height;
696 scr->totalUsableArea.x2 = scr->scr_width;
697 scr->totalUsableArea.y2 = scr->scr_height;
699 #if 0
700 if (!aquireManagerSelection(scr)) {
701 free(scr);
703 return NULL;
705 #endif
706 CantManageScreen = 0;
707 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
709 event_mask = EVENT_MASK;
711 if (wPreferences.disable_root_mouse) {
712 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
715 XSelectInput(dpy, scr->root_win, event_mask);
717 #ifdef KEEP_XKB_LOCK_STATUS
718 /* Only GroupLock doesn't work correctly in my system since right-alt
719 * can change mode while holding it too - ]d
721 if (wXkbSupported) {
722 XkbSelectEvents(dpy,XkbUseCoreKbd,
723 XkbStateNotifyMask,
724 XkbStateNotifyMask);
726 #endif /* KEEP_XKB_LOCK_STATUS */
728 XSync(dpy, False);
729 XSetErrorHandler(oldHandler);
731 if (CantManageScreen) {
732 free(scr);
733 return NULL;
736 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_DEFAULT]);
738 /* screen descriptor for raster graphic library */
739 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
740 rattr.render_mode = wPreferences.no_dithering
741 ? RBestMatchRendering
742 : RDitheredRendering;
744 /* if the std colormap stuff works ok, this will be ignored */
745 rattr.colors_per_channel = wPreferences.cmap_size;
746 if (rattr.colors_per_channel<2)
747 rattr.colors_per_channel = 2;
749 /* will only be accounted for in PseudoColor */
750 rattr.standard_colormap_mode = RCreateStdColormap;
752 if (wVisualID>=0) {
753 rattr.flags |= RC_VisualID;
754 rattr.visualid = wVisualID;
756 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
757 if (!scr->rcontext) {
758 wwarning(_("could not initialize graphics library context: %s"),
759 RMessageForError(RErrorCode));
760 wAbort(False);
761 } else {
762 char **formats;
763 int i = 0;
765 formats = RSupportedFileFormats();
766 if (formats) {
767 for (i=0; formats[i]!=NULL; i++) {
768 if (strcmp(formats[i], "TIFF")==0) {
769 scr->flags.supports_tiff = 1;
770 break;
776 scr->w_win = scr->rcontext->drawable;
777 scr->w_visual = scr->rcontext->visual;
778 scr->w_depth = scr->rcontext->depth;
779 scr->w_colormap = scr->rcontext->cmap;
781 scr->black_pixel = scr->rcontext->black;
782 scr->white_pixel = scr->rcontext->white;
784 /* create screen descriptor for WINGs */
785 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
786 scr->rcontext);
788 if (!scr->wmscreen) {
789 wfatal(_("could not do initialization of WINGs widget set"));
791 return NULL;
794 color = WMGrayColor(scr->wmscreen);
795 scr->light_pixel = WMColorPixel(color);
796 WMReleaseColor(color);
798 color = WMDarkGrayColor(scr->wmscreen);
799 scr->dark_pixel = WMColorPixel(color);
800 WMReleaseColor(color);
803 XColor xcol;
804 /* frame boder color */
805 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
806 scr->frame_border_pixel = xcol.pixel;
809 /* create GCs with default values */
810 allocGCs(scr);
812 /* read defaults for this screen */
813 wReadDefaults(scr, WDWindowMaker->dictionary);
815 createInternalWindows(scr);
817 #ifdef KWM_HINTS
818 wKWMInitStuff(scr);
819 #endif
821 #ifdef GNOME_STUFF
822 wGNOMEInitStuff(scr);
823 #endif
825 #ifdef OLWM_HINTS
826 wOLWMInitStuff(scr);
827 #endif
829 /* create initial workspace */
830 wWorkspaceNew(scr);
832 /* create shared pixmaps */
833 createPixmaps(scr);
835 /* set icon sizes we can accept from clients */
836 icon_size[0].min_width = 8;
837 icon_size[0].min_height = 8;
838 icon_size[0].max_width = wPreferences.icon_size-4;
839 icon_size[0].max_height = wPreferences.icon_size-4;
840 icon_size[0].width_inc = 1;
841 icon_size[0].height_inc = 1;
842 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
844 /* setup WindowMaker protocols property in the root window*/
845 PropSetWMakerProtocols(scr->root_win);
847 /* setup our noticeboard */
848 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
849 XA_WINDOW, 32, PropModeReplace,
850 (unsigned char*)&scr->info_window, 1);
851 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
852 XA_WINDOW, 32, PropModeReplace,
853 (unsigned char*)&scr->info_window, 1);
856 #ifdef BALLOON_TEXT
857 /* initialize balloon text stuff */
858 wBalloonInitialize(scr);
859 #endif
861 wScreenUpdateUsableArea(scr);
864 return scr;
868 void
869 wScreenUpdateUsableArea(WScreen *scr)
871 #ifdef GNOME_STUFF
872 WReservedArea *area;
873 #endif
875 scr->totalUsableArea = scr->usableArea;
878 if (scr->dock && (!scr->dock->lowered
879 || wPreferences.no_window_over_dock)) {
881 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
883 if (scr->dock->on_right_side) {
884 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
885 scr->scr_width - offset);
886 } else {
887 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
891 if (wPreferences.no_window_over_icons) {
892 if (wPreferences.icon_yard & IY_VERT) {
894 if (!(wPreferences.icon_yard & IY_RIGHT)) {
895 scr->totalUsableArea.x1 += wPreferences.icon_size;
896 } else {
897 scr->totalUsableArea.x2 -= wPreferences.icon_size;
899 } else {
901 if (wPreferences.icon_yard & IY_TOP) {
902 scr->totalUsableArea.y1 += wPreferences.icon_size;
903 } else {
904 scr->totalUsableArea.y2 -= wPreferences.icon_size;
909 #ifdef KWM_HINTS
911 WArea area;
913 if (wKWMGetUsableArea(scr, &area)) {
914 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
915 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
916 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
917 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
920 #endif
922 #ifdef GNOME_STUFF
923 area = scr->reservedAreas;
925 while (area) {
926 int th, bh;
927 int lw, rw;
928 int w, h;
930 w = area->area.x2 - area->area.x1;
931 h = area->area.y2 - area->area.y1;
933 th = area->area.y1;
934 bh = scr->scr_height - area->area.y2;
935 lw = area->area.x1;
936 rw = scr->scr_width - area->area.x2;
938 if (WMIN(th, bh) < WMIN(lw, rw)) {
939 /* horizontal */
940 if (th < bh) {
941 /* on top */
942 if (scr->totalUsableArea.y1 < area->area.y2)
943 scr->totalUsableArea.y1 = area->area.y2;
944 } else {
945 /* on bottom */
946 if (scr->totalUsableArea.y2 > area->area.y1)
947 scr->totalUsableArea.y2 = area->area.y1;
949 } else {
950 /* vertical */
951 if (lw < rw) {
952 /* on left */
953 if (scr->totalUsableArea.x1 < area->area.x2)
954 scr->totalUsableArea.x1 = area->area.x2;
955 } else {
956 /* on right */
957 if (scr->totalUsableArea.x2 > area->area.x1)
958 scr->totalUsableArea.x2 = area->area.x1;
962 area = area->next;
964 #endif /* GNOME_STUFF */
966 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
967 scr->totalUsableArea.x2 = scr->usableArea.x2;
968 scr->totalUsableArea.x1 = scr->usableArea.x1;
970 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
971 scr->totalUsableArea.y2 = scr->usableArea.y2;
972 scr->totalUsableArea.y1 = scr->usableArea.y1;
975 #ifdef not_used
976 #ifdef KWM_HINTS
978 int i;
980 for (i = 0; i < scr->workspace_count; i++) {
981 wKWMSetUsableAreaHint(scr, i);
984 #endif
985 #endif
989 void
990 wScreenRestoreState(WScreen *scr)
992 proplist_t state;
993 char *path;
996 #ifndef LITE
997 OpenRootMenu(scr, -10000, -10000, False);
998 wMenuUnmap(scr->root_menu);
999 #endif
1001 make_keys();
1003 if (wScreenCount == 1)
1004 path = wdefaultspathfordomain("WMState");
1005 else {
1006 char buf[16];
1007 sprintf(buf, "WMState.%i", scr->screen);
1008 path = wdefaultspathfordomain(buf);
1010 scr->session_state = PLGetProplistWithPath(path);
1011 free(path);
1012 if (!scr->session_state && wScreenCount>1) {
1013 char buf[16];
1014 sprintf(buf, "WMState.%i", scr->screen);
1015 path = wdefaultspathfordomain(buf);
1016 scr->session_state = PLGetProplistWithPath(path);
1017 free(path);
1020 if (!wPreferences.flags.noclip) {
1021 state = PLGetDictionaryEntry(scr->session_state, dClip);
1022 scr->clip_icon = wClipRestoreState(scr, state);
1025 wWorkspaceRestoreState(scr);
1027 if (!wPreferences.flags.nodock) {
1028 state = PLGetDictionaryEntry(scr->session_state, dDock);
1029 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
1032 wScreenUpdateUsableArea(scr);
1036 void
1037 wScreenSaveState(WScreen *scr)
1039 WWorkspaceState wstate;
1040 WWindow *wwin;
1041 char *str;
1042 proplist_t path, old_state, foo;
1043 CARD32 data[2];
1046 make_keys();
1049 * Save current workspace, so can go back to it upon restart.
1051 wstate.workspace = scr->current_workspace;
1053 data[0] = wstate.flags;
1054 data[1] = wstate.workspace;
1056 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
1057 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1058 (unsigned char *) data, 2);
1060 /* save state of windows */
1061 wwin = scr->focused_window;
1062 while (wwin) {
1063 wWindowSaveState(wwin);
1064 wwin = wwin->prev;
1068 if (wPreferences.flags.noupdates)
1069 return;
1072 old_state = scr->session_state;
1073 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
1075 PLSetStringCmpHook(NULL);
1077 /* save dock state to file */
1078 if (!wPreferences.flags.nodock) {
1079 wDockSaveState(scr, old_state);
1080 } else {
1081 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
1082 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
1085 if (!wPreferences.flags.noclip) {
1086 wClipSaveState(scr);
1087 } else {
1088 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
1089 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
1093 wWorkspaceSaveState(scr, old_state);
1095 if (wPreferences.save_session_on_exit) {
1096 wSessionSaveState(scr);
1097 } else {
1098 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
1099 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
1101 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
1102 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
1106 /* clean up */
1107 PLSetStringCmpHook(StringCompareHook);
1109 wMenuSaveState(scr);
1111 if (wScreenCount == 1)
1112 str = wdefaultspathfordomain("WMState");
1113 else {
1114 char buf[16];
1115 sprintf(buf, "WMState.%i", scr->screen);
1116 str = wdefaultspathfordomain(buf);
1118 path = PLMakeString(str);
1119 free(str);
1120 PLSetFilename(scr->session_state, path);
1121 if (!PLSave(scr->session_state, YES)) {
1122 wsyserror(_("could not save session state in %s"), PLGetString(path));
1124 PLRelease(path);
1125 PLRelease(old_state);
1131 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1133 int moved = 0;
1134 int tol_w, tol_h;
1136 if (width > 20)
1137 tol_w = width/2;
1138 else
1139 tol_w = 20;
1141 if (height > 20)
1142 tol_h = height/2;
1143 else
1144 tol_h = 20;
1146 if (*x+width < 10)
1147 *x = -tol_w, moved = 1;
1148 else if (*x >= scr->scr_width - 10)
1149 *x = scr->scr_width - tol_w - 1, moved = 1;
1151 if (*y < -height + 10)
1152 *y = -tol_h, moved = 1;
1153 else if (*y >= scr->scr_height - 10)
1154 *y = scr->scr_height - tol_h - 1, moved = 1;
1156 return moved;