1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
33 #include <X11/extensions/shape.h>
35 #ifdef KEEP_XKB_LOCK_STATUS
36 #include <X11/XKBlib.h>
37 #endif /* KEEP_XKB_LOCK_STATUS */
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
49 #include "properties.h"
51 #include "resources.h"
52 #include "workspace.h"
62 # include "openlook.h"
71 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
72 |SubstructureNotifyMask|PointerMotionMask \
73 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
75 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
76 |SubstructureNotifyMask|PointerMotionMask \
77 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
78 |KeyPressMask|KeyReleaseMask)
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
;
95 extern WDDomain
*WDWindowMaker
;
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
;
115 if (dApplications
!=NULL
)
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.
133 * Nothing, unless something really evil happens...
136 * CantManageScreen is set to 1;
137 *----------------------------------------------------------------------
140 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
142 CantManageScreen
= 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.
158 * Allocates shared pixmaps for the screen. These pixmaps should
159 * not be freed by anybody.
160 *----------------------------------------------------------------------
163 allocButtonPixmaps(WScreen
*scr
)
167 /* create predefined pixmaps */
168 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
171 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
173 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
176 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
178 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
181 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
182 #ifdef XKB_BUTTON_HINT
183 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
186 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
187 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
190 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
191 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
194 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
195 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
198 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
202 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
205 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
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);
222 make3Dots(WScreen
*scr
)
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);
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);
254 wpix
= wPixmapCreate(scr
, pix
, mask
);
262 allocGCs(WScreen
*scr
)
266 unsigned long mtextcolor
;
269 scr
->stipple_bitmap
=
270 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
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
;
286 gcv
.line_style
= LineDoubleDash
;
287 gcv
.fill_style
= FillSolid
;
290 gcv
.graphics_exposures
= False
;
292 gcm
= GCFunction
| GCGraphicsExposures
;
293 gcm
|= GCForeground
| GCBackground
;
294 gcm
|= GCLineWidth
| GCLineStyle
;
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
);
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
331 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
332 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
334 gcv
.plane_mask
= AllPlanes
;
335 gcv
.foreground
= color
.pixel
;
336 if (gcv
.foreground
== 0)
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
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. */
353 gcv
.function
= GXxor
;
354 gcv
.subwindow_mode
= IncludeInferiors
;
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
;
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
);
376 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
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
);
395 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
401 createPixmaps(WScreen
*scr
)
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
);
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
);
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
);
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
);
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
);
453 scr
->menu_shade_indicator
= pix
;
456 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
459 wwarning(_("could not load logo image for panels: %s"),
460 RMessageForError(RErrorCode
));
462 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
463 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
465 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
466 image
->width
, image
->height
,
468 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
469 WMReleasePixmap(wmpix
);
471 RDestroyImage(image
);
474 scr
->dock_dots
= make3Dots(scr
);
477 /* titlebar button pixmaps */
478 allocButtonPixmaps(scr
);
484 *----------------------------------------------------------------------
485 * createInternalWindows--
486 * Creates some windows used internally by the program. One to
487 * receive input focus when no other window can get it and another
488 * to display window geometry information during window resize/move.
494 * Windows are created and some colors are allocated for the
496 *----------------------------------------------------------------------
499 createInternalWindows(WScreen
*scr
)
502 XSetWindowAttributes attribs
;
504 /* window for displaying geometry information during resizes and moves */
505 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
506 attribs
.border_pixel
= 0;
507 attribs
.save_under
= True
;
508 attribs
.override_redirect
= True
;
509 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
510 attribs
.background_pixmap
= None
;
511 if (scr
->widget_texture
)
512 attribs
.background_pixel
= scr
->widget_texture
->normal
.pixel
;
514 attribs
.background_pixel
= scr
->light_pixel
;
516 attribs
.colormap
= scr
->w_colormap
;
518 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
519 &scr
->geometry_display_height
);
520 scr
->geometry_display
=
521 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
522 scr
->geometry_display_width
,
523 scr
->geometry_display_height
,
524 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
527 /* InputOnly window to get the focus when no other window can get it */
528 vmask
= CWEventMask
|CWOverrideRedirect
;
529 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
530 attribs
.override_redirect
= True
;
531 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
532 InputOnly
,CopyFromParent
, vmask
, &attribs
);
533 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
534 XMapWindow(dpy
, scr
->no_focus_win
);
536 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
538 /* shadow window for dock buttons */
539 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
540 attribs
.border_pixel
= 0;
541 attribs
.save_under
= True
;
542 attribs
.override_redirect
= True
;
543 attribs
.background_pixmap
= None
;
544 attribs
.background_pixel
= scr
->white_pixel
;
546 attribs
.colormap
= scr
->w_colormap
;
548 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
549 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
550 scr
->w_visual
, vmask
, &attribs
);
552 /* workspace name balloon for clip */
553 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
555 attribs
.save_under
= True
;
556 attribs
.override_redirect
= True
;
557 attribs
.colormap
= scr
->w_colormap
;
558 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
559 attribs
.border_pixel
= 0; /* do not care */
561 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
562 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
566 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
568 attribs
.save_under
= True
;
569 attribs
.override_redirect
= True
;
570 attribs
.colormap
= scr
->w_colormap
;
571 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
572 attribs
.border_pixel
= 0; /* do not care */
573 scr
->workspace_name
=
574 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
575 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
578 /* for our window manager info notice board */
580 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, CopyFromParent
,
581 CopyFromParent
, CopyFromParent
, CWOverrideRedirect
,
585 * If the window is clicked without having ButtonPress selected, the
586 * resulting event will have event.xbutton.window == root.
588 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
594 aquireManagerSelection(WScreen
*scr
)
600 sprintf(buffer
, "WM_S%i", scr
->screen
);
601 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
603 /* for race-conditions... */
606 /* if there is another manager running, don't try to replace it
607 * (for now, at least) */
608 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
613 /* become the manager for this screen */
615 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
618 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
619 /* get a timestamp */
620 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
621 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
623 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
624 if (ev
.type
== PropertyNotify
) {
625 timestamp
= ev
.xproperty
.time
;
629 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
630 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
632 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
636 /* announce our arrival */
638 ev
.xclient
.type
= ClientMessage
;
639 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
640 ev
.xclient
.destination
= scr
->root_win
;
641 ev
.xclient
.format
= 32;
642 ev
.xclient
.data
.l
[0] = timestamp
;
643 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
644 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
645 ev
.xclient
.data
.l
[3] = 0;
646 ev
.xclient
.data
.l
[4] = 0;
648 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
656 *----------------------------------------------------------------------
658 * Initializes the window manager for the given screen and
659 * allocates a WScreen descriptor for it. Many resources are allocated
660 * for the screen and the root window is setup appropriately.
663 * The WScreen descriptor for the screen.
666 * Many resources are allocated and the IconSize property is
667 * set on the root window.
668 * The program can be aborted if some fatal error occurs.
670 * TODO: User specifiable visual.
671 *----------------------------------------------------------------------
674 wScreenInit(int screen_number
)
677 XIconSize icon_size
[1];
678 RContextAttributes rattr
;
679 extern int wVisualID
;
682 XErrorHandler oldHandler
;
684 scr
= wmalloc(sizeof(WScreen
));
685 memset(scr
, 0, sizeof(WScreen
));
687 /* initialize globals */
688 scr
->screen
= screen_number
;
689 scr
->root_win
= RootWindow(dpy
, screen_number
);
690 scr
->depth
= DefaultDepth(dpy
, screen_number
);
691 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
693 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
694 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
696 scr
->usableArea
.x2
= scr
->scr_width
;
697 scr
->usableArea
.y2
= scr
->scr_height
;
698 scr
->totalUsableArea
.x2
= scr
->scr_width
;
699 scr
->totalUsableArea
.y2
= scr
->scr_height
;
702 if (!aquireManagerSelection(scr
)) {
708 CantManageScreen
= 0;
709 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
711 event_mask
= EVENT_MASK
;
713 if (wPreferences
.disable_root_mouse
) {
714 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
717 XSelectInput(dpy
, scr
->root_win
, event_mask
);
719 #ifdef KEEP_XKB_LOCK_STATUS
721 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
725 #endif /* KEEP_XKB_LOCK_STATUS */
728 XSetErrorHandler(oldHandler
);
730 if (CantManageScreen
) {
735 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
737 /* screen descriptor for raster graphic library */
738 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
739 rattr
.render_mode
= wPreferences
.no_dithering
740 ? RBestMatchRendering
741 : RDitheredRendering
;
743 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
744 if (rattr
.colors_per_channel
<2)
745 rattr
.colors_per_channel
= 2;
748 rattr
.flags
|= RC_VisualID
;
749 rattr
.visualid
= wVisualID
;
751 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
752 if (!scr
->rcontext
) {
753 wwarning(_("could not initialize graphics library context: %s"),
754 RMessageForError(RErrorCode
));
760 formats
= RSupportedFileFormats();
762 for (i
=0; formats
[i
]!=NULL
; i
++) {
763 if (strcmp(formats
[i
], "TIFF")==0) {
764 scr
->flags
.supports_tiff
= 1;
771 scr
->w_win
= scr
->rcontext
->drawable
;
772 scr
->w_visual
= scr
->rcontext
->visual
;
773 scr
->w_depth
= scr
->rcontext
->depth
;
774 scr
->w_colormap
= scr
->rcontext
->cmap
;
776 scr
->black_pixel
= scr
->rcontext
->black
;
777 scr
->white_pixel
= scr
->rcontext
->white
;
779 /* create screen descriptor for WINGs */
780 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
783 if (!scr
->wmscreen
) {
784 wfatal(_("could not do initialization of WINGs widget set"));
789 color
= WMGrayColor(scr
->wmscreen
);
790 scr
->light_pixel
= WMColorPixel(color
);
791 WMReleaseColor(color
);
793 color
= WMDarkGrayColor(scr
->wmscreen
);
794 scr
->dark_pixel
= WMColorPixel(color
);
795 WMReleaseColor(color
);
799 /* frame boder color */
800 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
801 scr
->frame_border_pixel
= xcol
.pixel
;
804 /* create GCs with default values */
807 /* read defaults for this screen */
808 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
810 createInternalWindows(scr
);
817 wGNOMEInitStuff(scr
);
824 /* create initial workspace */
827 /* create shared pixmaps */
830 /* set icon sizes we can accept from clients */
831 icon_size
[0].min_width
= 8;
832 icon_size
[0].min_height
= 8;
833 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
834 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
835 icon_size
[0].width_inc
= 1;
836 icon_size
[0].height_inc
= 1;
837 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
839 /* setup WindowMaker protocols property in the root window*/
840 PropSetWMakerProtocols(scr
->root_win
);
842 /* setup our noticeboard */
843 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
844 XA_WINDOW
, 32, PropModeReplace
,
845 (unsigned char*)&scr
->info_window
, 1);
846 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
847 XA_WINDOW
, 32, PropModeReplace
,
848 (unsigned char*)&scr
->info_window
, 1);
852 /* initialize balloon text stuff */
853 wBalloonInitialize(scr
);
856 wScreenUpdateUsableArea(scr
);
859 /* kluge to load menu configurations at startup */
860 OpenRootMenu(scr
, -10000, -10000, False
);
861 wMenuUnmap(scr
->root_menu
);
869 wScreenUpdateUsableArea(WScreen
*scr
)
875 scr
->totalUsableArea
= scr
->usableArea
;
878 if (scr
->dock
&& (!scr
->dock
->lowered
879 || wPreferences
.no_window_over_dock
)) {
881 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
883 if (scr
->dock
->on_right_side
) {
884 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
885 scr
->scr_width
- offset
);
887 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
891 if (wPreferences
.no_window_over_icons
) {
892 if (wPreferences
.icon_yard
& IY_VERT
) {
894 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
895 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
897 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
901 if (wPreferences
.icon_yard
& IY_TOP
) {
902 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
904 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
913 if (wKWMGetUsableArea(scr
, &area
)) {
914 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
915 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
916 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
917 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
923 area
= scr
->reservedAreas
;
930 w
= area
->area
.x2
- area
->area
.x1
;
931 h
= area
->area
.y2
- area
->area
.y1
;
934 bh
= scr
->scr_height
- area
->area
.y2
;
936 rw
= scr
->scr_width
- area
->area
.x2
;
938 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
942 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
943 scr
->totalUsableArea
.y1
= area
->area
.y2
;
946 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
947 scr
->totalUsableArea
.y2
= area
->area
.y1
;
953 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
954 scr
->totalUsableArea
.x1
= area
->area
.x2
;
957 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
958 scr
->totalUsableArea
.x2
= area
->area
.x1
;
964 #endif /* GNOME_STUFF */
966 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
967 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
968 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
970 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
971 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
972 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
980 for (i
= 0; i
< scr
->workspace_count
; i
++) {
981 wKWMSetUsableAreaHint(scr
, i
);
990 wScreenRestoreState(WScreen
*scr
)
997 if (wScreenCount
== 1)
998 path
= wdefaultspathfordomain("WMState");
1001 sprintf(buf
, "WMState.%i", scr
->screen
);
1002 path
= wdefaultspathfordomain(buf
);
1004 scr
->session_state
= PLGetProplistWithPath(path
);
1006 if (!scr
->session_state
&& wScreenCount
>1) {
1008 sprintf(buf
, "WMState.%i", scr
->screen
);
1009 path
= wdefaultspathfordomain(buf
);
1010 scr
->session_state
= PLGetProplistWithPath(path
);
1014 if (!wPreferences
.flags
.noclip
) {
1015 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
1016 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1019 wWorkspaceRestoreState(scr
);
1021 if (!wPreferences
.flags
.nodock
) {
1022 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
1023 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1026 wScreenUpdateUsableArea(scr
);
1031 wScreenSaveState(WScreen
*scr
)
1033 WWorkspaceState wstate
;
1036 proplist_t path
, old_state
, foo
;
1043 * Save current workspace, so can go back to it upon restart.
1045 wstate
.workspace
= scr
->current_workspace
;
1047 data
[0] = wstate
.flags
;
1048 data
[1] = wstate
.workspace
;
1050 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1051 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1052 (unsigned char *) data
, 2);
1054 /* save state of windows */
1055 wwin
= scr
->focused_window
;
1057 wWindowSaveState(wwin
);
1062 if (wPreferences
.flags
.noupdates
)
1066 old_state
= scr
->session_state
;
1067 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1069 PLSetStringCmpHook(NULL
);
1071 /* save dock state to file */
1072 if (!wPreferences
.flags
.nodock
) {
1073 wDockSaveState(scr
);
1075 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1076 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1079 if (!wPreferences
.flags
.noclip
) {
1080 wClipSaveState(scr
);
1082 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1083 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1087 wWorkspaceSaveState(scr
, old_state
);
1089 if (wPreferences
.save_session_on_exit
) {
1090 wSessionSaveState(scr
);
1092 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1093 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1095 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1096 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1101 PLSetStringCmpHook(StringCompareHook
);
1103 wMenuSaveState(scr
);
1105 if (wScreenCount
== 1)
1106 str
= wdefaultspathfordomain("WMState");
1109 sprintf(buf
, "WMState.%i", scr
->screen
);
1110 str
= wdefaultspathfordomain(buf
);
1112 path
= PLMakeString(str
);
1114 PLSetFilename(scr
->session_state
, path
);
1115 if (!PLSave(scr
->session_state
, YES
)) {
1116 wsyserror(_("could not save session state in %s"), PLGetString(path
));
1119 PLRelease(old_state
);
1125 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1141 *x
= -tol_w
, moved
= 1;
1142 else if (*x
>= scr
->scr_width
- 10)
1143 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1145 if (*y
< -height
+ 10)
1146 *y
= -tol_h
, moved
= 1;
1147 else if (*y
>= scr
->scr_height
- 10)
1148 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;