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
= wDefaultGetImage(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 /* will only be accounted for in PseudoColor */
600 if (wPreferences
.flags
.create_stdcmap
) {
601 rattr
.standard_colormap_mode
= RCreateStdColormap
;
603 rattr
.standard_colormap_mode
= RUseStdColormap
;
606 if (getWVisualID(screen_number
) >= 0) {
607 rattr
.flags
|= RC_VisualID
;
608 rattr
.visualid
= getWVisualID(screen_number
);
611 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
613 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
614 wwarning("%s", RMessageForError(RErrorCode
));
616 rattr
.flags
&= ~RC_StandardColormap
;
617 rattr
.standard_colormap_mode
= RUseStdColormap
;
619 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
622 if (!scr
->rcontext
) {
623 wwarning(_("could not initialize graphics library context: %s"), RMessageForError(RErrorCode
));
629 formats
= RSupportedFileFormats();
631 for (i
= 0; formats
[i
] != NULL
; i
++) {
632 if (strcmp(formats
[i
], "TIFF") == 0) {
633 scr
->flags
.supports_tiff
= 1;
640 scr
->w_win
= scr
->rcontext
->drawable
;
641 scr
->w_visual
= scr
->rcontext
->visual
;
642 scr
->w_depth
= scr
->rcontext
->depth
;
643 scr
->w_colormap
= scr
->rcontext
->cmap
;
645 /* create screen descriptor for WINGs */
646 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
, scr
->rcontext
);
648 if (!scr
->wmscreen
) {
649 wfatal(_("could not initialize WINGs widget set"));
653 scr
->black
= WMBlackColor(scr
->wmscreen
);
654 scr
->white
= WMWhiteColor(scr
->wmscreen
);
655 scr
->gray
= WMGrayColor(scr
->wmscreen
);
656 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
658 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black; */
659 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white; */
660 scr
->light_pixel
= WMColorPixel(scr
->gray
);
661 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
665 /* frame boder color */
666 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
667 scr
->frame_border_pixel
= xcol
.pixel
;
670 /* create GCs with default values */
673 /* for our window manager info notice board. Need to
674 * create before reading the defaults, because it will be used there.
676 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, 0, 0);
678 /* read defaults for this screen */
679 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
681 createInternalWindows(scr
);
683 wNETWMInitStuff(scr
);
685 /* create initial workspace */
688 /* create shared pixmaps */
691 /* set icon sizes we can accept from clients */
692 icon_size
[0].min_width
= 8;
693 icon_size
[0].min_height
= 8;
694 icon_size
[0].max_width
= wPreferences
.icon_size
- 4;
695 icon_size
[0].max_height
= wPreferences
.icon_size
- 4;
696 icon_size
[0].width_inc
= 1;
697 icon_size
[0].height_inc
= 1;
698 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
700 /* setup WindowMaker protocols property in the root window */
701 PropSetWMakerProtocols(scr
->root_win
);
703 /* setup our noticeboard */
704 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
705 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
706 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
707 XA_WINDOW
, 32, PropModeReplace
, (unsigned char *)&scr
->info_window
, 1);
710 /* initialize balloon text stuff */
711 wBalloonInitialize(scr
);
714 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
716 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
717 if (!scr
->tech_draw_font
)
718 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
720 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
721 WMRealizeWidget(scr
->gview
);
723 wScreenUpdateUsableArea(scr
);
728 void wScreenUpdateUsableArea(WScreen
* scr
)
731 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
732 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
738 unsigned long best_area
, tmp_area
;
739 unsigned int size
, position
;
741 dock_head
= scr
->xine_info
.primary_head
;
743 size
= wPreferences
.workspace_border_size
;
744 position
= wPreferences
.workspace_border_position
;
748 rect
.pos
.x
= scr
->dock
->x_pos
;
749 rect
.pos
.y
= scr
->dock
->y_pos
;
750 rect
.size
.width
= wPreferences
.icon_size
;
751 rect
.size
.height
= wPreferences
.icon_size
;
752 dock_head
= wGetHeadForRect(scr
, rect
);
755 for (i
= 0; i
< wXineramaHeads(scr
); ++i
) {
756 WMRect rect
= wGetRectForHead(scr
, i
);
757 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
758 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
759 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
760 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
762 if (scr
->dock
&& dock_head
== i
&& (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
763 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
765 if (scr
->dock
->on_right_side
) {
766 scr
->totalUsableArea
[i
].x2
-= offset
;
768 scr
->totalUsableArea
[i
].x1
+= offset
;
772 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
773 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
774 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
775 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
776 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
779 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
782 printf("usableArea[%d]: %d %d %d %d\n", i
,
783 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
, scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
785 if (wPreferences
.no_window_over_icons
) {
786 if (wPreferences
.icon_yard
& IY_VERT
) {
787 if (wPreferences
.icon_yard
& IY_RIGHT
) {
788 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
790 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
793 if (wPreferences
.icon_yard
& IY_TOP
) {
794 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
796 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
801 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/ 2) {
802 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
803 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
806 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/ 2) {
807 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
808 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
811 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
812 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
814 if (tmp_area
> best_area
) {
815 best_area
= tmp_area
;
816 area
= scr
->totalUsableArea
[i
];
819 if (size
> 0 && position
!= WB_NONE
) {
820 if (position
& WB_LEFTRIGHT
) {
821 scr
->totalUsableArea
[i
].x1
+= size
;
822 scr
->totalUsableArea
[i
].x2
-= size
;
824 if (position
& WB_TOPBOTTOM
) {
825 scr
->totalUsableArea
[i
].y1
+= size
;
826 scr
->totalUsableArea
[i
].y2
-= size
;
831 if (wPreferences
.auto_arrange_icons
)
832 wArrangeIcons(scr
, True
);
835 void wScreenRestoreState(WScreen
* scr
)
840 OpenRootMenu(scr
, -10000, -10000, False
);
841 wMenuUnmap(scr
->root_menu
);
845 if (wScreenCount
== 1) {
846 path
= wdefaultspathfordomain("WMState");
849 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
850 path
= wdefaultspathfordomain(buf
);
852 scr
->session_state
= WMReadPropListFromFile(path
);
854 if (!scr
->session_state
&& wScreenCount
> 1) {
855 path
= wdefaultspathfordomain("WMState");
856 scr
->session_state
= WMReadPropListFromFile(path
);
860 if (!scr
->session_state
) {
861 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
864 if (!wPreferences
.flags
.nodock
) {
865 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
866 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
869 if (!wPreferences
.flags
.noclip
) {
870 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
871 scr
->clip_icon
= wClipRestoreState(scr
, state
);
874 wWorkspaceRestoreState(scr
);
876 wScreenUpdateUsableArea(scr
);
879 void wScreenSaveState(WScreen
* scr
)
883 WMPropList
*old_state
, *foo
;
887 /* save state of windows */
888 wwin
= scr
->focused_window
;
890 wWindowSaveState(wwin
);
894 if (wPreferences
.flags
.noupdates
)
897 old_state
= scr
->session_state
;
898 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
900 WMPLSetCaseSensitive(True
);
902 /* save dock state to file */
903 if (!wPreferences
.flags
.nodock
) {
904 wDockSaveState(scr
, old_state
);
906 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
)) != NULL
) {
907 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
910 if (!wPreferences
.flags
.noclip
) {
913 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
)) != NULL
) {
914 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
918 wWorkspaceSaveState(scr
, old_state
);
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;