changed encoding of (c) thing in about panel to utf-8
[wmaker-crm.git] / src / screen.c
blob8e619f4acb296c934db11b46594d6ccc5d7f3802
1 /* screen.c - screen management
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2003 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 int gcm;
271 scr->stipple_bitmap =
272 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
273 STIPPLE_HEIGHT);
275 gcv.stipple = scr->stipple_bitmap;
276 gcv.foreground = scr->white_pixel;
277 gcv.fill_style = FillStippled;
278 gcv.graphics_exposures = False;
279 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
280 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
283 /* selected icon border GCs */
284 gcv.function = GXcopy;
285 gcv.foreground = scr->white_pixel;
286 gcv.background = scr->black_pixel;
287 gcv.line_width = 1;
288 gcv.line_style = LineDoubleDash;
289 gcv.fill_style = FillSolid;
290 gcv.dash_offset = 0;
291 gcv.dashes = 4;
292 gcv.graphics_exposures = False;
294 gcm = GCFunction | GCGraphicsExposures;
295 gcm |= GCForeground | GCBackground;
296 gcm |= GCLineWidth | GCLineStyle;
297 gcm |= GCFillStyle;
298 gcm |= GCDashOffset | GCDashList;
300 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
302 scr->menu_title_color[0] = WMRetainColor(scr->white);
304 /* don't retain scr->black here because we may alter its alpha */
305 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
306 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
308 /* frame GC */
309 wGetColor(scr, DEF_FRAME_COLOR, &color);
310 gcv.function = GXxor;
311 /* this will raise the probability of the XORed color being different
312 * of the original color in PseudoColor when not all color cells are
313 * initialized */
314 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
315 gcv.plane_mask = (1<<(scr->depth-1))|1;
316 else
317 gcv.plane_mask = AllPlanes;
318 gcv.foreground = color.pixel;
319 if (gcv.foreground == 0)
320 gcv.foreground = 1;
321 gcv.line_width = DEF_FRAME_THICKNESS;
322 gcv.subwindow_mode = IncludeInferiors;
323 gcv.graphics_exposures = False;
324 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
325 |GCFunction|GCSubwindowMode|GCLineWidth
326 |GCPlaneMask, &gcv);
328 /* line GC */
329 gcv.foreground = color.pixel;
331 if (gcv.foreground == 0)
332 /* XOR:ing with a zero is not going to be of much use, so
333 in that case, we somewhat arbitrarily xor with 17 instead. */
334 gcv.foreground = 17;
336 gcv.function = GXxor;
337 gcv.subwindow_mode = IncludeInferiors;
338 gcv.line_width = 1;
339 gcv.cap_style = CapRound;
340 gcv.graphics_exposures = False;
341 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
342 |GCGraphicsExposures;
343 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
345 scr->line_pixel = gcv.foreground;
347 /* copy GC */
348 gcv.foreground = scr->white_pixel;
349 gcv.background = scr->black_pixel;
350 gcv.graphics_exposures = False;
351 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
352 |GCGraphicsExposures, &gcv);
354 /* misc drawing GC */
355 gcv.graphics_exposures = False;
356 gcm = GCGraphicsExposures;
357 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
359 assert (scr->stipple_bitmap!=None);
362 /* mono GC */
363 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
368 static void
369 createPixmaps(WScreen *scr)
371 WPixmap *pix;
372 RImage *image;
374 /* load pixmaps */
375 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
376 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
377 MENU_RADIO_INDICATOR_XBM_SIZE,
378 MENU_RADIO_INDICATOR_XBM_SIZE,
379 scr->black_pixel, scr->white_pixel);
380 if (pix!=NULL)
381 pix->shared = 1;
382 scr->menu_radio_indicator = pix;
385 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
386 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
387 MENU_CHECK_INDICATOR_XBM_SIZE,
388 MENU_CHECK_INDICATOR_XBM_SIZE,
389 scr->black_pixel, scr->white_pixel);
390 if (pix!=NULL)
391 pix->shared = 1;
392 scr->menu_check_indicator = pix;
394 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
395 (char*)MENU_MINI_INDICATOR_XBM_DATA,
396 MENU_MINI_INDICATOR_XBM_SIZE,
397 MENU_MINI_INDICATOR_XBM_SIZE,
398 scr->black_pixel, scr->white_pixel);
399 if (pix!=NULL)
400 pix->shared = 1;
401 scr->menu_mini_indicator = pix;
403 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
404 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
405 MENU_HIDE_INDICATOR_XBM_SIZE,
406 MENU_HIDE_INDICATOR_XBM_SIZE,
407 scr->black_pixel, scr->white_pixel);
408 if (pix!=NULL)
409 pix->shared = 1;
410 scr->menu_hide_indicator = pix;
412 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
413 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
414 MENU_SHADE_INDICATOR_XBM_SIZE,
415 MENU_SHADE_INDICATOR_XBM_SIZE,
416 scr->black_pixel, scr->white_pixel);
417 if (pix!=NULL)
418 pix->shared = 1;
419 scr->menu_shade_indicator = pix;
422 image = wDefaultGetImage(scr, "Logo", "WMPanel");
424 if (!image) {
425 wwarning(_("could not load logo image for panels: %s"),
426 RMessageForError(RErrorCode));
427 } else {
428 WMSetApplicationIconImage(scr->wmscreen, image);
429 RReleaseImage(image);
432 scr->dock_dots = make3Dots(scr);
434 /* titlebar button pixmaps */
435 allocButtonPixmaps(scr);
440 *----------------------------------------------------------------------
441 * createInternalWindows--
442 * Creates some windows used internally by the program. One to
443 * receive input focus when no other window can get it and another
444 * to display window geometry information during window resize/move.
446 * Returns:
447 * Nothing
449 * Side effects:
450 * Windows are created and some colors are allocated for the
451 * window background.
452 *----------------------------------------------------------------------
454 static void
455 createInternalWindows(WScreen *scr)
457 int vmask;
458 XSetWindowAttributes attribs;
460 /* InputOnly window to get the focus when no other window can get it */
461 vmask = CWEventMask|CWOverrideRedirect;
462 attribs.event_mask = KeyPressMask|FocusChangeMask;
463 attribs.override_redirect = True;
464 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
465 InputOnly,CopyFromParent, vmask, &attribs);
466 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
467 XMapWindow(dpy, scr->no_focus_win);
469 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
471 /* shadow window for dock buttons */
472 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
473 attribs.border_pixel = scr->black_pixel;
474 attribs.save_under = True;
475 attribs.override_redirect = True;
476 attribs.background_pixmap = None;
477 attribs.background_pixel = scr->white_pixel;
478 attribs.cursor = wCursor[WCUR_DEFAULT];
479 vmask |= CWColormap;
480 attribs.colormap = scr->w_colormap;
481 scr->dock_shadow =
482 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
483 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
484 scr->w_visual, vmask, &attribs);
486 /* workspace name balloon for clip */
487 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
488 |CWBorderPixel;
489 attribs.save_under = True;
490 attribs.override_redirect = True;
491 attribs.colormap = scr->w_colormap;
492 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
493 attribs.border_pixel = 0; /* do not care */
494 scr->clip_balloon =
495 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
496 CopyFromParent, scr->w_visual, vmask, &attribs);
499 /* workspace name */
500 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
501 |CWBorderPixel;
502 attribs.save_under = True;
503 attribs.override_redirect = True;
504 attribs.colormap = scr->w_colormap;
505 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
506 attribs.border_pixel = 0; /* do not care */
507 scr->workspace_name =
508 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
509 CopyFromParent, scr->w_visual, vmask, &attribs);
512 * If the window is clicked without having ButtonPress selected, the
513 * resulting event will have event.xbutton.window == root.
515 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
519 #if 0
520 static Bool
521 aquireManagerSelection(WScreen *scr)
523 char buffer[32];
524 XEvent ev;
525 Time timestamp;
527 snprintf(buffer, sizeof(buffer), "WM_S%i", scr->screen);
528 scr->managerAtom = XInternAtom(dpy, buffer, False);
530 /* for race-conditions... */
531 XGrabServer(dpy);
533 /* if there is another manager running, don't try to replace it
534 * (for now, at least) */
535 if (XGetSelectionOwner(dpy, scr->managerAtom) != None) {
536 XUngrabServer(dpy);
537 return False;
540 /* become the manager for this screen */
542 scr->managerWindow = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 1, 1,
543 0, 0, 0);
545 XSelectInput(dpy, scr->managerWindow, PropertyChangeMask);
546 /* get a timestamp */
547 XChangeProperty(dpy, scr->managerWindow, scr->managerAtom,
548 XA_INTEGER, 32, PropModeAppend, NULL, 0);
549 while (1) {
550 XWindowEvent(dpy, scr->managerWindow, &ev);
551 if (ev.type == PropertyNotify) {
552 timestamp = ev.xproperty.time;
553 break;
556 XSelectInput(dpy, scr->managerWindow, NoEvents);
557 XDeleteProperty(dpy, scr->managerWindow, scr->managerAtom);
559 XSetSelectionOwner(dpy, scr->managerAtom, scr->managerWindow, CurrentTime);
561 XUngrabServer(dpy);
563 /* announce our arrival */
565 ev.xclient.type = ClientMessage;
566 ev.xclient.message_type = XInternAtom(dpy, "MANAGER", False);
567 ev.xclient.destination = scr->root_win;
568 ev.xclient.format = 32;
569 ev.xclient.data.l[0] = timestamp;
570 ev.xclient.data.l[1] = scr->managerAtom;
571 ev.xclient.data.l[2] = scr->managerWindow;
572 ev.xclient.data.l[3] = 0;
573 ev.xclient.data.l[4] = 0;
575 XSendEvent(dpy, scr->root_win, False, StructureNotify, &ev);
576 XSync(dpy, False);
578 return True;
580 #endif
583 *----------------------------------------------------------------------
584 * wScreenInit--
585 * Initializes the window manager for the given screen and
586 * allocates a WScreen descriptor for it. Many resources are allocated
587 * for the screen and the root window is setup appropriately.
589 * Returns:
590 * The WScreen descriptor for the screen.
592 * Side effects:
593 * Many resources are allocated and the IconSize property is
594 * set on the root window.
595 * The program can be aborted if some fatal error occurs.
597 * TODO: User specifiable visual.
598 *----------------------------------------------------------------------
600 WScreen*
601 wScreenInit(int screen_number)
603 WScreen *scr;
604 XIconSize icon_size[1];
605 RContextAttributes rattr;
606 extern int wVisualID;
607 long event_mask;
608 XErrorHandler oldHandler;
609 int i;
611 scr = wmalloc(sizeof(WScreen));
612 memset(scr, 0, sizeof(WScreen));
614 scr->stacking_list = WMCreateTreeBag();
616 /* initialize globals */
617 scr->screen = screen_number;
618 scr->root_win = RootWindow(dpy, screen_number);
619 scr->depth = DefaultDepth(dpy, screen_number);
620 scr->colormap = DefaultColormap(dpy, screen_number);
622 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
623 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
625 wInitXinerama(scr);
627 scr->usableArea = (WArea *)wmalloc(sizeof(WArea)*wXineramaHeads(scr));
628 scr->totalUsableArea = (WArea *)wmalloc(sizeof(WArea)*wXineramaHeads(scr));
630 for (i=0; i<wXineramaHeads(scr); ++i) {
631 WMRect rect = wGetRectForHead(scr, i);
632 scr->usableArea[i].x1 = scr->totalUsableArea[i].x1 = rect.pos.x;
633 scr->usableArea[i].y1 = scr->totalUsableArea[i].y1 = rect.pos.y;
634 scr->usableArea[i].x2 = scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
635 scr->usableArea[i].y2 = scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
638 scr->fakeGroupLeaders = WMCreateArray(16);
640 #if 0
641 if (!aquireManagerSelection(scr)) {
642 wfree(scr);
644 return NULL;
646 #endif
647 CantManageScreen = 0;
648 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
650 event_mask = EVENT_MASK;
652 if (wPreferences.disable_root_mouse) {
653 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
656 XSelectInput(dpy, scr->root_win, event_mask);
658 #ifdef KEEP_XKB_LOCK_STATUS
659 /* Only GroupLock doesn't work correctly in my system since right-alt
660 * can change mode while holding it too - ]d
662 if (wXkbSupported) {
663 XkbSelectEvents(dpy,XkbUseCoreKbd,
664 XkbStateNotifyMask,
665 XkbStateNotifyMask);
667 #endif /* KEEP_XKB_LOCK_STATUS */
669 XSync(dpy, False);
670 XSetErrorHandler(oldHandler);
672 if (CantManageScreen) {
673 wfree(scr);
674 return NULL;
677 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_ROOT]);
679 /* screen descriptor for raster graphic library */
680 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
681 rattr.render_mode = wPreferences.no_dithering
682 ? RBestMatchRendering
683 : RDitheredRendering;
685 /* if the std colormap stuff works ok, this will be ignored */
686 rattr.colors_per_channel = wPreferences.cmap_size;
687 if (rattr.colors_per_channel<2)
688 rattr.colors_per_channel = 2;
691 /* will only be accounted for in PseudoColor */
692 if (wPreferences.flags.create_stdcmap) {
693 rattr.standard_colormap_mode = RCreateStdColormap;
694 } else {
695 rattr.standard_colormap_mode = RUseStdColormap;
698 if (wVisualID>=0) {
699 rattr.flags |= RC_VisualID;
700 rattr.visualid = wVisualID;
703 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
705 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
706 wwarning(RMessageForError(RErrorCode));
708 rattr.flags &= ~RC_StandardColormap;
709 rattr.standard_colormap_mode = RUseStdColormap;
711 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
714 if (!scr->rcontext) {
715 wwarning(_("could not initialize graphics library context: %s"),
716 RMessageForError(RErrorCode));
717 wAbort(False);
718 } else {
719 char **formats;
720 int i = 0;
722 formats = RSupportedFileFormats();
723 if (formats) {
724 for (i=0; formats[i]!=NULL; i++) {
725 if (strcmp(formats[i], "TIFF")==0) {
726 scr->flags.supports_tiff = 1;
727 break;
733 scr->w_win = scr->rcontext->drawable;
734 scr->w_visual = scr->rcontext->visual;
735 scr->w_depth = scr->rcontext->depth;
736 scr->w_colormap = scr->rcontext->cmap;
738 /* create screen descriptor for WINGs */
739 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
740 scr->rcontext);
742 if (!scr->wmscreen) {
743 wfatal(_("could not initialize WINGs widget set"));
744 return NULL;
747 scr->black = WMBlackColor(scr->wmscreen);
748 scr->white = WMWhiteColor(scr->wmscreen);
749 scr->gray = WMGrayColor(scr->wmscreen);
750 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
752 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black;*/
753 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white;*/
754 scr->light_pixel = WMColorPixel(scr->gray);
755 scr->dark_pixel = WMColorPixel(scr->darkGray);
758 XColor xcol;
759 /* frame boder color */
760 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
761 scr->frame_border_pixel = xcol.pixel;
764 /* create GCs with default values */
765 allocGCs(scr);
767 /* for our window manager info notice board. Need to
768 * create before reading the defaults, because it will be used there.
770 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10,
771 0, 0, 0);
773 /* read defaults for this screen */
774 wReadDefaults(scr, WDWindowMaker->dictionary);
776 createInternalWindows(scr);
778 #ifdef KWM_HINTS
779 wKWMInitStuff(scr);
780 #endif
782 #ifdef GNOME_STUFF
783 wGNOMEInitStuff(scr);
784 #endif
786 #ifdef OLWM_HINTS
787 wOLWMInitStuff(scr);
788 #endif
790 /* create initial workspace */
791 wWorkspaceNew(scr);
793 /* create shared pixmaps */
794 createPixmaps(scr);
796 /* set icon sizes we can accept from clients */
797 icon_size[0].min_width = 8;
798 icon_size[0].min_height = 8;
799 icon_size[0].max_width = wPreferences.icon_size-4;
800 icon_size[0].max_height = wPreferences.icon_size-4;
801 icon_size[0].width_inc = 1;
802 icon_size[0].height_inc = 1;
803 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
805 /* setup WindowMaker protocols property in the root window*/
806 PropSetWMakerProtocols(scr->root_win);
808 /* setup our noticeboard */
809 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
810 XA_WINDOW, 32, PropModeReplace,
811 (unsigned char*)&scr->info_window, 1);
812 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
813 XA_WINDOW, 32, PropModeReplace,
814 (unsigned char*)&scr->info_window, 1);
817 #ifdef BALLOON_TEXT
818 /* initialize balloon text stuff */
819 wBalloonInitialize(scr);
820 #endif
822 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
824 scr->tech_draw_font= XLoadQueryFont(dpy, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
826 scr->gview = WCreateGeometryView(scr->wmscreen);
827 WMRealizeWidget(scr->gview);
829 wScreenUpdateUsableArea(scr);
831 return scr;
835 void
836 wScreenUpdateUsableArea(WScreen *scr)
839 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
840 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
841 * border.
844 int i;
845 unsigned long best_area = 0, tmp_area;
846 WArea area;
847 int dock_head = scr->xine_info.primary_head;
849 if (scr->dock) {
850 WMRect rect;
851 rect.pos.x = scr->dock->x_pos;
852 rect.pos.y = scr->dock->y_pos;
853 rect.size.width = wPreferences.icon_size;
854 rect.size.height = wPreferences.icon_size;
855 dock_head = wGetHeadForRect(scr, rect);
858 for (i=0; i<wXineramaHeads(scr); ++i) {
859 WMRect rect = wGetRectForHead(scr, i);
860 scr->totalUsableArea[i].x1 = rect.pos.x;
861 scr->totalUsableArea[i].y1 = rect.pos.y;
862 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
863 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
865 if (scr->dock && dock_head==i &&
866 (!scr->dock->lowered || wPreferences.no_window_over_dock)) {
867 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
869 if (scr->dock->on_right_side) {
870 scr->totalUsableArea[i].x2 -= offset;
871 } else {
872 scr->totalUsableArea[i].x1 += offset;
876 #ifdef NETWM_HINTS
878 WArea area;
879 if (wNETWMGetUsableArea(scr, i, &area)) {
880 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
881 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
882 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
883 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
886 #endif
888 #ifdef GNOME_STUFF
890 WArea area;
891 if (wGNOMEGetUsableArea(scr, i, &area)) {
892 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
893 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
894 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
895 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
898 #endif
900 #ifdef KWM_HINTS
902 WArea area;
903 if (wKWMGetUsableArea(scr, i, &area)) {
904 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
905 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
906 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
907 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
910 #endif
912 scr->usableArea[i] = scr->totalUsableArea[i];
914 #if 0
915 printf("usableArea[%d]: %d %d %d %d\n", i,
916 scr->usableArea[i].x1, scr->usableArea[i].x2,
917 scr->usableArea[i].y1, scr->usableArea[i].y2);
918 #endif
920 if (wPreferences.no_window_over_icons) {
921 if (wPreferences.icon_yard & IY_VERT) {
922 if (wPreferences.icon_yard & IY_RIGHT) {
923 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
924 } else {
925 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
927 } else {
928 if (wPreferences.icon_yard & IY_TOP) {
929 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
930 } else {
931 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
936 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width/2) {
937 scr->totalUsableArea[i].x1 = rect.pos.x;
938 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
941 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height/2) {
942 scr->totalUsableArea[i].y1 = rect.pos.y;
943 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
946 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
947 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
949 if (tmp_area > best_area) {
950 best_area = tmp_area;
951 area = scr->totalUsableArea[i];
955 unsigned size = wPreferences.workspace_border_size;
956 unsigned position = wPreferences.workspace_border_position;
958 if (size>0 && position!=WB_NONE) {
959 if (position & WB_LEFTRIGHT) {
960 scr->totalUsableArea[i].x1 += size;
961 scr->totalUsableArea[i].x2 -= size;
963 if (position & WB_TOPBOTTOM) {
964 scr->totalUsableArea[i].y1 += size;
965 scr->totalUsableArea[i].y2 -= size;
971 #ifdef NETWM_HINTS
972 wNETWMUpdateWorkarea(scr, area);
973 #endif
975 if (wPreferences.auto_arrange_icons) {
976 wArrangeIcons(scr, True);
980 #if 0
981 void
982 wScreenUpdateUsableArea(WScreen *scr)
984 scr->totalUsableArea = scr->usableArea;
986 if (scr->dock && (!scr->dock->lowered
987 || wPreferences.no_window_over_dock)) {
989 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
991 if (scr->dock->on_right_side) {
992 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
993 scr->scr_width - offset);
994 } else {
995 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
999 if (wPreferences.no_window_over_icons) {
1000 if (wPreferences.icon_yard & IY_VERT) {
1002 if (!(wPreferences.icon_yard & IY_RIGHT)) {
1003 scr->totalUsableArea.x1 += wPreferences.icon_size;
1004 } else {
1005 scr->totalUsableArea.x2 -= wPreferences.icon_size;
1007 } else {
1009 if (wPreferences.icon_yard & IY_TOP) {
1010 scr->totalUsableArea.y1 += wPreferences.icon_size;
1011 } else {
1012 scr->totalUsableArea.y2 -= wPreferences.icon_size;
1017 #ifdef KWM_HINTS
1019 WArea area;
1021 if (wKWMGetUsableArea(scr, &area)) {
1022 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
1023 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
1024 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
1025 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
1028 #endif
1030 #ifdef GNOME_STUFF
1032 WReservedArea *area = scr->reservedAreas;
1034 while (area) {
1035 int th, bh;
1036 int lw, rw;
1037 int w, h;
1039 w = area->area.x2 - area->area.x1;
1040 h = area->area.y2 - area->area.y1;
1042 th = area->area.y1;
1043 bh = scr->scr_height - area->area.y2;
1044 lw = area->area.x1;
1045 rw = scr->scr_width - area->area.x2;
1047 if (WMIN(th, bh) <= WMIN(lw, rw)) {
1048 /* horizontal */
1049 if (th < bh) {
1050 /* on top */
1051 if (scr->totalUsableArea.y1 < area->area.y2)
1052 scr->totalUsableArea.y1 = area->area.y2;
1053 } else {
1054 /* on bottom */
1055 if (scr->totalUsableArea.y2 > area->area.y1)
1056 scr->totalUsableArea.y2 = area->area.y1;
1058 } else {
1059 /* vertical */
1060 if (lw < rw) {
1061 /* on left */
1062 if (scr->totalUsableArea.x1 < area->area.x2)
1063 scr->totalUsableArea.x1 = area->area.x2;
1064 } else {
1065 /* on right */
1066 if (scr->totalUsableArea.x2 > area->area.x1)
1067 scr->totalUsableArea.x2 = area->area.x1;
1071 area = area->next;
1074 #endif /* GNOME_STUFF */
1076 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
1077 scr->totalUsableArea.x2 = scr->usableArea.x2;
1078 scr->totalUsableArea.x1 = scr->usableArea.x1;
1080 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
1081 scr->totalUsableArea.y2 = scr->usableArea.y2;
1082 scr->totalUsableArea.y1 = scr->usableArea.y1;
1085 #ifdef not_used
1086 #ifdef KWM_HINTS
1088 int i;
1090 for (i = 0; i < scr->workspace_count; i++) {
1091 wKWMSetUsableAreaHint(scr, i);
1094 #endif
1095 #endif
1098 unsigned size = wPreferences.workspace_border_size;
1099 unsigned position = wPreferences.workspace_border_position;
1101 if (size>0 && position!=WB_NONE) {
1102 if (position & WB_LEFTRIGHT) {
1103 scr->totalUsableArea.x1 += size;
1104 scr->totalUsableArea.x2 -= size;
1106 if (position & WB_TOPBOTTOM) {
1107 scr->totalUsableArea.y1 += size;
1108 scr->totalUsableArea.y2 -= size;
1113 if (wPreferences.auto_arrange_icons) {
1114 wArrangeIcons(scr, True);
1117 #endif
1120 void
1121 wScreenRestoreState(WScreen *scr)
1123 WMPropList *state;
1124 char *path;
1127 #ifndef LITE
1128 OpenRootMenu(scr, -10000, -10000, False);
1129 wMenuUnmap(scr->root_menu);
1130 #endif
1132 make_keys();
1134 if (wScreenCount == 1) {
1135 path = wdefaultspathfordomain("WMState");
1136 } else {
1137 char buf[16];
1138 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
1139 path = wdefaultspathfordomain(buf);
1141 scr->session_state = WMReadPropListFromFile(path);
1142 wfree(path);
1143 if (!scr->session_state && wScreenCount>1) {
1144 path = wdefaultspathfordomain("WMState");
1145 scr->session_state = WMReadPropListFromFile(path);
1146 wfree(path);
1149 if (!wPreferences.flags.noclip && scr->session_state) {
1150 state = WMGetFromPLDictionary(scr->session_state, dClip);
1151 scr->clip_icon = wClipRestoreState(scr, state);
1154 wWorkspaceRestoreState(scr);
1156 #ifdef VIRTUAL_DESKTOP
1158 * * create inputonly windows at the border of screen
1159 * */
1160 wWorkspaceManageEdge(scr);
1161 #endif
1163 if (!wPreferences.flags.nodock && scr->session_state) {
1164 state = WMGetFromPLDictionary(scr->session_state, dDock);
1165 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
1168 wScreenUpdateUsableArea(scr);
1172 void
1173 wScreenSaveState(WScreen *scr)
1175 WWindow *wwin;
1176 char *str;
1177 WMPropList *old_state, *foo;
1178 CARD32 data[2];
1181 make_keys();
1183 /* Save current workspace, so can go back to it upon restart. */
1184 data[0] = scr->current_workspace;
1185 data[1] = WFLAGS_NONE;
1187 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
1188 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1189 (unsigned char *) data, 2);
1191 /* save state of windows */
1192 wwin = scr->focused_window;
1193 while (wwin) {
1194 wWindowSaveState(wwin);
1195 wwin = wwin->prev;
1199 if (wPreferences.flags.noupdates)
1200 return;
1203 old_state = scr->session_state;
1204 scr->session_state = WMCreatePLDictionary(NULL, NULL, NULL);
1206 WMPLSetCaseSensitive(True);
1208 /* save dock state to file */
1209 if (!wPreferences.flags.nodock) {
1210 wDockSaveState(scr, old_state);
1211 } else {
1212 if ((foo = WMGetFromPLDictionary(old_state, dDock))!=NULL) {
1213 WMPutInPLDictionary(scr->session_state, dDock, foo);
1216 if (!wPreferences.flags.noclip) {
1217 wClipSaveState(scr);
1218 } else {
1219 if ((foo = WMGetFromPLDictionary(old_state, dClip))!=NULL) {
1220 WMPutInPLDictionary(scr->session_state, dClip, foo);
1224 wWorkspaceSaveState(scr, old_state);
1226 if (wPreferences.save_session_on_exit) {
1227 wSessionSaveState(scr);
1228 } else {
1229 if ((foo = WMGetFromPLDictionary(old_state, dApplications))!=NULL) {
1230 WMPutInPLDictionary(scr->session_state, dApplications, foo);
1232 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace))!=NULL) {
1233 WMPutInPLDictionary(scr->session_state, dWorkspace, foo);
1237 /* clean up */
1238 WMPLSetCaseSensitive(False);
1240 wMenuSaveState(scr);
1242 if (wScreenCount == 1)
1243 str = wdefaultspathfordomain("WMState");
1244 else {
1245 char buf[16];
1246 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
1247 str = wdefaultspathfordomain(buf);
1249 if (!WMWritePropListToFile(scr->session_state, str, True)) {
1250 wsyserror(_("could not save session state in %s"), str);
1252 wfree(str);
1253 WMReleasePropList(old_state);
1259 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1261 int moved = 0;
1262 int tol_w, tol_h;
1264 * With respect to the head that contains most of the window.
1266 int sx1, sy1, sx2, sy2;
1268 WMRect rect;
1269 int head, flags;
1271 rect.pos.x = *x;
1272 rect.pos.y = *y;
1273 rect.size.width = width;
1274 rect.size.height = height;
1276 head = wGetRectPlacementInfo(scr, rect, &flags);
1277 rect = wGetRectForHead(scr, head);
1279 sx1 = rect.pos.x;
1280 sy1 = rect.pos.y;
1281 sx2 = sx1 + rect.size.width;
1282 sy2 = sy1 + rect.size.height;
1284 #if 0 /* NOTE: gives funky group movement */
1285 if (flags & XFLAG_MULTIPLE) {
1287 * since we span multiple heads, pull window totaly inside
1289 if (*x < sx1)
1290 *x = sx1, moved = 1;
1291 else if (*x + width > sx2)
1292 *x = sx2 - width, moved = 1;
1294 if (*y < sy1)
1295 *y = sy1, moved = 1;
1296 else if (*y + height > sy2)
1297 *y = sy2 - height, moved = 1;
1299 return moved;
1301 #endif
1303 if (width > 20)
1304 tol_w = width/2;
1305 else
1306 tol_w = 20;
1308 if (height > 20)
1309 tol_h = height/2;
1310 else
1311 tol_h = 20;
1313 if (*x + width < sx1 + 10)
1314 *x = sx1 - tol_w, moved = 1;
1315 else if (*x >= sx2 - 10)
1316 *x = sx2 - tol_w - 1, moved = 1;
1318 if (*y < sy1 - height + 10)
1319 *y = sy1 - tol_h, moved = 1;
1320 else if (*y >= sy2 - 10)
1321 *y = sy2 - tol_h - 1, moved = 1;
1323 return moved;
1329 wScreenKeepInside(WScreen *scr, int *x, int *y, int width, int height)
1331 int moved = 0;
1332 int sx1, sy1, sx2, sy2;
1333 WMRect rect;
1334 int head;
1336 rect.pos.x = *x;
1337 rect.pos.y = *y;
1338 rect.size.width = width;
1339 rect.size.height = height;
1341 head = wGetHeadForRect(scr, rect);
1342 rect = wGetRectForHead(scr, head);
1344 sx1 = rect.pos.x;
1345 sy1 = rect.pos.y;
1346 sx2 = sx1 + rect.size.width;
1347 sy2 = sy1 + rect.size.height;
1349 if (*x < sx1)
1350 *x = sx1, moved = 1;
1351 else if (*x + width > sx2)
1352 *x = sx2 - width, moved = 1;
1354 if (*y < sy1)
1355 *y = sy1, moved = 1;
1356 else if (*y + height > sy2)
1357 *y = sy2 - height, moved = 1;
1359 return moved;