1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 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 */
39 #include <X11/extensions/Xrandr.h>
43 #include "WindowMaker.h"
44 #include "def_pixmaps.h"
51 #include "properties.h"
53 #include "resources.h"
54 #include "workspace.h"
62 #include <WINGs/WUtil.h>
66 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
67 |SubstructureNotifyMask|PointerMotionMask \
68 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
69 |KeyPressMask|KeyReleaseMask)
71 /**** Global variables ****/
72 extern Cursor wCursor
[WCUR_LAST
];
73 extern WPreferences wPreferences
;
74 extern Atom _XA_WINDOWMAKER_STATE
;
75 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
77 extern int wScreenCount
;
79 #ifdef KEEP_XKB_LOCK_STATUS
80 extern int wXkbSupported
;
86 extern WDDomain
*WDWindowMaker
;
89 #define STIPPLE_WIDTH 2
90 #define STIPPLE_HEIGHT 2
91 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
93 static int CantManageScreen
= 0;
95 static WMPropList
*dApplications
= NULL
;
96 static WMPropList
*dWorkspace
;
97 static WMPropList
*dDock
;
98 static WMPropList
*dClip
;
100 static void make_keys(void)
102 if (dApplications
!= NULL
)
105 dApplications
= WMCreatePLString("Applications");
106 dWorkspace
= WMCreatePLString("Workspace");
107 dDock
= WMCreatePLString("Dock");
108 dClip
= WMCreatePLString("Clip");
112 *----------------------------------------------------------------------
113 * alreadyRunningError--
114 * X error handler used to catch errors when trying to do
115 * XSelectInput() on the root window. These errors probably mean that
116 * there already is some other window manager running.
119 * Nothing, unless something really evil happens...
122 * CantManageScreen is set to 1;
123 *----------------------------------------------------------------------
125 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
127 CantManageScreen
= 1;
132 *----------------------------------------------------------------------
133 * allocButtonPixmaps--
134 * Allocate pixmaps used on window operation buttons (those in the
135 * titlebar). The pixmaps are linked to the program. If XPM is supported
136 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
142 * Allocates shared pixmaps for the screen. These pixmaps should
143 * not be freed by anybody.
144 *----------------------------------------------------------------------
146 static void allocButtonPixmaps(WScreen
* scr
)
150 /* create predefined pixmaps */
151 if (wPreferences
.new_style
== TS_NEXT
) {
152 pix
= wPixmapCreateFromXPMData(scr
, NEXT_CLOSE_XPM
);
154 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
158 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
160 if (wPreferences
.new_style
== TS_NEXT
) {
161 pix
= wPixmapCreateFromXPMData(scr
, NEXT_BROKEN_CLOSE_XPM
);
163 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
167 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
169 if (wPreferences
.new_style
== TS_NEXT
) {
170 pix
= wPixmapCreateFromXPMData(scr
, NEXT_ICONIFY_XPM
);
172 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
176 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
177 #ifdef XKB_BUTTON_HINT
178 if (wPreferences
.new_style
== TS_NEXT
) {
179 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP1_XPM
);
181 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
185 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
186 if (wPreferences
.new_style
== TS_NEXT
) {
187 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP2_XPM
);
189 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
193 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
194 if (wPreferences
.new_style
== TS_NEXT
) {
195 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP3_XPM
);
197 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
201 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
202 if (wPreferences
.new_style
== TS_NEXT
) {
203 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP4_XPM
);
205 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
209 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
212 if (wPreferences
.new_style
== TS_NEXT
) {
213 pix
= wPixmapCreateFromXPMData(scr
, NEXT_KILL_XPM
);
215 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
219 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
222 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
224 XSetForeground(dpy
, gc
, scr
->black_pixel
);
225 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
226 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
227 XSetForeground(dpy
, gc
, scr
->white_pixel
);
228 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
229 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
232 static WPixmap
*make3Dots(WScreen
* scr
)
240 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
241 XSetForeground(dpy
, gc
, scr
->black_pixel
);
242 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
243 XSetForeground(dpy
, gc
, scr
->white_pixel
);
244 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
245 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
246 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
248 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
250 gcv
.graphics_exposures
= False
;
251 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
252 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
253 XSetForeground(dpy
, gc2
, 1);
254 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
255 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
256 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
260 wpix
= wPixmapCreate(scr
, pix
, mask
);
266 static void allocGCs(WScreen
* scr
)
272 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
274 gcv
.stipple
= scr
->stipple_bitmap
;
275 gcv
.foreground
= scr
->white_pixel
;
276 gcv
.fill_style
= FillStippled
;
277 gcv
.graphics_exposures
= False
;
278 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
279 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 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
302 /* don't retain scr->black here because we may alter its alpha */
303 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
304 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
307 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
308 gcv
.function
= GXxor
;
309 /* this will raise the probability of the XORed color being different
310 * of the original color in PseudoColor when not all color cells are
312 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
313 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
315 gcv
.plane_mask
= AllPlanes
;
316 gcv
.foreground
= color
.pixel
;
317 if (gcv
.foreground
== 0)
319 gcv
.line_width
= DEF_FRAME_THICKNESS
;
320 gcv
.subwindow_mode
= IncludeInferiors
;
321 gcv
.graphics_exposures
= False
;
322 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
323 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
326 gcv
.foreground
= color
.pixel
;
328 if (gcv
.foreground
== 0)
329 /* XOR:ing with a zero is not going to be of much use, so
330 in that case, we somewhat arbitrarily xor with 17 instead. */
333 gcv
.function
= GXxor
;
334 gcv
.subwindow_mode
= IncludeInferiors
;
336 gcv
.cap_style
= CapRound
;
337 gcv
.graphics_exposures
= False
;
338 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| GCGraphicsExposures
;
339 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
341 scr
->line_pixel
= gcv
.foreground
;
344 gcv
.foreground
= scr
->white_pixel
;
345 gcv
.background
= scr
->black_pixel
;
346 gcv
.graphics_exposures
= False
;
347 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCGraphicsExposures
, &gcv
);
349 /* misc drawing GC */
350 gcv
.graphics_exposures
= False
;
351 gcm
= GCGraphicsExposures
;
352 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
354 assert(scr
->stipple_bitmap
!= None
);
357 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
360 static void createPixmaps(WScreen
* scr
)
366 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
367 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
368 MENU_RADIO_INDICATOR_XBM_SIZE
,
369 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
372 scr
->menu_radio_indicator
= pix
;
374 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
375 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
376 MENU_CHECK_INDICATOR_XBM_SIZE
,
377 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
380 scr
->menu_check_indicator
= pix
;
382 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
383 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
384 MENU_MINI_INDICATOR_XBM_SIZE
,
385 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
388 scr
->menu_mini_indicator
= pix
;
390 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
391 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
392 MENU_HIDE_INDICATOR_XBM_SIZE
,
393 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
396 scr
->menu_hide_indicator
= pix
;
398 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
399 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
400 MENU_SHADE_INDICATOR_XBM_SIZE
,
401 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
404 scr
->menu_shade_indicator
= pix
;
406 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
409 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
411 WMSetApplicationIconImage(scr
->wmscreen
, image
);
412 RReleaseImage(image
);
415 scr
->dock_dots
= make3Dots(scr
);
417 /* titlebar button pixmaps */
418 allocButtonPixmaps(scr
);
422 *----------------------------------------------------------------------
423 * createInternalWindows--
424 * Creates some windows used internally by the program. One to
425 * receive input focus when no other window can get it and another
426 * to display window geometry information during window resize/move.
432 * Windows are created and some colors are allocated for the
434 *----------------------------------------------------------------------
436 static void createInternalWindows(WScreen
* scr
)
439 XSetWindowAttributes attribs
;
441 /* InputOnly window to get the focus when no other window can get it */
442 vmask
= CWEventMask
| CWOverrideRedirect
;
443 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
444 attribs
.override_redirect
= True
;
445 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
446 InputOnly
, CopyFromParent
, vmask
, &attribs
);
447 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
448 XMapWindow(dpy
, scr
->no_focus_win
);
450 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
452 /* shadow window for dock buttons */
453 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
454 attribs
.border_pixel
= scr
->black_pixel
;
455 attribs
.save_under
= True
;
456 attribs
.override_redirect
= True
;
457 attribs
.background_pixmap
= None
;
458 attribs
.background_pixel
= scr
->white_pixel
;
459 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
461 attribs
.colormap
= scr
->w_colormap
;
463 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
464 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
466 /* workspace name balloon for clip */
467 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
468 attribs
.save_under
= True
;
469 attribs
.override_redirect
= True
;
470 attribs
.colormap
= scr
->w_colormap
;
471 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
472 attribs
.border_pixel
= 0; /* do not care */
474 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
475 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
478 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
479 attribs
.save_under
= True
;
480 attribs
.override_redirect
= True
;
481 attribs
.colormap
= scr
->w_colormap
;
482 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
483 attribs
.border_pixel
= 0; /* do not care */
484 scr
->workspace_name
=
485 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
486 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
489 * If the window is clicked without having ButtonPress selected, the
490 * resulting event will have event.xbutton.window == root.
492 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
496 static Bool
aquireManagerSelection(WScreen
* scr
)
502 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
503 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
505 /* for race-conditions... */
508 /* if there is another manager running, don't try to replace it
509 * (for now, at least) */
510 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
515 /* become the manager for this screen */
517 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1, 0, 0, 0);
519 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
520 /* get a timestamp */
521 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
, XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
523 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
524 if (ev
.type
== PropertyNotify
) {
525 timestamp
= ev
.xproperty
.time
;
529 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
530 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
532 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
536 /* announce our arrival */
538 ev
.xclient
.type
= ClientMessage
;
539 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
540 ev
.xclient
.destination
= scr
->root_win
;
541 ev
.xclient
.format
= 32;
542 ev
.xclient
.data
.l
[0] = timestamp
;
543 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
544 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
545 ev
.xclient
.data
.l
[3] = 0;
546 ev
.xclient
.data
.l
[4] = 0;
548 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
556 *----------------------------------------------------------------------
558 * Initializes the window manager for the given screen and
559 * allocates a WScreen descriptor for it. Many resources are allocated
560 * for the screen and the root window is setup appropriately.
563 * The WScreen descriptor for the screen.
566 * Many resources are allocated and the IconSize property is
567 * set on the root window.
568 * The program can be aborted if some fatal error occurs.
570 * TODO: User specifiable visual.
571 *----------------------------------------------------------------------
573 WScreen
*wScreenInit(int screen_number
)
576 XIconSize icon_size
[1];
577 RContextAttributes rattr
;
579 XErrorHandler oldHandler
;
582 scr
= wmalloc(sizeof(WScreen
));
583 memset(scr
, 0, sizeof(WScreen
));
585 scr
->stacking_list
= WMCreateTreeBag();
587 /* initialize globals */
588 scr
->screen
= screen_number
;
589 scr
->root_win
= RootWindow(dpy
, screen_number
);
590 scr
->depth
= DefaultDepth(dpy
, screen_number
);
591 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
593 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
594 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
598 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
599 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
601 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
602 WMRect rect
= wGetRectForHead(scr
, i
);
603 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
604 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
605 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
606 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
609 scr
->fakeGroupLeaders
= WMCreateArray(16);
612 if (!aquireManagerSelection(scr
)) {
618 CantManageScreen
= 0;
619 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
621 event_mask
= EVENT_MASK
;
623 if (wPreferences
.disable_root_mouse
) {
624 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
627 XSelectInput(dpy
, scr
->root_win
, event_mask
);
629 #ifdef KEEP_XKB_LOCK_STATUS
630 /* Only GroupLock doesn't work correctly in my system since right-alt
631 * can change mode while holding it too - ]d
634 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
636 #endif /* KEEP_XKB_LOCK_STATUS */
640 XRRSelectInput(dpy
, scr
->root_win
, RRScreenChangeNotifyMask
);
644 XSetErrorHandler(oldHandler
);
646 if (CantManageScreen
) {
651 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
653 /* screen descriptor for raster graphic library */
654 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
655 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
657 /* if the std colormap stuff works ok, this will be ignored */
658 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
659 if (rattr
.colors_per_channel
< 2)
660 rattr
.colors_per_channel
= 2;
662 /* will only be accounted for in PseudoColor */
663 if (wPreferences
.flags
.create_stdcmap
) {
664 rattr
.standard_colormap_mode
= RCreateStdColormap
;
666 rattr
.standard_colormap_mode
= RUseStdColormap
;
669 if (getWVisualID(screen_number
) >= 0) {
670 rattr
.flags
|= RC_VisualID
;
671 rattr
.visualid
= getWVisualID(screen_number
);
674 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
676 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
677 wwarning(RMessageForError(RErrorCode
));
679 rattr
.flags
&= ~RC_StandardColormap
;
680 rattr
.standard_colormap_mode
= RUseStdColormap
;
682 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
685 if (!scr
->rcontext
) {
686 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
692 formats
= RSupportedFileFormats();
694 for (i
= 0; formats
[i
] != NULL
; i
++) {
695 if (strcmp(formats
[i
], "TIFF") == 0) {
696 scr
->flags
.supports_tiff
= 1;
703 scr
->w_win
= scr
->rcontext
->drawable
;
704 scr
->w_visual
= scr
->rcontext
->visual
;
705 scr
->w_depth
= scr
->rcontext
->depth
;
706 scr
->w_colormap
= scr
->rcontext
->cmap
;
708 /* create screen descriptor for WINGs */
709 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
711 if (!scr
->wmscreen
) {
712 wfatal(_("could not initialize WINGs widget set"));
716 scr
->black
= WMBlackColor(scr
->wmscreen
);
717 scr
->white
= WMWhiteColor(scr
->wmscreen
);
718 scr
->gray
= WMGrayColor(scr
->wmscreen
);
719 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
721 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
722 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
723 scr
->light_pixel
= WMColorPixel(scr
->gray
);
724 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
728 /* frame boder color */
729 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
730 scr
->frame_border_pixel
= xcol
.pixel
;
733 /* create GCs with default values */
736 /* for our window manager info notice board. Need to
737 * create before reading the defaults, because it will be used there.
739 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
741 /* read defaults for this screen */
742 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
744 createInternalWindows(scr
);
746 wNETWMInitStuff(scr
);
748 /* create initial workspace */
751 /* create shared pixmaps */
754 /* set icon sizes we can accept from clients */
755 icon_size
[0].min_width
= 8;
756 icon_size
[0].min_height
= 8;
757 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
758 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
759 icon_size
[0].width_inc
= 1;
760 icon_size
[0].height_inc
= 1;
761 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
763 /* setup WindowMaker protocols property in the root window */
764 PropSetWMakerProtocols(scr
->root_win
);
766 /* setup our noticeboard */
767 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
768 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
769 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
770 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
773 /* initialize balloon text stuff */
774 wBalloonInitialize(scr
);
777 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
779 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
780 if (!scr
->tech_draw_font
)
781 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
783 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
784 WMRealizeWidget(scr
->gview
);
786 wScreenUpdateUsableArea(scr
);
791 void wScreenUpdateUsableArea(WScreen
* scr
)
794 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
795 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
800 unsigned long best_area
= 0, tmp_area
;
802 int dock_head
= scr
->xine_info
.primary_head
;
806 rect
.pos
.x
= scr
->dock
->x_pos
;
807 rect
.pos
.y
= scr
->dock
->y_pos
;
808 rect
.size
.width
= wPreferences
.icon_size
;
809 rect
.size
.height
= wPreferences
.icon_size
;
810 dock_head
= wGetHeadForRect(scr
, rect
);
813 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
814 WMRect rect
= wGetRectForHead(scr
, i
);
815 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
816 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
817 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
818 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
820 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
821 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
823 if (scr
->dock
->on_right_side
) {
824 scr
->totalUsableArea
[i
].x2
-= offset
;
826 scr
->totalUsableArea
[i
].x1
+= offset
;
832 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
833 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
834 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
835 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
836 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
840 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
843 printf("usableArea[%d]: %d %d %d %d\n", i
,
844 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
847 if (wPreferences
.no_window_over_icons
) {
848 if (wPreferences
.icon_yard
& IY_VERT
) {
849 if (wPreferences
.icon_yard
& IY_RIGHT
) {
850 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
852 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
855 if (wPreferences
.icon_yard
& IY_TOP
) {
856 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
858 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
863 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
864 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
865 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
868 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
869 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
870 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
873 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
874 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
876 if (tmp_area
> best_area
) {
877 best_area
= tmp_area
;
878 area
= scr
->totalUsableArea
[i
];
882 unsigned size
= wPreferences
.workspace_border_size
;
883 unsigned position
= wPreferences
.workspace_border_position
;
885 if (size
> 0 && position
!= WB_NONE
) {
886 if (position
& WB_LEFTRIGHT
) {
887 scr
->totalUsableArea
[i
].x1
+= size
;
888 scr
->totalUsableArea
[i
].x2
-= size
;
890 if (position
& WB_TOPBOTTOM
) {
891 scr
->totalUsableArea
[i
].y1
+= size
;
892 scr
->totalUsableArea
[i
].y2
-= size
;
898 wNETWMUpdateWorkarea(scr
, area
);
900 if (wPreferences
.auto_arrange_icons
)
901 wArrangeIcons(scr
, True
);
904 void wScreenRestoreState(WScreen
* scr
)
909 OpenRootMenu(scr
, -10000, -10000, False
);
910 wMenuUnmap(scr
->root_menu
);
914 if (wScreenCount
== 1) {
915 path
= wdefaultspathfordomain("WMState");
918 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
919 path
= wdefaultspathfordomain(buf
);
921 scr
->session_state
= WMReadPropListFromFile(path
);
923 if (!scr
->session_state
&& wScreenCount
> 1) {
924 path
= wdefaultspathfordomain("WMState");
925 scr
->session_state
= WMReadPropListFromFile(path
);
929 if (!scr
->session_state
) {
930 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
933 if (!wPreferences
.flags
.nodock
) {
934 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
935 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
938 if (!wPreferences
.flags
.noclip
) {
939 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
940 scr
->clip_icon
= wClipRestoreState(scr
, state
);
943 wWorkspaceRestoreState(scr
);
945 wScreenUpdateUsableArea(scr
);
948 void wScreenSaveState(WScreen
* scr
)
952 WMPropList
*old_state
, *foo
;
956 /* save state of windows */
957 wwin
= scr
->focused_window
;
959 wWindowSaveState(wwin
);
963 if (wPreferences
.flags
.noupdates
)
966 old_state
= scr
->session_state
;
967 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
969 WMPLSetCaseSensitive(True
);
971 /* save dock state to file */
972 if (!wPreferences
.flags
.nodock
) {
973 wDockSaveState(scr
, old_state
);
975 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
976 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
979 if (!wPreferences
.flags
.noclip
) {
982 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
983 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
987 wWorkspaceSaveState(scr
, old_state
);
989 if (wPreferences
.save_session_on_exit
) {
990 wSessionSaveState(scr
);
992 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
993 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
995 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
996 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1001 WMPLSetCaseSensitive(False
);
1003 wMenuSaveState(scr
);
1005 if (wScreenCount
== 1) {
1006 str
= wdefaultspathfordomain("WMState");
1009 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1010 str
= wdefaultspathfordomain(buf
);
1012 if (!WMWritePropListToFile(scr
->session_state
, str
)) {
1013 wsyserror(_("could not save session state in %s"), str
);
1016 WMReleasePropList(old_state
);
1019 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1024 * With respect to the head that contains most of the window.
1026 int sx1
, sy1
, sx2
, sy2
;
1033 rect
.size
.width
= width
;
1034 rect
.size
.height
= height
;
1036 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1037 rect
= wGetRectForHead(scr
, head
);
1041 sx2
= sx1
+ rect
.size
.width
;
1042 sy2
= sy1
+ rect
.size
.height
;
1044 #if 0 /* NOTE: gives funky group movement */
1045 if (flags
& XFLAG_MULTIPLE
) {
1047 * since we span multiple heads, pull window totaly inside
1050 *x
= sx1
, moved
= 1;
1051 else if (*x
+ width
> sx2
)
1052 *x
= sx2
- width
, moved
= 1;
1055 *y
= sy1
, moved
= 1;
1056 else if (*y
+ height
> sy2
)
1057 *y
= sy2
- height
, moved
= 1;
1073 if (*x
+ width
< sx1
+ 10)
1074 *x
= sx1
- tol_w
, moved
= 1;
1075 else if (*x
>= sx2
- 10)
1076 *x
= sx2
- tol_w
- 1, moved
= 1;
1078 if (*y
< sy1
- height
+ 10)
1079 *y
= sy1
- tol_h
, moved
= 1;
1080 else if (*y
>= sy2
- 10)
1081 *y
= sy2
- tol_h
- 1, moved
= 1;
1086 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1089 int sx1
, sy1
, sx2
, sy2
;
1095 rect
.size
.width
= width
;
1096 rect
.size
.height
= height
;
1098 head
= wGetHeadForRect(scr
, rect
);
1099 rect
= wGetRectForHead(scr
, head
);
1103 sx2
= sx1
+ rect
.size
.width
;
1104 sy2
= sy1
+ rect
.size
.height
;
1107 *x
= sx1
, moved
= 1;
1108 else if (*x
+ width
> sx2
)
1109 *x
= sx2
- width
, moved
= 1;
1112 *y
= sy1
, moved
= 1;
1113 else if (*y
+ height
> sy2
)
1114 *y
= sy2
- height
, moved
= 1;