1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
33 #include <X11/extensions/shape.h>
35 #ifdef KEEP_XKB_LOCK_STATUS
36 #include <X11/XKBlib.h>
37 #endif /* KEEP_XKB_LOCK_STATUS */
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
49 #include "properties.h"
51 #include "resources.h"
52 #include "workspace.h"
62 #include <WINGs/WUtil.h>
68 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
69 |SubstructureNotifyMask|PointerMotionMask \
70 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
72 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
73 |SubstructureNotifyMask|PointerMotionMask \
74 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
75 |KeyPressMask|KeyReleaseMask)
78 /**** Global variables ****/
80 extern Cursor wCursor
[WCUR_LAST
];
81 extern WPreferences wPreferences
;
82 extern Atom _XA_WINDOWMAKER_STATE
;
83 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
86 extern int wScreenCount
;
88 #ifdef KEEP_XKB_LOCK_STATUS
89 extern int wXkbSupported
;
92 extern WDDomain
*WDWindowMaker
;
97 #define STIPPLE_WIDTH 2
98 #define STIPPLE_HEIGHT 2
99 static char STIPPLE_DATA
[] = {0x02, 0x01};
101 static int CantManageScreen
= 0;
103 static WMPropList
*dApplications
= NULL
;
104 static WMPropList
*dWorkspace
;
105 static WMPropList
*dDock
;
106 static WMPropList
*dClip
;
112 if (dApplications
!=NULL
)
115 dApplications
= WMCreatePLString("Applications");
116 dWorkspace
= WMCreatePLString("Workspace");
117 dDock
= WMCreatePLString("Dock");
118 dClip
= WMCreatePLString("Clip");
123 *----------------------------------------------------------------------
124 * alreadyRunningError--
125 * X error handler used to catch errors when trying to do
126 * XSelectInput() on the root window. These errors probably mean that
127 * there already is some other window manager running.
130 * Nothing, unless something really evil happens...
133 * CantManageScreen is set to 1;
134 *----------------------------------------------------------------------
137 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
139 CantManageScreen
= 1;
145 *----------------------------------------------------------------------
146 * allocButtonPixmaps--
147 * Allocate pixmaps used on window operation buttons (those in the
148 * titlebar). The pixmaps are linked to the program. If XPM is supported
149 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
155 * Allocates shared pixmaps for the screen. These pixmaps should
156 * not be freed by anybody.
157 *----------------------------------------------------------------------
160 allocButtonPixmaps(WScreen
*scr
)
164 /* create predefined pixmaps */
165 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
168 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
170 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
173 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
175 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
178 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
179 #ifdef XKB_BUTTON_HINT
180 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
183 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
184 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
187 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
188 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
191 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
192 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
195 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
199 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
202 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
207 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
209 XSetForeground(dpy
, gc
, scr
->black_pixel
);
210 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
211 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
212 XSetForeground(dpy
, gc
, scr
->white_pixel
);
213 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
214 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
219 make3Dots(WScreen
*scr
)
227 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
228 wPreferences
.icon_size
, scr
->w_depth
);
229 XSetForeground(dpy
, gc
, scr
->black_pixel
);
230 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
231 wPreferences
.icon_size
);
232 XSetForeground(dpy
, gc
, scr
->white_pixel
);
233 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
234 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
235 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
237 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
238 wPreferences
.icon_size
, 1);
240 gcv
.graphics_exposures
= False
;
241 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
242 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
243 wPreferences
.icon_size
);
244 XSetForeground(dpy
, gc2
, 1);
245 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
246 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
247 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
251 wpix
= wPixmapCreate(scr
, pix
, mask
);
259 allocGCs(WScreen
*scr
)
265 scr
->stipple_bitmap
=
266 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
269 gcv
.stipple
= scr
->stipple_bitmap
;
270 gcv
.foreground
= scr
->white_pixel
;
271 gcv
.fill_style
= FillStippled
;
272 gcv
.graphics_exposures
= False
;
273 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
274 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
277 /* selected icon border GCs */
278 gcv
.function
= GXcopy
;
279 gcv
.foreground
= scr
->white_pixel
;
280 gcv
.background
= scr
->black_pixel
;
282 gcv
.line_style
= LineDoubleDash
;
283 gcv
.fill_style
= FillSolid
;
286 gcv
.graphics_exposures
= False
;
288 gcm
= GCFunction
| GCGraphicsExposures
;
289 gcm
|= GCForeground
| GCBackground
;
290 gcm
|= GCLineWidth
| GCLineStyle
;
292 gcm
|= GCDashOffset
| GCDashList
;
294 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
296 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
298 /* don't retain scr->black here because we may alter its alpha */
299 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
300 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
303 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
304 gcv
.function
= GXxor
;
305 /* this will raise the probability of the XORed color being different
306 * of the original color in PseudoColor when not all color cells are
308 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
309 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
311 gcv
.plane_mask
= AllPlanes
;
312 gcv
.foreground
= color
.pixel
;
313 if (gcv
.foreground
== 0)
315 gcv
.line_width
= DEF_FRAME_THICKNESS
;
316 gcv
.subwindow_mode
= IncludeInferiors
;
317 gcv
.graphics_exposures
= False
;
318 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
319 |GCFunction
|GCSubwindowMode
|GCLineWidth
323 gcv
.foreground
= color
.pixel
;
325 if (gcv
.foreground
== 0)
326 /* XOR:ing with a zero is not going to be of much use, so
327 in that case, we somewhat arbitrarily xor with 17 instead. */
330 gcv
.function
= GXxor
;
331 gcv
.subwindow_mode
= IncludeInferiors
;
333 gcv
.cap_style
= CapRound
;
334 gcv
.graphics_exposures
= False
;
335 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
336 |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
346 |GCGraphicsExposures
, &gcv
);
348 /* misc drawing GC */
349 gcv
.graphics_exposures
= False
;
350 gcm
= GCGraphicsExposures
;
351 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
353 assert (scr
->stipple_bitmap
!=None
);
357 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
363 createPixmaps(WScreen
*scr
)
369 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
370 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
371 MENU_RADIO_INDICATOR_XBM_SIZE
,
372 MENU_RADIO_INDICATOR_XBM_SIZE
,
373 scr
->black_pixel
, scr
->white_pixel
);
376 scr
->menu_radio_indicator
= pix
;
379 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
380 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
381 MENU_CHECK_INDICATOR_XBM_SIZE
,
382 MENU_CHECK_INDICATOR_XBM_SIZE
,
383 scr
->black_pixel
, scr
->white_pixel
);
386 scr
->menu_check_indicator
= pix
;
388 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
389 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
390 MENU_MINI_INDICATOR_XBM_SIZE
,
391 MENU_MINI_INDICATOR_XBM_SIZE
,
392 scr
->black_pixel
, scr
->white_pixel
);
395 scr
->menu_mini_indicator
= pix
;
397 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
398 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
399 MENU_HIDE_INDICATOR_XBM_SIZE
,
400 MENU_HIDE_INDICATOR_XBM_SIZE
,
401 scr
->black_pixel
, scr
->white_pixel
);
404 scr
->menu_hide_indicator
= pix
;
406 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
407 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
408 MENU_SHADE_INDICATOR_XBM_SIZE
,
409 MENU_SHADE_INDICATOR_XBM_SIZE
,
410 scr
->black_pixel
, scr
->white_pixel
);
413 scr
->menu_shade_indicator
= pix
;
416 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
419 wwarning(_("could not load logo image for panels: %s"),
420 RMessageForError(RErrorCode
));
422 WMSetApplicationIconImage(scr
->wmscreen
, image
);
423 RReleaseImage(image
);
426 scr
->dock_dots
= make3Dots(scr
);
428 /* titlebar button pixmaps */
429 allocButtonPixmaps(scr
);
434 *----------------------------------------------------------------------
435 * createInternalWindows--
436 * Creates some windows used internally by the program. One to
437 * receive input focus when no other window can get it and another
438 * to display window geometry information during window resize/move.
444 * Windows are created and some colors are allocated for the
446 *----------------------------------------------------------------------
449 createInternalWindows(WScreen
*scr
)
452 XSetWindowAttributes attribs
;
454 /* InputOnly window to get the focus when no other window can get it */
455 vmask
= CWEventMask
|CWOverrideRedirect
;
456 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
457 attribs
.override_redirect
= True
;
458 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
459 InputOnly
,CopyFromParent
, vmask
, &attribs
);
460 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
461 XMapWindow(dpy
, scr
->no_focus_win
);
463 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
465 /* shadow window for dock buttons */
466 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
467 attribs
.border_pixel
= scr
->black_pixel
;
468 attribs
.save_under
= True
;
469 attribs
.override_redirect
= True
;
470 attribs
.background_pixmap
= None
;
471 attribs
.background_pixel
= scr
->white_pixel
;
472 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
474 attribs
.colormap
= scr
->w_colormap
;
476 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
477 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
478 scr
->w_visual
, vmask
, &attribs
);
480 /* workspace name balloon for clip */
481 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
483 attribs
.save_under
= True
;
484 attribs
.override_redirect
= True
;
485 attribs
.colormap
= scr
->w_colormap
;
486 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
487 attribs
.border_pixel
= 0; /* do not care */
489 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
490 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
494 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
496 attribs
.save_under
= True
;
497 attribs
.override_redirect
= True
;
498 attribs
.colormap
= scr
->w_colormap
;
499 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
500 attribs
.border_pixel
= 0; /* do not care */
501 scr
->workspace_name
=
502 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
503 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
506 * If the window is clicked without having ButtonPress selected, the
507 * resulting event will have event.xbutton.window == root.
509 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
515 aquireManagerSelection(WScreen
*scr
)
521 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
522 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
524 /* for race-conditions... */
527 /* if there is another manager running, don't try to replace it
528 * (for now, at least) */
529 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
534 /* become the manager for this screen */
536 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
539 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
540 /* get a timestamp */
541 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
542 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
544 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
545 if (ev
.type
== PropertyNotify
) {
546 timestamp
= ev
.xproperty
.time
;
550 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
551 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
553 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
557 /* announce our arrival */
559 ev
.xclient
.type
= ClientMessage
;
560 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
561 ev
.xclient
.destination
= scr
->root_win
;
562 ev
.xclient
.format
= 32;
563 ev
.xclient
.data
.l
[0] = timestamp
;
564 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
565 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
566 ev
.xclient
.data
.l
[3] = 0;
567 ev
.xclient
.data
.l
[4] = 0;
569 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
577 *----------------------------------------------------------------------
579 * Initializes the window manager for the given screen and
580 * allocates a WScreen descriptor for it. Many resources are allocated
581 * for the screen and the root window is setup appropriately.
584 * The WScreen descriptor for the screen.
587 * Many resources are allocated and the IconSize property is
588 * set on the root window.
589 * The program can be aborted if some fatal error occurs.
591 * TODO: User specifiable visual.
592 *----------------------------------------------------------------------
595 wScreenInit(int screen_number
)
598 XIconSize icon_size
[1];
599 RContextAttributes rattr
;
600 extern int wVisualID
;
602 XErrorHandler oldHandler
;
605 scr
= wmalloc(sizeof(WScreen
));
606 memset(scr
, 0, sizeof(WScreen
));
608 scr
->stacking_list
= WMCreateTreeBag();
610 /* initialize globals */
611 scr
->screen
= screen_number
;
612 scr
->root_win
= RootWindow(dpy
, screen_number
);
613 scr
->depth
= DefaultDepth(dpy
, screen_number
);
614 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
616 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
617 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
621 scr
->usableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
622 scr
->totalUsableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
624 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
625 WMRect rect
= wGetRectForHead(scr
, i
);
626 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
627 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
628 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
629 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
632 scr
->fakeGroupLeaders
= WMCreateArray(16);
635 if (!aquireManagerSelection(scr
)) {
641 CantManageScreen
= 0;
642 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
644 event_mask
= EVENT_MASK
;
646 if (wPreferences
.disable_root_mouse
) {
647 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
650 XSelectInput(dpy
, scr
->root_win
, event_mask
);
652 #ifdef KEEP_XKB_LOCK_STATUS
653 /* Only GroupLock doesn't work correctly in my system since right-alt
654 * can change mode while holding it too - ]d
657 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
661 #endif /* KEEP_XKB_LOCK_STATUS */
664 XSetErrorHandler(oldHandler
);
666 if (CantManageScreen
) {
671 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
673 /* screen descriptor for raster graphic library */
674 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
675 rattr
.render_mode
= wPreferences
.no_dithering
676 ? RBestMatchRendering
677 : RDitheredRendering
;
679 /* if the std colormap stuff works ok, this will be ignored */
680 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
681 if (rattr
.colors_per_channel
<2)
682 rattr
.colors_per_channel
= 2;
685 /* will only be accounted for in PseudoColor */
686 if (wPreferences
.flags
.create_stdcmap
) {
687 rattr
.standard_colormap_mode
= RCreateStdColormap
;
689 rattr
.standard_colormap_mode
= RUseStdColormap
;
693 rattr
.flags
|= RC_VisualID
;
694 rattr
.visualid
= wVisualID
;
697 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
699 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
700 wwarning(RMessageForError(RErrorCode
));
702 rattr
.flags
&= ~RC_StandardColormap
;
703 rattr
.standard_colormap_mode
= RUseStdColormap
;
705 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
708 if (!scr
->rcontext
) {
709 wwarning(_("could not initialize graphics library context: %s"),
710 RMessageForError(RErrorCode
));
716 formats
= RSupportedFileFormats();
718 for (i
=0; formats
[i
]!=NULL
; i
++) {
719 if (strcmp(formats
[i
], "TIFF")==0) {
720 scr
->flags
.supports_tiff
= 1;
727 scr
->w_win
= scr
->rcontext
->drawable
;
728 scr
->w_visual
= scr
->rcontext
->visual
;
729 scr
->w_depth
= scr
->rcontext
->depth
;
730 scr
->w_colormap
= scr
->rcontext
->cmap
;
732 /* create screen descriptor for WINGs */
733 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
736 if (!scr
->wmscreen
) {
737 wfatal(_("could not initialize WINGs widget set"));
741 scr
->black
= WMBlackColor(scr
->wmscreen
);
742 scr
->white
= WMWhiteColor(scr
->wmscreen
);
743 scr
->gray
= WMGrayColor(scr
->wmscreen
);
744 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
746 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black;*/
747 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white;*/
748 scr
->light_pixel
= WMColorPixel(scr
->gray
);
749 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
753 /* frame boder color */
754 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
755 scr
->frame_border_pixel
= xcol
.pixel
;
758 /* create GCs with default values */
761 /* for our window manager info notice board. Need to
762 * create before reading the defaults, because it will be used there.
764 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
767 /* read defaults for this screen */
768 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
770 createInternalWindows(scr
);
773 wNETWMInitStuff(scr
);
776 /* create initial workspace */
779 /* create shared pixmaps */
782 /* set icon sizes we can accept from clients */
783 icon_size
[0].min_width
= 8;
784 icon_size
[0].min_height
= 8;
785 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
786 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
787 icon_size
[0].width_inc
= 1;
788 icon_size
[0].height_inc
= 1;
789 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
791 /* setup WindowMaker protocols property in the root window*/
792 PropSetWMakerProtocols(scr
->root_win
);
794 /* setup our noticeboard */
795 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
796 XA_WINDOW
, 32, PropModeReplace
,
797 (unsigned char*)&scr
->info_window
, 1);
798 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
799 XA_WINDOW
, 32, PropModeReplace
,
800 (unsigned char*)&scr
->info_window
, 1);
804 /* initialize balloon text stuff */
805 wBalloonInitialize(scr
);
808 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
810 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
811 if (!scr
->tech_draw_font
)
812 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "fixed");
814 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
815 WMRealizeWidget(scr
->gview
);
817 wScreenUpdateUsableArea(scr
);
824 wScreenUpdateUsableArea(WScreen
*scr
)
827 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
828 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
833 unsigned long best_area
= 0, tmp_area
;
835 int dock_head
= scr
->xine_info
.primary_head
;
839 rect
.pos
.x
= scr
->dock
->x_pos
;
840 rect
.pos
.y
= scr
->dock
->y_pos
;
841 rect
.size
.width
= wPreferences
.icon_size
;
842 rect
.size
.height
= wPreferences
.icon_size
;
843 dock_head
= wGetHeadForRect(scr
, rect
);
846 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
847 WMRect rect
= wGetRectForHead(scr
, i
);
848 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
849 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
850 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
851 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
853 if (scr
->dock
&& dock_head
==i
&&
854 (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
855 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
857 if (scr
->dock
->on_right_side
) {
858 scr
->totalUsableArea
[i
].x2
-= offset
;
860 scr
->totalUsableArea
[i
].x1
+= offset
;
867 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
868 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
869 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
870 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
871 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
876 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
879 printf("usableArea[%d]: %d %d %d %d\n", i
,
880 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
,
881 scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
884 if (wPreferences
.no_window_over_icons
) {
885 if (wPreferences
.icon_yard
& IY_VERT
) {
886 if (wPreferences
.icon_yard
& IY_RIGHT
) {
887 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
889 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
892 if (wPreferences
.icon_yard
& IY_TOP
) {
893 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
895 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
900 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/2) {
901 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
902 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
905 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/2) {
906 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
907 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
910 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
911 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
913 if (tmp_area
> best_area
) {
914 best_area
= tmp_area
;
915 area
= scr
->totalUsableArea
[i
];
919 unsigned size
= wPreferences
.workspace_border_size
;
920 unsigned position
= wPreferences
.workspace_border_position
;
922 if (size
>0 && position
!=WB_NONE
) {
923 if (position
& WB_LEFTRIGHT
) {
924 scr
->totalUsableArea
[i
].x1
+= size
;
925 scr
->totalUsableArea
[i
].x2
-= size
;
927 if (position
& WB_TOPBOTTOM
) {
928 scr
->totalUsableArea
[i
].y1
+= size
;
929 scr
->totalUsableArea
[i
].y2
-= size
;
936 wNETWMUpdateWorkarea(scr
, area
);
939 if (wPreferences
.auto_arrange_icons
) {
940 wArrangeIcons(scr
, True
);
946 wScreenUpdateUsableArea(WScreen
*scr
)
948 scr
->totalUsableArea
= scr
->usableArea
;
950 if (scr
->dock
&& (!scr
->dock
->lowered
951 || wPreferences
.no_window_over_dock
)) {
953 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
955 if (scr
->dock
->on_right_side
) {
956 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
957 scr
->scr_width
- offset
);
959 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
963 if (wPreferences
.no_window_over_icons
) {
964 if (wPreferences
.icon_yard
& IY_VERT
) {
966 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
967 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
969 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
973 if (wPreferences
.icon_yard
& IY_TOP
) {
974 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
976 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
984 if (wNETWMGetUsableArea(scr
, &area
)) {
985 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
986 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
987 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
988 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
993 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
994 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
995 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
997 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
998 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
999 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
1003 wNETWMUpdateWorkarea(scr
);
1007 unsigned size
= wPreferences
.workspace_border_size
;
1008 unsigned position
= wPreferences
.workspace_border_position
;
1010 if (size
>0 && position
!=WB_NONE
) {
1011 if (position
& WB_LEFTRIGHT
) {
1012 scr
->totalUsableArea
.x1
+= size
;
1013 scr
->totalUsableArea
.x2
-= size
;
1015 if (position
& WB_TOPBOTTOM
) {
1016 scr
->totalUsableArea
.y1
+= size
;
1017 scr
->totalUsableArea
.y2
-= size
;
1022 if (wPreferences
.auto_arrange_icons
) {
1023 wArrangeIcons(scr
, True
);
1030 wScreenRestoreState(WScreen
*scr
)
1037 OpenRootMenu(scr
, -10000, -10000, False
);
1038 wMenuUnmap(scr
->root_menu
);
1043 if (wScreenCount
== 1) {
1044 path
= wdefaultspathfordomain("WMState");
1047 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1048 path
= wdefaultspathfordomain(buf
);
1050 scr
->session_state
= WMReadPropListFromFile(path
);
1052 if (!scr
->session_state
&& wScreenCount
>1) {
1053 path
= wdefaultspathfordomain("WMState");
1054 scr
->session_state
= WMReadPropListFromFile(path
);
1058 if (!scr
->session_state
) {
1059 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
1062 if (!wPreferences
.flags
.nodock
) {
1063 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1064 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1067 if (!wPreferences
.flags
.noclip
) {
1068 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
1069 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1072 wWorkspaceRestoreState(scr
);
1074 wScreenUpdateUsableArea(scr
);
1079 wScreenSaveState(WScreen
*scr
)
1083 WMPropList
*old_state
, *foo
;
1087 /* save state of windows */
1088 wwin
= scr
->focused_window
;
1090 wWindowSaveState(wwin
);
1095 if (wPreferences
.flags
.noupdates
)
1099 old_state
= scr
->session_state
;
1100 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
1102 WMPLSetCaseSensitive(True
);
1104 /* save dock state to file */
1105 if (!wPreferences
.flags
.nodock
) {
1106 wDockSaveState(scr
, old_state
);
1108 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1109 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1112 if (!wPreferences
.flags
.noclip
) {
1113 wClipSaveState(scr
);
1115 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1116 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1120 wWorkspaceSaveState(scr
, old_state
);
1122 if (wPreferences
.save_session_on_exit
) {
1123 wSessionSaveState(scr
);
1125 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1126 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1128 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1129 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1134 WMPLSetCaseSensitive(False
);
1136 wMenuSaveState(scr
);
1138 if (wScreenCount
== 1) {
1139 str
= wdefaultspathfordomain("WMState");
1142 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1143 str
= wdefaultspathfordomain(buf
);
1145 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1146 wsyserror(_("could not save session state in %s"), str
);
1149 WMReleasePropList(old_state
);
1155 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1160 * With respect to the head that contains most of the window.
1162 int sx1
, sy1
, sx2
, sy2
;
1169 rect
.size
.width
= width
;
1170 rect
.size
.height
= height
;
1172 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1173 rect
= wGetRectForHead(scr
, head
);
1177 sx2
= sx1
+ rect
.size
.width
;
1178 sy2
= sy1
+ rect
.size
.height
;
1180 #if 0 /* NOTE: gives funky group movement */
1181 if (flags
& XFLAG_MULTIPLE
) {
1183 * since we span multiple heads, pull window totaly inside
1186 *x
= sx1
, moved
= 1;
1187 else if (*x
+ width
> sx2
)
1188 *x
= sx2
- width
, moved
= 1;
1191 *y
= sy1
, moved
= 1;
1192 else if (*y
+ height
> sy2
)
1193 *y
= sy2
- height
, moved
= 1;
1209 if (*x
+ width
< sx1
+ 10)
1210 *x
= sx1
- tol_w
, moved
= 1;
1211 else if (*x
>= sx2
- 10)
1212 *x
= sx2
- tol_w
- 1, moved
= 1;
1214 if (*y
< sy1
- height
+ 10)
1215 *y
= sy1
- tol_h
, moved
= 1;
1216 else if (*y
>= sy2
- 10)
1217 *y
= sy2
- tol_h
- 1, moved
= 1;
1225 wScreenKeepInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1228 int sx1
, sy1
, sx2
, sy2
;
1234 rect
.size
.width
= width
;
1235 rect
.size
.height
= height
;
1237 head
= wGetHeadForRect(scr
, rect
);
1238 rect
= wGetRectForHead(scr
, head
);
1242 sx2
= sx1
+ rect
.size
.width
;
1243 sy2
= sy1
+ rect
.size
.height
;
1246 *x
= sx1
, moved
= 1;
1247 else if (*x
+ width
> sx2
)
1248 *x
= sx2
- width
, moved
= 1;
1251 *y
= sy1
, moved
= 1;
1252 else if (*y
+ height
> sy2
)
1253 *y
= sy2
- height
, moved
= 1;