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 WDelayedActionSet
= 0;
233 * Make the event dispatcher do whatever it needs to do,
234 * including handling zombie processes, restart and exit
243 *----------------------------------------------------------------------
245 * general signal handler. Exits the program gently.
246 *----------------------------------------------------------------------
251 static int already_crashed
= 0;
253 #ifndef NO_EMERGENCY_AUTORESTART
261 * No functions that potentially do Xlib calls should be called from
262 * here. Xlib calls are not reentrant so the integrity of Xlib is
263 * not guaranteed if a Xlib call is made from a signal handler.
265 if (sig
== SIGUSR1
) {
266 #ifdef SYS_SIGLIST_DECLARED
267 wwarning(_("got signal %i (%s) - restarting\n"), sig
, sys_siglist
[sig
]);
269 wwarning(_("got signal %i - restarting\n"), sig
);
272 WCHANGE_STATE(WSTATE_NEED_RESTART
);
273 /* setup idle handler, so that this will be handled when
274 * the select() is returned becaused of the signal, even if
275 * there are no X events in the queue */
276 if (!WDelayedActionSet
) {
277 WDelayedActionSet
= 1;
278 WMAddIdleHandler(delayedAction
, NULL
);
281 } else if (sig
== SIGTERM
|| 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 WCHANGE_STATE(WSTATE_NEED_EXIT
);
290 if (!WDelayedActionSet
) {
291 WDelayedActionSet
= 1;
292 WMAddIdleHandler(delayedAction
, NULL
);
297 #ifdef SYS_SIGLIST_DECLARED
298 wfatal(_("got signal %i (%s)\n"), sig
, sys_siglist
[sig
]);
300 wfatal(_("got signal %i\n"), sig
);
303 /* Setting the signal behaviour back to default and then reraising the
304 * signal is a cleaner way to make program exit and core dump than calling
305 * abort(), since it correctly returns from the signal handler and sets
306 * the flags accordingly. -Dan
308 if (sig
==SIGSEGV
|| sig
==SIGFPE
|| sig
==SIGBUS
|| sig
==SIGILL
310 if (already_crashed
) {
311 wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly."));
312 signal(sig
, SIG_DFL
);
320 #ifndef NO_EMERGENCY_AUTORESTART
321 /* Close the X connection and open a new one. This is to avoid messing
322 * Xlib because we call to Xlib functions in a signal handler.
326 dpy
= XOpenDisplay("");
329 crashAction
= wShowCrashingDialogPanel(sig
);
333 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
334 crashAction
= WMAbort
;
337 if (crashAction
== WMAbort
) {
338 signal(sig
, SIG_DFL
);
343 if (crashAction
== WMRestart
) {
344 /* we try to restart Window Maker */
345 wmessage(_("trying to restart Window Maker..."));
346 Restart(NULL
, False
);
347 /* fallback to alternate window manager then */
350 wmessage(_("trying to start alternate window manager..."));
352 Restart(FALLBACK_WINDOWMANAGER
, False
);
353 Restart("fvwm", False
);
354 Restart("twm", False
);
355 wfatal(_("failed to start alternate window manager. Aborting."));
357 wfatal(_("a fatal error has occured, probably due to a bug. "
358 "Please fill the included BUGFORM and report it."));
359 #endif /* !NO_EMERGENCY_AUTORESTART */
361 signal(sig
, SIG_DFL
);
372 ignoreSig(int signal
)
385 /* If 2 or more kids exit in a small time window, before this handler gets
386 * the chance to get invoked, the SIGCHLD signals will be merged and only
387 * one SIGCHLD signal will be sent to us. We use a while loop to get all
388 * exited child status because we can't count on the number of SIGCHLD
389 * signals to know exactly how many kids have exited. -Dan
391 while ((pid
=waitpid(-1, &status
, WNOHANG
))>0 || (pid
<0 && errno
==EINTR
)) {
392 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
394 * Make sure that the kid will be buried even if there are
395 * no events in the X event queue
397 if (!WDelayedActionSet
) {
398 WDelayedActionSet
= 1;
399 WMAddIdleHandler(delayedAction
, NULL
);
406 getWorkspaceState(Window root
, WWorkspaceState
**state
)
410 unsigned long nitems_ret
;
411 unsigned long bytes_after_ret
;
414 if (XGetWindowProperty(dpy
, root
, _XA_WINDOWMAKER_STATE
, 0, 2,
415 True
, _XA_WINDOWMAKER_STATE
,
416 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
417 (unsigned char **)&data
)!=Success
|| !data
)
420 *state
= malloc(sizeof(WWorkspaceState
));
422 (*state
)->flags
= data
[0];
423 (*state
)->workspace
= data
[1];
427 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
435 getOffendingModifiers()
438 XModifierKeymap
*modmap
;
439 KeyCode nlock
, slock
;
440 static int mask_table
[8] = {
441 ShiftMask
,LockMask
,ControlMask
,Mod1Mask
,
442 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
445 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
446 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
449 * Find out the masks for the NumLock and ScrollLock modifiers,
450 * so that we can bind the grabs for when they are enabled too.
452 modmap
= XGetModifierMapping(dpy
);
454 if (modmap
!=NULL
&& modmap
->max_keypermod
>0) {
455 for (i
=0; i
<8*modmap
->max_keypermod
; i
++) {
456 if (modmap
->modifiermap
[i
]==nlock
&& nlock
!=0)
457 _NumLockMask
= mask_table
[i
/modmap
->max_keypermod
];
458 else if (modmap
->modifiermap
[i
]==slock
&& slock
!=0)
459 _ScrollLockMask
= mask_table
[i
/modmap
->max_keypermod
];
464 XFreeModifiermap(modmap
);
471 wHackedGrabKey(int keycode
, unsigned int modifiers
,
472 Window grab_window
, Bool owner_events
, int pointer_mode
,
475 if (modifiers
== AnyModifier
)
478 /* grab all combinations of the modifier with CapsLock, NumLock and
479 * ScrollLock. How much memory/CPU does such a monstrosity consume
483 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
,
484 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
486 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
,
487 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
488 if (_NumLockMask
&& _ScrollLockMask
)
489 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
,
490 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
492 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|LockMask
,
493 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
495 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
|LockMask
,
496 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
497 if (_NumLockMask
&& _ScrollLockMask
)
498 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
499 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
500 /* phew, I guess that's all, right? */
505 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
506 Window grab_window
, Bool owner_events
,
507 unsigned int event_mask
, int pointer_mode
,
508 int keyboard_mode
, Window confine_to
, Cursor cursor
)
510 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
511 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
513 if (modifiers
==AnyModifier
)
516 XGrabButton(dpy
, button
, modifiers
|LockMask
, grab_window
, owner_events
,
517 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
520 /* same as above, but for mouse buttons */
522 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
,
523 grab_window
, owner_events
, event_mask
, pointer_mode
,
524 keyboard_mode
, confine_to
, cursor
);
526 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
527 grab_window
, owner_events
, event_mask
, pointer_mode
,
528 keyboard_mode
, confine_to
, cursor
);
529 if (_NumLockMask
&& _ScrollLockMask
)
530 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
,
531 grab_window
, owner_events
, event_mask
, pointer_mode
,
532 keyboard_mode
, confine_to
, cursor
);
534 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
535 grab_window
, owner_events
, event_mask
, pointer_mode
,
536 keyboard_mode
, confine_to
, cursor
);
538 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
539 grab_window
, owner_events
, event_mask
, pointer_mode
,
540 keyboard_mode
, confine_to
, cursor
);
541 if (_NumLockMask
&& _ScrollLockMask
)
542 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
|LockMask
,
543 grab_window
, owner_events
, event_mask
, pointer_mode
,
544 keyboard_mode
, confine_to
, cursor
);
545 #endif /* NUMLOCK_HACK */
550 wHackedUngrabButton(unsigned int button
, unsigned int modifiers
,
553 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
,
555 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
557 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
,
559 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
561 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
563 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
571 wScreenWithNumber(int i
)
573 assert(i
< wScreenCount
);
580 wScreenForRootWindow(Window window
)
588 * Since the number of heads will probably be small (normally 2),
589 * it should be faster to use this than a hash table, because
592 for (i
=0; i
<wScreenCount
; i
++) {
593 if (wScreen
[i
]->root_win
== window
) {
598 assert("bad_root_window" && 0);
605 wScreenSearchForRootWindow(Window window
)
613 * Since the number of heads will probably be small (normally 2),
614 * it should be faster to use this than a hash table, because
617 for (i
=0; i
<wScreenCount
; i
++) {
618 if (wScreen
[i
]->root_win
== window
) {
628 wScreenForWindow(Window window
)
630 XWindowAttributes attr
;
635 if (XGetWindowAttributes(dpy
, window
, &attr
)) {
636 return wScreenForRootWindow(attr
.root
);
642 static char *atomNames
[] = {
650 "WM_COLORMAP_WINDOWS",
651 "WM_COLORMAP_NOTIFY",
652 GNUSTEP_WM_ATTR_NAME
,
654 "_WINDOWMAKER_STATE",
655 "_WINDOWMAKER_WM_PROTOCOLS",
656 GNUSTEP_WM_MINIATURIZE_WINDOW
,
657 "_WINDOWMAKER_WM_FUNCTION",
658 "_WINDOWMAKER_NOTICEBOARD",
659 "_WINDOWMAKER_COMMAND",
660 "_WINDOWMAKER_ICON_SIZE",
661 "_WINDOWMAKER_ICON_TILE",
662 GNUSTEP_TITLEBAR_STATE
667 *----------------------------------------------------------
669 * starts the window manager and setup global data.
670 * Called from main() at startup.
673 * global data declared in main.c is initialized
674 *----------------------------------------------------------
677 StartUp(Bool defaultScreenOnly
)
679 WWorkspaceState
*ws_state
;
680 struct sigaction sig_action
;
682 Atom atom
[sizeof(atomNames
)/sizeof(char*)];
685 * Ignore CapsLock in modifiers
687 ValidModMask
= 0xff & ~LockMask
;
689 getOffendingModifiers();
691 * Ignore NumLock and ScrollLock too
693 ValidModMask
&= ~(_NumLockMask
|_ScrollLockMask
);
696 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
698 wWinContext
= XUniqueContext();
699 wAppWinContext
= XUniqueContext();
700 wStackContext
= XUniqueContext();
702 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False);*/
704 #ifdef HAVE_XINTERNATOMS
705 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
)/sizeof(char*),
711 for (i
= 0; i
< sizeof(atomNames
)/sizeof(char*); i
++) {
712 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
717 _XA_WM_STATE
= atom
[0];
718 _XA_WM_CHANGE_STATE
= atom
[1];
719 _XA_WM_PROTOCOLS
= atom
[2];
720 _XA_WM_TAKE_FOCUS
= atom
[3];
721 _XA_WM_DELETE_WINDOW
= atom
[4];
722 _XA_WM_SAVE_YOURSELF
= atom
[5];
723 _XA_WM_CLIENT_LEADER
= atom
[6];
724 _XA_WM_COLORMAP_WINDOWS
= atom
[7];
725 _XA_WM_COLORMAP_NOTIFY
= atom
[8];
727 _XA_GNUSTEP_WM_ATTR
= atom
[9];
729 _XA_WINDOWMAKER_MENU
= atom
[10];
730 _XA_WINDOWMAKER_STATE
= atom
[11];
732 _XA_WINDOWMAKER_WM_PROTOCOLS
= atom
[12];
734 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
= atom
[13];
736 _XA_WINDOWMAKER_WM_FUNCTION
= atom
[14];
738 _XA_WINDOWMAKER_NOTICEBOARD
= atom
[15];
740 _XA_WINDOWMAKER_COMMAND
= atom
[16];
742 _XA_WINDOWMAKER_ICON_SIZE
= atom
[17];
743 _XA_WINDOWMAKER_ICON_TILE
= atom
[18];
745 _XA_GNUSTEP_TITLEBAR_STATE
= atom
[19];
748 _XA_DND_SELECTION
= XInternAtom(dpy
, "DndSelection", False
);
749 _XA_DND_PROTOCOL
= XInternAtom(dpy
, "DndProtocol", False
);
752 wXDNDInitializeAtoms();
757 #ifdef DEFINABLE_CURSOR
758 wCursor
[WCUR_NORMAL
] = None
;
760 wCursor
[WCUR_NORMAL
] = XCreateFontCursor(dpy
, XC_left_ptr
);
762 wCursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
763 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
764 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
765 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
766 wCursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
767 wCursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
768 wCursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
769 wCursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
770 wCursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
771 wCursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
772 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
773 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
774 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name???*/
775 wCursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
777 /* emergency exit... */
778 sig_action
.sa_handler
= handleSig
;
779 sigemptyset(&sig_action
.sa_mask
);
781 /* Here we don't care about SA_RESTART since these signals will close
784 sig_action
.sa_flags
= 0;
785 sigaction(SIGINT
, &sig_action
, NULL
);
786 sigaction(SIGTERM
, &sig_action
, NULL
);
787 sigaction(SIGHUP
, &sig_action
, NULL
);
788 sigaction(SIGQUIT
, &sig_action
, NULL
);
789 sigaction(SIGSEGV
, &sig_action
, NULL
);
790 sigaction(SIGBUS
, &sig_action
, NULL
);
791 sigaction(SIGFPE
, &sig_action
, NULL
);
792 sigaction(SIGABRT
, &sig_action
, NULL
);
794 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
797 sig_action
.sa_flags
= SA_RESTART
;
798 sigaction(SIGUSR1
, &sig_action
, NULL
);
800 /* ignore dead pipe */
801 sig_action
.sa_handler
= ignoreSig
;
802 sig_action
.sa_flags
= SA_RESTART
;
803 sigaction(SIGPIPE
, &sig_action
, NULL
);
805 /* handle dead children */
806 sig_action
.sa_handler
= buryChild
;
807 sig_action
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
808 sigaction(SIGCHLD
, &sig_action
, NULL
);
810 /* Now we unblock all signals, that may have been blocked by the parent
811 * who exec()-ed us. This can happen for example if Window Maker crashes
812 * and restarts itself or another window manager from the signal handler.
813 * In this case, the new proccess inherits the blocked signal mask and
814 * will no longer react to that signal, until unblocked.
815 * This is because the signal handler of the proccess who crashed (parent)
816 * didn't return, and the signal remained blocked. -Dan
818 sigfillset(&sig_action
.sa_mask
);
819 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
821 /* handle X shutdowns a such */
822 XSetIOErrorHandler(handleXIO
);
824 /* set hook for out event dispatcher in WINGs event dispatcher */
825 WMHookEventHandler(DispatchEvent
);
827 /* initialize defaults stuff */
828 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
829 if (!WDWindowMaker
->dictionary
) {
830 wwarning(_("could not read domain \"%s\" from defaults database"),
834 /* read defaults that don't change until a restart and are
835 * screen independent */
836 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
838 /* check sanity of some values */
839 if (wPreferences
.icon_size
< 16) {
840 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
841 wPreferences
.icon_size
);
842 wPreferences
.icon_size
= 16;
845 /* init other domains */
846 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
847 if (!WDRootMenu
->dictionary
) {
848 wwarning(_("could not read domain \"%s\" from defaults database"),
852 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
853 if (!WDWindowAttributes
->dictionary
) {
854 wwarning(_("could not read domain \"%s\" from defaults database"),
855 "WMWindowAttributes");
858 XSetErrorHandler((XErrorHandler
)catchXError
);
862 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
865 #ifdef KEEP_XKB_LOCK_STATUS
866 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
867 if(wPreferences
.modelock
&& !wXkbSupported
) {
868 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
869 wPreferences
.modelock
= 0;
873 if (defaultScreenOnly
) {
876 max
= ScreenCount(dpy
);
878 wScreen
= wmalloc(sizeof(WScreen
*)*max
);
882 /* manage the screens */
883 for (j
= 0; j
< max
; j
++) {
884 if (defaultScreenOnly
|| max
==1) {
885 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
886 if (!wScreen
[wScreenCount
]) {
887 wfatal(_("it seems that there is already a window manager running"));
891 wScreen
[wScreenCount
] = wScreenInit(j
);
892 if (!wScreen
[wScreenCount
]) {
893 wwarning(_("could not manage screen %i"), j
);
900 /* initialize/restore state for the screens */
901 for (j
= 0; j
< wScreenCount
; j
++) {
902 /* restore workspace state */
903 if (!getWorkspaceState(wScreen
[j
]->root_win
, &ws_state
)) {
907 wScreenRestoreState(wScreen
[j
]);
909 /* manage all windows that were already here before us */
910 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
911 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
913 manageAllWindows(wScreen
[j
]);
915 /* restore saved menus */
916 wMenuRestoreState(wScreen
[j
]);
918 /* If we're not restarting restore session */
919 if (ws_state
== NULL
&& !wPreferences
.flags
.norestore
)
920 wSessionRestoreState(wScreen
[j
]);
922 if (!wPreferences
.flags
.noautolaunch
) {
923 /* auto-launch apps */
924 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
925 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
926 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
928 /* auto-launch apps in clip */
929 if (!wPreferences
.flags
.noclip
) {
931 for(i
=0; i
<wScreen
[j
]->workspace_count
; i
++) {
932 if (wScreen
[j
]->workspaces
[i
]->clip
) {
933 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
934 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
940 /* go to workspace where we were before restart */
942 wWorkspaceForceChange(wScreen
[j
], ws_state
->workspace
);
945 wSessionRestoreLastWorkspace(wScreen
[j
]);
949 wKWMSetInitializedHint(wScreen
[j
]);
953 if (wScreenCount
== 0) {
954 wfatal(_("could not manage any screen"));
958 if (!wPreferences
.flags
.noupdates
) {
959 /* setup defaults file polling */
960 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
968 windowInList(Window window
, Window
*list
, int count
)
970 for (; count
>=0; count
--) {
971 if (window
== list
[count
])
978 *-----------------------------------------------------------------------
980 * Manages all windows in the screen.
983 * Called when the wm is being started.
984 * No events can be processed while the windows are being
985 * reparented/managed.
986 *-----------------------------------------------------------------------
989 manageAllWindows(WScreen
*scr
)
993 unsigned int nchildren
;
998 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
1000 scr
->flags
.startup
= 1;
1002 /* first remove all icon windows */
1003 for (i
= 0; i
< nchildren
; i
++) {
1006 if (children
[i
]==None
)
1009 wmhints
= XGetWMHints(dpy
, children
[i
]);
1010 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
1011 for (j
= 0; j
< nchildren
; j
++) {
1012 if (children
[j
] == wmhints
->icon_window
) {
1026 for (i
= 0; i
< nchildren
; i
++) {
1027 if (children
[i
] == None
)
1031 wKWMCheckModule(scr
, children
[i
]);
1033 wwin
= wManageWindow(scr
, children
[i
]);
1035 /* apply states got from WSavedState */
1036 /* shaded + minimized is not restored correctly */
1037 if (wwin
->flags
.shaded
) {
1038 wwin
->flags
.shaded
= 0;
1041 if (wwin
->flags
.miniaturized
1042 && (wwin
->transient_for
== None
1043 || wwin
->transient_for
== scr
->root_win
1044 || !windowInList(wwin
->transient_for
, children
,
1047 wwin
->flags
.skip_next_animation
= 1;
1048 wwin
->flags
.miniaturized
= 0;
1049 wIconifyWindow(wwin
);
1051 wClientSetState(wwin
, NormalState
, None
);
1058 wwin
= scr
->focused_window
;
1060 if (wwin
->flags
.hidden
) {
1061 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1064 wwin
->flags
.hidden
= 0;
1065 wHideApplication(wapp
);
1067 wwin
->flags
.hidden
= 0;
1074 scr
->flags
.startup
= 0;
1075 scr
->flags
.startup2
= 1;
1077 while (XPending(dpy
)) {
1079 WMNextEvent(dpy
, &ev
);
1082 wWorkspaceForceChange(scr
, 0);
1083 if (!wPreferences
.flags
.noclip
)
1084 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
1085 scr
->flags
.startup2
= 0;