wmaker: Created an array to hold the maximize menu entries
[wmaker-crm.git] / src / screen.c
blobc7295f336bbd870efb9b9d199ded8dfa47b77642
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 SHAPE
32 #include <X11/extensions/shape.h>
33 #endif
34 #ifdef KEEP_XKB_LOCK_STATUS
35 #include <X11/XKBlib.h>
36 #endif /* KEEP_XKB_LOCK_STATUS */
37 #ifdef HAVE_XRANDR
38 #include <X11/extensions/Xrandr.h>
39 #endif
41 #include <wraster.h>
42 #include "WindowMaker.h"
43 #include "def_pixmaps.h"
44 #include "screen.h"
45 #include "texture.h"
46 #include "pixmap.h"
47 #include "menu.h"
48 #include "window.h"
49 #include "main.h"
50 #include "actions.h"
51 #include "properties.h"
52 #include "dock.h"
53 #include "resources.h"
54 #include "workspace.h"
55 #include "session.h"
56 #include "balloon.h"
57 #include "geomview.h"
58 #include "wmspec.h"
59 #include "rootmenu.h"
61 #include "xinerama.h"
63 #include <WINGs/WUtil.h>
65 #include "defaults.h"
67 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
68 |SubstructureNotifyMask|PointerMotionMask \
69 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
70 |KeyPressMask|KeyReleaseMask)
72 #define STIPPLE_WIDTH 2
73 #define STIPPLE_HEIGHT 2
74 static char STIPPLE_DATA[] = { 0x02, 0x01 };
76 static int CantManageScreen = 0;
78 static WMPropList *dApplications = NULL;
79 static WMPropList *dWorkspace;
80 static WMPropList *dDock;
81 static WMPropList *dClip;
82 static WMPropList *dDrawers = NULL;
84 static void make_keys(void)
86 if (dApplications != NULL)
87 return;
89 dApplications = WMCreatePLString("Applications");
90 dWorkspace = WMCreatePLString("Workspace");
91 dDock = WMCreatePLString("Dock");
92 dClip = WMCreatePLString("Clip");
93 dDrawers = WMCreatePLString("Drawers");
97 *----------------------------------------------------------------------
98 * alreadyRunningError--
99 * X error handler used to catch errors when trying to do
100 * XSelectInput() on the root window. These errors probably mean that
101 * there already is some other window manager running.
103 * Returns:
104 * Nothing, unless something really evil happens...
106 * Side effects:
107 * CantManageScreen is set to 1;
108 *----------------------------------------------------------------------
110 static int alreadyRunningError(Display * dpy, XErrorEvent * error)
112 /* Parameter not used, but tell the compiler that it is ok */
113 (void) dpy;
114 (void) error;
116 CantManageScreen = 1;
117 return -1;
121 *----------------------------------------------------------------------
122 * allocButtonPixmaps--
123 * Allocate pixmaps used on window operation buttons (those in the
124 * titlebar). The pixmaps are linked to the program. If XPM is supported
125 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
127 * Returns:
128 * Nothing
130 * Side effects:
131 * Allocates shared pixmaps for the screen. These pixmaps should
132 * not be freed by anybody.
133 *----------------------------------------------------------------------
135 static void allocButtonPixmaps(WScreen * scr)
137 WPixmap *pix;
139 /* create predefined pixmaps */
140 if (wPreferences.new_style == TS_NEXT) {
141 pix = wPixmapCreateFromXPMData(scr, NEXT_CLOSE_XPM);
142 } else {
143 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
145 if (pix)
146 pix->shared = 1;
147 scr->b_pixmaps[WBUT_CLOSE] = pix;
149 if (wPreferences.new_style == TS_NEXT) {
150 pix = wPixmapCreateFromXPMData(scr, NEXT_BROKEN_CLOSE_XPM);
151 } else {
152 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
154 if (pix)
155 pix->shared = 1;
156 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
158 if (wPreferences.new_style == TS_NEXT) {
159 pix = wPixmapCreateFromXPMData(scr, NEXT_ICONIFY_XPM);
160 } else {
161 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
163 if (pix)
164 pix->shared = 1;
165 scr->b_pixmaps[WBUT_ICONIFY] = pix;
166 #ifdef XKB_BUTTON_HINT
167 if (wPreferences.new_style == TS_NEXT) {
168 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP1_XPM);
169 } else {
170 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
172 if (pix)
173 pix->shared = 1;
174 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
175 if (wPreferences.new_style == TS_NEXT) {
176 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP2_XPM);
177 } else {
178 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
180 if (pix)
181 pix->shared = 1;
182 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
183 if (wPreferences.new_style == TS_NEXT) {
184 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP3_XPM);
185 } else {
186 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
188 if (pix)
189 pix->shared = 1;
190 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
191 if (wPreferences.new_style == TS_NEXT) {
192 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP4_XPM);
193 } else {
194 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
196 if (pix)
197 pix->shared = 1;
198 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
199 #endif
201 if (wPreferences.new_style == TS_NEXT) {
202 pix = wPixmapCreateFromXPMData(scr, NEXT_KILL_XPM);
203 } else {
204 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
206 if (pix)
207 pix->shared = 1;
208 scr->b_pixmaps[WBUT_KILL] = pix;
211 static void draw_dot(WScreen * scr, Drawable d, int x, int y, GC gc)
213 XSetForeground(dpy, gc, scr->black_pixel);
214 XDrawLine(dpy, d, gc, x, y, x + 1, y);
215 XDrawPoint(dpy, d, gc, x, y + 1);
216 XSetForeground(dpy, gc, scr->white_pixel);
217 XDrawLine(dpy, d, gc, x + 2, y, x + 2, y + 1);
218 XDrawPoint(dpy, d, gc, x + 1, y + 1);
221 static WPixmap *make3Dots(WScreen * scr)
223 WPixmap *wpix;
224 GC gc2, gc;
225 XGCValues gcv;
226 Pixmap pix, mask;
228 gc = scr->copy_gc;
229 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, scr->w_depth);
230 XSetForeground(dpy, gc, scr->black_pixel);
231 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
232 XSetForeground(dpy, gc, scr->white_pixel);
233 draw_dot(scr, pix, 4, wPreferences.icon_size - 6, gc);
234 draw_dot(scr, pix, 9, wPreferences.icon_size - 6, gc);
235 draw_dot(scr, pix, 14, wPreferences.icon_size - 6, gc);
237 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, 1);
238 gcv.foreground = 0;
239 gcv.graphics_exposures = False;
240 gc2 = XCreateGC(dpy, mask, GCForeground | GCGraphicsExposures, &gcv);
241 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
242 XSetForeground(dpy, gc2, 1);
243 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size - 6, 3, 2);
244 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size - 6, 3, 2);
245 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size - 6, 3, 2);
247 XFreeGC(dpy, gc2);
249 wpix = wPixmapCreate(pix, mask);
250 wpix->shared = 1;
252 return wpix;
255 static void allocGCs(WScreen * scr)
257 XGCValues gcv;
258 XColor color;
259 int gcm;
261 scr->stipple_bitmap = XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH, STIPPLE_HEIGHT);
263 gcv.stipple = scr->stipple_bitmap;
264 gcv.foreground = scr->white_pixel;
265 gcv.fill_style = FillStippled;
266 gcv.graphics_exposures = False;
267 gcm = GCForeground | GCStipple | GCFillStyle | GCGraphicsExposures;
268 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
270 /* selected icon border GCs */
271 gcv.function = GXcopy;
272 gcv.foreground = scr->white_pixel;
273 gcv.background = scr->black_pixel;
274 gcv.line_width = 1;
275 gcv.line_style = LineDoubleDash;
276 gcv.fill_style = FillSolid;
277 gcv.dash_offset = 0;
278 gcv.dashes = 4;
279 gcv.graphics_exposures = False;
281 gcm = GCFunction | GCGraphicsExposures;
282 gcm |= GCForeground | GCBackground;
283 gcm |= GCLineWidth | GCLineStyle;
284 gcm |= GCFillStyle;
285 gcm |= GCDashOffset | GCDashList;
287 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
289 scr->menu_title_color[0] = WMRetainColor(scr->white);
291 /* don't retain scr->black here because we may alter its alpha */
292 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
293 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
295 /* frame GC */
296 wGetColor(scr, DEF_FRAME_COLOR, &color);
297 gcv.function = GXxor;
298 /* this will raise the probability of the XORed color being different
299 * of the original color in PseudoColor when not all color cells are
300 * initialized */
301 if (DefaultVisual(dpy, scr->screen)->class == PseudoColor)
302 gcv.plane_mask = (1 << (scr->depth - 1)) | 1;
303 else
304 gcv.plane_mask = AllPlanes;
305 gcv.foreground = color.pixel;
306 if (gcv.foreground == 0)
307 gcv.foreground = 1;
308 gcv.line_width = DEF_FRAME_THICKNESS;
309 gcv.subwindow_mode = IncludeInferiors;
310 gcv.graphics_exposures = False;
311 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground | GCGraphicsExposures
312 | GCFunction | GCSubwindowMode | GCLineWidth | GCPlaneMask, &gcv);
314 /* line GC */
315 gcv.foreground = color.pixel;
317 if (gcv.foreground == 0)
318 /* XOR:ing with a zero is not going to be of much use, so
319 in that case, we somewhat arbitrarily xor with 17 instead. */
320 gcv.foreground = 17;
322 gcv.function = GXxor;
323 gcv.subwindow_mode = IncludeInferiors;
324 gcv.line_width = 1;
325 gcv.cap_style = CapRound;
326 gcv.graphics_exposures = False;
327 gcm = GCForeground | GCFunction | GCSubwindowMode | GCLineWidth | GCCapStyle | GCGraphicsExposures;
328 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
330 scr->line_pixel = gcv.foreground;
332 /* copy GC */
333 gcv.foreground = scr->white_pixel;
334 gcv.background = scr->black_pixel;
335 gcv.graphics_exposures = False;
336 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCGraphicsExposures, &gcv);
338 /* misc drawing GC */
339 gcv.graphics_exposures = False;
340 gcm = GCGraphicsExposures;
341 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
343 assert(scr->stipple_bitmap != None);
345 /* mono GC */
346 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
349 static void createPixmaps(WScreen * scr)
351 WPixmap *pix;
353 /* load pixmaps */
354 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_RADIO_INDICATOR_XBM_DATA,
355 (char *)MENU_RADIO_INDICATOR_XBM_DATA,
356 MENU_RADIO_INDICATOR_XBM_SIZE,
357 MENU_RADIO_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
358 if (pix != NULL)
359 pix->shared = 1;
360 scr->menu_radio_indicator = pix;
362 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_CHECK_INDICATOR_XBM_DATA,
363 (char *)MENU_CHECK_INDICATOR_XBM_DATA,
364 MENU_CHECK_INDICATOR_XBM_SIZE,
365 MENU_CHECK_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
366 if (pix != NULL)
367 pix->shared = 1;
368 scr->menu_check_indicator = pix;
370 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_MINI_INDICATOR_XBM_DATA,
371 (char *)MENU_MINI_INDICATOR_XBM_DATA,
372 MENU_MINI_INDICATOR_XBM_SIZE,
373 MENU_MINI_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
374 if (pix != NULL)
375 pix->shared = 1;
376 scr->menu_mini_indicator = pix;
378 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_HIDE_INDICATOR_XBM_DATA,
379 (char *)MENU_HIDE_INDICATOR_XBM_DATA,
380 MENU_HIDE_INDICATOR_XBM_SIZE,
381 MENU_HIDE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
382 if (pix != NULL)
383 pix->shared = 1;
384 scr->menu_hide_indicator = pix;
386 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_SHADE_INDICATOR_XBM_DATA,
387 (char *)MENU_SHADE_INDICATOR_XBM_DATA,
388 MENU_SHADE_INDICATOR_XBM_SIZE,
389 MENU_SHADE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
390 if (pix != NULL)
391 pix->shared = 1;
392 scr->menu_shade_indicator = pix;
394 create_logo_image(scr);
396 scr->dock_dots = make3Dots(scr);
398 /* titlebar button pixmaps */
399 allocButtonPixmaps(scr);
402 void create_logo_image(WScreen *scr)
404 RImage *image = get_icon_image(scr, "Logo", "WMPanel", wPreferences.icon_size);
406 if (!image) {
407 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode));
408 } else {
409 WMSetApplicationIconImage(scr->wmscreen, image);
410 RReleaseImage(image);
415 *----------------------------------------------------------------------
416 * createInternalWindows--
417 * Creates some windows used internally by the program. One to
418 * receive input focus when no other window can get it and another
419 * to display window geometry information during window resize/move.
421 * Returns:
422 * Nothing
424 * Side effects:
425 * Windows are created and some colors are allocated for the
426 * window background.
427 *----------------------------------------------------------------------
429 static void createInternalWindows(WScreen * scr)
431 int vmask;
432 XSetWindowAttributes attribs;
434 /* InputOnly window to get the focus when no other window can get it */
435 vmask = CWEventMask | CWOverrideRedirect;
436 attribs.event_mask = KeyPressMask | FocusChangeMask;
437 attribs.override_redirect = True;
438 scr->no_focus_win = XCreateWindow(dpy, scr->root_win, -10, -10, 4, 4, 0, 0,
439 InputOnly, CopyFromParent, vmask, &attribs);
440 XSelectInput(dpy, scr->no_focus_win, KeyPressMask | KeyReleaseMask);
441 XMapWindow(dpy, scr->no_focus_win);
443 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
445 /* shadow window for dock buttons */
446 vmask = CWBorderPixel | CWBackPixmap | CWBackPixel | CWCursor | CWSaveUnder | CWOverrideRedirect;
447 attribs.border_pixel = scr->black_pixel;
448 attribs.save_under = True;
449 attribs.override_redirect = True;
450 attribs.background_pixmap = None;
451 attribs.background_pixel = scr->white_pixel;
452 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
453 vmask |= CWColormap;
454 attribs.colormap = scr->w_colormap;
455 scr->dock_shadow =
456 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
457 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent, scr->w_visual, vmask, &attribs);
459 /* workspace name */
460 vmask = CWBackPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWBorderPixel;
461 attribs.save_under = True;
462 attribs.override_redirect = True;
463 attribs.colormap = scr->w_colormap;
464 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
465 attribs.border_pixel = 0; /* do not care */
466 scr->workspace_name =
467 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
468 CopyFromParent, scr->w_visual, vmask, &attribs);
472 *----------------------------------------------------------------------
473 * wScreenInit--
474 * Initializes the window manager for the given screen and
475 * allocates a WScreen descriptor for it. Many resources are allocated
476 * for the screen and the root window is setup appropriately.
478 * Returns:
479 * The WScreen descriptor for the screen.
481 * Side effects:
482 * Many resources are allocated and the IconSize property is
483 * set on the root window.
484 * The program can be aborted if some fatal error occurs.
486 * TODO: User specifiable visual.
487 *----------------------------------------------------------------------
489 WScreen *wScreenInit(int screen_number)
491 WScreen *scr;
492 XIconSize icon_size[1];
493 RContextAttributes rattr;
494 long event_mask;
495 XErrorHandler oldHandler;
496 int i;
498 scr = wmalloc(sizeof(WScreen));
500 scr->stacking_list = WMCreateTreeBag();
502 /* initialize globals */
503 scr->screen = screen_number;
504 scr->root_win = RootWindow(dpy, screen_number);
505 scr->depth = DefaultDepth(dpy, screen_number);
506 scr->colormap = DefaultColormap(dpy, screen_number);
508 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
509 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
511 wInitXinerama(scr);
513 scr->usableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
514 scr->totalUsableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
516 for (i = 0; i < wXineramaHeads(scr); ++i) {
517 WMRect rect = wGetRectForHead(scr, i);
518 scr->usableArea[i].x1 = scr->totalUsableArea[i].x1 = rect.pos.x;
519 scr->usableArea[i].y1 = scr->totalUsableArea[i].y1 = rect.pos.y;
520 scr->usableArea[i].x2 = scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
521 scr->usableArea[i].y2 = scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
524 scr->fakeGroupLeaders = WMCreateArray(16);
526 CantManageScreen = 0;
527 oldHandler = XSetErrorHandler(alreadyRunningError);
529 event_mask = EVENT_MASK;
531 if (wPreferences.disable_root_mouse) {
532 event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
535 XSelectInput(dpy, scr->root_win, event_mask);
537 #ifdef KEEP_XKB_LOCK_STATUS
538 /* Only GroupLock doesn't work correctly in my system since right-alt
539 * can change mode while holding it too - ]d
541 if (w_global.xext.xkb.supported) {
542 XkbSelectEvents(dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
544 #endif /* KEEP_XKB_LOCK_STATUS */
546 #ifdef HAVE_XRANDR
547 if (w_global.xext.randr.supported)
548 XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
549 #endif
551 XSync(dpy, False);
552 XSetErrorHandler(oldHandler);
554 if (CantManageScreen) {
555 wfree(scr);
556 return NULL;
559 XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]);
561 /* screen descriptor for raster graphic library */
562 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
563 rattr.render_mode = wPreferences.no_dithering ? RBestMatchRendering : RDitheredRendering;
565 /* if the std colormap stuff works ok, this will be ignored */
566 rattr.colors_per_channel = wPreferences.cmap_size;
567 if (rattr.colors_per_channel < 2)
568 rattr.colors_per_channel = 2;
570 /* Use standard colormap */
571 rattr.standard_colormap_mode = RUseStdColormap;
573 if (getWVisualID(screen_number) >= 0) {
574 rattr.flags |= RC_VisualID;
575 rattr.visualid = getWVisualID(screen_number);
578 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
580 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
581 wwarning("%s", RMessageForError(RErrorCode));
583 rattr.flags &= ~RC_StandardColormap;
584 rattr.standard_colormap_mode = RUseStdColormap;
586 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
589 scr->w_win = scr->rcontext->drawable;
590 scr->w_visual = scr->rcontext->visual;
591 scr->w_depth = scr->rcontext->depth;
592 scr->w_colormap = scr->rcontext->cmap;
594 /* create screen descriptor for WINGs */
595 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number, scr->rcontext);
597 if (!scr->wmscreen) {
598 wfatal(_("could not initialize WINGs widget set"));
599 return NULL;
602 scr->black = WMBlackColor(scr->wmscreen);
603 scr->white = WMWhiteColor(scr->wmscreen);
604 scr->gray = WMGrayColor(scr->wmscreen);
605 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
607 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black; */
608 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white; */
609 scr->light_pixel = WMColorPixel(scr->gray);
610 scr->dark_pixel = WMColorPixel(scr->darkGray);
612 /* create GCs with default values */
613 allocGCs(scr);
615 /* for our window manager info notice board. Need to
616 * create before reading the defaults, because it will be used there.
618 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, 0, 0);
620 /* read defaults for this screen */
621 wReadDefaults(scr, w_global.domain.wmaker->dictionary);
624 XColor xcol;
625 /* frame boder color */
626 wGetColor(scr, WMGetColorRGBDescription(scr->frame_border_color), &xcol);
627 scr->frame_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, dock_head;
689 unsigned long best_area, tmp_area;
690 unsigned int size, position;
692 dock_head = scr->xine_info.primary_head;
693 best_area = 0;
694 size = wPreferences.workspace_border_size;
695 position = wPreferences.workspace_border_position;
697 if (scr->dock) {
698 WMRect rect;
699 rect.pos.x = scr->dock->x_pos;
700 rect.pos.y = scr->dock->y_pos;
701 rect.size.width = wPreferences.icon_size;
702 rect.size.height = wPreferences.icon_size;
703 dock_head = wGetHeadForRect(scr, rect);
706 for (i = 0; i < wXineramaHeads(scr); ++i) {
707 WMRect rect = wGetRectForHead(scr, i);
708 scr->totalUsableArea[i].x1 = rect.pos.x;
709 scr->totalUsableArea[i].y1 = rect.pos.y;
710 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
711 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
713 if (scr->dock && dock_head == i && (!scr->dock->lowered || wPreferences.no_window_over_dock)) {
714 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
716 if (scr->dock->on_right_side) {
717 scr->totalUsableArea[i].x2 -= offset;
718 } else {
719 scr->totalUsableArea[i].x1 += offset;
723 if (wNETWMGetUsableArea(scr, i, &area)) {
724 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
725 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
726 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
727 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
730 scr->usableArea[i] = scr->totalUsableArea[i];
732 #if 0
733 printf("usableArea[%d]: %d %d %d %d\n", i,
734 scr->usableArea[i].x1, scr->usableArea[i].x2, scr->usableArea[i].y1, scr->usableArea[i].y2);
735 #endif
736 if (wPreferences.no_window_over_icons) {
737 if (wPreferences.icon_yard & IY_VERT) {
738 if (wPreferences.icon_yard & IY_RIGHT) {
739 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
740 } else {
741 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
743 } else {
744 if (wPreferences.icon_yard & IY_TOP) {
745 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
746 } else {
747 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
752 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width / 2) {
753 scr->totalUsableArea[i].x1 = rect.pos.x;
754 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
757 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height / 2) {
758 scr->totalUsableArea[i].y1 = rect.pos.y;
759 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
762 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
763 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
765 if (tmp_area > best_area) {
766 best_area = tmp_area;
767 area = scr->totalUsableArea[i];
770 if (size > 0 && position != WB_NONE) {
771 if (position & WB_LEFTRIGHT) {
772 scr->totalUsableArea[i].x1 += size;
773 scr->totalUsableArea[i].x2 -= size;
775 if (position & WB_TOPBOTTOM) {
776 scr->totalUsableArea[i].y1 += size;
777 scr->totalUsableArea[i].y2 -= size;
782 if (wPreferences.auto_arrange_icons)
783 wArrangeIcons(scr, True);
786 void wScreenRestoreState(WScreen * scr)
788 WMPropList *state;
789 char *path;
791 OpenRootMenu(scr, -10000, -10000, False);
792 wMenuUnmap(scr->root_menu);
794 make_keys();
796 if (w_global.screen_count == 1) {
797 path = wdefaultspathfordomain("WMState");
798 } else {
799 char buf[16];
800 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
801 path = wdefaultspathfordomain(buf);
804 w_global.session_state = WMReadPropListFromFile(path);
805 wfree(path);
806 if (!w_global.session_state && w_global.screen_count > 1) {
807 path = wdefaultspathfordomain("WMState");
808 w_global.session_state = WMReadPropListFromFile(path);
809 wfree(path);
812 if (!w_global.session_state)
813 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
815 if (!wPreferences.flags.nodock) {
816 state = WMGetFromPLDictionary(w_global.session_state, dDock);
817 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
820 if (!wPreferences.flags.noclip) {
821 state = WMGetFromPLDictionary(w_global.session_state, dClip);
822 w_global.clip.icon = wClipRestoreState(scr, state);
825 if (!wPreferences.flags.nodrawer) {
826 if (!scr->dock->on_right_side) {
827 /* Drawer tile was created early in wScreenInit() -> wReadDefaults(). At
828 * that time, scr->dock was NULL and the tile was created as if we were on
829 * the right side. If we aren't, redo it now. */
830 assert(scr->drawer_tile);
831 RReleaseImage(scr->drawer_tile);
832 scr->drawer_tile = wDrawerMakeTile(scr, scr->icon_tile);
834 wDrawersRestoreState(scr);
837 wWorkspaceRestoreState(scr);
838 wScreenUpdateUsableArea(scr);
841 void wScreenSaveState(WScreen * scr)
843 WWindow *wwin;
844 char *str;
845 WMPropList *old_state, *foo;
847 make_keys();
849 /* save state of windows */
850 wwin = scr->focused_window;
851 while (wwin) {
852 wWindowSaveState(wwin);
853 wwin = wwin->prev;
856 if (wPreferences.flags.noupdates)
857 return;
859 old_state = w_global.session_state;
860 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
862 WMPLSetCaseSensitive(True);
864 /* save dock state to file */
865 if (!wPreferences.flags.nodock) {
866 wDockSaveState(scr, old_state);
867 } else {
868 if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) {
869 WMPutInPLDictionary(w_global.session_state, dDock, foo);
872 if (!wPreferences.flags.noclip) {
873 wClipSaveState();
874 } else {
875 if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) {
876 WMPutInPLDictionary(w_global.session_state, dClip, foo);
880 wWorkspaceSaveState(old_state);
882 if (!wPreferences.flags.nodrawer) {
883 wDrawersSaveState(scr);
884 } else {
885 if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) {
886 WMPutInPLDictionary(w_global.session_state, dDrawers, foo);
891 if (wPreferences.save_session_on_exit) {
892 wSessionSaveState(scr);
893 } else {
894 if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) {
895 WMPutInPLDictionary(w_global.session_state, dApplications, foo);
897 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) {
898 WMPutInPLDictionary(w_global.session_state, dWorkspace, foo);
902 /* clean up */
903 WMPLSetCaseSensitive(False);
905 wMenuSaveState(scr);
907 if (w_global.screen_count == 1) {
908 str = wdefaultspathfordomain("WMState");
909 } else {
910 char buf[16];
911 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
912 str = wdefaultspathfordomain(buf);
914 if (!WMWritePropListToFile(w_global.session_state, str)) {
915 werror(_("could not save session state in %s"), str);
917 wfree(str);
918 WMReleasePropList(old_state);
921 int wScreenBringInside(WScreen * scr, int *x, int *y, int width, int height)
923 int moved = 0;
924 int tol_w, tol_h;
926 * With respect to the head that contains most of the window.
928 int sx1, sy1, sx2, sy2;
930 WMRect rect;
931 int head, flags;
933 rect.pos.x = *x;
934 rect.pos.y = *y;
935 rect.size.width = width;
936 rect.size.height = height;
938 head = wGetRectPlacementInfo(scr, rect, &flags);
939 rect = wGetRectForHead(scr, head);
941 sx1 = rect.pos.x;
942 sy1 = rect.pos.y;
943 sx2 = sx1 + rect.size.width;
944 sy2 = sy1 + rect.size.height;
946 #if 0 /* NOTE: gives funky group movement */
947 if (flags & XFLAG_MULTIPLE) {
949 * since we span multiple heads, pull window totaly inside
951 if (*x < sx1)
952 *x = sx1, moved = 1;
953 else if (*x + width > sx2)
954 *x = sx2 - width, moved = 1;
956 if (*y < sy1)
957 *y = sy1, moved = 1;
958 else if (*y + height > sy2)
959 *y = sy2 - height, moved = 1;
961 return moved;
963 #endif
965 if (width > 20)
966 tol_w = width / 2;
967 else
968 tol_w = 20;
970 if (height > 20)
971 tol_h = height / 2;
972 else
973 tol_h = 20;
975 if (*x + width < sx1 + 10)
976 *x = sx1 - tol_w, moved = 1;
977 else if (*x >= sx2 - 10)
978 *x = sx2 - tol_w - 1, moved = 1;
980 if (*y < sy1 - height + 10)
981 *y = sy1 - tol_h, moved = 1;
982 else if (*y >= sy2 - 10)
983 *y = sy2 - tol_h - 1, moved = 1;
985 return moved;
988 int wScreenKeepInside(WScreen * scr, int *x, int *y, int width, int height)
990 int moved = 0;
991 int sx1, sy1, sx2, sy2;
992 WMRect rect;
993 int head;
995 rect.pos.x = *x;
996 rect.pos.y = *y;
997 rect.size.width = width;
998 rect.size.height = height;
1000 head = wGetHeadForRect(scr, rect);
1001 rect = wGetRectForHead(scr, head);
1003 sx1 = rect.pos.x;
1004 sy1 = rect.pos.y;
1005 sx2 = sx1 + rect.size.width;
1006 sy2 = sy1 + rect.size.height;
1008 if (*x < sx1)
1009 *x = sx1, moved = 1;
1010 else if (*x + width > sx2)
1011 *x = sx2 - width, moved = 1;
1013 if (*y < sy1)
1014 *y = sy1, moved = 1;
1015 else if (*y + height > sy2)
1016 *y = sy2 - height, moved = 1;
1018 return moved;