wmaker: Removed global variable 'WDelayedActionSet' and associated dead code
[wmaker-crm.git] / src / screen.c
blob32620af9f243cfcaf0c0766c2d475d2461d0a8bf
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 /**** Global variables ****/
74 extern WDDomain *WDWindowMaker;
76 /**** Local ****/
77 #define STIPPLE_WIDTH 2
78 #define STIPPLE_HEIGHT 2
79 static char STIPPLE_DATA[] = { 0x02, 0x01 };
81 static int CantManageScreen = 0;
83 static WMPropList *dApplications = NULL;
84 static WMPropList *dWorkspace;
85 static WMPropList *dDock;
86 static WMPropList *dClip;
87 static WMPropList *dDrawers = NULL;
89 static void make_keys(void)
91 if (dApplications != NULL)
92 return;
94 dApplications = WMCreatePLString("Applications");
95 dWorkspace = WMCreatePLString("Workspace");
96 dDock = WMCreatePLString("Dock");
97 dClip = WMCreatePLString("Clip");
98 dDrawers = WMCreatePLString("Drawers");
102 *----------------------------------------------------------------------
103 * alreadyRunningError--
104 * X error handler used to catch errors when trying to do
105 * XSelectInput() on the root window. These errors probably mean that
106 * there already is some other window manager running.
108 * Returns:
109 * Nothing, unless something really evil happens...
111 * Side effects:
112 * CantManageScreen is set to 1;
113 *----------------------------------------------------------------------
115 static int alreadyRunningError(Display * dpy, XErrorEvent * error)
117 CantManageScreen = 1;
118 return -1;
122 *----------------------------------------------------------------------
123 * allocButtonPixmaps--
124 * Allocate pixmaps used on window operation buttons (those in the
125 * titlebar). The pixmaps are linked to the program. If XPM is supported
126 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
128 * Returns:
129 * Nothing
131 * Side effects:
132 * Allocates shared pixmaps for the screen. These pixmaps should
133 * not be freed by anybody.
134 *----------------------------------------------------------------------
136 static void allocButtonPixmaps(WScreen * scr)
138 WPixmap *pix;
140 /* create predefined pixmaps */
141 if (wPreferences.new_style == TS_NEXT) {
142 pix = wPixmapCreateFromXPMData(scr, NEXT_CLOSE_XPM);
143 } else {
144 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
146 if (pix)
147 pix->shared = 1;
148 scr->b_pixmaps[WBUT_CLOSE] = pix;
150 if (wPreferences.new_style == TS_NEXT) {
151 pix = wPixmapCreateFromXPMData(scr, NEXT_BROKEN_CLOSE_XPM);
152 } else {
153 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
155 if (pix)
156 pix->shared = 1;
157 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
159 if (wPreferences.new_style == TS_NEXT) {
160 pix = wPixmapCreateFromXPMData(scr, NEXT_ICONIFY_XPM);
161 } else {
162 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
164 if (pix)
165 pix->shared = 1;
166 scr->b_pixmaps[WBUT_ICONIFY] = pix;
167 #ifdef XKB_BUTTON_HINT
168 if (wPreferences.new_style == TS_NEXT) {
169 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP1_XPM);
170 } else {
171 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
173 if (pix)
174 pix->shared = 1;
175 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
176 if (wPreferences.new_style == TS_NEXT) {
177 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP2_XPM);
178 } else {
179 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
181 if (pix)
182 pix->shared = 1;
183 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
184 if (wPreferences.new_style == TS_NEXT) {
185 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP3_XPM);
186 } else {
187 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
189 if (pix)
190 pix->shared = 1;
191 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
192 if (wPreferences.new_style == TS_NEXT) {
193 pix = wPixmapCreateFromXPMData(scr, NEXT_XKBGROUP4_XPM);
194 } else {
195 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
197 if (pix)
198 pix->shared = 1;
199 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
200 #endif
202 if (wPreferences.new_style == TS_NEXT) {
203 pix = wPixmapCreateFromXPMData(scr, NEXT_KILL_XPM);
204 } else {
205 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
207 if (pix)
208 pix->shared = 1;
209 scr->b_pixmaps[WBUT_KILL] = pix;
212 static void draw_dot(WScreen * scr, Drawable d, int x, int y, GC gc)
214 XSetForeground(dpy, gc, scr->black_pixel);
215 XDrawLine(dpy, d, gc, x, y, x + 1, y);
216 XDrawPoint(dpy, d, gc, x, y + 1);
217 XSetForeground(dpy, gc, scr->white_pixel);
218 XDrawLine(dpy, d, gc, x + 2, y, x + 2, y + 1);
219 XDrawPoint(dpy, d, gc, x + 1, y + 1);
222 static WPixmap *make3Dots(WScreen * scr)
224 WPixmap *wpix;
225 GC gc2, gc;
226 XGCValues gcv;
227 Pixmap pix, mask;
229 gc = scr->copy_gc;
230 pix = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, scr->w_depth);
231 XSetForeground(dpy, gc, scr->black_pixel);
232 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
233 XSetForeground(dpy, gc, scr->white_pixel);
234 draw_dot(scr, pix, 4, wPreferences.icon_size - 6, gc);
235 draw_dot(scr, pix, 9, wPreferences.icon_size - 6, gc);
236 draw_dot(scr, pix, 14, wPreferences.icon_size - 6, gc);
238 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size, wPreferences.icon_size, 1);
239 gcv.foreground = 0;
240 gcv.graphics_exposures = False;
241 gc2 = XCreateGC(dpy, mask, GCForeground | GCGraphicsExposures, &gcv);
242 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size, wPreferences.icon_size);
243 XSetForeground(dpy, gc2, 1);
244 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size - 6, 3, 2);
245 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size - 6, 3, 2);
246 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size - 6, 3, 2);
248 XFreeGC(dpy, gc2);
250 wpix = wPixmapCreate(scr, pix, mask);
251 wpix->shared = 1;
253 return wpix;
256 static void allocGCs(WScreen * scr)
258 XGCValues gcv;
259 XColor color;
260 int gcm;
262 scr->stipple_bitmap = XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH, STIPPLE_HEIGHT);
264 gcv.stipple = scr->stipple_bitmap;
265 gcv.foreground = scr->white_pixel;
266 gcv.fill_style = FillStippled;
267 gcv.graphics_exposures = False;
268 gcm = GCForeground | GCStipple | GCFillStyle | GCGraphicsExposures;
269 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
271 /* selected icon border GCs */
272 gcv.function = GXcopy;
273 gcv.foreground = scr->white_pixel;
274 gcv.background = scr->black_pixel;
275 gcv.line_width = 1;
276 gcv.line_style = LineDoubleDash;
277 gcv.fill_style = FillSolid;
278 gcv.dash_offset = 0;
279 gcv.dashes = 4;
280 gcv.graphics_exposures = False;
282 gcm = GCFunction | GCGraphicsExposures;
283 gcm |= GCForeground | GCBackground;
284 gcm |= GCLineWidth | GCLineStyle;
285 gcm |= GCFillStyle;
286 gcm |= GCDashOffset | GCDashList;
288 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
290 scr->menu_title_color[0] = WMRetainColor(scr->white);
292 /* don't retain scr->black here because we may alter its alpha */
293 scr->mtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
294 scr->dtext_color = WMCreateRGBColor(scr->wmscreen, 0, 0, 0, True);
296 /* frame GC */
297 wGetColor(scr, DEF_FRAME_COLOR, &color);
298 gcv.function = GXxor;
299 /* this will raise the probability of the XORed color being different
300 * of the original color in PseudoColor when not all color cells are
301 * initialized */
302 if (DefaultVisual(dpy, scr->screen)->class == PseudoColor)
303 gcv.plane_mask = (1 << (scr->depth - 1)) | 1;
304 else
305 gcv.plane_mask = AllPlanes;
306 gcv.foreground = color.pixel;
307 if (gcv.foreground == 0)
308 gcv.foreground = 1;
309 gcv.line_width = DEF_FRAME_THICKNESS;
310 gcv.subwindow_mode = IncludeInferiors;
311 gcv.graphics_exposures = False;
312 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground | GCGraphicsExposures
313 | GCFunction | GCSubwindowMode | GCLineWidth | GCPlaneMask, &gcv);
315 /* line GC */
316 gcv.foreground = color.pixel;
318 if (gcv.foreground == 0)
319 /* XOR:ing with a zero is not going to be of much use, so
320 in that case, we somewhat arbitrarily xor with 17 instead. */
321 gcv.foreground = 17;
323 gcv.function = GXxor;
324 gcv.subwindow_mode = IncludeInferiors;
325 gcv.line_width = 1;
326 gcv.cap_style = CapRound;
327 gcv.graphics_exposures = False;
328 gcm = GCForeground | GCFunction | GCSubwindowMode | GCLineWidth | GCCapStyle | GCGraphicsExposures;
329 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
331 scr->line_pixel = gcv.foreground;
333 /* copy GC */
334 gcv.foreground = scr->white_pixel;
335 gcv.background = scr->black_pixel;
336 gcv.graphics_exposures = False;
337 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground | GCBackground | GCGraphicsExposures, &gcv);
339 /* misc drawing GC */
340 gcv.graphics_exposures = False;
341 gcm = GCGraphicsExposures;
342 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
344 assert(scr->stipple_bitmap != None);
346 /* mono GC */
347 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
350 static void createPixmaps(WScreen * scr)
352 WPixmap *pix;
354 /* load pixmaps */
355 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_RADIO_INDICATOR_XBM_DATA,
356 (char *)MENU_RADIO_INDICATOR_XBM_DATA,
357 MENU_RADIO_INDICATOR_XBM_SIZE,
358 MENU_RADIO_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
359 if (pix != NULL)
360 pix->shared = 1;
361 scr->menu_radio_indicator = pix;
363 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_CHECK_INDICATOR_XBM_DATA,
364 (char *)MENU_CHECK_INDICATOR_XBM_DATA,
365 MENU_CHECK_INDICATOR_XBM_SIZE,
366 MENU_CHECK_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
367 if (pix != NULL)
368 pix->shared = 1;
369 scr->menu_check_indicator = pix;
371 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_MINI_INDICATOR_XBM_DATA,
372 (char *)MENU_MINI_INDICATOR_XBM_DATA,
373 MENU_MINI_INDICATOR_XBM_SIZE,
374 MENU_MINI_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
375 if (pix != NULL)
376 pix->shared = 1;
377 scr->menu_mini_indicator = pix;
379 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_HIDE_INDICATOR_XBM_DATA,
380 (char *)MENU_HIDE_INDICATOR_XBM_DATA,
381 MENU_HIDE_INDICATOR_XBM_SIZE,
382 MENU_HIDE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
383 if (pix != NULL)
384 pix->shared = 1;
385 scr->menu_hide_indicator = pix;
387 pix = wPixmapCreateFromXBMData(scr, (char *)MENU_SHADE_INDICATOR_XBM_DATA,
388 (char *)MENU_SHADE_INDICATOR_XBM_DATA,
389 MENU_SHADE_INDICATOR_XBM_SIZE,
390 MENU_SHADE_INDICATOR_XBM_SIZE, scr->black_pixel, scr->white_pixel);
391 if (pix != NULL)
392 pix->shared = 1;
393 scr->menu_shade_indicator = pix;
395 create_logo_image(scr);
397 scr->dock_dots = make3Dots(scr);
399 /* titlebar button pixmaps */
400 allocButtonPixmaps(scr);
403 void create_logo_image(WScreen *scr)
405 RImage *image = get_icon_image(scr, "Logo", "WMPanel", wPreferences.icon_size);
407 if (!image) {
408 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode));
409 } else {
410 WMSetApplicationIconImage(scr->wmscreen, image);
411 RReleaseImage(image);
416 *----------------------------------------------------------------------
417 * createInternalWindows--
418 * Creates some windows used internally by the program. One to
419 * receive input focus when no other window can get it and another
420 * to display window geometry information during window resize/move.
422 * Returns:
423 * Nothing
425 * Side effects:
426 * Windows are created and some colors are allocated for the
427 * window background.
428 *----------------------------------------------------------------------
430 static void createInternalWindows(WScreen * scr)
432 int vmask;
433 XSetWindowAttributes attribs;
435 /* InputOnly window to get the focus when no other window can get it */
436 vmask = CWEventMask | CWOverrideRedirect;
437 attribs.event_mask = KeyPressMask | FocusChangeMask;
438 attribs.override_redirect = True;
439 scr->no_focus_win = XCreateWindow(dpy, scr->root_win, -10, -10, 4, 4, 0, 0,
440 InputOnly, CopyFromParent, vmask, &attribs);
441 XSelectInput(dpy, scr->no_focus_win, KeyPressMask | KeyReleaseMask);
442 XMapWindow(dpy, scr->no_focus_win);
444 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
446 /* shadow window for dock buttons */
447 vmask = CWBorderPixel | CWBackPixmap | CWBackPixel | CWCursor | CWSaveUnder | CWOverrideRedirect;
448 attribs.border_pixel = scr->black_pixel;
449 attribs.save_under = True;
450 attribs.override_redirect = True;
451 attribs.background_pixmap = None;
452 attribs.background_pixel = scr->white_pixel;
453 attribs.cursor = wPreferences.cursor[WCUR_NORMAL];
454 vmask |= CWColormap;
455 attribs.colormap = scr->w_colormap;
456 scr->dock_shadow =
457 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
458 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent, scr->w_visual, vmask, &attribs);
460 /* workspace name */
461 vmask = CWBackPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWBorderPixel;
462 attribs.save_under = True;
463 attribs.override_redirect = True;
464 attribs.colormap = scr->w_colormap;
465 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
466 attribs.border_pixel = 0; /* do not care */
467 scr->workspace_name =
468 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
469 CopyFromParent, scr->w_visual, vmask, &attribs);
473 *----------------------------------------------------------------------
474 * wScreenInit--
475 * Initializes the window manager for the given screen and
476 * allocates a WScreen descriptor for it. Many resources are allocated
477 * for the screen and the root window is setup appropriately.
479 * Returns:
480 * The WScreen descriptor for the screen.
482 * Side effects:
483 * Many resources are allocated and the IconSize property is
484 * set on the root window.
485 * The program can be aborted if some fatal error occurs.
487 * TODO: User specifiable visual.
488 *----------------------------------------------------------------------
490 WScreen *wScreenInit(int screen_number)
492 WScreen *scr;
493 XIconSize icon_size[1];
494 RContextAttributes rattr;
495 long event_mask;
496 XErrorHandler oldHandler;
497 int i;
499 scr = wmalloc(sizeof(WScreen));
501 scr->stacking_list = WMCreateTreeBag();
503 /* initialize globals */
504 scr->screen = screen_number;
505 scr->root_win = RootWindow(dpy, screen_number);
506 scr->depth = DefaultDepth(dpy, screen_number);
507 scr->colormap = DefaultColormap(dpy, screen_number);
509 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
510 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
512 wInitXinerama(scr);
514 scr->usableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
515 scr->totalUsableArea = (WArea *) wmalloc(sizeof(WArea) * wXineramaHeads(scr));
517 for (i = 0; i < wXineramaHeads(scr); ++i) {
518 WMRect rect = wGetRectForHead(scr, i);
519 scr->usableArea[i].x1 = scr->totalUsableArea[i].x1 = rect.pos.x;
520 scr->usableArea[i].y1 = scr->totalUsableArea[i].y1 = rect.pos.y;
521 scr->usableArea[i].x2 = scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
522 scr->usableArea[i].y2 = scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
525 scr->fakeGroupLeaders = WMCreateArray(16);
527 CantManageScreen = 0;
528 oldHandler = XSetErrorHandler((XErrorHandler) alreadyRunningError);
530 event_mask = EVENT_MASK;
532 if (wPreferences.disable_root_mouse) {
533 event_mask &= ~(ButtonPressMask | ButtonReleaseMask);
536 XSelectInput(dpy, scr->root_win, event_mask);
538 #ifdef KEEP_XKB_LOCK_STATUS
539 /* Only GroupLock doesn't work correctly in my system since right-alt
540 * can change mode while holding it too - ]d
542 if (w_global.xext.xkb.supported) {
543 XkbSelectEvents(dpy, XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask);
545 #endif /* KEEP_XKB_LOCK_STATUS */
547 #ifdef HAVE_XRANDR
548 if (w_global.xext.randr.supported)
549 XRRSelectInput(dpy, scr->root_win, RRScreenChangeNotifyMask);
550 #endif
552 XSync(dpy, False);
553 XSetErrorHandler(oldHandler);
555 if (CantManageScreen) {
556 wfree(scr);
557 return NULL;
560 XDefineCursor(dpy, scr->root_win, wPreferences.cursor[WCUR_ROOT]);
562 /* screen descriptor for raster graphic library */
563 rattr.flags = RC_RenderMode | RC_ColorsPerChannel | RC_StandardColormap;
564 rattr.render_mode = wPreferences.no_dithering ? RBestMatchRendering : RDitheredRendering;
566 /* if the std colormap stuff works ok, this will be ignored */
567 rattr.colors_per_channel = wPreferences.cmap_size;
568 if (rattr.colors_per_channel < 2)
569 rattr.colors_per_channel = 2;
571 /* Use standard colormap */
572 rattr.standard_colormap_mode = RUseStdColormap;
574 if (getWVisualID(screen_number) >= 0) {
575 rattr.flags |= RC_VisualID;
576 rattr.visualid = getWVisualID(screen_number);
579 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
581 if (!scr->rcontext && RErrorCode == RERR_STDCMAPFAIL) {
582 wwarning("%s", RMessageForError(RErrorCode));
584 rattr.flags &= ~RC_StandardColormap;
585 rattr.standard_colormap_mode = RUseStdColormap;
587 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
590 scr->w_win = scr->rcontext->drawable;
591 scr->w_visual = scr->rcontext->visual;
592 scr->w_depth = scr->rcontext->depth;
593 scr->w_colormap = scr->rcontext->cmap;
595 /* create screen descriptor for WINGs */
596 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number, scr->rcontext);
598 if (!scr->wmscreen) {
599 wfatal(_("could not initialize WINGs widget set"));
600 return NULL;
603 scr->black = WMBlackColor(scr->wmscreen);
604 scr->white = WMWhiteColor(scr->wmscreen);
605 scr->gray = WMGrayColor(scr->wmscreen);
606 scr->darkGray = WMDarkGrayColor(scr->wmscreen);
608 scr->black_pixel = WMColorPixel(scr->black); /*scr->rcontext->black; */
609 scr->white_pixel = WMColorPixel(scr->white); /*scr->rcontext->white; */
610 scr->light_pixel = WMColorPixel(scr->gray);
611 scr->dark_pixel = WMColorPixel(scr->darkGray);
613 /* create GCs with default values */
614 allocGCs(scr);
616 /* for our window manager info notice board. Need to
617 * create before reading the defaults, because it will be used there.
619 scr->info_window = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, 0, 0);
621 /* read defaults for this screen */
622 wReadDefaults(scr, WDWindowMaker->dictionary);
625 XColor xcol;
626 /* frame boder color */
627 wGetColor(scr, WMGetColorRGBDescription(scr->frame_border_color), &xcol);
628 scr->frame_border_pixel = xcol.pixel;
629 wGetColor(scr, WMGetColorRGBDescription(scr->frame_selected_border_color), &xcol);
630 scr->frame_selected_border_pixel = xcol.pixel;
633 createInternalWindows(scr);
635 wNETWMInitStuff(scr);
637 /* create initial workspace */
638 wWorkspaceNew(scr);
640 /* create shared pixmaps */
641 createPixmaps(scr);
643 /* set icon sizes we can accept from clients */
644 icon_size[0].min_width = 8;
645 icon_size[0].min_height = 8;
646 icon_size[0].max_width = wPreferences.icon_size - 4;
647 icon_size[0].max_height = wPreferences.icon_size - 4;
648 icon_size[0].width_inc = 1;
649 icon_size[0].height_inc = 1;
650 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
652 /* setup WindowMaker protocols property in the root window */
653 PropSetWMakerProtocols(scr->root_win);
655 /* setup our noticeboard */
656 XChangeProperty(dpy, scr->info_window, w_global.atom.wmaker.noticeboard,
657 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
658 XChangeProperty(dpy, scr->root_win, w_global.atom.wmaker.noticeboard,
659 XA_WINDOW, 32, PropModeReplace, (unsigned char *)&scr->info_window, 1);
661 #ifdef BALLOON_TEXT
662 /* initialize balloon text stuff */
663 wBalloonInitialize(scr);
664 #endif
666 scr->info_text_font = WMBoldSystemFontOfSize(scr->wmscreen, 12);
668 scr->tech_draw_font = XLoadQueryFont(dpy, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
669 if (!scr->tech_draw_font)
670 scr->tech_draw_font = XLoadQueryFont(dpy, "fixed");
672 scr->gview = WCreateGeometryView(scr->wmscreen);
673 WMRealizeWidget(scr->gview);
675 wScreenUpdateUsableArea(scr);
677 return scr;
680 void wScreenUpdateUsableArea(WScreen * scr)
683 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
684 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
685 * border.
688 WArea area;
689 int i, dock_head;
690 unsigned long best_area, tmp_area;
691 unsigned int size, position;
693 dock_head = scr->xine_info.primary_head;
694 best_area = 0;
695 size = wPreferences.workspace_border_size;
696 position = wPreferences.workspace_border_position;
698 if (scr->dock) {
699 WMRect rect;
700 rect.pos.x = scr->dock->x_pos;
701 rect.pos.y = scr->dock->y_pos;
702 rect.size.width = wPreferences.icon_size;
703 rect.size.height = wPreferences.icon_size;
704 dock_head = wGetHeadForRect(scr, rect);
707 for (i = 0; i < wXineramaHeads(scr); ++i) {
708 WMRect rect = wGetRectForHead(scr, i);
709 scr->totalUsableArea[i].x1 = rect.pos.x;
710 scr->totalUsableArea[i].y1 = rect.pos.y;
711 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
712 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
714 if (scr->dock && dock_head == i && (!scr->dock->lowered || wPreferences.no_window_over_dock)) {
715 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
717 if (scr->dock->on_right_side) {
718 scr->totalUsableArea[i].x2 -= offset;
719 } else {
720 scr->totalUsableArea[i].x1 += offset;
724 if (wNETWMGetUsableArea(scr, i, &area)) {
725 scr->totalUsableArea[i].x1 = WMAX(scr->totalUsableArea[i].x1, area.x1);
726 scr->totalUsableArea[i].y1 = WMAX(scr->totalUsableArea[i].y1, area.y1);
727 scr->totalUsableArea[i].x2 = WMIN(scr->totalUsableArea[i].x2, area.x2);
728 scr->totalUsableArea[i].y2 = WMIN(scr->totalUsableArea[i].y2, area.y2);
731 scr->usableArea[i] = scr->totalUsableArea[i];
733 #if 0
734 printf("usableArea[%d]: %d %d %d %d\n", i,
735 scr->usableArea[i].x1, scr->usableArea[i].x2, scr->usableArea[i].y1, scr->usableArea[i].y2);
736 #endif
737 if (wPreferences.no_window_over_icons) {
738 if (wPreferences.icon_yard & IY_VERT) {
739 if (wPreferences.icon_yard & IY_RIGHT) {
740 scr->totalUsableArea[i].x2 -= wPreferences.icon_size;
741 } else {
742 scr->totalUsableArea[i].x1 += wPreferences.icon_size;
744 } else {
745 if (wPreferences.icon_yard & IY_TOP) {
746 scr->totalUsableArea[i].y1 += wPreferences.icon_size;
747 } else {
748 scr->totalUsableArea[i].y2 -= wPreferences.icon_size;
753 if (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1 < rect.size.width / 2) {
754 scr->totalUsableArea[i].x1 = rect.pos.x;
755 scr->totalUsableArea[i].x2 = rect.pos.x + rect.size.width;
758 if (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1 < rect.size.height / 2) {
759 scr->totalUsableArea[i].y1 = rect.pos.y;
760 scr->totalUsableArea[i].y2 = rect.pos.y + rect.size.height;
763 tmp_area = (scr->totalUsableArea[i].x2 - scr->totalUsableArea[i].x1) *
764 (scr->totalUsableArea[i].y2 - scr->totalUsableArea[i].y1);
766 if (tmp_area > best_area) {
767 best_area = tmp_area;
768 area = scr->totalUsableArea[i];
771 if (size > 0 && position != WB_NONE) {
772 if (position & WB_LEFTRIGHT) {
773 scr->totalUsableArea[i].x1 += size;
774 scr->totalUsableArea[i].x2 -= size;
776 if (position & WB_TOPBOTTOM) {
777 scr->totalUsableArea[i].y1 += size;
778 scr->totalUsableArea[i].y2 -= size;
783 if (wPreferences.auto_arrange_icons)
784 wArrangeIcons(scr, True);
787 void wScreenRestoreState(WScreen * scr)
789 WMPropList *state;
790 char *path;
792 OpenRootMenu(scr, -10000, -10000, False);
793 wMenuUnmap(scr->root_menu);
795 make_keys();
797 if (w_global.screen_count == 1) {
798 path = wdefaultspathfordomain("WMState");
799 } else {
800 char buf[16];
801 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
802 path = wdefaultspathfordomain(buf);
805 w_global.session_state = WMReadPropListFromFile(path);
806 wfree(path);
807 if (!w_global.session_state && w_global.screen_count > 1) {
808 path = wdefaultspathfordomain("WMState");
809 w_global.session_state = WMReadPropListFromFile(path);
810 wfree(path);
813 if (!w_global.session_state)
814 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
816 if (!wPreferences.flags.nodock) {
817 state = WMGetFromPLDictionary(w_global.session_state, dDock);
818 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
821 if (!wPreferences.flags.noclip) {
822 state = WMGetFromPLDictionary(w_global.session_state, dClip);
823 w_global.clip.icon = wClipRestoreState(scr, state);
826 if (!wPreferences.flags.nodrawer) {
827 if (!scr->dock->on_right_side) {
828 /* Drawer tile was created early in wScreenInit() -> wReadDefaults(). At
829 * that time, scr->dock was NULL and the tile was created as if we were on
830 * the right side. If we aren't, redo it now. */
831 assert(scr->drawer_tile);
832 RReleaseImage(scr->drawer_tile);
833 scr->drawer_tile = wDrawerMakeTile(scr, scr->icon_tile);
835 wDrawersRestoreState(scr);
838 wWorkspaceRestoreState(scr);
839 wScreenUpdateUsableArea(scr);
842 void wScreenSaveState(WScreen * scr)
844 WWindow *wwin;
845 char *str;
846 WMPropList *old_state, *foo;
848 make_keys();
850 /* save state of windows */
851 wwin = scr->focused_window;
852 while (wwin) {
853 wWindowSaveState(wwin);
854 wwin = wwin->prev;
857 if (wPreferences.flags.noupdates)
858 return;
860 old_state = w_global.session_state;
861 w_global.session_state = WMCreatePLDictionary(NULL, NULL);
863 WMPLSetCaseSensitive(True);
865 /* save dock state to file */
866 if (!wPreferences.flags.nodock) {
867 wDockSaveState(scr, old_state);
868 } else {
869 if ((foo = WMGetFromPLDictionary(old_state, dDock)) != NULL) {
870 WMPutInPLDictionary(w_global.session_state, dDock, foo);
873 if (!wPreferences.flags.noclip) {
874 wClipSaveState(scr);
875 } else {
876 if ((foo = WMGetFromPLDictionary(old_state, dClip)) != NULL) {
877 WMPutInPLDictionary(w_global.session_state, dClip, foo);
881 wWorkspaceSaveState(scr, old_state);
883 if (!wPreferences.flags.nodrawer) {
884 wDrawersSaveState(scr);
885 } else {
886 if ((foo = WMGetFromPLDictionary(old_state, dDrawers)) != NULL) {
887 WMPutInPLDictionary(w_global.session_state, dDrawers, foo);
892 if (wPreferences.save_session_on_exit) {
893 wSessionSaveState(scr);
894 } else {
895 if ((foo = WMGetFromPLDictionary(old_state, dApplications)) != NULL) {
896 WMPutInPLDictionary(w_global.session_state, dApplications, foo);
898 if ((foo = WMGetFromPLDictionary(old_state, dWorkspace)) != NULL) {
899 WMPutInPLDictionary(w_global.session_state, dWorkspace, foo);
903 /* clean up */
904 WMPLSetCaseSensitive(False);
906 wMenuSaveState(scr);
908 if (w_global.screen_count == 1) {
909 str = wdefaultspathfordomain("WMState");
910 } else {
911 char buf[16];
912 snprintf(buf, sizeof(buf), "WMState.%i", scr->screen);
913 str = wdefaultspathfordomain(buf);
915 if (!WMWritePropListToFile(w_global.session_state, str)) {
916 werror(_("could not save session state in %s"), str);
918 wfree(str);
919 WMReleasePropList(old_state);
922 int wScreenBringInside(WScreen * scr, int *x, int *y, int width, int height)
924 int moved = 0;
925 int tol_w, tol_h;
927 * With respect to the head that contains most of the window.
929 int sx1, sy1, sx2, sy2;
931 WMRect rect;
932 int head, flags;
934 rect.pos.x = *x;
935 rect.pos.y = *y;
936 rect.size.width = width;
937 rect.size.height = height;
939 head = wGetRectPlacementInfo(scr, rect, &flags);
940 rect = wGetRectForHead(scr, head);
942 sx1 = rect.pos.x;
943 sy1 = rect.pos.y;
944 sx2 = sx1 + rect.size.width;
945 sy2 = sy1 + rect.size.height;
947 #if 0 /* NOTE: gives funky group movement */
948 if (flags & XFLAG_MULTIPLE) {
950 * since we span multiple heads, pull window totaly inside
952 if (*x < sx1)
953 *x = sx1, moved = 1;
954 else if (*x + width > sx2)
955 *x = sx2 - width, moved = 1;
957 if (*y < sy1)
958 *y = sy1, moved = 1;
959 else if (*y + height > sy2)
960 *y = sy2 - height, moved = 1;
962 return moved;
964 #endif
966 if (width > 20)
967 tol_w = width / 2;
968 else
969 tol_w = 20;
971 if (height > 20)
972 tol_h = height / 2;
973 else
974 tol_h = 20;
976 if (*x + width < sx1 + 10)
977 *x = sx1 - tol_w, moved = 1;
978 else if (*x >= sx2 - 10)
979 *x = sx2 - tol_w - 1, moved = 1;
981 if (*y < sy1 - height + 10)
982 *y = sy1 - tol_h, moved = 1;
983 else if (*y >= sy2 - 10)
984 *y = sy2 - tol_h - 1, moved = 1;
986 return moved;
989 int wScreenKeepInside(WScreen * scr, int *x, int *y, int width, int height)
991 int moved = 0;
992 int sx1, sy1, sx2, sy2;
993 WMRect rect;
994 int head;
996 rect.pos.x = *x;
997 rect.pos.y = *y;
998 rect.size.width = width;
999 rect.size.height = height;
1001 head = wGetHeadForRect(scr, rect);
1002 rect = wGetRectForHead(scr, head);
1004 sx1 = rect.pos.x;
1005 sy1 = rect.pos.y;
1006 sx2 = sx1 + rect.size.width;
1007 sy2 = sy1 + rect.size.height;
1009 if (*x < sx1)
1010 *x = sx1, moved = 1;
1011 else if (*x + width > sx2)
1012 *x = sx2 - width, moved = 1;
1014 if (*y < sy1)
1015 *y = sy1, moved = 1;
1016 else if (*y + height > sy2)
1017 *y = sy2 - height, moved = 1;
1019 return moved;