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"
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
;
611 scr
= wmalloc(sizeof(WScreen
));
612 memset(scr
, 0, sizeof(WScreen
));
614 scr
->stacking_list
= WMCreateTreeBag();
616 /* initialize globals */
617 scr
->screen
= screen_number
;
618 scr
->root_win
= RootWindow(dpy
, screen_number
);
619 scr
->depth
= DefaultDepth(dpy
, screen_number
);
620 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
622 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
623 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
627 scr
->usableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
628 scr
->totalUsableArea
= (WArea
*)wmalloc(sizeof(WArea
)*wXineramaHeads(scr
));
630 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
631 WMRect rect
= wGetRectForHead(scr
, i
);
632 scr
->usableArea
[i
].x1
= scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
633 scr
->usableArea
[i
].y1
= scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
634 scr
->usableArea
[i
].x2
= scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
635 scr
->usableArea
[i
].y2
= scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
638 scr
->fakeGroupLeaders
= WMCreateArray(16);
641 if (!aquireManagerSelection(scr
)) {
647 CantManageScreen
= 0;
648 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
650 event_mask
= EVENT_MASK
;
652 if (wPreferences
.disable_root_mouse
) {
653 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
656 XSelectInput(dpy
, scr
->root_win
, event_mask
);
658 #ifdef KEEP_XKB_LOCK_STATUS
659 /* Only GroupLock doesn't work correctly in my system since right-alt
660 * can change mode while holding it too - ]d
663 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
667 #endif /* KEEP_XKB_LOCK_STATUS */
670 XSetErrorHandler(oldHandler
);
672 if (CantManageScreen
) {
677 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_ROOT
]);
679 /* screen descriptor for raster graphic library */
680 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
681 rattr
.render_mode
= wPreferences
.no_dithering
682 ? RBestMatchRendering
683 : RDitheredRendering
;
685 /* if the std colormap stuff works ok, this will be ignored */
686 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
687 if (rattr
.colors_per_channel
<2)
688 rattr
.colors_per_channel
= 2;
691 /* will only be accounted for in PseudoColor */
692 if (wPreferences
.flags
.create_stdcmap
) {
693 rattr
.standard_colormap_mode
= RCreateStdColormap
;
695 rattr
.standard_colormap_mode
= RUseStdColormap
;
699 rattr
.flags
|= RC_VisualID
;
700 rattr
.visualid
= wVisualID
;
703 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
705 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
706 wwarning(RMessageForError(RErrorCode
));
708 rattr
.flags
&= ~RC_StandardColormap
;
709 rattr
.standard_colormap_mode
= RUseStdColormap
;
711 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
714 if (!scr
->rcontext
) {
715 wwarning(_("could not initialize graphics library context: %s"),
716 RMessageForError(RErrorCode
));
722 formats
= RSupportedFileFormats();
724 for (i
=0; formats
[i
]!=NULL
; i
++) {
725 if (strcmp(formats
[i
], "TIFF")==0) {
726 scr
->flags
.supports_tiff
= 1;
733 scr
->w_win
= scr
->rcontext
->drawable
;
734 scr
->w_visual
= scr
->rcontext
->visual
;
735 scr
->w_depth
= scr
->rcontext
->depth
;
736 scr
->w_colormap
= scr
->rcontext
->cmap
;
738 /* create screen descriptor for WINGs */
739 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
742 if (!scr
->wmscreen
) {
743 wfatal(_("could not initialize WINGs widget set"));
747 scr
->black
= WMBlackColor(scr
->wmscreen
);
748 scr
->white
= WMWhiteColor(scr
->wmscreen
);
749 scr
->gray
= WMGrayColor(scr
->wmscreen
);
750 scr
->darkGray
= WMDarkGrayColor(scr
->wmscreen
);
752 scr
->black_pixel
= WMColorPixel(scr
->black
); /*scr->rcontext->black;*/
753 scr
->white_pixel
= WMColorPixel(scr
->white
); /*scr->rcontext->white;*/
754 scr
->light_pixel
= WMColorPixel(scr
->gray
);
755 scr
->dark_pixel
= WMColorPixel(scr
->darkGray
);
759 /* frame boder color */
760 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
761 scr
->frame_border_pixel
= xcol
.pixel
;
764 /* create GCs with default values */
767 /* for our window manager info notice board. Need to
768 * create before reading the defaults, because it will be used there.
770 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
773 /* read defaults for this screen */
774 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
776 createInternalWindows(scr
);
783 wGNOMEInitStuff(scr
);
790 /* create initial workspace */
793 /* create shared pixmaps */
796 /* set icon sizes we can accept from clients */
797 icon_size
[0].min_width
= 8;
798 icon_size
[0].min_height
= 8;
799 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
800 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
801 icon_size
[0].width_inc
= 1;
802 icon_size
[0].height_inc
= 1;
803 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
805 /* setup WindowMaker protocols property in the root window*/
806 PropSetWMakerProtocols(scr
->root_win
);
808 /* setup our noticeboard */
809 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
810 XA_WINDOW
, 32, PropModeReplace
,
811 (unsigned char*)&scr
->info_window
, 1);
812 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
813 XA_WINDOW
, 32, PropModeReplace
,
814 (unsigned char*)&scr
->info_window
, 1);
818 /* initialize balloon text stuff */
819 wBalloonInitialize(scr
);
822 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
824 scr
->tech_draw_font
= WMCreateFontWithFlags(scr
->wmscreen
,
828 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
829 WMRealizeWidget(scr
->gview
);
831 wScreenUpdateUsableArea(scr
);
838 wScreenUpdateUsableArea(WScreen
*scr
)
841 * scr->totalUsableArea[] will become the usableArea used for Windowplacement,
842 * scr->usableArea[] will be used for iconplacement, hence no iconyard nor
847 unsigned long best_area
= 0, tmp_area
;
849 int dock_head
= scr
->xine_info
.primary_head
;
853 rect
.pos
.x
= scr
->dock
->x_pos
;
854 rect
.pos
.y
= scr
->dock
->y_pos
;
855 rect
.size
.width
= wPreferences
.icon_size
;
856 rect
.size
.height
= wPreferences
.icon_size
;
857 dock_head
= wGetHeadForRect(scr
, rect
);
860 for (i
=0; i
<wXineramaHeads(scr
); ++i
) {
861 WMRect rect
= wGetRectForHead(scr
, i
);
862 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
863 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
864 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
865 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
867 if (scr
->dock
&& dock_head
==i
&&
868 (!scr
->dock
->lowered
|| wPreferences
.no_window_over_dock
)) {
869 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
871 if (scr
->dock
->on_right_side
) {
872 scr
->totalUsableArea
[i
].x2
-= offset
;
874 scr
->totalUsableArea
[i
].x1
+= offset
;
881 if (wNETWMGetUsableArea(scr
, i
, &area
)) {
882 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
883 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
884 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
885 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
893 if (wGNOMEGetUsableArea(scr
, i
, &area
)) {
894 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
895 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
896 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
897 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
905 if (wKWMGetUsableArea(scr
, i
, &area
)) {
906 scr
->totalUsableArea
[i
].x1
= WMAX(scr
->totalUsableArea
[i
].x1
, area
.x1
);
907 scr
->totalUsableArea
[i
].y1
= WMAX(scr
->totalUsableArea
[i
].y1
, area
.y1
);
908 scr
->totalUsableArea
[i
].x2
= WMIN(scr
->totalUsableArea
[i
].x2
, area
.x2
);
909 scr
->totalUsableArea
[i
].y2
= WMIN(scr
->totalUsableArea
[i
].y2
, area
.y2
);
914 scr
->usableArea
[i
] = scr
->totalUsableArea
[i
];
917 printf("usableArea[%d]: %d %d %d %d\n", i
,
918 scr
->usableArea
[i
].x1
, scr
->usableArea
[i
].x2
,
919 scr
->usableArea
[i
].y1
, scr
->usableArea
[i
].y2
);
922 if (wPreferences
.no_window_over_icons
) {
923 if (wPreferences
.icon_yard
& IY_VERT
) {
924 if (wPreferences
.icon_yard
& IY_RIGHT
) {
925 scr
->totalUsableArea
[i
].x2
-= wPreferences
.icon_size
;
927 scr
->totalUsableArea
[i
].x1
+= wPreferences
.icon_size
;
930 if (wPreferences
.icon_yard
& IY_TOP
) {
931 scr
->totalUsableArea
[i
].y1
+= wPreferences
.icon_size
;
933 scr
->totalUsableArea
[i
].y2
-= wPreferences
.icon_size
;
938 if (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
< rect
.size
.width
/2) {
939 scr
->totalUsableArea
[i
].x1
= rect
.pos
.x
;
940 scr
->totalUsableArea
[i
].x2
= rect
.pos
.x
+ rect
.size
.width
;
943 if (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
< rect
.size
.height
/2) {
944 scr
->totalUsableArea
[i
].y1
= rect
.pos
.y
;
945 scr
->totalUsableArea
[i
].y2
= rect
.pos
.y
+ rect
.size
.height
;
948 tmp_area
= (scr
->totalUsableArea
[i
].x2
- scr
->totalUsableArea
[i
].x1
) *
949 (scr
->totalUsableArea
[i
].y2
- scr
->totalUsableArea
[i
].y1
);
951 if (tmp_area
> best_area
) {
952 best_area
= tmp_area
;
953 area
= scr
->totalUsableArea
[i
];
957 unsigned size
= wPreferences
.workspace_border_size
;
958 unsigned position
= wPreferences
.workspace_border_position
;
960 if (size
>0 && position
!=WB_NONE
) {
961 if (position
& WB_LEFTRIGHT
) {
962 scr
->totalUsableArea
[i
].x1
+= size
;
963 scr
->totalUsableArea
[i
].x2
-= size
;
965 if (position
& WB_TOPBOTTOM
) {
966 scr
->totalUsableArea
[i
].y1
+= size
;
967 scr
->totalUsableArea
[i
].y2
-= size
;
974 wNETWMUpdateWorkarea(scr
, area
);
977 if (wPreferences
.auto_arrange_icons
) {
978 wArrangeIcons(scr
, True
);
984 wScreenUpdateUsableArea(WScreen
*scr
)
986 scr
->totalUsableArea
= scr
->usableArea
;
988 if (scr
->dock
&& (!scr
->dock
->lowered
989 || wPreferences
.no_window_over_dock
)) {
991 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
993 if (scr
->dock
->on_right_side
) {
994 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
995 scr
->scr_width
- offset
);
997 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
1001 if (wPreferences
.no_window_over_icons
) {
1002 if (wPreferences
.icon_yard
& IY_VERT
) {
1004 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
1005 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
1007 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
1011 if (wPreferences
.icon_yard
& IY_TOP
) {
1012 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
1014 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
1023 if (wKWMGetUsableArea(scr
, &area
)) {
1024 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
1025 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
1026 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
1027 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
1034 WReservedArea
*area
= scr
->reservedAreas
;
1041 w
= area
->area
.x2
- area
->area
.x1
;
1042 h
= area
->area
.y2
- area
->area
.y1
;
1045 bh
= scr
->scr_height
- area
->area
.y2
;
1047 rw
= scr
->scr_width
- area
->area
.x2
;
1049 if (WMIN(th
, bh
) <= WMIN(lw
, rw
)) {
1053 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
1054 scr
->totalUsableArea
.y1
= area
->area
.y2
;
1057 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
1058 scr
->totalUsableArea
.y2
= area
->area
.y1
;
1064 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
1065 scr
->totalUsableArea
.x1
= area
->area
.x2
;
1068 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
1069 scr
->totalUsableArea
.x2
= area
->area
.x1
;
1076 #endif /* GNOME_STUFF */
1078 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
1079 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
1080 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
1082 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
1083 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
1084 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
1092 for (i
= 0; i
< scr
->workspace_count
; i
++) {
1093 wKWMSetUsableAreaHint(scr
, i
);
1100 unsigned size
= wPreferences
.workspace_border_size
;
1101 unsigned position
= wPreferences
.workspace_border_position
;
1103 if (size
>0 && position
!=WB_NONE
) {
1104 if (position
& WB_LEFTRIGHT
) {
1105 scr
->totalUsableArea
.x1
+= size
;
1106 scr
->totalUsableArea
.x2
-= size
;
1108 if (position
& WB_TOPBOTTOM
) {
1109 scr
->totalUsableArea
.y1
+= size
;
1110 scr
->totalUsableArea
.y2
-= size
;
1115 if (wPreferences
.auto_arrange_icons
) {
1116 wArrangeIcons(scr
, True
);
1123 wScreenRestoreState(WScreen
*scr
)
1130 OpenRootMenu(scr
, -10000, -10000, False
);
1131 wMenuUnmap(scr
->root_menu
);
1136 if (wScreenCount
== 1) {
1137 path
= wdefaultspathfordomain("WMState");
1140 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1141 path
= wdefaultspathfordomain(buf
);
1143 scr
->session_state
= WMReadPropListFromFile(path
);
1145 if (!scr
->session_state
&& wScreenCount
>1) {
1146 path
= wdefaultspathfordomain("WMState");
1147 scr
->session_state
= WMReadPropListFromFile(path
);
1151 if (!wPreferences
.flags
.noclip
&& scr
->session_state
) {
1152 state
= WMGetFromPLDictionary(scr
->session_state
, dClip
);
1153 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1156 wWorkspaceRestoreState(scr
);
1158 #ifdef VIRTUAL_DESKTOP
1160 * * create inputonly windows at the border of screen
1162 wWorkspaceManageEdge(scr
);
1165 if (!wPreferences
.flags
.nodock
&& scr
->session_state
) {
1166 state
= WMGetFromPLDictionary(scr
->session_state
, dDock
);
1167 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1170 wScreenUpdateUsableArea(scr
);
1175 wScreenSaveState(WScreen
*scr
)
1179 WMPropList
*old_state
, *foo
;
1185 /* Save current workspace, so can go back to it upon restart. */
1186 data
[0] = scr
->current_workspace
;
1187 data
[1] = WFLAGS_NONE
;
1189 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1190 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1191 (unsigned char *) data
, 2);
1193 /* save state of windows */
1194 wwin
= scr
->focused_window
;
1196 wWindowSaveState(wwin
);
1201 if (wPreferences
.flags
.noupdates
)
1205 old_state
= scr
->session_state
;
1206 scr
->session_state
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
1208 WMPLSetCaseSensitive(True
);
1210 /* save dock state to file */
1211 if (!wPreferences
.flags
.nodock
) {
1212 wDockSaveState(scr
, old_state
);
1214 if ((foo
= WMGetFromPLDictionary(old_state
, dDock
))!=NULL
) {
1215 WMPutInPLDictionary(scr
->session_state
, dDock
, foo
);
1218 if (!wPreferences
.flags
.noclip
) {
1219 wClipSaveState(scr
);
1221 if ((foo
= WMGetFromPLDictionary(old_state
, dClip
))!=NULL
) {
1222 WMPutInPLDictionary(scr
->session_state
, dClip
, foo
);
1226 wWorkspaceSaveState(scr
, old_state
);
1228 if (wPreferences
.save_session_on_exit
) {
1229 wSessionSaveState(scr
);
1231 if ((foo
= WMGetFromPLDictionary(old_state
, dApplications
))!=NULL
) {
1232 WMPutInPLDictionary(scr
->session_state
, dApplications
, foo
);
1234 if ((foo
= WMGetFromPLDictionary(old_state
, dWorkspace
))!=NULL
) {
1235 WMPutInPLDictionary(scr
->session_state
, dWorkspace
, foo
);
1240 WMPLSetCaseSensitive(False
);
1242 wMenuSaveState(scr
);
1244 if (wScreenCount
== 1)
1245 str
= wdefaultspathfordomain("WMState");
1248 snprintf(buf
, sizeof(buf
), "WMState.%i", scr
->screen
);
1249 str
= wdefaultspathfordomain(buf
);
1251 if (!WMWritePropListToFile(scr
->session_state
, str
, True
)) {
1252 wsyserror(_("could not save session state in %s"), str
);
1255 WMReleasePropList(old_state
);
1261 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1266 * With respect to the head that contains most of the window.
1268 int sx1
, sy1
, sx2
, sy2
;
1275 rect
.size
.width
= width
;
1276 rect
.size
.height
= height
;
1278 head
= wGetRectPlacementInfo(scr
, rect
, &flags
);
1279 rect
= wGetRectForHead(scr
, head
);
1283 sx2
= sx1
+ rect
.size
.width
;
1284 sy2
= sy1
+ rect
.size
.height
;
1286 #if 0 /* NOTE: gives funky group movement */
1287 if (flags
& XFLAG_MULTIPLE
) {
1289 * since we span multiple heads, pull window totaly inside
1292 *x
= sx1
, moved
= 1;
1293 else if (*x
+ width
> sx2
)
1294 *x
= sx2
- width
, moved
= 1;
1297 *y
= sy1
, moved
= 1;
1298 else if (*y
+ height
> sy2
)
1299 *y
= sy2
- height
, moved
= 1;
1315 if (*x
+ width
< sx1
+ 10)
1316 *x
= sx1
- tol_w
, moved
= 1;
1317 else if (*x
>= sx2
- 10)
1318 *x
= sx2
- tol_w
- 1, moved
= 1;
1320 if (*y
< sy1
- height
+ 10)
1321 *y
= sy1
- tol_h
, moved
= 1;
1322 else if (*y
>= sy2
- 10)
1323 *y
= sy2
- tol_h
- 1, moved
= 1;
1331 wScreenKeepInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1334 int sx1
, sy1
, sx2
, sy2
;
1340 rect
.size
.width
= width
;
1341 rect
.size
.height
= height
;
1343 head
= wGetHeadForRect(scr
, rect
);
1344 rect
= wGetRectForHead(scr
, head
);
1348 sx2
= sx1
+ rect
.size
.width
;
1349 sy2
= sy1
+ rect
.size
.height
;
1352 *x
= sx1
, moved
= 1;
1353 else if (*x
+ width
> sx2
)
1354 *x
= sx2
- width
, moved
= 1;
1357 *y
= sy1
, moved
= 1;
1358 else if (*y
+ height
> sy2
)
1359 *y
= sy2
- height
, moved
= 1;