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"
63 # include "openlook.h"
71 #include <WINGs/WUtil.h>
77 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
78 |SubstructureNotifyMask|PointerMotionMask \
79 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
81 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
82 |SubstructureNotifyMask|PointerMotionMask \
83 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
84 |KeyPressMask|KeyReleaseMask)
87 /**** Global variables ****/
89 extern Cursor wCursor
[WCUR_LAST
];
90 extern WPreferences wPreferences
;
91 extern Atom _XA_WINDOWMAKER_STATE
;
92 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
95 extern int wScreenCount
;
97 #ifdef KEEP_XKB_LOCK_STATUS
98 extern int wXkbSupported
;
101 extern WDDomain
*WDWindowMaker
;
106 #define STIPPLE_WIDTH 2
107 #define STIPPLE_HEIGHT 2
108 static char STIPPLE_DATA
[] = {0x02, 0x01};
110 static int CantManageScreen
= 0;
112 static WMPropList
*dApplications
= NULL
;
113 static WMPropList
*dWorkspace
;
114 static WMPropList
*dDock
;
115 static WMPropList
*dClip
;
121 if (dApplications
!=NULL
)
124 dApplications
= WMCreatePLString("Applications");
125 dWorkspace
= WMCreatePLString("Workspace");
126 dDock
= WMCreatePLString("Dock");
127 dClip
= WMCreatePLString("Clip");
132 *----------------------------------------------------------------------
133 * alreadyRunningError--
134 * X error handler used to catch errors when trying to do
135 * XSelectInput() on the root window. These errors probably mean that
136 * there already is some other window manager running.
139 * Nothing, unless something really evil happens...
142 * CantManageScreen is set to 1;
143 *----------------------------------------------------------------------
146 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
148 CantManageScreen
= 1;
154 *----------------------------------------------------------------------
155 * allocButtonPixmaps--
156 * Allocate pixmaps used on window operation buttons (those in the
157 * titlebar). The pixmaps are linked to the program. If XPM is supported
158 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
164 * Allocates shared pixmaps for the screen. These pixmaps should
165 * not be freed by anybody.
166 *----------------------------------------------------------------------
169 allocButtonPixmaps(WScreen
*scr
)
173 /* create predefined pixmaps */
174 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
177 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
182 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
184 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
187 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
188 #ifdef XKB_BUTTON_HINT
189 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
192 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
193 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
196 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
197 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
200 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
201 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
204 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
208 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
211 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
216 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
218 XSetForeground(dpy
, gc
, scr
->black_pixel
);
219 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
220 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
221 XSetForeground(dpy
, gc
, scr
->white_pixel
);
222 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
223 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
228 make3Dots(WScreen
*scr
)
236 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
237 wPreferences
.icon_size
, scr
->w_depth
);
238 XSetForeground(dpy
, gc
, scr
->black_pixel
);
239 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
240 wPreferences
.icon_size
);
241 XSetForeground(dpy
, gc
, scr
->white_pixel
);
242 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
243 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
244 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
246 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
247 wPreferences
.icon_size
, 1);
249 gcv
.graphics_exposures
= False
;
250 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
251 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
252 wPreferences
.icon_size
);
253 XSetForeground(dpy
, gc2
, 1);
254 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
255 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
256 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
260 wpix
= wPixmapCreate(scr
, pix
, mask
);
268 allocGCs(WScreen
*scr
)
274 scr
->stipple_bitmap
=
275 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
278 gcv
.stipple
= scr
->stipple_bitmap
;
279 gcv
.foreground
= scr
->white_pixel
;
280 gcv
.fill_style
= FillStippled
;
281 gcv
.graphics_exposures
= False
;
282 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
283 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
332 gcv
.foreground
= color
.pixel
;
334 if (gcv
.foreground
== 0)
335 /* XOR:ing with a zero is not going to be of much use, so
336 in that case, we somewhat arbitrarily xor with 17 instead. */
339 gcv
.function
= GXxor
;
340 gcv
.subwindow_mode
= IncludeInferiors
;
342 gcv
.cap_style
= CapRound
;
343 gcv
.graphics_exposures
= False
;
344 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
345 |GCGraphicsExposures
;
346 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
348 scr
->line_pixel
= gcv
.foreground
;
351 gcv
.foreground
= scr
->white_pixel
;
352 gcv
.background
= scr
->black_pixel
;
353 gcv
.graphics_exposures
= False
;
354 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
355 |GCGraphicsExposures
, &gcv
);
357 /* misc drawing GC */
358 gcv
.graphics_exposures
= False
;
359 gcm
= GCGraphicsExposures
;
360 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
362 assert (scr
->stipple_bitmap
!=None
);
366 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
372 createPixmaps(WScreen
*scr
)
378 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
379 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
380 MENU_RADIO_INDICATOR_XBM_SIZE
,
381 MENU_RADIO_INDICATOR_XBM_SIZE
,
382 scr
->black_pixel
, scr
->white_pixel
);
385 scr
->menu_radio_indicator
= pix
;
388 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
389 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
390 MENU_CHECK_INDICATOR_XBM_SIZE
,
391 MENU_CHECK_INDICATOR_XBM_SIZE
,
392 scr
->black_pixel
, scr
->white_pixel
);
395 scr
->menu_check_indicator
= pix
;
397 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
398 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
399 MENU_MINI_INDICATOR_XBM_SIZE
,
400 MENU_MINI_INDICATOR_XBM_SIZE
,
401 scr
->black_pixel
, scr
->white_pixel
);
404 scr
->menu_mini_indicator
= pix
;
406 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
407 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
408 MENU_HIDE_INDICATOR_XBM_SIZE
,
409 MENU_HIDE_INDICATOR_XBM_SIZE
,
410 scr
->black_pixel
, scr
->white_pixel
);
413 scr
->menu_hide_indicator
= pix
;
415 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
416 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
417 MENU_SHADE_INDICATOR_XBM_SIZE
,
418 MENU_SHADE_INDICATOR_XBM_SIZE
,
419 scr
->black_pixel
, scr
->white_pixel
);
422 scr
->menu_shade_indicator
= pix
;
425 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
428 wwarning(_("could not load logo image for panels: %s"),
429 RMessageForError(RErrorCode
));
431 WMSetApplicationIconImage(scr
->wmscreen
, image
);
432 RReleaseImage(image
);
435 scr
->dock_dots
= make3Dots(scr
);
437 /* titlebar button pixmaps */
438 allocButtonPixmaps(scr
);
443 *----------------------------------------------------------------------
444 * createInternalWindows--
445 * Creates some windows used internally by the program. One to
446 * receive input focus when no other window can get it and another
447 * to display window geometry information during window resize/move.
453 * Windows are created and some colors are allocated for the
455 *----------------------------------------------------------------------
458 createInternalWindows(WScreen
*scr
)
461 XSetWindowAttributes attribs
;
463 /* InputOnly window to get the focus when no other window can get it */
464 vmask
= CWEventMask
|CWOverrideRedirect
;
465 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
466 attribs
.override_redirect
= True
;
467 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
468 InputOnly
,CopyFromParent
, vmask
, &attribs
);
469 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
470 XMapWindow(dpy
, scr
->no_focus_win
);
472 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
474 /* shadow window for dock buttons */
475 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
476 attribs
.border_pixel
= scr
->black_pixel
;
477 attribs
.save_under
= True
;
478 attribs
.override_redirect
= True
;
479 attribs
.background_pixmap
= None
;
480 attribs
.background_pixel
= scr
->white_pixel
;
481 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
483 attribs
.colormap
= scr
->w_colormap
;
485 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
486 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
487 scr
->w_visual
, vmask
, &attribs
);
489 /* workspace name balloon for clip */
490 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
492 attribs
.save_under
= True
;
493 attribs
.override_redirect
= True
;
494 attribs
.colormap
= scr
->w_colormap
;
495 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
496 attribs
.border_pixel
= 0; /* do not care */
498 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
499 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
503 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
505 attribs
.save_under
= True
;
506 attribs
.override_redirect
= True
;
507 attribs
.colormap
= scr
->w_colormap
;
508 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
509 attribs
.border_pixel
= 0; /* do not care */
510 scr
->workspace_name
=
511 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
512 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
515 * If the window is clicked without having ButtonPress selected, the
516 * resulting event will have event.xbutton.window == root.
518 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
524 aquireManagerSelection(WScreen
*scr
)
530 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
531 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
533 /* for race-conditions... */
536 /* if there is another manager running, don't try to replace it
537 * (for now, at least) */
538 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
543 /* become the manager for this screen */
545 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
548 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
549 /* get a timestamp */
550 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
551 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
553 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
554 if (ev
.type
== PropertyNotify
) {
555 timestamp
= ev
.xproperty
.time
;
559 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
560 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
562 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
566 /* announce our arrival */
568 ev
.xclient
.type
= ClientMessage
;
569 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
570 ev
.xclient
.destination
= scr
->root_win
;
571 ev
.xclient
.format
= 32;
572 ev
.xclient
.data
.l
[0] = timestamp
;
573 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
574 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
575 ev
.xclient
.data
.l
[3] = 0;
576 ev
.xclient
.data
.l
[4] = 0;
578 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
586 *----------------------------------------------------------------------
588 * Initializes the window manager for the given screen and
589 * allocates a WScreen descriptor for it. Many resources are allocated
590 * for the screen and the root window is setup appropriately.
593 * The WScreen descriptor for the screen.
596 * Many resources are allocated and the IconSize property is
597 * set on the root window.
598 * The program can be aborted if some fatal error occurs.
600 * TODO: User specifiable visual.
601 *----------------------------------------------------------------------
604 wScreenInit(int screen_number
)
607 XIconSize icon_size
[1];
608 RContextAttributes rattr
;
609 extern int wVisualID
;
611 XErrorHandler oldHandler
;
614 scr
= wmalloc(sizeof(WScreen
));
615 memset(scr
, 0, sizeof(WScreen
));
617 scr
->stacking_list
= WMCreateTreeBag();
619 /* initialize globals */
620 scr
->screen
= screen_number
;
621 scr
->root_win
= RootWindow(dpy
, screen_number
);
622 scr
->depth
= DefaultDepth(dpy
, screen_number
);
623 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
625 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
626 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
630 scr
->usableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
631 scr
->totalUsableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
633 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
634 WMRect rect
= wGetRectForHead(scr
, i
);
635 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
636 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
637 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
638 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
641 scr
->fakeGroupLeaders
= WMCreateArray(16);
644 if (!aquireManagerSelection(scr
)) {
650 CantManageScreen
= 0;
651 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
653 event_mask
= EVENT_MASK
;
655 if (wPreferences
.disable_root_mouse
) {
656 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
659 XSelectInput(dpy
, scr
->root_win
, event_mask
);
661 #ifdef KEEP_XKB_LOCK_STATUS
662 /* Only GroupLock doesn't work correctly in my system since right-alt
663 * can change mode while holding it too - ]d
666 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
670 #endif /* KEEP_XKB_LOCK_STATUS */
673 XSetErrorHandler(oldHandler
);
675 if (CantManageScreen
) {
680 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
682 /* screen descriptor for raster graphic library */
683 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
684 rattr
.render_mode
= wPreferences
.no_dithering
685 ? RBestMatchRendering
686 : RDitheredRendering
;
688 /* if the std colormap stuff works ok, this will be ignored */
689 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
690 if (rattr
.colors_per_channel
<2)
691 rattr
.colors_per_channel
= 2;
694 /* will only be accounted for in PseudoColor */
695 if (wPreferences
.flags
.create_stdcmap
) {
696 rattr
.standard_colormap_mode
= RCreateStdColormap
;
698 rattr
.standard_colormap_mode
= RUseStdColormap
;
702 rattr
.flags
|= RC_VisualID
;
703 rattr
.visualid
= wVisualID
;
706 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
708 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
709 wwarning(RMessageForError(RErrorCode
));
711 rattr
.flags
&= ~RC_StandardColormap
;
712 rattr
.standard_colormap_mode
= RUseStdColormap
;
714 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
717 if (!scr
->rcontext
) {
718 wwarning(_("could not initialize graphics library context: %s"),
719 RMessageForError(RErrorCode
));
725 formats
= RSupportedFileFormats();
727 for (i
=0; formats
[i
]!=NULL
; i
++) {
728 if (strcmp(formats
[i
], "TIFF")==0) {
729 scr
->flags
.supports_tiff
= 1;
736 scr
->w_win
= scr
->rcontext
->drawable
;
737 scr
->w_visual
= scr
->rcontext
->visual
;
738 scr
->w_depth
= scr
->rcontext
->depth
;
739 scr
->w_colormap
= scr
->rcontext
->cmap
;
741 /* create screen descriptor for WINGs */
742 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
745 if (!scr
->wmscreen
) {
746 wfatal(_("could not initialize WINGs widget set"));
750 scr
->black
= WMBlackColor(scr
->wmscreen
);
751 scr
->white
= WMWhiteColor(scr
->wmscreen
);
752 scr
->gray
= WMGrayColor(scr
->wmscreen
);
753 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
755 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black;*/
756 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white;*/
757 scr
->light_pixel
= WMColorPixel(scr
->gray
);
758 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
762 /* frame boder color */
763 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
764 scr
->frame_border_pixel
= xcol
.pixel
;
767 /* create GCs with default values */
770 /* for our window manager info notice board. Need to
771 * create before reading the defaults, because it will be used there.
773 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
776 /* read defaults for this screen */
777 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
779 createInternalWindows(scr
);
786 wGNOMEInitStuff(scr
);
794 wNETWMInitStuff(scr
);
797 /* create initial workspace */
800 /* create shared pixmaps */
803 /* set icon sizes we can accept from clients */
804 icon_size
[0].min_width
= 8;
805 icon_size
[0].min_height
= 8;
806 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
807 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
808 icon_size
[0].width_inc
= 1;
809 icon_size
[0].height_inc
= 1;
810 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
812 /* setup WindowMaker protocols property in the root window*/
813 PropSetWMakerProtocols(scr
->root_win
);
815 /* setup our noticeboard */
816 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
817 XA_WINDOW
, 32, PropModeReplace
,
818 (unsigned char*)&scr
->info_window
, 1);
819 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
820 XA_WINDOW
, 32, PropModeReplace
,
821 (unsigned char*)&scr
->info_window
, 1);
825 /* initialize balloon text stuff */
826 wBalloonInitialize(scr
);
829 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
831 scr
->tech_draw_font
= XLoadQueryFont(dpy
, "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
833 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
834 WMRealizeWidget(scr
->gview
);
836 wScreenUpdateUsableArea(scr
);
843 wScreenUpdateUsableArea(WScreen
*scr
)
846 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
847 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
852 unsigned long best_area
= 0, tmp_area
;
854 int dock_head
= scr
->xine_info
.primary_head
;
858 rect
.pos
.x
= scr
->dock
->x_pos
;
859 rect
.pos
.y
= scr
->dock
->y_pos
;
860 rect
.size
.width
= wPreferences
.icon_size
;
861 rect
.size
.height
= wPreferences
.icon_size
;
862 dock_head
= wGetHeadForRect(scr
, rect
);
865 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
866 WMRect rect
= wGetRectForHead(scr
, i
);
867 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
868 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
869 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
870 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
872 if (scr
->dock
&& dock_head
==i
&&
873 (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
874 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
876 if (scr
->dock
->on_right_side
) {
877 scr
->totalUsableArea
[i
].x2
-= offset
;
879 scr
->totalUsableArea
[i
].x1
+= offset
;
886 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
887 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
888 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
889 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
890 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
898 if (wGNOMEGetUsableArea(scr
, i
, &area
)) {
899 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
900 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
901 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
902 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
910 if (wKWMGetUsableArea(scr
, i
, &area
)) {
911 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
912 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
913 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
914 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
919 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
922 printf("usableArea[%d]: %d %d %d %d\n", i
,
923 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
,
924 scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
927 if (wPreferences
.no_window_over_icons
) {
928 if (wPreferences
.icon_yard
& IY_VERT
) {
929 if (wPreferences
.icon_yard
& IY_RIGHT
) {
930 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
932 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
935 if (wPreferences
.icon_yard
& IY_TOP
) {
936 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
938 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
943 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/2) {
944 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
945 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
948 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/2) {
949 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
950 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
953 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
954 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
956 if (tmp_area
> best_area
) {
957 best_area
= tmp_area
;
958 area
= scr
->totalUsableArea
[i
];
962 unsigned size
= wPreferences
.workspace_border_size
;
963 unsigned position
= wPreferences
.workspace_border_position
;
965 if (size
>0 && position
!=WB_NONE
) {
966 if (position
& WB_LEFTRIGHT
) {
967 scr
->totalUsableArea
[i
].x1
+= size
;
968 scr
->totalUsableArea
[i
].x2
-= size
;
970 if (position
& WB_TOPBOTTOM
) {
971 scr
->totalUsableArea
[i
].y1
+= size
;
972 scr
->totalUsableArea
[i
].y2
-= size
;
979 wNETWMUpdateWorkarea(scr
, area
);
982 if (wPreferences
.auto_arrange_icons
) {
983 wArrangeIcons(scr
, True
);
989 wScreenUpdateUsableArea(WScreen
*scr
)
991 scr
->totalUsableArea
= scr
->usableArea
;
993 if (scr
->dock
&& (!scr
->dock
->lowered
994 || wPreferences
.no_window_over_dock
)) {
996 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
998 if (scr
->dock
->on_right_side
) {
999 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
1000 scr
->scr_width
- offset
);
1002 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
1006 if (wPreferences
.no_window_over_icons
) {
1007 if (wPreferences
.icon_yard
& IY_VERT
) {
1009 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
1010 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
1012 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
1016 if (wPreferences
.icon_yard
& IY_TOP
) {
1017 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
1019 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
1027 if (wNETWMGetUsableArea(scr
, &area
)) {
1028 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
1029 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
1030 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
1031 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
1039 if (wKWMGetUsableArea(scr
, &area
)) {
1040 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
1041 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
1042 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
1043 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
1050 WReservedArea
*area
= scr
->reservedAreas
;
1057 w
= area
->area
.x2
- area
->area
.x1
;
1058 h
= area
->area
.y2
- area
->area
.y1
;
1061 bh
= scr
->scr_height
- area
->area
.y2
;
1063 rw
= scr
->scr_width
- area
->area
.x2
;
1065 if (WMIN(th
, bh
) <= WMIN(lw
, rw
)) {
1069 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
1070 scr
->totalUsableArea
.y1
= area
->area
.y2
;
1073 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
1074 scr
->totalUsableArea
.y2
= area
->area
.y1
;
1080 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
1081 scr
->totalUsableArea
.x1
= area
->area
.x2
;
1084 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
1085 scr
->totalUsableArea
.x2
= area
->area
.x1
;
1092 #endif /* GNOME_STUFF */
1094 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
1095 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
1096 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
1098 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
1099 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
1100 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
1108 for (i
= 0; i
< scr
->workspace_count
; i
++) {
1109 wKWMSetUsableAreaHint(scr
, i
);
1116 wNETWMUpdateWorkarea(scr
);
1120 unsigned size
= wPreferences
.workspace_border_size
;
1121 unsigned position
= wPreferences
.workspace_border_position
;
1123 if (size
>0 && position
!=WB_NONE
) {
1124 if (position
& WB_LEFTRIGHT
) {
1125 scr
->totalUsableArea
.x1
+= size
;
1126 scr
->totalUsableArea
.x2
-= size
;
1128 if (position
& WB_TOPBOTTOM
) {
1129 scr
->totalUsableArea
.y1
+= size
;
1130 scr
->totalUsableArea
.y2
-= size
;
1135 if (wPreferences
.auto_arrange_icons
) {
1136 wArrangeIcons(scr
, True
);
1143 wScreenRestoreState(WScreen
*scr
)
1150 OpenRootMenu(scr
, -10000, -10000, False
);
1151 wMenuUnmap(scr
->root_menu
);
1156 if (wScreenCount
== 1) {
1157 path
= wdefaultspathfordomain("WMState");
1160 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1161 path
= wdefaultspathfordomain(buf
);
1163 scr
->session_state
= WMReadPropListFromFile(path
);
1165 if (!scr
->session_state
&& wScreenCount
>1) {
1166 path
= wdefaultspathfordomain("WMState");
1167 scr
->session_state
= WMReadPropListFromFile(path
);
1171 if (!scr
->session_state
) {
1172 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
1175 if (!wPreferences
.flags
.nodock
) {
1176 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1177 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1180 if (!wPreferences
.flags
.noclip
) {
1181 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
1182 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1185 wWorkspaceRestoreState(scr
);
1187 #ifdef VIRTUAL_DESKTOP
1188 /* create inputonly windows at the border of screen */
1189 wWorkspaceManageEdge(scr
);
1192 wScreenUpdateUsableArea(scr
);
1197 wScreenSaveState(WScreen
*scr
)
1201 WMPropList
*old_state
, *foo
;
1207 /* Save current workspace, so can go back to it upon restart. */
1208 data
[0] = scr
->current_workspace
;
1209 data
[1] = WFLAGS_NONE
;
1211 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1212 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1213 (unsigned char *) data
, 2);
1215 /* save state of windows */
1216 wwin
= scr
->focused_window
;
1218 wWindowSaveState(wwin
);
1223 if (wPreferences
.flags
.noupdates
)
1227 old_state
= scr
->session_state
;
1228 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
);
1230 WMPLSetCaseSensitive(True
);
1232 /* save dock state to file */
1233 if (!wPreferences
.flags
.nodock
) {
1234 wDockSaveState(scr
, old_state
);
1236 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1237 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1240 if (!wPreferences
.flags
.noclip
) {
1241 wClipSaveState(scr
);
1243 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1244 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1248 wWorkspaceSaveState(scr
, old_state
);
1250 if (wPreferences
.save_session_on_exit
) {
1251 wSessionSaveState(scr
);
1253 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1254 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1256 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1257 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1262 WMPLSetCaseSensitive(False
);
1264 wMenuSaveState(scr
);
1266 if (wScreenCount
== 1) {
1267 str
= wdefaultspathfordomain("WMState");
1270 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1271 str
= wdefaultspathfordomain(buf
);
1273 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1274 wsyserror(_("could not save session state in %s"), str
);
1277 WMReleasePropList(old_state
);
1283 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1288 * With respect to the head that contains most of the window.
1290 int sx1
, sy1
, sx2
, sy2
;
1297 rect
.size
.width
= width
;
1298 rect
.size
.height
= height
;
1300 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1301 rect
= wGetRectForHead(scr
, head
);
1305 sx2
= sx1
+ rect
.size
.width
;
1306 sy2
= sy1
+ rect
.size
.height
;
1308 #if 0 /* NOTE: gives funky group movement */
1309 if (flags
& XFLAG_MULTIPLE
) {
1311 * since we span multiple heads, pull window totaly inside
1314 *x
= sx1
, moved
= 1;
1315 else if (*x
+ width
> sx2
)
1316 *x
= sx2
- width
, moved
= 1;
1319 *y
= sy1
, moved
= 1;
1320 else if (*y
+ height
> sy2
)
1321 *y
= sy2
- height
, moved
= 1;
1337 if (*x
+ width
< sx1
+ 10)
1338 *x
= sx1
- tol_w
, moved
= 1;
1339 else if (*x
>= sx2
- 10)
1340 *x
= sx2
- tol_w
- 1, moved
= 1;
1342 if (*y
< sy1
- height
+ 10)
1343 *y
= sy1
- tol_h
, moved
= 1;
1344 else if (*y
>= sy2
- 10)
1345 *y
= sy2
- tol_h
- 1, moved
= 1;
1353 wScreenKeepInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1356 int sx1
, sy1
, sx2
, sy2
;
1362 rect
.size
.width
= width
;
1363 rect
.size
.height
= height
;
1365 head
= wGetHeadForRect(scr
, rect
);
1366 rect
= wGetRectForHead(scr
, head
);
1370 sx2
= sx1
+ rect
.size
.width
;
1371 sy2
= sy1
+ rect
.size
.height
;
1374 *x
= sx1
, moved
= 1;
1375 else if (*x
+ width
> sx2
)
1376 *x
= sx2
- width
, moved
= 1;
1379 *y
= sy1
, moved
= 1;
1380 else if (*y
+ height
> sy2
)
1381 *y
= sy2
- height
, moved
= 1;