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 */
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
49 #include "properties.h"
51 #include "resources.h"
52 #include "workspace.h"
60 #include <WINGs/WUtil.h>
64 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
65 |SubstructureNotifyMask|PointerMotionMask \
66 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
67 |KeyPressMask|KeyReleaseMask)
69 /**** Global variables ****/
70 extern Cursor wCursor
[WCUR_LAST
];
71 extern WPreferences wPreferences
;
72 extern Atom _XA_WINDOWMAKER_STATE
;
73 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
75 extern int wScreenCount
;
77 #ifdef KEEP_XKB_LOCK_STATUS
78 extern int wXkbSupported
;
81 extern WDDomain
*WDWindowMaker
;
84 #define STIPPLE_WIDTH 2
85 #define STIPPLE_HEIGHT 2
86 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
88 static int CantManageScreen
= 0;
90 static WMPropList
*dApplications
= NULL
;
91 static WMPropList
*dWorkspace
;
92 static WMPropList
*dDock
;
93 static WMPropList
*dClip
;
95 static void make_keys()
97 if (dApplications
!= NULL
)
100 dApplications
= WMCreatePLString("Applications");
101 dWorkspace
= WMCreatePLString("Workspace");
102 dDock
= WMCreatePLString("Dock");
103 dClip
= WMCreatePLString("Clip");
107 *----------------------------------------------------------------------
108 * alreadyRunningError--
109 * X error handler used to catch errors when trying to do
110 * XSelectInput() on the root window. These errors probably mean that
111 * there already is some other window manager running.
114 * Nothing, unless something really evil happens...
117 * CantManageScreen is set to 1;
118 *----------------------------------------------------------------------
120 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
122 CantManageScreen
= 1;
127 *----------------------------------------------------------------------
128 * allocButtonPixmaps--
129 * Allocate pixmaps used on window operation buttons (those in the
130 * titlebar). The pixmaps are linked to the program. If XPM is supported
131 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
137 * Allocates shared pixmaps for the screen. These pixmaps should
138 * not be freed by anybody.
139 *----------------------------------------------------------------------
141 static void allocButtonPixmaps(WScreen
* scr
)
145 /* create predefined pixmaps */
146 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
149 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
151 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
154 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
156 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
159 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
160 #ifdef XKB_BUTTON_HINT
161 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
164 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
165 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
168 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
169 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
172 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
173 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
176 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
182 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
185 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
187 XSetForeground(dpy
, gc
, scr
->black_pixel
);
188 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
189 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
190 XSetForeground(dpy
, gc
, scr
->white_pixel
);
191 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
192 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
195 static WPixmap
*make3Dots(WScreen
* scr
)
203 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
204 XSetForeground(dpy
, gc
, scr
->black_pixel
);
205 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
206 XSetForeground(dpy
, gc
, scr
->white_pixel
);
207 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
208 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
209 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
211 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
213 gcv
.graphics_exposures
= False
;
214 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
215 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
216 XSetForeground(dpy
, gc2
, 1);
217 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
218 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
219 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
223 wpix
= wPixmapCreate(scr
, pix
, mask
);
229 static void allocGCs(WScreen
* scr
)
235 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
237 gcv
.stipple
= scr
->stipple_bitmap
;
238 gcv
.foreground
= scr
->white_pixel
;
239 gcv
.fill_style
= FillStippled
;
240 gcv
.graphics_exposures
= False
;
241 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
242 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
244 /* selected icon border GCs */
245 gcv
.function
= GXcopy
;
246 gcv
.foreground
= scr
->white_pixel
;
247 gcv
.background
= scr
->black_pixel
;
249 gcv
.line_style
= LineDoubleDash
;
250 gcv
.fill_style
= FillSolid
;
253 gcv
.graphics_exposures
= False
;
255 gcm
= GCFunction
| GCGraphicsExposures
;
256 gcm
|= GCForeground
| GCBackground
;
257 gcm
|= GCLineWidth
| GCLineStyle
;
259 gcm
|= GCDashOffset
| GCDashList
;
261 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
263 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
265 /* don't retain scr->black here because we may alter its alpha */
266 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
267 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
270 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
271 gcv
.function
= GXxor
;
272 /* this will raise the probability of the XORed color being different
273 * of the original color in PseudoColor when not all color cells are
275 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
276 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
278 gcv
.plane_mask
= AllPlanes
;
279 gcv
.foreground
= color
.pixel
;
280 if (gcv
.foreground
== 0)
282 gcv
.line_width
= DEF_FRAME_THICKNESS
;
283 gcv
.subwindow_mode
= IncludeInferiors
;
284 gcv
.graphics_exposures
= False
;
285 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
286 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
289 gcv
.foreground
= color
.pixel
;
291 if (gcv
.foreground
== 0)
292 /* XOR:ing with a zero is not going to be of much use, so
293 in that case, we somewhat arbitrarily xor with 17 instead. */
296 gcv
.function
= GXxor
;
297 gcv
.subwindow_mode
= IncludeInferiors
;
299 gcv
.cap_style
= CapRound
;
300 gcv
.graphics_exposures
= False
;
301 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| GCGraphicsExposures
;
302 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
304 scr
->line_pixel
= gcv
.foreground
;
307 gcv
.foreground
= scr
->white_pixel
;
308 gcv
.background
= scr
->black_pixel
;
309 gcv
.graphics_exposures
= False
;
310 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCGraphicsExposures
, &gcv
);
312 /* misc drawing GC */
313 gcv
.graphics_exposures
= False
;
314 gcm
= GCGraphicsExposures
;
315 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
317 assert(scr
->stipple_bitmap
!= None
);
320 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
323 static void createPixmaps(WScreen
* scr
)
329 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
330 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
331 MENU_RADIO_INDICATOR_XBM_SIZE
,
332 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
335 scr
->menu_radio_indicator
= pix
;
337 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
338 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
339 MENU_CHECK_INDICATOR_XBM_SIZE
,
340 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
343 scr
->menu_check_indicator
= pix
;
345 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
346 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
347 MENU_MINI_INDICATOR_XBM_SIZE
,
348 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
351 scr
->menu_mini_indicator
= pix
;
353 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
354 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
355 MENU_HIDE_INDICATOR_XBM_SIZE
,
356 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
359 scr
->menu_hide_indicator
= pix
;
361 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
362 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
363 MENU_SHADE_INDICATOR_XBM_SIZE
,
364 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
367 scr
->menu_shade_indicator
= pix
;
369 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
372 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
374 WMSetApplicationIconImage(scr
->wmscreen
, image
);
375 RReleaseImage(image
);
378 scr
->dock_dots
= make3Dots(scr
);
380 /* titlebar button pixmaps */
381 allocButtonPixmaps(scr
);
385 *----------------------------------------------------------------------
386 * createInternalWindows--
387 * Creates some windows used internally by the program. One to
388 * receive input focus when no other window can get it and another
389 * to display window geometry information during window resize/move.
395 * Windows are created and some colors are allocated for the
397 *----------------------------------------------------------------------
399 static void createInternalWindows(WScreen
* scr
)
402 XSetWindowAttributes attribs
;
404 /* InputOnly window to get the focus when no other window can get it */
405 vmask
= CWEventMask
| CWOverrideRedirect
;
406 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
407 attribs
.override_redirect
= True
;
408 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
409 InputOnly
, CopyFromParent
, vmask
, &attribs
);
410 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
411 XMapWindow(dpy
, scr
->no_focus_win
);
413 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
415 /* shadow window for dock buttons */
416 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
417 attribs
.border_pixel
= scr
->black_pixel
;
418 attribs
.save_under
= True
;
419 attribs
.override_redirect
= True
;
420 attribs
.background_pixmap
= None
;
421 attribs
.background_pixel
= scr
->white_pixel
;
422 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
424 attribs
.colormap
= scr
->w_colormap
;
426 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
427 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
429 /* workspace name balloon for clip */
430 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
431 attribs
.save_under
= True
;
432 attribs
.override_redirect
= True
;
433 attribs
.colormap
= scr
->w_colormap
;
434 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
435 attribs
.border_pixel
= 0; /* do not care */
437 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
438 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
441 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
442 attribs
.save_under
= True
;
443 attribs
.override_redirect
= True
;
444 attribs
.colormap
= scr
->w_colormap
;
445 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
446 attribs
.border_pixel
= 0; /* do not care */
447 scr
->workspace_name
=
448 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
449 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
452 * If the window is clicked without having ButtonPress selected, the
453 * resulting event will have event.xbutton.window == root.
455 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
459 static Bool
aquireManagerSelection(WScreen
* scr
)
465 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
466 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
468 /* for race-conditions... */
471 /* if there is another manager running, don't try to replace it
472 * (for now, at least) */
473 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
478 /* become the manager for this screen */
480 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1, 0, 0, 0);
482 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
483 /* get a timestamp */
484 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
, XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
486 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
487 if (ev
.type
== PropertyNotify
) {
488 timestamp
= ev
.xproperty
.time
;
492 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
493 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
495 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
499 /* announce our arrival */
501 ev
.xclient
.type
= ClientMessage
;
502 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
503 ev
.xclient
.destination
= scr
->root_win
;
504 ev
.xclient
.format
= 32;
505 ev
.xclient
.data
.l
[0] = timestamp
;
506 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
507 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
508 ev
.xclient
.data
.l
[3] = 0;
509 ev
.xclient
.data
.l
[4] = 0;
511 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
519 *----------------------------------------------------------------------
521 * Initializes the window manager for the given screen and
522 * allocates a WScreen descriptor for it. Many resources are allocated
523 * for the screen and the root window is setup appropriately.
526 * The WScreen descriptor for the screen.
529 * Many resources are allocated and the IconSize property is
530 * set on the root window.
531 * The program can be aborted if some fatal error occurs.
533 * TODO: User specifiable visual.
534 *----------------------------------------------------------------------
536 WScreen
*wScreenInit(int screen_number
)
539 XIconSize icon_size
[1];
540 RContextAttributes rattr
;
541 extern int wVisualID
;
543 XErrorHandler oldHandler
;
546 scr
= wmalloc(sizeof(WScreen
));
547 memset(scr
, 0, sizeof(WScreen
));
549 scr
->stacking_list
= WMCreateTreeBag();
551 /* initialize globals */
552 scr
->screen
= screen_number
;
553 scr
->root_win
= RootWindow(dpy
, screen_number
);
554 scr
->depth
= DefaultDepth(dpy
, screen_number
);
555 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
557 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
558 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
562 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
563 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
565 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
566 WMRect rect
= wGetRectForHead(scr
, i
);
567 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
568 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
569 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
570 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
573 scr
->fakeGroupLeaders
= WMCreateArray(16);
576 if (!aquireManagerSelection(scr
)) {
582 CantManageScreen
= 0;
583 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
585 event_mask
= EVENT_MASK
;
587 if (wPreferences
.disable_root_mouse
) {
588 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
591 XSelectInput(dpy
, scr
->root_win
, event_mask
);
593 #ifdef KEEP_XKB_LOCK_STATUS
594 /* Only GroupLock doesn't work correctly in my system since right-alt
595 * can change mode while holding it too - ]d
598 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
600 #endif /* KEEP_XKB_LOCK_STATUS */
603 XSetErrorHandler(oldHandler
);
605 if (CantManageScreen
) {
610 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
612 /* screen descriptor for raster graphic library */
613 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
614 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
616 /* if the std colormap stuff works ok, this will be ignored */
617 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
618 if (rattr
.colors_per_channel
< 2)
619 rattr
.colors_per_channel
= 2;
621 /* will only be accounted for in PseudoColor */
622 if (wPreferences
.flags
.create_stdcmap
) {
623 rattr
.standard_colormap_mode
= RCreateStdColormap
;
625 rattr
.standard_colormap_mode
= RUseStdColormap
;
628 if (wVisualID
>= 0) {
629 rattr
.flags
|= RC_VisualID
;
630 rattr
.visualid
= wVisualID
;
633 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
635 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
636 wwarning(RMessageForError(RErrorCode
));
638 rattr
.flags
&= ~RC_StandardColormap
;
639 rattr
.standard_colormap_mode
= RUseStdColormap
;
641 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
644 if (!scr
->rcontext
) {
645 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
651 formats
= RSupportedFileFormats();
653 for (i
= 0; formats
[i
] != NULL
; i
++) {
654 if (strcmp(formats
[i
], "TIFF") == 0) {
655 scr
->flags
.supports_tiff
= 1;
662 scr
->w_win
= scr
->rcontext
->drawable
;
663 scr
->w_visual
= scr
->rcontext
->visual
;
664 scr
->w_depth
= scr
->rcontext
->depth
;
665 scr
->w_colormap
= scr
->rcontext
->cmap
;
667 /* create screen descriptor for WINGs */
668 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
670 if (!scr
->wmscreen
) {
671 wfatal(_("could not initialize WINGs widget set"));
675 scr
->black
= WMBlackColor(scr
->wmscreen
);
676 scr
->white
= WMWhiteColor(scr
->wmscreen
);
677 scr
->gray
= WMGrayColor(scr
->wmscreen
);
678 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
680 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
681 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
682 scr
->light_pixel
= WMColorPixel(scr
->gray
);
683 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
687 /* frame boder color */
688 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
689 scr
->frame_border_pixel
= xcol
.pixel
;
692 /* create GCs with default values */
695 /* for our window manager info notice board. Need to
696 * create before reading the defaults, because it will be used there.
698 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
700 /* read defaults for this screen */
701 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
703 createInternalWindows(scr
);
705 wNETWMInitStuff(scr
);
707 /* create initial workspace */
710 /* create shared pixmaps */
713 /* set icon sizes we can accept from clients */
714 icon_size
[0].min_width
= 8;
715 icon_size
[0].min_height
= 8;
716 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
717 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
718 icon_size
[0].width_inc
= 1;
719 icon_size
[0].height_inc
= 1;
720 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
722 /* setup WindowMaker protocols property in the root window */
723 PropSetWMakerProtocols(scr
->root_win
);
725 /* setup our noticeboard */
726 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
727 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
728 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
729 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
732 /* initialize balloon text stuff */
733 wBalloonInitialize(scr
);
736 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
738 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
739 if (!scr
->tech_draw_font
)
740 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
742 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
743 WMRealizeWidget(scr
->gview
);
745 wScreenUpdateUsableArea(scr
);
750 void wScreenUpdateUsableArea(WScreen
* scr
)
753 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
754 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
759 unsigned long best_area
= 0, tmp_area
;
761 int dock_head
= scr
->xine_info
.primary_head
;
765 rect
.pos
.x
= scr
->dock
->x_pos
;
766 rect
.pos
.y
= scr
->dock
->y_pos
;
767 rect
.size
.width
= wPreferences
.icon_size
;
768 rect
.size
.height
= wPreferences
.icon_size
;
769 dock_head
= wGetHeadForRect(scr
, rect
);
772 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
773 WMRect rect
= wGetRectForHead(scr
, i
);
774 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
775 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
776 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
777 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
779 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
780 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
782 if (scr
->dock
->on_right_side
) {
783 scr
->totalUsableArea
[i
].x2
-= offset
;
785 scr
->totalUsableArea
[i
].x1
+= offset
;
791 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
792 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
793 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
794 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
795 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
799 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
802 printf("usableArea[%d]: %d %d %d %d\n", i
,
803 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
806 if (wPreferences
.no_window_over_icons
) {
807 if (wPreferences
.icon_yard
& IY_VERT
) {
808 if (wPreferences
.icon_yard
& IY_RIGHT
) {
809 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
811 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
814 if (wPreferences
.icon_yard
& IY_TOP
) {
815 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
817 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
822 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
823 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
824 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
827 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
828 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
829 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
832 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
833 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
835 if (tmp_area
> best_area
) {
836 best_area
= tmp_area
;
837 area
= scr
->totalUsableArea
[i
];
841 unsigned size
= wPreferences
.workspace_border_size
;
842 unsigned position
= wPreferences
.workspace_border_position
;
844 if (size
> 0 && position
!= WB_NONE
) {
845 if (position
& WB_LEFTRIGHT
) {
846 scr
->totalUsableArea
[i
].x1
+= size
;
847 scr
->totalUsableArea
[i
].x2
-= size
;
849 if (position
& WB_TOPBOTTOM
) {
850 scr
->totalUsableArea
[i
].y1
+= size
;
851 scr
->totalUsableArea
[i
].y2
-= size
;
857 wNETWMUpdateWorkarea(scr
, area
);
859 if (wPreferences
.auto_arrange_icons
)
860 wArrangeIcons(scr
, True
);
863 void wScreenRestoreState(WScreen
* scr
)
868 OpenRootMenu(scr
, -10000, -10000, False
);
869 wMenuUnmap(scr
->root_menu
);
873 if (wScreenCount
== 1) {
874 path
= wdefaultspathfordomain("WMState");
877 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
878 path
= wdefaultspathfordomain(buf
);
880 scr
->session_state
= WMReadPropListFromFile(path
);
882 if (!scr
->session_state
&& wScreenCount
> 1) {
883 path
= wdefaultspathfordomain("WMState");
884 scr
->session_state
= WMReadPropListFromFile(path
);
888 if (!scr
->session_state
) {
889 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
892 if (!wPreferences
.flags
.nodock
) {
893 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
894 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
897 if (!wPreferences
.flags
.noclip
) {
898 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
899 scr
->clip_icon
= wClipRestoreState(scr
, state
);
902 wWorkspaceRestoreState(scr
);
904 wScreenUpdateUsableArea(scr
);
907 void wScreenSaveState(WScreen
* scr
)
911 WMPropList
*old_state
, *foo
;
915 /* save state of windows */
916 wwin
= scr
->focused_window
;
918 wWindowSaveState(wwin
);
922 if (wPreferences
.flags
.noupdates
)
925 old_state
= scr
->session_state
;
926 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
928 WMPLSetCaseSensitive(True
);
930 /* save dock state to file */
931 if (!wPreferences
.flags
.nodock
) {
932 wDockSaveState(scr
, old_state
);
934 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
935 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
938 if (!wPreferences
.flags
.noclip
) {
941 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
942 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
946 wWorkspaceSaveState(scr
, old_state
);
948 if (wPreferences
.save_session_on_exit
) {
949 wSessionSaveState(scr
);
951 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
952 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
954 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
955 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
960 WMPLSetCaseSensitive(False
);
964 if (wScreenCount
== 1) {
965 str
= wdefaultspathfordomain("WMState");
968 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
969 str
= wdefaultspathfordomain(buf
);
971 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
972 wsyserror(_("could not save session state in %s"), str
);
975 WMReleasePropList(old_state
);
978 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
983 * With respect to the head that contains most of the window.
985 int sx1
, sy1
, sx2
, sy2
;
992 rect
.size
.width
= width
;
993 rect
.size
.height
= height
;
995 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
996 rect
= wGetRectForHead(scr
, head
);
1000 sx2
= sx1
+ rect
.size
.width
;
1001 sy2
= sy1
+ rect
.size
.height
;
1003 #if 0 /* NOTE: gives funky group movement */
1004 if (flags
& XFLAG_MULTIPLE
) {
1006 * since we span multiple heads, pull window totaly inside
1009 *x
= sx1
, moved
= 1;
1010 else if (*x
+ width
> sx2
)
1011 *x
= sx2
- width
, moved
= 1;
1014 *y
= sy1
, moved
= 1;
1015 else if (*y
+ height
> sy2
)
1016 *y
= sy2
- height
, moved
= 1;
1032 if (*x
+ width
< sx1
+ 10)
1033 *x
= sx1
- tol_w
, moved
= 1;
1034 else if (*x
>= sx2
- 10)
1035 *x
= sx2
- tol_w
- 1, moved
= 1;
1037 if (*y
< sy1
- height
+ 10)
1038 *y
= sy1
- tol_h
, moved
= 1;
1039 else if (*y
>= sy2
- 10)
1040 *y
= sy2
- tol_h
- 1, moved
= 1;
1045 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1048 int sx1
, sy1
, sx2
, sy2
;
1054 rect
.size
.width
= width
;
1055 rect
.size
.height
= height
;
1057 head
= wGetHeadForRect(scr
, rect
);
1058 rect
= wGetRectForHead(scr
, head
);
1062 sx2
= sx1
+ rect
.size
.width
;
1063 sy2
= sy1
+ rect
.size
.height
;
1066 *x
= sx1
, moved
= 1;
1067 else if (*x
+ width
> sx2
)
1068 *x
= sx2
- width
, moved
= 1;
1071 *y
= sy1
, moved
= 1;
1072 else if (*y
+ height
> sy2
)
1073 *y
= sy2
- height
, moved
= 1;