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 extern WDDomain
*WDWindowMaker
;
96 #define STIPPLE_WIDTH 2
97 #define STIPPLE_HEIGHT 2
98 static char STIPPLE_DATA
[] = {0x02, 0x01};
100 static int CantManageScreen
= 0;
102 static proplist_t dApplications
= NULL
;
103 static proplist_t dWorkspace
;
104 static proplist_t dDock
;
105 static proplist_t dClip
;
111 if (dApplications
!=NULL
)
114 dApplications
= PLMakeString("Applications");
115 dWorkspace
= PLMakeString("Workspace");
116 dDock
= PLMakeString("Dock");
117 dClip
= PLMakeString("Clip");
122 *----------------------------------------------------------------------
123 * alreadyRunningError--
124 * X error handler used to catch errors when trying to do
125 * XSelectInput() on the root window. These errors probably mean that
126 * there already is some other window manager running.
129 * Nothing, unless something really evil happens...
132 * CantManageScreen is set to 1;
133 *----------------------------------------------------------------------
136 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
138 CantManageScreen
= 1;
144 *----------------------------------------------------------------------
145 * allocButtonPixmaps--
146 * Allocate pixmaps used on window operation buttons (those in the
147 * titlebar). The pixmaps are linked to the program. If XPM is supported
148 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
154 * Allocates shared pixmaps for the screen. These pixmaps should
155 * not be freed by anybody.
156 *----------------------------------------------------------------------
159 allocButtonPixmaps(WScreen
*scr
)
163 /* create predefined pixmaps */
164 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
167 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
169 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
172 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
174 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
177 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
178 #ifdef XKB_BUTTON_HINT
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_THAI_XPM
);
182 scr
->b_pixmaps
[WBUT_THAI
] = pix
;
183 pix
= wPixmapCreateFromXPMData(scr
, PRED_ENGL_XPM
);
186 scr
->b_pixmaps
[WBUT_ENGL
] = pix
;
190 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
193 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
198 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
200 XSetForeground(dpy
, gc
, scr
->black_pixel
);
201 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
202 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
203 XSetForeground(dpy
, gc
, scr
->white_pixel
);
204 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
205 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
210 make3Dots(WScreen
*scr
)
218 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
219 wPreferences
.icon_size
, scr
->w_depth
);
220 XSetForeground(dpy
, gc
, scr
->black_pixel
);
221 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
222 wPreferences
.icon_size
);
223 XSetForeground(dpy
, gc
, scr
->white_pixel
);
224 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
225 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
226 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
228 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
229 wPreferences
.icon_size
, 1);
231 gcv
.graphics_exposures
= False
;
232 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
233 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
234 wPreferences
.icon_size
);
235 XSetForeground(dpy
, gc2
, 1);
236 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
237 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
238 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
242 wpix
= wPixmapCreate(scr
, pix
, mask
);
250 allocGCs(WScreen
*scr
)
254 unsigned long mtextcolor
;
257 scr
->stipple_bitmap
=
258 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
261 gcv
.stipple
= scr
->stipple_bitmap
;
262 gcv
.foreground
= scr
->white_pixel
;
263 gcv
.fill_style
= FillStippled
;
264 gcv
.graphics_exposures
= False
;
265 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
266 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
269 /* selected icon border GCs */
270 gcv
.function
= GXcopy
;
271 gcv
.foreground
= scr
->white_pixel
;
272 gcv
.background
= scr
->black_pixel
;
274 gcv
.line_style
= LineDoubleDash
;
275 gcv
.fill_style
= FillSolid
;
278 gcv
.graphics_exposures
= False
;
280 gcm
= GCFunction
| GCGraphicsExposures
;
281 gcm
|= GCForeground
| GCBackground
;
282 gcm
|= GCLineWidth
| GCLineStyle
;
284 gcm
|= GCDashOffset
| GCDashList
;
286 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
288 gcm
= GCForeground
|GCGraphicsExposures
;
290 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
291 gcv
.foreground
= scr
->white_pixel
;
292 gcv
.graphics_exposures
= False
;
293 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
295 scr
->mtext_pixel
= scr
->black_pixel
;
296 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
297 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
299 /* selected menu entry GC */
300 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
301 gcv
.foreground
= scr
->white_pixel
;
302 gcv
.background
= scr
->white_pixel
;
303 gcv
.graphics_exposures
= False
;
304 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
306 /* disabled menu entry GC */
307 scr
->dtext_pixel
= scr
->black_pixel
;
308 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
309 gcv
.stipple
= scr
->stipple_bitmap
;
310 gcv
.graphics_exposures
= False
;
311 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
314 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
315 gcv
.function
= GXxor
;
316 /* this will raise the probability of the XORed color being different
317 * of the original color in PseudoColor when not all color cells are
319 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
320 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
322 gcv
.plane_mask
= AllPlanes
;
323 gcv
.foreground
= color
.pixel
;
324 if (gcv
.foreground
== 0)
326 gcv
.line_width
= DEF_FRAME_THICKNESS
;
327 gcv
.subwindow_mode
= IncludeInferiors
;
328 gcv
.graphics_exposures
= False
;
329 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
330 |GCFunction
|GCSubwindowMode
|GCLineWidth
334 gcv
.foreground
= color
.pixel
;
336 if (gcv
.foreground
== 0)
337 /* XOR:ing with a zero is not going to be of much use, so
338 in that case, we somewhat arbitrarily xor with 17 instead. */
341 gcv
.function
= GXxor
;
342 gcv
.subwindow_mode
= IncludeInferiors
;
344 gcv
.cap_style
= CapRound
;
345 gcv
.graphics_exposures
= False
;
346 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
347 |GCGraphicsExposures
;
348 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
350 scr
->line_pixel
= gcv
.foreground
;
353 gcv
.foreground
= scr
->white_pixel
;
354 gcv
.background
= scr
->black_pixel
;
355 gcv
.graphics_exposures
= False
;
356 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
357 |GCGraphicsExposures
, &gcv
);
359 /* window title text GC */
360 gcv
.graphics_exposures
= False
;
361 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
364 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
367 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
369 /* move/size display GC */
370 gcv
.graphics_exposures
= False
;
371 gcm
= GCGraphicsExposures
;
372 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
374 /* misc drawing GC */
375 gcv
.graphics_exposures
= False
;
376 gcm
= GCGraphicsExposures
;
377 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
379 assert (scr
->stipple_bitmap
!=None
);
383 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
389 createPixmaps(WScreen
*scr
)
397 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
398 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
399 MENU_RADIO_INDICATOR_XBM_SIZE
,
400 MENU_RADIO_INDICATOR_XBM_SIZE
,
401 scr
->black_pixel
, scr
->white_pixel
);
404 scr
->menu_radio_indicator
= pix
;
407 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
408 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
409 MENU_CHECK_INDICATOR_XBM_SIZE
,
410 MENU_CHECK_INDICATOR_XBM_SIZE
,
411 scr
->black_pixel
, scr
->white_pixel
);
414 scr
->menu_check_indicator
= pix
;
416 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
417 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
418 MENU_MINI_INDICATOR_XBM_SIZE
,
419 MENU_MINI_INDICATOR_XBM_SIZE
,
420 scr
->black_pixel
, scr
->white_pixel
);
423 scr
->menu_mini_indicator
= pix
;
425 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
426 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
427 MENU_HIDE_INDICATOR_XBM_SIZE
,
428 MENU_HIDE_INDICATOR_XBM_SIZE
,
429 scr
->black_pixel
, scr
->white_pixel
);
432 scr
->menu_hide_indicator
= pix
;
434 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
435 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
436 MENU_SHADE_INDICATOR_XBM_SIZE
,
437 MENU_SHADE_INDICATOR_XBM_SIZE
,
438 scr
->black_pixel
, scr
->white_pixel
);
441 scr
->menu_shade_indicator
= pix
;
444 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
447 wwarning(_("could not load logo image for panels: %s"),
448 RMessageForError(RErrorCode
));
450 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
451 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
453 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
454 image
->width
, image
->height
,
456 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
457 WMReleasePixmap(wmpix
);
459 RDestroyImage(image
);
462 scr
->dock_dots
= make3Dots(scr
);
465 /* titlebar button pixmaps */
466 allocButtonPixmaps(scr
);
472 *----------------------------------------------------------------------
473 * createInternalWindows--
474 * Creates some windows used internally by the program. One to
475 * receive input focus when no other window can get it and another
476 * to display window geometry information during window resize/move.
482 * Windows are created and some colors are allocated for the
484 *----------------------------------------------------------------------
487 createInternalWindows(WScreen
*scr
)
490 XSetWindowAttributes attribs
;
492 /* window for displaying geometry information during resizes and moves */
493 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
494 attribs
.border_pixel
= 0;
495 attribs
.save_under
= True
;
496 attribs
.override_redirect
= True
;
497 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
498 attribs
.background_pixmap
= None
;
499 if (scr
->widget_texture
)
500 attribs
.background_pixel
= scr
->widget_texture
->normal
.pixel
;
502 attribs
.background_pixel
= scr
->light_pixel
;
504 attribs
.colormap
= scr
->w_colormap
;
506 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
507 &scr
->geometry_display_height
);
508 scr
->geometry_display
=
509 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
510 scr
->geometry_display_width
,
511 scr
->geometry_display_height
,
512 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
515 /* InputOnly window to get the focus when no other window can get it */
516 vmask
= CWEventMask
|CWOverrideRedirect
;
517 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
518 attribs
.override_redirect
= True
;
519 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
520 InputOnly
,CopyFromParent
, vmask
, &attribs
);
521 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
522 XMapWindow(dpy
, scr
->no_focus_win
);
524 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
526 /* shadow window for dock buttons */
527 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
528 attribs
.border_pixel
= 0;
529 attribs
.save_under
= True
;
530 attribs
.override_redirect
= True
;
531 attribs
.background_pixmap
= None
;
532 attribs
.background_pixel
= scr
->white_pixel
;
534 attribs
.colormap
= scr
->w_colormap
;
536 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
537 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
538 scr
->w_visual
, vmask
, &attribs
);
540 /* workspace name balloon for clip */
541 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
543 attribs
.save_under
= True
;
544 attribs
.override_redirect
= True
;
545 attribs
.colormap
= scr
->w_colormap
;
546 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
547 attribs
.border_pixel
= 0; /* do not care */
549 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
550 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
554 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
556 attribs
.save_under
= True
;
557 attribs
.override_redirect
= True
;
558 attribs
.colormap
= scr
->w_colormap
;
559 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
560 attribs
.border_pixel
= 0; /* do not care */
561 scr
->workspace_name
=
562 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
563 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
566 /* for our window manager info notice board */
568 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, CopyFromParent
,
569 CopyFromParent
, CopyFromParent
, CWOverrideRedirect
,
573 * If the window is clicked without having ButtonPress selected, the
574 * resulting event will have event.xbutton.window == root.
576 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
582 aquireManagerSelection(WScreen
*scr
)
588 sprintf(buffer
, "WM_S%i", scr
->screen
);
589 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
591 /* for race-conditions... */
594 /* if there is another manager running, don't try to replace it
595 * (for now, at least) */
596 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
601 /* become the manager for this screen */
603 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
606 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
607 /* get a timestamp */
608 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
609 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
611 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
612 if (ev
.type
== PropertyNotify
) {
613 timestamp
= ev
.xproperty
.time
;
617 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
618 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
620 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
624 /* announce our arrival */
626 ev
.xclient
.type
= ClientMessage
;
627 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
628 ev
.xclient
.destination
= scr
->root_win
;
629 ev
.xclient
.format
= 32;
630 ev
.xclient
.data
.l
[0] = timestamp
;
631 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
632 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
633 ev
.xclient
.data
.l
[3] = 0;
634 ev
.xclient
.data
.l
[4] = 0;
636 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
644 *----------------------------------------------------------------------
646 * Initializes the window manager for the given screen and
647 * allocates a WScreen descriptor for it. Many resources are allocated
648 * for the screen and the root window is setup appropriately.
651 * The WScreen descriptor for the screen.
654 * Many resources are allocated and the IconSize property is
655 * set on the root window.
656 * The program can be aborted if some fatal error occurs.
658 * TODO: User specifiable visual.
659 *----------------------------------------------------------------------
662 wScreenInit(int screen_number
)
665 XIconSize icon_size
[1];
666 RContextAttributes rattr
;
667 extern int wVisualID
;
670 XErrorHandler oldHandler
;
672 scr
= wmalloc(sizeof(WScreen
));
673 memset(scr
, 0, sizeof(WScreen
));
675 /* initialize globals */
676 scr
->screen
= screen_number
;
677 scr
->root_win
= RootWindow(dpy
, screen_number
);
678 scr
->depth
= DefaultDepth(dpy
, screen_number
);
679 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
681 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
682 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
684 scr
->usableArea
.x2
= scr
->scr_width
;
685 scr
->usableArea
.y2
= scr
->scr_height
;
686 scr
->totalUsableArea
.x2
= scr
->scr_width
;
687 scr
->totalUsableArea
.y2
= scr
->scr_height
;
690 if (!aquireManagerSelection(scr
)) {
696 CantManageScreen
= 0;
697 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
699 event_mask
= EVENT_MASK
;
701 if (wPreferences
.disable_root_mouse
) {
702 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
705 XSelectInput(dpy
, scr
->root_win
, event_mask
);
707 #ifdef KEEP_XKB_LOCK_STATUS
708 XkbSelectEvents(dpy
,XkbUseCoreKbd
,XkbIndicatorStateNotifyMask
,
709 XkbIndicatorStateNotifyMask
);
710 #endif /* KEEP_XKB_LOCK_STATUS */
713 XSetErrorHandler(oldHandler
);
715 if (CantManageScreen
) {
720 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
722 /* screen descriptor for raster graphic library */
723 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
724 rattr
.render_mode
= wPreferences
.no_dithering
725 ? RBestMatchRendering
726 : RDitheredRendering
;
728 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
729 if (rattr
.colors_per_channel
<2)
730 rattr
.colors_per_channel
= 2;
733 rattr
.flags
|= RC_VisualID
;
734 rattr
.visualid
= wVisualID
;
736 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
737 if (!scr
->rcontext
) {
738 wwarning(_("could not initialize graphics library context: %s"),
739 RMessageForError(RErrorCode
));
745 formats
= RSupportedFileFormats();
747 for (i
=0; formats
[i
]!=NULL
; i
++) {
748 if (strcmp(formats
[i
], "TIFF")==0) {
749 scr
->flags
.supports_tiff
= 1;
756 scr
->w_win
= scr
->rcontext
->drawable
;
757 scr
->w_visual
= scr
->rcontext
->visual
;
758 scr
->w_depth
= scr
->rcontext
->depth
;
759 scr
->w_colormap
= scr
->rcontext
->cmap
;
761 scr
->black_pixel
= scr
->rcontext
->black
;
762 scr
->white_pixel
= scr
->rcontext
->white
;
764 /* create screen descriptor for WINGs */
765 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
768 if (!scr
->wmscreen
) {
769 wfatal(_("could not do initialization of WINGs widget set"));
774 color
= WMGrayColor(scr
->wmscreen
);
775 scr
->light_pixel
= WMColorPixel(color
);
776 WMReleaseColor(color
);
778 color
= WMDarkGrayColor(scr
->wmscreen
);
779 scr
->dark_pixel
= WMColorPixel(color
);
780 WMReleaseColor(color
);
784 /* frame boder color */
785 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
786 scr
->frame_border_pixel
= xcol
.pixel
;
789 /* create GCs with default values */
792 /* read defaults for this screen */
793 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
795 createInternalWindows(scr
);
802 wGNOMEInitStuff(scr
);
809 /* create initial workspace */
812 /* create shared pixmaps */
815 /* set icon sizes we can accept from clients */
816 icon_size
[0].min_width
= 8;
817 icon_size
[0].min_height
= 8;
818 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
819 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
820 icon_size
[0].width_inc
= 1;
821 icon_size
[0].height_inc
= 1;
822 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
824 /* setup WindowMaker protocols property in the root window*/
825 PropSetWMakerProtocols(scr
->root_win
);
827 /* setup our noticeboard */
828 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
829 XA_WINDOW
, 32, PropModeReplace
,
830 (unsigned char*)&scr
->info_window
, 1);
831 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
832 XA_WINDOW
, 32, PropModeReplace
,
833 (unsigned char*)&scr
->info_window
, 1);
837 /* initialize balloon text stuff */
838 wBalloonInitialize(scr
);
841 wScreenUpdateUsableArea(scr
);
844 /* kluge to load menu configurations at startup */
845 OpenRootMenu(scr
, -10000, -10000, False
);
846 wMenuUnmap(scr
->root_menu
);
854 wScreenUpdateUsableArea(WScreen
*scr
)
860 scr
->totalUsableArea
= scr
->usableArea
;
863 if (scr
->dock
&& (!scr
->dock
->lowered
864 || wPreferences
.no_window_over_dock
)) {
866 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
868 if (scr
->dock
->on_right_side
) {
869 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
870 scr
->scr_width
- offset
);
872 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
876 if (wPreferences
.no_window_over_icons
) {
877 if (wPreferences
.icon_yard
& IY_VERT
) {
879 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
880 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
882 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
886 if (wPreferences
.icon_yard
& IY_TOP
) {
887 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
889 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
898 if (wKWMGetUsableArea(scr
, &area
)) {
899 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
900 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
901 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
902 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
908 area
= scr
->reservedAreas
;
915 w
= area
->area
.x2
- area
->area
.x1
;
916 h
= area
->area
.y2
- area
->area
.y1
;
919 bh
= scr
->scr_height
- area
->area
.y2
;
921 rw
= scr
->scr_width
- area
->area
.x2
;
923 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
927 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
928 scr
->totalUsableArea
.y1
= area
->area
.y2
;
931 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
932 scr
->totalUsableArea
.y2
= area
->area
.y1
;
938 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
939 scr
->totalUsableArea
.x1
= area
->area
.x2
;
942 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
943 scr
->totalUsableArea
.x2
= area
->area
.x1
;
949 #endif /* GNOME_STUFF */
951 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
952 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
953 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
955 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
956 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
957 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
965 for (i
= 0; i
< scr
->workspace_count
; i
++) {
966 wKWMSetUsableAreaHint(scr
, i
);
975 wScreenRestoreState(WScreen
*scr
)
982 if (wScreenCount
== 1)
983 path
= wdefaultspathfordomain("WMState");
986 sprintf(buf
, "WMState.%i", scr
->screen
);
987 path
= wdefaultspathfordomain(buf
);
989 scr
->session_state
= PLGetProplistWithPath(path
);
991 if (!scr
->session_state
&& wScreenCount
>1) {
993 sprintf(buf
, "WMState.%i", scr
->screen
);
994 path
= wdefaultspathfordomain(buf
);
995 scr
->session_state
= PLGetProplistWithPath(path
);
999 if (!wPreferences
.flags
.noclip
) {
1000 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
1001 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1004 wWorkspaceRestoreState(scr
);
1006 if (!wPreferences
.flags
.nodock
) {
1007 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
1008 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1011 wScreenUpdateUsableArea(scr
);
1016 wScreenSaveState(WScreen
*scr
)
1018 WWorkspaceState wstate
;
1021 proplist_t path
, old_state
, foo
;
1028 * Save current workspace, so can go back to it upon restart.
1030 wstate
.workspace
= scr
->current_workspace
;
1032 data
[0] = wstate
.flags
;
1033 data
[1] = wstate
.workspace
;
1035 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1036 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1037 (unsigned char *) data
, 2);
1039 /* save state of windows */
1040 wwin
= scr
->focused_window
;
1042 wWindowSaveState(wwin
);
1047 if (wPreferences
.flags
.noupdates
)
1051 old_state
= scr
->session_state
;
1052 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1054 PLSetStringCmpHook(NULL
);
1056 /* save dock state to file */
1057 if (!wPreferences
.flags
.nodock
) {
1058 wDockSaveState(scr
);
1060 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1061 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1064 if (!wPreferences
.flags
.noclip
) {
1065 wClipSaveState(scr
);
1067 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1068 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1072 wWorkspaceSaveState(scr
, old_state
);
1074 if (wPreferences
.save_session_on_exit
) {
1075 wSessionSaveState(scr
);
1077 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1078 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1080 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1081 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1086 PLSetStringCmpHook(StringCompareHook
);
1088 wMenuSaveState(scr
);
1090 if (wScreenCount
== 1)
1091 str
= wdefaultspathfordomain("WMState");
1094 sprintf(buf
, "WMState.%i", scr
->screen
);
1095 str
= wdefaultspathfordomain(buf
);
1097 path
= PLMakeString(str
);
1099 PLSetFilename(scr
->session_state
, path
);
1100 if (!PLSave(scr
->session_state
, YES
)) {
1101 wsyserror(_("could not save session state in %s"), PLGetString(path
));
1104 PLRelease(old_state
);
1110 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1126 *x
= -tol_w
, moved
= 1;
1127 else if (*x
>= scr
->scr_width
- 10)
1128 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1130 if (*y
< -height
+ 10)
1131 *y
= -tol_h
, moved
= 1;
1132 else if (*y
>= scr
->scr_height
- 10)
1133 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;