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"
68 #ifdef SYS_SIGLIST_DECLARED
69 extern const char * const sys_siglist
[];
79 /****** Global Variables ******/
81 extern WPreferences wPreferences
;
83 extern WDDomain
*WDWindowMaker
;
84 extern WDDomain
*WDRootMenu
;
85 extern WDDomain
*WDWindowAttributes
;
87 extern WShortKey wKeyBindings
[WKBD_LAST
];
89 extern int wScreenCount
;
93 extern Bool wShapeSupported
;
94 extern int wShapeEventBase
;
98 extern XContext wWinContext
;
99 extern XContext wAppWinContext
;
100 extern XContext wStackContext
;
103 extern Atom _XA_WM_STATE
;
104 extern Atom _XA_WM_CHANGE_STATE
;
105 extern Atom _XA_WM_PROTOCOLS
;
106 extern Atom _XA_WM_TAKE_FOCUS
;
107 extern Atom _XA_WM_DELETE_WINDOW
;
108 extern Atom _XA_WM_SAVE_YOURSELF
;
109 extern Atom _XA_WM_CLIENT_LEADER
;
110 extern Atom _XA_WM_COLORMAP_WINDOWS
;
111 extern Atom _XA_WM_COLORMAP_NOTIFY
;
113 extern Atom _XA_GNUSTEP_WM_ATTR
;
115 extern Atom _XA_WINDOWMAKER_MENU
;
116 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
117 extern Atom _XA_WINDOWMAKER_STATE
;
118 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
119 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
120 extern Atom _XA_WINDOWMAKER_COMMAND
;
122 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
125 extern Atom _XA_DND_PROTOCOL
;
126 extern Atom _XA_DND_SELECTION
;
129 extern Atom _XA_XDE_REQUEST
;
130 extern Atom _XA_XDE_ENTER
;
131 extern Atom _XA_XDE_LEAVE
;
132 extern Atom _XA_XDE_DATA_AVAILABLE
;
133 extern Atom _XDE_FILETYPE
;
134 extern Atom _XDE_URLTYPE
;
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 _XA_XDE_ENTER
= XInternAtom(dpy
, "_XDE_ENTER", False
);
702 _XA_XDE_REQUEST
= XInternAtom(dpy
, "_XDE_REQUEST", False
);
703 _XA_XDE_LEAVE
= XInternAtom(dpy
, "_XDE_LEAVE", False
);
704 _XA_XDE_DATA_AVAILABLE
= XInternAtom(dpy
, "_XDE_DATA_AVAILABLE", False
);
705 _XDE_FILETYPE
= XInternAtom(dpy
, "file:ALL", False
);
706 _XDE_URLTYPE
= XInternAtom(dpy
, "url:ALL", False
);
711 wCursor
[WCUR_NORMAL
] = XCreateFontCursor(dpy
, XC_left_ptr
);
712 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
713 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
714 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
715 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
716 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
717 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name???*/
719 /* emergency exit... */
720 sig_action
.sa_handler
= handleSig
;
721 sigemptyset(&sig_action
.sa_mask
);
723 /* Here we don't care about SA_RESTART since these signals will close
726 sig_action
.sa_flags
= 0;
727 sigaction(SIGINT
, &sig_action
, NULL
);
728 sigaction(SIGTERM
, &sig_action
, NULL
);
729 sigaction(SIGHUP
, &sig_action
, NULL
);
730 sigaction(SIGQUIT
, &sig_action
, NULL
);
731 sigaction(SIGSEGV
, &sig_action
, NULL
);
732 sigaction(SIGBUS
, &sig_action
, NULL
);
733 sigaction(SIGFPE
, &sig_action
, NULL
);
734 sigaction(SIGABRT
, &sig_action
, NULL
);
736 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
739 sig_action
.sa_flags
= SA_RESTART
;
740 sigaction(SIGUSR1
, &sig_action
, NULL
);
742 /* ignore dead pipe */
743 sig_action
.sa_handler
= ignoreSig
;
744 sig_action
.sa_flags
= SA_RESTART
;
745 sigaction(SIGPIPE
, &sig_action
, NULL
);
747 /* handle dead children */
748 sig_action
.sa_handler
= buryChild
;
749 sig_action
.sa_flags
= SA_NOCLDSTOP
|SA_RESTART
;
750 sigaction(SIGCHLD
, &sig_action
, NULL
);
752 /* Now we unblock all signals, that may have been blocked by the parent
753 * who exec()-ed us. This can happen for example if Window Maker crashes
754 * and restarts itself or another window manager from the signal handler.
755 * In this case, the new proccess inherits the blocked signal mask and
756 * will no longer react to that signal, until unblocked.
757 * This is because the signal handler of the proccess who crashed (parent)
758 * didn't return, and the signal remained blocked. -Dan
760 sigfillset(&sig_action
.sa_mask
);
761 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
763 /* handle X shutdowns a such */
764 XSetIOErrorHandler(handleXIO
);
766 /* set hook for out event dispatcher in WINGs event dispatcher */
767 WMHookEventHandler(DispatchEvent
);
769 /* initialize defaults stuff */
770 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
771 if (!WDWindowMaker
->dictionary
) {
772 wwarning(_("could not read domain \"%s\" from defaults database"),
776 /* read defaults that don't change until a restart and are
777 * screen independent */
778 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
780 /* check sanity of some values */
781 if (wPreferences
.icon_size
< 16) {
782 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
783 wPreferences
.icon_size
);
784 wPreferences
.icon_size
= 16;
787 /* init other domains */
788 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
789 if (!WDRootMenu
->dictionary
) {
790 wwarning(_("could not read domain \"%s\" from defaults database"),
794 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
795 if (!WDWindowAttributes
->dictionary
) {
796 wwarning(_("could not read domain \"%s\" from defaults database"),
797 "WMWindowAttributes");
800 XSetErrorHandler((XErrorHandler
)catchXError
);
804 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
807 if (defaultScreenOnly
) {
810 max
= ScreenCount(dpy
);
812 wScreen
= wmalloc(sizeof(WScreen
*)*max
);
816 /* manage the screens */
817 for (j
= 0; j
< max
; j
++) {
818 if (defaultScreenOnly
|| max
==1) {
819 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
820 if (!wScreen
[wScreenCount
]) {
821 wfatal(_("it seems that there is already a window manager running"));
825 wScreen
[wScreenCount
] = wScreenInit(j
);
826 if (!wScreen
[wScreenCount
]) {
827 wwarning(_("could not manage screen %i"), j
);
834 /* initialize/restore state for the screens */
835 for (j
= 0; j
< wScreenCount
; j
++) {
836 /* restore workspace state */
837 if (!getWorkspaceState(wScreen
[j
]->root_win
, &ws_state
)) {
841 wScreenRestoreState(wScreen
[j
]);
843 /* manage all windows that were already here before us */
844 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
845 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
847 manageAllWindows(wScreen
[j
]);
849 /* restore saved menus */
850 wMenuRestoreState(wScreen
[j
]);
852 /* If we're not restarting restore session */
853 if (ws_state
== NULL
)
854 wSessionRestoreState(wScreen
[j
]);
857 /* auto-launch apps */
858 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
859 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
860 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
862 /* auto-launch apps in clip */
863 if (!wPreferences
.flags
.noclip
) {
865 for(i
=0; i
<wScreen
[j
]->workspace_count
; i
++) {
866 if (wScreen
[j
]->workspaces
[i
]->clip
) {
867 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
868 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
873 /* go to workspace where we were before restart */
875 wWorkspaceForceChange(wScreen
[j
], ws_state
->workspace
);
878 wSessionRestoreLastWorkspace(wScreen
[j
]);
882 wKWMSetInitializedHint(wScreen
[j
]);
886 if (wScreenCount
== 0) {
887 wfatal(_("could not manage any screen"));
891 if (!wPreferences
.flags
.noupdates
) {
892 /* setup defaults file polling */
893 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
901 windowInList(Window window
, Window
*list
, int count
)
903 for (; count
>=0; count
--) {
904 if (window
== list
[count
])
911 *-----------------------------------------------------------------------
913 * Manages all windows in the screen.
916 * Called when the wm is being started.
917 * No events can be processed while the windows are being
918 * reparented/managed.
919 *-----------------------------------------------------------------------
922 manageAllWindows(WScreen
*scr
)
926 unsigned int nchildren
;
931 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
933 scr
->flags
.startup
= 1;
935 /* first remove all icon windows */
936 for (i
= 0; i
< nchildren
; i
++) {
939 if (children
[i
]==None
)
942 wmhints
= XGetWMHints(dpy
, children
[i
]);
943 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
944 for (j
= 0; j
< nchildren
; j
++) {
945 if (children
[j
] == wmhints
->icon_window
) {
959 for (i
= 0; i
< nchildren
; i
++) {
960 if (children
[i
] == None
)
964 wKWMCheckModule(scr
, children
[i
]);
966 wwin
= wManageWindow(scr
, children
[i
]);
968 /* apply states got from WSavedState */
969 /* shaded + minimized is not restored correctly */
970 if (wwin
->flags
.shaded
) {
971 wwin
->flags
.shaded
= 0;
974 if (wwin
->flags
.miniaturized
975 && (wwin
->transient_for
== None
976 || wwin
->transient_for
== scr
->root_win
977 || !windowInList(wwin
->transient_for
, children
,
980 wwin
->flags
.skip_next_animation
= 1;
981 wwin
->flags
.miniaturized
= 0;
982 wIconifyWindow(wwin
);
984 wClientSetState(wwin
, NormalState
, None
);
991 wwin
= scr
->focused_window
;
993 if (wwin
->flags
.hidden
) {
994 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
997 wwin
->flags
.hidden
= 0;
998 wHideApplication(wapp
);
1000 wwin
->flags
.hidden
= 0;
1007 scr
->flags
.startup
= 0;
1008 scr
->flags
.startup2
= 1;
1010 while (XPending(dpy
)) {
1012 WMNextEvent(dpy
, &ev
);
1015 wWorkspaceForceChange(scr
, 0);
1016 if (!wPreferences
.flags
.noclip
)
1017 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
1018 scr
->flags
.startup2
= 0;