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
;
87 extern WDDomain
*WDWindowMaker
;
90 #define STIPPLE_WIDTH 2
91 #define STIPPLE_HEIGHT 2
92 static char STIPPLE_DATA
[] = { 0x02, 0x01 };
94 static int CantManageScreen
= 0;
96 static WMPropList
*dApplications
= NULL
;
97 static WMPropList
*dWorkspace
;
98 static WMPropList
*dDock
;
99 static WMPropList
*dClip
;
101 static void make_keys(void)
103 if (dApplications
!= NULL
)
106 dApplications
= WMCreatePLString("Applications");
107 dWorkspace
= WMCreatePLString("Workspace");
108 dDock
= WMCreatePLString("Dock");
109 dClip
= WMCreatePLString("Clip");
113 *----------------------------------------------------------------------
114 * alreadyRunningError--
115 * X error handler used to catch errors when trying to do
116 * XSelectInput() on the root window. These errors probably mean that
117 * there already is some other window manager running.
120 * Nothing, unless something really evil happens...
123 * CantManageScreen is set to 1;
124 *----------------------------------------------------------------------
126 static int alreadyRunningError(Display
* dpy
, XErrorEvent
* error
)
128 CantManageScreen
= 1;
133 *----------------------------------------------------------------------
134 * allocButtonPixmaps--
135 * Allocate pixmaps used on window operation buttons (those in the
136 * titlebar). The pixmaps are linked to the program. If XPM is supported
137 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
143 * Allocates shared pixmaps for the screen. These pixmaps should
144 * not be freed by anybody.
145 *----------------------------------------------------------------------
147 static void allocButtonPixmaps(WScreen
* scr
)
151 /* create predefined pixmaps */
152 if (wPreferences
.new_style
== TS_NEXT
) {
153 pix
= wPixmapCreateFromXPMData(scr
, NEXT_CLOSE_XPM
);
155 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
159 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
161 if (wPreferences
.new_style
== TS_NEXT
) {
162 pix
= wPixmapCreateFromXPMData(scr
, NEXT_BROKEN_CLOSE_XPM
);
164 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
168 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
170 if (wPreferences
.new_style
== TS_NEXT
) {
171 pix
= wPixmapCreateFromXPMData(scr
, NEXT_ICONIFY_XPM
);
173 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
177 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
178 #ifdef XKB_BUTTON_HINT
179 if (wPreferences
.new_style
== TS_NEXT
) {
180 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP1_XPM
);
182 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
186 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
187 if (wPreferences
.new_style
== TS_NEXT
) {
188 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP2_XPM
);
190 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
194 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
195 if (wPreferences
.new_style
== TS_NEXT
) {
196 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP3_XPM
);
198 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
202 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
203 if (wPreferences
.new_style
== TS_NEXT
) {
204 pix
= wPixmapCreateFromXPMData(scr
, NEXT_XKBGROUP4_XPM
);
206 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
210 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
213 if (wPreferences
.new_style
== TS_NEXT
) {
214 pix
= wPixmapCreateFromXPMData(scr
, NEXT_KILL_XPM
);
216 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
220 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
223 static void draw_dot(WScreen
* scr
, Drawable d
, int x
, int y
, GC gc
)
225 XSetForeground(dpy
, gc
, scr
->black_pixel
);
226 XDrawLine(dpy
, d
, gc
, x
, y
, x
+ 1, y
);
227 XDrawPoint(dpy
, d
, gc
, x
, y
+ 1);
228 XSetForeground(dpy
, gc
, scr
->white_pixel
);
229 XDrawLine(dpy
, d
, gc
, x
+ 2, y
, x
+ 2, y
+ 1);
230 XDrawPoint(dpy
, d
, gc
, x
+ 1, y
+ 1);
233 static WPixmap
*make3Dots(WScreen
* scr
)
241 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, scr
->w_depth
);
242 XSetForeground(dpy
, gc
, scr
->black_pixel
);
243 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
244 XSetForeground(dpy
, gc
, scr
->white_pixel
);
245 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
- 6, gc
);
246 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
- 6, gc
);
247 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
- 6, gc
);
249 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
, wPreferences
.icon_size
, 1);
251 gcv
.graphics_exposures
= False
;
252 gc2
= XCreateGC(dpy
, mask
, GCForeground
| GCGraphicsExposures
, &gcv
);
253 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
, wPreferences
.icon_size
);
254 XSetForeground(dpy
, gc2
, 1);
255 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
- 6, 3, 2);
256 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
- 6, 3, 2);
257 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
- 6, 3, 2);
261 wpix
= wPixmapCreate(scr
, pix
, mask
);
267 static void allocGCs(WScreen
* scr
)
273 scr
->stipple_bitmap
= XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
, STIPPLE_HEIGHT
);
275 gcv
.stipple
= scr
->stipple_bitmap
;
276 gcv
.foreground
= scr
->white_pixel
;
277 gcv
.fill_style
= FillStippled
;
278 gcv
.graphics_exposures
= False
;
279 gcm
= GCForeground
| GCStipple
| GCFillStyle
| GCGraphicsExposures
;
280 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
282 /* selected icon border GCs */
283 gcv
.function
= GXcopy
;
284 gcv
.foreground
= scr
->white_pixel
;
285 gcv
.background
= scr
->black_pixel
;
287 gcv
.line_style
= LineDoubleDash
;
288 gcv
.fill_style
= FillSolid
;
291 gcv
.graphics_exposures
= False
;
293 gcm
= GCFunction
| GCGraphicsExposures
;
294 gcm
|= GCForeground
| GCBackground
;
295 gcm
|= GCLineWidth
| GCLineStyle
;
297 gcm
|= GCDashOffset
| GCDashList
;
299 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
301 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
303 /* don't retain scr->black here because we may alter its alpha */
304 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
305 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
308 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
309 gcv
.function
= GXxor
;
310 /* this will raise the probability of the XORed color being different
311 * of the original color in PseudoColor when not all color cells are
313 if (DefaultVisual(dpy
, scr
->screen
)->class == PseudoColor
)
314 gcv
.plane_mask
= (1 << (scr
->depth
- 1)) | 1;
316 gcv
.plane_mask
= AllPlanes
;
317 gcv
.foreground
= color
.pixel
;
318 if (gcv
.foreground
== 0)
320 gcv
.line_width
= DEF_FRAME_THICKNESS
;
321 gcv
.subwindow_mode
= IncludeInferiors
;
322 gcv
.graphics_exposures
= False
;
323 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
| GCGraphicsExposures
324 | GCFunction
| GCSubwindowMode
| GCLineWidth
| GCPlaneMask
, &gcv
);
327 gcv
.foreground
= color
.pixel
;
329 if (gcv
.foreground
== 0)
330 /* XOR:ing with a zero is not going to be of much use, so
331 in that case, we somewhat arbitrarily xor with 17 instead. */
334 gcv
.function
= GXxor
;
335 gcv
.subwindow_mode
= IncludeInferiors
;
337 gcv
.cap_style
= CapRound
;
338 gcv
.graphics_exposures
= False
;
339 gcm
= GCForeground
| GCFunction
| GCSubwindowMode
| GCLineWidth
| GCCapStyle
| GCGraphicsExposures
;
340 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
342 scr
->line_pixel
= gcv
.foreground
;
345 gcv
.foreground
= scr
->white_pixel
;
346 gcv
.background
= scr
->black_pixel
;
347 gcv
.graphics_exposures
= False
;
348 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
| GCBackground
| GCGraphicsExposures
, &gcv
);
350 /* misc drawing GC */
351 gcv
.graphics_exposures
= False
;
352 gcm
= GCGraphicsExposures
;
353 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
355 assert(scr
->stipple_bitmap
!= None
);
358 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
361 static void createPixmaps(WScreen
* scr
)
366 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
367 (char *)MENU_RADIO_INDICATOR_XBM_DATA
,
368 MENU_RADIO_INDICATOR_XBM_SIZE
,
369 MENU_RADIO_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
372 scr
->menu_radio_indicator
= pix
;
374 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
375 (char *)MENU_CHECK_INDICATOR_XBM_DATA
,
376 MENU_CHECK_INDICATOR_XBM_SIZE
,
377 MENU_CHECK_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
380 scr
->menu_check_indicator
= pix
;
382 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_MINI_INDICATOR_XBM_DATA
,
383 (char *)MENU_MINI_INDICATOR_XBM_DATA
,
384 MENU_MINI_INDICATOR_XBM_SIZE
,
385 MENU_MINI_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
388 scr
->menu_mini_indicator
= pix
;
390 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
391 (char *)MENU_HIDE_INDICATOR_XBM_DATA
,
392 MENU_HIDE_INDICATOR_XBM_SIZE
,
393 MENU_HIDE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
396 scr
->menu_hide_indicator
= pix
;
398 pix
= wPixmapCreateFromXBMData(scr
, (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
399 (char *)MENU_SHADE_INDICATOR_XBM_DATA
,
400 MENU_SHADE_INDICATOR_XBM_SIZE
,
401 MENU_SHADE_INDICATOR_XBM_SIZE
, scr
->black_pixel
, scr
->white_pixel
);
404 scr
->menu_shade_indicator
= pix
;
406 create_logo_image(scr
);
408 scr
->dock_dots
= make3Dots(scr
);
410 /* titlebar button pixmaps */
411 allocButtonPixmaps(scr
);
414 void create_logo_image(WScreen
*scr
)
416 RImage
*image
= get_icon_image(scr
, "Logo", "WMPanel", wPreferences
.icon_size
);
419 wwarning(_("could not load logo image for panels: %s"), RMessageForError(RErrorCode
));
421 WMSetApplicationIconImage(scr
->wmscreen
, image
);
422 RReleaseImage(image
);
427 *----------------------------------------------------------------------
428 * createInternalWindows--
429 * Creates some windows used internally by the program. One to
430 * receive input focus when no other window can get it and another
431 * to display window geometry information during window resize/move.
437 * Windows are created and some colors are allocated for the
439 *----------------------------------------------------------------------
441 static void createInternalWindows(WScreen
* scr
)
444 XSetWindowAttributes attribs
;
446 /* InputOnly window to get the focus when no other window can get it */
447 vmask
= CWEventMask
| CWOverrideRedirect
;
448 attribs
.event_mask
= KeyPressMask
| FocusChangeMask
;
449 attribs
.override_redirect
= True
;
450 scr
->no_focus_win
= XCreateWindow(dpy
, scr
->root_win
, -10, -10, 4, 4, 0, 0,
451 InputOnly
, CopyFromParent
, vmask
, &attribs
);
452 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
| KeyReleaseMask
);
453 XMapWindow(dpy
, scr
->no_focus_win
);
455 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
457 /* shadow window for dock buttons */
458 vmask
= CWBorderPixel
| CWBackPixmap
| CWBackPixel
| CWCursor
| CWSaveUnder
| CWOverrideRedirect
;
459 attribs
.border_pixel
= scr
->black_pixel
;
460 attribs
.save_under
= True
;
461 attribs
.override_redirect
= True
;
462 attribs
.background_pixmap
= None
;
463 attribs
.background_pixel
= scr
->white_pixel
;
464 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
466 attribs
.colormap
= scr
->w_colormap
;
468 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
469 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
471 /* workspace name balloon for clip */
472 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
473 attribs
.save_under
= True
;
474 attribs
.override_redirect
= True
;
475 attribs
.colormap
= scr
->w_colormap
;
476 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
477 attribs
.border_pixel
= 0; /* do not care */
479 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
480 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
483 vmask
= CWBackPixel
| CWSaveUnder
| CWOverrideRedirect
| CWColormap
| CWBorderPixel
;
484 attribs
.save_under
= True
;
485 attribs
.override_redirect
= True
;
486 attribs
.colormap
= scr
->w_colormap
;
487 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
488 attribs
.border_pixel
= 0; /* do not care */
489 scr
->workspace_name
=
490 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
491 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
494 * If the window is clicked without having ButtonPress selected, the
495 * resulting event will have event.xbutton.window == root.
497 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
501 *----------------------------------------------------------------------
503 * Initializes the window manager for the given screen and
504 * allocates a WScreen descriptor for it. Many resources are allocated
505 * for the screen and the root window is setup appropriately.
508 * The WScreen descriptor for the screen.
511 * Many resources are allocated and the IconSize property is
512 * set on the root window.
513 * The program can be aborted if some fatal error occurs.
515 * TODO: User specifiable visual.
516 *----------------------------------------------------------------------
518 WScreen
*wScreenInit(int screen_number
)
521 XIconSize icon_size
[1];
522 RContextAttributes rattr
;
524 XErrorHandler oldHandler
;
527 scr
= wmalloc(sizeof(WScreen
));
529 scr
->stacking_list
= WMCreateTreeBag();
531 /* initialize globals */
532 scr
->screen
= screen_number
;
533 scr
->root_win
= RootWindow(dpy
, screen_number
);
534 scr
->depth
= DefaultDepth(dpy
, screen_number
);
535 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
537 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
538 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
542 scr
->usableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
543 scr
->totalUsableArea
= (WArea
*) wmalloc(sizeof(WArea
) * wXineramaHeads(scr
));
545 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
546 WMRect rect
= wGetRectForHead(scr
, i
);
547 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
548 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
549 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
550 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
553 scr
->fakeGroupLeaders
= WMCreateArray(16);
555 CantManageScreen
= 0;
556 oldHandler
= XSetErrorHandler((XErrorHandler
) alreadyRunningError
);
558 event_mask
= EVENT_MASK
;
560 if (wPreferences
.disable_root_mouse
) {
561 event_mask
&= ~(ButtonPressMask
| ButtonReleaseMask
);
564 XSelectInput(dpy
, scr
->root_win
, event_mask
);
566 #ifdef KEEP_XKB_LOCK_STATUS
567 /* Only GroupLock doesn't work correctly in my system since right-alt
568 * can change mode while holding it too - ]d
571 XkbSelectEvents(dpy
, XkbUseCoreKbd
, XkbStateNotifyMask
, XkbStateNotifyMask
);
573 #endif /* KEEP_XKB_LOCK_STATUS */
577 XRRSelectInput(dpy
, scr
->root_win
, RRScreenChangeNotifyMask
);
581 XSetErrorHandler(oldHandler
);
583 if (CantManageScreen
) {
588 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
590 /* screen descriptor for raster graphic library */
591 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
592 rattr
.render_mode
= wPreferences
.no_dithering
? RBestMatchRendering
: RDitheredRendering
;
594 /* if the std colormap stuff works ok, this will be ignored */
595 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
596 if (rattr
.colors_per_channel
< 2)
597 rattr
.colors_per_channel
= 2;
599 /* Use standard colormap */
600 rattr
.standard_colormap_mode
= RUseStdColormap
;
602 if (getWVisualID(screen_number
) >= 0) {
603 rattr
.flags
|= RC_VisualID
;
604 rattr
.visualid
= getWVisualID(screen_number
);
607 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
609 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
610 wwarning("%s", RMessageForError(RErrorCode
));
612 rattr
.flags
&= ~RC_StandardColormap
;
613 rattr
.standard_colormap_mode
= RUseStdColormap
;
615 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
618 if (!scr
->rcontext
) {
619 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
625 formats
= RSupportedFileFormats();
627 for (i
= 0; formats
[i
] != NULL
; i
++) {
628 if (strcmp(formats
[i
], "TIFF") == 0) {
629 scr
->flags
.supports_tiff
= 1;
636 scr
->w_win
= scr
->rcontext
->drawable
;
637 scr
->w_visual
= scr
->rcontext
->visual
;
638 scr
->w_depth
= scr
->rcontext
->depth
;
639 scr
->w_colormap
= scr
->rcontext
->cmap
;
641 /* create screen descriptor for WINGs */
642 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
644 if (!scr
->wmscreen
) {
645 wfatal(_("could not initialize WINGs widget set"));
649 scr
->black
= WMBlackColor(scr
->wmscreen
);
650 scr
->white
= WMWhiteColor(scr
->wmscreen
);
651 scr
->gray
= WMGrayColor(scr
->wmscreen
);
652 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
654 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
655 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
656 scr
->light_pixel
= WMColorPixel(scr
->gray
);
657 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
661 /* frame boder color */
662 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
663 scr
->frame_border_pixel
= xcol
.pixel
;
666 /* create GCs with default values */
669 /* for our window manager info notice board. Need to
670 * create before reading the defaults, because it will be used there.
672 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
674 /* read defaults for this screen */
675 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
677 createInternalWindows(scr
);
679 wNETWMInitStuff(scr
);
681 /* create initial workspace */
684 /* create shared pixmaps */
687 /* set icon sizes we can accept from clients */
688 icon_size
[0].min_width
= 8;
689 icon_size
[0].min_height
= 8;
690 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
691 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
692 icon_size
[0].width_inc
= 1;
693 icon_size
[0].height_inc
= 1;
694 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
696 /* setup WindowMaker protocols property in the root window */
697 PropSetWMakerProtocols(scr
->root_win
);
699 /* setup our noticeboard */
700 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
701 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
702 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
703 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
706 /* initialize balloon text stuff */
707 wBalloonInitialize(scr
);
710 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
712 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
713 if (!scr
->tech_draw_font
)
714 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
716 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
717 WMRealizeWidget(scr
->gview
);
719 wScreenUpdateUsableArea(scr
);
724 void wScreenUpdateUsableArea(WScreen
* scr
)
727 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
728 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
734 unsigned long best_area
, tmp_area
;
735 unsigned int size
, position
;
737 dock_head
= scr
->xine_info
.primary_head
;
739 size
= wPreferences
.workspace_border_size
;
740 position
= wPreferences
.workspace_border_position
;
744 rect
.pos
.x
= scr
->dock
->x_pos
;
745 rect
.pos
.y
= scr
->dock
->y_pos
;
746 rect
.size
.width
= wPreferences
.icon_size
;
747 rect
.size
.height
= wPreferences
.icon_size
;
748 dock_head
= wGetHeadForRect(scr
, rect
);
751 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
752 WMRect rect
= wGetRectForHead(scr
, i
);
753 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
754 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
755 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
756 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
758 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
759 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
761 if (scr
->dock
->on_right_side
) {
762 scr
->totalUsableArea
[i
].x2
-= offset
;
764 scr
->totalUsableArea
[i
].x1
+= offset
;
768 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
769 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
770 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
771 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
772 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
775 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
778 printf("usableArea[%d]: %d %d %d %d\n", i
,
779 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
781 if (wPreferences
.no_window_over_icons
) {
782 if (wPreferences
.icon_yard
& IY_VERT
) {
783 if (wPreferences
.icon_yard
& IY_RIGHT
) {
784 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
786 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
789 if (wPreferences
.icon_yard
& IY_TOP
) {
790 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
792 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
797 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
798 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
799 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
802 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
803 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
804 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
807 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
808 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
810 if (tmp_area
> best_area
) {
811 best_area
= tmp_area
;
812 area
= scr
->totalUsableArea
[i
];
815 if (size
> 0 && position
!= WB_NONE
) {
816 if (position
& WB_LEFTRIGHT
) {
817 scr
->totalUsableArea
[i
].x1
+= size
;
818 scr
->totalUsableArea
[i
].x2
-= size
;
820 if (position
& WB_TOPBOTTOM
) {
821 scr
->totalUsableArea
[i
].y1
+= size
;
822 scr
->totalUsableArea
[i
].y2
-= size
;
827 if (wPreferences
.auto_arrange_icons
)
828 wArrangeIcons(scr
, True
);
831 void wScreenRestoreState(WScreen
* scr
)
836 OpenRootMenu(scr
, -10000, -10000, False
);
837 wMenuUnmap(scr
->root_menu
);
841 if (wScreenCount
== 1) {
842 path
= wdefaultspathfordomain("WMState");
845 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
846 path
= wdefaultspathfordomain(buf
);
848 scr
->session_state
= WMReadPropListFromFile(path
);
850 if (!scr
->session_state
&& wScreenCount
> 1) {
851 path
= wdefaultspathfordomain("WMState");
852 scr
->session_state
= WMReadPropListFromFile(path
);
856 if (!scr
->session_state
) {
857 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
860 if (!wPreferences
.flags
.nodock
) {
861 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
862 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
865 if (!wPreferences
.flags
.noclip
) {
866 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
867 scr
->clip_icon
= wClipRestoreState(scr
, state
);
870 wWorkspaceRestoreState(scr
);
872 wScreenUpdateUsableArea(scr
);
875 void wScreenSaveState(WScreen
* scr
)
879 WMPropList
*old_state
, *foo
;
883 /* save state of windows */
884 wwin
= scr
->focused_window
;
886 wWindowSaveState(wwin
);
890 if (wPreferences
.flags
.noupdates
)
893 old_state
= scr
->session_state
;
894 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
896 WMPLSetCaseSensitive(True
);
898 /* save dock state to file */
899 if (!wPreferences
.flags
.nodock
) {
900 wDockSaveState(scr
, old_state
);
902 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
903 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
906 if (!wPreferences
.flags
.noclip
) {
909 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
910 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
914 wWorkspaceSaveState(scr
, old_state
);
916 if (wPreferences
.save_session_on_exit
) {
917 wSessionSaveState(scr
);
919 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
)) != NULL
) {
920 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
922 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
)) != NULL
) {
923 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
928 WMPLSetCaseSensitive(False
);
932 if (wScreenCount
== 1) {
933 str
= wdefaultspathfordomain("WMState");
936 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
937 str
= wdefaultspathfordomain(buf
);
939 if (!WMWritePropListToFile(scr
->session_state
, str
)) {
940 werror(_("could not save session state in %s"), str
);
943 WMReleasePropList(old_state
);
946 int wScreenBringInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
951 * With respect to the head that contains most of the window.
953 int sx1
, sy1
, sx2
, sy2
;
960 rect
.size
.width
= width
;
961 rect
.size
.height
= height
;
963 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
964 rect
= wGetRectForHead(scr
, head
);
968 sx2
= sx1
+ rect
.size
.width
;
969 sy2
= sy1
+ rect
.size
.height
;
971 #if 0 /* NOTE: gives funky group movement */
972 if (flags
& XFLAG_MULTIPLE
) {
974 * since we span multiple heads, pull window totaly inside
978 else if (*x
+ width
> sx2
)
979 *x
= sx2
- width
, moved
= 1;
983 else if (*y
+ height
> sy2
)
984 *y
= sy2
- height
, moved
= 1;
1000 if (*x
+ width
< sx1
+ 10)
1001 *x
= sx1
- tol_w
, moved
= 1;
1002 else if (*x
>= sx2
- 10)
1003 *x
= sx2
- tol_w
- 1, moved
= 1;
1005 if (*y
< sy1
- height
+ 10)
1006 *y
= sy1
- tol_h
, moved
= 1;
1007 else if (*y
>= sy2
- 10)
1008 *y
= sy2
- tol_h
- 1, moved
= 1;
1013 int wScreenKeepInside(WScreen
* scr
, int *x
, int *y
, int width
, int height
)
1016 int sx1
, sy1
, sx2
, sy2
;
1022 rect
.size
.width
= width
;
1023 rect
.size
.height
= height
;
1025 head
= wGetHeadForRect(scr
, rect
);
1026 rect
= wGetRectForHead(scr
, head
);
1030 sx2
= sx1
+ rect
.size
.width
;
1031 sy2
= sy1
+ rect
.size
.height
;
1034 *x
= sx1
, moved
= 1;
1035 else if (*x
+ width
> sx2
)
1036 *x
= sx2
- width
, moved
= 1;
1039 *y
= sy1
, moved
= 1;
1040 else if (*y
+ height
> sy2
)
1041 *y
= sy2
- height
, moved
= 1;