wmaker: Remove dead links from BUGFORM.
[wmaker-crm.git] / src / screen.c
blobda578c252d81e939c2d5b5e5a3e5abcb4685791d
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", 128);
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;
527 XSelectInput(dpy, scr->root_win, event_mask);
529 #ifdef KEEP_XKB_LOCK_STATUS
530 /* Only GroupLock doesn't work correctly in my system since right-alt
531 * can change mode while holding it too - ]d
533 if (w_global.xext.xkb.supported) {
534 XkbSelectEvents(dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
536 #endif /* KEEP_XKB_LOCK_STATUS */
538 #ifdef USE_RANDR
539 if (w_global.xext.randr.supported)
540 XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
541 #endif
543 XSync(dpy, False);
544 XSetErrorHandler(oldHandler);
546 if (CantManageScreen) {
547 wfree(scr);
548 return NULL;
551 XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]);
553 /* screen descriptor for raster graphic library */
554 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
555 rattr.render_mode = wPreferences.no_dithering ? RBestMatchRendering : RDitheredRendering;
557 /* if the std colormap stuff works ok, this will be ignored */
558 rattr.colors_per_channel = wPreferences.cmap_size;
559 if (rattr.colors_per_channel < 2)
560 rattr.colors_per_channel = 2;
562 /* Use standard colormap */
563 rattr.standard_colormap_mode = RUseStdColormap;
565 if (getWVisualID(screen_number) >= 0) {
566 rattr.flags |= RC_VisualID;
567 rattr.visualid = getWVisualID(screen_number);
570 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
572 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
573 wwarning("%s", RMessageForError(RErrorCode));
575 rattr.flags &= ~RC_StandardColormap;
576 rattr.standard_colormap_mode = RUseStdColormap;
578 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
581 scr->w_win = scr->rcontext->drawable;
582 scr->w_visual = scr->rcontext->visual;
583 scr->w_depth = scr->rcontext->depth;
584 scr->w_colormap = scr->rcontext->cmap;
586 /* create screen descriptor for WINGs */
587 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number, scr->rcontext);
589 if (!scr->wmscreen) {
590 wfatal(_("could not initialize WINGs widget set"));
591 RDestroyContext(scr->rcontext);
592 WMFreeArray(scr->fakeGroupLeaders);
593 wfree(scr->totalUsableArea);
594 wfree(scr->usableArea);
595 WMFreeBag(scr->stacking_list);
596 wfree(scr);
597 return NULL;
600 scr->black = WMBlackColor(scr->wmscreen);
601 scr->white = WMWhiteColor(scr->wmscreen);
602 scr->gray = WMGrayColor(scr->wmscreen);
603 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
605 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black; */
606 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white; */
607 scr->light_pixel = WMColorPixel(scr->gray);
608 scr->dark_pixel = WMColorPixel(scr->darkGray);
610 /* create GCs with default values */
611 allocGCs(scr);
613 /* for our window manager info notice board. Need to
614 * create before reading the defaults, because it will be used there.
616 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, 0, 0);
618 /* read defaults for this screen */
619 wReadDefaults(scr, w_global.domain.wmaker->dictionary);
622 XColor xcol;
623 /* frame boder color */
624 wGetColor(scr, WMGetColorRGBDescription(scr->frame_border_color), &xcol);
625 scr->frame_border_pixel = xcol.pixel;
626 wGetColor(scr, WMGetColorRGBDescription(scr->frame_focused_border_color), &xcol);
627 scr->frame_focused_border_pixel = xcol.pixel;
628 wGetColor(scr, WMGetColorRGBDescription(scr->frame_selected_border_color), &xcol);
629 scr->frame_selected_border_pixel = xcol.pixel;
632 createInternalWindows(scr);
634 wNETWMInitStuff(scr);
636 /* create initial workspace */
637 wWorkspaceNew(scr);
639 /* create shared pixmaps */
640 createPixmaps(scr);
642 /* set icon sizes we can accept from clients */
643 icon_size[0].min_width = 8;
644 icon_size[0].min_height = 8;
645 icon_size[0].max_width = wPreferences.icon_size - 4;
646 icon_size[0].max_height = wPreferences.icon_size - 4;
647 icon_size[0].width_inc = 1;
648 icon_size[0].height_inc = 1;
649 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
651 /* setup WindowMaker protocols property in the root window */
652 PropSetWMakerProtocols(scr->root_win);
654 /* setup our noticeboard */
655 XChangeProperty(dpy, scr->info_window, w_global.atom.wmaker.noticeboard,
656 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
657 XChangeProperty(dpy, scr->root_win, w_global.atom.wmaker.noticeboard,
658 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
660 #ifdef BALLOON_TEXT
661 /* initialize balloon text stuff */
662 wBalloonInitialize(scr);
663 #endif
665 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
667 scr->tech_draw_font = XLoadQueryFont(dpy, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
668 if (!scr->tech_draw_font)
669 scr->tech_draw_font = XLoadQueryFont(dpy, "fixed");
671 scr->gview = WCreateGeometryView(scr->wmscreen);
672 WMRealizeWidget(scr->gview);
674 wScreenUpdateUsableArea(scr);
676 return scr;
679 void wScreenUpdateUsableArea(WScreen *scr)
682 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
683 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
684 * border.
687 WArea area;
688 int i;
689 unsigned long tmp_area, best_area = 0;
690 unsigned int size = wPreferences.workspace_border_size;
691 unsigned int position = wPreferences.workspace_border_position;
693 for (i = 0; i < wXineramaHeads(scr); ++i) {
694 WMRect rect = wGetRectForHead(scr, i);
695 scr->totalUsableArea[i].x1 = rect.pos.x;
696 scr->totalUsableArea[i].y1 = rect.pos.y;
697 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
698 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
700 if (wNETWMGetUsableArea(scr, i, &area)) {
701 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
702 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
703 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
704 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
707 scr->usableArea[i] = scr->totalUsableArea[i];
709 if (wPreferences.no_window_over_icons) {
710 if (wPreferences.icon_yard & IY_VERT) {
711 if (wPreferences.icon_yard & IY_RIGHT)
712 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
713 else
714 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
715 } else {
716 if (wPreferences.icon_yard & IY_TOP)
717 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
718 else
719 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
723 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width / 2) {
724 scr->totalUsableArea[i].x1 = rect.pos.x;
725 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
728 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height / 2) {
729 scr->totalUsableArea[i].y1 = rect.pos.y;
730 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
733 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
734 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
736 if (tmp_area > best_area) {
737 best_area = tmp_area;
738 area = scr->totalUsableArea[i];
741 if (size > 0 && position != WB_NONE) {
742 if (position & WB_LEFTRIGHT) {
743 scr->totalUsableArea[i].x1 += size;
744 scr->totalUsableArea[i].x2 -= size;
746 if (position & WB_TOPBOTTOM) {
747 scr->totalUsableArea[i].y1 += size;
748 scr->totalUsableArea[i].y2 -= size;
753 if (wPreferences.auto_arrange_icons)
754 wArrangeIcons(scr, True);
757 void wScreenRestoreState(WScreen * scr)
759 WMPropList *state;
760 char *path;
762 OpenRootMenu(scr, -10000, -10000, False);
763 wMenuUnmap(scr->root_menu);
765 make_keys();
767 if (w_global.screen_count == 1) {
768 path = wdefaultspathfordomain("WMState");
769 } else {
770 char buf[16];
771 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
772 path = wdefaultspathfordomain(buf);
775 w_global.session_state = WMReadPropListFromFile(path);
776 wfree(path);
777 if (!w_global.session_state && w_global.screen_count > 1) {
778 path = wdefaultspathfordomain("WMState");
779 w_global.session_state = WMReadPropListFromFile(path);
780 wfree(path);
783 if (!w_global.session_state)
784 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
786 if (!wPreferences.flags.nodock) {
787 state = WMGetFromPLDictionary(w_global.session_state, dDock);
788 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
791 if (!wPreferences.flags.noclip) {
792 state = WMGetFromPLDictionary(w_global.session_state, dClip);
793 w_global.clip.icon = wClipRestoreState(scr, state);
796 if (!wPreferences.flags.nodrawer) {
797 if (!scr->dock->on_right_side) {
798 /* Drawer tile was created early in wScreenInit() -> wReadDefaults(). At
799 * that time, scr->dock was NULL and the tile was created as if we were on
800 * the right side. If we aren't, redo it now. */
801 assert(scr->drawer_tile);
802 RReleaseImage(scr->drawer_tile);
803 scr->drawer_tile = wDrawerMakeTile(scr, scr->icon_tile);
805 wDrawersRestoreState(scr);
808 wWorkspaceRestoreState(scr);
809 wScreenUpdateUsableArea(scr);
812 void wScreenSaveState(WScreen * scr)
814 WWindow *wwin;
815 char *str;
816 WMPropList *old_state, *foo;
818 make_keys();
820 /* save state of windows */
821 wwin = scr->focused_window;
822 while (wwin) {
823 wWindowSaveState(wwin);
824 wwin = wwin->prev;
827 if (wPreferences.flags.noupdates)
828 return;
830 old_state = w_global.session_state;
831 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
833 WMPLSetCaseSensitive(True);
835 /* save dock state to file */
836 if (!wPreferences.flags.nodock) {
837 wDockSaveState(scr, old_state);
838 } else {
839 if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) {
840 WMPutInPLDictionary(w_global.session_state, dDock, foo);
843 if (!wPreferences.flags.noclip) {
844 wClipSaveState();
845 } else {
846 if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) {
847 WMPutInPLDictionary(w_global.session_state, dClip, foo);
851 wWorkspaceSaveState(old_state);
853 if (!wPreferences.flags.nodrawer) {
854 wDrawersSaveState(scr);
855 } else {
856 if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) {
857 WMPutInPLDictionary(w_global.session_state, dDrawers, foo);
862 if (wPreferences.save_session_on_exit) {
863 wSessionSaveState(scr);
864 } else {
865 if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) {
866 WMPutInPLDictionary(w_global.session_state, dApplications, foo);
868 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) {
869 WMPutInPLDictionary(w_global.session_state, dWorkspace, foo);
873 /* clean up */
874 WMPLSetCaseSensitive(False);
876 wMenuSaveState(scr);
878 if (w_global.screen_count == 1) {
879 str = wdefaultspathfordomain("WMState");
880 } else {
881 char buf[16];
882 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
883 str = wdefaultspathfordomain(buf);
885 if (!WMWritePropListToFile(w_global.session_state, str)) {
886 werror(_("could not save session state in %s"), str);
888 wfree(str);
889 WMReleasePropList(old_state);
892 int wScreenBringInside(WScreen * scr, int *x, int *y, int width, int height)
894 int moved = 0;
895 int tol_w, tol_h;
897 * With respect to the head that contains most of the window.
899 int sx1, sy1, sx2, sy2;
901 WMRect rect;
902 int head, flags;
904 rect.pos.x = *x;
905 rect.pos.y = *y;
906 rect.size.width = width;
907 rect.size.height = height;
909 head = wGetRectPlacementInfo(scr, rect, &flags);
910 rect = wGetRectForHead(scr, head);
912 sx1 = rect.pos.x;
913 sy1 = rect.pos.y;
914 sx2 = sx1 + rect.size.width;
915 sy2 = sy1 + rect.size.height;
917 #if 0 /* NOTE: gives funky group movement */
918 if (flags & XFLAG_MULTIPLE) {
920 * since we span multiple heads, pull window totaly inside
922 if (*x < sx1)
923 *x = sx1, moved = 1;
924 else if (*x + width > sx2)
925 *x = sx2 - width, moved = 1;
927 if (*y < sy1)
928 *y = sy1, moved = 1;
929 else if (*y + height > sy2)
930 *y = sy2 - height, moved = 1;
932 return moved;
934 #endif
936 if (width > 20)
937 tol_w = width / 2;
938 else
939 tol_w = 20;
941 if (height > 20)
942 tol_h = height / 2;
943 else
944 tol_h = 20;
946 if (*x + width < sx1 + 10)
947 *x = sx1 - tol_w, moved = 1;
948 else if (*x >= sx2 - 10)
949 *x = sx2 - tol_w - 1, moved = 1;
951 if (*y < sy1 - height + 10)
952 *y = sy1 - tol_h, moved = 1;
953 else if (*y >= sy2 - 10)
954 *y = sy2 - tol_h - 1, moved = 1;
956 return moved;
959 int wScreenKeepInside(WScreen * scr, int *x, int *y, int width, int height)
961 int moved = 0;
962 int sx1, sy1, sx2, sy2;
963 WMRect rect;
964 int head;
966 rect.pos.x = *x;
967 rect.pos.y = *y;
968 rect.size.width = width;
969 rect.size.height = height;
971 head = wGetHeadForRect(scr, rect);
972 rect = wGetRectForHead(scr, head);
974 sx1 = rect.pos.x;
975 sy1 = rect.pos.y;
976 sx2 = sx1 + rect.size.width;
977 sy2 = sy1 + rect.size.height;
979 if (*x < sx1)
980 *x = sx1, moved = 1;
981 else if (*x + width > sx2)
982 *x = sx2 - width, moved = 1;
984 if (*y < sy1)
985 *y = sy1, moved = 1;
986 else if (*y + height > sy2)
987 *y = sy2 - height, moved = 1;
989 return moved;