2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <sys/signal.h>
36 #include <X11/Xresource.h>
37 #include <X11/Xutil.h>
38 #include <X11/cursorfont.h>
39 #include <X11/Xproto.h>
40 #include <X11/keysym.h>
42 #include <X11/extensions/shape.h>
44 #ifdef KEEP_XKB_LOCK_STATUS
45 #include <X11/XKBlib.h>
48 #include <X11/extensions/Xrandr.h>
51 #include "WindowMaker.h"
61 #include "workspace.h"
66 #include "properties.h"
70 #include "switchmenu.h"
82 /* Just in case, for weirdo systems */
87 /****** Global Variables ******/
88 extern WDDomain
*WDWindowMaker
;
89 extern WDDomain
*WDRootMenu
;
90 extern WDDomain
*WDWindowAttributes
;
91 extern WShortKey wKeyBindings
[WKBD_LAST
];
92 extern int wScreenCount
;
95 extern Bool wShapeSupported
;
96 extern int wShapeEventBase
;
99 #ifdef KEEP_XKB_LOCK_STATUS
100 extern Bool wXkbSupported
;
101 extern int wXkbEventBase
;
106 extern char WDelayedActionSet
;
110 static WScreen
**wScreen
= NULL
;
111 static unsigned int _NumLockMask
= 0;
112 static unsigned int _ScrollLockMask
= 0;
113 static void manageAllWindows(WScreen
* scr
, int crashed
);
115 static int catchXError(Display
* dpy
, XErrorEvent
* error
)
117 char buffer
[MAXLINE
];
119 /* ignore some errors */
120 if (error
->resourceid
!= None
121 && ((error
->error_code
== BadDrawable
&& error
->request_code
== X_GetGeometry
)
122 || (error
->error_code
== BadMatch
&& (error
->request_code
== X_SetInputFocus
))
123 || (error
->error_code
== BadWindow
)
125 && (error->request_code == X_GetWindowAttributes
126 || error->request_code == X_SetInputFocus
127 || error->request_code == X_ChangeWindowAttributes
128 || error->request_code == X_GetProperty
129 || error->request_code == X_ChangeProperty
130 || error->request_code == X_QueryTree
131 || error->request_code == X_GrabButton
132 || error->request_code == X_UngrabButton
133 || error->request_code == X_SendEvent
134 || error->request_code == X_ConfigureWindow))
136 || (error
->request_code
== X_InstallColormap
))) {
139 FormatXError(dpy
, error
, buffer
, MAXLINE
);
140 wwarning(_("internal X error: %s"), buffer
);
145 *----------------------------------------------------------------------
147 * Handle X shutdowns and other stuff.
148 *----------------------------------------------------------------------
150 static int handleXIO(Display
* xio_dpy
)
159 *----------------------------------------------------------------------
161 * Action to be executed after the signal() handler is exited.
162 *----------------------------------------------------------------------
164 static void delayedAction(void *cdata
)
166 if (WDelayedActionSet
== 0)
171 * Make the event dispatcher do whatever it needs to do,
172 * including handling zombie processes, restart and exit
180 *----------------------------------------------------------------------
182 * User generated exit signal handler.
183 *----------------------------------------------------------------------
185 static RETSIGTYPE
handleExitSig(int sig
)
190 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
192 if (sig
== SIGUSR1
) {
193 wwarning("got signal %i - restarting", sig
);
194 SIG_WCHANGE_STATE(WSTATE_NEED_RESTART
);
195 } else if (sig
== SIGUSR2
) {
196 wwarning("got signal %i - rereading defaults", sig
);
197 SIG_WCHANGE_STATE(WSTATE_NEED_REREAD
);
198 } else if (sig
== SIGTERM
|| sig
== SIGINT
|| sig
== SIGHUP
) {
199 wwarning("got signal %i - exiting...", sig
);
200 SIG_WCHANGE_STATE(WSTATE_NEED_EXIT
);
203 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
204 DispatchEvent(NULL
); /* Dispatch events imediately. */
207 /* Dummy signal handler */
208 static void dummyHandler(int sig
)
213 *----------------------------------------------------------------------
215 * general signal handler. Exits the program gently.
216 *----------------------------------------------------------------------
218 static RETSIGTYPE
handleSig(int sig
)
220 wfatal("got signal %i", sig
);
222 /* Setting the signal behaviour back to default and then reraising the
223 * signal is a cleaner way to make program exit and core dump than calling
224 * abort(), since it correctly returns from the signal handler and sets
225 * the flags accordingly. -Dan
227 if (sig
== SIGSEGV
|| sig
== SIGFPE
|| sig
== SIGBUS
|| sig
== SIGILL
|| sig
== SIGABRT
) {
228 signal(sig
, SIG_DFL
);
236 static RETSIGTYPE
buryChild(int foo
)
240 int save_errno
= errno
;
244 /* Block signals so that NotifyDeadProcess() doesn't get fux0red */
245 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
248 /* If 2 or more kids exit in a small time window, before this handler gets
249 * the chance to get invoked, the SIGCHLD signals will be merged and only
250 * one SIGCHLD signal will be sent to us. We use a while loop to get all
251 * exited child status because we can't count on the number of SIGCHLD
252 * signals to know exactly how many kids have exited. -Dan
254 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0 || (pid
< 0 && errno
== EINTR
)) {
255 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
258 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
263 static void getOffendingModifiers(void)
266 XModifierKeymap
*modmap
;
267 KeyCode nlock
, slock
;
268 static int mask_table
[8] = {
269 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
270 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
273 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
274 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
277 * Find out the masks for the NumLock and ScrollLock modifiers,
278 * so that we can bind the grabs for when they are enabled too.
280 modmap
= XGetModifierMapping(dpy
);
282 if (modmap
!= NULL
&& modmap
->max_keypermod
> 0) {
283 for (i
= 0; i
< 8 * modmap
->max_keypermod
; i
++) {
284 if (modmap
->modifiermap
[i
] == nlock
&& nlock
!= 0)
285 _NumLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
286 else if (modmap
->modifiermap
[i
] == slock
&& slock
!= 0)
287 _ScrollLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
292 XFreeModifiermap(modmap
);
297 wHackedGrabKey(int keycode
, unsigned int modifiers
,
298 Window grab_window
, Bool owner_events
, int pointer_mode
, int keyboard_mode
)
300 if (modifiers
== AnyModifier
)
303 /* grab all combinations of the modifier with CapsLock, NumLock and
304 * ScrollLock. How much memory/CPU does such a monstrosity consume
308 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
,
309 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
311 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
,
312 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
313 if (_NumLockMask
&& _ScrollLockMask
)
314 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
,
315 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
317 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| LockMask
,
318 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
320 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
| LockMask
,
321 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
322 if (_NumLockMask
&& _ScrollLockMask
)
323 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
| LockMask
,
324 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
325 /* phew, I guess that's all, right? */
330 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
331 Window grab_window
, Bool owner_events
,
332 unsigned int event_mask
, int pointer_mode
, int keyboard_mode
, Window confine_to
, Cursor cursor
)
334 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
335 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
337 if (modifiers
== AnyModifier
)
340 XGrabButton(dpy
, button
, modifiers
| LockMask
, grab_window
, owner_events
,
341 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
344 /* same as above, but for mouse buttons */
346 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
,
347 grab_window
, owner_events
, event_mask
, pointer_mode
,
348 keyboard_mode
, confine_to
, cursor
);
350 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
,
351 grab_window
, owner_events
, event_mask
, pointer_mode
,
352 keyboard_mode
, confine_to
, cursor
);
353 if (_NumLockMask
&& _ScrollLockMask
)
354 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
,
355 grab_window
, owner_events
, event_mask
, pointer_mode
,
356 keyboard_mode
, confine_to
, cursor
);
358 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
| LockMask
,
359 grab_window
, owner_events
, event_mask
, pointer_mode
,
360 keyboard_mode
, confine_to
, cursor
);
362 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| LockMask
,
363 grab_window
, owner_events
, event_mask
, pointer_mode
,
364 keyboard_mode
, confine_to
, cursor
);
365 if (_NumLockMask
&& _ScrollLockMask
)
366 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
| LockMask
,
367 grab_window
, owner_events
, event_mask
, pointer_mode
,
368 keyboard_mode
, confine_to
, cursor
);
369 #endif /* NUMLOCK_HACK */
372 WScreen
*wScreenWithNumber(int i
)
374 assert(i
< wScreenCount
);
379 WScreen
*wScreenForRootWindow(Window window
)
383 if (wScreenCount
== 1)
386 /* Since the number of heads will probably be small (normally 2),
387 * it should be faster to use this than a hash table, because
388 * of the overhead. */
389 for (i
= 0; i
< wScreenCount
; i
++)
390 if (wScreen
[i
]->root_win
== window
)
393 return wScreenForWindow(window
);
396 WScreen
*wScreenForWindow(Window window
)
398 XWindowAttributes attr
;
400 if (wScreenCount
== 1)
403 if (XGetWindowAttributes(dpy
, window
, &attr
))
404 return wScreenForRootWindow(attr
.root
);
409 static char *atomNames
[] = {
417 "WM_COLORMAP_WINDOWS",
418 "WM_COLORMAP_NOTIFY",
421 "_WINDOWMAKER_STATE",
422 "_WINDOWMAKER_WM_PROTOCOLS",
423 "_WINDOWMAKER_WM_FUNCTION",
424 "_WINDOWMAKER_NOTICEBOARD",
425 "_WINDOWMAKER_COMMAND",
426 "_WINDOWMAKER_ICON_SIZE",
427 "_WINDOWMAKER_ICON_TILE",
429 GNUSTEP_WM_ATTR_NAME
,
430 GNUSTEP_WM_MINIATURIZE_WINDOW
,
431 GNUSTEP_TITLEBAR_STATE
,
433 "WM_IGNORE_FOCUS_EVENTS"
437 *----------------------------------------------------------
439 * starts the window manager and setup global data.
440 * Called from main() at startup.
443 * global data declared in main.c is initialized
444 *----------------------------------------------------------
446 void StartUp(Bool defaultScreenOnly
)
448 struct sigaction sig_action
;
454 Atom atom
[sizeof(atomNames
) / sizeof(atomNames
[0])];
457 * Ignore CapsLock in modifiers
459 ValidModMask
= 0xff & ~LockMask
;
461 getOffendingModifiers();
463 * Ignore NumLock and ScrollLock too
465 ValidModMask
&= ~(_NumLockMask
| _ScrollLockMask
);
467 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
469 w_global
.context
.client_win
= XUniqueContext();
470 w_global
.context
.app_win
= XUniqueContext();
471 w_global
.context
.stack
= XUniqueContext();
473 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
475 #ifdef HAVE_XINTERNATOMS
476 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
) / sizeof(atomNames
[0]), False
, atom
);
481 for (i
= 0; i
< sizeof(atomNames
) / sizeof(atomNames
[0]); i
++)
482 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
486 w_global
.atom
.wm
.state
= atom
[0];
487 w_global
.atom
.wm
.change_state
= atom
[1];
488 w_global
.atom
.wm
.protocols
= atom
[2];
489 w_global
.atom
.wm
.take_focus
= atom
[3];
490 w_global
.atom
.wm
.delete_window
= atom
[4];
491 w_global
.atom
.wm
.save_yourself
= atom
[5];
492 w_global
.atom
.wm
.client_leader
= atom
[6];
493 w_global
.atom
.wm
.colormap_windows
= atom
[7];
494 w_global
.atom
.wm
.colormap_notify
= atom
[8];
496 w_global
.atom
.wmaker
.menu
= atom
[9];
497 w_global
.atom
.wmaker
.state
= atom
[10];
498 w_global
.atom
.wmaker
.wm_protocols
= atom
[11];
499 w_global
.atom
.wmaker
.wm_function
= atom
[12];
500 w_global
.atom
.wmaker
.noticeboard
= atom
[13];
501 w_global
.atom
.wmaker
.command
= atom
[14];
502 w_global
.atom
.wmaker
.icon_size
= atom
[15];
503 w_global
.atom
.wmaker
.icon_tile
= atom
[16];
505 w_global
.atom
.gnustep
.wm_attr
= atom
[17];
506 w_global
.atom
.gnustep
.wm_miniaturize_window
= atom
[18];
507 w_global
.atom
.gnustep
.titlebar_state
= atom
[19];
509 w_global
.atom
.wm
.ignore_focus_events
= atom
[20];
512 wXDNDInitializeAtoms();
516 wPreferences
.cursor
[WCUR_NORMAL
] = None
; /* inherit from root */
517 wPreferences
.cursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
518 wPreferences
.cursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
519 wPreferences
.cursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
520 wPreferences
.cursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
521 wPreferences
.cursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
522 wPreferences
.cursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
523 wPreferences
.cursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
524 wPreferences
.cursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
525 wPreferences
.cursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
526 wPreferences
.cursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
527 wPreferences
.cursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
528 wPreferences
.cursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
529 wPreferences
.cursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name??? */
530 wPreferences
.cursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
532 Pixmap cur
= XCreatePixmap(dpy
, DefaultRootWindow(dpy
), 16, 16, 1);
533 GC gc
= XCreateGC(dpy
, cur
, 0, NULL
);
535 memset(&black
, 0, sizeof(XColor
));
536 XSetForeground(dpy
, gc
, 0);
537 XFillRectangle(dpy
, cur
, gc
, 0, 0, 16, 16);
539 wPreferences
.cursor
[WCUR_EMPTY
] = XCreatePixmapCursor(dpy
, cur
, cur
, &black
, &black
, 0, 0);
540 XFreePixmap(dpy
, cur
);
544 /* signal handler stuff that gets called when a signal is caught */
545 WMAddPersistentTimerHandler(500, delayedAction
, NULL
);
548 /* emergency exit... */
549 sig_action
.sa_handler
= handleSig
;
550 sigemptyset(&sig_action
.sa_mask
);
552 sig_action
.sa_flags
= SA_RESTART
;
553 sigaction(SIGQUIT
, &sig_action
, NULL
);
554 /* instead of catching these, we let the default handler abort the
555 * program. The new monitor process will take appropriate action
556 * when it detects the crash.
557 sigaction(SIGSEGV, &sig_action, NULL);
558 sigaction(SIGBUS, &sig_action, NULL);
559 sigaction(SIGFPE, &sig_action, NULL);
560 sigaction(SIGABRT, &sig_action, NULL);
563 sig_action
.sa_handler
= handleExitSig
;
565 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
566 * immediately. -Dan */
567 sig_action
.sa_flags
= SA_RESTART
;
568 sigaction(SIGTERM
, &sig_action
, NULL
);
569 sigaction(SIGINT
, &sig_action
, NULL
);
570 sigaction(SIGHUP
, &sig_action
, NULL
);
571 sigaction(SIGUSR1
, &sig_action
, NULL
);
572 sigaction(SIGUSR2
, &sig_action
, NULL
);
574 /* ignore dead pipe */
575 /* Because POSIX mandates that only signal with handlers are reset
576 * accross an exec*(), we do not want to propagate ignoring SIGPIPEs
577 * to children. Hence the dummy handler.
578 * Philippe Troin <phil@fifi.org>
580 sig_action
.sa_handler
= &dummyHandler
;
581 sig_action
.sa_flags
= SA_RESTART
;
582 sigaction(SIGPIPE
, &sig_action
, NULL
);
584 /* handle dead children */
585 sig_action
.sa_handler
= buryChild
;
586 sig_action
.sa_flags
= SA_NOCLDSTOP
| SA_RESTART
;
587 sigaction(SIGCHLD
, &sig_action
, NULL
);
589 /* Now we unblock all signals, that may have been blocked by the parent
590 * who exec()-ed us. This can happen for example if Window Maker crashes
591 * and restarts itself or another window manager from the signal handler.
592 * In this case, the new proccess inherits the blocked signal mask and
593 * will no longer react to that signal, until unblocked.
594 * This is because the signal handler of the proccess who crashed (parent)
595 * didn't return, and the signal remained blocked. -Dan
597 sigfillset(&sig_action
.sa_mask
);
598 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
600 /* handle X shutdowns a such */
601 XSetIOErrorHandler(handleXIO
);
603 /* set hook for out event dispatcher in WINGs event dispatcher */
604 WMHookEventHandler(DispatchEvent
);
606 /* initialize defaults stuff */
607 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
608 if (!WDWindowMaker
->dictionary
)
609 wwarning(_("could not read domain \"%s\" from defaults database"), "WindowMaker");
611 /* read defaults that don't change until a restart and are
612 * screen independent */
613 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
615 /* check sanity of some values */
616 if (wPreferences
.icon_size
< 16) {
617 wwarning(_("icon size is configured to %i, but it's too small. Using 16 instead"),
618 wPreferences
.icon_size
);
619 wPreferences
.icon_size
= 16;
622 /* init other domains */
623 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
624 if (!WDRootMenu
->dictionary
)
625 wwarning(_("could not read domain \"%s\" from defaults database"), "WMRootMenu");
627 wDefaultsMergeGlobalMenus(WDRootMenu
);
629 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
630 if (!WDWindowAttributes
->dictionary
)
631 wwarning(_("could not read domain \"%s\" from defaults database"), "WMWindowAttributes");
633 XSetErrorHandler((XErrorHandler
) catchXError
);
637 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
641 has_randr
= XRRQueryExtension(dpy
, &randr_event_base
, &dummy
);
644 #ifdef KEEP_XKB_LOCK_STATUS
645 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
646 if (wPreferences
.modelock
&& !wXkbSupported
) {
647 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
648 wPreferences
.modelock
= 0;
652 if (defaultScreenOnly
)
655 max
= ScreenCount(dpy
);
657 wScreen
= wmalloc(sizeof(WScreen
*) * max
);
661 /* Check if TIFF images are supported */
662 formats
= RSupportedFileFormats();
664 for (i
= 0; formats
[i
] != NULL
; i
++) {
665 if (strcmp(formats
[i
], "TIFF") == 0) {
666 wPreferences
.supports_tiff
= 1;
672 /* manage the screens */
673 for (j
= 0; j
< max
; j
++) {
674 if (defaultScreenOnly
|| max
== 1) {
675 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
676 if (!wScreen
[wScreenCount
]) {
677 wfatal(_("it seems that there is already a window manager running"));
681 wScreen
[wScreenCount
] = wScreenInit(j
);
682 if (!wScreen
[wScreenCount
]) {
683 wwarning(_("could not manage screen %i"), j
);
690 InitializeSwitchMenu();
692 /* initialize/restore state for the screens */
693 for (j
= 0; j
< wScreenCount
; j
++) {
696 lastDesktop
= wNETWMGetCurrentDesktopFromHint(wScreen
[j
]);
698 wScreenRestoreState(wScreen
[j
]);
700 /* manage all windows that were already here before us */
701 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
702 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
704 manageAllWindows(wScreen
[j
], wPreferences
.flags
.restarting
== 2);
706 /* restore saved menus */
707 wMenuRestoreState(wScreen
[j
]);
709 /* If we're not restarting, restore session */
710 if (wPreferences
.flags
.restarting
== 0 && !wPreferences
.flags
.norestore
)
711 wSessionRestoreState(wScreen
[j
]);
713 if (!wPreferences
.flags
.noautolaunch
) {
714 /* auto-launch apps */
715 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
716 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
717 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
719 /* auto-launch apps in clip */
720 if (!wPreferences
.flags
.noclip
) {
722 for (i
= 0; i
< w_global
.workspace
.count
; i
++) {
723 if (w_global
.workspace
.array
[i
]->clip
) {
724 wScreen
[j
]->last_dock
= w_global
.workspace
.array
[i
]->clip
;
725 wDockDoAutoLaunch(w_global
.workspace
.array
[i
]->clip
, i
);
729 /* auto-launch apps in drawers */
730 if (!wPreferences
.flags
.nodrawer
) {
732 for (dc
= wScreen
[j
]->drawers
; dc
; dc
= dc
->next
) {
733 wScreen
[j
]->last_dock
= dc
->adrawer
;
734 wDockDoAutoLaunch(dc
->adrawer
, 0);
739 /* go to workspace where we were before restart */
740 if (lastDesktop
>= 0)
741 wWorkspaceForceChange(wScreen
[j
], lastDesktop
);
743 wSessionRestoreLastWorkspace(wScreen
[j
]);
746 if (wScreenCount
== 0) {
747 wfatal(_("could not manage any screen"));
752 /* setup defaults file polling */
753 if (!wPreferences
.flags
.nopolling
&& !wPreferences
.flags
.noupdates
)
754 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
759 static Bool
windowInList(Window window
, Window
* list
, int count
)
761 for (; count
>= 0; count
--) {
762 if (window
== list
[count
])
769 *-----------------------------------------------------------------------
771 * Manages all windows in the screen.
774 * Called when the wm is being started.
775 * No events can be processed while the windows are being
776 * reparented/managed.
777 *-----------------------------------------------------------------------
779 static void manageAllWindows(WScreen
* scr
, int crashRecovery
)
783 unsigned int nchildren
;
788 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
790 scr
->flags
.startup
= 1;
792 /* first remove all icon windows */
793 for (i
= 0; i
< nchildren
; i
++) {
796 if (children
[i
] == None
)
799 wmhints
= XGetWMHints(dpy
, children
[i
]);
800 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
801 for (j
= 0; j
< nchildren
; j
++) {
802 if (children
[j
] == wmhints
->icon_window
) {
815 for (i
= 0; i
< nchildren
; i
++) {
816 if (children
[i
] == None
)
819 wwin
= wManageWindow(scr
, children
[i
]);
821 /* apply states got from WSavedState */
822 /* shaded + minimized is not restored correctly */
823 if (wwin
->flags
.shaded
) {
824 wwin
->flags
.shaded
= 0;
827 if (wwin
->flags
.miniaturized
828 && (wwin
->transient_for
== None
829 || wwin
->transient_for
== scr
->root_win
830 || !windowInList(wwin
->transient_for
, children
, nchildren
))) {
832 wwin
->flags
.skip_next_animation
= 1;
833 wwin
->flags
.miniaturized
= 0;
834 wIconifyWindow(wwin
);
836 wClientSetState(wwin
, NormalState
, None
);
841 border
= (!HAS_BORDER(wwin
) ? 0 : scr
->frame_border_width
);
843 wWindowMove(wwin
, wwin
->frame_x
- border
,
844 wwin
->frame_y
- border
-
845 (wwin
->frame
->titlebar
? wwin
->frame
->titlebar
->height
: 0));
852 wwin
= scr
->focused_window
;
854 if (wwin
->flags
.hidden
) {
855 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
858 wwin
->flags
.hidden
= 0;
859 wHideApplication(wapp
);
861 wwin
->flags
.hidden
= 0;
868 scr
->flags
.startup
= 0;
869 scr
->flags
.startup2
= 1;
871 while (XPending(dpy
)) {
873 WMNextEvent(dpy
, &ev
);
876 w_global
.workspace
.last_used
= 0;
877 wWorkspaceForceChange(scr
, 0);
878 if (!wPreferences
.flags
.noclip
)
879 wDockShowIcons(w_global
.workspace
.array
[w_global
.workspace
.current
]->clip
);
880 scr
->flags
.startup2
= 0;