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"
63 # include "openlook.h"
72 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
73 |SubstructureNotifyMask|PointerMotionMask \
74 |SubstructureRedirectMask|KeyPressMask|KeyReleaseMask)
76 #define EVENT_MASK (LeaveWindowMask|EnterWindowMask|PropertyChangeMask\
77 |SubstructureNotifyMask|PointerMotionMask \
78 |SubstructureRedirectMask|ButtonPressMask|ButtonReleaseMask\
79 |KeyPressMask|KeyReleaseMask)
82 /**** Global variables ****/
84 extern Cursor wCursor
[WCUR_LAST
];
85 extern WPreferences wPreferences
;
86 extern Atom _XA_WINDOWMAKER_STATE
;
87 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
90 extern int wScreenCount
;
92 #ifdef KEEP_XKB_LOCK_STATUS
93 extern int wXkbSupported
;
96 extern WDDomain
*WDWindowMaker
;
101 #define STIPPLE_WIDTH 2
102 #define STIPPLE_HEIGHT 2
103 static char STIPPLE_DATA
[] = {0x02, 0x01};
105 static int CantManageScreen
= 0;
107 static proplist_t dApplications
= NULL
;
108 static proplist_t dWorkspace
;
109 static proplist_t dDock
;
110 static proplist_t dClip
;
116 if (dApplications
!=NULL
)
119 dApplications
= PLMakeString("Applications");
120 dWorkspace
= PLMakeString("Workspace");
121 dDock
= PLMakeString("Dock");
122 dClip
= PLMakeString("Clip");
127 *----------------------------------------------------------------------
128 * alreadyRunningError--
129 * X error handler used to catch errors when trying to do
130 * XSelectInput() on the root window. These errors probably mean that
131 * there already is some other window manager running.
134 * Nothing, unless something really evil happens...
137 * CantManageScreen is set to 1;
138 *----------------------------------------------------------------------
141 alreadyRunningError(Display
*dpy
, XErrorEvent
*error
)
143 CantManageScreen
= 1;
149 *----------------------------------------------------------------------
150 * allocButtonPixmaps--
151 * Allocate pixmaps used on window operation buttons (those in the
152 * titlebar). The pixmaps are linked to the program. If XPM is supported
153 * XPM pixmaps are used otherwise, equivalent bitmaps are used.
159 * Allocates shared pixmaps for the screen. These pixmaps should
160 * not be freed by anybody.
161 *----------------------------------------------------------------------
164 allocButtonPixmaps(WScreen
*scr
)
168 /* create predefined pixmaps */
169 pix
= wPixmapCreateFromXPMData(scr
, PRED_CLOSE_XPM
);
172 scr
->b_pixmaps
[WBUT_CLOSE
] = pix
;
174 pix
= wPixmapCreateFromXPMData(scr
, PRED_BROKEN_CLOSE_XPM
);
177 scr
->b_pixmaps
[WBUT_BROKENCLOSE
] = pix
;
179 pix
= wPixmapCreateFromXPMData(scr
, PRED_ICONIFY_XPM
);
182 scr
->b_pixmaps
[WBUT_ICONIFY
] = pix
;
183 #ifdef XKB_BUTTON_HINT
184 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP1_XPM
);
187 scr
->b_pixmaps
[WBUT_XKBGROUP1
] = pix
;
188 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP2_XPM
);
191 scr
->b_pixmaps
[WBUT_XKBGROUP2
] = pix
;
192 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP3_XPM
);
195 scr
->b_pixmaps
[WBUT_XKBGROUP3
] = pix
;
196 pix
= wPixmapCreateFromXPMData(scr
, PRED_XKBGROUP4_XPM
);
199 scr
->b_pixmaps
[WBUT_XKBGROUP4
] = pix
;
203 pix
= wPixmapCreateFromXPMData(scr
, PRED_KILL_XPM
);
206 scr
->b_pixmaps
[WBUT_KILL
] = pix
;
211 draw_dot(WScreen
*scr
, Drawable d
, int x
, int y
, GC gc
)
213 XSetForeground(dpy
, gc
, scr
->black_pixel
);
214 XDrawLine(dpy
, d
, gc
, x
, y
, x
+1, y
);
215 XDrawPoint(dpy
, d
, gc
, x
, y
+1);
216 XSetForeground(dpy
, gc
, scr
->white_pixel
);
217 XDrawLine(dpy
, d
, gc
, x
+2, y
, x
+2, y
+1);
218 XDrawPoint(dpy
, d
, gc
, x
+1, y
+1);
223 make3Dots(WScreen
*scr
)
231 pix
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
232 wPreferences
.icon_size
, scr
->w_depth
);
233 XSetForeground(dpy
, gc
, scr
->black_pixel
);
234 XFillRectangle(dpy
, pix
, gc
, 0, 0, wPreferences
.icon_size
,
235 wPreferences
.icon_size
);
236 XSetForeground(dpy
, gc
, scr
->white_pixel
);
237 draw_dot(scr
, pix
, 4, wPreferences
.icon_size
-6, gc
);
238 draw_dot(scr
, pix
, 9, wPreferences
.icon_size
-6, gc
);
239 draw_dot(scr
, pix
, 14, wPreferences
.icon_size
-6, gc
);
241 mask
= XCreatePixmap(dpy
, scr
->w_win
, wPreferences
.icon_size
,
242 wPreferences
.icon_size
, 1);
244 gcv
.graphics_exposures
= False
;
245 gc2
= XCreateGC(dpy
, mask
, GCForeground
|GCGraphicsExposures
, &gcv
);
246 XFillRectangle(dpy
, mask
, gc2
, 0, 0, wPreferences
.icon_size
,
247 wPreferences
.icon_size
);
248 XSetForeground(dpy
, gc2
, 1);
249 XFillRectangle(dpy
, mask
, gc2
, 4, wPreferences
.icon_size
-6, 3, 2);
250 XFillRectangle(dpy
, mask
, gc2
, 9, wPreferences
.icon_size
-6, 3, 2);
251 XFillRectangle(dpy
, mask
, gc2
, 14, wPreferences
.icon_size
-6, 3, 2);
255 wpix
= wPixmapCreate(scr
, pix
, mask
);
263 allocGCs(WScreen
*scr
)
267 unsigned long mtextcolor
;
270 scr
->stipple_bitmap
=
271 XCreateBitmapFromData(dpy
, scr
->w_win
, STIPPLE_DATA
, STIPPLE_WIDTH
,
274 gcv
.stipple
= scr
->stipple_bitmap
;
275 gcv
.foreground
= scr
->white_pixel
;
276 gcv
.fill_style
= FillStippled
;
277 gcv
.graphics_exposures
= False
;
278 gcm
= GCForeground
|GCStipple
|GCFillStyle
|GCGraphicsExposures
;
279 scr
->stipple_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
282 /* selected icon border GCs */
283 gcv
.function
= GXcopy
;
284 gcv
.foreground
= scr
->white_pixel
;
285 gcv
.background
= scr
->black_pixel
;
287 gcv
.line_style
= LineDoubleDash
;
288 gcv
.fill_style
= FillSolid
;
291 gcv
.graphics_exposures
= False
;
293 gcm
= GCFunction
| GCGraphicsExposures
;
294 gcm
|= GCForeground
| GCBackground
;
295 gcm
|= GCLineWidth
| GCLineStyle
;
297 gcm
|= GCDashOffset
| GCDashList
;
299 scr
->icon_select_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
301 gcm
= GCForeground
|GCGraphicsExposures
;
303 scr
->menu_title_pixel
[0] = scr
->white_pixel
;
304 gcv
.foreground
= scr
->white_pixel
;
305 gcv
.graphics_exposures
= False
;
306 scr
->menu_title_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
308 scr
->mtext_pixel
= scr
->black_pixel
;
309 mtextcolor
= gcv
.foreground
= scr
->black_pixel
;
310 scr
->menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
312 /* selected menu entry GC */
313 gcm
= GCForeground
|GCBackground
|GCGraphicsExposures
;
314 gcv
.foreground
= scr
->white_pixel
;
315 gcv
.background
= scr
->white_pixel
;
316 gcv
.graphics_exposures
= False
;
317 scr
->select_menu_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
319 /* disabled menu entry GC */
320 scr
->dtext_pixel
= scr
->black_pixel
;
321 gcm
= GCForeground
|GCBackground
|GCStipple
|GCGraphicsExposures
;
322 gcv
.stipple
= scr
->stipple_bitmap
;
323 gcv
.graphics_exposures
= False
;
324 scr
->disabled_menu_entry_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
327 wGetColor(scr
, DEF_FRAME_COLOR
, &color
);
328 gcv
.function
= GXxor
;
329 /* this will raise the probability of the XORed color being different
330 * of the original color in PseudoColor when not all color cells are
332 if (DefaultVisual(dpy
, scr
->screen
)->class==PseudoColor
)
333 gcv
.plane_mask
= (1<<(scr
->depth
-1))|1;
335 gcv
.plane_mask
= AllPlanes
;
336 gcv
.foreground
= color
.pixel
;
337 if (gcv
.foreground
== 0)
339 gcv
.line_width
= DEF_FRAME_THICKNESS
;
340 gcv
.subwindow_mode
= IncludeInferiors
;
341 gcv
.graphics_exposures
= False
;
342 scr
->frame_gc
= XCreateGC(dpy
, scr
->root_win
, GCForeground
|GCGraphicsExposures
343 |GCFunction
|GCSubwindowMode
|GCLineWidth
347 gcv
.foreground
= color
.pixel
;
349 if (gcv
.foreground
== 0)
350 /* XOR:ing with a zero is not going to be of much use, so
351 in that case, we somewhat arbitrarily xor with 17 instead. */
354 gcv
.function
= GXxor
;
355 gcv
.subwindow_mode
= IncludeInferiors
;
357 gcv
.cap_style
= CapRound
;
358 gcv
.graphics_exposures
= False
;
359 gcm
= GCForeground
|GCFunction
|GCSubwindowMode
|GCLineWidth
|GCCapStyle
360 |GCGraphicsExposures
;
361 scr
->line_gc
= XCreateGC(dpy
, scr
->root_win
, gcm
, &gcv
);
363 scr
->line_pixel
= gcv
.foreground
;
366 gcv
.foreground
= scr
->white_pixel
;
367 gcv
.background
= scr
->black_pixel
;
368 gcv
.graphics_exposures
= False
;
369 scr
->copy_gc
= XCreateGC(dpy
, scr
->w_win
, GCForeground
|GCBackground
370 |GCGraphicsExposures
, &gcv
);
372 /* window title text GC */
373 gcv
.graphics_exposures
= False
;
374 scr
->window_title_gc
= XCreateGC(dpy
, scr
->w_win
,GCGraphicsExposures
,&gcv
);
377 scr
->icon_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
380 scr
->clip_title_gc
= XCreateGC(dpy
, scr
->w_win
, GCGraphicsExposures
, &gcv
);
382 /* move/size display GC */
383 gcv
.graphics_exposures
= False
;
384 gcm
= GCGraphicsExposures
;
385 scr
->info_text_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
387 /* misc drawing GC */
388 gcv
.graphics_exposures
= False
;
389 gcm
= GCGraphicsExposures
;
390 scr
->draw_gc
= XCreateGC(dpy
, scr
->w_win
, gcm
, &gcv
);
392 assert (scr
->stipple_bitmap
!=None
);
396 scr
->mono_gc
= XCreateGC(dpy
, scr
->stipple_bitmap
, gcm
, &gcv
);
402 createPixmaps(WScreen
*scr
)
410 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
411 (char*)MENU_RADIO_INDICATOR_XBM_DATA
,
412 MENU_RADIO_INDICATOR_XBM_SIZE
,
413 MENU_RADIO_INDICATOR_XBM_SIZE
,
414 scr
->black_pixel
, scr
->white_pixel
);
417 scr
->menu_radio_indicator
= pix
;
420 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
421 (char*)MENU_CHECK_INDICATOR_XBM_DATA
,
422 MENU_CHECK_INDICATOR_XBM_SIZE
,
423 MENU_CHECK_INDICATOR_XBM_SIZE
,
424 scr
->black_pixel
, scr
->white_pixel
);
427 scr
->menu_check_indicator
= pix
;
429 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_MINI_INDICATOR_XBM_DATA
,
430 (char*)MENU_MINI_INDICATOR_XBM_DATA
,
431 MENU_MINI_INDICATOR_XBM_SIZE
,
432 MENU_MINI_INDICATOR_XBM_SIZE
,
433 scr
->black_pixel
, scr
->white_pixel
);
436 scr
->menu_mini_indicator
= pix
;
438 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
439 (char*)MENU_HIDE_INDICATOR_XBM_DATA
,
440 MENU_HIDE_INDICATOR_XBM_SIZE
,
441 MENU_HIDE_INDICATOR_XBM_SIZE
,
442 scr
->black_pixel
, scr
->white_pixel
);
445 scr
->menu_hide_indicator
= pix
;
447 pix
= wPixmapCreateFromXBMData(scr
, (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
448 (char*)MENU_SHADE_INDICATOR_XBM_DATA
,
449 MENU_SHADE_INDICATOR_XBM_SIZE
,
450 MENU_SHADE_INDICATOR_XBM_SIZE
,
451 scr
->black_pixel
, scr
->white_pixel
);
454 scr
->menu_shade_indicator
= pix
;
457 image
= wDefaultGetImage(scr
, "Logo", "WMPanel");
460 wwarning(_("could not load logo image for panels: %s"),
461 RMessageForError(RErrorCode
));
463 if (!RConvertImageMask(scr
->rcontext
, image
, &p
, &m
, 128)) {
464 wwarning(_("error making logo image for panel:%s"), RMessageForError(RErrorCode
));
466 wmpix
= WMCreatePixmapFromXPixmaps(scr
->wmscreen
, p
, m
,
467 image
->width
, image
->height
,
469 WMSetApplicationIconImage(scr
->wmscreen
, wmpix
);
470 WMReleasePixmap(wmpix
);
472 RDestroyImage(image
);
475 scr
->dock_dots
= make3Dots(scr
);
477 /* titlebar button pixmaps */
478 allocButtonPixmaps(scr
);
483 *----------------------------------------------------------------------
484 * createInternalWindows--
485 * Creates some windows used internally by the program. One to
486 * receive input focus when no other window can get it and another
487 * to display window geometry information during window resize/move.
493 * Windows are created and some colors are allocated for the
495 *----------------------------------------------------------------------
498 createInternalWindows(WScreen
*scr
)
501 XSetWindowAttributes attribs
;
503 /* InputOnly window to get the focus when no other window can get it */
504 vmask
= CWEventMask
|CWOverrideRedirect
;
505 attribs
.event_mask
= KeyPressMask
|FocusChangeMask
;
506 attribs
.override_redirect
= True
;
507 scr
->no_focus_win
=XCreateWindow(dpy
,scr
->root_win
,-10, -10, 4, 4, 0, 0,
508 InputOnly
,CopyFromParent
, vmask
, &attribs
);
509 XSelectInput(dpy
, scr
->no_focus_win
, KeyPressMask
|KeyReleaseMask
);
510 XMapWindow(dpy
, scr
->no_focus_win
);
512 XSetInputFocus(dpy
, scr
->no_focus_win
, RevertToParent
, CurrentTime
);
514 /* shadow window for dock buttons */
515 vmask
= CWBorderPixel
|CWBackPixmap
|CWBackPixel
|CWCursor
|CWSaveUnder
|CWOverrideRedirect
;
516 attribs
.border_pixel
= scr
->black_pixel
;
517 attribs
.save_under
= True
;
518 attribs
.override_redirect
= True
;
519 attribs
.background_pixmap
= None
;
520 attribs
.background_pixel
= scr
->white_pixel
;
521 attribs
.cursor
= wCursor
[WCUR_DEFAULT
];
523 attribs
.colormap
= scr
->w_colormap
;
525 XCreateWindow(dpy
, scr
->root_win
, 0, 0, wPreferences
.icon_size
,
526 wPreferences
.icon_size
, 0, scr
->w_depth
, CopyFromParent
,
527 scr
->w_visual
, vmask
, &attribs
);
529 /* workspace name balloon for clip */
530 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
532 attribs
.save_under
= True
;
533 attribs
.override_redirect
= True
;
534 attribs
.colormap
= scr
->w_colormap
;
535 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
536 attribs
.border_pixel
= 0; /* do not care */
538 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
539 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
543 vmask
= CWBackPixel
|CWSaveUnder
|CWOverrideRedirect
|CWColormap
545 attribs
.save_under
= True
;
546 attribs
.override_redirect
= True
;
547 attribs
.colormap
= scr
->w_colormap
;
548 attribs
.background_pixel
= scr
->icon_back_texture
->normal
.pixel
;
549 attribs
.border_pixel
= 0; /* do not care */
550 scr
->workspace_name
=
551 XCreateWindow(dpy
, scr
->root_win
, 0, 0, 10, 10, 0, scr
->w_depth
,
552 CopyFromParent
, scr
->w_visual
, vmask
, &attribs
);
555 * If the window is clicked without having ButtonPress selected, the
556 * resulting event will have event.xbutton.window == root.
558 XSelectInput(dpy
, scr
->clip_balloon
, ButtonPressMask
);
564 aquireManagerSelection(WScreen
*scr
)
570 sprintf(buffer
, "WM_S%i", scr
->screen
);
571 scr
->managerAtom
= XInternAtom(dpy
, buffer
, False
);
573 /* for race-conditions... */
576 /* if there is another manager running, don't try to replace it
577 * (for now, at least) */
578 if (XGetSelectionOwner(dpy
, scr
->managerAtom
) != None
) {
583 /* become the manager for this screen */
585 scr
->managerWindow
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 1, 1,
588 XSelectInput(dpy
, scr
->managerWindow
, PropertyChangeMask
);
589 /* get a timestamp */
590 XChangeProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
,
591 XA_INTEGER
, 32, PropModeAppend
, NULL
, 0);
593 XWindowEvent(dpy
, scr
->managerWindow
, &ev
);
594 if (ev
.type
== PropertyNotify
) {
595 timestamp
= ev
.xproperty
.time
;
599 XSelectInput(dpy
, scr
->managerWindow
, NoEvents
);
600 XDeleteProperty(dpy
, scr
->managerWindow
, scr
->managerAtom
);
602 XSetSelectionOwner(dpy
, scr
->managerAtom
, scr
->managerWindow
, CurrentTime
);
606 /* announce our arrival */
608 ev
.xclient
.type
= ClientMessage
;
609 ev
.xclient
.message_type
= XInternAtom(dpy
, "MANAGER", False
);
610 ev
.xclient
.destination
= scr
->root_win
;
611 ev
.xclient
.format
= 32;
612 ev
.xclient
.data
.l
[0] = timestamp
;
613 ev
.xclient
.data
.l
[1] = scr
->managerAtom
;
614 ev
.xclient
.data
.l
[2] = scr
->managerWindow
;
615 ev
.xclient
.data
.l
[3] = 0;
616 ev
.xclient
.data
.l
[4] = 0;
618 XSendEvent(dpy
, scr
->root_win
, False
, StructureNotify
, &ev
);
626 *----------------------------------------------------------------------
628 * Initializes the window manager for the given screen and
629 * allocates a WScreen descriptor for it. Many resources are allocated
630 * for the screen and the root window is setup appropriately.
633 * The WScreen descriptor for the screen.
636 * Many resources are allocated and the IconSize property is
637 * set on the root window.
638 * The program can be aborted if some fatal error occurs.
640 * TODO: User specifiable visual.
641 *----------------------------------------------------------------------
644 wScreenInit(int screen_number
)
647 XIconSize icon_size
[1];
648 RContextAttributes rattr
;
649 extern int wVisualID
;
652 XErrorHandler oldHandler
;
654 scr
= wmalloc(sizeof(WScreen
));
655 memset(scr
, 0, sizeof(WScreen
));
657 /* initialize globals */
658 scr
->screen
= screen_number
;
659 scr
->root_win
= RootWindow(dpy
, screen_number
);
660 scr
->depth
= DefaultDepth(dpy
, screen_number
);
661 scr
->colormap
= DefaultColormap(dpy
, screen_number
);
663 scr
->scr_width
= WidthOfScreen(ScreenOfDisplay(dpy
, screen_number
));
664 scr
->scr_height
= HeightOfScreen(ScreenOfDisplay(dpy
, screen_number
));
666 scr
->usableArea
.x2
= scr
->scr_width
;
667 scr
->usableArea
.y2
= scr
->scr_height
;
668 scr
->totalUsableArea
.x2
= scr
->scr_width
;
669 scr
->totalUsableArea
.y2
= scr
->scr_height
;
672 if (!aquireManagerSelection(scr
)) {
678 CantManageScreen
= 0;
679 oldHandler
= XSetErrorHandler((XErrorHandler
)alreadyRunningError
);
681 event_mask
= EVENT_MASK
;
683 if (wPreferences
.disable_root_mouse
) {
684 event_mask
&= ~(ButtonPressMask
|ButtonReleaseMask
);
687 XSelectInput(dpy
, scr
->root_win
, event_mask
);
689 #ifdef KEEP_XKB_LOCK_STATUS
690 /* Only GroupLock doesn't work correctly in my system since right-alt
691 * can change mode while holding it too - ]d
694 XkbSelectEvents(dpy
,XkbUseCoreKbd
,
698 #endif /* KEEP_XKB_LOCK_STATUS */
701 XSetErrorHandler(oldHandler
);
703 if (CantManageScreen
) {
708 #ifndef DEFINABLE_CURSOR
709 XDefineCursor(dpy
, scr
->root_win
, wCursor
[WCUR_DEFAULT
]);
712 /* screen descriptor for raster graphic library */
713 rattr
.flags
= RC_RenderMode
| RC_ColorsPerChannel
| RC_StandardColormap
;
714 rattr
.render_mode
= wPreferences
.no_dithering
715 ? RBestMatchRendering
716 : RDitheredRendering
;
718 /* if the std colormap stuff works ok, this will be ignored */
719 rattr
.colors_per_channel
= wPreferences
.cmap_size
;
720 if (rattr
.colors_per_channel
<2)
721 rattr
.colors_per_channel
= 2;
723 /* will only be accounted for in PseudoColor */
724 rattr
.standard_colormap_mode
= RCreateStdColormap
;
727 rattr
.flags
|= RC_VisualID
;
728 rattr
.visualid
= wVisualID
;
731 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
733 if (!scr
->rcontext
&& RErrorCode
== RERR_STDCMAPFAIL
) {
734 wwarning(RMessageForError(RErrorCode
));
736 rattr
.flags
&= ~RC_StandardColormap
;
737 rattr
.standard_colormap_mode
= RUseStdColormap
;
739 scr
->rcontext
= RCreateContext(dpy
, screen_number
, &rattr
);
742 if (!scr
->rcontext
) {
743 wwarning(_("could not initialize graphics library context: %s"),
744 RMessageForError(RErrorCode
));
750 formats
= RSupportedFileFormats();
752 for (i
=0; formats
[i
]!=NULL
; i
++) {
753 if (strcmp(formats
[i
], "TIFF")==0) {
754 scr
->flags
.supports_tiff
= 1;
761 scr
->w_win
= scr
->rcontext
->drawable
;
762 scr
->w_visual
= scr
->rcontext
->visual
;
763 scr
->w_depth
= scr
->rcontext
->depth
;
764 scr
->w_colormap
= scr
->rcontext
->cmap
;
766 scr
->black_pixel
= scr
->rcontext
->black
;
767 scr
->white_pixel
= scr
->rcontext
->white
;
769 /* create screen descriptor for WINGs */
770 scr
->wmscreen
= WMCreateScreenWithRContext(dpy
, screen_number
,
773 if (!scr
->wmscreen
) {
774 wfatal(_("could not do initialization of WINGs widget set"));
779 color
= WMGrayColor(scr
->wmscreen
);
780 scr
->light_pixel
= WMColorPixel(color
);
781 WMReleaseColor(color
);
783 color
= WMDarkGrayColor(scr
->wmscreen
);
784 scr
->dark_pixel
= WMColorPixel(color
);
785 WMReleaseColor(color
);
789 /* frame boder color */
790 wGetColor(scr
, FRAME_BORDER_COLOR
, &xcol
);
791 scr
->frame_border_pixel
= xcol
.pixel
;
794 /* create GCs with default values */
798 /* for our window manager info notice board. Need to
799 * create before reading the defaults, because it will be used there.
801 scr
->info_window
= XCreateSimpleWindow(dpy
, scr
->root_win
, 0, 0, 10, 10,
804 /* read defaults for this screen */
805 wReadDefaults(scr
, WDWindowMaker
->dictionary
);
807 createInternalWindows(scr
);
814 wGNOMEInitStuff(scr
);
821 /* create initial workspace */
824 /* create shared pixmaps */
827 /* set icon sizes we can accept from clients */
828 icon_size
[0].min_width
= 8;
829 icon_size
[0].min_height
= 8;
830 icon_size
[0].max_width
= wPreferences
.icon_size
-4;
831 icon_size
[0].max_height
= wPreferences
.icon_size
-4;
832 icon_size
[0].width_inc
= 1;
833 icon_size
[0].height_inc
= 1;
834 XSetIconSizes(dpy
, scr
->root_win
, icon_size
, 1);
836 /* setup WindowMaker protocols property in the root window*/
837 PropSetWMakerProtocols(scr
->root_win
);
839 /* setup our noticeboard */
840 XChangeProperty(dpy
, scr
->info_window
, _XA_WINDOWMAKER_NOTICEBOARD
,
841 XA_WINDOW
, 32, PropModeReplace
,
842 (unsigned char*)&scr
->info_window
, 1);
843 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_NOTICEBOARD
,
844 XA_WINDOW
, 32, PropModeReplace
,
845 (unsigned char*)&scr
->info_window
, 1);
849 /* initialize balloon text stuff */
850 wBalloonInitialize(scr
);
853 scr
->info_text_font
= WMBoldSystemFontOfSize(scr
->wmscreen
, 12);
856 scr
->gview
= WCreateGeometryView(scr
->wmscreen
);
857 WMRealizeWidget(scr
->gview
);
859 wScreenUpdateUsableArea(scr
);
866 wScreenUpdateUsableArea(WScreen
*scr
)
872 scr
->totalUsableArea
= scr
->usableArea
;
875 if (scr
->dock
&& (!scr
->dock
->lowered
876 || wPreferences
.no_window_over_dock
)) {
878 int offset
= wPreferences
.icon_size
+ DOCK_EXTRA_SPACE
;
880 if (scr
->dock
->on_right_side
) {
881 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
,
882 scr
->scr_width
- offset
);
884 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, offset
);
888 if (wPreferences
.no_window_over_icons
) {
889 if (wPreferences
.icon_yard
& IY_VERT
) {
891 if (!(wPreferences
.icon_yard
& IY_RIGHT
)) {
892 scr
->totalUsableArea
.x1
+= wPreferences
.icon_size
;
894 scr
->totalUsableArea
.x2
-= wPreferences
.icon_size
;
898 if (wPreferences
.icon_yard
& IY_TOP
) {
899 scr
->totalUsableArea
.y1
+= wPreferences
.icon_size
;
901 scr
->totalUsableArea
.y2
-= wPreferences
.icon_size
;
910 if (wKWMGetUsableArea(scr
, &area
)) {
911 scr
->totalUsableArea
.x1
= WMAX(scr
->totalUsableArea
.x1
, area
.x1
);
912 scr
->totalUsableArea
.y1
= WMAX(scr
->totalUsableArea
.y1
, area
.y1
);
913 scr
->totalUsableArea
.x2
= WMIN(scr
->totalUsableArea
.x2
, area
.x2
);
914 scr
->totalUsableArea
.y2
= WMIN(scr
->totalUsableArea
.y2
, area
.y2
);
920 area
= scr
->reservedAreas
;
927 w
= area
->area
.x2
- area
->area
.x1
;
928 h
= area
->area
.y2
- area
->area
.y1
;
931 bh
= scr
->scr_height
- area
->area
.y2
;
933 rw
= scr
->scr_width
- area
->area
.x2
;
935 if (WMIN(th
, bh
) < WMIN(lw
, rw
)) {
939 if (scr
->totalUsableArea
.y1
< area
->area
.y2
)
940 scr
->totalUsableArea
.y1
= area
->area
.y2
;
943 if (scr
->totalUsableArea
.y2
> area
->area
.y1
)
944 scr
->totalUsableArea
.y2
= area
->area
.y1
;
950 if (scr
->totalUsableArea
.x1
< area
->area
.x2
)
951 scr
->totalUsableArea
.x1
= area
->area
.x2
;
954 if (scr
->totalUsableArea
.x2
> area
->area
.x1
)
955 scr
->totalUsableArea
.x2
= area
->area
.x1
;
961 #endif /* GNOME_STUFF */
963 if (scr
->totalUsableArea
.x2
- scr
->totalUsableArea
.x1
< scr
->scr_width
/2) {
964 scr
->totalUsableArea
.x2
= scr
->usableArea
.x2
;
965 scr
->totalUsableArea
.x1
= scr
->usableArea
.x1
;
967 if (scr
->totalUsableArea
.y2
- scr
->totalUsableArea
.y1
< scr
->scr_height
/2) {
968 scr
->totalUsableArea
.y2
= scr
->usableArea
.y2
;
969 scr
->totalUsableArea
.y1
= scr
->usableArea
.y1
;
977 for (i
= 0; i
< scr
->workspace_count
; i
++) {
978 wKWMSetUsableAreaHint(scr
, i
);
987 wScreenRestoreState(WScreen
*scr
)
994 OpenRootMenu(scr
, -10000, -10000, False
);
995 wMenuUnmap(scr
->root_menu
);
1000 if (wScreenCount
== 1)
1001 path
= wdefaultspathfordomain("WMState");
1004 sprintf(buf
, "WMState.%i", scr
->screen
);
1005 path
= wdefaultspathfordomain(buf
);
1007 scr
->session_state
= PLGetProplistWithPath(path
);
1009 if (!scr
->session_state
&& wScreenCount
>1) {
1011 sprintf(buf
, "WMState.%i", scr
->screen
);
1012 path
= wdefaultspathfordomain(buf
);
1013 scr
->session_state
= PLGetProplistWithPath(path
);
1017 if (!wPreferences
.flags
.noclip
) {
1018 state
= PLGetDictionaryEntry(scr
->session_state
, dClip
);
1019 scr
->clip_icon
= wClipRestoreState(scr
, state
);
1022 wWorkspaceRestoreState(scr
);
1024 #ifdef VIRTUAL_DESKTOP
1026 * * create inputonly windows at the border of screen
1028 wWorkspaceManageEdge(scr
);
1031 if (!wPreferences
.flags
.nodock
) {
1032 state
= PLGetDictionaryEntry(scr
->session_state
, dDock
);
1033 scr
->dock
= wDockRestoreState(scr
, state
, WM_DOCK
);
1036 wScreenUpdateUsableArea(scr
);
1041 wScreenSaveState(WScreen
*scr
)
1043 WWorkspaceState wstate
;
1046 proplist_t path
, old_state
, foo
;
1053 * Save current workspace, so can go back to it upon restart.
1055 wstate
.workspace
= scr
->current_workspace
;
1057 data
[0] = wstate
.flags
;
1058 data
[1] = wstate
.workspace
;
1060 XChangeProperty(dpy
, scr
->root_win
, _XA_WINDOWMAKER_STATE
,
1061 _XA_WINDOWMAKER_STATE
, 32, PropModeReplace
,
1062 (unsigned char *) data
, 2);
1064 /* save state of windows */
1065 wwin
= scr
->focused_window
;
1067 wWindowSaveState(wwin
);
1072 if (wPreferences
.flags
.noupdates
)
1076 old_state
= scr
->session_state
;
1077 scr
->session_state
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
1079 PLSetStringCmpHook(NULL
);
1081 /* save dock state to file */
1082 if (!wPreferences
.flags
.nodock
) {
1083 wDockSaveState(scr
, old_state
);
1085 if ((foo
= PLGetDictionaryEntry(old_state
, dDock
))!=NULL
) {
1086 PLInsertDictionaryEntry(scr
->session_state
, dDock
, foo
);
1089 if (!wPreferences
.flags
.noclip
) {
1090 wClipSaveState(scr
);
1092 if ((foo
= PLGetDictionaryEntry(old_state
, dClip
))!=NULL
) {
1093 PLInsertDictionaryEntry(scr
->session_state
, dClip
, foo
);
1097 wWorkspaceSaveState(scr
, old_state
);
1099 if (wPreferences
.save_session_on_exit
) {
1100 wSessionSaveState(scr
);
1102 if ((foo
= PLGetDictionaryEntry(old_state
, dApplications
))!=NULL
) {
1103 PLInsertDictionaryEntry(scr
->session_state
, dApplications
, foo
);
1105 if ((foo
= PLGetDictionaryEntry(old_state
, dWorkspace
))!=NULL
) {
1106 PLInsertDictionaryEntry(scr
->session_state
, dWorkspace
, foo
);
1111 PLSetStringCmpHook(StringCompareHook
);
1113 wMenuSaveState(scr
);
1115 if (wScreenCount
== 1)
1116 str
= wdefaultspathfordomain("WMState");
1119 sprintf(buf
, "WMState.%i", scr
->screen
);
1120 str
= wdefaultspathfordomain(buf
);
1122 path
= PLMakeString(str
);
1124 PLSetFilename(scr
->session_state
, path
);
1125 if (!PLSave(scr
->session_state
, YES
)) {
1126 wsyserror(_("could not save session state in %s"), PLGetString(path
));
1129 PLRelease(old_state
);
1135 wScreenBringInside(WScreen
*scr
, int *x
, int *y
, int width
, int height
)
1151 *x
= -tol_w
, moved
= 1;
1152 else if (*x
>= scr
->scr_width
- 10)
1153 *x
= scr
->scr_width
- tol_w
- 1, moved
= 1;
1155 if (*y
< -height
+ 10)
1156 *y
= -tol_h
, moved
= 1;
1157 else if (*y
>= scr
->scr_height
- 10)
1158 *y
= scr
->scr_height
- tol_h
- 1, moved
= 1;