1 /* screen.c - screen management
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include <X11/Xutil.h>
31 #include <X11/Xatom.h>
33 #include <X11/extensions/shape.h>
35 #ifdef KEEP_XKB_LOCK_STATUS
36 #include <X11/XKBlib.h>
37 #endif /* KEEP_XKB_LOCK_STATUS */
41 #include "WindowMaker.h"
42 #include "def_pixmaps.h"
49 #include "properties.h"
51 #include "resources.h"
52 #include "workspace.h"
62 # include "openlook.h"
71 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
72 |SubstructureNotifyMask|PointerMotionMask \
73 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
75 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
76 |SubstructureNotifyMask|PointerMotionMask \
77 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
78 |KeyPressMask|KeyReleaseMask)
81 /**** Global variables ****/
83 extern Cursor wCursor
[WCUR_LAST
];
84 extern WPreferences wPreferences
;
85 extern Atom _XA_WINDOWMAKER_STATE
;
86 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
89 extern int wScreenCount
;
91 #ifdef KEEP_XKB_LOCK_STATUS
92 extern int wXkbSupported
;
95 extern WDDomain
*WDWindowMaker
;
100 #define STIPPLE_WIDTH 2
101 #define STIPPLE_HEIGHT 2
102 static char STIPPLE_DATA
[] = {0x02, 0x01};
104 static int CantManageScreen
= 0;
106 static proplist_t dApplications
= NULL
;
107 static proplist_t dWorkspace
;
108 static proplist_t dDock
;
109 static proplist_t dClip
;
115 if (dApplications
!=NULL
)
118 dApplications
= PLMakeString("Applications");
119 dWorkspace
= PLMakeString("Workspace");
120 dDock
= PLMakeString("Dock");
121 dClip
= PLMakeString("Clip");
126 *----------------------------------------------------------------------
127 * alreadyRunningError--
128 * X error handler used to catch errors when trying to do
129 * XSelectInput() on the root window. These errors probably mean that
130 * there already is some other window manager running.
133 * Nothing, unless something really evil happens...
136 * CantManageScreen is set to 1;
137 *----------------------------------------------------------------------
140 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
142 CantManageScreen
= 1;
148 *----------------------------------------------------------------------
149 * allocButtonPixmaps--
150 * Allocate pixmaps used on window operation buttons (those in the
151 * titlebar). The pixmaps are linked to the program. If XPM is supported
152 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
158 * Allocates shared pixmaps for the screen. These pixmaps should
159 * not be freed by anybody.
160 *----------------------------------------------------------------------
163 allocButtonPixmaps(WScreen
*scr
)
167 /* create predefined pixmaps */
168 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
171 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
173 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
176 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
178 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
181 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
182 #ifdef XKB_BUTTON_HINT
183 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
186 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
187 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
190 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
191 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
194 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
195 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
198 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
202 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
205 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
210 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
212 XSetForeground(dpy
, gc
, scr
->black_pixel
);
213 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
214 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
215 XSetForeground(dpy
, gc
, scr
->white_pixel
);
216 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
217 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
222 make3Dots(WScreen
*scr
)
230 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
231 wPreferences
.icon_size
, scr
->w_depth
);
232 XSetForeground(dpy
, gc
, scr
->black_pixel
);
233 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
234 wPreferences
.icon_size
);
235 XSetForeground(dpy
, gc
, scr
->white_pixel
);
236 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
237 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
238 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
240 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
241 wPreferences
.icon_size
, 1);
243 gcv
.graphics_exposures
= False
;
244 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
245 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
246 wPreferences
.icon_size
);
247 XSetForeground(dpy
, gc2
, 1);
248 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
249 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
250 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
254 wpix
= wPixmapCreate(scr
, pix
, mask
);
262 allocGCs(WScreen
*scr
)
266 unsigned long mtextcolor
;
269 scr
->stipple_bitmap
=
270 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
273 gcv
.stipple
= scr
->stipple_bitmap
;
274 gcv
.foreground
= scr
->white_pixel
;
275 gcv
.fill_style
= FillStippled
;
276 gcv
.graphics_exposures
= False
;
277 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
278 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
281 /* selected icon border GCs */
282 gcv
.function
= GXcopy
;
283 gcv
.foreground
= scr
->white_pixel
;
284 gcv
.background
= scr
->black_pixel
;
286 gcv
.line_style
= LineDoubleDash
;
287 gcv
.fill_style
= FillSolid
;
290 gcv
.graphics_exposures
= False
;
292 gcm
= GCFunction
| GCGraphicsExposures
;
293 gcm
|= GCForeground
| GCBackground
;
294 gcm
|= GCLineWidth
| GCLineStyle
;
296 gcm
|= GCDashOffset
| GCDashList
;
298 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
300 gcm
= GCForeground
|GCGraphicsExposures
;
302 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
303 gcv
.foreground
= scr
->white_pixel
;
304 gcv
.graphics_exposures
= False
;
305 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
307 scr
->mtext_pixel
= scr
->black_pixel
;
308 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
309 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
311 /* selected menu entry GC */
312 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
313 gcv
.foreground
= scr
->white_pixel
;
314 gcv
.background
= scr
->white_pixel
;
315 gcv
.graphics_exposures
= False
;
316 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
318 /* disabled menu entry GC */
319 scr
->dtext_pixel
= scr
->black_pixel
;
320 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
321 gcv
.stipple
= scr
->stipple_bitmap
;
322 gcv
.graphics_exposures
= False
;
323 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
326 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
327 gcv
.function
= GXxor
;
328 /* this will raise the probability of the XORed color being different
329 * of the original color in PseudoColor when not all color cells are
331 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
332 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
334 gcv
.plane_mask
= AllPlanes
;
335 gcv
.foreground
= color
.pixel
;
336 if (gcv
.foreground
== 0)
338 gcv
.line_width
= DEF_FRAME_THICKNESS
;
339 gcv
.subwindow_mode
= IncludeInferiors
;
340 gcv
.graphics_exposures
= False
;
341 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
342 |GCFunction
|GCSubwindowMode
|GCLineWidth
346 gcv
.foreground
= color
.pixel
;
348 if (gcv
.foreground
== 0)
349 /* XOR:ing with a zero is not going to be of much use, so
350 in that case, we somewhat arbitrarily xor with 17 instead. */
353 gcv
.function
= GXxor
;
354 gcv
.subwindow_mode
= IncludeInferiors
;
356 gcv
.cap_style
= CapRound
;
357 gcv
.graphics_exposures
= False
;
358 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
359 |GCGraphicsExposures
;
360 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
362 scr
->line_pixel
= gcv
.foreground
;
365 gcv
.foreground
= scr
->white_pixel
;
366 gcv
.background
= scr
->black_pixel
;
367 gcv
.graphics_exposures
= False
;
368 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
369 |GCGraphicsExposures
, &gcv
);
371 /* window title text GC */
372 gcv
.graphics_exposures
= False
;
373 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
376 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
379 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
381 /* move/size display GC */
382 gcv
.graphics_exposures
= False
;
383 gcm
= GCGraphicsExposures
;
384 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
386 /* misc drawing GC */
387 gcv
.graphics_exposures
= False
;
388 gcm
= GCGraphicsExposures
;
389 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
391 assert (scr
->stipple_bitmap
!=None
);
395 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
401 createPixmaps(WScreen
*scr
)
409 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
410 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
411 MENU_RADIO_INDICATOR_XBM_SIZE
,
412 MENU_RADIO_INDICATOR_XBM_SIZE
,
413 scr
->black_pixel
, scr
->white_pixel
);
416 scr
->menu_radio_indicator
= pix
;
419 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
420 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
421 MENU_CHECK_INDICATOR_XBM_SIZE
,
422 MENU_CHECK_INDICATOR_XBM_SIZE
,
423 scr
->black_pixel
, scr
->white_pixel
);
426 scr
->menu_check_indicator
= pix
;
428 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
429 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
430 MENU_MINI_INDICATOR_XBM_SIZE
,
431 MENU_MINI_INDICATOR_XBM_SIZE
,
432 scr
->black_pixel
, scr
->white_pixel
);
435 scr
->menu_mini_indicator
= pix
;
437 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
438 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
439 MENU_HIDE_INDICATOR_XBM_SIZE
,
440 MENU_HIDE_INDICATOR_XBM_SIZE
,
441 scr
->black_pixel
, scr
->white_pixel
);
444 scr
->menu_hide_indicator
= pix
;
446 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
447 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
448 MENU_SHADE_INDICATOR_XBM_SIZE
,
449 MENU_SHADE_INDICATOR_XBM_SIZE
,
450 scr
->black_pixel
, scr
->white_pixel
);
453 scr
->menu_shade_indicator
= pix
;
456 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
459 wwarning(_("could not load logo image for panels: %s"),
460 RMessageForError(RErrorCode
));
462 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
463 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
465 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
466 image
->width
, image
->height
,
468 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
469 WMReleasePixmap(wmpix
);
471 RDestroyImage(image
);
474 scr
->dock_dots
= make3Dots(scr
);
476 /* titlebar button pixmaps */
477 allocButtonPixmaps(scr
);
482 *----------------------------------------------------------------------
483 * createInternalWindows--
484 * Creates some windows used internally by the program. One to
485 * receive input focus when no other window can get it and another
486 * to display window geometry information during window resize/move.
492 * Windows are created and some colors are allocated for the
494 *----------------------------------------------------------------------
497 createInternalWindows(WScreen
*scr
)
500 XSetWindowAttributes attribs
;
502 /* window for displaying geometry information during resizes and moves */
503 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
504 attribs
.border_pixel
= scr
->black_pixel
;
505 attribs
.save_under
= True
;
506 attribs
.override_redirect
= True
;
507 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
508 attribs
.background_pixmap
= None
;
509 if (scr
->widget_texture
)
510 attribs
.background_pixel
= scr
->widget_texture
->normal
.pixel
;
512 attribs
.background_pixel
= scr
->light_pixel
;
514 attribs
.colormap
= scr
->w_colormap
;
516 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
517 &scr
->geometry_display_height
);
518 scr
->geometry_display
=
519 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
520 scr
->geometry_display_width
,
521 scr
->geometry_display_height
,
522 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
525 /* InputOnly window to get the focus when no other window can get it */
526 vmask
= CWEventMask
|CWOverrideRedirect
;
527 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
528 attribs
.override_redirect
= True
;
529 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
530 InputOnly
,CopyFromParent
, vmask
, &attribs
);
531 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
532 XMapWindow(dpy
, scr
->no_focus_win
);
534 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
536 /* shadow window for dock buttons */
537 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
538 attribs
.border_pixel
= scr
->black_pixel
;
539 attribs
.save_under
= True
;
540 attribs
.override_redirect
= True
;
541 attribs
.background_pixmap
= None
;
542 attribs
.background_pixel
= scr
->white_pixel
;
544 attribs
.colormap
= scr
->w_colormap
;
546 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
547 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
548 scr
->w_visual
, vmask
, &attribs
);
550 /* workspace name balloon for clip */
551 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
553 attribs
.save_under
= True
;
554 attribs
.override_redirect
= True
;
555 attribs
.colormap
= scr
->w_colormap
;
556 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
557 attribs
.border_pixel
= 0; /* do not care */
559 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
560 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
564 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
566 attribs
.save_under
= True
;
567 attribs
.override_redirect
= True
;
568 attribs
.colormap
= scr
->w_colormap
;
569 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
570 attribs
.border_pixel
= 0; /* do not care */
571 scr
->workspace_name
=
572 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
573 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
576 /* for our window manager info notice board */
578 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, CopyFromParent
,
579 CopyFromParent
, CopyFromParent
, CWOverrideRedirect
,
583 * If the window is clicked without having ButtonPress selected, the
584 * resulting event will have event.xbutton.window == root.
586 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
592 aquireManagerSelection(WScreen
*scr
)
598 sprintf(buffer
, "WM_S%i", scr
->screen
);
599 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
601 /* for race-conditions... */
604 /* if there is another manager running, don't try to replace it
605 * (for now, at least) */
606 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
611 /* become the manager for this screen */
613 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
616 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
617 /* get a timestamp */
618 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
619 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
621 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
622 if (ev
.type
== PropertyNotify
) {
623 timestamp
= ev
.xproperty
.time
;
627 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
628 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
630 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
634 /* announce our arrival */
636 ev
.xclient
.type
= ClientMessage
;
637 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
638 ev
.xclient
.destination
= scr
->root_win
;
639 ev
.xclient
.format
= 32;
640 ev
.xclient
.data
.l
[0] = timestamp
;
641 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
642 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
643 ev
.xclient
.data
.l
[3] = 0;
644 ev
.xclient
.data
.l
[4] = 0;
646 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
654 *----------------------------------------------------------------------
656 * Initializes the window manager for the given screen and
657 * allocates a WScreen descriptor for it. Many resources are allocated
658 * for the screen and the root window is setup appropriately.
661 * The WScreen descriptor for the screen.
664 * Many resources are allocated and the IconSize property is
665 * set on the root window.
666 * The program can be aborted if some fatal error occurs.
668 * TODO: User specifiable visual.
669 *----------------------------------------------------------------------
672 wScreenInit(int screen_number
)
675 XIconSize icon_size
[1];
676 RContextAttributes rattr
;
677 extern int wVisualID
;
680 XErrorHandler oldHandler
;
682 scr
= wmalloc(sizeof(WScreen
));
683 memset(scr
, 0, sizeof(WScreen
));
685 /* initialize globals */
686 scr
->screen
= screen_number
;
687 scr
->root_win
= RootWindow(dpy
, screen_number
);
688 scr
->depth
= DefaultDepth(dpy
, screen_number
);
689 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
691 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
692 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
694 scr
->usableArea
.x2
= scr
->scr_width
;
695 scr
->usableArea
.y2
= scr
->scr_height
;
696 scr
->totalUsableArea
.x2
= scr
->scr_width
;
697 scr
->totalUsableArea
.y2
= scr
->scr_height
;
700 if (!aquireManagerSelection(scr
)) {
706 CantManageScreen
= 0;
707 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
709 event_mask
= EVENT_MASK
;
711 if (wPreferences
.disable_root_mouse
) {
712 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
715 XSelectInput(dpy
, scr
->root_win
, event_mask
);
717 #ifdef KEEP_XKB_LOCK_STATUS
718 /* Only GroupLock doesn't work correctly in my system since right-alt
719 * can change mode while holding it too - ]d
722 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
726 #endif /* KEEP_XKB_LOCK_STATUS */
729 XSetErrorHandler(oldHandler
);
731 if (CantManageScreen
) {
736 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
738 /* screen descriptor for raster graphic library */
739 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
740 rattr
.render_mode
= wPreferences
.no_dithering
741 ? RBestMatchRendering
742 : RDitheredRendering
;
744 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
745 if (rattr
.colors_per_channel
<2)
746 rattr
.colors_per_channel
= 2;
749 rattr
.flags
|= RC_VisualID
;
750 rattr
.visualid
= wVisualID
;
752 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
753 if (!scr
->rcontext
) {
754 wwarning(_("could not initialize graphics library context: %s"),
755 RMessageForError(RErrorCode
));
761 formats
= RSupportedFileFormats();
763 for (i
=0; formats
[i
]!=NULL
; i
++) {
764 if (strcmp(formats
[i
], "TIFF")==0) {
765 scr
->flags
.supports_tiff
= 1;
772 scr
->w_win
= scr
->rcontext
->drawable
;
773 scr
->w_visual
= scr
->rcontext
->visual
;
774 scr
->w_depth
= scr
->rcontext
->depth
;
775 scr
->w_colormap
= scr
->rcontext
->cmap
;
777 scr
->black_pixel
= scr
->rcontext
->black
;
778 scr
->white_pixel
= scr
->rcontext
->white
;
780 /* create screen descriptor for WINGs */
781 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
784 if (!scr
->wmscreen
) {
785 wfatal(_("could not do initialization of WINGs widget set"));
790 color
= WMGrayColor(scr
->wmscreen
);
791 scr
->light_pixel
= WMColorPixel(color
);
792 WMReleaseColor(color
);
794 color
= WMDarkGrayColor(scr
->wmscreen
);
795 scr
->dark_pixel
= WMColorPixel(color
);
796 WMReleaseColor(color
);
800 /* frame boder color */
801 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
802 scr
->frame_border_pixel
= xcol
.pixel
;
805 /* create GCs with default values */
808 /* read defaults for this screen */
809 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
811 createInternalWindows(scr
);
818 wGNOMEInitStuff(scr
);
825 /* create initial workspace */
828 /* create shared pixmaps */
831 /* set icon sizes we can accept from clients */
832 icon_size
[0].min_width
= 8;
833 icon_size
[0].min_height
= 8;
834 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
835 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
836 icon_size
[0].width_inc
= 1;
837 icon_size
[0].height_inc
= 1;
838 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
840 /* setup WindowMaker protocols property in the root window*/
841 PropSetWMakerProtocols(scr
->root_win
);
843 /* setup our noticeboard */
844 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
845 XA_WINDOW
, 32, PropModeReplace
,
846 (unsigned char*)&scr
->info_window
, 1);
847 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
848 XA_WINDOW
, 32, PropModeReplace
,
849 (unsigned char*)&scr
->info_window
, 1);
853 /* initialize balloon text stuff */
854 wBalloonInitialize(scr
);
857 wScreenUpdateUsableArea(scr
);
865 wScreenUpdateUsableArea(WScreen
*scr
)
871 scr
->totalUsableArea
= scr
->usableArea
;
874 if (scr
->dock
&& (!scr
->dock
->lowered
875 || wPreferences
.no_window_over_dock
)) {
877 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
879 if (scr
->dock
->on_right_side
) {
880 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
881 scr
->scr_width
- offset
);
883 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
887 if (wPreferences
.no_window_over_icons
) {
888 if (wPreferences
.icon_yard
& IY_VERT
) {
890 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
891 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
893 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
897 if (wPreferences
.icon_yard
& IY_TOP
) {
898 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
900 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
909 if (wKWMGetUsableArea(scr
, &area
)) {
910 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
911 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
912 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
913 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
919 area
= scr
->reservedAreas
;
926 w
= area
->area
.x2
- area
->area
.x1
;
927 h
= area
->area
.y2
- area
->area
.y1
;
930 bh
= scr
->scr_height
- area
->area
.y2
;
932 rw
= scr
->scr_width
- area
->area
.x2
;
934 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
938 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
939 scr
->totalUsableArea
.y1
= area
->area
.y2
;
942 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
943 scr
->totalUsableArea
.y2
= area
->area
.y1
;
949 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
950 scr
->totalUsableArea
.x1
= area
->area
.x2
;
953 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
954 scr
->totalUsableArea
.x2
= area
->area
.x1
;
960 #endif /* GNOME_STUFF */
962 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
963 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
964 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
966 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
967 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
968 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
976 for (i
= 0; i
< scr
->workspace_count
; i
++) {
977 wKWMSetUsableAreaHint(scr
, i
);
986 wScreenRestoreState(WScreen
*scr
)
993 OpenRootMenu(scr
, -10000, -10000, False
);
994 wMenuUnmap(scr
->root_menu
);
999 if (wScreenCount
== 1)
1000 path
= wdefaultspathfordomain("WMState");
1003 sprintf(buf
, "WMState.%i", scr
->screen
);
1004 path
= wdefaultspathfordomain(buf
);
1006 scr
->session_state
= PLGetProplistWithPath(path
);
1008 if (!scr
->session_state
&& wScreenCount
>1) {
1010 sprintf(buf
, "WMState.%i", scr
->screen
);
1011 path
= wdefaultspathfordomain(buf
);
1012 scr
->session_state
= PLGetProplistWithPath(path
);
1016 if (!wPreferences
.flags
.noclip
) {
1017 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
1018 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1021 wWorkspaceRestoreState(scr
);
1023 if (!wPreferences
.flags
.nodock
) {
1024 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
1025 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1028 wScreenUpdateUsableArea(scr
);
1033 wScreenSaveState(WScreen
*scr
)
1035 WWorkspaceState wstate
;
1038 proplist_t path
, old_state
, foo
;
1045 * Save current workspace, so can go back to it upon restart.
1047 wstate
.workspace
= scr
->current_workspace
;
1049 data
[0] = wstate
.flags
;
1050 data
[1] = wstate
.workspace
;
1052 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1053 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1054 (unsigned char *) data
, 2);
1056 /* save state of windows */
1057 wwin
= scr
->focused_window
;
1059 wWindowSaveState(wwin
);
1064 if (wPreferences
.flags
.noupdates
)
1068 old_state
= scr
->session_state
;
1069 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1071 PLSetStringCmpHook(NULL
);
1073 /* save dock state to file */
1074 if (!wPreferences
.flags
.nodock
) {
1075 wDockSaveState(scr
, old_state
);
1077 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1078 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1081 if (!wPreferences
.flags
.noclip
) {
1082 wClipSaveState(scr
);
1084 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1085 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1089 wWorkspaceSaveState(scr
, old_state
);
1091 if (wPreferences
.save_session_on_exit
) {
1092 wSessionSaveState(scr
);
1094 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1095 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1097 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1098 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1103 PLSetStringCmpHook(StringCompareHook
);
1105 wMenuSaveState(scr
);
1107 if (wScreenCount
== 1)
1108 str
= wdefaultspathfordomain("WMState");
1111 sprintf(buf
, "WMState.%i", scr
->screen
);
1112 str
= wdefaultspathfordomain(buf
);
1114 path
= PLMakeString(str
);
1116 PLSetFilename(scr
->session_state
, path
);
1117 if (!PLSave(scr
->session_state
, YES
)) {
1118 wsyserror(_("could not save session state in %s"), PLGetString(path
));
1121 PLRelease(old_state
);
1127 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1143 *x
= -tol_w
, moved
= 1;
1144 else if (*x
>= scr
->scr_width
- 10)
1145 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1147 if (*y
< -height
+ 10)
1148 *y
= -tol_h
, moved
= 1;
1149 else if (*y
>= scr
->scr_height
- 10)
1150 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;