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 extern WDDomain
*WDWindowMaker
;
96 #define STIPPLE_WIDTH 2
97 #define STIPPLE_HEIGHT 2
98 static char STIPPLE_DATA
[] = {0x02, 0x01};
100 static int CantManageScreen
= 0;
102 static proplist_t dApplications
= NULL
;
103 static proplist_t dWorkspace
;
104 static proplist_t dDock
;
105 static proplist_t dClip
;
111 if (dApplications
!=NULL
)
114 dApplications
= PLMakeString("Applications");
115 dWorkspace
= PLMakeString("Workspace");
116 dDock
= PLMakeString("Dock");
117 dClip
= PLMakeString("Clip");
122 *----------------------------------------------------------------------
123 * alreadyRunningError--
124 * X error handler used to catch errors when trying to do
125 * XSelectInput() on the root window. These errors probably mean that
126 * there already is some other window manager running.
129 * Nothing, unless something really evil happens...
132 * CantManageScreen is set to 1;
133 *----------------------------------------------------------------------
136 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
138 CantManageScreen
= 1;
144 *----------------------------------------------------------------------
145 * allocButtonPixmaps--
146 * Allocate pixmaps used on window operation buttons (those in the
147 * titlebar). The pixmaps are linked to the program. If XPM is supported
148 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
154 * Allocates shared pixmaps for the screen. These pixmaps should
155 * not be freed by anybody.
156 *----------------------------------------------------------------------
159 allocButtonPixmaps(WScreen
*scr
)
163 /* create predefined pixmaps */
164 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
167 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
169 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
172 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
174 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
177 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
182 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
188 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
190 XSetForeground(dpy
, gc
, scr
->black_pixel
);
191 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
192 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
193 XSetForeground(dpy
, gc
, scr
->white_pixel
);
194 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
195 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
200 make3Dots(WScreen
*scr
)
208 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
209 wPreferences
.icon_size
, scr
->w_depth
);
210 XSetForeground(dpy
, gc
, scr
->black_pixel
);
211 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
212 wPreferences
.icon_size
);
213 XSetForeground(dpy
, gc
, scr
->white_pixel
);
214 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
215 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
216 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
218 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
219 wPreferences
.icon_size
, 1);
221 gcv
.graphics_exposures
= False
;
222 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
223 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
224 wPreferences
.icon_size
);
225 XSetForeground(dpy
, gc2
, 1);
226 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
227 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
228 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
232 wpix
= wPixmapCreate(scr
, pix
, mask
);
240 allocGCs(WScreen
*scr
)
244 unsigned long mtextcolor
;
247 scr
->stipple_bitmap
=
248 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
251 gcv
.stipple
= scr
->stipple_bitmap
;
252 gcv
.foreground
= scr
->white_pixel
;
253 gcv
.fill_style
= FillStippled
;
254 gcv
.graphics_exposures
= False
;
255 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
256 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
259 /* selected icon border GCs */
260 gcv
.function
= GXcopy
;
261 gcv
.foreground
= scr
->white_pixel
;
262 gcv
.background
= scr
->black_pixel
;
264 gcv
.line_style
= LineDoubleDash
;
265 gcv
.fill_style
= FillSolid
;
268 gcv
.graphics_exposures
= False
;
270 gcm
= GCFunction
| GCGraphicsExposures
;
271 gcm
|= GCForeground
| GCBackground
;
272 gcm
|= GCLineWidth
| GCLineStyle
;
274 gcm
|= GCDashOffset
| GCDashList
;
276 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
278 gcm
= GCForeground
|GCGraphicsExposures
;
280 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
281 gcv
.foreground
= scr
->white_pixel
;
282 gcv
.graphics_exposures
= False
;
283 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
285 scr
->mtext_pixel
= scr
->black_pixel
;
286 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
287 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
289 /* selected menu entry GC */
290 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
291 gcv
.foreground
= scr
->white_pixel
;
292 gcv
.background
= scr
->white_pixel
;
293 gcv
.graphics_exposures
= False
;
294 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
296 /* disabled menu entry GC */
297 scr
->dtext_pixel
= scr
->black_pixel
;
298 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
299 gcv
.stipple
= scr
->stipple_bitmap
;
300 gcv
.graphics_exposures
= False
;
301 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
304 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
305 gcv
.function
= GXxor
;
306 /* this will raise the probability of the XORed color being different
307 * of the original color in PseudoColor when not all color cells are
309 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
310 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
312 gcv
.plane_mask
= AllPlanes
;
313 gcv
.foreground
= color
.pixel
;
314 if (gcv
.foreground
== 0)
316 gcv
.line_width
= DEF_FRAME_THICKNESS
;
317 gcv
.subwindow_mode
= IncludeInferiors
;
318 gcv
.graphics_exposures
= False
;
319 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
320 |GCFunction
|GCSubwindowMode
|GCLineWidth
324 gcv
.foreground
= color
.pixel
;
326 if (gcv
.foreground
== 0)
327 /* XOR:ing with a zero is not going to be of much use, so
328 in that case, we somewhat arbitrarily xor with 17 instead. */
331 gcv
.function
= GXxor
;
332 gcv
.subwindow_mode
= IncludeInferiors
;
334 gcv
.cap_style
= CapRound
;
335 gcv
.graphics_exposures
= False
;
336 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
337 |GCGraphicsExposures
;
338 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
340 scr
->line_pixel
= gcv
.foreground
;
343 gcv
.foreground
= scr
->white_pixel
;
344 gcv
.background
= scr
->black_pixel
;
345 gcv
.graphics_exposures
= False
;
346 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
347 |GCGraphicsExposures
, &gcv
);
349 /* window title text GC */
350 gcv
.graphics_exposures
= False
;
351 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
354 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
357 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
359 /* move/size display GC */
360 gcv
.graphics_exposures
= False
;
361 gcm
= GCGraphicsExposures
;
362 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
364 /* misc drawing GC */
365 gcv
.graphics_exposures
= False
;
366 gcm
= GCGraphicsExposures
;
367 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
373 createPixmaps(WScreen
*scr
)
381 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
382 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
383 MENU_RADIO_INDICATOR_XBM_SIZE
,
384 MENU_RADIO_INDICATOR_XBM_SIZE
,
385 scr
->black_pixel
, scr
->white_pixel
);
388 scr
->menu_radio_indicator
= pix
;
391 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
392 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
393 MENU_CHECK_INDICATOR_XBM_SIZE
,
394 MENU_CHECK_INDICATOR_XBM_SIZE
,
395 scr
->black_pixel
, scr
->white_pixel
);
398 scr
->menu_check_indicator
= pix
;
400 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
401 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
402 MENU_MINI_INDICATOR_XBM_SIZE
,
403 MENU_MINI_INDICATOR_XBM_SIZE
,
404 scr
->black_pixel
, scr
->white_pixel
);
407 scr
->menu_mini_indicator
= pix
;
409 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
410 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
411 MENU_HIDE_INDICATOR_XBM_SIZE
,
412 MENU_HIDE_INDICATOR_XBM_SIZE
,
413 scr
->black_pixel
, scr
->white_pixel
);
416 scr
->menu_hide_indicator
= pix
;
418 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
419 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
420 MENU_SHADE_INDICATOR_XBM_SIZE
,
421 MENU_SHADE_INDICATOR_XBM_SIZE
,
422 scr
->black_pixel
, scr
->white_pixel
);
425 scr
->menu_shade_indicator
= pix
;
428 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
431 wwarning(_("could not load logo image for panels: %s"),
432 RMessageForError(RErrorCode
));
434 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
435 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
437 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
438 image
->width
, image
->height
,
440 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
441 WMReleasePixmap(wmpix
);
443 RDestroyImage(image
);
446 if (!wPreferences
.flags
.nodock
|| !wPreferences
.flags
.noclip
) {
447 scr
->dock_dots
= make3Dots(scr
);
450 /* titlebar button pixmaps */
451 allocButtonPixmaps(scr
);
456 *----------------------------------------------------------------------
457 * createInternalWindows--
458 * Creates some windows used internally by the program. One to
459 * receive input focus when no other window can get it and another
460 * to display window geometry information during window resize/move.
466 * Windows are created and some colors are allocated for the
468 *----------------------------------------------------------------------
471 createInternalWindows(WScreen
*scr
)
474 XSetWindowAttributes attribs
;
476 /* window for displaying geometry information during resizes and moves */
477 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
478 attribs
.border_pixel
= 0;
479 attribs
.save_under
= True
;
480 attribs
.override_redirect
= True
;
481 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
482 attribs
.background_pixmap
= None
;
483 if (scr
->resizebar_texture
[0])
484 attribs
.background_pixel
= scr
->resizebar_texture
[0]->normal
.pixel
;
486 attribs
.background_pixel
= scr
->light_pixel
;
488 attribs
.colormap
= scr
->w_colormap
;
490 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
491 &scr
->geometry_display_height
);
492 scr
->geometry_display
=
493 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
494 scr
->geometry_display_width
,
495 scr
->geometry_display_height
,
496 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
499 /* InputOnly window to get the focus when no other window can get it */
500 vmask
= CWEventMask
|CWOverrideRedirect
;
501 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
502 attribs
.override_redirect
= True
;
503 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
504 InputOnly
,CopyFromParent
, vmask
, &attribs
);
505 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
506 XMapWindow(dpy
, scr
->no_focus_win
);
508 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
510 /* shadow window for dock buttons */
511 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
512 attribs
.border_pixel
= 0;
513 attribs
.save_under
= True
;
514 attribs
.override_redirect
= True
;
515 attribs
.background_pixmap
= None
;
516 attribs
.background_pixel
= scr
->white_pixel
;
518 attribs
.colormap
= scr
->w_colormap
;
520 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
521 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
522 scr
->w_visual
, vmask
, &attribs
);
524 /* workspace name balloon for clip */
525 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
527 attribs
.save_under
= True
;
528 attribs
.override_redirect
= True
;
529 attribs
.colormap
= scr
->w_colormap
;
530 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
531 attribs
.border_pixel
= 0; /* do not care */
533 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
534 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
537 /* for our window manager info notice board */
539 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, CopyFromParent
,
540 CopyFromParent
, CopyFromParent
, CWOverrideRedirect
,
544 * If the window is clicked without having ButtonPress selected, the
545 * resulting event will have event.xbutton.window == root.
547 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
553 aquireManagerSelection(WScreen
*scr
)
559 sprintf(buffer
, "WM_S%i", scr
->screen
);
560 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
562 /* for race-conditions... */
565 /* if there is another manager running, don't try to replace it
566 * (for now, at least) */
567 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
572 /* become the manager for this screen */
574 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
577 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
578 /* get a timestamp */
579 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
580 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
582 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
583 if (ev
.type
== PropertyNotify
) {
584 timestamp
= ev
.xproperty
.time
;
588 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
589 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
591 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
595 /* announce our arrival */
597 ev
.xclient
.type
= ClientMessage
;
598 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
599 ev
.xclient
.destination
= scr
->root_win
;
600 ev
.xclient
.format
= 32;
601 ev
.xclient
.data
.l
[0] = timestamp
;
602 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
603 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
604 ev
.xclient
.data
.l
[3] = 0;
605 ev
.xclient
.data
.l
[4] = 0;
607 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
615 *----------------------------------------------------------------------
617 * Initializes the window manager for the given screen and
618 * allocates a WScreen descriptor for it. Many resources are allocated
619 * for the screen and the root window is setup appropriately.
622 * The WScreen descriptor for the screen.
625 * Many resources are allocated and the IconSize property is
626 * set on the root window.
627 * The program can be aborted if some fatal error occurs.
629 * TODO: User specifiable visual.
630 *----------------------------------------------------------------------
633 wScreenInit(int screen_number
)
636 XIconSize icon_size
[1];
637 RContextAttributes rattr
;
638 extern int wVisualID
;
641 XErrorHandler oldHandler
;
643 scr
= wmalloc(sizeof(WScreen
));
644 memset(scr
, 0, sizeof(WScreen
));
646 /* initialize globals */
647 scr
->screen
= screen_number
;
648 scr
->root_win
= RootWindow(dpy
, screen_number
);
649 scr
->depth
= DefaultDepth(dpy
, screen_number
);
650 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
652 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
653 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
655 scr
->usableArea
.x2
= scr
->scr_width
;
656 scr
->usableArea
.y2
= scr
->scr_height
;
657 scr
->totalUsableArea
.x2
= scr
->scr_width
;
658 scr
->totalUsableArea
.y2
= scr
->scr_height
;
661 if (!aquireManagerSelection(scr
)) {
667 CantManageScreen
= 0;
668 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
670 event_mask
= EVENT_MASK
;
672 if (wPreferences
.disable_root_mouse
) {
673 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
676 XSelectInput(dpy
, scr
->root_win
, event_mask
);
678 #ifdef KEEP_XKB_LOCK_STATUS
679 XkbSelectEvents(dpy
,XkbUseCoreKbd
,XkbIndicatorStateNotifyMask
,
680 XkbIndicatorStateNotifyMask
);
681 #endif /* KEEP_XKB_LOCK_STATUS */
684 XSetErrorHandler(oldHandler
);
686 if (CantManageScreen
) {
691 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
693 /* screen descriptor for raster graphic library */
694 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
695 rattr
.render_mode
= wPreferences
.no_dithering
?RM_MATCH
:RM_DITHER
;
696 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
697 if (rattr
.colors_per_channel
<2)
698 rattr
.colors_per_channel
= 2;
701 rattr
.flags
|= RC_VisualID
;
702 rattr
.visualid
= wVisualID
;
704 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
705 if (!scr
->rcontext
) {
706 wwarning(_("could not initialize graphics library context: %s"),
707 RMessageForError(RErrorCode
));
713 formats
= RSupportedFileFormats();
715 for (i
=0; formats
[i
]!=NULL
; i
++) {
716 if (strcmp(formats
[i
], "TIFF")==0) {
717 scr
->flags
.supports_tiff
= 1;
724 scr
->w_win
= scr
->rcontext
->drawable
;
725 scr
->w_visual
= scr
->rcontext
->visual
;
726 scr
->w_depth
= scr
->rcontext
->depth
;
727 scr
->w_colormap
= scr
->rcontext
->cmap
;
729 scr
->black_pixel
= scr
->rcontext
->black
;
730 scr
->white_pixel
= scr
->rcontext
->white
;
732 /* create screen descriptor for WINGs */
733 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
736 if (!scr
->wmscreen
) {
737 wfatal(_("could not do initialization of WINGs widget set"));
742 color
= WMGrayColor(scr
->wmscreen
);
743 scr
->light_pixel
= WMColorPixel(color
);
744 WMReleaseColor(color
);
746 color
= WMDarkGrayColor(scr
->wmscreen
);
747 scr
->dark_pixel
= WMColorPixel(color
);
748 WMReleaseColor(color
);
752 /* frame boder color */
753 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
754 scr
->frame_border_pixel
= xcol
.pixel
;
757 /* create GCs with default values */
760 /* read defaults for this screen */
761 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
763 createInternalWindows(scr
);
770 wGNOMEInitStuff(scr
);
777 /* create initial workspace */
780 /* create shared pixmaps */
783 /* set icon sizes we can accept from clients */
784 icon_size
[0].min_width
= 8;
785 icon_size
[0].min_height
= 8;
786 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
787 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
788 icon_size
[0].width_inc
= 1;
789 icon_size
[0].height_inc
= 1;
790 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
792 /* setup WindowMaker protocols property in the root window*/
793 PropSetWMakerProtocols(scr
->root_win
);
795 /* setup our noticeboard */
796 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
797 XA_WINDOW
, 32, PropModeReplace
,
798 (unsigned char*)&scr
->info_window
, 1);
799 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
800 XA_WINDOW
, 32, PropModeReplace
,
801 (unsigned char*)&scr
->info_window
, 1);
805 /* initialize balloon text stuff */
806 wBalloonInitialize(scr
);
809 wScreenUpdateUsableArea(scr
);
812 /* kluge to load menu configurations at startup */
813 OpenRootMenu(scr
, -10000, -10000, False
);
814 wMenuUnmap(scr
->root_menu
);
822 wScreenUpdateUsableArea(WScreen
*scr
)
828 scr
->totalUsableArea
= scr
->usableArea
;
831 if (scr
->dock
&& (!scr
->dock
->lowered
832 || wPreferences
.no_window_over_dock
)) {
834 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
836 if (scr
->dock
->on_right_side
) {
837 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
838 scr
->scr_width
- offset
);
840 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
844 if (wPreferences
.no_window_over_icons
) {
845 if (wPreferences
.icon_yard
& IY_VERT
) {
847 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
848 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
850 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
854 if (wPreferences
.icon_yard
& IY_TOP
) {
855 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
857 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
866 if (wKWMGetUsableArea(scr
, &area
)) {
867 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
868 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
869 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
870 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
876 area
= scr
->reservedAreas
;
883 w
= area
->area
.x2
- area
->area
.x1
;
884 h
= area
->area
.y2
- area
->area
.y1
;
887 bh
= scr
->scr_height
- area
->area
.y2
;
889 rw
= scr
->scr_width
- area
->area
.x2
;
891 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
895 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
896 scr
->totalUsableArea
.y1
= area
->area
.y2
;
899 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
900 scr
->totalUsableArea
.y2
= area
->area
.y1
;
906 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
907 scr
->totalUsableArea
.x1
= area
->area
.x2
;
910 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
911 scr
->totalUsableArea
.x2
= area
->area
.x1
;
917 #endif /* GNOME_STUFF */
919 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
920 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
921 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
923 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
924 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
925 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
933 for (i
= 0; i
< scr
->workspace_count
; i
++) {
934 wKWMSetUsableAreaHint(scr
, i
);
943 wScreenRestoreState(WScreen
*scr
)
950 if (wScreenCount
== 1)
951 path
= wdefaultspathfordomain("WMState");
954 sprintf(buf
, "WMState.%i", scr
->screen
);
955 path
= wdefaultspathfordomain(buf
);
957 scr
->session_state
= PLGetProplistWithPath(path
);
959 if (!scr
->session_state
&& wScreenCount
>1) {
961 sprintf(buf
, "WMState.%i", scr
->screen
);
962 path
= wdefaultspathfordomain(buf
);
963 scr
->session_state
= PLGetProplistWithPath(path
);
967 if (!wPreferences
.flags
.noclip
) {
968 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
969 scr
->clip_icon
= wClipRestoreState(scr
, state
);
972 wWorkspaceRestoreState(scr
);
974 if (!wPreferences
.flags
.nodock
) {
975 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
976 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
979 wScreenUpdateUsableArea(scr
);
984 wScreenSaveState(WScreen
*scr
)
986 WWorkspaceState wstate
;
989 proplist_t path
, old_state
, foo
;
996 * Save current workspace, so can go back to it upon restart.
998 wstate
.workspace
= scr
->current_workspace
;
1000 data
[0] = wstate
.flags
;
1001 data
[1] = wstate
.workspace
;
1003 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1004 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1005 (unsigned char *) data
, 2);
1007 /* save state of windows */
1008 wwin
= scr
->focused_window
;
1010 wWindowSaveState(wwin
);
1015 if (wPreferences
.flags
.noupdates
)
1019 old_state
= scr
->session_state
;
1020 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1022 PLSetStringCmpHook(NULL
);
1024 /* save dock state to file */
1025 if (!wPreferences
.flags
.nodock
) {
1026 wDockSaveState(scr
);
1028 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1029 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1032 if (!wPreferences
.flags
.noclip
) {
1033 wClipSaveState(scr
);
1035 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1036 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1040 wWorkspaceSaveState(scr
, old_state
);
1042 if (wPreferences
.save_session_on_exit
) {
1043 wSessionSaveState(scr
);
1045 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1046 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1048 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1049 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1054 PLSetStringCmpHook(StringCompareHook
);
1056 wMenuSaveState(scr
);
1058 if (wScreenCount
== 1)
1059 str
= wdefaultspathfordomain("WMState");
1062 sprintf(buf
, "WMState.%i", scr
->screen
);
1063 str
= wdefaultspathfordomain(buf
);
1065 path
= PLMakeString(str
);
1067 PLSetFilename(scr
->session_state
, path
);
1068 if (!PLSave(scr
->session_state
, YES
)) {
1069 wwarning(_("could not save session state in %s"), PLGetString(path
));
1072 PLRelease(old_state
);
1078 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1094 *x
= -tol_w
, moved
= 1;
1095 else if (*x
>= scr
->scr_width
- 10)
1096 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1098 if (*y
< -height
+ 10)
1099 *y
= -tol_h
, moved
= 1;
1100 else if (*y
>= scr
->scr_height
- 10)
1101 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;