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
;
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
182 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
187 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
189 XSetForeground(dpy
, gc
, scr
->black_pixel
);
190 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
191 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
192 XSetForeground(dpy
, gc
, scr
->white_pixel
);
193 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
194 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
199 make3Dots(WScreen
*scr
)
207 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
208 wPreferences
.icon_size
, scr
->w_depth
);
209 XSetForeground(dpy
, gc
, scr
->black_pixel
);
210 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
211 wPreferences
.icon_size
);
212 XSetForeground(dpy
, gc
, scr
->white_pixel
);
213 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
214 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
215 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
217 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
218 wPreferences
.icon_size
, 1);
220 gcv
.graphics_exposures
= False
;
221 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
222 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
223 wPreferences
.icon_size
);
224 XSetForeground(dpy
, gc2
, 1);
225 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
226 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
227 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
231 wpix
= wPixmapCreate(scr
, pix
, mask
);
239 allocGCs(WScreen
*scr
)
243 unsigned long mtextcolor
;
246 scr
->stipple_bitmap
=
247 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
250 gcv
.stipple
= scr
->stipple_bitmap
;
251 gcv
.foreground
= scr
->white_pixel
;
252 gcv
.fill_style
= FillStippled
;
253 gcv
.graphics_exposures
= False
;
254 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
255 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
258 /* selected icon border GCs */
259 gcv
.function
= GXcopy
;
260 gcv
.foreground
= scr
->white_pixel
;
261 gcv
.background
= scr
->black_pixel
;
263 gcv
.line_style
= LineDoubleDash
;
264 gcv
.fill_style
= FillSolid
;
267 gcv
.graphics_exposures
= False
;
269 gcm
= GCFunction
| GCGraphicsExposures
;
270 gcm
|= GCForeground
| GCBackground
;
271 gcm
|= GCLineWidth
| GCLineStyle
;
273 gcm
|= GCDashOffset
| GCDashList
;
275 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
277 gcm
= GCForeground
|GCGraphicsExposures
;
279 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
280 gcv
.foreground
= scr
->white_pixel
;
281 gcv
.graphics_exposures
= False
;
282 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
284 scr
->mtext_pixel
= scr
->black_pixel
;
285 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
286 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
288 /* selected menu entry GC */
289 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
290 gcv
.foreground
= scr
->white_pixel
;
291 gcv
.background
= scr
->white_pixel
;
292 gcv
.graphics_exposures
= False
;
293 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
295 /* disabled menu entry GC */
296 scr
->dtext_pixel
= scr
->black_pixel
;
297 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
298 gcv
.stipple
= scr
->stipple_bitmap
;
299 gcv
.graphics_exposures
= False
;
300 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
303 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
304 gcv
.function
= GXxor
;
305 /* this will raise the probability of the XORed color being different
306 * of the original color in PseudoColor when not all color cells are
308 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
309 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
311 gcv
.plane_mask
= AllPlanes
;
312 gcv
.foreground
= color
.pixel
;
313 if (gcv
.foreground
== 0)
315 gcv
.line_width
= DEF_FRAME_THICKNESS
;
316 gcv
.subwindow_mode
= IncludeInferiors
;
317 gcv
.graphics_exposures
= False
;
318 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
319 |GCFunction
|GCSubwindowMode
|GCLineWidth
323 gcv
.foreground
= color
.pixel
;
325 if (gcv
.foreground
== 0)
326 /* XOR:ing with a zero is not going to be of much use, so
327 in that case, we somewhat arbitrarily xor with 17 instead. */
330 gcv
.function
= GXxor
;
331 gcv
.subwindow_mode
= IncludeInferiors
;
333 gcv
.cap_style
= CapRound
;
334 gcv
.graphics_exposures
= False
;
335 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
336 |GCGraphicsExposures
;
337 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
339 scr
->line_pixel
= gcv
.foreground
;
342 gcv
.foreground
= scr
->white_pixel
;
343 gcv
.background
= scr
->black_pixel
;
344 gcv
.graphics_exposures
= False
;
345 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
346 |GCGraphicsExposures
, &gcv
);
348 /* window title text GC */
349 gcv
.graphics_exposures
= False
;
350 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
353 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
356 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
358 /* move/size display GC */
359 gcv
.graphics_exposures
= False
;
360 gcm
= GCGraphicsExposures
;
361 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
363 /* misc drawing GC */
364 gcv
.graphics_exposures
= False
;
365 gcm
= GCGraphicsExposures
;
366 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
368 assert (scr
->stipple_bitmap
!=None
);
372 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
378 createPixmaps(WScreen
*scr
)
386 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
387 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
388 MENU_RADIO_INDICATOR_XBM_SIZE
,
389 MENU_RADIO_INDICATOR_XBM_SIZE
,
390 scr
->black_pixel
, scr
->white_pixel
);
393 scr
->menu_radio_indicator
= pix
;
396 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
397 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
398 MENU_CHECK_INDICATOR_XBM_SIZE
,
399 MENU_CHECK_INDICATOR_XBM_SIZE
,
400 scr
->black_pixel
, scr
->white_pixel
);
403 scr
->menu_check_indicator
= pix
;
405 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
406 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
407 MENU_MINI_INDICATOR_XBM_SIZE
,
408 MENU_MINI_INDICATOR_XBM_SIZE
,
409 scr
->black_pixel
, scr
->white_pixel
);
412 scr
->menu_mini_indicator
= pix
;
414 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
415 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
416 MENU_HIDE_INDICATOR_XBM_SIZE
,
417 MENU_HIDE_INDICATOR_XBM_SIZE
,
418 scr
->black_pixel
, scr
->white_pixel
);
421 scr
->menu_hide_indicator
= pix
;
423 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
424 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
425 MENU_SHADE_INDICATOR_XBM_SIZE
,
426 MENU_SHADE_INDICATOR_XBM_SIZE
,
427 scr
->black_pixel
, scr
->white_pixel
);
430 scr
->menu_shade_indicator
= pix
;
433 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
436 wwarning(_("could not load logo image for panels: %s"),
437 RMessageForError(RErrorCode
));
439 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
440 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
442 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
443 image
->width
, image
->height
,
445 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
446 WMReleasePixmap(wmpix
);
448 RDestroyImage(image
);
452 if (!wPreferences
.flags
.nodock
|| !wPreferences
.flags
.noclip
) {
453 scr
->dock_dots
= make3Dots(scr
);
458 /* titlebar button pixmaps */
459 allocButtonPixmaps(scr
);
465 *----------------------------------------------------------------------
466 * createInternalWindows--
467 * Creates some windows used internally by the program. One to
468 * receive input focus when no other window can get it and another
469 * to display window geometry information during window resize/move.
475 * Windows are created and some colors are allocated for the
477 *----------------------------------------------------------------------
480 createInternalWindows(WScreen
*scr
)
483 XSetWindowAttributes attribs
;
485 /* window for displaying geometry information during resizes and moves */
486 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
487 attribs
.border_pixel
= 0;
488 attribs
.save_under
= True
;
489 attribs
.override_redirect
= True
;
490 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
491 attribs
.background_pixmap
= None
;
492 if (scr
->widget_texture
)
493 attribs
.background_pixel
= scr
->widget_texture
->normal
.pixel
;
495 attribs
.background_pixel
= scr
->light_pixel
;
497 attribs
.colormap
= scr
->w_colormap
;
499 wGetGeometryWindowSize(scr
, &scr
->geometry_display_width
,
500 &scr
->geometry_display_height
);
501 scr
->geometry_display
=
502 XCreateWindow(dpy
, scr
->root_win
, 1, 1,
503 scr
->geometry_display_width
,
504 scr
->geometry_display_height
,
505 1, scr
->w_depth
, CopyFromParent
, scr
->w_visual
,
508 /* InputOnly window to get the focus when no other window can get it */
509 vmask
= CWEventMask
|CWOverrideRedirect
;
510 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
511 attribs
.override_redirect
= True
;
512 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
513 InputOnly
,CopyFromParent
, vmask
, &attribs
);
514 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
515 XMapWindow(dpy
, scr
->no_focus_win
);
517 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
519 /* shadow window for dock buttons */
520 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
521 attribs
.border_pixel
= 0;
522 attribs
.save_under
= True
;
523 attribs
.override_redirect
= True
;
524 attribs
.background_pixmap
= None
;
525 attribs
.background_pixel
= scr
->white_pixel
;
527 attribs
.colormap
= scr
->w_colormap
;
529 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
530 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
531 scr
->w_visual
, vmask
, &attribs
);
533 /* workspace name balloon for clip */
534 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
536 attribs
.save_under
= True
;
537 attribs
.override_redirect
= True
;
538 attribs
.colormap
= scr
->w_colormap
;
539 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
540 attribs
.border_pixel
= 0; /* do not care */
542 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
543 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
547 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
549 attribs
.save_under
= True
;
550 attribs
.override_redirect
= True
;
551 attribs
.colormap
= scr
->w_colormap
;
552 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
553 attribs
.border_pixel
= 0; /* do not care */
554 scr
->workspace_name
=
555 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
556 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
559 /* for our window manager info notice board */
561 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, CopyFromParent
,
562 CopyFromParent
, CopyFromParent
, CWOverrideRedirect
,
566 * If the window is clicked without having ButtonPress selected, the
567 * resulting event will have event.xbutton.window == root.
569 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
575 aquireManagerSelection(WScreen
*scr
)
581 sprintf(buffer
, "WM_S%i", scr
->screen
);
582 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
584 /* for race-conditions... */
587 /* if there is another manager running, don't try to replace it
588 * (for now, at least) */
589 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
594 /* become the manager for this screen */
596 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
599 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
600 /* get a timestamp */
601 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
602 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
604 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
605 if (ev
.type
== PropertyNotify
) {
606 timestamp
= ev
.xproperty
.time
;
610 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
611 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
613 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
617 /* announce our arrival */
619 ev
.xclient
.type
= ClientMessage
;
620 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
621 ev
.xclient
.destination
= scr
->root_win
;
622 ev
.xclient
.format
= 32;
623 ev
.xclient
.data
.l
[0] = timestamp
;
624 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
625 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
626 ev
.xclient
.data
.l
[3] = 0;
627 ev
.xclient
.data
.l
[4] = 0;
629 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
637 *----------------------------------------------------------------------
639 * Initializes the window manager for the given screen and
640 * allocates a WScreen descriptor for it. Many resources are allocated
641 * for the screen and the root window is setup appropriately.
644 * The WScreen descriptor for the screen.
647 * Many resources are allocated and the IconSize property is
648 * set on the root window.
649 * The program can be aborted if some fatal error occurs.
651 * TODO: User specifiable visual.
652 *----------------------------------------------------------------------
655 wScreenInit(int screen_number
)
658 XIconSize icon_size
[1];
659 RContextAttributes rattr
;
660 extern int wVisualID
;
663 XErrorHandler oldHandler
;
665 scr
= wmalloc(sizeof(WScreen
));
666 memset(scr
, 0, sizeof(WScreen
));
668 /* initialize globals */
669 scr
->screen
= screen_number
;
670 scr
->root_win
= RootWindow(dpy
, screen_number
);
671 scr
->depth
= DefaultDepth(dpy
, screen_number
);
672 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
674 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
675 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
677 scr
->usableArea
.x2
= scr
->scr_width
;
678 scr
->usableArea
.y2
= scr
->scr_height
;
679 scr
->totalUsableArea
.x2
= scr
->scr_width
;
680 scr
->totalUsableArea
.y2
= scr
->scr_height
;
683 if (!aquireManagerSelection(scr
)) {
689 CantManageScreen
= 0;
690 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
692 event_mask
= EVENT_MASK
;
694 if (wPreferences
.disable_root_mouse
) {
695 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
698 XSelectInput(dpy
, scr
->root_win
, event_mask
);
700 #ifdef KEEP_XKB_LOCK_STATUS
701 XkbSelectEvents(dpy
,XkbUseCoreKbd
,XkbIndicatorStateNotifyMask
,
702 XkbIndicatorStateNotifyMask
);
703 #endif /* KEEP_XKB_LOCK_STATUS */
706 XSetErrorHandler(oldHandler
);
708 if (CantManageScreen
) {
713 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
715 /* screen descriptor for raster graphic library */
716 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
;
717 rattr
.render_mode
= wPreferences
.no_dithering
?RM_MATCH
:RM_DITHER
;
718 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
719 if (rattr
.colors_per_channel
<2)
720 rattr
.colors_per_channel
= 2;
723 rattr
.flags
|= RC_VisualID
;
724 rattr
.visualid
= wVisualID
;
726 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
727 if (!scr
->rcontext
) {
728 wwarning(_("could not initialize graphics library context: %s"),
729 RMessageForError(RErrorCode
));
735 formats
= RSupportedFileFormats();
737 for (i
=0; formats
[i
]!=NULL
; i
++) {
738 if (strcmp(formats
[i
], "TIFF")==0) {
739 scr
->flags
.supports_tiff
= 1;
746 scr
->w_win
= scr
->rcontext
->drawable
;
747 scr
->w_visual
= scr
->rcontext
->visual
;
748 scr
->w_depth
= scr
->rcontext
->depth
;
749 scr
->w_colormap
= scr
->rcontext
->cmap
;
751 scr
->black_pixel
= scr
->rcontext
->black
;
752 scr
->white_pixel
= scr
->rcontext
->white
;
754 /* create screen descriptor for WINGs */
755 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
758 if (!scr
->wmscreen
) {
759 wfatal(_("could not do initialization of WINGs widget set"));
764 color
= WMGrayColor(scr
->wmscreen
);
765 scr
->light_pixel
= WMColorPixel(color
);
766 WMReleaseColor(color
);
768 color
= WMDarkGrayColor(scr
->wmscreen
);
769 scr
->dark_pixel
= WMColorPixel(color
);
770 WMReleaseColor(color
);
774 /* frame boder color */
775 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
776 scr
->frame_border_pixel
= xcol
.pixel
;
779 scr
->workspace_name_font
= wLoadFont(DEF_WORKSPACE_NAME_FONT
);
781 /* create GCs with default values */
784 /* read defaults for this screen */
785 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
787 createInternalWindows(scr
);
794 wGNOMEInitStuff(scr
);
801 /* create initial workspace */
804 /* create shared pixmaps */
807 /* set icon sizes we can accept from clients */
808 icon_size
[0].min_width
= 8;
809 icon_size
[0].min_height
= 8;
810 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
811 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
812 icon_size
[0].width_inc
= 1;
813 icon_size
[0].height_inc
= 1;
814 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
816 /* setup WindowMaker protocols property in the root window*/
817 PropSetWMakerProtocols(scr
->root_win
);
819 /* setup our noticeboard */
820 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
821 XA_WINDOW
, 32, PropModeReplace
,
822 (unsigned char*)&scr
->info_window
, 1);
823 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
824 XA_WINDOW
, 32, PropModeReplace
,
825 (unsigned char*)&scr
->info_window
, 1);
829 /* initialize balloon text stuff */
830 wBalloonInitialize(scr
);
833 wScreenUpdateUsableArea(scr
);
836 /* kluge to load menu configurations at startup */
837 OpenRootMenu(scr
, -10000, -10000, False
);
838 wMenuUnmap(scr
->root_menu
);
846 wScreenUpdateUsableArea(WScreen
*scr
)
852 scr
->totalUsableArea
= scr
->usableArea
;
855 if (scr
->dock
&& (!scr
->dock
->lowered
856 || wPreferences
.no_window_over_dock
)) {
858 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
860 if (scr
->dock
->on_right_side
) {
861 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
862 scr
->scr_width
- offset
);
864 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
868 if (wPreferences
.no_window_over_icons
) {
869 if (wPreferences
.icon_yard
& IY_VERT
) {
871 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
872 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
874 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
878 if (wPreferences
.icon_yard
& IY_TOP
) {
879 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
881 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
890 if (wKWMGetUsableArea(scr
, &area
)) {
891 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
892 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
893 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
894 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
900 area
= scr
->reservedAreas
;
907 w
= area
->area
.x2
- area
->area
.x1
;
908 h
= area
->area
.y2
- area
->area
.y1
;
911 bh
= scr
->scr_height
- area
->area
.y2
;
913 rw
= scr
->scr_width
- area
->area
.x2
;
915 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
919 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
920 scr
->totalUsableArea
.y1
= area
->area
.y2
;
923 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
924 scr
->totalUsableArea
.y2
= area
->area
.y1
;
930 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
931 scr
->totalUsableArea
.x1
= area
->area
.x2
;
934 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
935 scr
->totalUsableArea
.x2
= area
->area
.x1
;
941 #endif /* GNOME_STUFF */
943 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
944 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
945 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
947 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
948 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
949 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
957 for (i
= 0; i
< scr
->workspace_count
; i
++) {
958 wKWMSetUsableAreaHint(scr
, i
);
967 wScreenRestoreState(WScreen
*scr
)
974 if (wScreenCount
== 1)
975 path
= wdefaultspathfordomain("WMState");
978 sprintf(buf
, "WMState.%i", scr
->screen
);
979 path
= wdefaultspathfordomain(buf
);
981 scr
->session_state
= PLGetProplistWithPath(path
);
983 if (!scr
->session_state
&& wScreenCount
>1) {
985 sprintf(buf
, "WMState.%i", scr
->screen
);
986 path
= wdefaultspathfordomain(buf
);
987 scr
->session_state
= PLGetProplistWithPath(path
);
991 if (!wPreferences
.flags
.noclip
) {
992 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
993 scr
->clip_icon
= wClipRestoreState(scr
, state
);
996 wWorkspaceRestoreState(scr
);
998 if (!wPreferences
.flags
.nodock
) {
999 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
1000 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1003 wScreenUpdateUsableArea(scr
);
1008 wScreenSaveState(WScreen
*scr
)
1010 WWorkspaceState wstate
;
1013 proplist_t path
, old_state
, foo
;
1020 * Save current workspace, so can go back to it upon restart.
1022 wstate
.workspace
= scr
->current_workspace
;
1024 data
[0] = wstate
.flags
;
1025 data
[1] = wstate
.workspace
;
1027 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1028 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1029 (unsigned char *) data
, 2);
1031 /* save state of windows */
1032 wwin
= scr
->focused_window
;
1034 wWindowSaveState(wwin
);
1039 if (wPreferences
.flags
.noupdates
)
1043 old_state
= scr
->session_state
;
1044 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1046 PLSetStringCmpHook(NULL
);
1048 /* save dock state to file */
1049 if (!wPreferences
.flags
.nodock
) {
1050 wDockSaveState(scr
);
1052 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1053 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1056 if (!wPreferences
.flags
.noclip
) {
1057 wClipSaveState(scr
);
1059 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1060 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1064 wWorkspaceSaveState(scr
, old_state
);
1066 if (wPreferences
.save_session_on_exit
) {
1067 wSessionSaveState(scr
);
1069 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1070 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1072 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1073 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1078 PLSetStringCmpHook(StringCompareHook
);
1080 wMenuSaveState(scr
);
1082 if (wScreenCount
== 1)
1083 str
= wdefaultspathfordomain("WMState");
1086 sprintf(buf
, "WMState.%i", scr
->screen
);
1087 str
= wdefaultspathfordomain(buf
);
1089 path
= PLMakeString(str
);
1091 PLSetFilename(scr
->session_state
, path
);
1092 if (!PLSave(scr
->session_state
, YES
)) {
1093 wwarning(_("could not save session state in %s"), PLGetString(path
));
1096 PLRelease(old_state
);
1102 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1118 *x
= -tol_w
, moved
= 1;
1119 else if (*x
>= scr
->scr_width
- 10)
1120 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1122 if (*y
< -height
+ 10)
1123 *y
= -tol_h
, moved
= 1;
1124 else if (*y
>= scr
->scr_height
- 10)
1125 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;