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
->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
)
407 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
408 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
409 MENU_RADIO_INDICATOR_XBM_SIZE
,
410 MENU_RADIO_INDICATOR_XBM_SIZE
,
411 scr
->black_pixel
, scr
->white_pixel
);
414 scr
->menu_radio_indicator
= pix
;
417 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
418 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
419 MENU_CHECK_INDICATOR_XBM_SIZE
,
420 MENU_CHECK_INDICATOR_XBM_SIZE
,
421 scr
->black_pixel
, scr
->white_pixel
);
424 scr
->menu_check_indicator
= pix
;
426 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
427 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
428 MENU_MINI_INDICATOR_XBM_SIZE
,
429 MENU_MINI_INDICATOR_XBM_SIZE
,
430 scr
->black_pixel
, scr
->white_pixel
);
433 scr
->menu_mini_indicator
= pix
;
435 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
436 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
437 MENU_HIDE_INDICATOR_XBM_SIZE
,
438 MENU_HIDE_INDICATOR_XBM_SIZE
,
439 scr
->black_pixel
, scr
->white_pixel
);
442 scr
->menu_hide_indicator
= pix
;
444 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
445 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
446 MENU_SHADE_INDICATOR_XBM_SIZE
,
447 MENU_SHADE_INDICATOR_XBM_SIZE
,
448 scr
->black_pixel
, scr
->white_pixel
);
451 scr
->menu_shade_indicator
= pix
;
454 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
457 wwarning(_("could not load logo image for panels: %s"),
458 RMessageForError(RErrorCode
));
460 WMSetApplicationIconImage(scr
->wmscreen
, image
);
461 RReleaseImage(image
);
464 scr
->dock_dots
= make3Dots(scr
);
466 /* titlebar button pixmaps */
467 allocButtonPixmaps(scr
);
472 *----------------------------------------------------------------------
473 * createInternalWindows--
474 * Creates some windows used internally by the program. One to
475 * receive input focus when no other window can get it and another
476 * to display window geometry information during window resize/move.
482 * Windows are created and some colors are allocated for the
484 *----------------------------------------------------------------------
487 createInternalWindows(WScreen
*scr
)
490 XSetWindowAttributes attribs
;
492 /* InputOnly window to get the focus when no other window can get it */
493 vmask
= CWEventMask
|CWOverrideRedirect
;
494 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
495 attribs
.override_redirect
= True
;
496 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
497 InputOnly
,CopyFromParent
, vmask
, &attribs
);
498 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
499 XMapWindow(dpy
, scr
->no_focus_win
);
501 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
503 /* shadow window for dock buttons */
504 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
505 attribs
.border_pixel
= scr
->black_pixel
;
506 attribs
.save_under
= True
;
507 attribs
.override_redirect
= True
;
508 attribs
.background_pixmap
= None
;
509 attribs
.background_pixel
= scr
->white_pixel
;
510 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
512 attribs
.colormap
= scr
->w_colormap
;
514 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
515 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
516 scr
->w_visual
, vmask
, &attribs
);
518 /* workspace name balloon for clip */
519 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
521 attribs
.save_under
= True
;
522 attribs
.override_redirect
= True
;
523 attribs
.colormap
= scr
->w_colormap
;
524 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
525 attribs
.border_pixel
= 0; /* do not care */
527 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
528 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
532 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
534 attribs
.save_under
= True
;
535 attribs
.override_redirect
= True
;
536 attribs
.colormap
= scr
->w_colormap
;
537 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
538 attribs
.border_pixel
= 0; /* do not care */
539 scr
->workspace_name
=
540 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
541 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
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 snprintf(buffer
, sizeof(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 scr
->stacking_list
= WMCreateTreeBag();
648 /* initialize globals */
649 scr
->screen
= screen_number
;
650 scr
->root_win
= RootWindow(dpy
, screen_number
);
651 scr
->depth
= DefaultDepth(dpy
, screen_number
);
652 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
654 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
655 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
657 scr
->usableArea
.x2
= scr
->scr_width
;
658 scr
->usableArea
.y2
= scr
->scr_height
;
659 scr
->totalUsableArea
.x2
= scr
->scr_width
;
660 scr
->totalUsableArea
.y2
= scr
->scr_height
;
662 scr
->fakeGroupLeaders
= WMCreateArray(16);
665 if (!aquireManagerSelection(scr
)) {
671 CantManageScreen
= 0;
672 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
674 event_mask
= EVENT_MASK
;
676 if (wPreferences
.disable_root_mouse
) {
677 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
680 XSelectInput(dpy
, scr
->root_win
, event_mask
);
682 #ifdef KEEP_XKB_LOCK_STATUS
683 /* Only GroupLock doesn't work correctly in my system since right-alt
684 * can change mode while holding it too - ]d
687 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
691 #endif /* KEEP_XKB_LOCK_STATUS */
694 XSetErrorHandler(oldHandler
);
696 if (CantManageScreen
) {
706 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
708 /* screen descriptor for raster graphic library */
709 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
710 rattr
.render_mode
= wPreferences
.no_dithering
711 ? RBestMatchRendering
712 : RDitheredRendering
;
714 /* if the std colormap stuff works ok, this will be ignored */
715 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
716 if (rattr
.colors_per_channel
<2)
717 rattr
.colors_per_channel
= 2;
720 /* will only be accounted for in PseudoColor */
721 if (wPreferences
.flags
.create_stdcmap
) {
722 rattr
.standard_colormap_mode
= RCreateStdColormap
;
724 rattr
.standard_colormap_mode
= RUseStdColormap
;
728 rattr
.flags
|= RC_VisualID
;
729 rattr
.visualid
= wVisualID
;
732 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
734 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
735 wwarning(RMessageForError(RErrorCode
));
737 rattr
.flags
&= ~RC_StandardColormap
;
738 rattr
.standard_colormap_mode
= RUseStdColormap
;
740 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
743 if (!scr
->rcontext
) {
744 wwarning(_("could not initialize graphics library context: %s"),
745 RMessageForError(RErrorCode
));
751 formats
= RSupportedFileFormats();
753 for (i
=0; formats
[i
]!=NULL
; i
++) {
754 if (strcmp(formats
[i
], "TIFF")==0) {
755 scr
->flags
.supports_tiff
= 1;
762 scr
->w_win
= scr
->rcontext
->drawable
;
763 scr
->w_visual
= scr
->rcontext
->visual
;
764 scr
->w_depth
= scr
->rcontext
->depth
;
765 scr
->w_colormap
= scr
->rcontext
->cmap
;
767 scr
->black_pixel
= scr
->rcontext
->black
;
768 scr
->white_pixel
= scr
->rcontext
->white
;
770 /* create screen descriptor for WINGs */
771 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
774 if (!scr
->wmscreen
) {
775 wfatal(_("could not do initialization of WINGs widget set"));
780 color
= WMGrayColor(scr
->wmscreen
);
781 scr
->light_pixel
= WMColorPixel(color
);
782 WMReleaseColor(color
);
784 color
= WMDarkGrayColor(scr
->wmscreen
);
785 scr
->dark_pixel
= WMColorPixel(color
);
786 WMReleaseColor(color
);
790 /* frame boder color */
791 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
792 scr
->frame_border_pixel
= xcol
.pixel
;
795 /* create GCs with default values */
799 /* for our window manager info notice board. Need to
800 * create before reading the defaults, because it will be used there.
802 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
805 /* read defaults for this screen */
806 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
808 createInternalWindows(scr
);
815 wGNOMEInitStuff(scr
);
822 /* create initial workspace */
825 /* create shared pixmaps */
828 /* set icon sizes we can accept from clients */
829 icon_size
[0].min_width
= 8;
830 icon_size
[0].min_height
= 8;
831 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
832 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
833 icon_size
[0].width_inc
= 1;
834 icon_size
[0].height_inc
= 1;
835 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
837 /* setup WindowMaker protocols property in the root window*/
838 PropSetWMakerProtocols(scr
->root_win
);
840 /* setup our noticeboard */
841 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
842 XA_WINDOW
, 32, PropModeReplace
,
843 (unsigned char*)&scr
->info_window
, 1);
844 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
845 XA_WINDOW
, 32, PropModeReplace
,
846 (unsigned char*)&scr
->info_window
, 1);
850 /* initialize balloon text stuff */
851 wBalloonInitialize(scr
);
854 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
857 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
858 WMRealizeWidget(scr
->gview
);
860 wScreenUpdateUsableArea(scr
);
867 static WArea
subtractRectangle(WArea area
, WArea rect
)
876 wScreenUpdateUsableArea(WScreen
*scr
)
880 scr
->totalUsableArea
= scr
->usableArea
;
883 if (scr
->dock
&& (!scr
->dock
->lowered
884 || wPreferences
.no_window_over_dock
)) {
886 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
888 if (scr
->dock
->on_right_side
) {
889 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
890 scr
->scr_width
- offset
);
892 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
896 if (wPreferences
.no_window_over_icons
) {
897 if (wPreferences
.icon_yard
& IY_VERT
) {
899 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
900 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
902 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
906 if (wPreferences
.icon_yard
& IY_TOP
) {
907 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
909 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
918 if (wKWMGetUsableArea(scr
, &area
)) {
919 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
920 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
921 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
922 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
928 area
= scr
->reservedAreas
;
935 w
= area
->area
.x2
- area
->area
.x1
;
936 h
= area
->area
.y2
- area
->area
.y1
;
939 bh
= scr
->scr_height
- area
->area
.y2
;
941 rw
= scr
->scr_width
- area
->area
.x2
;
943 if (WMIN(th
, bh
) <= WMIN(lw
, rw
)) {
947 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
948 scr
->totalUsableArea
.y1
= area
->area
.y2
;
951 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
952 scr
->totalUsableArea
.y2
= area
->area
.y1
;
958 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
959 scr
->totalUsableArea
.x1
= area
->area
.x2
;
962 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
963 scr
->totalUsableArea
.x2
= area
->area
.x1
;
969 #endif /* GNOME_STUFF */
971 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
972 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
973 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
975 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
976 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
977 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
985 for (i
= 0; i
< scr
->workspace_count
; i
++) {
986 wKWMSetUsableAreaHint(scr
, i
);
993 unsigned size
= wPreferences
.workspace_border_size
;
994 unsigned position
= wPreferences
.workspace_border_position
;
996 if (size
>0 && position
!=WB_NONE
) {
997 if (position
& WB_LEFTRIGHT
) {
998 scr
->totalUsableArea
.x1
+= size
;
999 scr
->totalUsableArea
.x2
-= size
;
1001 if (position
& WB_TOPBOTTOM
) {
1002 scr
->totalUsableArea
.y1
+= size
;
1003 scr
->totalUsableArea
.y2
-= size
;
1012 wScreenRestoreState(WScreen
*scr
)
1019 OpenRootMenu(scr
, -10000, -10000, False
);
1020 wMenuUnmap(scr
->root_menu
);
1025 if (wScreenCount
== 1) {
1026 path
= wdefaultspathfordomain("WMState");
1029 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1030 path
= wdefaultspathfordomain(buf
);
1032 scr
->session_state
= WMReadPropListFromFile(path
);
1034 if (!scr
->session_state
&& wScreenCount
>1) {
1035 path
= wdefaultspathfordomain("WMState");
1036 scr
->session_state
= WMReadPropListFromFile(path
);
1040 if (!wPreferences
.flags
.noclip
&& scr
->session_state
) {
1041 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
1042 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1045 wWorkspaceRestoreState(scr
);
1047 #ifdef VIRTUAL_DESKTOP
1049 * * create inputonly windows at the border of screen
1051 wWorkspaceManageEdge(scr
);
1054 if (!wPreferences
.flags
.nodock
&& scr
->session_state
) {
1055 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1056 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1059 wScreenUpdateUsableArea(scr
);
1064 wScreenSaveState(WScreen
*scr
)
1068 WMPropList
*old_state
, *foo
;
1074 /* Save current workspace, so can go back to it upon restart. */
1075 data
[0] = scr
->current_workspace
;
1076 data
[1] = WFLAGS_NONE
;
1078 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1079 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1080 (unsigned char *) data
, 2);
1082 /* save state of windows */
1083 wwin
= scr
->focused_window
;
1085 wWindowSaveState(wwin
);
1090 if (wPreferences
.flags
.noupdates
)
1094 old_state
= scr
->session_state
;
1095 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
1097 WMPLSetCaseSensitive(True
);
1099 /* save dock state to file */
1100 if (!wPreferences
.flags
.nodock
) {
1101 wDockSaveState(scr
, old_state
);
1103 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1104 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1107 if (!wPreferences
.flags
.noclip
) {
1108 wClipSaveState(scr
);
1110 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1111 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1115 wWorkspaceSaveState(scr
, old_state
);
1117 if (wPreferences
.save_session_on_exit
) {
1118 wSessionSaveState(scr
);
1120 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1121 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1123 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1124 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1129 WMPLSetCaseSensitive(False
);
1131 wMenuSaveState(scr
);
1133 if (wScreenCount
== 1)
1134 str
= wdefaultspathfordomain("WMState");
1137 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1138 str
= wdefaultspathfordomain(buf
);
1140 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1141 wsyserror(_("could not save session state in %s"), str
);
1144 WMReleasePropList(old_state
);
1150 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1166 *x
= -tol_w
, moved
= 1;
1167 else if (*x
>= scr
->scr_width
- 10)
1168 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1170 if (*y
< -height
+ 10)
1171 *y
= -tol_h
, moved
= 1;
1172 else if (*y
>= scr
->scr_height
- 10)
1173 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;