Allow setting separate border color for focused windows
[wmaker-crm.git] / src / screen.c
blobafc9d17d3c1e46da0b56f4a918c2caa5d6f812ff
1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "wconfig.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
31 #ifdef KEEP_XKB_LOCK_STATUS
32 #include <X11/XKBlib.h>
33 #endif /* KEEP_XKB_LOCK_STATUS */
34 #ifdef USE_RANDR
35 #include <X11/extensions/Xrandr.h>
36 #endif
38 #include <wraster.h>
39 #include "WindowMaker.h"
40 #include "def_pixmaps.h"
41 #include "screen.h"
42 #include "texture.h"
43 #include "pixmap.h"
44 #include "menu.h"
45 #include "window.h"
46 #include "main.h"
47 #include "actions.h"
48 #include "properties.h"
49 #include "dock.h"
50 #include "resources.h"
51 #include "workspace.h"
52 #include "session.h"
53 #include "balloon.h"
54 #include "geomview.h"
55 #include "wmspec.h"
56 #include "rootmenu.h"
58 #include "xinerama.h"
60 #include <WINGs/WUtil.h>
62 #include "defaults.h"
64 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
65 |SubstructureNotifyMask|PointerMotionMask \
66 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
67 |KeyPressMask|KeyReleaseMask)
69 #define STIPPLE_WIDTH 2
70 #define STIPPLE_HEIGHT 2
71 static char STIPPLE_DATA[] = { 0x02, 0x01 };
73 static int CantManageScreen = 0;
75 static WMPropList *dApplications = NULL;
76 static WMPropList *dWorkspace;
77 static WMPropList *dDock;
78 static WMPropList *dClip;
79 static WMPropList *dDrawers = NULL;
81 static void make_keys(void)
83 if (dApplications != NULL)
84 return;
86 dApplications = WMCreatePLString("Applications");
87 dWorkspace = WMCreatePLString("Workspace");
88 dDock = WMCreatePLString("Dock");
89 dClip = WMCreatePLString("Clip");
90 dDrawers = WMCreatePLString("Drawers");
94 *----------------------------------------------------------------------
95 * alreadyRunningError--
96 * X error handler used to catch errors when trying to do
97 * XSelectInput() on the root window. These errors probably mean that
98 * there already is some other window manager running.
100 * Returns:
101 * Nothing, unless something really evil happens...
103 * Side effects:
104 * CantManageScreen is set to 1;
105 *----------------------------------------------------------------------
107 static int alreadyRunningError(Display * dpy, XErrorEvent * error)
109 /* Parameter not used, but tell the compiler that it is ok */
110 (void) dpy;
111 (void) error;
113 CantManageScreen = 1;
114 return -1;
118 *----------------------------------------------------------------------
119 * allocButtonPixmaps--
120 * Allocate pixmaps used on window operation buttons (those in the
121 * titlebar). The pixmaps are linked to the program. If XPM is supported
122 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
124 * Returns:
125 * Nothing
127 * Side effects:
128 * Allocates shared pixmaps for the screen. These pixmaps should
129 * not be freed by anybody.
130 *----------------------------------------------------------------------
132 static void allocButtonPixmaps(WScreen * scr)
134 WPixmap *pix;
136 /* create predefined pixmaps */
137 if (wPreferences.new_style == TS_NEXT) {
138 pix = wPixmapCreateFromXPMData(scr, NEXT_CLOSE_XPM);
139 } else {
140 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
142 if (pix)
143 pix->shared = 1;
144 scr->b_pixmaps[WBUT_CLOSE] = pix;
146 if (wPreferences.new_style == TS_NEXT) {
147 pix = wPixmapCreateFromXPMData(scr, NEXT_BROKEN_CLOSE_XPM);
148 } else {
149 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
151 if (pix)
152 pix->shared = 1;
153 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
155 if (wPreferences.new_style == TS_NEXT) {
156 pix = wPixmapCreateFromXPMData(scr, NEXT_ICONIFY_XPM);
157 } else {
158 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
160 if (pix)
161 pix->shared = 1;
162 scr->b_pixmaps[WBUT_ICONIFY] = pix;
163 #ifdef XKB_BUTTON_HINT
164 if (wPreferences.new_style == TS_NEXT) {
165 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP1_XPM);
166 } else {
167 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
169 if (pix)
170 pix->shared = 1;
171 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
172 if (wPreferences.new_style == TS_NEXT) {
173 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP2_XPM);
174 } else {
175 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
177 if (pix)
178 pix->shared = 1;
179 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
180 if (wPreferences.new_style == TS_NEXT) {
181 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP3_XPM);
182 } else {
183 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
185 if (pix)
186 pix->shared = 1;
187 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
188 if (wPreferences.new_style == TS_NEXT) {
189 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP4_XPM);
190 } else {
191 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
193 if (pix)
194 pix->shared = 1;
195 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
196 #endif
198 if (wPreferences.new_style == TS_NEXT) {
199 pix = wPixmapCreateFromXPMData(scr, NEXT_KILL_XPM);
200 } else {
201 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
203 if (pix)
204 pix->shared = 1;
205 scr->b_pixmaps[WBUT_KILL] = pix;
208 static void draw_dot(WScreen * scr, Drawable d, int x, int y, GC gc)
210 XSetForeground(dpy, gc, scr->black_pixel);
211 XDrawLine(dpy, d, gc, x, y, x + 1, y);
212 XDrawPoint(dpy, d, gc, x, y + 1);
213 XSetForeground(dpy, gc, scr->white_pixel);
214 XDrawLine(dpy, d, gc, x + 2, y, x + 2, y + 1);
215 XDrawPoint(dpy, d, gc, x + 1, y + 1);
218 static WPixmap *make3Dots(WScreen * scr)
220 WPixmap *wpix;
221 GC gc2, gc;
222 XGCValues gcv;
223 Pixmap pix, mask;
225 gc = scr->copy_gc;
226 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, scr->w_depth);
227 XSetForeground(dpy, gc, scr->black_pixel);
228 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
229 XSetForeground(dpy, gc, scr->white_pixel);
230 draw_dot(scr, pix, 4, wPreferences.icon_size - 6, gc);
231 draw_dot(scr, pix, 9, wPreferences.icon_size - 6, gc);
232 draw_dot(scr, pix, 14, wPreferences.icon_size - 6, gc);
234 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, 1);
235 gcv.foreground = 0;
236 gcv.graphics_exposures = False;
237 gc2 = XCreateGC(dpy, mask, GCForeground | GCGraphicsExposures, &gcv);
238 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
239 XSetForeground(dpy, gc2, 1);
240 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size - 6, 3, 2);
241 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size - 6, 3, 2);
242 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size - 6, 3, 2);
244 XFreeGC(dpy, gc2);
246 wpix = wPixmapCreate(pix, mask);
247 wpix->shared = 1;
249 return wpix;
252 static void allocGCs(WScreen * scr)
254 XGCValues gcv;
255 XColor color;
256 int gcm;
258 scr->stipple_bitmap = XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH, STIPPLE_HEIGHT);
260 gcv.stipple = scr->stipple_bitmap;
261 gcv.foreground = scr->white_pixel;
262 gcv.fill_style = FillStippled;
263 gcv.graphics_exposures = False;
264 gcm = GCForeground | GCStipple | GCFillStyle | GCGraphicsExposures;
265 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
267 /* selected icon border GCs */
268 gcv.function = GXcopy;
269 gcv.foreground = scr->white_pixel;
270 gcv.background = scr->black_pixel;
271 gcv.line_width = 1;
272 gcv.line_style = LineDoubleDash;
273 gcv.fill_style = FillSolid;
274 gcv.dash_offset = 0;
275 gcv.dashes = 4;
276 gcv.graphics_exposures = False;
278 gcm = GCFunction | GCGraphicsExposures;
279 gcm |= GCForeground | GCBackground;
280 gcm |= GCLineWidth | GCLineStyle;
281 gcm |= GCFillStyle;
282 gcm |= GCDashOffset | GCDashList;
284 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
286 scr->menu_title_color[0] = WMRetainColor(scr->white);
288 /* don't retain scr->black here because we may alter its alpha */
289 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
290 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
292 /* frame GC */
293 wGetColor(scr, DEF_FRAME_COLOR, &color);
294 gcv.function = GXxor;
295 /* this will raise the probability of the XORed color being different
296 * of the original color in PseudoColor when not all color cells are
297 * initialized */
298 if (DefaultVisual(dpy, scr->screen)->class == PseudoColor)
299 gcv.plane_mask = (1 << (scr->depth - 1)) | 1;
300 else
301 gcv.plane_mask = AllPlanes;
302 gcv.foreground = color.pixel;
303 if (gcv.foreground == 0)
304 gcv.foreground = 1;
305 gcv.line_width = DEF_FRAME_THICKNESS;
306 gcv.subwindow_mode = IncludeInferiors;
307 gcv.graphics_exposures = False;
308 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground | GCGraphicsExposures
309 | GCFunction | GCSubwindowMode | GCLineWidth | GCPlaneMask, &gcv);
311 /* line GC */
312 gcv.foreground = color.pixel;
314 if (gcv.foreground == 0)
315 /* XOR:ing with a zero is not going to be of much use, so
316 in that case, we somewhat arbitrarily xor with 17 instead. */
317 gcv.foreground = 17;
319 gcv.function = GXxor;
320 gcv.subwindow_mode = IncludeInferiors;
321 gcv.line_width = 1;
322 gcv.cap_style = CapRound;
323 gcv.graphics_exposures = False;
324 gcm = GCForeground | GCFunction | GCSubwindowMode | GCLineWidth | GCCapStyle | GCGraphicsExposures;
325 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
327 scr->line_pixel = gcv.foreground;
329 /* copy GC */
330 gcv.foreground = scr->white_pixel;
331 gcv.background = scr->black_pixel;
332 gcv.graphics_exposures = False;
333 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCGraphicsExposures, &gcv);
335 /* misc drawing GC */
336 gcv.graphics_exposures = False;
337 gcm = GCGraphicsExposures;
338 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
340 assert(scr->stipple_bitmap != None);
342 /* mono GC */
343 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
346 static void createPixmaps(WScreen * scr)
348 WPixmap *pix;
350 /* load pixmaps */
351 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_RADIO_INDICATOR_XBM_DATA,
352 (char *)MENU_RADIO_INDICATOR_XBM_DATA,
353 MENU_RADIO_INDICATOR_XBM_SIZE,
354 MENU_RADIO_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
355 if (pix != NULL)
356 pix->shared = 1;
357 scr->menu_radio_indicator = pix;
359 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_CHECK_INDICATOR_XBM_DATA,
360 (char *)MENU_CHECK_INDICATOR_XBM_DATA,
361 MENU_CHECK_INDICATOR_XBM_SIZE,
362 MENU_CHECK_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
363 if (pix != NULL)
364 pix->shared = 1;
365 scr->menu_check_indicator = pix;
367 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_MINI_INDICATOR_XBM_DATA,
368 (char *)MENU_MINI_INDICATOR_XBM_DATA,
369 MENU_MINI_INDICATOR_XBM_SIZE,
370 MENU_MINI_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
371 if (pix != NULL)
372 pix->shared = 1;
373 scr->menu_mini_indicator = pix;
375 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_HIDE_INDICATOR_XBM_DATA,
376 (char *)MENU_HIDE_INDICATOR_XBM_DATA,
377 MENU_HIDE_INDICATOR_XBM_SIZE,
378 MENU_HIDE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
379 if (pix != NULL)
380 pix->shared = 1;
381 scr->menu_hide_indicator = pix;
383 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_SHADE_INDICATOR_XBM_DATA,
384 (char *)MENU_SHADE_INDICATOR_XBM_DATA,
385 MENU_SHADE_INDICATOR_XBM_SIZE,
386 MENU_SHADE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
387 if (pix != NULL)
388 pix->shared = 1;
389 scr->menu_shade_indicator = pix;
391 create_logo_image(scr);
393 scr->dock_dots = make3Dots(scr);
395 /* titlebar button pixmaps */
396 allocButtonPixmaps(scr);
399 void create_logo_image(WScreen *scr)
401 RImage *image = get_icon_image(scr, "Logo", "WMPanel", wPreferences.icon_size);
403 if (!image) {
404 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode));
405 } else {
406 WMSetApplicationIconImage(scr->wmscreen, image);
407 RReleaseImage(image);
412 *----------------------------------------------------------------------
413 * createInternalWindows--
414 * Creates some windows used internally by the program. One to
415 * receive input focus when no other window can get it and another
416 * to display window geometry information during window resize/move.
418 * Returns:
419 * Nothing
421 * Side effects:
422 * Windows are created and some colors are allocated for the
423 * window background.
424 *----------------------------------------------------------------------
426 static void createInternalWindows(WScreen * scr)
428 int vmask;
429 XSetWindowAttributes attribs;
431 /* InputOnly window to get the focus when no other window can get it */
432 vmask = CWEventMask | CWOverrideRedirect;
433 attribs.event_mask = KeyPressMask | FocusChangeMask;
434 attribs.override_redirect = True;
435 scr->no_focus_win = XCreateWindow(dpy, scr->root_win, -10, -10, 4, 4, 0, 0,
436 InputOnly, CopyFromParent, vmask, &attribs);
437 XSelectInput(dpy, scr->no_focus_win, KeyPressMask | KeyReleaseMask);
438 XMapWindow(dpy, scr->no_focus_win);
440 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
442 /* shadow window for dock buttons */
443 vmask = CWBorderPixel | CWBackPixmap | CWBackPixel | CWCursor | CWSaveUnder | CWOverrideRedirect;
444 attribs.border_pixel = scr->black_pixel;
445 attribs.save_under = True;
446 attribs.override_redirect = True;
447 attribs.background_pixmap = None;
448 attribs.background_pixel = scr->white_pixel;
449 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
450 vmask |= CWColormap;
451 attribs.colormap = scr->w_colormap;
452 scr->dock_shadow =
453 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
454 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent, scr->w_visual, vmask, &attribs);
456 /* workspace name */
457 vmask = CWBackPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWBorderPixel;
458 attribs.save_under = True;
459 attribs.override_redirect = True;
460 attribs.colormap = scr->w_colormap;
461 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
462 attribs.border_pixel = 0; /* do not care */
463 scr->workspace_name =
464 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
465 CopyFromParent, scr->w_visual, vmask, &attribs);
469 *----------------------------------------------------------------------
470 * wScreenInit--
471 * Initializes the window manager for the given screen and
472 * allocates a WScreen descriptor for it. Many resources are allocated
473 * for the screen and the root window is setup appropriately.
475 * Returns:
476 * The WScreen descriptor for the screen.
478 * Side effects:
479 * Many resources are allocated and the IconSize property is
480 * set on the root window.
481 * The program can be aborted if some fatal error occurs.
483 * TODO: User specifiable visual.
484 *----------------------------------------------------------------------
486 WScreen *wScreenInit(int screen_number)
488 WScreen *scr;
489 XIconSize icon_size[1];
490 RContextAttributes rattr;
491 long event_mask;
492 XErrorHandler oldHandler;
493 int i;
495 scr = wmalloc(sizeof(WScreen));
497 scr->stacking_list = WMCreateTreeBag();
499 /* initialize globals */
500 scr->screen = screen_number;
501 scr->root_win = RootWindow(dpy, screen_number);
502 scr->depth = DefaultDepth(dpy, screen_number);
503 scr->colormap = DefaultColormap(dpy, screen_number);
505 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
506 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
508 wInitXinerama(scr);
510 scr->usableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
511 scr->totalUsableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
513 for (i = 0; i < wXineramaHeads(scr); ++i) {
514 WMRect rect = wGetRectForHead(scr, i);
515 scr->usableArea[i].x1 = scr->totalUsableArea[i].x1 = rect.pos.x;
516 scr->usableArea[i].y1 = scr->totalUsableArea[i].y1 = rect.pos.y;
517 scr->usableArea[i].x2 = scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
518 scr->usableArea[i].y2 = scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
521 scr->fakeGroupLeaders = WMCreateArray(16);
523 CantManageScreen = 0;
524 oldHandler = XSetErrorHandler(alreadyRunningError);
526 event_mask = EVENT_MASK;
528 if (wPreferences.disable_root_mouse) {
529 event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
532 XSelectInput(dpy, scr->root_win, event_mask);
534 #ifdef KEEP_XKB_LOCK_STATUS
535 /* Only GroupLock doesn't work correctly in my system since right-alt
536 * can change mode while holding it too - ]d
538 if (w_global.xext.xkb.supported) {
539 XkbSelectEvents(dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
541 #endif /* KEEP_XKB_LOCK_STATUS */
543 #ifdef USE_RANDR
544 if (w_global.xext.randr.supported)
545 XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
546 #endif
548 XSync(dpy, False);
549 XSetErrorHandler(oldHandler);
551 if (CantManageScreen) {
552 wfree(scr);
553 return NULL;
556 XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]);
558 /* screen descriptor for raster graphic library */
559 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
560 rattr.render_mode = wPreferences.no_dithering ? RBestMatchRendering : RDitheredRendering;
562 /* if the std colormap stuff works ok, this will be ignored */
563 rattr.colors_per_channel = wPreferences.cmap_size;
564 if (rattr.colors_per_channel < 2)
565 rattr.colors_per_channel = 2;
567 /* Use standard colormap */
568 rattr.standard_colormap_mode = RUseStdColormap;
570 if (getWVisualID(screen_number) >= 0) {
571 rattr.flags |= RC_VisualID;
572 rattr.visualid = getWVisualID(screen_number);
575 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
577 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
578 wwarning("%s", RMessageForError(RErrorCode));
580 rattr.flags &= ~RC_StandardColormap;
581 rattr.standard_colormap_mode = RUseStdColormap;
583 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
586 scr->w_win = scr->rcontext->drawable;
587 scr->w_visual = scr->rcontext->visual;
588 scr->w_depth = scr->rcontext->depth;
589 scr->w_colormap = scr->rcontext->cmap;
591 /* create screen descriptor for WINGs */
592 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number, scr->rcontext);
594 if (!scr->wmscreen) {
595 wfatal(_("could not initialize WINGs widget set"));
596 return NULL;
599 scr->black = WMBlackColor(scr->wmscreen);
600 scr->white = WMWhiteColor(scr->wmscreen);
601 scr->gray = WMGrayColor(scr->wmscreen);
602 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
604 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black; */
605 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white; */
606 scr->light_pixel = WMColorPixel(scr->gray);
607 scr->dark_pixel = WMColorPixel(scr->darkGray);
609 /* create GCs with default values */
610 allocGCs(scr);
612 /* for our window manager info notice board. Need to
613 * create before reading the defaults, because it will be used there.
615 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, 0, 0);
617 /* read defaults for this screen */
618 wReadDefaults(scr, w_global.domain.wmaker->dictionary);
621 XColor xcol;
622 /* frame boder color */
623 wGetColor(scr, WMGetColorRGBDescription(scr->frame_border_color), &xcol);
624 scr->frame_border_pixel = xcol.pixel;
625 wGetColor(scr, WMGetColorRGBDescription(scr->frame_focused_border_color), &xcol);
626 scr->frame_focused_border_pixel = xcol.pixel;
627 wGetColor(scr, WMGetColorRGBDescription(scr->frame_selected_border_color), &xcol);
628 scr->frame_selected_border_pixel = xcol.pixel;
631 createInternalWindows(scr);
633 wNETWMInitStuff(scr);
635 /* create initial workspace */
636 wWorkspaceNew(scr);
638 /* create shared pixmaps */
639 createPixmaps(scr);
641 /* set icon sizes we can accept from clients */
642 icon_size[0].min_width = 8;
643 icon_size[0].min_height = 8;
644 icon_size[0].max_width = wPreferences.icon_size - 4;
645 icon_size[0].max_height = wPreferences.icon_size - 4;
646 icon_size[0].width_inc = 1;
647 icon_size[0].height_inc = 1;
648 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
650 /* setup WindowMaker protocols property in the root window */
651 PropSetWMakerProtocols(scr->root_win);
653 /* setup our noticeboard */
654 XChangeProperty(dpy, scr->info_window, w_global.atom.wmaker.noticeboard,
655 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
656 XChangeProperty(dpy, scr->root_win, w_global.atom.wmaker.noticeboard,
657 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
659 #ifdef BALLOON_TEXT
660 /* initialize balloon text stuff */
661 wBalloonInitialize(scr);
662 #endif
664 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
666 scr->tech_draw_font = XLoadQueryFont(dpy, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
667 if (!scr->tech_draw_font)
668 scr->tech_draw_font = XLoadQueryFont(dpy, "fixed");
670 scr->gview = WCreateGeometryView(scr->wmscreen);
671 WMRealizeWidget(scr->gview);
673 wScreenUpdateUsableArea(scr);
675 return scr;
678 void wScreenUpdateUsableArea(WScreen *scr)
681 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
682 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
683 * border.
686 WArea area;
687 int i;
688 unsigned long tmp_area, best_area = 0;
689 unsigned int size = wPreferences.workspace_border_size;
690 unsigned int position = wPreferences.workspace_border_position;
692 for (i = 0; i < wXineramaHeads(scr); ++i) {
693 WMRect rect = wGetRectForHead(scr, i);
694 scr->totalUsableArea[i].x1 = rect.pos.x;
695 scr->totalUsableArea[i].y1 = rect.pos.y;
696 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
697 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
699 if (wNETWMGetUsableArea(scr, i, &area)) {
700 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
701 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
702 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
703 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
706 scr->usableArea[i] = scr->totalUsableArea[i];
708 if (wPreferences.no_window_over_icons) {
709 if (wPreferences.icon_yard & IY_VERT) {
710 if (wPreferences.icon_yard & IY_RIGHT)
711 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
712 else
713 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
714 } else {
715 if (wPreferences.icon_yard & IY_TOP)
716 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
717 else
718 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
722 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width / 2) {
723 scr->totalUsableArea[i].x1 = rect.pos.x;
724 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
727 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height / 2) {
728 scr->totalUsableArea[i].y1 = rect.pos.y;
729 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
732 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
733 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
735 if (tmp_area > best_area) {
736 best_area = tmp_area;
737 area = scr->totalUsableArea[i];
740 if (size > 0 && position != WB_NONE) {
741 if (position & WB_LEFTRIGHT) {
742 scr->totalUsableArea[i].x1 += size;
743 scr->totalUsableArea[i].x2 -= size;
745 if (position & WB_TOPBOTTOM) {
746 scr->totalUsableArea[i].y1 += size;
747 scr->totalUsableArea[i].y2 -= size;
752 if (wPreferences.auto_arrange_icons)
753 wArrangeIcons(scr, True);
756 void wScreenRestoreState(WScreen * scr)
758 WMPropList *state;
759 char *path;
761 OpenRootMenu(scr, -10000, -10000, False);
762 wMenuUnmap(scr->root_menu);
764 make_keys();
766 if (w_global.screen_count == 1) {
767 path = wdefaultspathfordomain("WMState");
768 } else {
769 char buf[16];
770 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
771 path = wdefaultspathfordomain(buf);
774 w_global.session_state = WMReadPropListFromFile(path);
775 wfree(path);
776 if (!w_global.session_state && w_global.screen_count > 1) {
777 path = wdefaultspathfordomain("WMState");
778 w_global.session_state = WMReadPropListFromFile(path);
779 wfree(path);
782 if (!w_global.session_state)
783 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
785 if (!wPreferences.flags.nodock) {
786 state = WMGetFromPLDictionary(w_global.session_state, dDock);
787 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
790 if (!wPreferences.flags.noclip) {
791 state = WMGetFromPLDictionary(w_global.session_state, dClip);
792 w_global.clip.icon = wClipRestoreState(scr, state);
795 if (!wPreferences.flags.nodrawer) {
796 if (!scr->dock->on_right_side) {
797 /* Drawer tile was created early in wScreenInit() -> wReadDefaults(). At
798 * that time, scr->dock was NULL and the tile was created as if we were on
799 * the right side. If we aren't, redo it now. */
800 assert(scr->drawer_tile);
801 RReleaseImage(scr->drawer_tile);
802 scr->drawer_tile = wDrawerMakeTile(scr, scr->icon_tile);
804 wDrawersRestoreState(scr);
807 wWorkspaceRestoreState(scr);
808 wScreenUpdateUsableArea(scr);
811 void wScreenSaveState(WScreen * scr)
813 WWindow *wwin;
814 char *str;
815 WMPropList *old_state, *foo;
817 make_keys();
819 /* save state of windows */
820 wwin = scr->focused_window;
821 while (wwin) {
822 wWindowSaveState(wwin);
823 wwin = wwin->prev;
826 if (wPreferences.flags.noupdates)
827 return;
829 old_state = w_global.session_state;
830 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
832 WMPLSetCaseSensitive(True);
834 /* save dock state to file */
835 if (!wPreferences.flags.nodock) {
836 wDockSaveState(scr, old_state);
837 } else {
838 if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) {
839 WMPutInPLDictionary(w_global.session_state, dDock, foo);
842 if (!wPreferences.flags.noclip) {
843 wClipSaveState();
844 } else {
845 if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) {
846 WMPutInPLDictionary(w_global.session_state, dClip, foo);
850 wWorkspaceSaveState(old_state);
852 if (!wPreferences.flags.nodrawer) {
853 wDrawersSaveState(scr);
854 } else {
855 if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) {
856 WMPutInPLDictionary(w_global.session_state, dDrawers, foo);
861 if (wPreferences.save_session_on_exit) {
862 wSessionSaveState(scr);
863 } else {
864 if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) {
865 WMPutInPLDictionary(w_global.session_state, dApplications, foo);
867 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) {
868 WMPutInPLDictionary(w_global.session_state, dWorkspace, foo);
872 /* clean up */
873 WMPLSetCaseSensitive(False);
875 wMenuSaveState(scr);
877 if (w_global.screen_count == 1) {
878 str = wdefaultspathfordomain("WMState");
879 } else {
880 char buf[16];
881 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
882 str = wdefaultspathfordomain(buf);
884 if (!WMWritePropListToFile(w_global.session_state, str)) {
885 werror(_("could not save session state in %s"), str);
887 wfree(str);
888 WMReleasePropList(old_state);
891 int wScreenBringInside(WScreen * scr, int *x, int *y, int width, int height)
893 int moved = 0;
894 int tol_w, tol_h;
896 * With respect to the head that contains most of the window.
898 int sx1, sy1, sx2, sy2;
900 WMRect rect;
901 int head, flags;
903 rect.pos.x = *x;
904 rect.pos.y = *y;
905 rect.size.width = width;
906 rect.size.height = height;
908 head = wGetRectPlacementInfo(scr, rect, &flags);
909 rect = wGetRectForHead(scr, head);
911 sx1 = rect.pos.x;
912 sy1 = rect.pos.y;
913 sx2 = sx1 + rect.size.width;
914 sy2 = sy1 + rect.size.height;
916 #if 0 /* NOTE: gives funky group movement */
917 if (flags & XFLAG_MULTIPLE) {
919 * since we span multiple heads, pull window totaly inside
921 if (*x < sx1)
922 *x = sx1, moved = 1;
923 else if (*x + width > sx2)
924 *x = sx2 - width, moved = 1;
926 if (*y < sy1)
927 *y = sy1, moved = 1;
928 else if (*y + height > sy2)
929 *y = sy2 - height, moved = 1;
931 return moved;
933 #endif
935 if (width > 20)
936 tol_w = width / 2;
937 else
938 tol_w = 20;
940 if (height > 20)
941 tol_h = height / 2;
942 else
943 tol_h = 20;
945 if (*x + width < sx1 + 10)
946 *x = sx1 - tol_w, moved = 1;
947 else if (*x >= sx2 - 10)
948 *x = sx2 - tol_w - 1, moved = 1;
950 if (*y < sy1 - height + 10)
951 *y = sy1 - tol_h, moved = 1;
952 else if (*y >= sy2 - 10)
953 *y = sy2 - tol_h - 1, moved = 1;
955 return moved;
958 int wScreenKeepInside(WScreen * scr, int *x, int *y, int width, int height)
960 int moved = 0;
961 int sx1, sy1, sx2, sy2;
962 WMRect rect;
963 int head;
965 rect.pos.x = *x;
966 rect.pos.y = *y;
967 rect.size.width = width;
968 rect.size.height = height;
970 head = wGetHeadForRect(scr, rect);
971 rect = wGetRectForHead(scr, head);
973 sx1 = rect.pos.x;
974 sy1 = rect.pos.y;
975 sx2 = sx1 + rect.size.width;
976 sy2 = sy1 + rect.size.height;
978 if (*x < sx1)
979 *x = sx1, moved = 1;
980 else if (*x + width > sx2)
981 *x = sx2 - width, moved = 1;
983 if (*y < sy1)
984 *y = sy1, moved = 1;
985 else if (*y + height > sy2)
986 *y = sy2 - height, moved = 1;
988 return moved;