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"
51 #include "properties.h"
53 #include "resources.h"
54 #include "workspace.h"
63 #include <WINGs/WUtil.h>
67 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
68 |SubstructureNotifyMask|PointerMotionMask \
69 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
70 |KeyPressMask|KeyReleaseMask)
72 /**** Global variables ****/
73 extern Cursor wCursor
[WCUR_LAST
];
74 extern WPreferences wPreferences
;
75 extern Atom _XA_WINDOWMAKER_STATE
;
76 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
78 extern int wScreenCount
;
80 #ifdef KEEP_XKB_LOCK_STATUS
81 extern int wXkbSupported
;
84 extern WDDomain
*WDWindowMaker
;
87 #define STIPPLE_WIDTH 2
88 #define STIPPLE_HEIGHT 2
89 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
91 static int CantManageScreen
= 0;
93 static WMPropList
*dApplications
= NULL
;
94 static WMPropList
*dWorkspace
;
95 static WMPropList
*dDock
;
96 static WMPropList
*dClip
;
98 static void make_keys(void)
100 if (dApplications
!= NULL
)
103 dApplications
= WMCreatePLString("Applications");
104 dWorkspace
= WMCreatePLString("Workspace");
105 dDock
= WMCreatePLString("Dock");
106 dClip
= WMCreatePLString("Clip");
110 *----------------------------------------------------------------------
111 * alreadyRunningError--
112 * X error handler used to catch errors when trying to do
113 * XSelectInput() on the root window. These errors probably mean that
114 * there already is some other window manager running.
117 * Nothing, unless something really evil happens...
120 * CantManageScreen is set to 1;
121 *----------------------------------------------------------------------
123 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
125 CantManageScreen
= 1;
130 *----------------------------------------------------------------------
131 * allocButtonPixmaps--
132 * Allocate pixmaps used on window operation buttons (those in the
133 * titlebar). The pixmaps are linked to the program. If XPM is supported
134 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
140 * Allocates shared pixmaps for the screen. These pixmaps should
141 * not be freed by anybody.
142 *----------------------------------------------------------------------
144 static void allocButtonPixmaps(WScreen
* scr
)
148 /* create predefined pixmaps */
149 if (wPreferences
.new_style
== TS_NEXT
) {
150 pix
= wPixmapCreateFromXPMData(scr
, NEXT_CLOSE_XPM
);
152 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
156 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
158 if (wPreferences
.new_style
== TS_NEXT
) {
159 pix
= wPixmapCreateFromXPMData(scr
, NEXT_BROKEN_CLOSE_XPM
);
161 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
165 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
167 if (wPreferences
.new_style
== TS_NEXT
) {
168 pix
= wPixmapCreateFromXPMData(scr
, NEXT_ICONIFY_XPM
);
170 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
174 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
175 #ifdef XKB_BUTTON_HINT
176 if (wPreferences
.new_style
== TS_NEXT
) {
177 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP1_XPM
);
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
183 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
184 if (wPreferences
.new_style
== TS_NEXT
) {
185 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP2_XPM
);
187 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
191 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
192 if (wPreferences
.new_style
== TS_NEXT
) {
193 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP3_XPM
);
195 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
199 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
200 if (wPreferences
.new_style
== TS_NEXT
) {
201 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP4_XPM
);
203 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
207 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
210 if (wPreferences
.new_style
== TS_NEXT
) {
211 pix
= wPixmapCreateFromXPMData(scr
, NEXT_KILL_XPM
);
213 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
217 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
220 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
222 XSetForeground(dpy
, gc
, scr
->black_pixel
);
223 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
224 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
225 XSetForeground(dpy
, gc
, scr
->white_pixel
);
226 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
227 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
230 static WPixmap
*make3Dots(WScreen
* scr
)
238 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
239 XSetForeground(dpy
, gc
, scr
->black_pixel
);
240 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
241 XSetForeground(dpy
, gc
, scr
->white_pixel
);
242 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
243 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
244 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
246 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
248 gcv
.graphics_exposures
= False
;
249 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
250 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
251 XSetForeground(dpy
, gc2
, 1);
252 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
253 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
254 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
258 wpix
= wPixmapCreate(scr
, pix
, mask
);
264 static void allocGCs(WScreen
* scr
)
270 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
272 gcv
.stipple
= scr
->stipple_bitmap
;
273 gcv
.foreground
= scr
->white_pixel
;
274 gcv
.fill_style
= FillStippled
;
275 gcv
.graphics_exposures
= False
;
276 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
277 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
279 /* selected icon border GCs */
280 gcv
.function
= GXcopy
;
281 gcv
.foreground
= scr
->white_pixel
;
282 gcv
.background
= scr
->black_pixel
;
284 gcv
.line_style
= LineDoubleDash
;
285 gcv
.fill_style
= FillSolid
;
288 gcv
.graphics_exposures
= False
;
290 gcm
= GCFunction
| GCGraphicsExposures
;
291 gcm
|= GCForeground
| GCBackground
;
292 gcm
|= GCLineWidth
| GCLineStyle
;
294 gcm
|= GCDashOffset
| GCDashList
;
296 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
298 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
300 /* don't retain scr->black here because we may alter its alpha */
301 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
302 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
305 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
306 gcv
.function
= GXxor
;
307 /* this will raise the probability of the XORed color being different
308 * of the original color in PseudoColor when not all color cells are
310 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
311 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
313 gcv
.plane_mask
= AllPlanes
;
314 gcv
.foreground
= color
.pixel
;
315 if (gcv
.foreground
== 0)
317 gcv
.line_width
= DEF_FRAME_THICKNESS
;
318 gcv
.subwindow_mode
= IncludeInferiors
;
319 gcv
.graphics_exposures
= False
;
320 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
321 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
324 gcv
.foreground
= color
.pixel
;
326 if (gcv
.foreground
== 0)
327 /* XOR:ing with a zero is not going to be of much use, so
328 in that case, we somewhat arbitrarily xor with 17 instead. */
331 gcv
.function
= GXxor
;
332 gcv
.subwindow_mode
= IncludeInferiors
;
334 gcv
.cap_style
= CapRound
;
335 gcv
.graphics_exposures
= False
;
336 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| GCGraphicsExposures
;
337 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
339 scr
->line_pixel
= gcv
.foreground
;
342 gcv
.foreground
= scr
->white_pixel
;
343 gcv
.background
= scr
->black_pixel
;
344 gcv
.graphics_exposures
= False
;
345 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCGraphicsExposures
, &gcv
);
347 /* misc drawing GC */
348 gcv
.graphics_exposures
= False
;
349 gcm
= GCGraphicsExposures
;
350 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
352 assert(scr
->stipple_bitmap
!= None
);
355 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
358 static void createPixmaps(WScreen
* scr
)
363 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
364 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
365 MENU_RADIO_INDICATOR_XBM_SIZE
,
366 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
369 scr
->menu_radio_indicator
= pix
;
371 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
372 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
373 MENU_CHECK_INDICATOR_XBM_SIZE
,
374 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
377 scr
->menu_check_indicator
= pix
;
379 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
380 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
381 MENU_MINI_INDICATOR_XBM_SIZE
,
382 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
385 scr
->menu_mini_indicator
= pix
;
387 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
388 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
389 MENU_HIDE_INDICATOR_XBM_SIZE
,
390 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
393 scr
->menu_hide_indicator
= pix
;
395 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
396 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
397 MENU_SHADE_INDICATOR_XBM_SIZE
,
398 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
401 scr
->menu_shade_indicator
= pix
;
403 create_logo_image(scr
);
405 scr
->dock_dots
= make3Dots(scr
);
407 /* titlebar button pixmaps */
408 allocButtonPixmaps(scr
);
411 void create_logo_image(WScreen
*scr
)
413 RImage
*image
= get_icon_image(scr
, "Logo", "WMPanel", wPreferences
.icon_size
);
416 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
418 WMSetApplicationIconImage(scr
->wmscreen
, image
);
419 RReleaseImage(image
);
424 *----------------------------------------------------------------------
425 * createInternalWindows--
426 * Creates some windows used internally by the program. One to
427 * receive input focus when no other window can get it and another
428 * to display window geometry information during window resize/move.
434 * Windows are created and some colors are allocated for the
436 *----------------------------------------------------------------------
438 static void createInternalWindows(WScreen
* scr
)
441 XSetWindowAttributes attribs
;
443 /* InputOnly window to get the focus when no other window can get it */
444 vmask
= CWEventMask
| CWOverrideRedirect
;
445 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
446 attribs
.override_redirect
= True
;
447 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
448 InputOnly
, CopyFromParent
, vmask
, &attribs
);
449 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
450 XMapWindow(dpy
, scr
->no_focus_win
);
452 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
454 /* shadow window for dock buttons */
455 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
456 attribs
.border_pixel
= scr
->black_pixel
;
457 attribs
.save_under
= True
;
458 attribs
.override_redirect
= True
;
459 attribs
.background_pixmap
= None
;
460 attribs
.background_pixel
= scr
->white_pixel
;
461 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
463 attribs
.colormap
= scr
->w_colormap
;
465 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
466 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
468 /* workspace name balloon for clip */
469 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
470 attribs
.save_under
= True
;
471 attribs
.override_redirect
= True
;
472 attribs
.colormap
= scr
->w_colormap
;
473 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
474 attribs
.border_pixel
= 0; /* do not care */
476 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
477 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
480 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
481 attribs
.save_under
= True
;
482 attribs
.override_redirect
= True
;
483 attribs
.colormap
= scr
->w_colormap
;
484 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
485 attribs
.border_pixel
= 0; /* do not care */
486 scr
->workspace_name
=
487 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
488 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
491 * If the window is clicked without having ButtonPress selected, the
492 * resulting event will have event.xbutton.window == root.
494 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
498 *----------------------------------------------------------------------
500 * Initializes the window manager for the given screen and
501 * allocates a WScreen descriptor for it. Many resources are allocated
502 * for the screen and the root window is setup appropriately.
505 * The WScreen descriptor for the screen.
508 * Many resources are allocated and the IconSize property is
509 * set on the root window.
510 * The program can be aborted if some fatal error occurs.
512 * TODO: User specifiable visual.
513 *----------------------------------------------------------------------
515 WScreen
*wScreenInit(int screen_number
)
518 XIconSize icon_size
[1];
519 RContextAttributes rattr
;
521 XErrorHandler oldHandler
;
524 scr
= wmalloc(sizeof(WScreen
));
526 scr
->stacking_list
= WMCreateTreeBag();
528 /* initialize globals */
529 scr
->screen
= screen_number
;
530 scr
->root_win
= RootWindow(dpy
, screen_number
);
531 scr
->depth
= DefaultDepth(dpy
, screen_number
);
532 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
534 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
535 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
539 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
540 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
542 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
543 WMRect rect
= wGetRectForHead(scr
, i
);
544 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
545 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
546 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
547 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
550 scr
->fakeGroupLeaders
= WMCreateArray(16);
552 CantManageScreen
= 0;
553 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
555 event_mask
= EVENT_MASK
;
557 if (wPreferences
.disable_root_mouse
) {
558 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
561 XSelectInput(dpy
, scr
->root_win
, event_mask
);
563 #ifdef KEEP_XKB_LOCK_STATUS
564 /* Only GroupLock doesn't work correctly in my system since right-alt
565 * can change mode while holding it too - ]d
568 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
570 #endif /* KEEP_XKB_LOCK_STATUS */
574 XRRSelectInput(dpy
, scr
->root_win
, RRScreenChangeNotifyMask
);
578 XSetErrorHandler(oldHandler
);
580 if (CantManageScreen
) {
585 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
587 /* screen descriptor for raster graphic library */
588 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
589 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
591 /* if the std colormap stuff works ok, this will be ignored */
592 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
593 if (rattr
.colors_per_channel
< 2)
594 rattr
.colors_per_channel
= 2;
596 /* Use standard colormap */
597 rattr
.standard_colormap_mode
= RUseStdColormap
;
599 if (getWVisualID(screen_number
) >= 0) {
600 rattr
.flags
|= RC_VisualID
;
601 rattr
.visualid
= getWVisualID(screen_number
);
604 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
606 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
607 wwarning("%s", RMessageForError(RErrorCode
));
609 rattr
.flags
&= ~RC_StandardColormap
;
610 rattr
.standard_colormap_mode
= RUseStdColormap
;
612 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
615 if (!scr
->rcontext
) {
616 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
622 formats
= RSupportedFileFormats();
624 for (i
= 0; formats
[i
] != NULL
; i
++) {
625 if (strcmp(formats
[i
], "TIFF") == 0) {
626 scr
->flags
.supports_tiff
= 1;
633 scr
->w_win
= scr
->rcontext
->drawable
;
634 scr
->w_visual
= scr
->rcontext
->visual
;
635 scr
->w_depth
= scr
->rcontext
->depth
;
636 scr
->w_colormap
= scr
->rcontext
->cmap
;
638 /* create screen descriptor for WINGs */
639 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
641 if (!scr
->wmscreen
) {
642 wfatal(_("could not initialize WINGs widget set"));
646 scr
->black
= WMBlackColor(scr
->wmscreen
);
647 scr
->white
= WMWhiteColor(scr
->wmscreen
);
648 scr
->gray
= WMGrayColor(scr
->wmscreen
);
649 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
651 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
652 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
653 scr
->light_pixel
= WMColorPixel(scr
->gray
);
654 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
658 /* frame boder color */
659 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
660 scr
->frame_border_pixel
= xcol
.pixel
;
663 /* create GCs with default values */
666 /* for our window manager info notice board. Need to
667 * create before reading the defaults, because it will be used there.
669 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
671 /* read defaults for this screen */
672 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
674 createInternalWindows(scr
);
676 wNETWMInitStuff(scr
);
678 /* create initial workspace */
681 /* create shared pixmaps */
684 /* set icon sizes we can accept from clients */
685 icon_size
[0].min_width
= 8;
686 icon_size
[0].min_height
= 8;
687 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
688 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
689 icon_size
[0].width_inc
= 1;
690 icon_size
[0].height_inc
= 1;
691 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
693 /* setup WindowMaker protocols property in the root window */
694 PropSetWMakerProtocols(scr
->root_win
);
696 /* setup our noticeboard */
697 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
698 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
699 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
700 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
703 /* initialize balloon text stuff */
704 wBalloonInitialize(scr
);
707 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
709 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
710 if (!scr
->tech_draw_font
)
711 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
713 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
714 WMRealizeWidget(scr
->gview
);
716 wScreenUpdateUsableArea(scr
);
721 void wScreenUpdateUsableArea(WScreen
* scr
)
724 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
725 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
731 unsigned long best_area
, tmp_area
;
732 unsigned int size
, position
;
734 dock_head
= scr
->xine_info
.primary_head
;
736 size
= wPreferences
.workspace_border_size
;
737 position
= wPreferences
.workspace_border_position
;
741 rect
.pos
.x
= scr
->dock
->x_pos
;
742 rect
.pos
.y
= scr
->dock
->y_pos
;
743 rect
.size
.width
= wPreferences
.icon_size
;
744 rect
.size
.height
= wPreferences
.icon_size
;
745 dock_head
= wGetHeadForRect(scr
, rect
);
748 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
749 WMRect rect
= wGetRectForHead(scr
, i
);
750 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
751 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
752 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
753 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
755 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
756 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
758 if (scr
->dock
->on_right_side
) {
759 scr
->totalUsableArea
[i
].x2
-= offset
;
761 scr
->totalUsableArea
[i
].x1
+= offset
;
765 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
766 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
767 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
768 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
769 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
772 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
775 printf("usableArea[%d]: %d %d %d %d\n", i
,
776 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
778 if (wPreferences
.no_window_over_icons
) {
779 if (wPreferences
.icon_yard
& IY_VERT
) {
780 if (wPreferences
.icon_yard
& IY_RIGHT
) {
781 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
783 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
786 if (wPreferences
.icon_yard
& IY_TOP
) {
787 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
789 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
794 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
795 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
796 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
799 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
800 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
801 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
804 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
805 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
807 if (tmp_area
> best_area
) {
808 best_area
= tmp_area
;
809 area
= scr
->totalUsableArea
[i
];
812 if (size
> 0 && position
!= WB_NONE
) {
813 if (position
& WB_LEFTRIGHT
) {
814 scr
->totalUsableArea
[i
].x1
+= size
;
815 scr
->totalUsableArea
[i
].x2
-= size
;
817 if (position
& WB_TOPBOTTOM
) {
818 scr
->totalUsableArea
[i
].y1
+= size
;
819 scr
->totalUsableArea
[i
].y2
-= size
;
824 if (wPreferences
.auto_arrange_icons
)
825 wArrangeIcons(scr
, True
);
828 void wScreenRestoreState(WScreen
* scr
)
833 OpenRootMenu(scr
, -10000, -10000, False
);
834 wMenuUnmap(scr
->root_menu
);
838 if (wScreenCount
== 1) {
839 path
= wdefaultspathfordomain("WMState");
842 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
843 path
= wdefaultspathfordomain(buf
);
845 scr
->session_state
= WMReadPropListFromFile(path
);
847 if (!scr
->session_state
&& wScreenCount
> 1) {
848 path
= wdefaultspathfordomain("WMState");
849 scr
->session_state
= WMReadPropListFromFile(path
);
853 if (!scr
->session_state
) {
854 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
857 if (!wPreferences
.flags
.nodock
) {
858 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
859 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
862 if (!wPreferences
.flags
.noclip
) {
863 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
864 scr
->clip_icon
= wClipRestoreState(scr
, state
);
867 wWorkspaceRestoreState(scr
);
869 wScreenUpdateUsableArea(scr
);
872 void wScreenSaveState(WScreen
* scr
)
876 WMPropList
*old_state
, *foo
;
880 /* save state of windows */
881 wwin
= scr
->focused_window
;
883 wWindowSaveState(wwin
);
887 if (wPreferences
.flags
.noupdates
)
890 old_state
= scr
->session_state
;
891 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
893 WMPLSetCaseSensitive(True
);
895 /* save dock state to file */
896 if (!wPreferences
.flags
.nodock
) {
897 wDockSaveState(scr
, old_state
);
899 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
900 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
903 if (!wPreferences
.flags
.noclip
) {
906 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
907 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
911 wWorkspaceSaveState(scr
, old_state
);
913 if (wPreferences
.save_session_on_exit
) {
914 wSessionSaveState(scr
);
916 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
917 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
919 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
920 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
925 WMPLSetCaseSensitive(False
);
929 if (wScreenCount
== 1) {
930 str
= wdefaultspathfordomain("WMState");
933 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
934 str
= wdefaultspathfordomain(buf
);
936 if (!WMWritePropListToFile(scr
->session_state
, str
)) {
937 werror(_("could not save session state in %s"), str
);
940 WMReleasePropList(old_state
);
943 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
948 * With respect to the head that contains most of the window.
950 int sx1
, sy1
, sx2
, sy2
;
957 rect
.size
.width
= width
;
958 rect
.size
.height
= height
;
960 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
961 rect
= wGetRectForHead(scr
, head
);
965 sx2
= sx1
+ rect
.size
.width
;
966 sy2
= sy1
+ rect
.size
.height
;
968 #if 0 /* NOTE: gives funky group movement */
969 if (flags
& XFLAG_MULTIPLE
) {
971 * since we span multiple heads, pull window totaly inside
975 else if (*x
+ width
> sx2
)
976 *x
= sx2
- width
, moved
= 1;
980 else if (*y
+ height
> sy2
)
981 *y
= sy2
- height
, moved
= 1;
997 if (*x
+ width
< sx1
+ 10)
998 *x
= sx1
- tol_w
, moved
= 1;
999 else if (*x
>= sx2
- 10)
1000 *x
= sx2
- tol_w
- 1, moved
= 1;
1002 if (*y
< sy1
- height
+ 10)
1003 *y
= sy1
- tol_h
, moved
= 1;
1004 else if (*y
>= sy2
- 10)
1005 *y
= sy2
- tol_h
- 1, moved
= 1;
1010 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1013 int sx1
, sy1
, sx2
, sy2
;
1019 rect
.size
.width
= width
;
1020 rect
.size
.height
= height
;
1022 head
= wGetHeadForRect(scr
, rect
);
1023 rect
= wGetRectForHead(scr
, head
);
1027 sx2
= sx1
+ rect
.size
.width
;
1028 sy2
= sy1
+ rect
.size
.height
;
1031 *x
= sx1
, moved
= 1;
1032 else if (*x
+ width
> sx2
)
1033 *x
= sx2
- width
, moved
= 1;
1036 *y
= sy1
, moved
= 1;
1037 else if (*y
+ height
> sy2
)
1038 *y
= sy2
- height
, moved
= 1;