1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 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"
63 # include "openlook.h"
68 #include <WINGs/WUtil.h>
74 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
75 |SubstructureNotifyMask|PointerMotionMask \
76 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
78 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
79 |SubstructureNotifyMask|PointerMotionMask \
80 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
81 |KeyPressMask|KeyReleaseMask)
84 /**** Global variables ****/
86 extern Cursor wCursor
[WCUR_LAST
];
87 extern WPreferences wPreferences
;
88 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
92 extern int wScreenCount
;
94 #ifdef KEEP_XKB_LOCK_STATUS
95 extern int wXkbSupported
;
98 extern WDDomain
*WDWindowMaker
;
103 #define STIPPLE_WIDTH 2
104 #define STIPPLE_HEIGHT 2
105 static char STIPPLE_DATA
[] = {0x02, 0x01};
107 static int CantManageScreen
= 0;
109 static WMPropList
*dApplications
= NULL
;
110 static WMPropList
*dWorkspace
;
111 static WMPropList
*dDock
;
112 static WMPropList
*dClip
;
118 if (dApplications
!=NULL
)
121 dApplications
= WMCreatePLString("Applications");
122 dWorkspace
= WMCreatePLString("Workspace");
123 dDock
= WMCreatePLString("Dock");
124 dClip
= WMCreatePLString("Clip");
129 *----------------------------------------------------------------------
130 * alreadyRunningError--
131 * X error handler used to catch errors when trying to do
132 * XSelectInput() on the root window. These errors probably mean that
133 * there already is some other window manager running.
136 * Nothing, unless something really evil happens...
139 * CantManageScreen is set to 1;
140 *----------------------------------------------------------------------
143 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
145 CantManageScreen
= 1;
151 *----------------------------------------------------------------------
152 * allocButtonPixmaps--
153 * Allocate pixmaps used on window operation buttons (those in the
154 * titlebar). The pixmaps are linked to the program. If XPM is supported
155 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
161 * Allocates shared pixmaps for the screen. These pixmaps should
162 * not be freed by anybody.
163 *----------------------------------------------------------------------
166 allocButtonPixmaps(WScreen
*scr
)
170 /* create predefined pixmaps */
171 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
174 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
176 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
179 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
181 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
184 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
185 #ifdef XKB_BUTTON_HINT
186 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
189 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
190 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
193 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
194 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
197 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
198 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
201 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
205 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
208 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
213 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
215 XSetForeground(dpy
, gc
, scr
->black_pixel
);
216 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
217 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
218 XSetForeground(dpy
, gc
, scr
->white_pixel
);
219 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
220 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
225 make3Dots(WScreen
*scr
)
233 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
234 wPreferences
.icon_size
, scr
->w_depth
);
235 XSetForeground(dpy
, gc
, scr
->black_pixel
);
236 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
237 wPreferences
.icon_size
);
238 XSetForeground(dpy
, gc
, scr
->white_pixel
);
239 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
240 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
241 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
243 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
244 wPreferences
.icon_size
, 1);
246 gcv
.graphics_exposures
= False
;
247 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
248 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
249 wPreferences
.icon_size
);
250 XSetForeground(dpy
, gc2
, 1);
251 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
252 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
253 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
257 wpix
= wPixmapCreate(scr
, pix
, mask
);
265 allocGCs(WScreen
*scr
)
269 unsigned long mtextcolor
;
272 scr
->stipple_bitmap
=
273 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
276 gcv
.stipple
= scr
->stipple_bitmap
;
277 gcv
.foreground
= scr
->white_pixel
;
278 gcv
.fill_style
= FillStippled
;
279 gcv
.graphics_exposures
= False
;
280 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
281 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
284 /* selected icon border GCs */
285 gcv
.function
= GXcopy
;
286 gcv
.foreground
= scr
->white_pixel
;
287 gcv
.background
= scr
->black_pixel
;
289 gcv
.line_style
= LineDoubleDash
;
290 gcv
.fill_style
= FillSolid
;
293 gcv
.graphics_exposures
= False
;
295 gcm
= GCFunction
| GCGraphicsExposures
;
296 gcm
|= GCForeground
| GCBackground
;
297 gcm
|= GCLineWidth
| GCLineStyle
;
299 gcm
|= GCDashOffset
| GCDashList
;
301 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
303 gcm
= GCForeground
|GCGraphicsExposures
;
305 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
306 gcv
.foreground
= scr
->white_pixel
;
307 gcv
.graphics_exposures
= False
;
308 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
310 scr
->mtext_pixel
= scr
->black_pixel
;
311 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
312 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
314 /* selected menu entry GC */
315 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
316 gcv
.foreground
= scr
->white_pixel
;
317 gcv
.background
= scr
->white_pixel
;
318 gcv
.graphics_exposures
= False
;
319 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
321 /* disabled menu entry GC */
322 scr
->dtext_pixel
= scr
->black_pixel
;
323 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
324 gcv
.stipple
= scr
->stipple_bitmap
;
325 gcv
.graphics_exposures
= False
;
326 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
329 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
330 gcv
.function
= GXxor
;
331 /* this will raise the probability of the XORed color being different
332 * of the original color in PseudoColor when not all color cells are
334 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
335 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
337 gcv
.plane_mask
= AllPlanes
;
338 gcv
.foreground
= color
.pixel
;
339 if (gcv
.foreground
== 0)
341 gcv
.line_width
= DEF_FRAME_THICKNESS
;
342 gcv
.subwindow_mode
= IncludeInferiors
;
343 gcv
.graphics_exposures
= False
;
344 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
345 |GCFunction
|GCSubwindowMode
|GCLineWidth
349 gcv
.foreground
= color
.pixel
;
351 if (gcv
.foreground
== 0)
352 /* XOR:ing with a zero is not going to be of much use, so
353 in that case, we somewhat arbitrarily xor with 17 instead. */
356 gcv
.function
= GXxor
;
357 gcv
.subwindow_mode
= IncludeInferiors
;
359 gcv
.cap_style
= CapRound
;
360 gcv
.graphics_exposures
= False
;
361 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
362 |GCGraphicsExposures
;
363 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
365 scr
->line_pixel
= gcv
.foreground
;
368 gcv
.foreground
= scr
->white_pixel
;
369 gcv
.background
= scr
->black_pixel
;
370 gcv
.graphics_exposures
= False
;
371 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
372 |GCGraphicsExposures
, &gcv
);
374 /* window title text GC */
375 gcv
.graphics_exposures
= False
;
376 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
379 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
382 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
384 /* move/size display GC */
385 gcv
.graphics_exposures
= False
;
386 gcm
= GCGraphicsExposures
;
387 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
389 /* misc drawing GC */
390 gcv
.graphics_exposures
= False
;
391 gcm
= GCGraphicsExposures
;
392 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
394 assert (scr
->stipple_bitmap
!=None
);
398 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
404 createPixmaps(WScreen
*scr
)
410 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
411 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
412 MENU_RADIO_INDICATOR_XBM_SIZE
,
413 MENU_RADIO_INDICATOR_XBM_SIZE
,
414 scr
->black_pixel
, scr
->white_pixel
);
417 scr
->menu_radio_indicator
= pix
;
420 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
421 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
422 MENU_CHECK_INDICATOR_XBM_SIZE
,
423 MENU_CHECK_INDICATOR_XBM_SIZE
,
424 scr
->black_pixel
, scr
->white_pixel
);
427 scr
->menu_check_indicator
= pix
;
429 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
430 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
431 MENU_MINI_INDICATOR_XBM_SIZE
,
432 MENU_MINI_INDICATOR_XBM_SIZE
,
433 scr
->black_pixel
, scr
->white_pixel
);
436 scr
->menu_mini_indicator
= pix
;
438 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
439 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
440 MENU_HIDE_INDICATOR_XBM_SIZE
,
441 MENU_HIDE_INDICATOR_XBM_SIZE
,
442 scr
->black_pixel
, scr
->white_pixel
);
445 scr
->menu_hide_indicator
= pix
;
447 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
448 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
449 MENU_SHADE_INDICATOR_XBM_SIZE
,
450 MENU_SHADE_INDICATOR_XBM_SIZE
,
451 scr
->black_pixel
, scr
->white_pixel
);
454 scr
->menu_shade_indicator
= pix
;
457 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
460 wwarning(_("could not load logo image for panels: %s"),
461 RMessageForError(RErrorCode
));
463 WMSetApplicationIconImage(scr
->wmscreen
, image
);
464 RReleaseImage(image
);
467 scr
->dock_dots
= make3Dots(scr
);
469 /* titlebar button pixmaps */
470 allocButtonPixmaps(scr
);
475 *----------------------------------------------------------------------
476 * createInternalWindows--
477 * Creates some windows used internally by the program. One to
478 * receive input focus when no other window can get it and another
479 * to display window geometry information during window resize/move.
485 * Windows are created and some colors are allocated for the
487 *----------------------------------------------------------------------
490 createInternalWindows(WScreen
*scr
)
493 XSetWindowAttributes attribs
;
495 /* InputOnly window to get the focus when no other window can get it */
496 vmask
= CWEventMask
|CWOverrideRedirect
;
497 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
498 attribs
.override_redirect
= True
;
499 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
500 InputOnly
,CopyFromParent
, vmask
, &attribs
);
501 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
502 XMapWindow(dpy
, scr
->no_focus_win
);
504 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
506 /* shadow window for dock buttons */
507 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
508 attribs
.border_pixel
= scr
->black_pixel
;
509 attribs
.save_under
= True
;
510 attribs
.override_redirect
= True
;
511 attribs
.background_pixmap
= None
;
512 attribs
.background_pixel
= scr
->white_pixel
;
513 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
515 attribs
.colormap
= scr
->w_colormap
;
517 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
518 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
519 scr
->w_visual
, vmask
, &attribs
);
521 /* workspace name balloon for clip */
522 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
524 attribs
.save_under
= True
;
525 attribs
.override_redirect
= True
;
526 attribs
.colormap
= scr
->w_colormap
;
527 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
528 attribs
.border_pixel
= 0; /* do not care */
530 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
531 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
535 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
537 attribs
.save_under
= True
;
538 attribs
.override_redirect
= True
;
539 attribs
.colormap
= scr
->w_colormap
;
540 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
541 attribs
.border_pixel
= 0; /* do not care */
542 scr
->workspace_name
=
543 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
544 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
547 * If the window is clicked without having ButtonPress selected, the
548 * resulting event will have event.xbutton.window == root.
550 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
556 aquireManagerSelection(WScreen
*scr
)
562 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
563 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
565 /* for race-conditions... */
568 /* if there is another manager running, don't try to replace it
569 * (for now, at least) */
570 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
575 /* become the manager for this screen */
577 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
580 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
581 /* get a timestamp */
582 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
583 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
585 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
586 if (ev
.type
== PropertyNotify
) {
587 timestamp
= ev
.xproperty
.time
;
591 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
592 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
594 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
598 /* announce our arrival */
600 ev
.xclient
.type
= ClientMessage
;
601 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
602 ev
.xclient
.destination
= scr
->root_win
;
603 ev
.xclient
.format
= 32;
604 ev
.xclient
.data
.l
[0] = timestamp
;
605 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
606 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
607 ev
.xclient
.data
.l
[3] = 0;
608 ev
.xclient
.data
.l
[4] = 0;
610 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
618 *----------------------------------------------------------------------
620 * Initializes the window manager for the given screen and
621 * allocates a WScreen descriptor for it. Many resources are allocated
622 * for the screen and the root window is setup appropriately.
625 * The WScreen descriptor for the screen.
628 * Many resources are allocated and the IconSize property is
629 * set on the root window.
630 * The program can be aborted if some fatal error occurs.
632 * TODO: User specifiable visual.
633 *----------------------------------------------------------------------
636 wScreenInit(int screen_number
)
639 XIconSize icon_size
[1];
640 RContextAttributes rattr
;
641 extern int wVisualID
;
644 XErrorHandler oldHandler
;
646 scr
= wmalloc(sizeof(WScreen
));
647 memset(scr
, 0, sizeof(WScreen
));
649 scr
->stacking_list
= WMCreateTreeBag();
651 /* initialize globals */
652 scr
->screen
= screen_number
;
653 scr
->root_win
= RootWindow(dpy
, screen_number
);
654 scr
->depth
= DefaultDepth(dpy
, screen_number
);
655 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
657 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
658 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
660 scr
->usableArea
.x2
= scr
->scr_width
;
661 scr
->usableArea
.y2
= scr
->scr_height
;
662 scr
->totalUsableArea
.x2
= scr
->scr_width
;
663 scr
->totalUsableArea
.y2
= scr
->scr_height
;
665 scr
->fakeGroupLeaders
= WMCreateArray(16);
668 if (!aquireManagerSelection(scr
)) {
674 CantManageScreen
= 0;
675 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
677 event_mask
= EVENT_MASK
;
679 if (wPreferences
.disable_root_mouse
) {
680 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
683 XSelectInput(dpy
, scr
->root_win
, event_mask
);
685 #ifdef KEEP_XKB_LOCK_STATUS
686 /* Only GroupLock doesn't work correctly in my system since right-alt
687 * can change mode while holding it too - ]d
690 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
694 #endif /* KEEP_XKB_LOCK_STATUS */
697 XSetErrorHandler(oldHandler
);
699 if (CantManageScreen
) {
709 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
711 /* screen descriptor for raster graphic library */
712 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
713 rattr
.render_mode
= wPreferences
.no_dithering
714 ? RBestMatchRendering
715 : RDitheredRendering
;
717 /* if the std colormap stuff works ok, this will be ignored */
718 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
719 if (rattr
.colors_per_channel
<2)
720 rattr
.colors_per_channel
= 2;
723 /* will only be accounted for in PseudoColor */
724 if (wPreferences
.flags
.create_stdcmap
) {
725 rattr
.standard_colormap_mode
= RCreateStdColormap
;
727 rattr
.standard_colormap_mode
= RUseStdColormap
;
731 rattr
.flags
|= RC_VisualID
;
732 rattr
.visualid
= wVisualID
;
735 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
737 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
738 wwarning(RMessageForError(RErrorCode
));
740 rattr
.flags
&= ~RC_StandardColormap
;
741 rattr
.standard_colormap_mode
= RUseStdColormap
;
743 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
746 if (!scr
->rcontext
) {
747 wwarning(_("could not initialize graphics library context: %s"),
748 RMessageForError(RErrorCode
));
754 formats
= RSupportedFileFormats();
756 for (i
=0; formats
[i
]!=NULL
; i
++) {
757 if (strcmp(formats
[i
], "TIFF")==0) {
758 scr
->flags
.supports_tiff
= 1;
765 scr
->w_win
= scr
->rcontext
->drawable
;
766 scr
->w_visual
= scr
->rcontext
->visual
;
767 scr
->w_depth
= scr
->rcontext
->depth
;
768 scr
->w_colormap
= scr
->rcontext
->cmap
;
770 scr
->black_pixel
= scr
->rcontext
->black
;
771 scr
->white_pixel
= scr
->rcontext
->white
;
773 /* create screen descriptor for WINGs */
774 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
777 if (!scr
->wmscreen
) {
778 wfatal(_("could not do initialization of WINGs widget set"));
783 color
= WMGrayColor(scr
->wmscreen
);
784 scr
->light_pixel
= WMColorPixel(color
);
785 WMReleaseColor(color
);
787 color
= WMDarkGrayColor(scr
->wmscreen
);
788 scr
->dark_pixel
= WMColorPixel(color
);
789 WMReleaseColor(color
);
793 /* frame boder color */
794 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
795 scr
->frame_border_pixel
= xcol
.pixel
;
798 /* create GCs with default values */
802 /* for our window manager info notice board. Need to
803 * create before reading the defaults, because it will be used there.
805 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
808 /* read defaults for this screen */
809 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
811 createInternalWindows(scr
);
818 wGNOMEInitStuff(scr
);
825 /* create initial workspace */
828 /* create shared pixmaps */
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);
853 /* initialize balloon text stuff */
854 wBalloonInitialize(scr
);
857 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
860 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
861 WMRealizeWidget(scr
->gview
);
863 wScreenUpdateUsableArea(scr
);
870 static WArea
subtractRectangle(WArea area
, WArea rect
)
879 wScreenUpdateUsableArea(WScreen
*scr
)
883 scr
->totalUsableArea
= scr
->usableArea
;
886 if (scr
->dock
&& (!scr
->dock
->lowered
887 || wPreferences
.no_window_over_dock
)) {
889 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
891 if (scr
->dock
->on_right_side
) {
892 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
893 scr
->scr_width
- offset
);
895 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
899 if (wPreferences
.no_window_over_icons
) {
900 if (wPreferences
.icon_yard
& IY_VERT
) {
902 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
903 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
905 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
909 if (wPreferences
.icon_yard
& IY_TOP
) {
910 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
912 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
921 if (wKWMGetUsableArea(scr
, &area
)) {
922 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
923 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
924 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
925 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
931 area
= scr
->reservedAreas
;
938 w
= area
->area
.x2
- area
->area
.x1
;
939 h
= area
->area
.y2
- area
->area
.y1
;
942 bh
= scr
->scr_height
- area
->area
.y2
;
944 rw
= scr
->scr_width
- area
->area
.x2
;
946 if (WMIN(th
, bh
) <= WMIN(lw
, rw
)) {
950 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
951 scr
->totalUsableArea
.y1
= area
->area
.y2
;
954 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
955 scr
->totalUsableArea
.y2
= area
->area
.y1
;
961 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
962 scr
->totalUsableArea
.x1
= area
->area
.x2
;
965 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
966 scr
->totalUsableArea
.x2
= area
->area
.x1
;
972 #endif /* GNOME_STUFF */
974 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
975 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
976 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
978 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
979 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
980 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
988 for (i
= 0; i
< scr
->workspace_count
; i
++) {
989 wKWMSetUsableAreaHint(scr
, i
);
996 unsigned size
= wPreferences
.workspace_border_size
;
997 unsigned position
= wPreferences
.workspace_border_position
;
999 if (size
>0 && position
!=WB_NONE
) {
1000 if (position
& WB_LEFTRIGHT
) {
1001 scr
->totalUsableArea
.x1
+= size
;
1002 scr
->totalUsableArea
.x2
-= size
;
1004 if (position
& WB_TOPBOTTOM
) {
1005 scr
->totalUsableArea
.y1
+= size
;
1006 scr
->totalUsableArea
.y2
-= size
;
1015 wScreenRestoreState(WScreen
*scr
)
1022 OpenRootMenu(scr
, -10000, -10000, False
);
1023 wMenuUnmap(scr
->root_menu
);
1028 if (wScreenCount
== 1) {
1029 path
= wdefaultspathfordomain("WMState");
1032 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1033 path
= wdefaultspathfordomain(buf
);
1035 scr
->session_state
= WMReadPropListFromFile(path
);
1037 if (!scr
->session_state
&& wScreenCount
>1) {
1038 path
= wdefaultspathfordomain("WMState");
1039 scr
->session_state
= WMReadPropListFromFile(path
);
1043 if (!wPreferences
.flags
.noclip
&& scr
->session_state
) {
1044 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
1045 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1048 wWorkspaceRestoreState(scr
);
1050 #ifdef VIRTUAL_DESKTOP
1052 * * create inputonly windows at the border of screen
1054 wWorkspaceManageEdge(scr
);
1057 if (!wPreferences
.flags
.nodock
&& scr
->session_state
) {
1058 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1059 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1062 wScreenUpdateUsableArea(scr
);
1067 wScreenSaveState(WScreen
*scr
)
1071 WMPropList
*old_state
, *foo
;
1077 /* Save current workspace, so can go back to it upon restart. */
1078 data
[0] = scr
->current_workspace
;
1079 data
[1] = WFLAGS_NONE
;
1081 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1082 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1083 (unsigned char *) data
, 2);
1085 /* save state of windows */
1086 wwin
= scr
->focused_window
;
1088 wWindowSaveState(wwin
);
1093 if (wPreferences
.flags
.noupdates
)
1097 old_state
= scr
->session_state
;
1098 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
1100 WMPLSetCaseSensitive(True
);
1102 /* save dock state to file */
1103 if (!wPreferences
.flags
.nodock
) {
1104 wDockSaveState(scr
, old_state
);
1106 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1107 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1110 if (!wPreferences
.flags
.noclip
) {
1111 wClipSaveState(scr
);
1113 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1114 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1118 wWorkspaceSaveState(scr
, old_state
);
1120 if (wPreferences
.save_session_on_exit
) {
1121 wSessionSaveState(scr
);
1123 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1124 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1126 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1127 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1132 WMPLSetCaseSensitive(False
);
1134 wMenuSaveState(scr
);
1136 if (wScreenCount
== 1)
1137 str
= wdefaultspathfordomain("WMState");
1140 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1141 str
= wdefaultspathfordomain(buf
);
1143 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1144 wsyserror(_("could not save session state in %s"), str
);
1147 WMReleasePropList(old_state
);
1153 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1169 *x
= -tol_w
, moved
= 1;
1170 else if (*x
>= scr
->scr_width
- 10)
1171 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1173 if (*y
< -height
+ 10)
1174 *y
= -tol_h
, moved
= 1;
1175 else if (*y
>= scr
->scr_height
- 10)
1176 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;