syncing wtextfield.c
[wmaker-crm.git] / src / screen.c
blob0d352bb90d4386612ac4d5a77ee1806328aa3fd6
1 /* screen.c - screen management
2 *
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
32 #ifdef SHAPE
33 #include <X11/extensions/shape.h>
34 #endif
35 #ifdef KEEP_XKB_LOCK_STATUS
36 #include <X11/XKBlib.h>
37 #endif /* KEEP_XKB_LOCK_STATUS */
39 #include <wraster.h>
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
43 #include "screen.h"
44 #include "texture.h"
45 #include "pixmap.h"
46 #include "menu.h"
47 #include "funcs.h"
48 #include "actions.h"
49 #include "properties.h"
50 #include "dock.h"
51 #include "resources.h"
52 #include "workspace.h"
53 #include "session.h"
54 #include "balloon.h"
55 #ifdef KWM_HINTS
56 # include "kwm.h"
57 #endif
58 #ifdef GNOME_STUFF
59 # include "gnome.h"
60 #endif
61 #ifdef OLWM_HINTS
62 # include "openlook.h"
63 #endif
65 #include <proplist.h>
67 #include "defaults.h"
70 #ifdef LITE
71 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
72 |SubstructureNotifyMask|PointerMotionMask \
73 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
74 #else
75 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
76 |SubstructureNotifyMask|PointerMotionMask \
77 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
78 |KeyPressMask|KeyReleaseMask)
79 #endif
81 /**** Global variables ****/
83 extern Cursor wCursor[WCUR_LAST];
84 extern WPreferences wPreferences;
85 extern Atom _XA_WINDOWMAKER_STATE;
86 extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
89 extern int wScreenCount;
91 #ifdef KEEP_XKB_LOCK_STATUS
92 extern int wXkbSupported;
93 #endif
95 extern WDDomain *WDWindowMaker;
98 /**** Local ****/
100 #define STIPPLE_WIDTH 2
101 #define STIPPLE_HEIGHT 2
102 static char STIPPLE_DATA[] = {0x02, 0x01};
104 static int CantManageScreen = 0;
106 static proplist_t dApplications = NULL;
107 static proplist_t dWorkspace;
108 static proplist_t dDock;
109 static proplist_t dClip;
112 static void
113 make_keys()
115 if (dApplications!=NULL)
116 return;
118 dApplications = PLMakeString("Applications");
119 dWorkspace = PLMakeString("Workspace");
120 dDock = PLMakeString("Dock");
121 dClip = PLMakeString("Clip");
126 *----------------------------------------------------------------------
127 * alreadyRunningError--
128 * X error handler used to catch errors when trying to do
129 * XSelectInput() on the root window. These errors probably mean that
130 * there already is some other window manager running.
132 * Returns:
133 * Nothing, unless something really evil happens...
135 * Side effects:
136 * CantManageScreen is set to 1;
137 *----------------------------------------------------------------------
139 static int
140 alreadyRunningError(Display *dpy, XErrorEvent *error)
142 CantManageScreen = 1;
143 return -1;
148 *----------------------------------------------------------------------
149 * allocButtonPixmaps--
150 * Allocate pixmaps used on window operation buttons (those in the
151 * titlebar). The pixmaps are linked to the program. If XPM is supported
152 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
154 * Returns:
155 * Nothing
157 * Side effects:
158 * Allocates shared pixmaps for the screen. These pixmaps should
159 * not be freed by anybody.
160 *----------------------------------------------------------------------
162 static void
163 allocButtonPixmaps(WScreen *scr)
165 WPixmap *pix;
167 /* create predefined pixmaps */
168 pix = wPixmapCreateFromXPMData(scr, PRED_CLOSE_XPM);
169 if (pix)
170 pix->shared = 1;
171 scr->b_pixmaps[WBUT_CLOSE] = pix;
173 pix = wPixmapCreateFromXPMData(scr, PRED_BROKEN_CLOSE_XPM);
174 if (pix)
175 pix->shared = 1;
176 scr->b_pixmaps[WBUT_BROKENCLOSE] = pix;
178 pix = wPixmapCreateFromXPMData(scr, PRED_ICONIFY_XPM);
179 if (pix)
180 pix->shared = 1;
181 scr->b_pixmaps[WBUT_ICONIFY] = pix;
182 #ifdef XKB_BUTTON_HINT
183 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP1_XPM);
184 if (pix)
185 pix->shared = 1;
186 scr->b_pixmaps[WBUT_XKBGROUP1] = pix;
187 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP2_XPM);
188 if (pix)
189 pix->shared = 1;
190 scr->b_pixmaps[WBUT_XKBGROUP2] = pix;
191 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP3_XPM);
192 if (pix)
193 pix->shared = 1;
194 scr->b_pixmaps[WBUT_XKBGROUP3] = pix;
195 pix = wPixmapCreateFromXPMData(scr, PRED_XKBGROUP4_XPM);
196 if (pix)
197 pix->shared = 1;
198 scr->b_pixmaps[WBUT_XKBGROUP4] = pix;
199 #endif
202 pix = wPixmapCreateFromXPMData(scr, PRED_KILL_XPM);
203 if (pix)
204 pix->shared = 1;
205 scr->b_pixmaps[WBUT_KILL] = pix;
209 static void
210 draw_dot(WScreen *scr, Drawable d, int x, int y, GC gc)
212 XSetForeground(dpy, gc, scr->black_pixel);
213 XDrawLine(dpy, d, gc, x, y, x+1, y);
214 XDrawPoint(dpy, d, gc, x, y+1);
215 XSetForeground(dpy, gc, scr->white_pixel);
216 XDrawLine(dpy, d, gc, x+2, y, x+2, y+1);
217 XDrawPoint(dpy, d, gc, x+1, y+1);
221 static WPixmap*
222 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,
231 wPreferences.icon_size, scr->w_depth);
232 XSetForeground(dpy, gc, scr->black_pixel);
233 XFillRectangle(dpy, pix, gc, 0, 0, wPreferences.icon_size,
234 wPreferences.icon_size);
235 XSetForeground(dpy, gc, scr->white_pixel);
236 draw_dot(scr, pix, 4, wPreferences.icon_size-6, gc);
237 draw_dot(scr, pix, 9, wPreferences.icon_size-6, gc);
238 draw_dot(scr, pix, 14, wPreferences.icon_size-6, gc);
240 mask = XCreatePixmap(dpy, scr->w_win, wPreferences.icon_size,
241 wPreferences.icon_size, 1);
242 gcv.foreground = 0;
243 gcv.graphics_exposures = False;
244 gc2 = XCreateGC(dpy, mask, GCForeground|GCGraphicsExposures, &gcv);
245 XFillRectangle(dpy, mask, gc2, 0, 0, wPreferences.icon_size,
246 wPreferences.icon_size);
247 XSetForeground(dpy, gc2, 1);
248 XFillRectangle(dpy, mask, gc2, 4, wPreferences.icon_size-6, 3, 2);
249 XFillRectangle(dpy, mask, gc2, 9, wPreferences.icon_size-6, 3, 2);
250 XFillRectangle(dpy, mask, gc2, 14, wPreferences.icon_size-6, 3, 2);
252 XFreeGC(dpy, gc2);
254 wpix = wPixmapCreate(scr, pix, mask);
255 wpix->shared = 1;
257 return wpix;
261 static void
262 allocGCs(WScreen *scr)
264 XGCValues gcv;
265 XColor color;
266 unsigned long mtextcolor;
267 int gcm;
269 scr->stipple_bitmap =
270 XCreateBitmapFromData(dpy, scr->w_win, STIPPLE_DATA, STIPPLE_WIDTH,
271 STIPPLE_HEIGHT);
273 gcv.stipple = scr->stipple_bitmap;
274 gcv.foreground = scr->white_pixel;
275 gcv.fill_style = FillStippled;
276 gcv.graphics_exposures = False;
277 gcm = GCForeground|GCStipple|GCFillStyle|GCGraphicsExposures;
278 scr->stipple_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
281 /* selected icon border GCs */
282 gcv.function = GXcopy;
283 gcv.foreground = scr->white_pixel;
284 gcv.background = scr->black_pixel;
285 gcv.line_width = 1;
286 gcv.line_style = LineDoubleDash;
287 gcv.fill_style = FillSolid;
288 gcv.dash_offset = 0;
289 gcv.dashes = 4;
290 gcv.graphics_exposures = False;
292 gcm = GCFunction | GCGraphicsExposures;
293 gcm |= GCForeground | GCBackground;
294 gcm |= GCLineWidth | GCLineStyle;
295 gcm |= GCFillStyle;
296 gcm |= GCDashOffset | GCDashList;
298 scr->icon_select_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
300 gcm = GCForeground|GCGraphicsExposures;
302 scr->menu_title_pixel[0] = scr->white_pixel;
303 gcv.foreground = scr->white_pixel;
304 gcv.graphics_exposures = False;
305 scr->menu_title_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
307 scr->mtext_pixel = scr->black_pixel;
308 mtextcolor = gcv.foreground = scr->black_pixel;
309 scr->menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
311 /* selected menu entry GC */
312 gcm = GCForeground|GCBackground|GCGraphicsExposures;
313 gcv.foreground = scr->white_pixel;
314 gcv.background = scr->white_pixel;
315 gcv.graphics_exposures = False;
316 scr->select_menu_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
318 /* disabled menu entry GC */
319 scr->dtext_pixel = scr->black_pixel;
320 gcm = GCForeground|GCBackground|GCStipple|GCGraphicsExposures;
321 gcv.stipple = scr->stipple_bitmap;
322 gcv.graphics_exposures = False;
323 scr->disabled_menu_entry_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
325 /* frame GC */
326 wGetColor(scr, DEF_FRAME_COLOR, &color);
327 gcv.function = GXxor;
328 /* this will raise the probability of the XORed color being different
329 * of the original color in PseudoColor when not all color cells are
330 * initialized */
331 if (DefaultVisual(dpy, scr->screen)->class==PseudoColor)
332 gcv.plane_mask = (1<<(scr->depth-1))|1;
333 else
334 gcv.plane_mask = AllPlanes;
335 gcv.foreground = color.pixel;
336 if (gcv.foreground == 0)
337 gcv.foreground = 1;
338 gcv.line_width = DEF_FRAME_THICKNESS;
339 gcv.subwindow_mode = IncludeInferiors;
340 gcv.graphics_exposures = False;
341 scr->frame_gc = XCreateGC(dpy, scr->root_win, GCForeground|GCGraphicsExposures
342 |GCFunction|GCSubwindowMode|GCLineWidth
343 |GCPlaneMask, &gcv);
345 /* line GC */
346 gcv.foreground = color.pixel;
348 if (gcv.foreground == 0)
349 /* XOR:ing with a zero is not going to be of much use, so
350 in that case, we somewhat arbitrarily xor with 17 instead. */
351 gcv.foreground = 17;
353 gcv.function = GXxor;
354 gcv.subwindow_mode = IncludeInferiors;
355 gcv.line_width = 1;
356 gcv.cap_style = CapRound;
357 gcv.graphics_exposures = False;
358 gcm = GCForeground|GCFunction|GCSubwindowMode|GCLineWidth|GCCapStyle
359 |GCGraphicsExposures;
360 scr->line_gc = XCreateGC(dpy, scr->root_win, gcm, &gcv);
362 scr->line_pixel = gcv.foreground;
364 /* copy GC */
365 gcv.foreground = scr->white_pixel;
366 gcv.background = scr->black_pixel;
367 gcv.graphics_exposures = False;
368 scr->copy_gc = XCreateGC(dpy, scr->w_win, GCForeground|GCBackground
369 |GCGraphicsExposures, &gcv);
371 /* window title text GC */
372 gcv.graphics_exposures = False;
373 scr->window_title_gc = XCreateGC(dpy, scr->w_win,GCGraphicsExposures,&gcv);
375 /* icon title GC */
376 scr->icon_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
378 /* clip title GC */
379 scr->clip_title_gc = XCreateGC(dpy, scr->w_win, GCGraphicsExposures, &gcv);
381 /* move/size display GC */
382 gcv.graphics_exposures = False;
383 gcm = GCGraphicsExposures;
384 scr->info_text_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
386 /* misc drawing GC */
387 gcv.graphics_exposures = False;
388 gcm = GCGraphicsExposures;
389 scr->draw_gc = XCreateGC(dpy, scr->w_win, gcm, &gcv);
391 assert (scr->stipple_bitmap!=None);
394 /* mono GC */
395 scr->mono_gc = XCreateGC(dpy, scr->stipple_bitmap, gcm, &gcv);
400 static void
401 createPixmaps(WScreen *scr)
403 WPixmap *pix;
404 WMPixmap *wmpix;
405 RImage *image;
406 Pixmap p, m;
408 /* load pixmaps */
409 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_RADIO_INDICATOR_XBM_DATA,
410 (char*)MENU_RADIO_INDICATOR_XBM_DATA,
411 MENU_RADIO_INDICATOR_XBM_SIZE,
412 MENU_RADIO_INDICATOR_XBM_SIZE,
413 scr->black_pixel, scr->white_pixel);
414 if (pix!=NULL)
415 pix->shared = 1;
416 scr->menu_radio_indicator = pix;
419 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_CHECK_INDICATOR_XBM_DATA,
420 (char*)MENU_CHECK_INDICATOR_XBM_DATA,
421 MENU_CHECK_INDICATOR_XBM_SIZE,
422 MENU_CHECK_INDICATOR_XBM_SIZE,
423 scr->black_pixel, scr->white_pixel);
424 if (pix!=NULL)
425 pix->shared = 1;
426 scr->menu_check_indicator = pix;
428 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_MINI_INDICATOR_XBM_DATA,
429 (char*)MENU_MINI_INDICATOR_XBM_DATA,
430 MENU_MINI_INDICATOR_XBM_SIZE,
431 MENU_MINI_INDICATOR_XBM_SIZE,
432 scr->black_pixel, scr->white_pixel);
433 if (pix!=NULL)
434 pix->shared = 1;
435 scr->menu_mini_indicator = pix;
437 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_HIDE_INDICATOR_XBM_DATA,
438 (char*)MENU_HIDE_INDICATOR_XBM_DATA,
439 MENU_HIDE_INDICATOR_XBM_SIZE,
440 MENU_HIDE_INDICATOR_XBM_SIZE,
441 scr->black_pixel, scr->white_pixel);
442 if (pix!=NULL)
443 pix->shared = 1;
444 scr->menu_hide_indicator = pix;
446 pix = wPixmapCreateFromXBMData(scr, (char*)MENU_SHADE_INDICATOR_XBM_DATA,
447 (char*)MENU_SHADE_INDICATOR_XBM_DATA,
448 MENU_SHADE_INDICATOR_XBM_SIZE,
449 MENU_SHADE_INDICATOR_XBM_SIZE,
450 scr->black_pixel, scr->white_pixel);
451 if (pix!=NULL)
452 pix->shared = 1;
453 scr->menu_shade_indicator = pix;
456 image = wDefaultGetImage(scr, "Logo", "WMPanel");
458 if (!image) {
459 wwarning(_("could not load logo image for panels: %s"),
460 RMessageForError(RErrorCode));
461 } else {
462 if (!RConvertImageMask(scr->rcontext, image, &p, &m, 128)) {
463 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode));
464 } else {
465 wmpix = WMCreatePixmapFromXPixmaps(scr->wmscreen, p, m,
466 image->width, image->height,
467 scr->depth);
468 WMSetApplicationIconImage(scr->wmscreen, wmpix);
469 WMReleasePixmap(wmpix);
471 RDestroyImage(image);
474 scr->dock_dots = make3Dots(scr);
476 /* titlebar button pixmaps */
477 allocButtonPixmaps(scr);
482 *----------------------------------------------------------------------
483 * createInternalWindows--
484 * Creates some windows used internally by the program. One to
485 * receive input focus when no other window can get it and another
486 * to display window geometry information during window resize/move.
488 * Returns:
489 * Nothing
491 * Side effects:
492 * Windows are created and some colors are allocated for the
493 * window background.
494 *----------------------------------------------------------------------
496 static void
497 createInternalWindows(WScreen *scr)
499 int vmask;
500 XSetWindowAttributes attribs;
502 /* window for displaying geometry information during resizes and moves */
503 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
504 attribs.border_pixel = scr->black_pixel;
505 attribs.save_under = True;
506 attribs.override_redirect = True;
507 attribs.cursor = wCursor[WCUR_DEFAULT];
508 attribs.background_pixmap = None;
509 if (scr->widget_texture)
510 attribs.background_pixel = scr->widget_texture->normal.pixel;
511 else
512 attribs.background_pixel = scr->light_pixel;
513 vmask |= CWColormap;
514 attribs.colormap = scr->w_colormap;
516 wGetGeometryWindowSize(scr, &scr->geometry_display_width,
517 &scr->geometry_display_height);
518 scr->geometry_display =
519 XCreateWindow(dpy, scr->root_win, 1, 1,
520 scr->geometry_display_width,
521 scr->geometry_display_height,
522 1, scr->w_depth, CopyFromParent, scr->w_visual,
523 vmask, &attribs);
525 /* InputOnly window to get the focus when no other window can get it */
526 vmask = CWEventMask|CWOverrideRedirect;
527 attribs.event_mask = KeyPressMask|FocusChangeMask;
528 attribs.override_redirect = True;
529 scr->no_focus_win=XCreateWindow(dpy,scr->root_win,-10, -10, 4, 4, 0, 0,
530 InputOnly,CopyFromParent, vmask, &attribs);
531 XSelectInput(dpy, scr->no_focus_win, KeyPressMask|KeyReleaseMask);
532 XMapWindow(dpy, scr->no_focus_win);
534 XSetInputFocus(dpy, scr->no_focus_win, RevertToParent, CurrentTime);
536 /* shadow window for dock buttons */
537 vmask = CWBorderPixel|CWBackPixmap|CWBackPixel|CWCursor|CWSaveUnder|CWOverrideRedirect;
538 attribs.border_pixel = scr->black_pixel;
539 attribs.save_under = True;
540 attribs.override_redirect = True;
541 attribs.background_pixmap = None;
542 attribs.background_pixel = scr->white_pixel;
543 vmask |= CWColormap;
544 attribs.colormap = scr->w_colormap;
545 scr->dock_shadow =
546 XCreateWindow(dpy, scr->root_win, 0, 0, wPreferences.icon_size,
547 wPreferences.icon_size, 0, scr->w_depth, CopyFromParent,
548 scr->w_visual, vmask, &attribs);
550 /* workspace name balloon for clip */
551 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
552 |CWBorderPixel;
553 attribs.save_under = True;
554 attribs.override_redirect = True;
555 attribs.colormap = scr->w_colormap;
556 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
557 attribs.border_pixel = 0; /* do not care */
558 scr->clip_balloon =
559 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
560 CopyFromParent, scr->w_visual, vmask, &attribs);
563 /* workspace name */
564 vmask = CWBackPixel|CWSaveUnder|CWOverrideRedirect|CWColormap
565 |CWBorderPixel;
566 attribs.save_under = True;
567 attribs.override_redirect = True;
568 attribs.colormap = scr->w_colormap;
569 attribs.background_pixel = scr->icon_back_texture->normal.pixel;
570 attribs.border_pixel = 0; /* do not care */
571 scr->workspace_name =
572 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, scr->w_depth,
573 CopyFromParent, scr->w_visual, vmask, &attribs);
576 /* for our window manager info notice board */
577 scr->info_window =
578 XCreateWindow(dpy, scr->root_win, 0, 0, 10, 10, 0, CopyFromParent,
579 CopyFromParent, CopyFromParent, CWOverrideRedirect,
580 &attribs);
583 * If the window is clicked without having ButtonPress selected, the
584 * resulting event will have event.xbutton.window == root.
586 XSelectInput(dpy, scr->clip_balloon, ButtonPressMask);
590 #if 0
591 static Bool
592 aquireManagerSelection(WScreen *scr)
594 char buffer[32];
595 XEvent ev;
596 Time timestamp;
598 sprintf(buffer, "WM_S%i", scr->screen);
599 scr->managerAtom = XInternAtom(dpy, buffer, False);
601 /* for race-conditions... */
602 XGrabServer(dpy);
604 /* if there is another manager running, don't try to replace it
605 * (for now, at least) */
606 if (XGetSelectionOwner(dpy, scr->managerAtom) != None) {
607 XUngrabServer(dpy);
608 return False;
611 /* become the manager for this screen */
613 scr->managerWindow = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 1, 1,
614 0, 0, 0);
616 XSelectInput(dpy, scr->managerWindow, PropertyChangeMask);
617 /* get a timestamp */
618 XChangeProperty(dpy, scr->managerWindow, scr->managerAtom,
619 XA_INTEGER, 32, PropModeAppend, NULL, 0);
620 while (1) {
621 XWindowEvent(dpy, scr->managerWindow, &ev);
622 if (ev.type == PropertyNotify) {
623 timestamp = ev.xproperty.time;
624 break;
627 XSelectInput(dpy, scr->managerWindow, NoEvents);
628 XDeleteProperty(dpy, scr->managerWindow, scr->managerAtom);
630 XSetSelectionOwner(dpy, scr->managerAtom, scr->managerWindow, CurrentTime);
632 XUngrabServer(dpy);
634 /* announce our arrival */
636 ev.xclient.type = ClientMessage;
637 ev.xclient.message_type = XInternAtom(dpy, "MANAGER", False);
638 ev.xclient.destination = scr->root_win;
639 ev.xclient.format = 32;
640 ev.xclient.data.l[0] = timestamp;
641 ev.xclient.data.l[1] = scr->managerAtom;
642 ev.xclient.data.l[2] = scr->managerWindow;
643 ev.xclient.data.l[3] = 0;
644 ev.xclient.data.l[4] = 0;
646 XSendEvent(dpy, scr->root_win, False, StructureNotify, &ev);
647 XSync(dpy, False);
649 return True;
651 #endif
654 *----------------------------------------------------------------------
655 * wScreenInit--
656 * Initializes the window manager for the given screen and
657 * allocates a WScreen descriptor for it. Many resources are allocated
658 * for the screen and the root window is setup appropriately.
660 * Returns:
661 * The WScreen descriptor for the screen.
663 * Side effects:
664 * Many resources are allocated and the IconSize property is
665 * set on the root window.
666 * The program can be aborted if some fatal error occurs.
668 * TODO: User specifiable visual.
669 *----------------------------------------------------------------------
671 WScreen*
672 wScreenInit(int screen_number)
674 WScreen *scr;
675 XIconSize icon_size[1];
676 RContextAttributes rattr;
677 extern int wVisualID;
678 long event_mask;
679 WMColor *color;
680 XErrorHandler oldHandler;
682 scr = wmalloc(sizeof(WScreen));
683 memset(scr, 0, sizeof(WScreen));
685 /* initialize globals */
686 scr->screen = screen_number;
687 scr->root_win = RootWindow(dpy, screen_number);
688 scr->depth = DefaultDepth(dpy, screen_number);
689 scr->colormap = DefaultColormap(dpy, screen_number);
691 scr->scr_width = WidthOfScreen(ScreenOfDisplay(dpy, screen_number));
692 scr->scr_height = HeightOfScreen(ScreenOfDisplay(dpy, screen_number));
694 scr->usableArea.x2 = scr->scr_width;
695 scr->usableArea.y2 = scr->scr_height;
696 scr->totalUsableArea.x2 = scr->scr_width;
697 scr->totalUsableArea.y2 = scr->scr_height;
699 #if 0
700 if (!aquireManagerSelection(scr)) {
701 free(scr);
703 return NULL;
705 #endif
706 CantManageScreen = 0;
707 oldHandler = XSetErrorHandler((XErrorHandler)alreadyRunningError);
709 event_mask = EVENT_MASK;
711 if (wPreferences.disable_root_mouse) {
712 event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
715 XSelectInput(dpy, scr->root_win, event_mask);
717 #ifdef KEEP_XKB_LOCK_STATUS
718 /* Only GroupLock doesn't work correctly in my system since right-alt
719 * can change mode while holding it too - ]d
721 if (wXkbSupported) {
722 XkbSelectEvents(dpy,XkbUseCoreKbd,
723 XkbStateNotifyMask,
724 XkbStateNotifyMask);
726 #endif /* KEEP_XKB_LOCK_STATUS */
728 XSync(dpy, False);
729 XSetErrorHandler(oldHandler);
731 if (CantManageScreen) {
732 free(scr);
733 return NULL;
736 XDefineCursor(dpy, scr->root_win, wCursor[WCUR_DEFAULT]);
738 /* screen descriptor for raster graphic library */
739 rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
740 rattr.render_mode = wPreferences.no_dithering
741 ? RBestMatchRendering
742 : RDitheredRendering;
744 rattr.colors_per_channel = wPreferences.cmap_size;
745 if (rattr.colors_per_channel<2)
746 rattr.colors_per_channel = 2;
748 if (wVisualID>=0) {
749 rattr.flags |= RC_VisualID;
750 rattr.visualid = wVisualID;
752 scr->rcontext = RCreateContext(dpy, screen_number, &rattr);
753 if (!scr->rcontext) {
754 wwarning(_("could not initialize graphics library context: %s"),
755 RMessageForError(RErrorCode));
756 wAbort(False);
757 } else {
758 char **formats;
759 int i = 0;
761 formats = RSupportedFileFormats();
762 if (formats) {
763 for (i=0; formats[i]!=NULL; i++) {
764 if (strcmp(formats[i], "TIFF")==0) {
765 scr->flags.supports_tiff = 1;
766 break;
772 scr->w_win = scr->rcontext->drawable;
773 scr->w_visual = scr->rcontext->visual;
774 scr->w_depth = scr->rcontext->depth;
775 scr->w_colormap = scr->rcontext->cmap;
777 scr->black_pixel = scr->rcontext->black;
778 scr->white_pixel = scr->rcontext->white;
780 /* create screen descriptor for WINGs */
781 scr->wmscreen = WMCreateScreenWithRContext(dpy, screen_number,
782 scr->rcontext);
784 if (!scr->wmscreen) {
785 wfatal(_("could not do initialization of WINGs widget set"));
787 return NULL;
790 color = WMGrayColor(scr->wmscreen);
791 scr->light_pixel = WMColorPixel(color);
792 WMReleaseColor(color);
794 color = WMDarkGrayColor(scr->wmscreen);
795 scr->dark_pixel = WMColorPixel(color);
796 WMReleaseColor(color);
799 XColor xcol;
800 /* frame boder color */
801 wGetColor(scr, FRAME_BORDER_COLOR, &xcol);
802 scr->frame_border_pixel = xcol.pixel;
805 /* create GCs with default values */
806 allocGCs(scr);
808 /* read defaults for this screen */
809 wReadDefaults(scr, WDWindowMaker->dictionary);
811 createInternalWindows(scr);
813 #ifdef KWM_HINTS
814 wKWMInitStuff(scr);
815 #endif
817 #ifdef GNOME_STUFF
818 wGNOMEInitStuff(scr);
819 #endif
821 #ifdef OLWM_HINTS
822 wOLWMInitStuff(scr);
823 #endif
825 /* create initial workspace */
826 wWorkspaceNew(scr);
828 /* create shared pixmaps */
829 createPixmaps(scr);
831 /* set icon sizes we can accept from clients */
832 icon_size[0].min_width = 8;
833 icon_size[0].min_height = 8;
834 icon_size[0].max_width = wPreferences.icon_size-4;
835 icon_size[0].max_height = wPreferences.icon_size-4;
836 icon_size[0].width_inc = 1;
837 icon_size[0].height_inc = 1;
838 XSetIconSizes(dpy, scr->root_win, icon_size, 1);
840 /* setup WindowMaker protocols property in the root window*/
841 PropSetWMakerProtocols(scr->root_win);
843 /* setup our noticeboard */
844 XChangeProperty(dpy, scr->info_window, _XA_WINDOWMAKER_NOTICEBOARD,
845 XA_WINDOW, 32, PropModeReplace,
846 (unsigned char*)&scr->info_window, 1);
847 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_NOTICEBOARD,
848 XA_WINDOW, 32, PropModeReplace,
849 (unsigned char*)&scr->info_window, 1);
852 #ifdef BALLOON_TEXT
853 /* initialize balloon text stuff */
854 wBalloonInitialize(scr);
855 #endif
857 wScreenUpdateUsableArea(scr);
860 return scr;
864 void
865 wScreenUpdateUsableArea(WScreen *scr)
867 #ifdef GNOME_STUFF
868 WReservedArea *area;
869 #endif
871 scr->totalUsableArea = scr->usableArea;
874 if (scr->dock && (!scr->dock->lowered
875 || wPreferences.no_window_over_dock)) {
877 int offset = wPreferences.icon_size + DOCK_EXTRA_SPACE;
879 if (scr->dock->on_right_side) {
880 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2,
881 scr->scr_width - offset);
882 } else {
883 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, offset);
887 if (wPreferences.no_window_over_icons) {
888 if (wPreferences.icon_yard & IY_VERT) {
890 if (!(wPreferences.icon_yard & IY_RIGHT)) {
891 scr->totalUsableArea.x1 += wPreferences.icon_size;
892 } else {
893 scr->totalUsableArea.x2 -= wPreferences.icon_size;
895 } else {
897 if (wPreferences.icon_yard & IY_TOP) {
898 scr->totalUsableArea.y1 += wPreferences.icon_size;
899 } else {
900 scr->totalUsableArea.y2 -= wPreferences.icon_size;
905 #ifdef KWM_HINTS
907 WArea area;
909 if (wKWMGetUsableArea(scr, &area)) {
910 scr->totalUsableArea.x1 = WMAX(scr->totalUsableArea.x1, area.x1);
911 scr->totalUsableArea.y1 = WMAX(scr->totalUsableArea.y1, area.y1);
912 scr->totalUsableArea.x2 = WMIN(scr->totalUsableArea.x2, area.x2);
913 scr->totalUsableArea.y2 = WMIN(scr->totalUsableArea.y2, area.y2);
916 #endif
918 #ifdef GNOME_STUFF
919 area = scr->reservedAreas;
921 while (area) {
922 int th, bh;
923 int lw, rw;
924 int w, h;
926 w = area->area.x2 - area->area.x1;
927 h = area->area.y2 - area->area.y1;
929 th = area->area.y1;
930 bh = scr->scr_height - area->area.y2;
931 lw = area->area.x1;
932 rw = scr->scr_width - area->area.x2;
934 if (WMIN(th, bh) < WMIN(lw, rw)) {
935 /* horizontal */
936 if (th < bh) {
937 /* on top */
938 if (scr->totalUsableArea.y1 < area->area.y2)
939 scr->totalUsableArea.y1 = area->area.y2;
940 } else {
941 /* on bottom */
942 if (scr->totalUsableArea.y2 > area->area.y1)
943 scr->totalUsableArea.y2 = area->area.y1;
945 } else {
946 /* vertical */
947 if (lw < rw) {
948 /* on left */
949 if (scr->totalUsableArea.x1 < area->area.x2)
950 scr->totalUsableArea.x1 = area->area.x2;
951 } else {
952 /* on right */
953 if (scr->totalUsableArea.x2 > area->area.x1)
954 scr->totalUsableArea.x2 = area->area.x1;
958 area = area->next;
960 #endif /* GNOME_STUFF */
962 if (scr->totalUsableArea.x2 - scr->totalUsableArea.x1 < scr->scr_width/2) {
963 scr->totalUsableArea.x2 = scr->usableArea.x2;
964 scr->totalUsableArea.x1 = scr->usableArea.x1;
966 if (scr->totalUsableArea.y2 - scr->totalUsableArea.y1 < scr->scr_height/2) {
967 scr->totalUsableArea.y2 = scr->usableArea.y2;
968 scr->totalUsableArea.y1 = scr->usableArea.y1;
971 #ifdef not_used
972 #ifdef KWM_HINTS
974 int i;
976 for (i = 0; i < scr->workspace_count; i++) {
977 wKWMSetUsableAreaHint(scr, i);
980 #endif
981 #endif
985 void
986 wScreenRestoreState(WScreen *scr)
988 proplist_t state;
989 char *path;
992 #ifndef LITE
993 OpenRootMenu(scr, -10000, -10000, False);
994 wMenuUnmap(scr->root_menu);
995 #endif
997 make_keys();
999 if (wScreenCount == 1)
1000 path = wdefaultspathfordomain("WMState");
1001 else {
1002 char buf[16];
1003 sprintf(buf, "WMState.%i", scr->screen);
1004 path = wdefaultspathfordomain(buf);
1006 scr->session_state = PLGetProplistWithPath(path);
1007 free(path);
1008 if (!scr->session_state && wScreenCount>1) {
1009 char buf[16];
1010 sprintf(buf, "WMState.%i", scr->screen);
1011 path = wdefaultspathfordomain(buf);
1012 scr->session_state = PLGetProplistWithPath(path);
1013 free(path);
1016 if (!wPreferences.flags.noclip) {
1017 state = PLGetDictionaryEntry(scr->session_state, dClip);
1018 scr->clip_icon = wClipRestoreState(scr, state);
1021 wWorkspaceRestoreState(scr);
1023 if (!wPreferences.flags.nodock) {
1024 state = PLGetDictionaryEntry(scr->session_state, dDock);
1025 scr->dock = wDockRestoreState(scr, state, WM_DOCK);
1028 wScreenUpdateUsableArea(scr);
1032 void
1033 wScreenSaveState(WScreen *scr)
1035 WWorkspaceState wstate;
1036 WWindow *wwin;
1037 char *str;
1038 proplist_t path, old_state, foo;
1039 CARD32 data[2];
1042 make_keys();
1045 * Save current workspace, so can go back to it upon restart.
1047 wstate.workspace = scr->current_workspace;
1049 data[0] = wstate.flags;
1050 data[1] = wstate.workspace;
1052 XChangeProperty(dpy, scr->root_win, _XA_WINDOWMAKER_STATE,
1053 _XA_WINDOWMAKER_STATE, 32, PropModeReplace,
1054 (unsigned char *) data, 2);
1056 /* save state of windows */
1057 wwin = scr->focused_window;
1058 while (wwin) {
1059 wWindowSaveState(wwin);
1060 wwin = wwin->prev;
1064 if (wPreferences.flags.noupdates)
1065 return;
1068 old_state = scr->session_state;
1069 scr->session_state = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
1071 PLSetStringCmpHook(NULL);
1073 /* save dock state to file */
1074 if (!wPreferences.flags.nodock) {
1075 wDockSaveState(scr, old_state);
1076 } else {
1077 if ((foo = PLGetDictionaryEntry(old_state, dDock))!=NULL) {
1078 PLInsertDictionaryEntry(scr->session_state, dDock, foo);
1081 if (!wPreferences.flags.noclip) {
1082 wClipSaveState(scr);
1083 } else {
1084 if ((foo = PLGetDictionaryEntry(old_state, dClip))!=NULL) {
1085 PLInsertDictionaryEntry(scr->session_state, dClip, foo);
1089 wWorkspaceSaveState(scr, old_state);
1091 if (wPreferences.save_session_on_exit) {
1092 wSessionSaveState(scr);
1093 } else {
1094 if ((foo = PLGetDictionaryEntry(old_state, dApplications))!=NULL) {
1095 PLInsertDictionaryEntry(scr->session_state, dApplications, foo);
1097 if ((foo = PLGetDictionaryEntry(old_state, dWorkspace))!=NULL) {
1098 PLInsertDictionaryEntry(scr->session_state, dWorkspace, foo);
1102 /* clean up */
1103 PLSetStringCmpHook(StringCompareHook);
1105 wMenuSaveState(scr);
1107 if (wScreenCount == 1)
1108 str = wdefaultspathfordomain("WMState");
1109 else {
1110 char buf[16];
1111 sprintf(buf, "WMState.%i", scr->screen);
1112 str = wdefaultspathfordomain(buf);
1114 path = PLMakeString(str);
1115 free(str);
1116 PLSetFilename(scr->session_state, path);
1117 if (!PLSave(scr->session_state, YES)) {
1118 wsyserror(_("could not save session state in %s"), PLGetString(path));
1120 PLRelease(path);
1121 PLRelease(old_state);
1127 wScreenBringInside(WScreen *scr, int *x, int *y, int width, int height)
1129 int moved = 0;
1130 int tol_w, tol_h;
1132 if (width > 20)
1133 tol_w = width/2;
1134 else
1135 tol_w = 20;
1137 if (height > 20)
1138 tol_h = height/2;
1139 else
1140 tol_h = 20;
1142 if (*x+width < 10)
1143 *x = -tol_w, moved = 1;
1144 else if (*x >= scr->scr_width - 10)
1145 *x = scr->scr_width - tol_w - 1, moved = 1;
1147 if (*y < -height + 10)
1148 *y = -tol_h, moved = 1;
1149 else if (*y >= scr->scr_height - 10)
1150 *y = scr->scr_height - tol_h - 1, moved = 1;
1152 return moved;