1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997-2002 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"
68 #include <WINGs/WUtil.h>
74 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
75 |SubstructureNotifyMask|PointerMotionMask \
76 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
78 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
79 |SubstructureNotifyMask|PointerMotionMask \
80 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
81 |KeyPressMask|KeyReleaseMask)
84 /**** Global variables ****/
86 extern Cursor wCursor
[WCUR_LAST
];
87 extern WPreferences wPreferences
;
88 extern Atom _XA_WINDOWMAKER_STATE
;
89 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
92 extern int wScreenCount
;
94 #ifdef KEEP_XKB_LOCK_STATUS
95 extern int wXkbSupported
;
98 extern WDDomain
*WDWindowMaker
;
103 #define STIPPLE_WIDTH 2
104 #define STIPPLE_HEIGHT 2
105 static char STIPPLE_DATA
[] = {0x02, 0x01};
107 static int CantManageScreen
= 0;
109 static WMPropList
*dApplications
= NULL
;
110 static WMPropList
*dWorkspace
;
111 static WMPropList
*dDock
;
112 static WMPropList
*dClip
;
118 if (dApplications
!=NULL
)
121 dApplications
= WMCreatePLString("Applications");
122 dWorkspace
= WMCreatePLString("Workspace");
123 dDock
= WMCreatePLString("Dock");
124 dClip
= WMCreatePLString("Clip");
129 *----------------------------------------------------------------------
130 * alreadyRunningError--
131 * X error handler used to catch errors when trying to do
132 * XSelectInput() on the root window. These errors probably mean that
133 * there already is some other window manager running.
136 * Nothing, unless something really evil happens...
139 * CantManageScreen is set to 1;
140 *----------------------------------------------------------------------
143 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
145 CantManageScreen
= 1;
151 *----------------------------------------------------------------------
152 * allocButtonPixmaps--
153 * Allocate pixmaps used on window operation buttons (those in the
154 * titlebar). The pixmaps are linked to the program. If XPM is supported
155 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
161 * Allocates shared pixmaps for the screen. These pixmaps should
162 * not be freed by anybody.
163 *----------------------------------------------------------------------
166 allocButtonPixmaps(WScreen
*scr
)
170 /* create predefined pixmaps */
171 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
174 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
176 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
179 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
181 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
184 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
185 #ifdef XKB_BUTTON_HINT
186 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
189 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
190 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
193 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
194 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
197 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
198 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
201 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
205 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
208 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
213 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
215 XSetForeground(dpy
, gc
, scr
->black_pixel
);
216 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
217 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
218 XSetForeground(dpy
, gc
, scr
->white_pixel
);
219 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
220 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
225 make3Dots(WScreen
*scr
)
233 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
234 wPreferences
.icon_size
, scr
->w_depth
);
235 XSetForeground(dpy
, gc
, scr
->black_pixel
);
236 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
237 wPreferences
.icon_size
);
238 XSetForeground(dpy
, gc
, scr
->white_pixel
);
239 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
240 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
241 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
243 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
244 wPreferences
.icon_size
, 1);
246 gcv
.graphics_exposures
= False
;
247 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
248 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
249 wPreferences
.icon_size
);
250 XSetForeground(dpy
, gc2
, 1);
251 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
252 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
253 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
257 wpix
= wPixmapCreate(scr
, pix
, mask
);
265 allocGCs(WScreen
*scr
)
271 scr
->stipple_bitmap
=
272 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
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
);
283 /* selected icon border GCs */
284 gcv
.function
= GXcopy
;
285 gcv
.foreground
= scr
->white_pixel
;
286 gcv
.background
= scr
->black_pixel
;
288 gcv
.line_style
= LineDoubleDash
;
289 gcv
.fill_style
= FillSolid
;
292 gcv
.graphics_exposures
= False
;
294 gcm
= GCFunction
| GCGraphicsExposures
;
295 gcm
|= GCForeground
| GCBackground
;
296 gcm
|= GCLineWidth
| GCLineStyle
;
298 gcm
|= GCDashOffset
| GCDashList
;
300 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
302 scr
->menu_title_color
[0] = WMRetainColor(scr
->white
);
304 /* don't retain scr->black here because we may alter its alpha */
305 scr
->mtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
306 scr
->dtext_color
= WMCreateRGBColor(scr
->wmscreen
, 0, 0, 0, True
);
309 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
310 gcv
.function
= GXxor
;
311 /* this will raise the probability of the XORed color being different
312 * of the original color in PseudoColor when not all color cells are
314 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
315 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
317 gcv
.plane_mask
= AllPlanes
;
318 gcv
.foreground
= color
.pixel
;
319 if (gcv
.foreground
== 0)
321 gcv
.line_width
= DEF_FRAME_THICKNESS
;
322 gcv
.subwindow_mode
= IncludeInferiors
;
323 gcv
.graphics_exposures
= False
;
324 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
325 |GCFunction
|GCSubwindowMode
|GCLineWidth
329 gcv
.foreground
= color
.pixel
;
331 if (gcv
.foreground
== 0)
332 /* XOR:ing with a zero is not going to be of much use, so
333 in that case, we somewhat arbitrarily xor with 17 instead. */
336 gcv
.function
= GXxor
;
337 gcv
.subwindow_mode
= IncludeInferiors
;
339 gcv
.cap_style
= CapRound
;
340 gcv
.graphics_exposures
= False
;
341 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
342 |GCGraphicsExposures
;
343 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
345 scr
->line_pixel
= gcv
.foreground
;
348 gcv
.foreground
= scr
->white_pixel
;
349 gcv
.background
= scr
->black_pixel
;
350 gcv
.graphics_exposures
= False
;
351 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
352 |GCGraphicsExposures
, &gcv
);
354 /* misc drawing GC */
355 gcv
.graphics_exposures
= False
;
356 gcm
= GCGraphicsExposures
;
357 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
359 assert (scr
->stipple_bitmap
!=None
);
363 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
369 createPixmaps(WScreen
*scr
)
375 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
376 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
377 MENU_RADIO_INDICATOR_XBM_SIZE
,
378 MENU_RADIO_INDICATOR_XBM_SIZE
,
379 scr
->black_pixel
, scr
->white_pixel
);
382 scr
->menu_radio_indicator
= pix
;
385 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
386 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
387 MENU_CHECK_INDICATOR_XBM_SIZE
,
388 MENU_CHECK_INDICATOR_XBM_SIZE
,
389 scr
->black_pixel
, scr
->white_pixel
);
392 scr
->menu_check_indicator
= pix
;
394 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
395 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
396 MENU_MINI_INDICATOR_XBM_SIZE
,
397 MENU_MINI_INDICATOR_XBM_SIZE
,
398 scr
->black_pixel
, scr
->white_pixel
);
401 scr
->menu_mini_indicator
= pix
;
403 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
404 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
405 MENU_HIDE_INDICATOR_XBM_SIZE
,
406 MENU_HIDE_INDICATOR_XBM_SIZE
,
407 scr
->black_pixel
, scr
->white_pixel
);
410 scr
->menu_hide_indicator
= pix
;
412 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
413 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
414 MENU_SHADE_INDICATOR_XBM_SIZE
,
415 MENU_SHADE_INDICATOR_XBM_SIZE
,
416 scr
->black_pixel
, scr
->white_pixel
);
419 scr
->menu_shade_indicator
= pix
;
422 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
425 wwarning(_("could not load logo image for panels: %s"),
426 RMessageForError(RErrorCode
));
428 WMSetApplicationIconImage(scr
->wmscreen
, image
);
429 RReleaseImage(image
);
432 scr
->dock_dots
= make3Dots(scr
);
434 /* titlebar button pixmaps */
435 allocButtonPixmaps(scr
);
440 *----------------------------------------------------------------------
441 * createInternalWindows--
442 * Creates some windows used internally by the program. One to
443 * receive input focus when no other window can get it and another
444 * to display window geometry information during window resize/move.
450 * Windows are created and some colors are allocated for the
452 *----------------------------------------------------------------------
455 createInternalWindows(WScreen
*scr
)
458 XSetWindowAttributes attribs
;
460 /* InputOnly window to get the focus when no other window can get it */
461 vmask
= CWEventMask
|CWOverrideRedirect
;
462 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
463 attribs
.override_redirect
= True
;
464 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
465 InputOnly
,CopyFromParent
, vmask
, &attribs
);
466 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
467 XMapWindow(dpy
, scr
->no_focus_win
);
469 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
471 /* shadow window for dock buttons */
472 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
473 attribs
.border_pixel
= scr
->black_pixel
;
474 attribs
.save_under
= True
;
475 attribs
.override_redirect
= True
;
476 attribs
.background_pixmap
= None
;
477 attribs
.background_pixel
= scr
->white_pixel
;
478 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
480 attribs
.colormap
= scr
->w_colormap
;
482 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
483 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
484 scr
->w_visual
, vmask
, &attribs
);
486 /* workspace name balloon for clip */
487 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
489 attribs
.save_under
= True
;
490 attribs
.override_redirect
= True
;
491 attribs
.colormap
= scr
->w_colormap
;
492 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
493 attribs
.border_pixel
= 0; /* do not care */
495 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
496 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
500 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
502 attribs
.save_under
= True
;
503 attribs
.override_redirect
= True
;
504 attribs
.colormap
= scr
->w_colormap
;
505 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
506 attribs
.border_pixel
= 0; /* do not care */
507 scr
->workspace_name
=
508 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
509 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
512 * If the window is clicked without having ButtonPress selected, the
513 * resulting event will have event.xbutton.window == root.
515 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
521 aquireManagerSelection(WScreen
*scr
)
527 snprintf(buffer
, sizeof(buffer
), "WM_S%i", scr
->screen
);
528 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
530 /* for race-conditions... */
533 /* if there is another manager running, don't try to replace it
534 * (for now, at least) */
535 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
540 /* become the manager for this screen */
542 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
545 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
546 /* get a timestamp */
547 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
548 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
550 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
551 if (ev
.type
== PropertyNotify
) {
552 timestamp
= ev
.xproperty
.time
;
556 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
557 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
559 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
563 /* announce our arrival */
565 ev
.xclient
.type
= ClientMessage
;
566 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
567 ev
.xclient
.destination
= scr
->root_win
;
568 ev
.xclient
.format
= 32;
569 ev
.xclient
.data
.l
[0] = timestamp
;
570 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
571 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
572 ev
.xclient
.data
.l
[3] = 0;
573 ev
.xclient
.data
.l
[4] = 0;
575 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
583 *----------------------------------------------------------------------
585 * Initializes the window manager for the given screen and
586 * allocates a WScreen descriptor for it. Many resources are allocated
587 * for the screen and the root window is setup appropriately.
590 * The WScreen descriptor for the screen.
593 * Many resources are allocated and the IconSize property is
594 * set on the root window.
595 * The program can be aborted if some fatal error occurs.
597 * TODO: User specifiable visual.
598 *----------------------------------------------------------------------
601 wScreenInit(int screen_number
)
604 XIconSize icon_size
[1];
605 RContextAttributes rattr
;
606 extern int wVisualID
;
608 XErrorHandler oldHandler
;
610 scr
= wmalloc(sizeof(WScreen
));
611 memset(scr
, 0, sizeof(WScreen
));
613 scr
->stacking_list
= WMCreateTreeBag();
615 /* initialize globals */
616 scr
->screen
= screen_number
;
617 scr
->root_win
= RootWindow(dpy
, screen_number
);
618 scr
->depth
= DefaultDepth(dpy
, screen_number
);
619 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
621 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
622 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
624 scr
->usableArea
.x2
= scr
->scr_width
;
625 scr
->usableArea
.y2
= scr
->scr_height
;
626 scr
->totalUsableArea
.x2
= scr
->scr_width
;
627 scr
->totalUsableArea
.y2
= scr
->scr_height
;
629 scr
->fakeGroupLeaders
= WMCreateArray(16);
632 if (!aquireManagerSelection(scr
)) {
638 CantManageScreen
= 0;
639 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
641 event_mask
= EVENT_MASK
;
643 if (wPreferences
.disable_root_mouse
) {
644 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
647 XSelectInput(dpy
, scr
->root_win
, event_mask
);
649 #ifdef KEEP_XKB_LOCK_STATUS
650 /* Only GroupLock doesn't work correctly in my system since right-alt
651 * can change mode while holding it too - ]d
654 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
658 #endif /* KEEP_XKB_LOCK_STATUS */
661 XSetErrorHandler(oldHandler
);
663 if (CantManageScreen
) {
670 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
672 /* screen descriptor for raster graphic library */
673 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
674 rattr
.render_mode
= wPreferences
.no_dithering
675 ? RBestMatchRendering
676 : RDitheredRendering
;
678 /* if the std colormap stuff works ok, this will be ignored */
679 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
680 if (rattr
.colors_per_channel
<2)
681 rattr
.colors_per_channel
= 2;
684 /* will only be accounted for in PseudoColor */
685 if (wPreferences
.flags
.create_stdcmap
) {
686 rattr
.standard_colormap_mode
= RCreateStdColormap
;
688 rattr
.standard_colormap_mode
= RUseStdColormap
;
692 rattr
.flags
|= RC_VisualID
;
693 rattr
.visualid
= wVisualID
;
696 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
698 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
699 wwarning(RMessageForError(RErrorCode
));
701 rattr
.flags
&= ~RC_StandardColormap
;
702 rattr
.standard_colormap_mode
= RUseStdColormap
;
704 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
707 if (!scr
->rcontext
) {
708 wwarning(_("could not initialize graphics library context: %s"),
709 RMessageForError(RErrorCode
));
715 formats
= RSupportedFileFormats();
717 for (i
=0; formats
[i
]!=NULL
; i
++) {
718 if (strcmp(formats
[i
], "TIFF")==0) {
719 scr
->flags
.supports_tiff
= 1;
726 scr
->w_win
= scr
->rcontext
->drawable
;
727 scr
->w_visual
= scr
->rcontext
->visual
;
728 scr
->w_depth
= scr
->rcontext
->depth
;
729 scr
->w_colormap
= scr
->rcontext
->cmap
;
731 /* create screen descriptor for WINGs */
732 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
735 if (!scr
->wmscreen
) {
736 wfatal(_("could not initialize WINGs widget set"));
740 scr
->black
= WMBlackColor(scr
->wmscreen
);
741 scr
->white
= WMWhiteColor(scr
->wmscreen
);
742 scr
->gray
= WMGrayColor(scr
->wmscreen
);
743 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
745 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black;*/
746 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white;*/
747 scr
->light_pixel
= WMColorPixel(scr
->gray
);
748 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
752 /* frame boder color */
753 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
754 scr
->frame_border_pixel
= xcol
.pixel
;
757 /* create GCs with default values */
760 /* for our window manager info notice board. Need to
761 * create before reading the defaults, because it will be used there.
763 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
766 /* read defaults for this screen */
767 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
769 createInternalWindows(scr
);
776 wGNOMEInitStuff(scr
);
783 /* create initial workspace */
786 /* create shared pixmaps */
789 /* set icon sizes we can accept from clients */
790 icon_size
[0].min_width
= 8;
791 icon_size
[0].min_height
= 8;
792 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
793 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
794 icon_size
[0].width_inc
= 1;
795 icon_size
[0].height_inc
= 1;
796 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
798 /* setup WindowMaker protocols property in the root window*/
799 PropSetWMakerProtocols(scr
->root_win
);
801 /* setup our noticeboard */
802 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
803 XA_WINDOW
, 32, PropModeReplace
,
804 (unsigned char*)&scr
->info_window
, 1);
805 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
806 XA_WINDOW
, 32, PropModeReplace
,
807 (unsigned char*)&scr
->info_window
, 1);
811 /* initialize balloon text stuff */
812 wBalloonInitialize(scr
);
815 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
817 scr
->tech_draw_font
= WMCreateFontWithFlags(scr
->wmscreen
,
821 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
822 WMRealizeWidget(scr
->gview
);
824 wScreenUpdateUsableArea(scr
);
832 wScreenUpdateUsableArea(WScreen
*scr
)
834 scr
->totalUsableArea
= scr
->usableArea
;
837 if (scr
->dock
&& (!scr
->dock
->lowered
838 || wPreferences
.no_window_over_dock
)) {
840 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
842 if (scr
->dock
->on_right_side
) {
843 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
844 scr
->scr_width
- offset
);
846 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
850 if (wPreferences
.no_window_over_icons
) {
851 if (wPreferences
.icon_yard
& IY_VERT
) {
853 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
854 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
856 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
860 if (wPreferences
.icon_yard
& IY_TOP
) {
861 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
863 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
872 if (wKWMGetUsableArea(scr
, &area
)) {
873 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
874 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
875 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
876 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
882 area
= scr
->reservedAreas
;
889 w
= area
->area
.x2
- area
->area
.x1
;
890 h
= area
->area
.y2
- area
->area
.y1
;
893 bh
= scr
->scr_height
- area
->area
.y2
;
895 rw
= scr
->scr_width
- area
->area
.x2
;
897 if (WMIN(th
, bh
) <= WMIN(lw
, rw
)) {
901 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
902 scr
->totalUsableArea
.y1
= area
->area
.y2
;
905 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
906 scr
->totalUsableArea
.y2
= area
->area
.y1
;
912 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
913 scr
->totalUsableArea
.x1
= area
->area
.x2
;
916 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
917 scr
->totalUsableArea
.x2
= area
->area
.x1
;
923 #endif /* GNOME_STUFF */
925 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
926 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
927 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
929 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
930 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
931 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
939 for (i
= 0; i
< scr
->workspace_count
; i
++) {
940 wKWMSetUsableAreaHint(scr
, i
);
947 unsigned size
= wPreferences
.workspace_border_size
;
948 unsigned position
= wPreferences
.workspace_border_position
;
950 if (size
>0 && position
!=WB_NONE
) {
951 if (position
& WB_LEFTRIGHT
) {
952 scr
->totalUsableArea
.x1
+= size
;
953 scr
->totalUsableArea
.x2
-= size
;
955 if (position
& WB_TOPBOTTOM
) {
956 scr
->totalUsableArea
.y1
+= size
;
957 scr
->totalUsableArea
.y2
-= size
;
966 wScreenRestoreState(WScreen
*scr
)
973 OpenRootMenu(scr
, -10000, -10000, False
);
974 wMenuUnmap(scr
->root_menu
);
979 if (wScreenCount
== 1) {
980 path
= wdefaultspathfordomain("WMState");
983 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
984 path
= wdefaultspathfordomain(buf
);
986 scr
->session_state
= WMReadPropListFromFile(path
);
988 if (!scr
->session_state
&& wScreenCount
>1) {
989 path
= wdefaultspathfordomain("WMState");
990 scr
->session_state
= WMReadPropListFromFile(path
);
994 if (!wPreferences
.flags
.noclip
&& scr
->session_state
) {
995 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
996 scr
->clip_icon
= wClipRestoreState(scr
, state
);
999 wWorkspaceRestoreState(scr
);
1001 #ifdef VIRTUAL_DESKTOP
1003 * * create inputonly windows at the border of screen
1005 wWorkspaceManageEdge(scr
);
1008 if (!wPreferences
.flags
.nodock
&& scr
->session_state
) {
1009 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1010 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1013 wScreenUpdateUsableArea(scr
);
1018 wScreenSaveState(WScreen
*scr
)
1022 WMPropList
*old_state
, *foo
;
1028 /* Save current workspace, so can go back to it upon restart. */
1029 data
[0] = scr
->current_workspace
;
1030 data
[1] = WFLAGS_NONE
;
1032 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1033 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1034 (unsigned char *) data
, 2);
1036 /* save state of windows */
1037 wwin
= scr
->focused_window
;
1039 wWindowSaveState(wwin
);
1044 if (wPreferences
.flags
.noupdates
)
1048 old_state
= scr
->session_state
;
1049 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
1051 WMPLSetCaseSensitive(True
);
1053 /* save dock state to file */
1054 if (!wPreferences
.flags
.nodock
) {
1055 wDockSaveState(scr
, old_state
);
1057 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1058 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1061 if (!wPreferences
.flags
.noclip
) {
1062 wClipSaveState(scr
);
1064 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1065 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1069 wWorkspaceSaveState(scr
, old_state
);
1071 if (wPreferences
.save_session_on_exit
) {
1072 wSessionSaveState(scr
);
1074 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1075 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1077 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1078 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1083 WMPLSetCaseSensitive(False
);
1085 wMenuSaveState(scr
);
1087 if (wScreenCount
== 1)
1088 str
= wdefaultspathfordomain("WMState");
1091 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1092 str
= wdefaultspathfordomain(buf
);
1094 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1095 wsyserror(_("could not save session state in %s"), str
);
1098 WMReleasePropList(old_state
);
1104 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1109 * With respect to the head that contains most of the window.
1111 int sx1
, sy1
, sx2
, sy2
;
1118 rect
.size
.width
= width
;
1119 rect
.size
.height
= height
;
1121 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1122 rect
= wGetRectForHead(scr
, head
);
1126 sx2
= sx1
+ rect
.size
.width
;
1127 sy2
= sy1
+ rect
.size
.height
;
1129 #if 0 /* NOTE: gives funky group movement */
1130 if (flags
& XFLAG_MULTIPLE
) {
1132 * since we span multiple heads, pull window totaly inside
1135 *x
= sx1
, moved
= 1;
1136 else if (*x
+ width
> sx2
)
1137 *x
= sx2
- width
, moved
= 1;
1140 *y
= sy1
, moved
= 1;
1141 else if (*y
+ height
> sy2
)
1142 *y
= sy2
- height
, moved
= 1;
1158 if (*x
+ width
< sx1
+ 10)
1159 *x
= sx1
- tol_w
, moved
= 1;
1160 else if (*x
>= sx2
- 10)
1161 *x
= sx2
- tol_w
- 1, moved
= 1;
1163 if (*y
< sy1
- height
+ 10)
1164 *y
= sy1
- tol_h
, moved
= 1;
1165 else if (*y
>= sy2
- 10)
1166 *y
= sy2
- tol_h
- 1, moved
= 1;
1174 wScreenKeepInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1177 int sx1
, sy1
, sx2
, sy2
;
1183 rect
.size
.width
= width
;
1184 rect
.size
.height
= height
;
1186 head
= wGetHeadForRect(scr
, rect
);
1187 rect
= wGetRectForHead(scr
, head
);
1191 sx2
= sx1
+ rect
.size
.width
;
1192 sy2
= sy1
+ rect
.size
.height
;
1195 *x
= sx1
, moved
= 1;
1196 else if (*x
+ width
> sx2
)
1197 *x
= sx2
- width
, moved
= 1;
1200 *y
= sy1
, moved
= 1;
1201 else if (*y
+ height
> sy2
)
1202 *y
= sy2
- height
, moved
= 1;