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
[];
82 /****** Global Variables ******/
84 extern WPreferences wPreferences
;
86 extern WDDomain
*WDWindowMaker
;
87 extern WDDomain
*WDRootMenu
;
88 extern WDDomain
*WDWindowAttributes
;
90 extern WShortKey wKeyBindings
[WKBD_LAST
];
92 extern int wScreenCount
;
96 extern Bool wShapeSupported
;
97 extern int wShapeEventBase
;
100 #ifdef KEEP_XKB_LOCK_STATUS
101 extern Bool wXkbSupported
;
102 extern int wXkbEventBase
;
106 extern XContext wWinContext
;
107 extern XContext wAppWinContext
;
108 extern XContext wStackContext
;
111 extern Atom _XA_WM_STATE
;
112 extern Atom _XA_WM_CHANGE_STATE
;
113 extern Atom _XA_WM_PROTOCOLS
;
114 extern Atom _XA_WM_TAKE_FOCUS
;
115 extern Atom _XA_WM_DELETE_WINDOW
;
116 extern Atom _XA_WM_SAVE_YOURSELF
;
117 extern Atom _XA_WM_CLIENT_LEADER
;
118 extern Atom _XA_WM_COLORMAP_WINDOWS
;
119 extern Atom _XA_WM_COLORMAP_NOTIFY
;
121 extern Atom _XA_GNUSTEP_WM_ATTR
;
123 extern Atom _XA_WINDOWMAKER_MENU
;
124 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
125 extern Atom _XA_WINDOWMAKER_STATE
;
126 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
127 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
128 extern Atom _XA_WINDOWMAKER_COMMAND
;
130 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
133 extern Atom _XA_DND_PROTOCOL
;
134 extern Atom _XA_DND_SELECTION
;
139 extern Cursor wCursor
[WCUR_LAST
];
142 extern char WDelayedActionSet
;
146 static WScreen
**wScreen
= NULL
;
149 static unsigned int _NumLockMask
= 0;
150 static unsigned int _ScrollLockMask
= 0;
154 static void manageAllWindows();
156 extern void NotifyDeadProcess(pid_t pid
, unsigned char status
);
160 catchXError(Display
*dpy
, XErrorEvent
*error
)
162 char buffer
[MAXLINE
];
164 /* ignore some errors */
165 if (error
->resourceid
!= None
166 && ((error
->error_code
== BadDrawable
167 && error
->request_code
== X_GetGeometry
)
168 || (error
->error_code
== BadMatch
169 && (error
->request_code
== X_SetInputFocus
))
170 || (error
->error_code
== BadWindow
)
172 && (error->request_code == X_GetWindowAttributes
173 || error->request_code == X_SetInputFocus
174 || error->request_code == X_ChangeWindowAttributes
175 || error->request_code == X_GetProperty
176 || error->request_code == X_ChangeProperty
177 || error->request_code == X_QueryTree
178 || error->request_code == X_GrabButton
179 || error->request_code == X_UngrabButton
180 || error->request_code == X_SendEvent
181 || error->request_code == X_ConfigureWindow))
183 || (error
->request_code
== X_InstallColormap
))) {
188 printf("got X error %x %x %x\n", error
->request_code
,
189 error
->error_code
, (unsigned)error
->resourceid
);
193 FormatXError(dpy
, error
, buffer
, MAXLINE
);
194 wwarning(_("internal X error: %s\n"), buffer
);
200 *----------------------------------------------------------------------
202 * Handle X shutdowns and other stuff.
203 *----------------------------------------------------------------------
206 handleXIO(Display
*xio_dpy
)
215 *----------------------------------------------------------------------
217 * Action to be executed after the signal() handler is exited.
218 *----------------------------------------------------------------------
221 delayedAction(void *cdata
)
223 WDelayedActionSet
= 0;
225 * Make the event dispatcher do whatever it needs to do,
226 * including handling zombie processes, restart and exit
235 *----------------------------------------------------------------------
237 * general signal handler. Exits the program gently.
238 *----------------------------------------------------------------------
243 static int already_crashed
= 0;
245 #ifndef NO_EMERGENCY_AUTORESTART
253 * No functions that potentially do Xlib calls should be called from
254 * here. Xlib calls are not reentrant so the integrity of Xlib is
255 * not guaranteed if a Xlib call is made from a signal handler.
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 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 if (!WDelayedActionSet
) {
269 WDelayedActionSet
= 1;
270 WMAddIdleHandler(delayedAction
, NULL
);
273 } else if (sig
== SIGTERM
|| sig
== SIGHUP
) {
274 #ifdef SYS_SIGLIST_DECLARED
275 wwarning(_("got signal %i (%s) - exiting...\n"), sig
, sys_siglist
[sig
]);
277 wwarning(_("got signal %i - exiting...\n"), sig
);
280 WCHANGE_STATE(WSTATE_NEED_EXIT
);
282 if (!WDelayedActionSet
) {
283 WDelayedActionSet
= 1;
284 WMAddIdleHandler(delayedAction
, NULL
);
289 #ifdef SYS_SIGLIST_DECLARED
290 wfatal(_("got signal %i (%s)\n"), sig
, sys_siglist
[sig
]);
292 wfatal(_("got signal %i\n"), sig
);
295 /* Setting the signal behaviour back to default and then reraising the
296 * signal is a cleaner way to make program exit and core dump than calling
297 * abort(), since it correctly returns from the signal handler and sets
298 * the flags accordingly. -Dan
300 if (sig
==SIGSEGV
|| sig
==SIGFPE
|| sig
==SIGBUS
|| sig
==SIGILL
302 if (already_crashed
) {
303 wfatal(_("crashed while trying to do some post-crash cleanup. Aborting immediatelly."));
304 signal(sig
, SIG_DFL
);
312 #ifndef NO_EMERGENCY_AUTORESTART
313 /* Close the X connection and open a new one. This is to avoid messing
314 * Xlib because we call to Xlib functions in a signal handler.
318 dpy
= XOpenDisplay("");
321 crashAction
= wShowCrashingDialogPanel(sig
);
325 wsyserror(_("cannot open connection for crashing dialog panel. Aborting."));
326 crashAction
= WMAbort
;
329 if (crashAction
== WMAbort
) {
330 signal(sig
, SIG_DFL
);
335 if (crashAction
== WMRestart
) {
336 /* we try to restart Window Maker */
337 wwarning(_("trying to restart Window Maker..."));
338 Restart(NULL
, False
);
339 /* fallback to alternate window manager then */
342 wwarning(_("trying to start alternate window manager..."));
344 Restart(FALLBACK_WINDOWMANAGER
, False
);
345 Restart("fvwm", False
);
346 Restart("twm", False
);
347 wfatal(_("failed to start alternate window manager. Aborting."));
349 wfatal(_("a fatal error has occured, probably due to a bug. "
350 "Please fill the included BUGFORM and report it."));
351 #endif /* !NO_EMERGENCY_AUTORESTART */
353 signal(sig
, SIG_DFL
);
364 ignoreSig(int signal
)
377 pid
= waitpid(-1, &status
, WNOHANG
);
379 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
381 * Make sure that the kid will be buried even if there are
382 * no events in the X event queue
384 if (!WDelayedActionSet
) {
385 WDelayedActionSet
= 1;
386 WMAddIdleHandler(delayedAction
, NULL
);
393 getWorkspaceState(Window root
, WWorkspaceState
**state
)
397 unsigned long nitems_ret
;
398 unsigned long bytes_after_ret
;
401 if (XGetWindowProperty(dpy
, root
, _XA_WINDOWMAKER_STATE
, 0, 2,
402 True
, _XA_WINDOWMAKER_STATE
,
403 &type_ret
, &fmt_ret
, &nitems_ret
, &bytes_after_ret
,
404 (unsigned char **)&data
)!=Success
|| !data
)
407 *state
= malloc(sizeof(WWorkspaceState
));
409 (*state
)->flags
= data
[0];
410 (*state
)->workspace
= data
[1];
414 if (*state
&& type_ret
==_XA_WINDOWMAKER_STATE
)
422 getOffendingModifiers()
425 XModifierKeymap
*modmap
;
426 KeyCode nlock
, slock
;
427 static int mask_table
[8] = {
428 ShiftMask
,LockMask
,ControlMask
,Mod1Mask
,
429 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
432 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
433 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
436 * Find out the masks for the NumLock and ScrollLock modifiers,
437 * so that we can bind the grabs for when they are enabled too.
439 modmap
= XGetModifierMapping(dpy
);
441 if (modmap
!=NULL
&& modmap
->max_keypermod
>0) {
442 for (i
=0; i
<8*modmap
->max_keypermod
; i
++) {
443 if (modmap
->modifiermap
[i
]==nlock
&& nlock
!=0)
444 _NumLockMask
= mask_table
[i
/modmap
->max_keypermod
];
445 else if (modmap
->modifiermap
[i
]==slock
&& slock
!=0)
446 _ScrollLockMask
= mask_table
[i
/modmap
->max_keypermod
];
451 XFreeModifiermap(modmap
);
458 wHackedGrabKey(int keycode
, unsigned int modifiers
,
459 Window grab_window
, Bool owner_events
, int pointer_mode
,
462 if (modifiers
== AnyModifier
)
465 /* grab all combinations of the modifier with CapsLock, NumLock and
466 * ScrollLock. How much memory/CPU does such a monstrosity consume
470 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
,
471 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
473 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
,
474 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
475 if (_NumLockMask
&& _ScrollLockMask
)
476 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
,
477 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
479 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|LockMask
,
480 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
482 XGrabKey(dpy
, keycode
, modifiers
|_ScrollLockMask
|LockMask
,
483 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
484 if (_NumLockMask
&& _ScrollLockMask
)
485 XGrabKey(dpy
, keycode
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
486 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
487 /* phew, I guess that's all, right? */
492 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
493 Window grab_window
, Bool owner_events
,
494 unsigned int event_mask
, int pointer_mode
,
495 int keyboard_mode
, Window confine_to
, Cursor cursor
)
497 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
498 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
500 if (modifiers
==AnyModifier
)
503 XGrabButton(dpy
, button
, modifiers
|LockMask
, grab_window
, owner_events
,
504 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
507 /* same as above, but for mouse buttons */
509 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
,
510 grab_window
, owner_events
, event_mask
, pointer_mode
,
511 keyboard_mode
, confine_to
, cursor
);
513 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
514 grab_window
, owner_events
, event_mask
, pointer_mode
,
515 keyboard_mode
, confine_to
, cursor
);
516 if (_NumLockMask
&& _ScrollLockMask
)
517 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
,
518 grab_window
, owner_events
, event_mask
, pointer_mode
,
519 keyboard_mode
, confine_to
, cursor
);
521 XGrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
522 grab_window
, owner_events
, event_mask
, pointer_mode
,
523 keyboard_mode
, confine_to
, cursor
);
525 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
526 grab_window
, owner_events
, event_mask
, pointer_mode
,
527 keyboard_mode
, confine_to
, cursor
);
528 if (_NumLockMask
&& _ScrollLockMask
)
529 XGrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|_NumLockMask
|LockMask
,
530 grab_window
, owner_events
, event_mask
, pointer_mode
,
531 keyboard_mode
, confine_to
, cursor
);
532 #endif /* NUMLOCK_HACK */
537 wHackedUngrabButton(unsigned int button
, unsigned int modifiers
,
540 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
,
542 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
,
544 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
,
546 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|LockMask
,
548 XUngrabButton(dpy
, button
, modifiers
|_ScrollLockMask
|LockMask
,
550 XUngrabButton(dpy
, button
, modifiers
|_NumLockMask
|_ScrollLockMask
|LockMask
,
558 wScreenWithNumber(int i
)
560 assert(i
< wScreenCount
);
567 wScreenForRootWindow(Window window
)
575 * Since the number of heads will probably be small (normally 2),
576 * it should be faster to use this than a hash table, because
579 for (i
=0; i
<wScreenCount
; i
++) {
580 if (wScreen
[i
]->root_win
== window
) {
585 assert("bad_root_window" && 0);
592 wScreenSearchForRootWindow(Window window
)
600 * Since the number of heads will probably be small (normally 2),
601 * it should be faster to use this than a hash table, because
604 for (i
=0; i
<wScreenCount
; i
++) {
605 if (wScreen
[i
]->root_win
== window
) {
615 wScreenForWindow(Window window
)
617 XWindowAttributes attr
;
622 if (XGetWindowAttributes(dpy
, window
, &attr
)) {
623 return wScreenForRootWindow(attr
.root
);
631 *----------------------------------------------------------
633 * starts the window manager and setup global data.
634 * Called from main() at startup.
637 * global data declared in main.c is initialized
638 *----------------------------------------------------------
641 StartUp(Bool defaultScreenOnly
)
643 WWorkspaceState
*ws_state
;
644 struct sigaction sig_action
;
648 * Ignore CapsLock in modifiers
650 ValidModMask
= 0xff & ~LockMask
;
652 getOffendingModifiers();
654 * Ignore NumLock and ScrollLock too
656 ValidModMask
&= ~(_NumLockMask
|_ScrollLockMask
);
659 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
661 wWinContext
= XUniqueContext();
662 wAppWinContext
= XUniqueContext();
663 wStackContext
= XUniqueContext();
665 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False);*/
667 _XA_WM_STATE
= XInternAtom(dpy
, "WM_STATE", False
);
668 _XA_WM_CHANGE_STATE
= XInternAtom(dpy
, "WM_CHANGE_STATE", False
);
669 _XA_WM_PROTOCOLS
= XInternAtom(dpy
, "WM_PROTOCOLS", False
);
670 _XA_WM_TAKE_FOCUS
= XInternAtom(dpy
, "WM_TAKE_FOCUS", False
);
671 _XA_WM_DELETE_WINDOW
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
672 _XA_WM_SAVE_YOURSELF
= XInternAtom(dpy
, "WM_SAVE_YOURSELF", False
);
673 _XA_WM_CLIENT_LEADER
= XInternAtom(dpy
, "WM_CLIENT_LEADER", False
);
674 _XA_WM_COLORMAP_WINDOWS
= XInternAtom(dpy
, "WM_COLORMAP_WINDOWS", False
);
675 _XA_WM_COLORMAP_NOTIFY
= XInternAtom(dpy
, "WM_COLORMAP_NOTIFY", False
);
677 _XA_GNUSTEP_WM_ATTR
= XInternAtom(dpy
, GNUSTEP_WM_ATTR_NAME
, False
);
679 _XA_WINDOWMAKER_MENU
= XInternAtom(dpy
, "_WINDOWMAKER_MENU", False
);
680 _XA_WINDOWMAKER_STATE
= XInternAtom(dpy
, "_WINDOWMAKER_STATE", False
);
682 _XA_WINDOWMAKER_WM_PROTOCOLS
=
683 XInternAtom(dpy
, "_WINDOWMAKER_WM_PROTOCOLS", False
);
685 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
=
686 XInternAtom(dpy
, GNUSTEP_WM_MINIATURIZE_WINDOW
, False
);
688 _XA_WINDOWMAKER_WM_FUNCTION
= XInternAtom(dpy
, "_WINDOWMAKER_WM_FUNCTION",
691 _XA_WINDOWMAKER_NOTICEBOARD
= XInternAtom(dpy
, "_WINDOWMAKER_NOTICEBOARD",
694 _XA_WINDOWMAKER_COMMAND
= XInternAtom(dpy
, "_WINDOWMAKER_COMMAND", False
);
697 _XA_DND_SELECTION
= XInternAtom(dpy
, "DndSelection", False
);
698 _XA_DND_PROTOCOL
= XInternAtom(dpy
, "DndProtocol", False
);
701 wXDNDInitializeAtoms();
706 wCursor
[WCUR_NORMAL
] = XCreateFontCursor(dpy
, XC_left_ptr
);
707 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
708 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
709 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
710 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
711 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
712 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name???*/
714 /* emergency exit... */
715 sig_action
.sa_handler
= handleSig
;
716 sigemptyset(&sig_action
.sa_mask
);
718 /* Here we don't care about SA_RESTART since these signals will close
721 sig_action
.sa_flags
= 0;
722 sigaction(SIGINT
, &sig_action
, NULL
);
723 sigaction(SIGTERM
, &sig_action
, NULL
);
724 sigaction(SIGHUP
, &sig_action
, NULL
);
725 sigaction(SIGQUIT
, &sig_action
, NULL
);
726 sigaction(SIGSEGV
, &sig_action
, NULL
);
727 sigaction(SIGBUS
, &sig_action
, NULL
);
728 sigaction(SIGFPE
, &sig_action
, NULL
);
729 sigaction(SIGABRT
, &sig_action
, NULL
);
731 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
734 sig_action
.sa_flags
= SA_RESTART
;
735 sigaction(SIGUSR1
, &sig_action
, NULL
);
737 /* ignore dead pipe */
738 sig_action
.sa_handler
= ignoreSig
;
739 sig_action
.sa_flags
= SA_RESTART
;
740 sigaction(SIGPIPE
, &sig_action
, NULL
);
742 /* handle dead children */
743 sig_action
.sa_handler
= buryChild
;
744 sig_action
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
745 sigaction(SIGCHLD
, &sig_action
, NULL
);
747 /* Now we unblock all signals, that may have been blocked by the parent
748 * who exec()-ed us. This can happen for example if Window Maker crashes
749 * and restarts itself or another window manager from the signal handler.
750 * In this case, the new proccess inherits the blocked signal mask and
751 * will no longer react to that signal, until unblocked.
752 * This is because the signal handler of the proccess who crashed (parent)
753 * didn't return, and the signal remained blocked. -Dan
755 sigfillset(&sig_action
.sa_mask
);
756 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
758 /* handle X shutdowns a such */
759 XSetIOErrorHandler(handleXIO
);
761 /* set hook for out event dispatcher in WINGs event dispatcher */
762 WMHookEventHandler(DispatchEvent
);
764 /* initialize defaults stuff */
765 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
766 if (!WDWindowMaker
->dictionary
) {
767 wwarning(_("could not read domain \"%s\" from defaults database"),
771 /* read defaults that don't change until a restart and are
772 * screen independent */
773 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
775 /* check sanity of some values */
776 if (wPreferences
.icon_size
< 16) {
777 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
778 wPreferences
.icon_size
);
779 wPreferences
.icon_size
= 16;
782 /* init other domains */
783 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
784 if (!WDRootMenu
->dictionary
) {
785 wwarning(_("could not read domain \"%s\" from defaults database"),
789 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
790 if (!WDWindowAttributes
->dictionary
) {
791 wwarning(_("could not read domain \"%s\" from defaults database"),
792 "WMWindowAttributes");
795 XSetErrorHandler((XErrorHandler
)catchXError
);
799 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
802 #ifdef KEEP_XKB_LOCK_STATUS
803 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
804 if(wPreferences
.modelock
&& !wXkbSupported
) {
805 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
806 wPreferences
.modelock
= 0;
810 if (defaultScreenOnly
) {
813 max
= ScreenCount(dpy
);
815 wScreen
= wmalloc(sizeof(WScreen
*)*max
);
819 /* manage the screens */
820 for (j
= 0; j
< max
; j
++) {
821 if (defaultScreenOnly
|| max
==1) {
822 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
823 if (!wScreen
[wScreenCount
]) {
824 wfatal(_("it seems that there is already a window manager running"));
828 wScreen
[wScreenCount
] = wScreenInit(j
);
829 if (!wScreen
[wScreenCount
]) {
830 wwarning(_("could not manage screen %i"), j
);
837 /* initialize/restore state for the screens */
838 for (j
= 0; j
< wScreenCount
; j
++) {
839 /* restore workspace state */
840 if (!getWorkspaceState(wScreen
[j
]->root_win
, &ws_state
)) {
844 wScreenRestoreState(wScreen
[j
]);
846 /* manage all windows that were already here before us */
847 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
848 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
850 manageAllWindows(wScreen
[j
]);
852 /* restore saved menus */
853 wMenuRestoreState(wScreen
[j
]);
855 /* If we're not restarting restore session */
856 if (ws_state
== NULL
)
857 wSessionRestoreState(wScreen
[j
]);
860 /* auto-launch apps */
861 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
862 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
863 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
865 /* auto-launch apps in clip */
866 if (!wPreferences
.flags
.noclip
) {
868 for(i
=0; i
<wScreen
[j
]->workspace_count
; i
++) {
869 if (wScreen
[j
]->workspaces
[i
]->clip
) {
870 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
871 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
876 /* go to workspace where we were before restart */
878 wWorkspaceForceChange(wScreen
[j
], ws_state
->workspace
);
881 wSessionRestoreLastWorkspace(wScreen
[j
]);
885 wKWMSetInitializedHint(wScreen
[j
]);
889 if (wScreenCount
== 0) {
890 wfatal(_("could not manage any screen"));
894 if (!wPreferences
.flags
.noupdates
) {
895 /* setup defaults file polling */
896 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
904 windowInList(Window window
, Window
*list
, int count
)
906 for (; count
>=0; count
--) {
907 if (window
== list
[count
])
914 *-----------------------------------------------------------------------
916 * Manages all windows in the screen.
919 * Called when the wm is being started.
920 * No events can be processed while the windows are being
921 * reparented/managed.
922 *-----------------------------------------------------------------------
925 manageAllWindows(WScreen
*scr
)
929 unsigned int nchildren
;
934 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
936 scr
->flags
.startup
= 1;
938 /* first remove all icon windows */
939 for (i
= 0; i
< nchildren
; i
++) {
942 if (children
[i
]==None
)
945 wmhints
= XGetWMHints(dpy
, children
[i
]);
946 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
947 for (j
= 0; j
< nchildren
; j
++) {
948 if (children
[j
] == wmhints
->icon_window
) {
962 for (i
= 0; i
< nchildren
; i
++) {
963 if (children
[i
] == None
)
967 wKWMCheckModule(scr
, children
[i
]);
969 wwin
= wManageWindow(scr
, children
[i
]);
971 /* apply states got from WSavedState */
972 /* shaded + minimized is not restored correctly */
973 if (wwin
->flags
.shaded
) {
974 wwin
->flags
.shaded
= 0;
977 if (wwin
->flags
.miniaturized
978 && (wwin
->transient_for
== None
979 || wwin
->transient_for
== scr
->root_win
980 || !windowInList(wwin
->transient_for
, children
,
983 wwin
->flags
.skip_next_animation
= 1;
984 wwin
->flags
.miniaturized
= 0;
985 wIconifyWindow(wwin
);
987 wClientSetState(wwin
, NormalState
, None
);
994 wwin
= scr
->focused_window
;
996 if (wwin
->flags
.hidden
) {
997 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
1000 wwin
->flags
.hidden
= 0;
1001 wHideApplication(wapp
);
1003 wwin
->flags
.hidden
= 0;
1010 scr
->flags
.startup
= 0;
1011 scr
->flags
.startup2
= 1;
1013 while (XPending(dpy
)) {
1015 WMNextEvent(dpy
, &ev
);
1018 wWorkspaceForceChange(scr
, 0);
1019 if (!wPreferences
.flags
.noclip
)
1020 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
1021 scr
->flags
.startup2
= 0;