2 * Window Maker window manager
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 * Copyright (c) 1999 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,
31 #include <sys/signal.h>
35 #include <X11/Xutil.h>
36 #include <X11/Intrinsic.h>
37 #include <X11/cursorfont.h>
38 #include <X11/Xproto.h>
39 #include <X11/keysym.h>
41 #include <X11/extensions/shape.h>
44 #include "WindowMaker.h"
53 #include "workspace.h"
58 #include "properties.h"
71 #ifdef SYS_SIGLIST_DECLARED
72 extern const char * const sys_siglist
[];
81 /* Just in case, for weirdo systems */
86 /****** Global Variables ******/
88 extern WPreferences wPreferences
;
90 extern WDDomain
*WDWindowMaker
;
91 extern WDDomain
*WDRootMenu
;
92 extern WDDomain
*WDWindowAttributes
;
94 extern WShortKey wKeyBindings
[WKBD_LAST
];
96 extern int wScreenCount
;
100 extern Bool wShapeSupported
;
101 extern int wShapeEventBase
;
104 #ifdef KEEP_XKB_LOCK_STATUS
105 extern Bool wXkbSupported
;
106 extern int wXkbEventBase
;
110 extern XContext wWinContext
;
111 extern XContext wAppWinContext
;
112 extern XContext wStackContext
;
115 extern Atom _XA_WM_STATE
;
116 extern Atom _XA_WM_CHANGE_STATE
;
117 extern Atom _XA_WM_PROTOCOLS
;
118 extern Atom _XA_WM_TAKE_FOCUS
;
119 extern Atom _XA_WM_DELETE_WINDOW
;
120 extern Atom _XA_WM_SAVE_YOURSELF
;
121 extern Atom _XA_WM_CLIENT_LEADER
;
122 extern Atom _XA_WM_COLORMAP_WINDOWS
;
123 extern Atom _XA_WM_COLORMAP_NOTIFY
;
125 extern Atom _XA_GNUSTEP_WM_ATTR
;
127 extern Atom _XA_WINDOWMAKER_MENU
;
128 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
129 extern Atom _XA_WINDOWMAKER_STATE
;
130 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
131 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
132 extern Atom _XA_WINDOWMAKER_COMMAND
;
133 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
134 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
136 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
137 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
140 extern Atom _XA_DND_PROTOCOL
;
141 extern Atom _XA_DND_SELECTION
;
146 extern Cursor wCursor
[WCUR_LAST
];
149 extern char WDelayedActionSet
;
153 static WScreen
**wScreen
= NULL
;
156 static unsigned int _NumLockMask
= 0;
157 static unsigned int _ScrollLockMask
= 0;
161 static void manageAllWindows();
163 extern void NotifyDeadProcess(pid_t pid
, unsigned char status
);
167 catchXError(Display
*dpy
, XErrorEvent
*error
)
169 char buffer
[MAXLINE
];
171 /* ignore some errors */
172 if (error
->resourceid
!= None
173 && ((error
->error_code
== BadDrawable
174 && error
->request_code
== X_GetGeometry
)
175 || (error
->error_code
== BadMatch
176 && (error
->request_code
== X_SetInputFocus
))
177 || (error
->error_code
== BadWindow
)
179 && (error->request_code == X_GetWindowAttributes
180 || error->request_code == X_SetInputFocus
181 || error->request_code == X_ChangeWindowAttributes
182 || error->request_code == X_GetProperty
183 || error->request_code == X_ChangeProperty
184 || error->request_code == X_QueryTree
185 || error->request_code == X_GrabButton
186 || error->request_code == X_UngrabButton
187 || error->request_code == X_SendEvent
188 || error->request_code == X_ConfigureWindow))
190 || (error
->request_code
== X_InstallColormap
))) {
195 printf("got X error %x %x %x\n", error
->request_code
,
196 error
->error_code
, (unsigned)error
->resourceid
);
200 FormatXError(dpy
, error
, buffer
, MAXLINE
);
201 wwarning(_("internal X error: %s\n"), buffer
);
207 *----------------------------------------------------------------------
209 * Handle X shutdowns and other stuff.
210 *----------------------------------------------------------------------
213 handleXIO(Display
*xio_dpy
)
222 *----------------------------------------------------------------------
224 * Action to be executed after the signal() handler is exited.
225 *----------------------------------------------------------------------
228 delayedAction(void *cdata
)
230 WDelayedActionSet
= 0;
232 * Make the event dispatcher do whatever it needs to do,
233 * including handling zombie processes, restart and exit
242 *----------------------------------------------------------------------
244 * general signal handler. Exits the program gently.
245 *----------------------------------------------------------------------
250 static int already_crashed
= 0;
252 #ifndef NO_EMERGENCY_AUTORESTART
260 * No functions that potentially do Xlib calls should be called from
261 * here. Xlib calls are not reentrant so the integrity of Xlib is
262 * not guaranteed if a Xlib call is made from a signal handler.
264 if (sig
== SIGUSR1
) {
265 #ifdef SYS_SIGLIST_DECLARED
266 wwarning(_("got signal %i (%s) - restarting\n"), sig
, sys_siglist
[sig
]);
268 wwarning(_("got signal %i - restarting\n"), sig
);
271 WCHANGE_STATE(WSTATE_NEED_RESTART
);
272 /* setup idle handler, so that this will be handled when
273 * the select() is returned becaused of the signal, even if
274 * there are no X events in the queue */
275 if (!WDelayedActionSet
) {
276 WDelayedActionSet
= 1;
277 WMAddIdleHandler(delayedAction
, NULL
);
280 } else if (sig
== SIGTERM
|| sig
== SIGHUP
) {
281 #ifdef SYS_SIGLIST_DECLARED
282 wwarning(_("got signal %i (%s) - exiting...\n"), sig
, sys_siglist
[sig
]);
284 wwarning(_("got signal %i - exiting...\n"), sig
);
287 WCHANGE_STATE(WSTATE_NEED_EXIT
);
289 if (!WDelayedActionSet
) {
290 WDelayedActionSet
= 1;
291 WMAddIdleHandler(delayedAction
, NULL
);
296 #ifdef SYS_SIGLIST_DECLARED
297 wfatal(_("got signal %i (%s)\n"), sig
, sys_siglist
[sig
]);
299 wfatal(_("got signal %i\n"), sig
);
302 /* Setting the signal behaviour back to default and then reraising the
303 * signal is a cleaner way to make program exit and core dump than calling
304 * abort(), since it correctly returns from the signal handler and sets
305 * the flags accordingly. -Dan
307 if (sig
==SIGSEGV
|| sig
==SIGFPE
|| sig
==SIGBUS
|| sig
==SIGILL
309 if (already_crashed
) {
310 wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly."));
311 signal(sig
, SIG_DFL
);
319 #ifndef NO_EMERGENCY_AUTORESTART
320 /* Close the X connection and open a new one. This is to avoid messing
321 * Xlib because we call to Xlib functions in a signal handler.
325 dpy
= XOpenDisplay("");
328 crashAction
= wShowCrashingDialogPanel(sig
);
332 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
333 crashAction
= WMAbort
;
336 if (crashAction
== WMAbort
) {
337 signal(sig
, SIG_DFL
);
342 if (crashAction
== WMRestart
) {
343 /* we try to restart Window Maker */
344 wmessage(_("trying to restart Window Maker..."));
345 Restart(NULL
, False
);
346 /* fallback to alternate window manager then */
349 wmessage(_("trying to start alternate window manager..."));
351 Restart(FALLBACK_WINDOWMANAGER
, False
);
352 Restart("fvwm", False
);
353 Restart("twm", False
);
354 wfatal(_("failed to start alternate window manager. Aborting."));
356 wfatal(_("a fatal error has occured, probably due to a bug. "
357 "Please fill the included BUGFORM and report it."));
358 #endif /* !NO_EMERGENCY_AUTORESTART */
360 signal(sig
, SIG_DFL
);
371 ignoreSig(int signal
)
384 /* SIGCHLD's are blocked while we are in this signal handler, and if 2 or
385 * more kids exit while we handle the exit of one child in this handler
386 * (ie, about at the same time), we will miss the SIGCHLD signals the
387 * other kids will send and will be left with zombies. Using a while loop
388 * tries to avoid this (or at least minimize the probability), by calling
389 * waitpid until there are no more exited kids that respond.
390 * I think there is still a small probability that a a SIGCHLD signal can
391 * arrive after we finished the while loop, but before we return.
392 * Passing SA_NODEFER to the SIGCHLD handler doesn't seem to help at all,
393 * though tha man page sais that using this flag should allow receival of
394 * other SIGCHLD signals while processing one. Why is this? -Dan
396 * There seem to be SA_NOCLDWAIT, but I'm not sure its available on all
397 * platforms, and its possible that even if it will prevent zombie
398 * generation, it may also prevent us from receiving the exit status
399 * of our kids (I'm not sure, because the man page doesn't state this
402 * Maybe the best way would be to forget about SA_NODEFER and do it the
403 * old way: unblock SIGCHLD immediately after we entered this handler,
404 * then call waitpid in a while loop to get the exit status of all kids
405 * that exited while SIGCHLD was blocked and we missed the signal.
406 * This way there is no way we can miss any kid, because the while loop
407 * takes care of signals that were missed before we reenabled SIGCHLD
408 * and after enabling the signal, we we start getting them even if we
409 * are in the signal handler itself. Only need to check if it doesn't
410 * have any problem with reentrancy, but I don't think so. -Dan
412 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0) {
413 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
415 * Make sure that the kid will be buried even if there are
416 * no events in the X event queue
418 if (!WDelayedActionSet
) {
419 WDelayedActionSet
= 1;
420 WMAddIdleHandler(delayedAction
, NULL
);
427 getWorkspaceState(Window root
, WWorkspaceState
**state
)
431 unsigned long nitems_ret
;
432 unsigned long bytes_after_ret
;
435 if (XGetWindowProperty(dpy
, root
, _XA_WINDOWMAKER_STATE
, 0, 2,
436 True
, _XA_WINDOWMAKER_STATE
,
437 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
438 (unsigned char **)&data
)!=Success
|| !data
)
441 *state
= malloc(sizeof(WWorkspaceState
));
443 (*state
)->flags
= data
[0];
444 (*state
)->workspace
= data
[1];
448 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
456 getOffendingModifiers()
459 XModifierKeymap
*modmap
;
460 KeyCode nlock
, slock
;
461 static int mask_table
[8] = {
462 ShiftMask
,LockMask
,ControlMask
,Mod1Mask
,
463 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
466 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
467 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
470 * Find out the masks for the NumLock and ScrollLock modifiers,
471 * so that we can bind the grabs for when they are enabled too.
473 modmap
= XGetModifierMapping(dpy
);
475 if (modmap
!=NULL
&& modmap
->max_keypermod
>0) {
476 for (i
=0; i
<8*modmap
->max_keypermod
; i
++) {
477 if (modmap
->modifiermap
[i
]==nlock
&& nlock
!=0)
478 _NumLockMask
= mask_table
[i
/modmap
->max_keypermod
];
479 else if (modmap
->modifiermap
[i
]==slock
&& slock
!=0)
480 _ScrollLockMask
= mask_table
[i
/modmap
->max_keypermod
];
485 XFreeModifiermap(modmap
);
492 wHackedGrabKey(int keycode
, unsigned int modifiers
,
493 Window grab_window
, Bool owner_events
, int pointer_mode
,
496 if (modifiers
== AnyModifier
)
499 /* grab all combinations of the modifier with CapsLock, NumLock and
500 * ScrollLock. How much memory/CPU does such a monstrosity consume
504 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
,
505 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
507 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
,
508 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
509 if (_NumLockMask
&& _ScrollLockMask
)
510 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
,
511 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
513 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|LockMask
,
514 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
516 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
|LockMask
,
517 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
518 if (_NumLockMask
&& _ScrollLockMask
)
519 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
520 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
521 /* phew, I guess that's all, right? */
526 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
527 Window grab_window
, Bool owner_events
,
528 unsigned int event_mask
, int pointer_mode
,
529 int keyboard_mode
, Window confine_to
, Cursor cursor
)
531 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
532 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
534 if (modifiers
==AnyModifier
)
537 XGrabButton(dpy
, button
, modifiers
|LockMask
, grab_window
, owner_events
,
538 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
541 /* same as above, but for mouse buttons */
543 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
,
544 grab_window
, owner_events
, event_mask
, pointer_mode
,
545 keyboard_mode
, confine_to
, cursor
);
547 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
548 grab_window
, owner_events
, event_mask
, pointer_mode
,
549 keyboard_mode
, confine_to
, cursor
);
550 if (_NumLockMask
&& _ScrollLockMask
)
551 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
,
552 grab_window
, owner_events
, event_mask
, pointer_mode
,
553 keyboard_mode
, confine_to
, cursor
);
555 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
556 grab_window
, owner_events
, event_mask
, pointer_mode
,
557 keyboard_mode
, confine_to
, cursor
);
559 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
560 grab_window
, owner_events
, event_mask
, pointer_mode
,
561 keyboard_mode
, confine_to
, cursor
);
562 if (_NumLockMask
&& _ScrollLockMask
)
563 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
|LockMask
,
564 grab_window
, owner_events
, event_mask
, pointer_mode
,
565 keyboard_mode
, confine_to
, cursor
);
566 #endif /* NUMLOCK_HACK */
571 wHackedUngrabButton(unsigned int button
, unsigned int modifiers
,
574 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
,
576 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
578 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
,
580 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
582 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
584 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
592 wScreenWithNumber(int i
)
594 assert(i
< wScreenCount
);
601 wScreenForRootWindow(Window window
)
609 * Since the number of heads will probably be small (normally 2),
610 * it should be faster to use this than a hash table, because
613 for (i
=0; i
<wScreenCount
; i
++) {
614 if (wScreen
[i
]->root_win
== window
) {
619 assert("bad_root_window" && 0);
626 wScreenSearchForRootWindow(Window window
)
634 * Since the number of heads will probably be small (normally 2),
635 * it should be faster to use this than a hash table, because
638 for (i
=0; i
<wScreenCount
; i
++) {
639 if (wScreen
[i
]->root_win
== window
) {
649 wScreenForWindow(Window window
)
651 XWindowAttributes attr
;
656 if (XGetWindowAttributes(dpy
, window
, &attr
)) {
657 return wScreenForRootWindow(attr
.root
);
663 static char *atomNames
[] = {
671 "WM_COLORMAP_WINDOWS",
672 "WM_COLORMAP_NOTIFY",
673 GNUSTEP_WM_ATTR_NAME
,
675 "_WINDOWMAKER_STATE",
676 "_WINDOWMAKER_WM_PROTOCOLS",
677 GNUSTEP_WM_MINIATURIZE_WINDOW
,
678 "_WINDOWMAKER_WM_FUNCTION",
679 "_WINDOWMAKER_NOTICEBOARD",
680 "_WINDOWMAKER_COMMAND",
681 "_WINDOWMAKER_ICON_SIZE",
682 "_WINDOWMAKER_ICON_TILE",
683 GNUSTEP_TITLEBAR_STATE
688 *----------------------------------------------------------
690 * starts the window manager and setup global data.
691 * Called from main() at startup.
694 * global data declared in main.c is initialized
695 *----------------------------------------------------------
698 StartUp(Bool defaultScreenOnly
)
700 WWorkspaceState
*ws_state
;
701 struct sigaction sig_action
;
703 Atom atom
[sizeof(atomNames
)/sizeof(char*)];
706 * Ignore CapsLock in modifiers
708 ValidModMask
= 0xff & ~LockMask
;
710 getOffendingModifiers();
712 * Ignore NumLock and ScrollLock too
714 ValidModMask
&= ~(_NumLockMask
|_ScrollLockMask
);
717 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
719 wWinContext
= XUniqueContext();
720 wAppWinContext
= XUniqueContext();
721 wStackContext
= XUniqueContext();
723 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False);*/
725 #ifdef HAVE_XINTERNATOMS
726 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
)/sizeof(char*),
732 for (i
= 0; i
< sizeof(atomNames
)/sizeof(char*); i
++) {
733 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
738 _XA_WM_STATE
= atom
[0];
739 _XA_WM_CHANGE_STATE
= atom
[1];
740 _XA_WM_PROTOCOLS
= atom
[2];
741 _XA_WM_TAKE_FOCUS
= atom
[3];
742 _XA_WM_DELETE_WINDOW
= atom
[4];
743 _XA_WM_SAVE_YOURSELF
= atom
[5];
744 _XA_WM_CLIENT_LEADER
= atom
[6];
745 _XA_WM_COLORMAP_WINDOWS
= atom
[7];
746 _XA_WM_COLORMAP_NOTIFY
= atom
[8];
748 _XA_GNUSTEP_WM_ATTR
= atom
[9];
750 _XA_WINDOWMAKER_MENU
= atom
[10];
751 _XA_WINDOWMAKER_STATE
= atom
[11];
753 _XA_WINDOWMAKER_WM_PROTOCOLS
= atom
[12];
755 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
= atom
[13];
757 _XA_WINDOWMAKER_WM_FUNCTION
= atom
[14];
759 _XA_WINDOWMAKER_NOTICEBOARD
= atom
[15];
761 _XA_WINDOWMAKER_COMMAND
= atom
[16];
763 _XA_WINDOWMAKER_ICON_SIZE
= atom
[17];
764 _XA_WINDOWMAKER_ICON_TILE
= atom
[18];
766 _XA_GNUSTEP_TITLEBAR_STATE
= atom
[19];
769 _XA_DND_SELECTION
= XInternAtom(dpy
, "DndSelection", False
);
770 _XA_DND_PROTOCOL
= XInternAtom(dpy
, "DndProtocol", False
);
773 wXDNDInitializeAtoms();
778 #ifdef DEFINABLE_CURSOR
779 wCursor
[WCUR_NORMAL
] = None
;
781 wCursor
[WCUR_NORMAL
] = XCreateFontCursor(dpy
, XC_left_ptr
);
783 wCursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
784 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
785 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
786 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
787 wCursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
788 wCursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
789 wCursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
790 wCursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
791 wCursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
792 wCursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
793 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
794 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
795 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name???*/
796 wCursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
798 /* emergency exit... */
799 sig_action
.sa_handler
= handleSig
;
800 sigemptyset(&sig_action
.sa_mask
);
802 /* Here we don't care about SA_RESTART since these signals will close
805 sig_action
.sa_flags
= 0;
806 sigaction(SIGINT
, &sig_action
, NULL
);
807 sigaction(SIGTERM
, &sig_action
, NULL
);
808 sigaction(SIGHUP
, &sig_action
, NULL
);
809 sigaction(SIGQUIT
, &sig_action
, NULL
);
810 sigaction(SIGSEGV
, &sig_action
, NULL
);
811 sigaction(SIGBUS
, &sig_action
, NULL
);
812 sigaction(SIGFPE
, &sig_action
, NULL
);
813 sigaction(SIGABRT
, &sig_action
, NULL
);
815 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
818 sig_action
.sa_flags
= SA_RESTART
;
819 sigaction(SIGUSR1
, &sig_action
, NULL
);
821 /* ignore dead pipe */
822 sig_action
.sa_handler
= ignoreSig
;
823 sig_action
.sa_flags
= SA_RESTART
;
824 sigaction(SIGPIPE
, &sig_action
, NULL
);
826 /* handle dead children */
827 /* Using SA_NODEFER doesn't seem to have any effect. Why? -Dan */
828 sig_action
.sa_handler
= buryChild
;
829 sig_action
.sa_flags
= SA_NODEFER
|SA_NOCLDSTOP
|SA_RESTART
;
830 sigaction(SIGCHLD
, &sig_action
, NULL
);
832 /* Now we unblock all signals, that may have been blocked by the parent
833 * who exec()-ed us. This can happen for example if Window Maker crashes
834 * and restarts itself or another window manager from the signal handler.
835 * In this case, the new proccess inherits the blocked signal mask and
836 * will no longer react to that signal, until unblocked.
837 * This is because the signal handler of the proccess who crashed (parent)
838 * didn't return, and the signal remained blocked. -Dan
840 sigfillset(&sig_action
.sa_mask
);
841 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
843 /* handle X shutdowns a such */
844 XSetIOErrorHandler(handleXIO
);
846 /* set hook for out event dispatcher in WINGs event dispatcher */
847 WMHookEventHandler(DispatchEvent
);
849 /* initialize defaults stuff */
850 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
851 if (!WDWindowMaker
->dictionary
) {
852 wwarning(_("could not read domain \"%s\" from defaults database"),
856 /* read defaults that don't change until a restart and are
857 * screen independent */
858 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
860 /* check sanity of some values */
861 if (wPreferences
.icon_size
< 16) {
862 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
863 wPreferences
.icon_size
);
864 wPreferences
.icon_size
= 16;
867 /* init other domains */
868 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
869 if (!WDRootMenu
->dictionary
) {
870 wwarning(_("could not read domain \"%s\" from defaults database"),
874 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
875 if (!WDWindowAttributes
->dictionary
) {
876 wwarning(_("could not read domain \"%s\" from defaults database"),
877 "WMWindowAttributes");
880 XSetErrorHandler((XErrorHandler
)catchXError
);
884 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
887 #ifdef KEEP_XKB_LOCK_STATUS
888 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
889 if(wPreferences
.modelock
&& !wXkbSupported
) {
890 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
891 wPreferences
.modelock
= 0;
895 if (defaultScreenOnly
) {
898 max
= ScreenCount(dpy
);
900 wScreen
= wmalloc(sizeof(WScreen
*)*max
);
904 /* manage the screens */
905 for (j
= 0; j
< max
; j
++) {
906 if (defaultScreenOnly
|| max
==1) {
907 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
908 if (!wScreen
[wScreenCount
]) {
909 wfatal(_("it seems that there is already a window manager running"));
913 wScreen
[wScreenCount
] = wScreenInit(j
);
914 if (!wScreen
[wScreenCount
]) {
915 wwarning(_("could not manage screen %i"), j
);
922 /* initialize/restore state for the screens */
923 for (j
= 0; j
< wScreenCount
; j
++) {
924 /* restore workspace state */
925 if (!getWorkspaceState(wScreen
[j
]->root_win
, &ws_state
)) {
929 wScreenRestoreState(wScreen
[j
]);
931 /* manage all windows that were already here before us */
932 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
933 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
935 manageAllWindows(wScreen
[j
]);
937 /* restore saved menus */
938 wMenuRestoreState(wScreen
[j
]);
940 /* If we're not restarting restore session */
941 if (ws_state
== NULL
&& !wPreferences
.flags
.norestore
)
942 wSessionRestoreState(wScreen
[j
]);
944 if (!wPreferences
.flags
.noautolaunch
) {
945 /* auto-launch apps */
946 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
947 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
948 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
950 /* auto-launch apps in clip */
951 if (!wPreferences
.flags
.noclip
) {
953 for(i
=0; i
<wScreen
[j
]->workspace_count
; i
++) {
954 if (wScreen
[j
]->workspaces
[i
]->clip
) {
955 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
956 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
962 /* go to workspace where we were before restart */
964 wWorkspaceForceChange(wScreen
[j
], ws_state
->workspace
);
967 wSessionRestoreLastWorkspace(wScreen
[j
]);
971 wKWMSetInitializedHint(wScreen
[j
]);
975 if (wScreenCount
== 0) {
976 wfatal(_("could not manage any screen"));
980 if (!wPreferences
.flags
.noupdates
) {
981 /* setup defaults file polling */
982 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
990 windowInList(Window window
, Window
*list
, int count
)
992 for (; count
>=0; count
--) {
993 if (window
== list
[count
])
1000 *-----------------------------------------------------------------------
1001 * manageAllWindows--
1002 * Manages all windows in the screen.
1005 * Called when the wm is being started.
1006 * No events can be processed while the windows are being
1007 * reparented/managed.
1008 *-----------------------------------------------------------------------
1011 manageAllWindows(WScreen
*scr
)
1013 Window root
, parent
;
1015 unsigned int nchildren
;
1020 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
1022 scr
->flags
.startup
= 1;
1024 /* first remove all icon windows */
1025 for (i
= 0; i
< nchildren
; i
++) {
1028 if (children
[i
]==None
)
1031 wmhints
= XGetWMHints(dpy
, children
[i
]);
1032 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
1033 for (j
= 0; j
< nchildren
; j
++) {
1034 if (children
[j
] == wmhints
->icon_window
) {
1048 for (i
= 0; i
< nchildren
; i
++) {
1049 if (children
[i
] == None
)
1053 wKWMCheckModule(scr
, children
[i
]);
1055 wwin
= wManageWindow(scr
, children
[i
]);
1057 /* apply states got from WSavedState */
1058 /* shaded + minimized is not restored correctly */
1059 if (wwin
->flags
.shaded
) {
1060 wwin
->flags
.shaded
= 0;
1063 if (wwin
->flags
.miniaturized
1064 && (wwin
->transient_for
== None
1065 || wwin
->transient_for
== scr
->root_win
1066 || !windowInList(wwin
->transient_for
, children
,
1069 wwin
->flags
.skip_next_animation
= 1;
1070 wwin
->flags
.miniaturized
= 0;
1071 wIconifyWindow(wwin
);
1073 wClientSetState(wwin
, NormalState
, None
);
1080 wwin
= scr
->focused_window
;
1082 if (wwin
->flags
.hidden
) {
1083 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1086 wwin
->flags
.hidden
= 0;
1087 wHideApplication(wapp
);
1089 wwin
->flags
.hidden
= 0;
1096 scr
->flags
.startup
= 0;
1097 scr
->flags
.startup2
= 1;
1099 while (XPending(dpy
)) {
1101 WMNextEvent(dpy
, &ev
);
1104 wWorkspaceForceChange(scr
, 0);
1105 if (!wPreferences
.flags
.noclip
)
1106 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
1107 scr
->flags
.startup2
= 0;