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
;
105 extern XContext wWinContext
;
106 extern XContext wAppWinContext
;
107 extern XContext wStackContext
;
108 extern XContext wVEdgeContext
;
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
;
120 extern Atom _XA_GNUSTEP_WM_ATTR
;
121 extern Atom _XA_WINDOWMAKER_MENU
;
122 extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
123 extern Atom _XA_WINDOWMAKER_STATE
;
124 extern Atom _XA_WINDOWMAKER_WM_FUNCTION
;
125 extern Atom _XA_WINDOWMAKER_NOTICEBOARD
;
126 extern Atom _XA_WINDOWMAKER_COMMAND
;
127 extern Atom _XA_WINDOWMAKER_ICON_SIZE
;
128 extern Atom _XA_WINDOWMAKER_ICON_TILE
;
129 extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
130 extern Atom _XA_GNUSTEP_TITLEBAR_STATE
;
131 extern Atom _XA_WM_IGNORE_FOCUS_EVENTS
;
134 extern Cursor wCursor
[WCUR_LAST
];
138 extern char WDelayedActionSet
;
141 extern void NotifyDeadProcess(pid_t pid
, unsigned char status
);
144 static WScreen
**wScreen
= NULL
;
145 static unsigned int _NumLockMask
= 0;
146 static unsigned int _ScrollLockMask
= 0;
147 static void manageAllWindows(WScreen
* scr
, int crashed
);
149 static int catchXError(Display
* dpy
, XErrorEvent
* error
)
151 char buffer
[MAXLINE
];
153 /* ignore some errors */
154 if (error
->resourceid
!= None
155 && ((error
->error_code
== BadDrawable
&& error
->request_code
== X_GetGeometry
)
156 || (error
->error_code
== BadMatch
&& (error
->request_code
== X_SetInputFocus
))
157 || (error
->error_code
== BadWindow
)
159 && (error->request_code == X_GetWindowAttributes
160 || error->request_code == X_SetInputFocus
161 || error->request_code == X_ChangeWindowAttributes
162 || error->request_code == X_GetProperty
163 || error->request_code == X_ChangeProperty
164 || error->request_code == X_QueryTree
165 || error->request_code == X_GrabButton
166 || error->request_code == X_UngrabButton
167 || error->request_code == X_SendEvent
168 || error->request_code == X_ConfigureWindow))
170 || (error
->request_code
== X_InstallColormap
))) {
173 FormatXError(dpy
, error
, buffer
, MAXLINE
);
174 wwarning(_("internal X error: %s"), buffer
);
179 *----------------------------------------------------------------------
181 * Handle X shutdowns and other stuff.
182 *----------------------------------------------------------------------
184 static int handleXIO(Display
* xio_dpy
)
193 *----------------------------------------------------------------------
195 * Action to be executed after the signal() handler is exited.
196 *----------------------------------------------------------------------
198 static void delayedAction(void *cdata
)
200 if (WDelayedActionSet
== 0)
205 * Make the event dispatcher do whatever it needs to do,
206 * including handling zombie processes, restart and exit
214 *----------------------------------------------------------------------
216 * User generated exit signal handler.
217 *----------------------------------------------------------------------
219 static RETSIGTYPE
handleExitSig(int sig
)
224 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
226 if (sig
== SIGUSR1
) {
227 wwarning("got signal %i - restarting", sig
);
228 SIG_WCHANGE_STATE(WSTATE_NEED_RESTART
);
229 } else if (sig
== SIGUSR2
) {
230 wwarning("got signal %i - rereading defaults", sig
);
231 SIG_WCHANGE_STATE(WSTATE_NEED_REREAD
);
232 } else if (sig
== SIGTERM
|| sig
== SIGINT
|| sig
== SIGHUP
) {
233 wwarning("got signal %i - exiting...", sig
);
234 SIG_WCHANGE_STATE(WSTATE_NEED_EXIT
);
237 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
238 DispatchEvent(NULL
); /* Dispatch events imediately. */
241 /* Dummy signal handler */
242 static void dummyHandler(int sig
)
247 *----------------------------------------------------------------------
249 * general signal handler. Exits the program gently.
250 *----------------------------------------------------------------------
252 static RETSIGTYPE
handleSig(int sig
)
254 wfatal("got signal %i", sig
);
256 /* Setting the signal behaviour back to default and then reraising the
257 * signal is a cleaner way to make program exit and core dump than calling
258 * abort(), since it correctly returns from the signal handler and sets
259 * the flags accordingly. -Dan
261 if (sig
== SIGSEGV
|| sig
== SIGFPE
|| sig
== SIGBUS
|| sig
== SIGILL
|| sig
== SIGABRT
) {
262 signal(sig
, SIG_DFL
);
270 static RETSIGTYPE
buryChild(int foo
)
274 int save_errno
= errno
;
278 /* Block signals so that NotifyDeadProcess() doesn't get fux0red */
279 sigprocmask(SIG_BLOCK
, &sigs
, NULL
);
282 /* If 2 or more kids exit in a small time window, before this handler gets
283 * the chance to get invoked, the SIGCHLD signals will be merged and only
284 * one SIGCHLD signal will be sent to us. We use a while loop to get all
285 * exited child status because we can't count on the number of SIGCHLD
286 * signals to know exactly how many kids have exited. -Dan
288 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0 || (pid
< 0 && errno
== EINTR
)) {
289 NotifyDeadProcess(pid
, WEXITSTATUS(status
));
292 sigprocmask(SIG_UNBLOCK
, &sigs
, NULL
);
297 static void getOffendingModifiers(void)
300 XModifierKeymap
*modmap
;
301 KeyCode nlock
, slock
;
302 static int mask_table
[8] = {
303 ShiftMask
, LockMask
, ControlMask
, Mod1Mask
,
304 Mod2Mask
, Mod3Mask
, Mod4Mask
, Mod5Mask
307 nlock
= XKeysymToKeycode(dpy
, XK_Num_Lock
);
308 slock
= XKeysymToKeycode(dpy
, XK_Scroll_Lock
);
311 * Find out the masks for the NumLock and ScrollLock modifiers,
312 * so that we can bind the grabs for when they are enabled too.
314 modmap
= XGetModifierMapping(dpy
);
316 if (modmap
!= NULL
&& modmap
->max_keypermod
> 0) {
317 for (i
= 0; i
< 8 * modmap
->max_keypermod
; i
++) {
318 if (modmap
->modifiermap
[i
] == nlock
&& nlock
!= 0)
319 _NumLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
320 else if (modmap
->modifiermap
[i
] == slock
&& slock
!= 0)
321 _ScrollLockMask
= mask_table
[i
/ modmap
->max_keypermod
];
326 XFreeModifiermap(modmap
);
331 wHackedGrabKey(int keycode
, unsigned int modifiers
,
332 Window grab_window
, Bool owner_events
, int pointer_mode
, int keyboard_mode
)
334 if (modifiers
== AnyModifier
)
337 /* grab all combinations of the modifier with CapsLock, NumLock and
338 * ScrollLock. How much memory/CPU does such a monstrosity consume
342 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
,
343 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
345 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
,
346 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
347 if (_NumLockMask
&& _ScrollLockMask
)
348 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
,
349 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
351 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| LockMask
,
352 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
354 XGrabKey(dpy
, keycode
, modifiers
| _ScrollLockMask
| LockMask
,
355 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
356 if (_NumLockMask
&& _ScrollLockMask
)
357 XGrabKey(dpy
, keycode
, modifiers
| _NumLockMask
| _ScrollLockMask
| LockMask
,
358 grab_window
, owner_events
, pointer_mode
, keyboard_mode
);
359 /* phew, I guess that's all, right? */
364 wHackedGrabButton(unsigned int button
, unsigned int modifiers
,
365 Window grab_window
, Bool owner_events
,
366 unsigned int event_mask
, int pointer_mode
, int keyboard_mode
, Window confine_to
, Cursor cursor
)
368 XGrabButton(dpy
, button
, modifiers
, grab_window
, owner_events
,
369 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
371 if (modifiers
== AnyModifier
)
374 XGrabButton(dpy
, button
, modifiers
| LockMask
, grab_window
, owner_events
,
375 event_mask
, pointer_mode
, keyboard_mode
, confine_to
, cursor
);
378 /* same as above, but for mouse buttons */
380 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
,
381 grab_window
, owner_events
, event_mask
, pointer_mode
,
382 keyboard_mode
, confine_to
, cursor
);
384 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
,
385 grab_window
, owner_events
, event_mask
, pointer_mode
,
386 keyboard_mode
, confine_to
, cursor
);
387 if (_NumLockMask
&& _ScrollLockMask
)
388 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
,
389 grab_window
, owner_events
, event_mask
, pointer_mode
,
390 keyboard_mode
, confine_to
, cursor
);
392 XGrabButton(dpy
, button
, modifiers
| _NumLockMask
| LockMask
,
393 grab_window
, owner_events
, event_mask
, pointer_mode
,
394 keyboard_mode
, confine_to
, cursor
);
396 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| LockMask
,
397 grab_window
, owner_events
, event_mask
, pointer_mode
,
398 keyboard_mode
, confine_to
, cursor
);
399 if (_NumLockMask
&& _ScrollLockMask
)
400 XGrabButton(dpy
, button
, modifiers
| _ScrollLockMask
| _NumLockMask
| LockMask
,
401 grab_window
, owner_events
, event_mask
, pointer_mode
,
402 keyboard_mode
, confine_to
, cursor
);
403 #endif /* NUMLOCK_HACK */
406 WScreen
*wScreenWithNumber(int i
)
408 assert(i
< wScreenCount
);
413 WScreen
*wScreenForRootWindow(Window window
)
417 if (wScreenCount
== 1)
420 /* Since the number of heads will probably be small (normally 2),
421 * it should be faster to use this than a hash table, because
422 * of the overhead. */
423 for (i
= 0; i
< wScreenCount
; i
++)
424 if (wScreen
[i
]->root_win
== window
)
427 return wScreenForWindow(window
);
430 WScreen
*wScreenForWindow(Window window
)
432 XWindowAttributes attr
;
434 if (wScreenCount
== 1)
437 if (XGetWindowAttributes(dpy
, window
, &attr
))
438 return wScreenForRootWindow(attr
.root
);
443 static char *atomNames
[] = {
451 "WM_COLORMAP_WINDOWS",
452 "WM_COLORMAP_NOTIFY",
455 "_WINDOWMAKER_STATE",
456 "_WINDOWMAKER_WM_PROTOCOLS",
457 "_WINDOWMAKER_WM_FUNCTION",
458 "_WINDOWMAKER_NOTICEBOARD",
459 "_WINDOWMAKER_COMMAND",
460 "_WINDOWMAKER_ICON_SIZE",
461 "_WINDOWMAKER_ICON_TILE",
463 GNUSTEP_WM_ATTR_NAME
,
464 GNUSTEP_WM_MINIATURIZE_WINDOW
,
465 GNUSTEP_TITLEBAR_STATE
,
467 "WM_IGNORE_FOCUS_EVENTS"
471 *----------------------------------------------------------
473 * starts the window manager and setup global data.
474 * Called from main() at startup.
477 * global data declared in main.c is initialized
478 *----------------------------------------------------------
480 void StartUp(Bool defaultScreenOnly
)
482 struct sigaction sig_action
;
487 Atom atom
[sizeof(atomNames
) / sizeof(atomNames
[0])];
490 * Ignore CapsLock in modifiers
492 ValidModMask
= 0xff & ~LockMask
;
494 getOffendingModifiers();
496 * Ignore NumLock and ScrollLock too
498 ValidModMask
&= ~(_NumLockMask
| _ScrollLockMask
);
500 memset(&wKeyBindings
, 0, sizeof(wKeyBindings
));
502 wWinContext
= XUniqueContext();
503 wAppWinContext
= XUniqueContext();
504 wStackContext
= XUniqueContext();
505 wVEdgeContext
= XUniqueContext();
507 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
509 #ifdef HAVE_XINTERNATOMS
510 XInternAtoms(dpy
, atomNames
, sizeof(atomNames
) / sizeof(atomNames
[0]), False
, atom
);
515 for (i
= 0; i
< sizeof(atomNames
) / sizeof(atomNames
[0]); i
++)
516 atom
[i
] = XInternAtom(dpy
, atomNames
[i
], False
);
520 _XA_WM_STATE
= atom
[0];
521 _XA_WM_CHANGE_STATE
= atom
[1];
522 _XA_WM_PROTOCOLS
= atom
[2];
523 _XA_WM_TAKE_FOCUS
= atom
[3];
524 _XA_WM_DELETE_WINDOW
= atom
[4];
525 _XA_WM_SAVE_YOURSELF
= atom
[5];
526 _XA_WM_CLIENT_LEADER
= atom
[6];
527 _XA_WM_COLORMAP_WINDOWS
= atom
[7];
528 _XA_WM_COLORMAP_NOTIFY
= atom
[8];
530 _XA_WINDOWMAKER_MENU
= atom
[9];
531 _XA_WINDOWMAKER_STATE
= atom
[10];
532 _XA_WINDOWMAKER_WM_PROTOCOLS
= atom
[11];
533 _XA_WINDOWMAKER_WM_FUNCTION
= atom
[12];
534 _XA_WINDOWMAKER_NOTICEBOARD
= atom
[13];
535 _XA_WINDOWMAKER_COMMAND
= atom
[14];
536 _XA_WINDOWMAKER_ICON_SIZE
= atom
[15];
537 _XA_WINDOWMAKER_ICON_TILE
= atom
[16];
539 _XA_GNUSTEP_WM_ATTR
= atom
[17];
540 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
= atom
[18];
541 _XA_GNUSTEP_TITLEBAR_STATE
= atom
[19];
543 _XA_WM_IGNORE_FOCUS_EVENTS
= atom
[20];
546 wXDNDInitializeAtoms();
550 wCursor
[WCUR_NORMAL
] = None
; /* inherit from root */
551 wCursor
[WCUR_ROOT
] = XCreateFontCursor(dpy
, XC_left_ptr
);
552 wCursor
[WCUR_ARROW
] = XCreateFontCursor(dpy
, XC_top_left_arrow
);
553 wCursor
[WCUR_MOVE
] = XCreateFontCursor(dpy
, XC_fleur
);
554 wCursor
[WCUR_RESIZE
] = XCreateFontCursor(dpy
, XC_sizing
);
555 wCursor
[WCUR_TOPLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_top_left_corner
);
556 wCursor
[WCUR_TOPRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_top_right_corner
);
557 wCursor
[WCUR_BOTTOMLEFTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_left_corner
);
558 wCursor
[WCUR_BOTTOMRIGHTRESIZE
] = XCreateFontCursor(dpy
, XC_bottom_right_corner
);
559 wCursor
[WCUR_VERTICALRESIZE
] = XCreateFontCursor(dpy
, XC_sb_v_double_arrow
);
560 wCursor
[WCUR_HORIZONRESIZE
] = XCreateFontCursor(dpy
, XC_sb_h_double_arrow
);
561 wCursor
[WCUR_WAIT
] = XCreateFontCursor(dpy
, XC_watch
);
562 wCursor
[WCUR_QUESTION
] = XCreateFontCursor(dpy
, XC_question_arrow
);
563 wCursor
[WCUR_TEXT
] = XCreateFontCursor(dpy
, XC_xterm
); /* odd name??? */
564 wCursor
[WCUR_SELECT
] = XCreateFontCursor(dpy
, XC_cross
);
566 Pixmap cur
= XCreatePixmap(dpy
, DefaultRootWindow(dpy
), 16, 16, 1);
567 GC gc
= XCreateGC(dpy
, cur
, 0, NULL
);
569 memset(&black
, 0, sizeof(XColor
));
570 XSetForeground(dpy
, gc
, 0);
571 XFillRectangle(dpy
, cur
, gc
, 0, 0, 16, 16);
573 wCursor
[WCUR_EMPTY
] = XCreatePixmapCursor(dpy
, cur
, cur
, &black
, &black
, 0, 0);
574 XFreePixmap(dpy
, cur
);
578 /* signal handler stuff that gets called when a signal is caught */
579 WMAddPersistentTimerHandler(500, delayedAction
, NULL
);
582 /* emergency exit... */
583 sig_action
.sa_handler
= handleSig
;
584 sigemptyset(&sig_action
.sa_mask
);
586 sig_action
.sa_flags
= SA_RESTART
;
587 sigaction(SIGQUIT
, &sig_action
, NULL
);
588 /* instead of catching these, we let the default handler abort the
589 * program. The new monitor process will take appropriate action
590 * when it detects the crash.
591 sigaction(SIGSEGV, &sig_action, NULL);
592 sigaction(SIGBUS, &sig_action, NULL);
593 sigaction(SIGFPE, &sig_action, NULL);
594 sigaction(SIGABRT, &sig_action, NULL);
597 sig_action
.sa_handler
= handleExitSig
;
599 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
600 * immediately. -Dan */
601 sig_action
.sa_flags
= SA_RESTART
;
602 sigaction(SIGTERM
, &sig_action
, NULL
);
603 sigaction(SIGINT
, &sig_action
, NULL
);
604 sigaction(SIGHUP
, &sig_action
, NULL
);
605 sigaction(SIGUSR1
, &sig_action
, NULL
);
606 sigaction(SIGUSR2
, &sig_action
, NULL
);
608 /* ignore dead pipe */
609 /* Because POSIX mandates that only signal with handlers are reset
610 * accross an exec*(), we do not want to propagate ignoring SIGPIPEs
611 * to children. Hence the dummy handler.
612 * Philippe Troin <phil@fifi.org>
614 sig_action
.sa_handler
= &dummyHandler
;
615 sig_action
.sa_flags
= SA_RESTART
;
616 sigaction(SIGPIPE
, &sig_action
, NULL
);
618 /* handle dead children */
619 sig_action
.sa_handler
= buryChild
;
620 sig_action
.sa_flags
= SA_NOCLDSTOP
| SA_RESTART
;
621 sigaction(SIGCHLD
, &sig_action
, NULL
);
623 /* Now we unblock all signals, that may have been blocked by the parent
624 * who exec()-ed us. This can happen for example if Window Maker crashes
625 * and restarts itself or another window manager from the signal handler.
626 * In this case, the new proccess inherits the blocked signal mask and
627 * will no longer react to that signal, until unblocked.
628 * This is because the signal handler of the proccess who crashed (parent)
629 * didn't return, and the signal remained blocked. -Dan
631 sigfillset(&sig_action
.sa_mask
);
632 sigprocmask(SIG_UNBLOCK
, &sig_action
.sa_mask
, NULL
);
634 /* handle X shutdowns a such */
635 XSetIOErrorHandler(handleXIO
);
637 /* set hook for out event dispatcher in WINGs event dispatcher */
638 WMHookEventHandler(DispatchEvent
);
640 /* initialize defaults stuff */
641 WDWindowMaker
= wDefaultsInitDomain("WindowMaker", True
);
642 if (!WDWindowMaker
->dictionary
)
643 wwarning(_("could not read domain \"%s\" from defaults database"), "WindowMaker");
645 /* read defaults that don't change until a restart and are
646 * screen independent */
647 wReadStaticDefaults(WDWindowMaker
? WDWindowMaker
->dictionary
: NULL
);
649 /* check sanity of some values */
650 if (wPreferences
.icon_size
< 16) {
651 wwarning(_("icon size is configured to %i, but it's too small. Using 16 instead"),
652 wPreferences
.icon_size
);
653 wPreferences
.icon_size
= 16;
656 /* init other domains */
657 WDRootMenu
= wDefaultsInitDomain("WMRootMenu", False
);
658 if (!WDRootMenu
->dictionary
)
659 wwarning(_("could not read domain \"%s\" from defaults database"), "WMRootMenu");
661 wDefaultsMergeGlobalMenus(WDRootMenu
);
663 WDWindowAttributes
= wDefaultsInitDomain("WMWindowAttributes", True
);
664 if (!WDWindowAttributes
->dictionary
)
665 wwarning(_("could not read domain \"%s\" from defaults database"), "WMWindowAttributes");
667 XSetErrorHandler((XErrorHandler
) catchXError
);
671 wShapeSupported
= XShapeQueryExtension(dpy
, &wShapeEventBase
, &j
);
675 has_randr
= XRRQueryExtension(dpy
, &randr_event_base
, &dummy
);
678 #ifdef KEEP_XKB_LOCK_STATUS
679 wXkbSupported
= XkbQueryExtension(dpy
, NULL
, &wXkbEventBase
, NULL
, NULL
, NULL
);
680 if (wPreferences
.modelock
&& !wXkbSupported
) {
681 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
682 wPreferences
.modelock
= 0;
686 if (defaultScreenOnly
)
689 max
= ScreenCount(dpy
);
691 wScreen
= wmalloc(sizeof(WScreen
*) * max
);
695 /* manage the screens */
696 for (j
= 0; j
< max
; j
++) {
697 if (defaultScreenOnly
|| max
== 1) {
698 wScreen
[wScreenCount
] = wScreenInit(DefaultScreen(dpy
));
699 if (!wScreen
[wScreenCount
]) {
700 wfatal(_("it seems that there is already a window manager running"));
704 wScreen
[wScreenCount
] = wScreenInit(j
);
705 if (!wScreen
[wScreenCount
]) {
706 wwarning(_("could not manage screen %i"), j
);
713 InitializeSwitchMenu();
715 /* initialize/restore state for the screens */
716 for (j
= 0; j
< wScreenCount
; j
++) {
719 lastDesktop
= wNETWMGetCurrentDesktopFromHint(wScreen
[j
]);
721 wScreenRestoreState(wScreen
[j
]);
723 /* manage all windows that were already here before us */
724 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
)
725 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
727 manageAllWindows(wScreen
[j
], wPreferences
.flags
.restarting
== 2);
729 /* restore saved menus */
730 wMenuRestoreState(wScreen
[j
]);
732 /* If we're not restarting, restore session */
733 if (wPreferences
.flags
.restarting
== 0 && !wPreferences
.flags
.norestore
)
734 wSessionRestoreState(wScreen
[j
]);
736 if (!wPreferences
.flags
.noautolaunch
) {
737 /* auto-launch apps */
738 if (!wPreferences
.flags
.nodock
&& wScreen
[j
]->dock
) {
739 wScreen
[j
]->last_dock
= wScreen
[j
]->dock
;
740 wDockDoAutoLaunch(wScreen
[j
]->dock
, 0);
742 /* auto-launch apps in clip */
743 if (!wPreferences
.flags
.noclip
) {
745 for (i
= 0; i
< wScreen
[j
]->workspace_count
; i
++) {
746 if (wScreen
[j
]->workspaces
[i
]->clip
) {
747 wScreen
[j
]->last_dock
= wScreen
[j
]->workspaces
[i
]->clip
;
748 wDockDoAutoLaunch(wScreen
[j
]->workspaces
[i
]->clip
, i
);
752 /* auto-launch apps in drawers */
753 if (!wPreferences
.flags
.nodrawer
) {
755 for (dc
= wScreen
[j
]->drawers
; dc
; dc
= dc
->next
) {
756 wScreen
[j
]->last_dock
= dc
->adrawer
;
757 wDockDoAutoLaunch(dc
->adrawer
, 0);
762 /* go to workspace where we were before restart */
763 if (lastDesktop
>= 0)
764 wWorkspaceForceChange(wScreen
[j
], lastDesktop
);
766 wSessionRestoreLastWorkspace(wScreen
[j
]);
769 if (wScreenCount
== 0) {
770 wfatal(_("could not manage any screen"));
775 /* setup defaults file polling */
776 if (!wPreferences
.flags
.nopolling
&& !wPreferences
.flags
.noupdates
)
777 WMAddTimerHandler(3000, wDefaultsCheckDomains
, NULL
);
782 static Bool
windowInList(Window window
, Window
* list
, int count
)
784 for (; count
>= 0; count
--) {
785 if (window
== list
[count
])
792 *-----------------------------------------------------------------------
794 * Manages all windows in the screen.
797 * Called when the wm is being started.
798 * No events can be processed while the windows are being
799 * reparented/managed.
800 *-----------------------------------------------------------------------
802 static void manageAllWindows(WScreen
* scr
, int crashRecovery
)
806 unsigned int nchildren
;
811 XQueryTree(dpy
, scr
->root_win
, &root
, &parent
, &children
, &nchildren
);
813 scr
->flags
.startup
= 1;
815 /* first remove all icon windows */
816 for (i
= 0; i
< nchildren
; i
++) {
819 if (children
[i
] == None
)
822 wmhints
= XGetWMHints(dpy
, children
[i
]);
823 if (wmhints
&& (wmhints
->flags
& IconWindowHint
)) {
824 for (j
= 0; j
< nchildren
; j
++) {
825 if (children
[j
] == wmhints
->icon_window
) {
838 for (i
= 0; i
< nchildren
; i
++) {
839 if (children
[i
] == None
)
842 wwin
= wManageWindow(scr
, children
[i
]);
844 /* apply states got from WSavedState */
845 /* shaded + minimized is not restored correctly */
846 if (wwin
->flags
.shaded
) {
847 wwin
->flags
.shaded
= 0;
850 if (wwin
->flags
.miniaturized
851 && (wwin
->transient_for
== None
852 || wwin
->transient_for
== scr
->root_win
853 || !windowInList(wwin
->transient_for
, children
, nchildren
))) {
855 wwin
->flags
.skip_next_animation
= 1;
856 wwin
->flags
.miniaturized
= 0;
857 wIconifyWindow(wwin
);
859 wClientSetState(wwin
, NormalState
, None
);
864 border
= (!HAS_BORDER(wwin
) ? 0 : scr
->frame_border_width
);
866 wWindowMove(wwin
, wwin
->frame_x
- border
,
867 wwin
->frame_y
- border
-
868 (wwin
->frame
->titlebar
? wwin
->frame
->titlebar
->height
: 0));
875 wwin
= scr
->focused_window
;
877 if (wwin
->flags
.hidden
) {
878 WApplication
*wapp
= wApplicationOf(wwin
->main_window
);
881 wwin
->flags
.hidden
= 0;
882 wHideApplication(wapp
);
884 wwin
->flags
.hidden
= 0;
891 scr
->flags
.startup
= 0;
892 scr
->flags
.startup2
= 1;
894 while (XPending(dpy
)) {
896 WMNextEvent(dpy
, &ev
);
899 scr
->last_workspace
= 0;
900 wWorkspaceForceChange(scr
, 0);
901 if (!wPreferences
.flags
.noclip
)
902 wDockShowIcons(scr
->workspaces
[scr
->current_workspace
]->clip
);
903 scr
->flags
.startup2
= 0;