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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <X11/Xutil.h>
30 #include <X11/Xatom.h>
32 #include <X11/extensions/shape.h>
34 #ifdef KEEP_XKB_LOCK_STATUS
35 #include <X11/XKBlib.h>
36 #endif /* KEEP_XKB_LOCK_STATUS */
38 #include <X11/extensions/Xrandr.h>
42 #include "WindowMaker.h"
43 #include "def_pixmaps.h"
50 #include "properties.h"
52 #include "resources.h"
53 #include "workspace.h"
61 #include <WINGs/WUtil.h>
65 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
66 |SubstructureNotifyMask|PointerMotionMask \
67 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
68 |KeyPressMask|KeyReleaseMask)
70 /**** Global variables ****/
71 extern Cursor wCursor
[WCUR_LAST
];
72 extern WPreferences wPreferences
;
73 extern Atom _XA_WINDOWMAKER_STATE
;
74 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
76 extern int wScreenCount
;
78 #ifdef KEEP_XKB_LOCK_STATUS
79 extern int wXkbSupported
;
85 extern WDDomain
*WDWindowMaker
;
88 #define STIPPLE_WIDTH 2
89 #define STIPPLE_HEIGHT 2
90 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
92 static int CantManageScreen
= 0;
94 static WMPropList
*dApplications
= NULL
;
95 static WMPropList
*dWorkspace
;
96 static WMPropList
*dDock
;
97 static WMPropList
*dClip
;
99 static void make_keys(void)
101 if (dApplications
!= NULL
)
104 dApplications
= WMCreatePLString("Applications");
105 dWorkspace
= WMCreatePLString("Workspace");
106 dDock
= WMCreatePLString("Dock");
107 dClip
= WMCreatePLString("Clip");
111 *----------------------------------------------------------------------
112 * alreadyRunningError--
113 * X error handler used to catch errors when trying to do
114 * XSelectInput() on the root window. These errors probably mean that
115 * there already is some other window manager running.
118 * Nothing, unless something really evil happens...
121 * CantManageScreen is set to 1;
122 *----------------------------------------------------------------------
124 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
126 CantManageScreen
= 1;
131 *----------------------------------------------------------------------
132 * allocButtonPixmaps--
133 * Allocate pixmaps used on window operation buttons (those in the
134 * titlebar). The pixmaps are linked to the program. If XPM is supported
135 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
141 * Allocates shared pixmaps for the screen. These pixmaps should
142 * not be freed by anybody.
143 *----------------------------------------------------------------------
145 static void allocButtonPixmaps(WScreen
* scr
)
149 /* create predefined pixmaps */
150 if (wPreferences
.new_style
== TS_NEXT
) {
151 pix
= wPixmapCreateFromXPMData(scr
, NEXT_CLOSE_XPM
);
153 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
157 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
159 if (wPreferences
.new_style
== TS_NEXT
) {
160 pix
= wPixmapCreateFromXPMData(scr
, NEXT_BROKEN_CLOSE_XPM
);
162 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
166 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
168 if (wPreferences
.new_style
== TS_NEXT
) {
169 pix
= wPixmapCreateFromXPMData(scr
, NEXT_ICONIFY_XPM
);
171 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
175 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
176 #ifdef XKB_BUTTON_HINT
177 if (wPreferences
.new_style
== TS_NEXT
) {
178 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP1_XPM
);
180 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
184 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
185 if (wPreferences
.new_style
== TS_NEXT
) {
186 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP2_XPM
);
188 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
192 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
193 if (wPreferences
.new_style
== TS_NEXT
) {
194 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP3_XPM
);
196 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
200 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
201 if (wPreferences
.new_style
== TS_NEXT
) {
202 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP4_XPM
);
204 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
208 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
211 if (wPreferences
.new_style
== TS_NEXT
) {
212 pix
= wPixmapCreateFromXPMData(scr
, NEXT_KILL_XPM
);
214 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
218 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
221 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
223 XSetForeground(dpy
, gc
, scr
->black_pixel
);
224 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
225 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
226 XSetForeground(dpy
, gc
, scr
->white_pixel
);
227 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
228 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
231 static WPixmap
*make3Dots(WScreen
* scr
)
239 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
240 XSetForeground(dpy
, gc
, scr
->black_pixel
);
241 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
242 XSetForeground(dpy
, gc
, scr
->white_pixel
);
243 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
244 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
245 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
247 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
249 gcv
.graphics_exposures
= False
;
250 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
251 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
252 XSetForeground(dpy
, gc2
, 1);
253 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
254 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
255 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
259 wpix
= wPixmapCreate(scr
, pix
, mask
);
265 static void allocGCs(WScreen
* scr
)
271 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
273 gcv
.stipple
= scr
->stipple_bitmap
;
274 gcv
.foreground
= scr
->white_pixel
;
275 gcv
.fill_style
= FillStippled
;
276 gcv
.graphics_exposures
= False
;
277 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
278 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
280 /* selected icon border GCs */
281 gcv
.function
= GXcopy
;
282 gcv
.foreground
= scr
->white_pixel
;
283 gcv
.background
= scr
->black_pixel
;
285 gcv
.line_style
= LineDoubleDash
;
286 gcv
.fill_style
= FillSolid
;
289 gcv
.graphics_exposures
= False
;
291 gcm
= GCFunction
| GCGraphicsExposures
;
292 gcm
|= GCForeground
| GCBackground
;
293 gcm
|= GCLineWidth
| GCLineStyle
;
295 gcm
|= GCDashOffset
| GCDashList
;
297 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
299 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
301 /* don't retain scr->black here because we may alter its alpha */
302 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
303 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
306 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
307 gcv
.function
= GXxor
;
308 /* this will raise the probability of the XORed color being different
309 * of the original color in PseudoColor when not all color cells are
311 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
312 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
314 gcv
.plane_mask
= AllPlanes
;
315 gcv
.foreground
= color
.pixel
;
316 if (gcv
.foreground
== 0)
318 gcv
.line_width
= DEF_FRAME_THICKNESS
;
319 gcv
.subwindow_mode
= IncludeInferiors
;
320 gcv
.graphics_exposures
= False
;
321 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
322 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
325 gcv
.foreground
= color
.pixel
;
327 if (gcv
.foreground
== 0)
328 /* XOR:ing with a zero is not going to be of much use, so
329 in that case, we somewhat arbitrarily xor with 17 instead. */
332 gcv
.function
= GXxor
;
333 gcv
.subwindow_mode
= IncludeInferiors
;
335 gcv
.cap_style
= CapRound
;
336 gcv
.graphics_exposures
= False
;
337 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| 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
| GCGraphicsExposures
, &gcv
);
348 /* misc drawing GC */
349 gcv
.graphics_exposures
= False
;
350 gcm
= GCGraphicsExposures
;
351 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
353 assert(scr
->stipple_bitmap
!= None
);
356 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
359 static void createPixmaps(WScreen
* scr
)
365 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
366 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
367 MENU_RADIO_INDICATOR_XBM_SIZE
,
368 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
371 scr
->menu_radio_indicator
= pix
;
373 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
374 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
375 MENU_CHECK_INDICATOR_XBM_SIZE
,
376 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
379 scr
->menu_check_indicator
= pix
;
381 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
382 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
383 MENU_MINI_INDICATOR_XBM_SIZE
,
384 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
387 scr
->menu_mini_indicator
= pix
;
389 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
390 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
391 MENU_HIDE_INDICATOR_XBM_SIZE
,
392 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
395 scr
->menu_hide_indicator
= pix
;
397 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
398 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
399 MENU_SHADE_INDICATOR_XBM_SIZE
,
400 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
403 scr
->menu_shade_indicator
= pix
;
405 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
408 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
410 WMSetApplicationIconImage(scr
->wmscreen
, image
);
411 RReleaseImage(image
);
414 scr
->dock_dots
= make3Dots(scr
);
416 /* titlebar button pixmaps */
417 allocButtonPixmaps(scr
);
421 *----------------------------------------------------------------------
422 * createInternalWindows--
423 * Creates some windows used internally by the program. One to
424 * receive input focus when no other window can get it and another
425 * to display window geometry information during window resize/move.
431 * Windows are created and some colors are allocated for the
433 *----------------------------------------------------------------------
435 static void createInternalWindows(WScreen
* scr
)
438 XSetWindowAttributes attribs
;
440 /* InputOnly window to get the focus when no other window can get it */
441 vmask
= CWEventMask
| CWOverrideRedirect
;
442 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
443 attribs
.override_redirect
= True
;
444 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
445 InputOnly
, CopyFromParent
, vmask
, &attribs
);
446 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
447 XMapWindow(dpy
, scr
->no_focus_win
);
449 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
451 /* shadow window for dock buttons */
452 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
453 attribs
.border_pixel
= scr
->black_pixel
;
454 attribs
.save_under
= True
;
455 attribs
.override_redirect
= True
;
456 attribs
.background_pixmap
= None
;
457 attribs
.background_pixel
= scr
->white_pixel
;
458 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
460 attribs
.colormap
= scr
->w_colormap
;
462 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
463 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
465 /* workspace name balloon for clip */
466 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
467 attribs
.save_under
= True
;
468 attribs
.override_redirect
= True
;
469 attribs
.colormap
= scr
->w_colormap
;
470 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
471 attribs
.border_pixel
= 0; /* do not care */
473 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
474 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
477 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
478 attribs
.save_under
= True
;
479 attribs
.override_redirect
= True
;
480 attribs
.colormap
= scr
->w_colormap
;
481 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
482 attribs
.border_pixel
= 0; /* do not care */
483 scr
->workspace_name
=
484 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
485 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
488 * If the window is clicked without having ButtonPress selected, the
489 * resulting event will have event.xbutton.window == root.
491 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
495 static Bool
aquireManagerSelection(WScreen
* scr
)
501 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
502 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
504 /* for race-conditions... */
507 /* if there is another manager running, don't try to replace it
508 * (for now, at least) */
509 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
514 /* become the manager for this screen */
516 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1, 0, 0, 0);
518 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
519 /* get a timestamp */
520 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
, XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
522 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
523 if (ev
.type
== PropertyNotify
) {
524 timestamp
= ev
.xproperty
.time
;
528 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
529 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
531 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
535 /* announce our arrival */
537 ev
.xclient
.type
= ClientMessage
;
538 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
539 ev
.xclient
.destination
= scr
->root_win
;
540 ev
.xclient
.format
= 32;
541 ev
.xclient
.data
.l
[0] = timestamp
;
542 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
543 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
544 ev
.xclient
.data
.l
[3] = 0;
545 ev
.xclient
.data
.l
[4] = 0;
547 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
555 *----------------------------------------------------------------------
557 * Initializes the window manager for the given screen and
558 * allocates a WScreen descriptor for it. Many resources are allocated
559 * for the screen and the root window is setup appropriately.
562 * The WScreen descriptor for the screen.
565 * Many resources are allocated and the IconSize property is
566 * set on the root window.
567 * The program can be aborted if some fatal error occurs.
569 * TODO: User specifiable visual.
570 *----------------------------------------------------------------------
572 WScreen
*wScreenInit(int screen_number
)
575 XIconSize icon_size
[1];
576 RContextAttributes rattr
;
578 XErrorHandler oldHandler
;
581 scr
= wmalloc(sizeof(WScreen
));
582 memset(scr
, 0, sizeof(WScreen
));
584 scr
->stacking_list
= WMCreateTreeBag();
586 /* initialize globals */
587 scr
->screen
= screen_number
;
588 scr
->root_win
= RootWindow(dpy
, screen_number
);
589 scr
->depth
= DefaultDepth(dpy
, screen_number
);
590 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
592 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
593 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
597 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
598 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
600 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
601 WMRect rect
= wGetRectForHead(scr
, i
);
602 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
603 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
604 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
605 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
608 scr
->fakeGroupLeaders
= WMCreateArray(16);
611 if (!aquireManagerSelection(scr
)) {
617 CantManageScreen
= 0;
618 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
620 event_mask
= EVENT_MASK
;
622 if (wPreferences
.disable_root_mouse
) {
623 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
626 XSelectInput(dpy
, scr
->root_win
, event_mask
);
628 #ifdef KEEP_XKB_LOCK_STATUS
629 /* Only GroupLock doesn't work correctly in my system since right-alt
630 * can change mode while holding it too - ]d
633 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
635 #endif /* KEEP_XKB_LOCK_STATUS */
639 XRRSelectInput(dpy
, scr
->root_win
, RRScreenChangeNotifyMask
);
643 XSetErrorHandler(oldHandler
);
645 if (CantManageScreen
) {
650 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
652 /* screen descriptor for raster graphic library */
653 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
654 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
656 /* if the std colormap stuff works ok, this will be ignored */
657 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
658 if (rattr
.colors_per_channel
< 2)
659 rattr
.colors_per_channel
= 2;
661 /* will only be accounted for in PseudoColor */
662 if (wPreferences
.flags
.create_stdcmap
) {
663 rattr
.standard_colormap_mode
= RCreateStdColormap
;
665 rattr
.standard_colormap_mode
= RUseStdColormap
;
668 if (getWVisualID(screen_number
) >= 0) {
669 rattr
.flags
|= RC_VisualID
;
670 rattr
.visualid
= getWVisualID(screen_number
);
673 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
675 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
676 wwarning("%s", RMessageForError(RErrorCode
));
678 rattr
.flags
&= ~RC_StandardColormap
;
679 rattr
.standard_colormap_mode
= RUseStdColormap
;
681 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
684 if (!scr
->rcontext
) {
685 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
691 formats
= RSupportedFileFormats();
693 for (i
= 0; formats
[i
] != NULL
; i
++) {
694 if (strcmp(formats
[i
], "TIFF") == 0) {
695 scr
->flags
.supports_tiff
= 1;
702 scr
->w_win
= scr
->rcontext
->drawable
;
703 scr
->w_visual
= scr
->rcontext
->visual
;
704 scr
->w_depth
= scr
->rcontext
->depth
;
705 scr
->w_colormap
= scr
->rcontext
->cmap
;
707 /* create screen descriptor for WINGs */
708 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
710 if (!scr
->wmscreen
) {
711 wfatal(_("could not initialize WINGs widget set"));
715 scr
->black
= WMBlackColor(scr
->wmscreen
);
716 scr
->white
= WMWhiteColor(scr
->wmscreen
);
717 scr
->gray
= WMGrayColor(scr
->wmscreen
);
718 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
720 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
721 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
722 scr
->light_pixel
= WMColorPixel(scr
->gray
);
723 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
727 /* frame boder color */
728 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
729 scr
->frame_border_pixel
= xcol
.pixel
;
732 /* create GCs with default values */
735 /* for our window manager info notice board. Need to
736 * create before reading the defaults, because it will be used there.
738 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
740 /* read defaults for this screen */
741 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
743 createInternalWindows(scr
);
745 wNETWMInitStuff(scr
);
747 /* create initial workspace */
750 /* create shared pixmaps */
753 /* set icon sizes we can accept from clients */
754 icon_size
[0].min_width
= 8;
755 icon_size
[0].min_height
= 8;
756 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
757 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
758 icon_size
[0].width_inc
= 1;
759 icon_size
[0].height_inc
= 1;
760 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
762 /* setup WindowMaker protocols property in the root window */
763 PropSetWMakerProtocols(scr
->root_win
);
765 /* setup our noticeboard */
766 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
767 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
768 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
769 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
772 /* initialize balloon text stuff */
773 wBalloonInitialize(scr
);
776 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
778 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
779 if (!scr
->tech_draw_font
)
780 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
782 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
783 WMRealizeWidget(scr
->gview
);
785 wScreenUpdateUsableArea(scr
);
790 void wScreenUpdateUsableArea(WScreen
* scr
)
793 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
794 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
799 unsigned long best_area
= 0, tmp_area
;
801 int dock_head
= scr
->xine_info
.primary_head
;
805 rect
.pos
.x
= scr
->dock
->x_pos
;
806 rect
.pos
.y
= scr
->dock
->y_pos
;
807 rect
.size
.width
= wPreferences
.icon_size
;
808 rect
.size
.height
= wPreferences
.icon_size
;
809 dock_head
= wGetHeadForRect(scr
, rect
);
812 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
813 WMRect rect
= wGetRectForHead(scr
, i
);
814 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
815 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
816 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
817 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
819 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
820 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
822 if (scr
->dock
->on_right_side
) {
823 scr
->totalUsableArea
[i
].x2
-= offset
;
825 scr
->totalUsableArea
[i
].x1
+= offset
;
831 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
832 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
833 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
834 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
835 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
839 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
842 printf("usableArea[%d]: %d %d %d %d\n", i
,
843 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
846 if (wPreferences
.no_window_over_icons
) {
847 if (wPreferences
.icon_yard
& IY_VERT
) {
848 if (wPreferences
.icon_yard
& IY_RIGHT
) {
849 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
851 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
854 if (wPreferences
.icon_yard
& IY_TOP
) {
855 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
857 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
862 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
863 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
864 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
867 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
868 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
869 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
872 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
873 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
875 if (tmp_area
> best_area
) {
876 best_area
= tmp_area
;
877 area
= scr
->totalUsableArea
[i
];
881 unsigned size
= wPreferences
.workspace_border_size
;
882 unsigned position
= wPreferences
.workspace_border_position
;
884 if (size
> 0 && position
!= WB_NONE
) {
885 if (position
& WB_LEFTRIGHT
) {
886 scr
->totalUsableArea
[i
].x1
+= size
;
887 scr
->totalUsableArea
[i
].x2
-= size
;
889 if (position
& WB_TOPBOTTOM
) {
890 scr
->totalUsableArea
[i
].y1
+= size
;
891 scr
->totalUsableArea
[i
].y2
-= size
;
897 wNETWMUpdateWorkarea(scr
, area
);
899 if (wPreferences
.auto_arrange_icons
)
900 wArrangeIcons(scr
, True
);
903 void wScreenRestoreState(WScreen
* scr
)
908 OpenRootMenu(scr
, -10000, -10000, False
);
909 wMenuUnmap(scr
->root_menu
);
913 if (wScreenCount
== 1) {
914 path
= wdefaultspathfordomain("WMState");
917 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
918 path
= wdefaultspathfordomain(buf
);
920 scr
->session_state
= WMReadPropListFromFile(path
);
922 if (!scr
->session_state
&& wScreenCount
> 1) {
923 path
= wdefaultspathfordomain("WMState");
924 scr
->session_state
= WMReadPropListFromFile(path
);
928 if (!scr
->session_state
) {
929 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
932 if (!wPreferences
.flags
.nodock
) {
933 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
934 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
937 if (!wPreferences
.flags
.noclip
) {
938 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
939 scr
->clip_icon
= wClipRestoreState(scr
, state
);
942 wWorkspaceRestoreState(scr
);
944 wScreenUpdateUsableArea(scr
);
947 void wScreenSaveState(WScreen
* scr
)
951 WMPropList
*old_state
, *foo
;
955 /* save state of windows */
956 wwin
= scr
->focused_window
;
958 wWindowSaveState(wwin
);
962 if (wPreferences
.flags
.noupdates
)
965 old_state
= scr
->session_state
;
966 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
968 WMPLSetCaseSensitive(True
);
970 /* save dock state to file */
971 if (!wPreferences
.flags
.nodock
) {
972 wDockSaveState(scr
, old_state
);
974 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
975 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
978 if (!wPreferences
.flags
.noclip
) {
981 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
982 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
986 wWorkspaceSaveState(scr
, old_state
);
988 if (wPreferences
.save_session_on_exit
) {
989 wSessionSaveState(scr
);
991 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
992 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
994 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
995 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1000 WMPLSetCaseSensitive(False
);
1002 wMenuSaveState(scr
);
1004 if (wScreenCount
== 1) {
1005 str
= wdefaultspathfordomain("WMState");
1008 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1009 str
= wdefaultspathfordomain(buf
);
1011 if (!WMWritePropListToFile(scr
->session_state
, str
)) {
1012 werror(_("could not save session state in %s"), str
);
1015 WMReleasePropList(old_state
);
1018 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1023 * With respect to the head that contains most of the window.
1025 int sx1
, sy1
, sx2
, sy2
;
1032 rect
.size
.width
= width
;
1033 rect
.size
.height
= height
;
1035 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1036 rect
= wGetRectForHead(scr
, head
);
1040 sx2
= sx1
+ rect
.size
.width
;
1041 sy2
= sy1
+ rect
.size
.height
;
1043 #if 0 /* NOTE: gives funky group movement */
1044 if (flags
& XFLAG_MULTIPLE
) {
1046 * since we span multiple heads, pull window totaly inside
1049 *x
= sx1
, moved
= 1;
1050 else if (*x
+ width
> sx2
)
1051 *x
= sx2
- width
, moved
= 1;
1054 *y
= sy1
, moved
= 1;
1055 else if (*y
+ height
> sy2
)
1056 *y
= sy2
- height
, moved
= 1;
1072 if (*x
+ width
< sx1
+ 10)
1073 *x
= sx1
- tol_w
, moved
= 1;
1074 else if (*x
>= sx2
- 10)
1075 *x
= sx2
- tol_w
- 1, moved
= 1;
1077 if (*y
< sy1
- height
+ 10)
1078 *y
= sy1
- tol_h
, moved
= 1;
1079 else if (*y
>= sy2
- 10)
1080 *y
= sy2
- tol_h
- 1, moved
= 1;
1085 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1088 int sx1
, sy1
, sx2
, sy2
;
1094 rect
.size
.width
= width
;
1095 rect
.size
.height
= height
;
1097 head
= wGetHeadForRect(scr
, rect
);
1098 rect
= wGetRectForHead(scr
, head
);
1102 sx2
= sx1
+ rect
.size
.width
;
1103 sy2
= sy1
+ rect
.size
.height
;
1106 *x
= sx1
, moved
= 1;
1107 else if (*x
+ width
> sx2
)
1108 *x
= sx2
- width
, moved
= 1;
1111 *y
= sy1
, moved
= 1;
1112 else if (*y
+ height
> sy2
)
1113 *y
= sy2
- height
, moved
= 1;