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
;
89 extern WDDomain
*WDWindowMaker
;
92 #define STIPPLE_WIDTH 2
93 #define STIPPLE_HEIGHT 2
94 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
96 static int CantManageScreen
= 0;
98 static WMPropList
*dApplications
= NULL
;
99 static WMPropList
*dWorkspace
;
100 static WMPropList
*dDock
;
101 static WMPropList
*dClip
;
102 static WMPropList
*dDrawers
= NULL
;
104 static void make_keys(void)
106 if (dApplications
!= NULL
)
109 dApplications
= WMCreatePLString("Applications");
110 dWorkspace
= WMCreatePLString("Workspace");
111 dDock
= WMCreatePLString("Dock");
112 dClip
= WMCreatePLString("Clip");
113 dDrawers
= WMCreatePLString("Drawers");
117 *----------------------------------------------------------------------
118 * alreadyRunningError--
119 * X error handler used to catch errors when trying to do
120 * XSelectInput() on the root window. These errors probably mean that
121 * there already is some other window manager running.
124 * Nothing, unless something really evil happens...
127 * CantManageScreen is set to 1;
128 *----------------------------------------------------------------------
130 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
132 CantManageScreen
= 1;
137 *----------------------------------------------------------------------
138 * allocButtonPixmaps--
139 * Allocate pixmaps used on window operation buttons (those in the
140 * titlebar). The pixmaps are linked to the program. If XPM is supported
141 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
147 * Allocates shared pixmaps for the screen. These pixmaps should
148 * not be freed by anybody.
149 *----------------------------------------------------------------------
151 static void allocButtonPixmaps(WScreen
* scr
)
155 /* create predefined pixmaps */
156 if (wPreferences
.new_style
== TS_NEXT
) {
157 pix
= wPixmapCreateFromXPMData(scr
, NEXT_CLOSE_XPM
);
159 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
163 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
165 if (wPreferences
.new_style
== TS_NEXT
) {
166 pix
= wPixmapCreateFromXPMData(scr
, NEXT_BROKEN_CLOSE_XPM
);
168 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
172 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
174 if (wPreferences
.new_style
== TS_NEXT
) {
175 pix
= wPixmapCreateFromXPMData(scr
, NEXT_ICONIFY_XPM
);
177 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
181 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
182 #ifdef XKB_BUTTON_HINT
183 if (wPreferences
.new_style
== TS_NEXT
) {
184 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP1_XPM
);
186 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
190 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
191 if (wPreferences
.new_style
== TS_NEXT
) {
192 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP2_XPM
);
194 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
198 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
199 if (wPreferences
.new_style
== TS_NEXT
) {
200 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP3_XPM
);
202 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
206 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
207 if (wPreferences
.new_style
== TS_NEXT
) {
208 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP4_XPM
);
210 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
214 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
217 if (wPreferences
.new_style
== TS_NEXT
) {
218 pix
= wPixmapCreateFromXPMData(scr
, NEXT_KILL_XPM
);
220 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
224 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
227 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
229 XSetForeground(dpy
, gc
, scr
->black_pixel
);
230 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
231 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
232 XSetForeground(dpy
, gc
, scr
->white_pixel
);
233 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
234 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
237 static WPixmap
*make3Dots(WScreen
* scr
)
245 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
246 XSetForeground(dpy
, gc
, scr
->black_pixel
);
247 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
248 XSetForeground(dpy
, gc
, scr
->white_pixel
);
249 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
250 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
251 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
253 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
255 gcv
.graphics_exposures
= False
;
256 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
257 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
258 XSetForeground(dpy
, gc2
, 1);
259 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
260 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
261 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
265 wpix
= wPixmapCreate(scr
, pix
, mask
);
271 static void allocGCs(WScreen
* scr
)
277 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
279 gcv
.stipple
= scr
->stipple_bitmap
;
280 gcv
.foreground
= scr
->white_pixel
;
281 gcv
.fill_style
= FillStippled
;
282 gcv
.graphics_exposures
= False
;
283 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
284 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
286 /* selected icon border GCs */
287 gcv
.function
= GXcopy
;
288 gcv
.foreground
= scr
->white_pixel
;
289 gcv
.background
= scr
->black_pixel
;
291 gcv
.line_style
= LineDoubleDash
;
292 gcv
.fill_style
= FillSolid
;
295 gcv
.graphics_exposures
= False
;
297 gcm
= GCFunction
| GCGraphicsExposures
;
298 gcm
|= GCForeground
| GCBackground
;
299 gcm
|= GCLineWidth
| GCLineStyle
;
301 gcm
|= GCDashOffset
| GCDashList
;
303 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
305 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
307 /* don't retain scr->black here because we may alter its alpha */
308 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
309 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
312 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
313 gcv
.function
= GXxor
;
314 /* this will raise the probability of the XORed color being different
315 * of the original color in PseudoColor when not all color cells are
317 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
318 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
320 gcv
.plane_mask
= AllPlanes
;
321 gcv
.foreground
= color
.pixel
;
322 if (gcv
.foreground
== 0)
324 gcv
.line_width
= DEF_FRAME_THICKNESS
;
325 gcv
.subwindow_mode
= IncludeInferiors
;
326 gcv
.graphics_exposures
= False
;
327 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
328 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
331 gcv
.foreground
= color
.pixel
;
333 if (gcv
.foreground
== 0)
334 /* XOR:ing with a zero is not going to be of much use, so
335 in that case, we somewhat arbitrarily xor with 17 instead. */
338 gcv
.function
= GXxor
;
339 gcv
.subwindow_mode
= IncludeInferiors
;
341 gcv
.cap_style
= CapRound
;
342 gcv
.graphics_exposures
= False
;
343 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| GCGraphicsExposures
;
344 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
346 scr
->line_pixel
= gcv
.foreground
;
349 gcv
.foreground
= scr
->white_pixel
;
350 gcv
.background
= scr
->black_pixel
;
351 gcv
.graphics_exposures
= False
;
352 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCGraphicsExposures
, &gcv
);
354 /* misc drawing GC */
355 gcv
.graphics_exposures
= False
;
356 gcm
= GCGraphicsExposures
;
357 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
359 assert(scr
->stipple_bitmap
!= None
);
362 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
365 static void createPixmaps(WScreen
* scr
)
370 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
371 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
372 MENU_RADIO_INDICATOR_XBM_SIZE
,
373 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
376 scr
->menu_radio_indicator
= pix
;
378 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
379 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
380 MENU_CHECK_INDICATOR_XBM_SIZE
,
381 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
384 scr
->menu_check_indicator
= pix
;
386 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
387 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
388 MENU_MINI_INDICATOR_XBM_SIZE
,
389 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
392 scr
->menu_mini_indicator
= pix
;
394 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
395 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
396 MENU_HIDE_INDICATOR_XBM_SIZE
,
397 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
400 scr
->menu_hide_indicator
= pix
;
402 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
403 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
404 MENU_SHADE_INDICATOR_XBM_SIZE
,
405 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
408 scr
->menu_shade_indicator
= pix
;
410 create_logo_image(scr
);
412 scr
->dock_dots
= make3Dots(scr
);
414 /* titlebar button pixmaps */
415 allocButtonPixmaps(scr
);
418 void create_logo_image(WScreen
*scr
)
420 RImage
*image
= get_icon_image(scr
, "Logo", "WMPanel", wPreferences
.icon_size
);
423 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
425 WMSetApplicationIconImage(scr
->wmscreen
, image
);
426 RReleaseImage(image
);
431 *----------------------------------------------------------------------
432 * createInternalWindows--
433 * Creates some windows used internally by the program. One to
434 * receive input focus when no other window can get it and another
435 * to display window geometry information during window resize/move.
441 * Windows are created and some colors are allocated for the
443 *----------------------------------------------------------------------
445 static void createInternalWindows(WScreen
* scr
)
448 XSetWindowAttributes attribs
;
450 /* InputOnly window to get the focus when no other window can get it */
451 vmask
= CWEventMask
| CWOverrideRedirect
;
452 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
453 attribs
.override_redirect
= True
;
454 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
455 InputOnly
, CopyFromParent
, vmask
, &attribs
);
456 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
457 XMapWindow(dpy
, scr
->no_focus_win
);
459 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
461 /* shadow window for dock buttons */
462 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
463 attribs
.border_pixel
= scr
->black_pixel
;
464 attribs
.save_under
= True
;
465 attribs
.override_redirect
= True
;
466 attribs
.background_pixmap
= None
;
467 attribs
.background_pixel
= scr
->white_pixel
;
468 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
470 attribs
.colormap
= scr
->w_colormap
;
472 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
473 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
476 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
477 attribs
.save_under
= True
;
478 attribs
.override_redirect
= True
;
479 attribs
.colormap
= scr
->w_colormap
;
480 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
481 attribs
.border_pixel
= 0; /* do not care */
482 scr
->workspace_name
=
483 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
484 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
488 *----------------------------------------------------------------------
490 * Initializes the window manager for the given screen and
491 * allocates a WScreen descriptor for it. Many resources are allocated
492 * for the screen and the root window is setup appropriately.
495 * The WScreen descriptor for the screen.
498 * Many resources are allocated and the IconSize property is
499 * set on the root window.
500 * The program can be aborted if some fatal error occurs.
502 * TODO: User specifiable visual.
503 *----------------------------------------------------------------------
505 WScreen
*wScreenInit(int screen_number
)
508 XIconSize icon_size
[1];
509 RContextAttributes rattr
;
511 XErrorHandler oldHandler
;
514 scr
= wmalloc(sizeof(WScreen
));
516 scr
->stacking_list
= WMCreateTreeBag();
518 /* initialize globals */
519 scr
->screen
= screen_number
;
520 scr
->root_win
= RootWindow(dpy
, screen_number
);
521 scr
->depth
= DefaultDepth(dpy
, screen_number
);
522 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
524 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
525 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
529 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
530 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
532 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
533 WMRect rect
= wGetRectForHead(scr
, i
);
534 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
535 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
536 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
537 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
540 scr
->fakeGroupLeaders
= WMCreateArray(16);
542 CantManageScreen
= 0;
543 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
545 event_mask
= EVENT_MASK
;
547 if (wPreferences
.disable_root_mouse
) {
548 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
551 XSelectInput(dpy
, scr
->root_win
, event_mask
);
553 #ifdef KEEP_XKB_LOCK_STATUS
554 /* Only GroupLock doesn't work correctly in my system since right-alt
555 * can change mode while holding it too - ]d
558 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
560 #endif /* KEEP_XKB_LOCK_STATUS */
564 XRRSelectInput(dpy
, scr
->root_win
, RRScreenChangeNotifyMask
);
568 XSetErrorHandler(oldHandler
);
570 if (CantManageScreen
) {
575 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
577 /* screen descriptor for raster graphic library */
578 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
579 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
581 /* if the std colormap stuff works ok, this will be ignored */
582 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
583 if (rattr
.colors_per_channel
< 2)
584 rattr
.colors_per_channel
= 2;
586 /* Use standard colormap */
587 rattr
.standard_colormap_mode
= RUseStdColormap
;
589 if (getWVisualID(screen_number
) >= 0) {
590 rattr
.flags
|= RC_VisualID
;
591 rattr
.visualid
= getWVisualID(screen_number
);
594 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
596 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
597 wwarning("%s", RMessageForError(RErrorCode
));
599 rattr
.flags
&= ~RC_StandardColormap
;
600 rattr
.standard_colormap_mode
= RUseStdColormap
;
602 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
605 if (!scr
->rcontext
) {
606 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
612 formats
= RSupportedFileFormats();
614 for (i
= 0; formats
[i
] != NULL
; i
++) {
615 if (strcmp(formats
[i
], "TIFF") == 0) {
616 scr
->flags
.supports_tiff
= 1;
623 scr
->w_win
= scr
->rcontext
->drawable
;
624 scr
->w_visual
= scr
->rcontext
->visual
;
625 scr
->w_depth
= scr
->rcontext
->depth
;
626 scr
->w_colormap
= scr
->rcontext
->cmap
;
628 /* create screen descriptor for WINGs */
629 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
631 if (!scr
->wmscreen
) {
632 wfatal(_("could not initialize WINGs widget set"));
636 scr
->black
= WMBlackColor(scr
->wmscreen
);
637 scr
->white
= WMWhiteColor(scr
->wmscreen
);
638 scr
->gray
= WMGrayColor(scr
->wmscreen
);
639 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
641 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
642 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
643 scr
->light_pixel
= WMColorPixel(scr
->gray
);
644 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
646 /* create GCs with default values */
649 /* for our window manager info notice board. Need to
650 * create before reading the defaults, because it will be used there.
652 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
654 /* read defaults for this screen */
655 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
659 /* frame boder color */
660 wGetColor(scr
, WMGetColorRGBDescription(scr
->frame_border_color
), &xcol
);
661 scr
->frame_border_pixel
= xcol
.pixel
;
662 wGetColor(scr
, WMGetColorRGBDescription(scr
->frame_selected_border_color
), &xcol
);
663 scr
->frame_selected_border_pixel
= xcol
.pixel
;
666 createInternalWindows(scr
);
668 wNETWMInitStuff(scr
);
670 /* create initial workspace */
673 /* create shared pixmaps */
676 /* set icon sizes we can accept from clients */
677 icon_size
[0].min_width
= 8;
678 icon_size
[0].min_height
= 8;
679 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
680 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
681 icon_size
[0].width_inc
= 1;
682 icon_size
[0].height_inc
= 1;
683 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
685 /* setup WindowMaker protocols property in the root window */
686 PropSetWMakerProtocols(scr
->root_win
);
688 /* setup our noticeboard */
689 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
690 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
691 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
692 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
695 /* initialize balloon text stuff */
696 wBalloonInitialize(scr
);
699 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
701 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
702 if (!scr
->tech_draw_font
)
703 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
705 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
706 WMRealizeWidget(scr
->gview
);
708 wScreenUpdateUsableArea(scr
);
713 void wScreenUpdateUsableArea(WScreen
* scr
)
716 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
717 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
723 unsigned long best_area
, tmp_area
;
724 unsigned int size
, position
;
726 dock_head
= scr
->xine_info
.primary_head
;
728 size
= wPreferences
.workspace_border_size
;
729 position
= wPreferences
.workspace_border_position
;
733 rect
.pos
.x
= scr
->dock
->x_pos
;
734 rect
.pos
.y
= scr
->dock
->y_pos
;
735 rect
.size
.width
= wPreferences
.icon_size
;
736 rect
.size
.height
= wPreferences
.icon_size
;
737 dock_head
= wGetHeadForRect(scr
, rect
);
740 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
741 WMRect rect
= wGetRectForHead(scr
, i
);
742 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
743 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
744 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
745 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
747 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
748 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
750 if (scr
->dock
->on_right_side
) {
751 scr
->totalUsableArea
[i
].x2
-= offset
;
753 scr
->totalUsableArea
[i
].x1
+= offset
;
757 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
758 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
759 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
760 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
761 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
764 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
767 printf("usableArea[%d]: %d %d %d %d\n", i
,
768 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
770 if (wPreferences
.no_window_over_icons
) {
771 if (wPreferences
.icon_yard
& IY_VERT
) {
772 if (wPreferences
.icon_yard
& IY_RIGHT
) {
773 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
775 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
778 if (wPreferences
.icon_yard
& IY_TOP
) {
779 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
781 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
786 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
787 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
788 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
791 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
792 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
793 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
796 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
797 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
799 if (tmp_area
> best_area
) {
800 best_area
= tmp_area
;
801 area
= scr
->totalUsableArea
[i
];
804 if (size
> 0 && position
!= WB_NONE
) {
805 if (position
& WB_LEFTRIGHT
) {
806 scr
->totalUsableArea
[i
].x1
+= size
;
807 scr
->totalUsableArea
[i
].x2
-= size
;
809 if (position
& WB_TOPBOTTOM
) {
810 scr
->totalUsableArea
[i
].y1
+= size
;
811 scr
->totalUsableArea
[i
].y2
-= size
;
816 if (wPreferences
.auto_arrange_icons
)
817 wArrangeIcons(scr
, True
);
820 void wScreenRestoreState(WScreen
* scr
)
825 OpenRootMenu(scr
, -10000, -10000, False
);
826 wMenuUnmap(scr
->root_menu
);
830 if (wScreenCount
== 1) {
831 path
= wdefaultspathfordomain("WMState");
834 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
835 path
= wdefaultspathfordomain(buf
);
837 scr
->session_state
= WMReadPropListFromFile(path
);
839 if (!scr
->session_state
&& wScreenCount
> 1) {
840 path
= wdefaultspathfordomain("WMState");
841 scr
->session_state
= WMReadPropListFromFile(path
);
845 if (!scr
->session_state
) {
846 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
849 if (!wPreferences
.flags
.nodock
) {
850 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
851 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
852 /* If clip_merged_in_dock, setting scr->clip_icon is done by
853 * wDockRestoreState()->wDockCreate()->mainIconCreate() */
856 if (!wPreferences
.flags
.noclip
) {
857 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
858 scr
->clip_icon
= wClipRestoreState(scr
, state
);
861 if (!wPreferences
.flags
.nodrawer
) {
862 wDrawersRestoreState(scr
);
865 wWorkspaceRestoreState(scr
);
867 wScreenUpdateUsableArea(scr
);
870 void wScreenSaveState(WScreen
* scr
)
874 WMPropList
*old_state
, *foo
;
878 /* save state of windows */
879 wwin
= scr
->focused_window
;
881 wWindowSaveState(wwin
);
885 if (wPreferences
.flags
.noupdates
)
888 old_state
= scr
->session_state
;
889 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
891 WMPLSetCaseSensitive(True
);
893 /* save dock state to file */
894 if (!wPreferences
.flags
.nodock
) {
895 wDockSaveState(scr
, old_state
);
897 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
898 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
901 if (!wPreferences
.flags
.noclip
) {
904 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
905 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
909 wWorkspaceSaveState(scr
, old_state
);
911 if (!wPreferences
.flags
.nodrawer
) {
912 wDrawersSaveState(scr
);
914 if ((foo
= WMGetFromPLDictionary(old_state
, dDrawers
)) != NULL
) {
915 WMPutInPLDictionary(scr
->session_state
, dDrawers
, foo
);
920 if (wPreferences
.save_session_on_exit
) {
921 wSessionSaveState(scr
);
923 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
924 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
926 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
927 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
932 WMPLSetCaseSensitive(False
);
936 if (wScreenCount
== 1) {
937 str
= wdefaultspathfordomain("WMState");
940 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
941 str
= wdefaultspathfordomain(buf
);
943 if (!WMWritePropListToFile(scr
->session_state
, str
)) {
944 werror(_("could not save session state in %s"), str
);
947 WMReleasePropList(old_state
);
950 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
955 * With respect to the head that contains most of the window.
957 int sx1
, sy1
, sx2
, sy2
;
964 rect
.size
.width
= width
;
965 rect
.size
.height
= height
;
967 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
968 rect
= wGetRectForHead(scr
, head
);
972 sx2
= sx1
+ rect
.size
.width
;
973 sy2
= sy1
+ rect
.size
.height
;
975 #if 0 /* NOTE: gives funky group movement */
976 if (flags
& XFLAG_MULTIPLE
) {
978 * since we span multiple heads, pull window totaly inside
982 else if (*x
+ width
> sx2
)
983 *x
= sx2
- width
, moved
= 1;
987 else if (*y
+ height
> sy2
)
988 *y
= sy2
- height
, moved
= 1;
1004 if (*x
+ width
< sx1
+ 10)
1005 *x
= sx1
- tol_w
, moved
= 1;
1006 else if (*x
>= sx2
- 10)
1007 *x
= sx2
- tol_w
- 1, moved
= 1;
1009 if (*y
< sy1
- height
+ 10)
1010 *y
= sy1
- tol_h
, moved
= 1;
1011 else if (*y
>= sy2
- 10)
1012 *y
= sy2
- tol_h
- 1, moved
= 1;
1017 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1020 int sx1
, sy1
, sx2
, sy2
;
1026 rect
.size
.width
= width
;
1027 rect
.size
.height
= height
;
1029 head
= wGetHeadForRect(scr
, rect
);
1030 rect
= wGetRectForHead(scr
, head
);
1034 sx2
= sx1
+ rect
.size
.width
;
1035 sy2
= sy1
+ rect
.size
.height
;
1038 *x
= sx1
, moved
= 1;
1039 else if (*x
+ width
> sx2
)
1040 *x
= sx2
- width
, moved
= 1;
1043 *y
= sy1
, moved
= 1;
1044 else if (*y
+ height
> sy2
)
1045 *y
= sy2
- height
, moved
= 1;