Removed unused WScreen argument in Pixmap function
[wmaker-crm.git] / src / screen.c
blob715894e29bb6c393c1ce565ccb0eb1f333c77962
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 CantManageScreen = 1;
113 return -1;
117 *----------------------------------------------------------------------
118 * allocButtonPixmaps--
119 * Allocate pixmaps used on window operation buttons (those in the
120 * titlebar). The pixmaps are linked to the program. If XPM is supported
121 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
123 * Returns:
124 * Nothing
126 * Side effects:
127 * Allocates shared pixmaps for the screen. These pixmaps should
128 * not be freed by anybody.
129 *----------------------------------------------------------------------
131 static void allocButtonPixmaps(WScreen * scr)
133 WPixmap *pix;
135 /* create predefined pixmaps */
136 if (wPreferences.new_style == TS_NEXT) {
137 pix = wPixmapCreateFromXPMData(scr, NEXT_CLOSE_XPM);
138 } else {
139 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
141 if (pix)
142 pix->shared = 1;
143 scr->b_pixmaps[WBUT_CLOSE] = pix;
145 if (wPreferences.new_style == TS_NEXT) {
146 pix = wPixmapCreateFromXPMData(scr, NEXT_BROKEN_CLOSE_XPM);
147 } else {
148 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
150 if (pix)
151 pix->shared = 1;
152 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
154 if (wPreferences.new_style == TS_NEXT) {
155 pix = wPixmapCreateFromXPMData(scr, NEXT_ICONIFY_XPM);
156 } else {
157 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
159 if (pix)
160 pix->shared = 1;
161 scr->b_pixmaps[WBUT_ICONIFY] = pix;
162 #ifdef XKB_BUTTON_HINT
163 if (wPreferences.new_style == TS_NEXT) {
164 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP1_XPM);
165 } else {
166 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
168 if (pix)
169 pix->shared = 1;
170 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
171 if (wPreferences.new_style == TS_NEXT) {
172 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP2_XPM);
173 } else {
174 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
176 if (pix)
177 pix->shared = 1;
178 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
179 if (wPreferences.new_style == TS_NEXT) {
180 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP3_XPM);
181 } else {
182 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
184 if (pix)
185 pix->shared = 1;
186 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
187 if (wPreferences.new_style == TS_NEXT) {
188 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP4_XPM);
189 } else {
190 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
192 if (pix)
193 pix->shared = 1;
194 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
195 #endif
197 if (wPreferences.new_style == TS_NEXT) {
198 pix = wPixmapCreateFromXPMData(scr, NEXT_KILL_XPM);
199 } else {
200 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
202 if (pix)
203 pix->shared = 1;
204 scr->b_pixmaps[WBUT_KILL] = pix;
207 static void draw_dot(WScreen * scr, Drawable d, int x, int y, GC gc)
209 XSetForeground(dpy, gc, scr->black_pixel);
210 XDrawLine(dpy, d, gc, x, y, x + 1, y);
211 XDrawPoint(dpy, d, gc, x, y + 1);
212 XSetForeground(dpy, gc, scr->white_pixel);
213 XDrawLine(dpy, d, gc, x + 2, y, x + 2, y + 1);
214 XDrawPoint(dpy, d, gc, x + 1, y + 1);
217 static WPixmap *make3Dots(WScreen * scr)
219 WPixmap *wpix;
220 GC gc2, gc;
221 XGCValues gcv;
222 Pixmap pix, mask;
224 gc = scr->copy_gc;
225 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, scr->w_depth);
226 XSetForeground(dpy, gc, scr->black_pixel);
227 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
228 XSetForeground(dpy, gc, scr->white_pixel);
229 draw_dot(scr, pix, 4, wPreferences.icon_size - 6, gc);
230 draw_dot(scr, pix, 9, wPreferences.icon_size - 6, gc);
231 draw_dot(scr, pix, 14, wPreferences.icon_size - 6, gc);
233 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, 1);
234 gcv.foreground = 0;
235 gcv.graphics_exposures = False;
236 gc2 = XCreateGC(dpy, mask, GCForeground | GCGraphicsExposures, &gcv);
237 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
238 XSetForeground(dpy, gc2, 1);
239 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size - 6, 3, 2);
240 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size - 6, 3, 2);
241 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size - 6, 3, 2);
243 XFreeGC(dpy, gc2);
245 wpix = wPixmapCreate(pix, mask);
246 wpix->shared = 1;
248 return wpix;
251 static void allocGCs(WScreen * scr)
253 XGCValues gcv;
254 XColor color;
255 int gcm;
257 scr->stipple_bitmap = XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH, STIPPLE_HEIGHT);
259 gcv.stipple = scr->stipple_bitmap;
260 gcv.foreground = scr->white_pixel;
261 gcv.fill_style = FillStippled;
262 gcv.graphics_exposures = False;
263 gcm = GCForeground | GCStipple | GCFillStyle | GCGraphicsExposures;
264 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
266 /* selected icon border GCs */
267 gcv.function = GXcopy;
268 gcv.foreground = scr->white_pixel;
269 gcv.background = scr->black_pixel;
270 gcv.line_width = 1;
271 gcv.line_style = LineDoubleDash;
272 gcv.fill_style = FillSolid;
273 gcv.dash_offset = 0;
274 gcv.dashes = 4;
275 gcv.graphics_exposures = False;
277 gcm = GCFunction | GCGraphicsExposures;
278 gcm |= GCForeground | GCBackground;
279 gcm |= GCLineWidth | GCLineStyle;
280 gcm |= GCFillStyle;
281 gcm |= GCDashOffset | GCDashList;
283 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
285 scr->menu_title_color[0] = WMRetainColor(scr->white);
287 /* don't retain scr->black here because we may alter its alpha */
288 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
289 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
291 /* frame GC */
292 wGetColor(scr, DEF_FRAME_COLOR, &color);
293 gcv.function = GXxor;
294 /* this will raise the probability of the XORed color being different
295 * of the original color in PseudoColor when not all color cells are
296 * initialized */
297 if (DefaultVisual(dpy, scr->screen)->class == PseudoColor)
298 gcv.plane_mask = (1 << (scr->depth - 1)) | 1;
299 else
300 gcv.plane_mask = AllPlanes;
301 gcv.foreground = color.pixel;
302 if (gcv.foreground == 0)
303 gcv.foreground = 1;
304 gcv.line_width = DEF_FRAME_THICKNESS;
305 gcv.subwindow_mode = IncludeInferiors;
306 gcv.graphics_exposures = False;
307 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground | GCGraphicsExposures
308 | GCFunction | GCSubwindowMode | GCLineWidth | GCPlaneMask, &gcv);
310 /* line GC */
311 gcv.foreground = color.pixel;
313 if (gcv.foreground == 0)
314 /* XOR:ing with a zero is not going to be of much use, so
315 in that case, we somewhat arbitrarily xor with 17 instead. */
316 gcv.foreground = 17;
318 gcv.function = GXxor;
319 gcv.subwindow_mode = IncludeInferiors;
320 gcv.line_width = 1;
321 gcv.cap_style = CapRound;
322 gcv.graphics_exposures = False;
323 gcm = GCForeground | GCFunction | GCSubwindowMode | GCLineWidth | GCCapStyle | GCGraphicsExposures;
324 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
326 scr->line_pixel = gcv.foreground;
328 /* copy GC */
329 gcv.foreground = scr->white_pixel;
330 gcv.background = scr->black_pixel;
331 gcv.graphics_exposures = False;
332 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCGraphicsExposures, &gcv);
334 /* misc drawing GC */
335 gcv.graphics_exposures = False;
336 gcm = GCGraphicsExposures;
337 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
339 assert(scr->stipple_bitmap != None);
341 /* mono GC */
342 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
345 static void createPixmaps(WScreen * scr)
347 WPixmap *pix;
349 /* load pixmaps */
350 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_RADIO_INDICATOR_XBM_DATA,
351 (char *)MENU_RADIO_INDICATOR_XBM_DATA,
352 MENU_RADIO_INDICATOR_XBM_SIZE,
353 MENU_RADIO_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
354 if (pix != NULL)
355 pix->shared = 1;
356 scr->menu_radio_indicator = pix;
358 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_CHECK_INDICATOR_XBM_DATA,
359 (char *)MENU_CHECK_INDICATOR_XBM_DATA,
360 MENU_CHECK_INDICATOR_XBM_SIZE,
361 MENU_CHECK_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
362 if (pix != NULL)
363 pix->shared = 1;
364 scr->menu_check_indicator = pix;
366 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_MINI_INDICATOR_XBM_DATA,
367 (char *)MENU_MINI_INDICATOR_XBM_DATA,
368 MENU_MINI_INDICATOR_XBM_SIZE,
369 MENU_MINI_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
370 if (pix != NULL)
371 pix->shared = 1;
372 scr->menu_mini_indicator = pix;
374 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_HIDE_INDICATOR_XBM_DATA,
375 (char *)MENU_HIDE_INDICATOR_XBM_DATA,
376 MENU_HIDE_INDICATOR_XBM_SIZE,
377 MENU_HIDE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
378 if (pix != NULL)
379 pix->shared = 1;
380 scr->menu_hide_indicator = pix;
382 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_SHADE_INDICATOR_XBM_DATA,
383 (char *)MENU_SHADE_INDICATOR_XBM_DATA,
384 MENU_SHADE_INDICATOR_XBM_SIZE,
385 MENU_SHADE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
386 if (pix != NULL)
387 pix->shared = 1;
388 scr->menu_shade_indicator = pix;
390 create_logo_image(scr);
392 scr->dock_dots = make3Dots(scr);
394 /* titlebar button pixmaps */
395 allocButtonPixmaps(scr);
398 void create_logo_image(WScreen *scr)
400 RImage *image = get_icon_image(scr, "Logo", "WMPanel", wPreferences.icon_size);
402 if (!image) {
403 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode));
404 } else {
405 WMSetApplicationIconImage(scr->wmscreen, image);
406 RReleaseImage(image);
411 *----------------------------------------------------------------------
412 * createInternalWindows--
413 * Creates some windows used internally by the program. One to
414 * receive input focus when no other window can get it and another
415 * to display window geometry information during window resize/move.
417 * Returns:
418 * Nothing
420 * Side effects:
421 * Windows are created and some colors are allocated for the
422 * window background.
423 *----------------------------------------------------------------------
425 static void createInternalWindows(WScreen * scr)
427 int vmask;
428 XSetWindowAttributes attribs;
430 /* InputOnly window to get the focus when no other window can get it */
431 vmask = CWEventMask | CWOverrideRedirect;
432 attribs.event_mask = KeyPressMask | FocusChangeMask;
433 attribs.override_redirect = True;
434 scr->no_focus_win = XCreateWindow(dpy, scr->root_win, -10, -10, 4, 4, 0, 0,
435 InputOnly, CopyFromParent, vmask, &attribs);
436 XSelectInput(dpy, scr->no_focus_win, KeyPressMask | KeyReleaseMask);
437 XMapWindow(dpy, scr->no_focus_win);
439 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
441 /* shadow window for dock buttons */
442 vmask = CWBorderPixel | CWBackPixmap | CWBackPixel | CWCursor | CWSaveUnder | CWOverrideRedirect;
443 attribs.border_pixel = scr->black_pixel;
444 attribs.save_under = True;
445 attribs.override_redirect = True;
446 attribs.background_pixmap = None;
447 attribs.background_pixel = scr->white_pixel;
448 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
449 vmask |= CWColormap;
450 attribs.colormap = scr->w_colormap;
451 scr->dock_shadow =
452 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
453 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent, scr->w_visual, vmask, &attribs);
455 /* workspace name */
456 vmask = CWBackPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWBorderPixel;
457 attribs.save_under = True;
458 attribs.override_redirect = True;
459 attribs.colormap = scr->w_colormap;
460 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
461 attribs.border_pixel = 0; /* do not care */
462 scr->workspace_name =
463 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
464 CopyFromParent, scr->w_visual, vmask, &attribs);
468 *----------------------------------------------------------------------
469 * wScreenInit--
470 * Initializes the window manager for the given screen and
471 * allocates a WScreen descriptor for it. Many resources are allocated
472 * for the screen and the root window is setup appropriately.
474 * Returns:
475 * The WScreen descriptor for the screen.
477 * Side effects:
478 * Many resources are allocated and the IconSize property is
479 * set on the root window.
480 * The program can be aborted if some fatal error occurs.
482 * TODO: User specifiable visual.
483 *----------------------------------------------------------------------
485 WScreen *wScreenInit(int screen_number)
487 WScreen *scr;
488 XIconSize icon_size[1];
489 RContextAttributes rattr;
490 long event_mask;
491 XErrorHandler oldHandler;
492 int i;
494 scr = wmalloc(sizeof(WScreen));
496 scr->stacking_list = WMCreateTreeBag();
498 /* initialize globals */
499 scr->screen = screen_number;
500 scr->root_win = RootWindow(dpy, screen_number);
501 scr->depth = DefaultDepth(dpy, screen_number);
502 scr->colormap = DefaultColormap(dpy, screen_number);
504 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
505 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
507 wInitXinerama(scr);
509 scr->usableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
510 scr->totalUsableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
512 for (i = 0; i < wXineramaHeads(scr); ++i) {
513 WMRect rect = wGetRectForHead(scr, i);
514 scr->usableArea[i].x1 = scr->totalUsableArea[i].x1 = rect.pos.x;
515 scr->usableArea[i].y1 = scr->totalUsableArea[i].y1 = rect.pos.y;
516 scr->usableArea[i].x2 = scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
517 scr->usableArea[i].y2 = scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
520 scr->fakeGroupLeaders = WMCreateArray(16);
522 CantManageScreen = 0;
523 oldHandler = XSetErrorHandler((XErrorHandler) alreadyRunningError);
525 event_mask = EVENT_MASK;
527 if (wPreferences.disable_root_mouse) {
528 event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
531 XSelectInput(dpy, scr->root_win, event_mask);
533 #ifdef KEEP_XKB_LOCK_STATUS
534 /* Only GroupLock doesn't work correctly in my system since right-alt
535 * can change mode while holding it too - ]d
537 if (w_global.xext.xkb.supported) {
538 XkbSelectEvents(dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
540 #endif /* KEEP_XKB_LOCK_STATUS */
542 #ifdef HAVE_XRANDR
543 if (w_global.xext.randr.supported)
544 XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
545 #endif
547 XSync(dpy, False);
548 XSetErrorHandler(oldHandler);
550 if (CantManageScreen) {
551 wfree(scr);
552 return NULL;
555 XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]);
557 /* screen descriptor for raster graphic library */
558 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
559 rattr.render_mode = wPreferences.no_dithering ? RBestMatchRendering : RDitheredRendering;
561 /* if the std colormap stuff works ok, this will be ignored */
562 rattr.colors_per_channel = wPreferences.cmap_size;
563 if (rattr.colors_per_channel < 2)
564 rattr.colors_per_channel = 2;
566 /* Use standard colormap */
567 rattr.standard_colormap_mode = RUseStdColormap;
569 if (getWVisualID(screen_number) >= 0) {
570 rattr.flags |= RC_VisualID;
571 rattr.visualid = getWVisualID(screen_number);
574 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
576 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
577 wwarning("%s", RMessageForError(RErrorCode));
579 rattr.flags &= ~RC_StandardColormap;
580 rattr.standard_colormap_mode = RUseStdColormap;
582 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
585 scr->w_win = scr->rcontext->drawable;
586 scr->w_visual = scr->rcontext->visual;
587 scr->w_depth = scr->rcontext->depth;
588 scr->w_colormap = scr->rcontext->cmap;
590 /* create screen descriptor for WINGs */
591 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number, scr->rcontext);
593 if (!scr->wmscreen) {
594 wfatal(_("could not initialize WINGs widget set"));
595 return NULL;
598 scr->black = WMBlackColor(scr->wmscreen);
599 scr->white = WMWhiteColor(scr->wmscreen);
600 scr->gray = WMGrayColor(scr->wmscreen);
601 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
603 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black; */
604 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white; */
605 scr->light_pixel = WMColorPixel(scr->gray);
606 scr->dark_pixel = WMColorPixel(scr->darkGray);
608 /* create GCs with default values */
609 allocGCs(scr);
611 /* for our window manager info notice board. Need to
612 * create before reading the defaults, because it will be used there.
614 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, 0, 0);
616 /* read defaults for this screen */
617 wReadDefaults(scr, w_global.domain.wmaker->dictionary);
620 XColor xcol;
621 /* frame boder color */
622 wGetColor(scr, WMGetColorRGBDescription(scr->frame_border_color), &xcol);
623 scr->frame_border_pixel = xcol.pixel;
624 wGetColor(scr, WMGetColorRGBDescription(scr->frame_selected_border_color), &xcol);
625 scr->frame_selected_border_pixel = xcol.pixel;
628 createInternalWindows(scr);
630 wNETWMInitStuff(scr);
632 /* create initial workspace */
633 wWorkspaceNew(scr);
635 /* create shared pixmaps */
636 createPixmaps(scr);
638 /* set icon sizes we can accept from clients */
639 icon_size[0].min_width = 8;
640 icon_size[0].min_height = 8;
641 icon_size[0].max_width = wPreferences.icon_size - 4;
642 icon_size[0].max_height = wPreferences.icon_size - 4;
643 icon_size[0].width_inc = 1;
644 icon_size[0].height_inc = 1;
645 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
647 /* setup WindowMaker protocols property in the root window */
648 PropSetWMakerProtocols(scr->root_win);
650 /* setup our noticeboard */
651 XChangeProperty(dpy, scr->info_window, w_global.atom.wmaker.noticeboard,
652 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
653 XChangeProperty(dpy, scr->root_win, w_global.atom.wmaker.noticeboard,
654 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
656 #ifdef BALLOON_TEXT
657 /* initialize balloon text stuff */
658 wBalloonInitialize(scr);
659 #endif
661 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
663 scr->tech_draw_font = XLoadQueryFont(dpy, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
664 if (!scr->tech_draw_font)
665 scr->tech_draw_font = XLoadQueryFont(dpy, "fixed");
667 scr->gview = WCreateGeometryView(scr->wmscreen);
668 WMRealizeWidget(scr->gview);
670 wScreenUpdateUsableArea(scr);
672 return scr;
675 void wScreenUpdateUsableArea(WScreen * scr)
678 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
679 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
680 * border.
683 WArea area;
684 int i, dock_head;
685 unsigned long best_area, tmp_area;
686 unsigned int size, position;
688 dock_head = scr->xine_info.primary_head;
689 best_area = 0;
690 size = wPreferences.workspace_border_size;
691 position = wPreferences.workspace_border_position;
693 if (scr->dock) {
694 WMRect rect;
695 rect.pos.x = scr->dock->x_pos;
696 rect.pos.y = scr->dock->y_pos;
697 rect.size.width = wPreferences.icon_size;
698 rect.size.height = wPreferences.icon_size;
699 dock_head = wGetHeadForRect(scr, rect);
702 for (i = 0; i < wXineramaHeads(scr); ++i) {
703 WMRect rect = wGetRectForHead(scr, i);
704 scr->totalUsableArea[i].x1 = rect.pos.x;
705 scr->totalUsableArea[i].y1 = rect.pos.y;
706 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
707 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
709 if (scr->dock && dock_head == i && (!scr->dock->lowered || wPreferences.no_window_over_dock)) {
710 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
712 if (scr->dock->on_right_side) {
713 scr->totalUsableArea[i].x2 -= offset;
714 } else {
715 scr->totalUsableArea[i].x1 += offset;
719 if (wNETWMGetUsableArea(scr, i, &area)) {
720 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
721 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
722 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
723 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
726 scr->usableArea[i] = scr->totalUsableArea[i];
728 #if 0
729 printf("usableArea[%d]: %d %d %d %d\n", i,
730 scr->usableArea[i].x1, scr->usableArea[i].x2, scr->usableArea[i].y1, scr->usableArea[i].y2);
731 #endif
732 if (wPreferences.no_window_over_icons) {
733 if (wPreferences.icon_yard & IY_VERT) {
734 if (wPreferences.icon_yard & IY_RIGHT) {
735 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
736 } else {
737 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
739 } else {
740 if (wPreferences.icon_yard & IY_TOP) {
741 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
742 } else {
743 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
748 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width / 2) {
749 scr->totalUsableArea[i].x1 = rect.pos.x;
750 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
753 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height / 2) {
754 scr->totalUsableArea[i].y1 = rect.pos.y;
755 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
758 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
759 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
761 if (tmp_area > best_area) {
762 best_area = tmp_area;
763 area = scr->totalUsableArea[i];
766 if (size > 0 && position != WB_NONE) {
767 if (position & WB_LEFTRIGHT) {
768 scr->totalUsableArea[i].x1 += size;
769 scr->totalUsableArea[i].x2 -= size;
771 if (position & WB_TOPBOTTOM) {
772 scr->totalUsableArea[i].y1 += size;
773 scr->totalUsableArea[i].y2 -= size;
778 if (wPreferences.auto_arrange_icons)
779 wArrangeIcons(scr, True);
782 void wScreenRestoreState(WScreen * scr)
784 WMPropList *state;
785 char *path;
787 OpenRootMenu(scr, -10000, -10000, False);
788 wMenuUnmap(scr->root_menu);
790 make_keys();
792 if (w_global.screen_count == 1) {
793 path = wdefaultspathfordomain("WMState");
794 } else {
795 char buf[16];
796 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
797 path = wdefaultspathfordomain(buf);
800 w_global.session_state = WMReadPropListFromFile(path);
801 wfree(path);
802 if (!w_global.session_state && w_global.screen_count > 1) {
803 path = wdefaultspathfordomain("WMState");
804 w_global.session_state = WMReadPropListFromFile(path);
805 wfree(path);
808 if (!w_global.session_state)
809 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
811 if (!wPreferences.flags.nodock) {
812 state = WMGetFromPLDictionary(w_global.session_state, dDock);
813 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
816 if (!wPreferences.flags.noclip) {
817 state = WMGetFromPLDictionary(w_global.session_state, dClip);
818 w_global.clip.icon = wClipRestoreState(scr, state);
821 if (!wPreferences.flags.nodrawer) {
822 if (!scr->dock->on_right_side) {
823 /* Drawer tile was created early in wScreenInit() -> wReadDefaults(). At
824 * that time, scr->dock was NULL and the tile was created as if we were on
825 * the right side. If we aren't, redo it now. */
826 assert(scr->drawer_tile);
827 RReleaseImage(scr->drawer_tile);
828 scr->drawer_tile = wDrawerMakeTile(scr, scr->icon_tile);
830 wDrawersRestoreState(scr);
833 wWorkspaceRestoreState(scr);
834 wScreenUpdateUsableArea(scr);
837 void wScreenSaveState(WScreen * scr)
839 WWindow *wwin;
840 char *str;
841 WMPropList *old_state, *foo;
843 make_keys();
845 /* save state of windows */
846 wwin = scr->focused_window;
847 while (wwin) {
848 wWindowSaveState(wwin);
849 wwin = wwin->prev;
852 if (wPreferences.flags.noupdates)
853 return;
855 old_state = w_global.session_state;
856 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
858 WMPLSetCaseSensitive(True);
860 /* save dock state to file */
861 if (!wPreferences.flags.nodock) {
862 wDockSaveState(scr, old_state);
863 } else {
864 if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) {
865 WMPutInPLDictionary(w_global.session_state, dDock, foo);
868 if (!wPreferences.flags.noclip) {
869 wClipSaveState();
870 } else {
871 if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) {
872 WMPutInPLDictionary(w_global.session_state, dClip, foo);
876 wWorkspaceSaveState(old_state);
878 if (!wPreferences.flags.nodrawer) {
879 wDrawersSaveState(scr);
880 } else {
881 if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) {
882 WMPutInPLDictionary(w_global.session_state, dDrawers, foo);
887 if (wPreferences.save_session_on_exit) {
888 wSessionSaveState(scr);
889 } else {
890 if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) {
891 WMPutInPLDictionary(w_global.session_state, dApplications, foo);
893 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) {
894 WMPutInPLDictionary(w_global.session_state, dWorkspace, foo);
898 /* clean up */
899 WMPLSetCaseSensitive(False);
901 wMenuSaveState(scr);
903 if (w_global.screen_count == 1) {
904 str = wdefaultspathfordomain("WMState");
905 } else {
906 char buf[16];
907 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
908 str = wdefaultspathfordomain(buf);
910 if (!WMWritePropListToFile(w_global.session_state, str)) {
911 werror(_("could not save session state in %s"), str);
913 wfree(str);
914 WMReleasePropList(old_state);
917 int wScreenBringInside(WScreen * scr, int *x, int *y, int width, int height)
919 int moved = 0;
920 int tol_w, tol_h;
922 * With respect to the head that contains most of the window.
924 int sx1, sy1, sx2, sy2;
926 WMRect rect;
927 int head, flags;
929 rect.pos.x = *x;
930 rect.pos.y = *y;
931 rect.size.width = width;
932 rect.size.height = height;
934 head = wGetRectPlacementInfo(scr, rect, &flags);
935 rect = wGetRectForHead(scr, head);
937 sx1 = rect.pos.x;
938 sy1 = rect.pos.y;
939 sx2 = sx1 + rect.size.width;
940 sy2 = sy1 + rect.size.height;
942 #if 0 /* NOTE: gives funky group movement */
943 if (flags & XFLAG_MULTIPLE) {
945 * since we span multiple heads, pull window totaly inside
947 if (*x < sx1)
948 *x = sx1, moved = 1;
949 else if (*x + width > sx2)
950 *x = sx2 - width, moved = 1;
952 if (*y < sy1)
953 *y = sy1, moved = 1;
954 else if (*y + height > sy2)
955 *y = sy2 - height, moved = 1;
957 return moved;
959 #endif
961 if (width > 20)
962 tol_w = width / 2;
963 else
964 tol_w = 20;
966 if (height > 20)
967 tol_h = height / 2;
968 else
969 tol_h = 20;
971 if (*x + width < sx1 + 10)
972 *x = sx1 - tol_w, moved = 1;
973 else if (*x >= sx2 - 10)
974 *x = sx2 - tol_w - 1, moved = 1;
976 if (*y < sy1 - height + 10)
977 *y = sy1 - tol_h, moved = 1;
978 else if (*y >= sy2 - 10)
979 *y = sy2 - tol_h - 1, moved = 1;
981 return moved;
984 int wScreenKeepInside(WScreen * scr, int *x, int *y, int width, int height)
986 int moved = 0;
987 int sx1, sy1, sx2, sy2;
988 WMRect rect;
989 int head;
991 rect.pos.x = *x;
992 rect.pos.y = *y;
993 rect.size.width = width;
994 rect.size.height = height;
996 head = wGetHeadForRect(scr, rect);
997 rect = wGetRectForHead(scr, head);
999 sx1 = rect.pos.x;
1000 sy1 = rect.pos.y;
1001 sx2 = sx1 + rect.size.width;
1002 sy2 = sy1 + rect.size.height;
1004 if (*x < sx1)
1005 *x = sx1, moved = 1;
1006 else if (*x + width > sx2)
1007 *x = sx2 - width, moved = 1;
1009 if (*y < sy1)
1010 *y = sy1, moved = 1;
1011 else if (*y + height > sy2)
1012 *y = sy2 - height, moved = 1;
1014 return moved;