2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 Dan Pascu
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,
33 #include <sys/signal.h>
37 #include <X11/Xresource.h>
38 #include <X11/Xutil.h>
39 #include <X11/cursorfont.h>
40 #include <X11/Xproto.h>
41 #include <X11/keysym.h>
43 #include <X11/extensions/shape.h>
46 #include "WindowMaker.h"
55 #include "workspace.h"
60 #include "properties.h"
70 #ifdef SYS_SIGLIST_DECLARED
71 extern const char *const sys_siglist
[];
80 /* Just in case, for weirdo systems */
85 /****** Global Variables ******/
87 extern WPreferences wPreferences
;
89 extern WDDomain
*WDWindowMaker
;
90 extern WDDomain
*WDRootMenu
;
91 extern WDDomain
*WDWindowAttributes
;
93 extern WShortKey wKeyBindings
[WKBD_LAST
];
95 extern int wScreenCount
;
98 extern Bool wShapeSupported
;
99 extern int wShapeEventBase
;
102 #ifdef KEEP_XKB_LOCK_STATUS
103 extern Bool wXkbSupported
;
104 extern int wXkbEventBase
;
108 extern XContext wWinContext
;
109 extern XContext wAppWinContext
;
110 extern XContext wStackContext
;
111 extern XContext wVEdgeContext
;
114 extern Atom _XA_WM_STATE
;
115 extern Atom _XA_WM_CHANGE_STATE
;
116 extern Atom _XA_WM_PROTOCOLS
;
117 extern Atom _XA_WM_TAKE_FOCUS
;
118 extern Atom _XA_WM_DELETE_WINDOW
;
119 extern Atom _XA_WM_SAVE_YOURSELF
;
120 extern Atom _XA_WM_CLIENT_LEADER
;
121 extern Atom _XA_WM_COLORMAP_WINDOWS
;
122 extern Atom _XA_WM_COLORMAP_NOTIFY
;
124 extern Atom _XA_GNUSTEP_WM_ATTR
;
126 extern Atom _XA_WINDOWMAKER_MENU
;
127 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
128 extern Atom _XA_WINDOWMAKER_STATE
;
129 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
130 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
131 extern Atom _XA_WINDOWMAKER_COMMAND
;
132 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
133 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
135 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
136 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
138 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
141 extern Cursor wCursor
[WCUR_LAST
];
144 /*extern char WDelayedActionSet;*/
148 static WScreen
**wScreen
= NULL
;
150 static unsigned int _NumLockMask
= 0;
151 static unsigned int _ScrollLockMask
= 0;
153 static void manageAllWindows(WScreen
* scr
, int crashed
);
155 extern void NotifyDeadProcess(pid_t pid
, unsigned char status
);
157 static int catchXError(Display
* dpy
, XErrorEvent
* error
)
159 char buffer
[MAXLINE
];
161 /* ignore some errors */
162 if (error
->resourceid
!= None
163 && ((error
->error_code
== BadDrawable
&& error
->request_code
== X_GetGeometry
)
164 || (error
->error_code
== BadMatch
&& (error
->request_code
== X_SetInputFocus
))
165 || (error
->error_code
== BadWindow
)
167 && (error->request_code == X_GetWindowAttributes
168 || error->request_code == X_SetInputFocus
169 || error->request_code == X_ChangeWindowAttributes
170 || error->request_code == X_GetProperty
171 || error->request_code == X_ChangeProperty
172 || error->request_code == X_QueryTree
173 || error->request_code == X_GrabButton
174 || error->request_code == X_UngrabButton
175 || error->request_code == X_SendEvent
176 || error->request_code == X_ConfigureWindow))
178 || (error
->request_code
== X_InstallColormap
))) {
183 printf("got X error %x %x %x\n", error
->request_code
,
184 error
->error_code
, (unsigned)error
->resourceid
);
188 FormatXError(dpy
, error
, buffer
, MAXLINE
);
189 wwarning(_("internal X error: %s\n"), buffer
);
194 *----------------------------------------------------------------------
196 * Handle X shutdowns and other stuff.
197 *----------------------------------------------------------------------
199 static int handleXIO(Display
* xio_dpy
)
207 *----------------------------------------------------------------------
209 * Action to be executed after the signal() handler is exited.
210 * This was called every 500ms to 'clean up' signals. Not used now.
211 *----------------------------------------------------------------------
214 static void delayedAction(void *cdata
)
216 if (WDelayedActionSet
== 0) {
221 * Make the event dispatcher do whatever it needs to do,
222 * including handling zombie processes, restart and exit
230 *----------------------------------------------------------------------
232 * User generated exit signal handler.
233 *----------------------------------------------------------------------
235 static RETSIGTYPE
handleExitSig(int sig
)
240 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
242 if (sig
== SIGUSR1
) {
243 #ifdef SYS_SIGLIST_DECLARED
244 wwarning("got signal %i (%s) - restarting\n", sig
, sys_siglist
[sig
]);
246 wwarning("got signal %i - restarting\n", sig
);
249 SIG_WCHANGE_STATE(WSTATE_NEED_RESTART
);
251 } else if (sig
== SIGUSR2
) {
252 #ifdef SYS_SIGLIST_DECLARED
253 wwarning("got signal %i (%s) - rereading defaults\n", sig
, sys_siglist
[sig
]);
255 wwarning("got signal %i - rereading defaults\n", sig
);
258 SIG_WCHANGE_STATE(WSTATE_NEED_REREAD
);
260 } else if (sig
== SIGTERM
|| sig
== SIGINT
|| sig
== SIGHUP
) {
261 #ifdef SYS_SIGLIST_DECLARED
262 wwarning("got signal %i (%s) - exiting...\n", sig
, sys_siglist
[sig
]);
264 wwarning("got signal %i - exiting...\n", sig
);
267 SIG_WCHANGE_STATE(WSTATE_NEED_EXIT
);
271 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
272 DispatchEvent(NULL
); /* Dispatch events imediately. */
275 /* Dummy signal handler */
276 static void dummyHandler(int sig
)
281 *----------------------------------------------------------------------
283 * general signal handler. Exits the program gently.
284 *----------------------------------------------------------------------
286 static RETSIGTYPE
handleSig(int sig
)
288 #ifdef SYS_SIGLIST_DECLARED
289 wfatal("got signal %i (%s)\n", sig
, sys_siglist
[sig
]);
291 wfatal("got signal %i\n", sig
);
294 /* Setting the signal behaviour back to default and then reraising the
295 * signal is a cleaner way to make program exit and core dump than calling
296 * abort(), since it correctly returns from the signal handler and sets
297 * the flags accordingly. -Dan
299 if (sig
== SIGSEGV
|| sig
== SIGFPE
|| sig
== SIGBUS
|| sig
== SIGILL
|| sig
== SIGABRT
) {
300 signal(sig
, SIG_DFL
);
308 static RETSIGTYPE
buryChild(int foo
)
312 int save_errno
= errno
;
316 /* Block signals so that NotifyDeadProcess() doesn't get fux0red */
317 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
320 /* If 2 or more kids exit in a small time window, before this handler gets
321 * the chance to get invoked, the SIGCHLD signals will be merged and only
322 * one SIGCHLD signal will be sent to us. We use a while loop to get all
323 * exited child status because we can't count on the number of SIGCHLD
324 * signals to know exactly how many kids have exited. -Dan
326 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0 || (pid
< 0 && errno
== EINTR
)) {
327 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
330 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
335 static void getOffendingModifiers()
338 XModifierKeymap
*modmap
;
339 KeyCode nlock
, slock
;
340 static int mask_table
[8] = {
341 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
342 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
345 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
346 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
349 * Find out the masks for the NumLock and ScrollLock modifiers,
350 * so that we can bind the grabs for when they are enabled too.
352 modmap
= XGetModifierMapping(dpy
);
354 if (modmap
!= NULL
&& modmap
->max_keypermod
> 0) {
355 for (i
= 0; i
< 8 * modmap
->max_keypermod
; i
++) {
356 if (modmap
->modifiermap
[i
] == nlock
&& nlock
!= 0)
357 _NumLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
358 else if (modmap
->modifiermap
[i
] == slock
&& slock
!= 0)
359 _ScrollLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
364 XFreeModifiermap(modmap
);
369 wHackedGrabKey(int keycode
, unsigned int modifiers
,
370 Window grab_window
, Bool owner_events
, int pointer_mode
, int keyboard_mode
)
372 if (modifiers
== AnyModifier
)
375 /* grab all combinations of the modifier with CapsLock, NumLock and
376 * ScrollLock. How much memory/CPU does such a monstrosity consume
380 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
,
381 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
383 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
,
384 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
385 if (_NumLockMask
&& _ScrollLockMask
)
386 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
,
387 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
389 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| LockMask
,
390 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
392 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
| LockMask
,
393 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
394 if (_NumLockMask
&& _ScrollLockMask
)
395 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
| LockMask
,
396 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
397 /* phew, I guess that's all, right? */
402 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
403 Window grab_window
, Bool owner_events
,
404 unsigned int event_mask
, int pointer_mode
, int keyboard_mode
, Window confine_to
, Cursor cursor
)
406 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
407 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
409 if (modifiers
== AnyModifier
)
412 XGrabButton(dpy
, button
, modifiers
| LockMask
, grab_window
, owner_events
,
413 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
416 /* same as above, but for mouse buttons */
418 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
,
419 grab_window
, owner_events
, event_mask
, pointer_mode
,
420 keyboard_mode
, confine_to
, cursor
);
422 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
,
423 grab_window
, owner_events
, event_mask
, pointer_mode
,
424 keyboard_mode
, confine_to
, cursor
);
425 if (_NumLockMask
&& _ScrollLockMask
)
426 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
,
427 grab_window
, owner_events
, event_mask
, pointer_mode
,
428 keyboard_mode
, confine_to
, cursor
);
430 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
| LockMask
,
431 grab_window
, owner_events
, event_mask
, pointer_mode
,
432 keyboard_mode
, confine_to
, cursor
);
434 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| LockMask
,
435 grab_window
, owner_events
, event_mask
, pointer_mode
,
436 keyboard_mode
, confine_to
, cursor
);
437 if (_NumLockMask
&& _ScrollLockMask
)
438 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
| LockMask
,
439 grab_window
, owner_events
, event_mask
, pointer_mode
,
440 keyboard_mode
, confine_to
, cursor
);
441 #endif /* NUMLOCK_HACK */
445 void wHackedUngrabButton(unsigned int button
, unsigned int modifiers
, Window grab_window
)
447 XUngrabButton(dpy
, button
, modifiers
| _NumLockMask
, grab_window
);
448 XUngrabButton(dpy
, button
, modifiers
| _ScrollLockMask
, grab_window
);
449 XUngrabButton(dpy
, button
, modifiers
| _NumLockMask
| _ScrollLockMask
, grab_window
);
450 XUngrabButton(dpy
, button
, modifiers
| _NumLockMask
| LockMask
, grab_window
);
451 XUngrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| LockMask
, grab_window
);
452 XUngrabButton(dpy
, button
, modifiers
| _NumLockMask
| _ScrollLockMask
| LockMask
, grab_window
);
456 WScreen
*wScreenWithNumber(int i
)
458 assert(i
< wScreenCount
);
463 WScreen
*wScreenForRootWindow(Window window
)
467 if (wScreenCount
== 1)
471 * Since the number of heads will probably be small (normally 2),
472 * it should be faster to use this than a hash table, because
475 for (i
= 0; i
< wScreenCount
; i
++) {
476 if (wScreen
[i
]->root_win
== window
) {
481 return wScreenForWindow(window
);
484 WScreen
*wScreenSearchForRootWindow(Window window
)
488 if (wScreenCount
== 1)
492 * Since the number of heads will probably be small (normally 2),
493 * it should be faster to use this than a hash table, because
496 for (i
= 0; i
< wScreenCount
; i
++) {
497 if (wScreen
[i
]->root_win
== window
) {
502 return wScreenForWindow(window
);
505 WScreen
*wScreenForWindow(Window window
)
507 XWindowAttributes attr
;
509 if (wScreenCount
== 1)
512 if (XGetWindowAttributes(dpy
, window
, &attr
)) {
513 return wScreenForRootWindow(attr
.root
);
518 static char *atomNames
[] = {
526 "WM_COLORMAP_WINDOWS",
527 "WM_COLORMAP_NOTIFY",
530 "_WINDOWMAKER_STATE",
531 "_WINDOWMAKER_WM_PROTOCOLS",
532 "_WINDOWMAKER_WM_FUNCTION",
533 "_WINDOWMAKER_NOTICEBOARD",
534 "_WINDOWMAKER_COMMAND",
535 "_WINDOWMAKER_ICON_SIZE",
536 "_WINDOWMAKER_ICON_TILE",
538 GNUSTEP_WM_ATTR_NAME
,
539 GNUSTEP_WM_MINIATURIZE_WINDOW
,
540 GNUSTEP_TITLEBAR_STATE
,
542 "WM_IGNORE_FOCUS_EVENTS"
546 *----------------------------------------------------------
548 * starts the window manager and setup global data.
549 * Called from main() at startup.
552 * global data declared in main.c is initialized
553 *----------------------------------------------------------
555 void StartUp(Bool defaultScreenOnly
)
557 struct sigaction sig_action
;
559 Atom atom
[sizeof(atomNames
) / sizeof(char *)];
562 * Ignore CapsLock in modifiers
564 ValidModMask
= 0xff & ~LockMask
;
566 getOffendingModifiers();
568 * Ignore NumLock and ScrollLock too
570 ValidModMask
&= ~(_NumLockMask
| _ScrollLockMask
);
572 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
574 wWinContext
= XUniqueContext();
575 wAppWinContext
= XUniqueContext();
576 wStackContext
= XUniqueContext();
577 wVEdgeContext
= XUniqueContext();
579 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
581 #ifdef HAVE_XINTERNATOMS
582 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
) / sizeof(char *), False
, atom
);
587 for (i
= 0; i
< sizeof(atomNames
) / sizeof(char *); i
++) {
588 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
593 _XA_WM_STATE
= atom
[0];
594 _XA_WM_CHANGE_STATE
= atom
[1];
595 _XA_WM_PROTOCOLS
= atom
[2];
596 _XA_WM_TAKE_FOCUS
= atom
[3];
597 _XA_WM_DELETE_WINDOW
= atom
[4];
598 _XA_WM_SAVE_YOURSELF
= atom
[5];
599 _XA_WM_CLIENT_LEADER
= atom
[6];
600 _XA_WM_COLORMAP_WINDOWS
= atom
[7];
601 _XA_WM_COLORMAP_NOTIFY
= atom
[8];
603 _XA_WINDOWMAKER_MENU
= atom
[9];
604 _XA_WINDOWMAKER_STATE
= atom
[10];
605 _XA_WINDOWMAKER_WM_PROTOCOLS
= atom
[11];
606 _XA_WINDOWMAKER_WM_FUNCTION
= atom
[12];
607 _XA_WINDOWMAKER_NOTICEBOARD
= atom
[13];
608 _XA_WINDOWMAKER_COMMAND
= atom
[14];
609 _XA_WINDOWMAKER_ICON_SIZE
= atom
[15];
610 _XA_WINDOWMAKER_ICON_TILE
= atom
[16];
612 _XA_GNUSTEP_WM_ATTR
= atom
[17];
613 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
= atom
[18];
614 _XA_GNUSTEP_TITLEBAR_STATE
= atom
[19];
616 _XA_WM_IGNORE_FOCUS_EVENTS
= atom
[20];
619 wXDNDInitializeAtoms();
623 wCursor
[WCUR_NORMAL
] = None
; /* inherit from root */
624 wCursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
625 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
626 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
627 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
628 wCursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
629 wCursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
630 wCursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
631 wCursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
632 wCursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
633 wCursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
634 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
635 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
636 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name??? */
637 wCursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
639 Pixmap cur
= XCreatePixmap(dpy
, DefaultRootWindow(dpy
), 16, 16, 1);
640 GC gc
= XCreateGC(dpy
, cur
, 0, NULL
);
642 memset(&black
, 0, sizeof(XColor
));
643 XSetForeground(dpy
, gc
, 0);
644 XFillRectangle(dpy
, cur
, gc
, 0, 0, 16, 16);
646 wCursor
[WCUR_EMPTY
] = XCreatePixmapCursor(dpy
, cur
, cur
, &black
, &black
, 0, 0);
647 XFreePixmap(dpy
, cur
);
650 /* emergency exit... */
651 sig_action
.sa_handler
= handleSig
;
652 sigemptyset(&sig_action
.sa_mask
);
654 sig_action
.sa_flags
= SA_RESTART
;
655 sigaction(SIGQUIT
, &sig_action
, NULL
);
656 /* instead of catching these, we let the default handler abort the
657 * program. The new monitor process will take appropriate action
658 * when it detects the crash.
659 sigaction(SIGSEGV, &sig_action, NULL);
660 sigaction(SIGBUS, &sig_action, NULL);
661 sigaction(SIGFPE, &sig_action, NULL);
662 sigaction(SIGABRT, &sig_action, NULL);
665 sig_action
.sa_handler
= handleExitSig
;
667 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
668 * immediately. -Dan */
669 sig_action
.sa_flags
= SA_RESTART
;
670 sigaction(SIGTERM
, &sig_action
, NULL
);
671 sigaction(SIGINT
, &sig_action
, NULL
);
672 sigaction(SIGHUP
, &sig_action
, NULL
);
673 sigaction(SIGUSR1
, &sig_action
, NULL
);
674 sigaction(SIGUSR2
, &sig_action
, NULL
);
676 /* ignore dead pipe */
677 /* Because POSIX mandates that only signal with handlers are reset
678 * accross an exec*(), we do not want to propagate ignoring SIGPIPEs
679 * to children. Hence the dummy handler.
680 * Philippe Troin <phil@fifi.org>
682 sig_action
.sa_handler
= &dummyHandler
;
683 sig_action
.sa_flags
= SA_RESTART
;
684 sigaction(SIGPIPE
, &sig_action
, NULL
);
686 /* handle dead children */
687 sig_action
.sa_handler
= buryChild
;
688 sig_action
.sa_flags
= SA_NOCLDSTOP
| SA_RESTART
;
689 sigaction(SIGCHLD
, &sig_action
, NULL
);
691 /* Now we unblock all signals, that may have been blocked by the parent
692 * who exec()-ed us. This can happen for example if Window Maker crashes
693 * and restarts itself or another window manager from the signal handler.
694 * In this case, the new proccess inherits the blocked signal mask and
695 * will no longer react to that signal, until unblocked.
696 * This is because the signal handler of the proccess who crashed (parent)
697 * didn't return, and the signal remained blocked. -Dan
699 sigfillset(&sig_action
.sa_mask
);
700 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
702 /* handle X shutdowns a such */
703 XSetIOErrorHandler(handleXIO
);
705 /* set hook for out event dispatcher in WINGs event dispatcher */
706 WMHookEventHandler(DispatchEvent
);
708 /* initialize defaults stuff */
709 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
710 if (!WDWindowMaker
->dictionary
) {
711 wwarning(_("could not read domain \"%s\" from defaults database"), "WindowMaker");
714 /* read defaults that don't change until a restart and are
715 * screen independent */
716 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
718 /* check sanity of some values */
719 if (wPreferences
.icon_size
< 16) {
720 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
721 wPreferences
.icon_size
);
722 wPreferences
.icon_size
= 16;
725 /* init other domains */
726 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
727 if (!WDRootMenu
->dictionary
) {
728 wwarning(_("could not read domain \"%s\" from defaults database"), "WMRootMenu");
730 wDefaultsMergeGlobalMenus(WDRootMenu
);
732 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
733 if (!WDWindowAttributes
->dictionary
) {
734 wwarning(_("could not read domain \"%s\" from defaults database"), "WMWindowAttributes");
737 XSetErrorHandler((XErrorHandler
) catchXError
);
741 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
744 #ifdef KEEP_XKB_LOCK_STATUS
745 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
746 if (wPreferences
.modelock
&& !wXkbSupported
) {
747 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
748 wPreferences
.modelock
= 0;
752 if (defaultScreenOnly
) {
755 max
= ScreenCount(dpy
);
757 wScreen
= wmalloc(sizeof(WScreen
*) * max
);
761 /* manage the screens */
762 for (j
= 0; j
< max
; j
++) {
763 if (defaultScreenOnly
|| max
== 1) {
764 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
765 if (!wScreen
[wScreenCount
]) {
766 wfatal(_("it seems that there is already a window manager running"));
770 wScreen
[wScreenCount
] = wScreenInit(j
);
771 if (!wScreen
[wScreenCount
]) {
772 wwarning(_("could not manage screen %i"), j
);
780 InitializeSwitchMenu();
783 /* initialize/restore state for the screens */
784 for (j
= 0; j
< wScreenCount
; j
++) {
787 lastDesktop
= wNETWMGetCurrentDesktopFromHint(wScreen
[j
]);
789 wScreenRestoreState(wScreen
[j
]);
791 /* manage all windows that were already here before us */
792 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
793 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
795 manageAllWindows(wScreen
[j
], wPreferences
.flags
.restarting
== 2);
797 /* restore saved menus */
798 wMenuRestoreState(wScreen
[j
]);
800 /* If we're not restarting, restore session */
801 if (wPreferences
.flags
.restarting
== 0 && !wPreferences
.flags
.norestore
)
802 wSessionRestoreState(wScreen
[j
]);
804 if (!wPreferences
.flags
.noautolaunch
) {
805 /* auto-launch apps */
806 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
807 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
808 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
810 /* auto-launch apps in clip */
811 if (!wPreferences
.flags
.noclip
) {
813 for (i
= 0; i
< wScreen
[j
]->workspace_count
; i
++) {
814 if (wScreen
[j
]->workspaces
[i
]->clip
) {
815 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
816 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
822 /* go to workspace where we were before restart */
823 if (lastDesktop
>= 0) {
824 wWorkspaceForceChange(wScreen
[j
], lastDesktop
);
826 wSessionRestoreLastWorkspace(wScreen
[j
]);
830 if (wScreenCount
== 0) {
831 wfatal(_("could not manage any screen"));
837 static Bool
windowInList(Window window
, Window
* list
, int count
)
839 for (; count
>= 0; count
--) {
840 if (window
== list
[count
])
847 *-----------------------------------------------------------------------
849 * Manages all windows in the screen.
852 * Called when the wm is being started.
853 * No events can be processed while the windows are being
854 * reparented/managed.
855 *-----------------------------------------------------------------------
857 static void manageAllWindows(WScreen
* scr
, int crashRecovery
)
861 unsigned int nchildren
;
866 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
868 scr
->flags
.startup
= 1;
870 /* first remove all icon windows */
871 for (i
= 0; i
< nchildren
; i
++) {
874 if (children
[i
] == None
)
877 wmhints
= XGetWMHints(dpy
, children
[i
]);
878 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
879 for (j
= 0; j
< nchildren
; j
++) {
880 if (children
[j
] == wmhints
->icon_window
) {
893 for (i
= 0; i
< nchildren
; i
++) {
894 if (children
[i
] == None
)
897 wwin
= wManageWindow(scr
, children
[i
]);
899 /* apply states got from WSavedState */
900 /* shaded + minimized is not restored correctly */
901 if (wwin
->flags
.shaded
) {
902 wwin
->flags
.shaded
= 0;
905 if (wwin
->flags
.miniaturized
906 && (wwin
->transient_for
== None
907 || wwin
->transient_for
== scr
->root_win
908 || !windowInList(wwin
->transient_for
, children
, nchildren
))) {
910 wwin
->flags
.skip_next_animation
= 1;
911 wwin
->flags
.miniaturized
= 0;
912 wIconifyWindow(wwin
);
914 wClientSetState(wwin
, NormalState
, None
);
919 border
= (!HAS_BORDER(wwin
) ? 0 : FRAME_BORDER_WIDTH
);
921 wWindowMove(wwin
, wwin
->frame_x
- border
,
922 wwin
->frame_y
- border
-
923 (wwin
->frame
->titlebar
? wwin
->frame
->titlebar
->height
: 0));
930 wwin
= scr
->focused_window
;
932 if (wwin
->flags
.hidden
) {
933 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
936 wwin
->flags
.hidden
= 0;
937 wHideApplication(wapp
);
939 wwin
->flags
.hidden
= 0;
946 scr
->flags
.startup
= 0;
947 scr
->flags
.startup2
= 1;
949 while (XPending(dpy
)) {
951 WMNextEvent(dpy
, &ev
);
954 wWorkspaceForceChange(scr
, 0);
955 if (!wPreferences
.flags
.noclip
)
956 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
957 scr
->flags
.startup2
= 0;