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,
32 #include <sys/signal.h>
36 #include <X11/Xutil.h>
37 #include <X11/Intrinsic.h>
38 #include <X11/cursorfont.h>
39 #include <X11/Xproto.h>
40 #include <X11/keysym.h>
42 #include <X11/extensions/shape.h>
45 #include "WindowMaker.h"
54 #include "workspace.h"
59 #include "properties.h"
72 #ifdef SYS_SIGLIST_DECLARED
73 extern const char * const sys_siglist
[];
82 /* Just in case, for weirdo systems */
87 /****** Global Variables ******/
89 extern WPreferences wPreferences
;
91 extern WDDomain
*WDWindowMaker
;
92 extern WDDomain
*WDRootMenu
;
93 extern WDDomain
*WDWindowAttributes
;
95 extern WShortKey wKeyBindings
[WKBD_LAST
];
97 extern int wScreenCount
;
101 extern Bool wShapeSupported
;
102 extern int wShapeEventBase
;
105 #ifdef KEEP_XKB_LOCK_STATUS
106 extern Bool wXkbSupported
;
107 extern int wXkbEventBase
;
111 extern XContext wWinContext
;
112 extern XContext wAppWinContext
;
113 extern XContext wStackContext
;
116 extern Atom _XA_WM_STATE
;
117 extern Atom _XA_WM_CHANGE_STATE
;
118 extern Atom _XA_WM_PROTOCOLS
;
119 extern Atom _XA_WM_TAKE_FOCUS
;
120 extern Atom _XA_WM_DELETE_WINDOW
;
121 extern Atom _XA_WM_SAVE_YOURSELF
;
122 extern Atom _XA_WM_CLIENT_LEADER
;
123 extern Atom _XA_WM_COLORMAP_WINDOWS
;
124 extern Atom _XA_WM_COLORMAP_NOTIFY
;
126 extern Atom _XA_GNUSTEP_WM_ATTR
;
128 extern Atom _XA_WINDOWMAKER_MENU
;
129 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
130 extern Atom _XA_WINDOWMAKER_STATE
;
131 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
132 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
133 extern Atom _XA_WINDOWMAKER_COMMAND
;
134 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
135 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
137 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
138 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
141 extern Atom _XA_DND_PROTOCOL
;
142 extern Atom _XA_DND_SELECTION
;
147 extern Cursor wCursor
[WCUR_LAST
];
150 extern char WDelayedActionSet
;
154 static WScreen
**wScreen
= NULL
;
157 static unsigned int _NumLockMask
= 0;
158 static unsigned int _ScrollLockMask
= 0;
162 static void manageAllWindows();
164 extern void NotifyDeadProcess(pid_t pid
, unsigned char status
);
168 catchXError(Display
*dpy
, XErrorEvent
*error
)
170 char buffer
[MAXLINE
];
172 /* ignore some errors */
173 if (error
->resourceid
!= None
174 && ((error
->error_code
== BadDrawable
175 && error
->request_code
== X_GetGeometry
)
176 || (error
->error_code
== BadMatch
177 && (error
->request_code
== X_SetInputFocus
))
178 || (error
->error_code
== BadWindow
)
180 && (error->request_code == X_GetWindowAttributes
181 || error->request_code == X_SetInputFocus
182 || error->request_code == X_ChangeWindowAttributes
183 || error->request_code == X_GetProperty
184 || error->request_code == X_ChangeProperty
185 || error->request_code == X_QueryTree
186 || error->request_code == X_GrabButton
187 || error->request_code == X_UngrabButton
188 || error->request_code == X_SendEvent
189 || error->request_code == X_ConfigureWindow))
191 || (error
->request_code
== X_InstallColormap
))) {
196 printf("got X error %x %x %x\n", error
->request_code
,
197 error
->error_code
, (unsigned)error
->resourceid
);
201 FormatXError(dpy
, error
, buffer
, MAXLINE
);
202 wwarning(_("internal X error: %s\n"), buffer
);
208 *----------------------------------------------------------------------
210 * Handle X shutdowns and other stuff.
211 *----------------------------------------------------------------------
214 handleXIO(Display
*xio_dpy
)
223 *----------------------------------------------------------------------
225 * Action to be executed after the signal() handler is exited.
226 *----------------------------------------------------------------------
229 delayedAction(void *cdata
)
231 if (WDelatedActionSet
== 0)
233 WDelayedActionSet
= 0;
235 * Make the event dispatcher do whatever it needs to do,
236 * including handling zombie processes, restart and exit
244 *----------------------------------------------------------------------
246 * User generated exit signal handler.
247 *----------------------------------------------------------------------
250 handleExitSig(int sig
)
255 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
257 if (sig
== SIGUSR1
) {
258 #ifdef SYS_SIGLIST_DECLARED
259 wwarning(_("got signal %i (%s) - restarting\n"), sig
, sys_siglist
[sig
]);
261 wwarning(_("got signal %i - restarting\n"), sig
);
264 SIG_WCHANGE_STATE(WSTATE_NEED_RESTART
);
265 /* setup idle handler, so that this will be handled when
266 * the select() is returned becaused of the signal, even if
267 * there are no X events in the queue */
268 WDelayedActionSet
= 1;
269 } else if (sig
== SIGUSR2
) {
270 #ifdef SYS_SIGLIST_DECLARED
271 wwarning(_("got signal %i (%s) - rereading defaults\n"), sig
, sys_siglist
[sig
]);
273 wwarning(_("got signal %i - rereading defaults\n"), sig
);
276 SIG_WCHANGE_STATE(WSTATE_NEED_REREAD
);
277 /* setup idle handler, so that this will be handled when
278 * the select() is returned becaused of the signal, even if
279 * there are no X events in the queue */
280 WDelayedActionSet
= 1;
281 } else if (sig
== SIGINT
|| sig
== SIGHUP
) {
282 #ifdef SYS_SIGLIST_DECLARED
283 wwarning(_("got signal %i (%s) - exiting...\n"), sig
, sys_siglist
[sig
]);
285 wwarning(_("got signal %i - exiting...\n"), sig
);
288 SIG_WCHANGE_STATE(WSTATE_NEED_EXIT
);
290 WDelayedActionSet
= 1;
293 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
297 *----------------------------------------------------------------------
299 * general signal handler. Exits the program gently.
300 *----------------------------------------------------------------------
305 static int already_crashed
= 0;
307 #ifndef NO_EMERGENCY_AUTORESTART
315 * No functions that potentially do Xlib calls should be called from
316 * here. Xlib calls are not reentrant so the integrity of Xlib is
317 * not guaranteed if a Xlib call is made from a signal handler.
320 #ifdef SYS_SIGLIST_DECLARED
321 wfatal(_("got signal %i (%s)\n"), sig
, sys_siglist
[sig
]);
323 wfatal(_("got signal %i\n"), sig
);
326 /* Setting the signal behaviour back to default and then reraising the
327 * signal is a cleaner way to make program exit and core dump than calling
328 * abort(), since it correctly returns from the signal handler and sets
329 * the flags accordingly. -Dan
331 if (sig
==SIGSEGV
|| sig
==SIGFPE
|| sig
==SIGBUS
|| sig
==SIGILL
333 if (already_crashed
) {
334 wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly."));
335 signal(sig
, SIG_DFL
);
344 * Yeah, we shouldn't do this, but it's already crashed anyway :P
347 #ifndef NO_EMERGENCY_AUTORESTART
348 /* Close the X connection and open a new one. This is to avoid messing
349 * Xlib because we call to Xlib functions in a signal handler.
353 dpy
= XOpenDisplay("");
356 crashAction
= wShowCrashingDialogPanel(sig
);
360 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
361 crashAction
= WMAbort
;
364 if (crashAction
== WMAbort
) {
365 signal(sig
, SIG_DFL
);
370 if (crashAction
== WMRestart
) {
371 /* we try to restart Window Maker */
372 wmessage(_("trying to restart Window Maker..."));
373 Restart(NULL
, False
);
374 /* fallback to alternate window manager then */
377 wmessage(_("trying to start alternate window manager..."));
379 Restart(FALLBACK_WINDOWMANAGER
, False
);
380 Restart("fvwm", False
);
381 Restart("twm", False
);
382 wfatal(_("failed to start alternate window manager. Aborting."));
384 wfatal(_("a fatal error has occured, probably due to a bug. "
385 "Please fill the included BUGFORM and report it."));
386 #endif /* !NO_EMERGENCY_AUTORESTART */
388 signal(sig
, SIG_DFL
);
403 int save_errno
= errno
;
407 /* Block signals so that NotifyDeadProcess() doesn't get fux0red */
408 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
411 /* If 2 or more kids exit in a small time window, before this handler gets
412 * the chance to get invoked, the SIGCHLD signals will be merged and only
413 * one SIGCHLD signal will be sent to us. We use a while loop to get all
414 * exited child status because we can't count on the number of SIGCHLD
415 * signals to know exactly how many kids have exited. -Dan
417 while ((pid
=waitpid(-1, &status
, WNOHANG
))>0 || (pid
<0 && errno
==EINTR
)) {
418 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
421 WDelayedActionSet
= 1;
423 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
430 getWorkspaceState(Window root
, WWorkspaceState
**state
)
434 unsigned long nitems_ret
;
435 unsigned long bytes_after_ret
;
438 if (XGetWindowProperty(dpy
, root
, _XA_WINDOWMAKER_STATE
, 0, 2,
439 True
, _XA_WINDOWMAKER_STATE
,
440 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
441 (unsigned char **)&data
)!=Success
|| !data
)
444 *state
= malloc(sizeof(WWorkspaceState
));
446 (*state
)->flags
= data
[0];
447 (*state
)->workspace
= data
[1];
451 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
459 getOffendingModifiers()
462 XModifierKeymap
*modmap
;
463 KeyCode nlock
, slock
;
464 static int mask_table
[8] = {
465 ShiftMask
,LockMask
,ControlMask
,Mod1Mask
,
466 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
469 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
470 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
473 * Find out the masks for the NumLock and ScrollLock modifiers,
474 * so that we can bind the grabs for when they are enabled too.
476 modmap
= XGetModifierMapping(dpy
);
478 if (modmap
!=NULL
&& modmap
->max_keypermod
>0) {
479 for (i
=0; i
<8*modmap
->max_keypermod
; i
++) {
480 if (modmap
->modifiermap
[i
]==nlock
&& nlock
!=0)
481 _NumLockMask
= mask_table
[i
/modmap
->max_keypermod
];
482 else if (modmap
->modifiermap
[i
]==slock
&& slock
!=0)
483 _ScrollLockMask
= mask_table
[i
/modmap
->max_keypermod
];
488 XFreeModifiermap(modmap
);
495 wHackedGrabKey(int keycode
, unsigned int modifiers
,
496 Window grab_window
, Bool owner_events
, int pointer_mode
,
499 if (modifiers
== AnyModifier
)
502 /* grab all combinations of the modifier with CapsLock, NumLock and
503 * ScrollLock. How much memory/CPU does such a monstrosity consume
507 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
,
508 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
510 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
,
511 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
512 if (_NumLockMask
&& _ScrollLockMask
)
513 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
,
514 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
516 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|LockMask
,
517 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
519 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
|LockMask
,
520 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
521 if (_NumLockMask
&& _ScrollLockMask
)
522 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
523 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
524 /* phew, I guess that's all, right? */
529 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
530 Window grab_window
, Bool owner_events
,
531 unsigned int event_mask
, int pointer_mode
,
532 int keyboard_mode
, Window confine_to
, Cursor cursor
)
534 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
535 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
537 if (modifiers
==AnyModifier
)
540 XGrabButton(dpy
, button
, modifiers
|LockMask
, grab_window
, owner_events
,
541 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
544 /* same as above, but for mouse buttons */
546 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
,
547 grab_window
, owner_events
, event_mask
, pointer_mode
,
548 keyboard_mode
, confine_to
, cursor
);
550 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
551 grab_window
, owner_events
, event_mask
, pointer_mode
,
552 keyboard_mode
, confine_to
, cursor
);
553 if (_NumLockMask
&& _ScrollLockMask
)
554 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
,
555 grab_window
, owner_events
, event_mask
, pointer_mode
,
556 keyboard_mode
, confine_to
, cursor
);
558 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
559 grab_window
, owner_events
, event_mask
, pointer_mode
,
560 keyboard_mode
, confine_to
, cursor
);
562 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
563 grab_window
, owner_events
, event_mask
, pointer_mode
,
564 keyboard_mode
, confine_to
, cursor
);
565 if (_NumLockMask
&& _ScrollLockMask
)
566 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
|LockMask
,
567 grab_window
, owner_events
, event_mask
, pointer_mode
,
568 keyboard_mode
, confine_to
, cursor
);
569 #endif /* NUMLOCK_HACK */
574 wHackedUngrabButton(unsigned int button
, unsigned int modifiers
,
577 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
,
579 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
581 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
,
583 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
585 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
587 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
595 wScreenWithNumber(int i
)
597 assert(i
< wScreenCount
);
604 wScreenForRootWindow(Window window
)
612 * Since the number of heads will probably be small (normally 2),
613 * it should be faster to use this than a hash table, because
616 for (i
=0; i
<wScreenCount
; i
++) {
617 if (wScreen
[i
]->root_win
== window
) {
622 assert("bad_root_window" && 0);
629 wScreenSearchForRootWindow(Window window
)
637 * Since the number of heads will probably be small (normally 2),
638 * it should be faster to use this than a hash table, because
641 for (i
=0; i
<wScreenCount
; i
++) {
642 if (wScreen
[i
]->root_win
== window
) {
652 wScreenForWindow(Window window
)
654 XWindowAttributes attr
;
659 if (XGetWindowAttributes(dpy
, window
, &attr
)) {
660 return wScreenForRootWindow(attr
.root
);
666 static char *atomNames
[] = {
674 "WM_COLORMAP_WINDOWS",
675 "WM_COLORMAP_NOTIFY",
676 GNUSTEP_WM_ATTR_NAME
,
678 "_WINDOWMAKER_STATE",
679 "_WINDOWMAKER_WM_PROTOCOLS",
680 GNUSTEP_WM_MINIATURIZE_WINDOW
,
681 "_WINDOWMAKER_WM_FUNCTION",
682 "_WINDOWMAKER_NOTICEBOARD",
683 "_WINDOWMAKER_COMMAND",
684 "_WINDOWMAKER_ICON_SIZE",
685 "_WINDOWMAKER_ICON_TILE",
686 GNUSTEP_TITLEBAR_STATE
691 *----------------------------------------------------------
693 * starts the window manager and setup global data.
694 * Called from main() at startup.
697 * global data declared in main.c is initialized
698 *----------------------------------------------------------
701 StartUp(Bool defaultScreenOnly
)
703 WWorkspaceState
*ws_state
;
704 struct sigaction sig_action
;
706 Atom atom
[sizeof(atomNames
)/sizeof(char*)];
709 * Ignore CapsLock in modifiers
711 ValidModMask
= 0xff & ~LockMask
;
713 getOffendingModifiers();
715 * Ignore NumLock and ScrollLock too
717 ValidModMask
&= ~(_NumLockMask
|_ScrollLockMask
);
720 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
722 wWinContext
= XUniqueContext();
723 wAppWinContext
= XUniqueContext();
724 wStackContext
= XUniqueContext();
726 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False);*/
728 #ifdef HAVE_XINTERNATOMS
729 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
)/sizeof(char*),
735 for (i
= 0; i
< sizeof(atomNames
)/sizeof(char*); i
++) {
736 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
741 _XA_WM_STATE
= atom
[0];
742 _XA_WM_CHANGE_STATE
= atom
[1];
743 _XA_WM_PROTOCOLS
= atom
[2];
744 _XA_WM_TAKE_FOCUS
= atom
[3];
745 _XA_WM_DELETE_WINDOW
= atom
[4];
746 _XA_WM_SAVE_YOURSELF
= atom
[5];
747 _XA_WM_CLIENT_LEADER
= atom
[6];
748 _XA_WM_COLORMAP_WINDOWS
= atom
[7];
749 _XA_WM_COLORMAP_NOTIFY
= atom
[8];
751 _XA_GNUSTEP_WM_ATTR
= atom
[9];
753 _XA_WINDOWMAKER_MENU
= atom
[10];
754 _XA_WINDOWMAKER_STATE
= atom
[11];
756 _XA_WINDOWMAKER_WM_PROTOCOLS
= atom
[12];
758 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
= atom
[13];
760 _XA_WINDOWMAKER_WM_FUNCTION
= atom
[14];
762 _XA_WINDOWMAKER_NOTICEBOARD
= atom
[15];
764 _XA_WINDOWMAKER_COMMAND
= atom
[16];
766 _XA_WINDOWMAKER_ICON_SIZE
= atom
[17];
767 _XA_WINDOWMAKER_ICON_TILE
= atom
[18];
769 _XA_GNUSTEP_TITLEBAR_STATE
= atom
[19];
772 _XA_DND_SELECTION
= XInternAtom(dpy
, "DndSelection", False
);
773 _XA_DND_PROTOCOL
= XInternAtom(dpy
, "DndProtocol", False
);
776 wXDNDInitializeAtoms();
781 #ifdef DEFINABLE_CURSOR
782 wCursor
[WCUR_NORMAL
] = None
;
784 wCursor
[WCUR_NORMAL
] = XCreateFontCursor(dpy
, XC_left_ptr
);
786 wCursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
787 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
788 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
789 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
790 wCursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
791 wCursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
792 wCursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
793 wCursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
794 wCursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
795 wCursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
796 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
797 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
798 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name???*/
799 wCursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
801 /* signal handler stuff that gets called when a signal is caught */
802 WMAddEternalTimerHandler(500, delayedAction
, NULL
);
804 /* emergency exit... */
805 sig_action
.sa_handler
= handleSig
;
806 sigemptyset(&sig_action
.sa_mask
);
808 sig_action
.sa_flags
= SA_RESTART
;
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 sig_action
.sa_handler
= handleExitSig
;
817 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
820 sig_action
.sa_flags
= SA_RESTART
;
821 /* sigaction(SIGTERM, &sig_action, NULL);*/
822 sigaction(SIGINT
, &sig_action
, NULL
);
823 sigaction(SIGHUP
, &sig_action
, NULL
);
824 sigaction(SIGUSR1
, &sig_action
, NULL
);
825 sigaction(SIGUSR2
, &sig_action
, NULL
);
827 /* ignore dead pipe */
828 sig_action
.sa_handler
= SIG_IGN
;
829 sig_action
.sa_flags
= SA_RESTART
;
830 sigaction(SIGPIPE
, &sig_action
, NULL
);
832 /* handle dead children */
833 sig_action
.sa_handler
= buryChild
;
834 sig_action
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
835 sigaction(SIGCHLD
, &sig_action
, NULL
);
837 /* Now we unblock all signals, that may have been blocked by the parent
838 * who exec()-ed us. This can happen for example if Window Maker crashes
839 * and restarts itself or another window manager from the signal handler.
840 * In this case, the new proccess inherits the blocked signal mask and
841 * will no longer react to that signal, until unblocked.
842 * This is because the signal handler of the proccess who crashed (parent)
843 * didn't return, and the signal remained blocked. -Dan
845 sigfillset(&sig_action
.sa_mask
);
846 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
848 /* handle X shutdowns a such */
849 XSetIOErrorHandler(handleXIO
);
851 /* set hook for out event dispatcher in WINGs event dispatcher */
852 WMHookEventHandler(DispatchEvent
);
854 /* initialize defaults stuff */
855 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
856 if (!WDWindowMaker
->dictionary
) {
857 wwarning(_("could not read domain \"%s\" from defaults database"),
861 /* read defaults that don't change until a restart and are
862 * screen independent */
863 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
865 /* check sanity of some values */
866 if (wPreferences
.icon_size
< 16) {
867 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
868 wPreferences
.icon_size
);
869 wPreferences
.icon_size
= 16;
872 /* init other domains */
873 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
874 if (!WDRootMenu
->dictionary
) {
875 wwarning(_("could not read domain \"%s\" from defaults database"),
879 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
880 if (!WDWindowAttributes
->dictionary
) {
881 wwarning(_("could not read domain \"%s\" from defaults database"),
882 "WMWindowAttributes");
885 XSetErrorHandler((XErrorHandler
)catchXError
);
889 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
892 #ifdef KEEP_XKB_LOCK_STATUS
893 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
894 if(wPreferences
.modelock
&& !wXkbSupported
) {
895 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
896 wPreferences
.modelock
= 0;
900 if (defaultScreenOnly
) {
903 max
= ScreenCount(dpy
);
905 wScreen
= wmalloc(sizeof(WScreen
*)*max
);
909 /* manage the screens */
910 for (j
= 0; j
< max
; j
++) {
911 if (defaultScreenOnly
|| max
==1) {
912 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
913 if (!wScreen
[wScreenCount
]) {
914 wfatal(_("it seems that there is already a window manager running"));
918 wScreen
[wScreenCount
] = wScreenInit(j
);
919 if (!wScreen
[wScreenCount
]) {
920 wwarning(_("could not manage screen %i"), j
);
927 /* initialize/restore state for the screens */
928 for (j
= 0; j
< wScreenCount
; j
++) {
929 /* restore workspace state */
930 if (!getWorkspaceState(wScreen
[j
]->root_win
, &ws_state
)) {
934 wScreenRestoreState(wScreen
[j
]);
936 /* manage all windows that were already here before us */
937 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
938 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
940 manageAllWindows(wScreen
[j
]);
942 /* restore saved menus */
943 wMenuRestoreState(wScreen
[j
]);
945 /* If we're not restarting restore session */
946 if (ws_state
== NULL
&& !wPreferences
.flags
.norestore
)
947 wSessionRestoreState(wScreen
[j
]);
949 if (!wPreferences
.flags
.noautolaunch
) {
950 /* auto-launch apps */
951 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
952 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
953 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
955 /* auto-launch apps in clip */
956 if (!wPreferences
.flags
.noclip
) {
958 for(i
=0; i
<wScreen
[j
]->workspace_count
; i
++) {
959 if (wScreen
[j
]->workspaces
[i
]->clip
) {
960 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
961 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
967 /* go to workspace where we were before restart */
969 wWorkspaceForceChange(wScreen
[j
], ws_state
->workspace
);
972 wSessionRestoreLastWorkspace(wScreen
[j
]);
976 wKWMSetInitializedHint(wScreen
[j
]);
980 if (wScreenCount
== 0) {
981 wfatal(_("could not manage any screen"));
985 if (!wPreferences
.flags
.nopolling
&& !wPreferences
.flags
.noupdates
) {
986 /* setup defaults file polling */
987 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
995 windowInList(Window window
, Window
*list
, int count
)
997 for (; count
>=0; count
--) {
998 if (window
== list
[count
])
1005 *-----------------------------------------------------------------------
1006 * manageAllWindows--
1007 * Manages all windows in the screen.
1010 * Called when the wm is being started.
1011 * No events can be processed while the windows are being
1012 * reparented/managed.
1013 *-----------------------------------------------------------------------
1016 manageAllWindows(WScreen
*scr
)
1018 Window root
, parent
;
1020 unsigned int nchildren
;
1025 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
1027 scr
->flags
.startup
= 1;
1029 /* first remove all icon windows */
1030 for (i
= 0; i
< nchildren
; i
++) {
1033 if (children
[i
]==None
)
1036 wmhints
= XGetWMHints(dpy
, children
[i
]);
1037 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
1038 for (j
= 0; j
< nchildren
; j
++) {
1039 if (children
[j
] == wmhints
->icon_window
) {
1053 for (i
= 0; i
< nchildren
; i
++) {
1054 if (children
[i
] == None
)
1058 wKWMCheckModule(scr
, children
[i
]);
1060 wwin
= wManageWindow(scr
, children
[i
]);
1062 /* apply states got from WSavedState */
1063 /* shaded + minimized is not restored correctly */
1064 if (wwin
->flags
.shaded
) {
1065 wwin
->flags
.shaded
= 0;
1068 if (wwin
->flags
.miniaturized
1069 && (wwin
->transient_for
== None
1070 || wwin
->transient_for
== scr
->root_win
1071 || !windowInList(wwin
->transient_for
, children
,
1074 wwin
->flags
.skip_next_animation
= 1;
1075 wwin
->flags
.miniaturized
= 0;
1076 wIconifyWindow(wwin
);
1078 wClientSetState(wwin
, NormalState
, None
);
1085 wwin
= scr
->focused_window
;
1087 if (wwin
->flags
.hidden
) {
1088 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1091 wwin
->flags
.hidden
= 0;
1092 wHideApplication(wapp
);
1094 wwin
->flags
.hidden
= 0;
1101 scr
->flags
.startup
= 0;
1102 scr
->flags
.startup2
= 1;
1104 while (XPending(dpy
)) {
1106 WMNextEvent(dpy
, &ev
);
1109 wWorkspaceForceChange(scr
, 0);
1110 if (!wPreferences
.flags
.noclip
)
1111 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
1112 scr
->flags
.startup2
= 0;