Make wmaker XRandR aware
[wmaker-crm.git] / src / startup.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/*
9af1c6c4 dan1998-10-21 14:43:47 +00002 * Window Maker window manager
59eb9475 dan1998-11-03 12:53:26 +00003 *
4153e2fd dan2003-01-16 23:30:45 +00004 * Copyright (c) 1997-2003 Alfredo K. Kojima
5 * Copyright (c) 1998-2003 Dan Pascu
59eb9475 dan1998-11-03 12:53:26 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
23#include "wconfig.h"
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
c0317dda dan2005-08-22 23:58:19 +000028#include <string.h>
bb6182f4 dan2000-11-29 05:15:59 +000029#include <errno.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000030#include <signal.h>
31#include <sys/wait.h>
32#ifdef __FreeBSD__
33#include <sys/signal.h>
34#endif
35
36#include <X11/Xlib.h>
0c469de0 Carlos R. Mafra2008-11-10 01:35:57 +010037#include <X11/Xresource.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000038#include <X11/Xutil.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000039#include <X11/cursorfont.h>
40#include <X11/Xproto.h>
41#include <X11/keysym.h>
9af1c6c4 dan1998-10-21 14:43:47 +000042#ifdef SHAPE
43#include <X11/extensions/shape.h>
44#endif
65aa3ae9
BJ
Brad Jorsch2010-04-08 17:01:24 -040045#ifdef KEEP_XKB_LOCK_STATUS
46#include <X11/XKBlib.h>
47#endif
c201e161
CM
Carlos R. Mafra2010-08-22 19:05:07 +020048#ifdef HAVE_XRANDR
49#include <X11/extensions/Xrandr.h>
50#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000051
52#include "WindowMaker.h"
53#include "GNUstep.h"
9d2e6ef9 scottc1998-09-29 22:36:29 +000054#include "texture.h"
55#include "screen.h"
56#include "window.h"
57#include "actions.h"
58#include "client.h"
59#include "funcs.h"
60#include "dock.h"
61#include "workspace.h"
62#include "keybind.h"
63#include "framewin.h"
64#include "session.h"
65#include "defaults.h"
088c0ac2 dan1999-03-09 14:58:01 +000066#include "properties.h"
52917e53 dan1999-04-16 20:05:26 +000067#include "dialog.h"
0d9b73cd dan2004-10-25 02:23:41 +000068#include "wmspec.h"
d4025072 id1999-05-17 20:21:43 +000069#ifdef XDND
70#include "xdnd.h"
71#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +000072
73#include "xutil.h"
74
9007a657 dan1998-11-23 11:32:19 +000075/* for SunOS */
76#ifndef SA_RESTART
77# define SA_RESTART 0
78#endif
79
4eb26a0b dan2000-11-25 04:13:39 +000080/* Just in case, for weirdo systems */
81#ifndef SA_NODEFER
82# define SA_NODEFER 0
83#endif
9007a657 dan1998-11-23 11:32:19 +000084
9d2e6ef9 scottc1998-09-29 22:36:29 +000085/****** Global Variables ******/
9d2e6ef9 scottc1998-09-29 22:36:29 +000086extern WPreferences wPreferences;
9d2e6ef9 scottc1998-09-29 22:36:29 +000087extern WDDomain *WDWindowMaker;
88extern WDDomain *WDRootMenu;
89extern WDDomain *WDWindowAttributes;
9d2e6ef9 scottc1998-09-29 22:36:29 +000090extern WShortKey wKeyBindings[WKBD_LAST];
9d2e6ef9 scottc1998-09-29 22:36:29 +000091extern int wScreenCount;
92
9af1c6c4 dan1998-10-21 14:43:47 +000093#ifdef SHAPE
94extern Bool wShapeSupported;
95extern int wShapeEventBase;
96#endif
97
daaccf6f id1999-05-23 23:48:08 +000098#ifdef KEEP_XKB_LOCK_STATUS
99extern Bool wXkbSupported;
100extern int wXkbEventBase;
101#endif
102
c201e161
CM
Carlos R. Mafra2010-08-22 19:05:07 +0200103#ifdef HAVE_XRANDR
104extern Bool has_randr;
105extern int randr_event_base;
106#endif
107
9d2e6ef9 scottc1998-09-29 22:36:29 +0000108/* contexts */
109extern XContext wWinContext;
110extern XContext wAppWinContext;
111extern XContext wStackContext;
9aca0d5f dan2004-10-12 01:34:32 +0000112extern XContext wVEdgeContext;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000113
114/* atoms */
115extern Atom _XA_WM_STATE;
116extern Atom _XA_WM_CHANGE_STATE;
117extern Atom _XA_WM_PROTOCOLS;
118extern Atom _XA_WM_TAKE_FOCUS;
119extern Atom _XA_WM_DELETE_WINDOW;
120extern Atom _XA_WM_SAVE_YOURSELF;
121extern Atom _XA_WM_CLIENT_LEADER;
122extern Atom _XA_WM_COLORMAP_WINDOWS;
59eb9475 dan1998-11-03 12:53:26 +0000123extern Atom _XA_WM_COLORMAP_NOTIFY;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000124extern Atom _XA_GNUSTEP_WM_ATTR;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000125extern Atom _XA_WINDOWMAKER_MENU;
126extern Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
127extern Atom _XA_WINDOWMAKER_STATE;
128extern Atom _XA_WINDOWMAKER_WM_FUNCTION;
416e3a82 dan1999-01-25 19:06:50 +0000129extern Atom _XA_WINDOWMAKER_NOTICEBOARD;
9df0e167 kojima1999-04-03 03:51:17 +0000130extern Atom _XA_WINDOWMAKER_COMMAND;
754230a6 kojima2000-02-16 18:26:15 +0000131extern Atom _XA_WINDOWMAKER_ICON_SIZE;
132extern Atom _XA_WINDOWMAKER_ICON_TILE;
9af1c6c4 dan1998-10-21 14:43:47 +0000133extern Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
0af24483 richard2000-03-02 07:36:02 +0000134extern Atom _XA_GNUSTEP_TITLEBAR_STATE;
3f7110b1
DD
Daniel Déchelotte2009-08-19 00:50:49 +0200135extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
136
9d2e6ef9 scottc1998-09-29 22:36:29 +0000137/* cursors */
138extern Cursor wCursor[WCUR_LAST];
139
c7868fa4
TT
Tamas TEVESZ2010-03-18 19:18:18 +0100140#ifndef HAVE_INOTIFY
141/* special flags */
142extern char WDelayedActionSet;
143#endif
144
0350b844 Carlos R. Mafra2010-04-14 11:01:14 +0200145extern void NotifyDeadProcess(pid_t pid, unsigned char status);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000146
0350b844 Carlos R. Mafra2010-04-14 11:01:14 +0200147/***** Local *****/
9d2e6ef9 scottc1998-09-29 22:36:29 +0000148static WScreen **wScreen = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000149static unsigned int _NumLockMask = 0;
150static unsigned int _ScrollLockMask = 0;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200151static void manageAllWindows(WScreen * scr, int crashed);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000152
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200153static int catchXError(Display * dpy, XErrorEvent * error)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000154{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200155 char buffer[MAXLINE];
156
157 /* ignore some errors */
158 if (error->resourceid != None
159 && ((error->error_code == BadDrawable && error->request_code == X_GetGeometry)
160 || (error->error_code == BadMatch && (error->request_code == X_SetInputFocus))
161 || (error->error_code == BadWindow)
162 /*
163 && (error->request_code == X_GetWindowAttributes
164 || error->request_code == X_SetInputFocus
165 || error->request_code == X_ChangeWindowAttributes
166 || error->request_code == X_GetProperty
167 || error->request_code == X_ChangeProperty
168 || error->request_code == X_QueryTree
169 || error->request_code == X_GrabButton
170 || error->request_code == X_UngrabButton
171 || error->request_code == X_SendEvent
172 || error->request_code == X_ConfigureWindow))
173 */
174 || (error->request_code == X_InstallColormap))) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200175 return 0;
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200176 }
177 FormatXError(dpy, error, buffer, MAXLINE);
178 wwarning(_("internal X error: %s\n"), buffer);
179 return -1;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000180}
181
9d2e6ef9 scottc1998-09-29 22:36:29 +0000182/*
6830b057 dan2004-10-12 21:28:27 +0000183 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000184 * handleXIO-
6830b057 dan2004-10-12 21:28:27 +0000185 * Handle X shutdowns and other stuff.
186 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000187 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200188static int handleXIO(Display * xio_dpy)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000189{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200190 dpy = NULL;
191 Exit(0);
192 return 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000193}
194
c7868fa4
TT
Tamas TEVESZ2010-03-18 19:18:18 +0100195#ifndef HAVE_INOTIFY
196/*
197 *----------------------------------------------------------------------
198 * delayedAction-
199 * Action to be executed after the signal() handler is exited.
200 *----------------------------------------------------------------------
201 */
202static void delayedAction(void *cdata)
203{
204 if (WDelayedActionSet == 0)
205 return;
206
207 WDelayedActionSet--;
208 /*
209 * Make the event dispatcher do whatever it needs to do,
210 * including handling zombie processes, restart and exit
211 * signals.
212 */
213 DispatchEvent(NULL);
214}
215#endif
216
9d2e6ef9 scottc1998-09-29 22:36:29 +0000217/*
218 *----------------------------------------------------------------------
51b1bf34 kojima2001-03-14 02:54:54 +0000219 * handleExitSig--
220 * User generated exit signal handler.
6830b057 dan2004-10-12 21:28:27 +0000221 *----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000222 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200223static RETSIGTYPE handleExitSig(int sig)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000224{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200225 sigset_t sigs;
51b1bf34 kojima2001-03-14 02:54:54 +0000226
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200227 sigfillset(&sigs);
228 sigprocmask(SIG_BLOCK, &sigs, NULL);
6830b057 dan2004-10-12 21:28:27 +0000229
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200230 if (sig == SIGUSR1) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200231 wwarning("got signal %i - restarting\n", sig);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200232 SIG_WCHANGE_STATE(WSTATE_NEED_RESTART);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200233 } else if (sig == SIGUSR2) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200234 wwarning("got signal %i - rereading defaults\n", sig);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200235 SIG_WCHANGE_STATE(WSTATE_NEED_REREAD);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200236 } else if (sig == SIGTERM || sig == SIGINT || sig == SIGHUP) {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200237 wwarning("got signal %i - exiting...\n", sig);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200238 SIG_WCHANGE_STATE(WSTATE_NEED_EXIT);
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200239 }
6830b057 dan2004-10-12 21:28:27 +0000240
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200241 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
242 DispatchEvent(NULL); /* Dispatch events imediately. */
51b1bf34 kojima2001-03-14 02:54:54 +0000243}
244
71739224 dan2001-09-01 13:30:55 +0000245/* Dummy signal handler */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200246static void dummyHandler(int sig)
71739224 dan2001-09-01 13:30:55 +0000247{
248}
249
51b1bf34 kojima2001-03-14 02:54:54 +0000250/*
251 *----------------------------------------------------------------------
252 * handleSig--
253 * general signal handler. Exits the program gently.
6830b057 dan2004-10-12 21:28:27 +0000254 *----------------------------------------------------------------------
51b1bf34 kojima2001-03-14 02:54:54 +0000255 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200256static RETSIGTYPE handleSig(int sig)
51b1bf34 kojima2001-03-14 02:54:54 +0000257{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200258 wfatal("got signal %i\n", sig);
9af1c6c4 dan1998-10-21 14:43:47 +0000259
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200260 /* Setting the signal behaviour back to default and then reraising the
261 * signal is a cleaner way to make program exit and core dump than calling
262 * abort(), since it correctly returns from the signal handler and sets
263 * the flags accordingly. -Dan
264 */
265 if (sig == SIGSEGV || sig == SIGFPE || sig == SIGBUS || sig == SIGILL || sig == SIGABRT) {
266 signal(sig, SIG_DFL);
267 kill(getpid(), sig);
268 return;
269 }
270
271 wAbort(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000272}
273
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200274static RETSIGTYPE buryChild(int foo)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000275{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200276 pid_t pid;
277 int status;
278 int save_errno = errno;
279 sigset_t sigs;
280
281 sigfillset(&sigs);
282 /* Block signals so that NotifyDeadProcess() doesn't get fux0red */
283 sigprocmask(SIG_BLOCK, &sigs, NULL);
284
285 /* R.I.P. */
286 /* If 2 or more kids exit in a small time window, before this handler gets
287 * the chance to get invoked, the SIGCHLD signals will be merged and only
288 * one SIGCHLD signal will be sent to us. We use a while loop to get all
289 * exited child status because we can't count on the number of SIGCHLD
290 * signals to know exactly how many kids have exited. -Dan
291 */
292 while ((pid = waitpid(-1, &status, WNOHANG)) > 0 || (pid < 0 && errno == EINTR)) {
293 NotifyDeadProcess(pid, WEXITSTATUS(status));
294 }
295
296 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
297
298 errno = save_errno;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000299}
300
4041278f Carlos R. Mafra2010-04-12 23:31:59 +0200301static void getOffendingModifiers(void)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000302{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200303 int i;
304 XModifierKeymap *modmap;
305 KeyCode nlock, slock;
306 static int mask_table[8] = {
307 ShiftMask, LockMask, ControlMask, Mod1Mask,
308 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
309 };
310
311 nlock = XKeysymToKeycode(dpy, XK_Num_Lock);
312 slock = XKeysymToKeycode(dpy, XK_Scroll_Lock);
313
314 /*
315 * Find out the masks for the NumLock and ScrollLock modifiers,
316 * so that we can bind the grabs for when they are enabled too.
317 */
318 modmap = XGetModifierMapping(dpy);
319
320 if (modmap != NULL && modmap->max_keypermod > 0) {
321 for (i = 0; i < 8 * modmap->max_keypermod; i++) {
322 if (modmap->modifiermap[i] == nlock && nlock != 0)
323 _NumLockMask = mask_table[i / modmap->max_keypermod];
324 else if (modmap->modifiermap[i] == slock && slock != 0)
325 _ScrollLockMask = mask_table[i / modmap->max_keypermod];
326 }
327 }
328
329 if (modmap)
330 XFreeModifiermap(modmap);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000331}
332
9d2e6ef9 scottc1998-09-29 22:36:29 +0000333#ifdef NUMLOCK_HACK
6830b057 dan2004-10-12 21:28:27 +0000334void
9d2e6ef9 scottc1998-09-29 22:36:29 +0000335wHackedGrabKey(int keycode, unsigned int modifiers,
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200336 Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000337{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200338 if (modifiers == AnyModifier)
339 return;
340
341 /* grab all combinations of the modifier with CapsLock, NumLock and
342 * ScrollLock. How much memory/CPU does such a monstrosity consume
343 * in the server?
344 */
345 if (_NumLockMask)
346 XGrabKey(dpy, keycode, modifiers | _NumLockMask,
347 grab_window, owner_events, pointer_mode, keyboard_mode);
348 if (_ScrollLockMask)
349 XGrabKey(dpy, keycode, modifiers | _ScrollLockMask,
350 grab_window, owner_events, pointer_mode, keyboard_mode);
351 if (_NumLockMask && _ScrollLockMask)
352 XGrabKey(dpy, keycode, modifiers | _NumLockMask | _ScrollLockMask,
353 grab_window, owner_events, pointer_mode, keyboard_mode);
354 if (_NumLockMask)
355 XGrabKey(dpy, keycode, modifiers | _NumLockMask | LockMask,
356 grab_window, owner_events, pointer_mode, keyboard_mode);
357 if (_ScrollLockMask)
358 XGrabKey(dpy, keycode, modifiers | _ScrollLockMask | LockMask,
359 grab_window, owner_events, pointer_mode, keyboard_mode);
360 if (_NumLockMask && _ScrollLockMask)
361 XGrabKey(dpy, keycode, modifiers | _NumLockMask | _ScrollLockMask | LockMask,
362 grab_window, owner_events, pointer_mode, keyboard_mode);
363 /* phew, I guess that's all, right? */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000364}
9af1c6c4 dan1998-10-21 14:43:47 +0000365#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000366
6830b057 dan2004-10-12 21:28:27 +0000367void
368wHackedGrabButton(unsigned int button, unsigned int modifiers,
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200369 Window grab_window, Bool owner_events,
370 unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000371{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200372 XGrabButton(dpy, button, modifiers, grab_window, owner_events,
373 event_mask, pointer_mode, keyboard_mode, confine_to, cursor);
9af1c6c4 dan1998-10-21 14:43:47 +0000374
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200375 if (modifiers == AnyModifier)
376 return;
9af1c6c4 dan1998-10-21 14:43:47 +0000377
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200378 XGrabButton(dpy, button, modifiers | LockMask, grab_window, owner_events,
379 event_mask, pointer_mode, keyboard_mode, confine_to, cursor);
6830b057 dan2004-10-12 21:28:27 +0000380
381#ifdef NUMLOCK_HACK
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200382 /* same as above, but for mouse buttons */
383 if (_NumLockMask)
384 XGrabButton(dpy, button, modifiers | _NumLockMask,
385 grab_window, owner_events, event_mask, pointer_mode,
386 keyboard_mode, confine_to, cursor);
387 if (_ScrollLockMask)
388 XGrabButton(dpy, button, modifiers | _ScrollLockMask,
389 grab_window, owner_events, event_mask, pointer_mode,
390 keyboard_mode, confine_to, cursor);
391 if (_NumLockMask && _ScrollLockMask)
392 XGrabButton(dpy, button, modifiers | _ScrollLockMask | _NumLockMask,
393 grab_window, owner_events, event_mask, pointer_mode,
394 keyboard_mode, confine_to, cursor);
395 if (_NumLockMask)
396 XGrabButton(dpy, button, modifiers | _NumLockMask | LockMask,
397 grab_window, owner_events, event_mask, pointer_mode,
398 keyboard_mode, confine_to, cursor);
399 if (_ScrollLockMask)
400 XGrabButton(dpy, button, modifiers | _ScrollLockMask | LockMask,
401 grab_window, owner_events, event_mask, pointer_mode,
402 keyboard_mode, confine_to, cursor);
403 if (_NumLockMask && _ScrollLockMask)
404 XGrabButton(dpy, button, modifiers | _ScrollLockMask | _NumLockMask | LockMask,
405 grab_window, owner_events, event_mask, pointer_mode,
406 keyboard_mode, confine_to, cursor);
407#endif /* NUMLOCK_HACK */
9d2e6ef9 scottc1998-09-29 22:36:29 +0000408}
409
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200410WScreen *wScreenWithNumber(int i)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000411{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200412 assert(i < wScreenCount);
e7495baf dan1999-02-17 11:06:40 +0000413
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200414 return wScreen[i];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000415}
416
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200417WScreen *wScreenForRootWindow(Window window)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000418{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200419 int i;
420
421 if (wScreenCount == 1)
422 return wScreen[0];
423
424 /*
425 * Since the number of heads will probably be small (normally 2),
426 * it should be faster to use this than a hash table, because
427 * of the overhead.
428 */
429 for (i = 0; i < wScreenCount; i++) {
430 if (wScreen[i]->root_win == window) {
431 return wScreen[i];
432 }
433 }
434
435 return wScreenForWindow(window);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000436}
437
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200438WScreen *wScreenSearchForRootWindow(Window window)
e7495baf dan1999-02-17 11:06:40 +0000439{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200440 int i;
441
442 if (wScreenCount == 1)
443 return wScreen[0];
444
445 /*
446 * Since the number of heads will probably be small (normally 2),
447 * it should be faster to use this than a hash table, because
448 * of the overhead.
449 */
450 for (i = 0; i < wScreenCount; i++) {
451 if (wScreen[i]->root_win == window) {
452 return wScreen[i];
453 }
454 }
455
456 return wScreenForWindow(window);
e7495baf dan1999-02-17 11:06:40 +0000457}
458
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200459WScreen *wScreenForWindow(Window window)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000460{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200461 XWindowAttributes attr;
9af1c6c4 dan1998-10-21 14:43:47 +0000462
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200463 if (wScreenCount == 1)
464 return wScreen[0];
9af1c6c4 dan1998-10-21 14:43:47 +0000465
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200466 if (XGetWindowAttributes(dpy, window, &attr)) {
467 return wScreenForRootWindow(attr.root);
468 }
469 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000470}
471
34cd5125 kojima2000-01-20 11:51:42 +0000472static char *atomNames[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200473 "WM_STATE",
474 "WM_CHANGE_STATE",
475 "WM_PROTOCOLS",
476 "WM_TAKE_FOCUS",
477 "WM_DELETE_WINDOW",
478 "WM_SAVE_YOURSELF",
479 "WM_CLIENT_LEADER",
480 "WM_COLORMAP_WINDOWS",
481 "WM_COLORMAP_NOTIFY",
482
483 "_WINDOWMAKER_MENU",
484 "_WINDOWMAKER_STATE",
485 "_WINDOWMAKER_WM_PROTOCOLS",
486 "_WINDOWMAKER_WM_FUNCTION",
487 "_WINDOWMAKER_NOTICEBOARD",
488 "_WINDOWMAKER_COMMAND",
489 "_WINDOWMAKER_ICON_SIZE",
490 "_WINDOWMAKER_ICON_TILE",
491
492 GNUSTEP_WM_ATTR_NAME,
493 GNUSTEP_WM_MINIATURIZE_WINDOW,
3f7110b1
DD
Daniel Déchelotte2009-08-19 00:50:49 +0200494 GNUSTEP_TITLEBAR_STATE,
495
496 "WM_IGNORE_FOCUS_EVENTS"
34cd5125 kojima2000-01-20 11:51:42 +0000497};
498
9d2e6ef9 scottc1998-09-29 22:36:29 +0000499/*
500 *----------------------------------------------------------
501 * StartUp--
502 * starts the window manager and setup global data.
503 * Called from main() at startup.
6830b057 dan2004-10-12 21:28:27 +0000504 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000505 * Side effects:
506 * global data declared in main.c is initialized
507 *----------------------------------------------------------
508 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200509void StartUp(Bool defaultScreenOnly)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000510{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200511 struct sigaction sig_action;
c201e161 Carlos R. Mafra2010-08-22 19:05:07 +0200512 int j, max, dummy;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200513 Atom atom[sizeof(atomNames) / sizeof(char *)];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000514
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200515 /*
516 * Ignore CapsLock in modifiers
517 */
518 ValidModMask = 0xff & ~LockMask;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000519
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200520 getOffendingModifiers();
521 /*
522 * Ignore NumLock and ScrollLock too
523 */
524 ValidModMask &= ~(_NumLockMask | _ScrollLockMask);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000525
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200526 memset(&wKeyBindings, 0, sizeof(wKeyBindings));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000527
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200528 wWinContext = XUniqueContext();
529 wAppWinContext = XUniqueContext();
530 wStackContext = XUniqueContext();
531 wVEdgeContext = XUniqueContext();
9d2e6ef9 scottc1998-09-29 22:36:29 +0000532
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200533 /* _XA_VERSION = XInternAtom(dpy, "VERSION", False); */
59eb9475 dan1998-11-03 12:53:26 +0000534
32160ff6 kojima2000-04-01 02:16:14 +0000535#ifdef HAVE_XINTERNATOMS
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200536 XInternAtoms(dpy, atomNames, sizeof(atomNames) / sizeof(char *), False, atom);
32160ff6 kojima2000-04-01 02:16:14 +0000537#else
538
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200539 {
540 int i;
541 for (i = 0; i < sizeof(atomNames) / sizeof(char *); i++) {
542 atom[i] = XInternAtom(dpy, atomNames[i], False);
543 }
544 }
32160ff6 kojima2000-04-01 02:16:14 +0000545#endif
6830b057 dan2004-10-12 21:28:27 +0000546
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200547 _XA_WM_STATE = atom[0];
548 _XA_WM_CHANGE_STATE = atom[1];
549 _XA_WM_PROTOCOLS = atom[2];
550 _XA_WM_TAKE_FOCUS = atom[3];
551 _XA_WM_DELETE_WINDOW = atom[4];
552 _XA_WM_SAVE_YOURSELF = atom[5];
553 _XA_WM_CLIENT_LEADER = atom[6];
554 _XA_WM_COLORMAP_WINDOWS = atom[7];
555 _XA_WM_COLORMAP_NOTIFY = atom[8];
556
557 _XA_WINDOWMAKER_MENU = atom[9];
558 _XA_WINDOWMAKER_STATE = atom[10];
559 _XA_WINDOWMAKER_WM_PROTOCOLS = atom[11];
560 _XA_WINDOWMAKER_WM_FUNCTION = atom[12];
561 _XA_WINDOWMAKER_NOTICEBOARD = atom[13];
562 _XA_WINDOWMAKER_COMMAND = atom[14];
563 _XA_WINDOWMAKER_ICON_SIZE = atom[15];
564 _XA_WINDOWMAKER_ICON_TILE = atom[16];
565
566 _XA_GNUSTEP_WM_ATTR = atom[17];
567 _XA_GNUSTEP_WM_MINIATURIZE_WINDOW = atom[18];
568 _XA_GNUSTEP_TITLEBAR_STATE = atom[19];
0af24483 richard2000-03-02 07:36:02 +0000569
3f7110b1
DD
Daniel Déchelotte2009-08-19 00:50:49 +0200570 _XA_WM_IGNORE_FOCUS_EVENTS = atom[20];
571
d4025072 id1999-05-17 20:21:43 +0000572#ifdef XDND
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200573 wXDNDInitializeAtoms();
9af1c6c4 dan1998-10-21 14:43:47 +0000574#endif
575
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200576 /* cursors */
577 wCursor[WCUR_NORMAL] = None; /* inherit from root */
578 wCursor[WCUR_ROOT] = XCreateFontCursor(dpy, XC_left_ptr);
579 wCursor[WCUR_ARROW] = XCreateFontCursor(dpy, XC_top_left_arrow);
580 wCursor[WCUR_MOVE] = XCreateFontCursor(dpy, XC_fleur);
581 wCursor[WCUR_RESIZE] = XCreateFontCursor(dpy, XC_sizing);
582 wCursor[WCUR_TOPLEFTRESIZE] = XCreateFontCursor(dpy, XC_top_left_corner);
583 wCursor[WCUR_TOPRIGHTRESIZE] = XCreateFontCursor(dpy, XC_top_right_corner);
584 wCursor[WCUR_BOTTOMLEFTRESIZE] = XCreateFontCursor(dpy, XC_bottom_left_corner);
585 wCursor[WCUR_BOTTOMRIGHTRESIZE] = XCreateFontCursor(dpy, XC_bottom_right_corner);
586 wCursor[WCUR_VERTICALRESIZE] = XCreateFontCursor(dpy, XC_sb_v_double_arrow);
587 wCursor[WCUR_HORIZONRESIZE] = XCreateFontCursor(dpy, XC_sb_h_double_arrow);
588 wCursor[WCUR_WAIT] = XCreateFontCursor(dpy, XC_watch);
589 wCursor[WCUR_QUESTION] = XCreateFontCursor(dpy, XC_question_arrow);
590 wCursor[WCUR_TEXT] = XCreateFontCursor(dpy, XC_xterm); /* odd name??? */
591 wCursor[WCUR_SELECT] = XCreateFontCursor(dpy, XC_cross);
592 {
593 Pixmap cur = XCreatePixmap(dpy, DefaultRootWindow(dpy), 16, 16, 1);
594 GC gc = XCreateGC(dpy, cur, 0, NULL);
595 XColor black;
596 memset(&black, 0, sizeof(XColor));
597 XSetForeground(dpy, gc, 0);
598 XFillRectangle(dpy, cur, gc, 0, 0, 16, 16);
599 XFreeGC(dpy, gc);
600 wCursor[WCUR_EMPTY] = XCreatePixmapCursor(dpy, cur, cur, &black, &black, 0, 0);
601 XFreePixmap(dpy, cur);
602 }
603
c7868fa4
TT
Tamas TEVESZ2010-03-18 19:18:18 +0100604#ifndef HAVE_INOTIFY
605 /* signal handler stuff that gets called when a signal is caught */
606 WMAddPersistentTimerHandler(500, delayedAction, NULL);
607#endif
608
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200609 /* emergency exit... */
610 sig_action.sa_handler = handleSig;
611 sigemptyset(&sig_action.sa_mask);
612
613 sig_action.sa_flags = SA_RESTART;
614 sigaction(SIGQUIT, &sig_action, NULL);
615 /* instead of catching these, we let the default handler abort the
616 * program. The new monitor process will take appropriate action
617 * when it detects the crash.
618 sigaction(SIGSEGV, &sig_action, NULL);
619 sigaction(SIGBUS, &sig_action, NULL);
620 sigaction(SIGFPE, &sig_action, NULL);
621 sigaction(SIGABRT, &sig_action, NULL);
622 */
623
624 sig_action.sa_handler = handleExitSig;
625
626 /* Here we set SA_RESTART for safety, because SIGUSR1 may not be handled
627 * immediately. -Dan */
628 sig_action.sa_flags = SA_RESTART;
629 sigaction(SIGTERM, &sig_action, NULL);
630 sigaction(SIGINT, &sig_action, NULL);
631 sigaction(SIGHUP, &sig_action, NULL);
632 sigaction(SIGUSR1, &sig_action, NULL);
633 sigaction(SIGUSR2, &sig_action, NULL);
634
635 /* ignore dead pipe */
636 /* Because POSIX mandates that only signal with handlers are reset
637 * accross an exec*(), we do not want to propagate ignoring SIGPIPEs
638 * to children. Hence the dummy handler.
639 * Philippe Troin <phil@fifi.org>
640 */
641 sig_action.sa_handler = &dummyHandler;
642 sig_action.sa_flags = SA_RESTART;
643 sigaction(SIGPIPE, &sig_action, NULL);
644
645 /* handle dead children */
646 sig_action.sa_handler = buryChild;
647 sig_action.sa_flags = SA_NOCLDSTOP | SA_RESTART;
648 sigaction(SIGCHLD, &sig_action, NULL);
649
650 /* Now we unblock all signals, that may have been blocked by the parent
651 * who exec()-ed us. This can happen for example if Window Maker crashes
652 * and restarts itself or another window manager from the signal handler.
653 * In this case, the new proccess inherits the blocked signal mask and
654 * will no longer react to that signal, until unblocked.
655 * This is because the signal handler of the proccess who crashed (parent)
656 * didn't return, and the signal remained blocked. -Dan
657 */
658 sigfillset(&sig_action.sa_mask);
659 sigprocmask(SIG_UNBLOCK, &sig_action.sa_mask, NULL);
660
661 /* handle X shutdowns a such */
662 XSetIOErrorHandler(handleXIO);
663
664 /* set hook for out event dispatcher in WINGs event dispatcher */
665 WMHookEventHandler(DispatchEvent);
666
667 /* initialize defaults stuff */
668 WDWindowMaker = wDefaultsInitDomain("WindowMaker", True);
669 if (!WDWindowMaker->dictionary) {
670 wwarning(_("could not read domain \"%s\" from defaults database"), "WindowMaker");
671 }
672
673 /* read defaults that don't change until a restart and are
674 * screen independent */
675 wReadStaticDefaults(WDWindowMaker ? WDWindowMaker->dictionary : NULL);
676
677 /* check sanity of some values */
678 if (wPreferences.icon_size < 16) {
679 wwarning(_("icon size is configured to %i, but it's too small. Using 16, instead\n"),
680 wPreferences.icon_size);
681 wPreferences.icon_size = 16;
682 }
683
684 /* init other domains */
685 WDRootMenu = wDefaultsInitDomain("WMRootMenu", False);
686 if (!WDRootMenu->dictionary) {
687 wwarning(_("could not read domain \"%s\" from defaults database"), "WMRootMenu");
688 }
689 wDefaultsMergeGlobalMenus(WDRootMenu);
690
691 WDWindowAttributes = wDefaultsInitDomain("WMWindowAttributes", True);
692 if (!WDWindowAttributes->dictionary) {
693 wwarning(_("could not read domain \"%s\" from defaults database"), "WMWindowAttributes");
694 }
695
696 XSetErrorHandler((XErrorHandler) catchXError);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000697
9af1c6c4 dan1998-10-21 14:43:47 +0000698#ifdef SHAPE
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200699 /* ignore j */
700 wShapeSupported = XShapeQueryExtension(dpy, &wShapeEventBase, &j);
9af1c6c4 dan1998-10-21 14:43:47 +0000701#endif
6830b057 dan2004-10-12 21:28:27 +0000702
c201e161
CM
Carlos R. Mafra2010-08-22 19:05:07 +0200703#ifdef HAVE_XRANDR
704 has_randr = XRRQueryExtension(dpy, &randr_event_base, &dummy);
705#else
706 has_randr = false;
707#endif
708
daaccf6f id1999-05-23 23:48:08 +0000709#ifdef KEEP_XKB_LOCK_STATUS
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200710 wXkbSupported = XkbQueryExtension(dpy, NULL, &wXkbEventBase, NULL, NULL, NULL);
711 if (wPreferences.modelock && !wXkbSupported) {
712 wwarning(_("XKB is not supported. KbdModeLock is automatically disabled."));
713 wPreferences.modelock = 0;
714 }
daaccf6f id1999-05-23 23:48:08 +0000715#endif
9d2e6ef9 scottc1998-09-29 22:36:29 +0000716
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200717 if (defaultScreenOnly) {
718 max = 1;
719 } else {
720 max = ScreenCount(dpy);
721 }
722 wScreen = wmalloc(sizeof(WScreen *) * max);
723
724 wScreenCount = 0;
725
726 /* manage the screens */
727 for (j = 0; j < max; j++) {
728 if (defaultScreenOnly || max == 1) {
729 wScreen[wScreenCount] = wScreenInit(DefaultScreen(dpy));
730 if (!wScreen[wScreenCount]) {
731 wfatal(_("it seems that there is already a window manager running"));
732 Exit(1);
733 }
734 } else {
735 wScreen[wScreenCount] = wScreenInit(j);
736 if (!wScreen[wScreenCount]) {
737 wwarning(_("could not manage screen %i"), j);
738 continue;
739 }
740 }
741 wScreenCount++;
742 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000743
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200744 InitializeSwitchMenu();
851835c7 dan2002-09-11 15:02:43 +0000745
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200746 /* initialize/restore state for the screens */
747 for (j = 0; j < wScreenCount; j++) {
748 int lastDesktop;
749
750 lastDesktop = wNETWMGetCurrentDesktopFromHint(wScreen[j]);
751
752 wScreenRestoreState(wScreen[j]);
753
754 /* manage all windows that were already here before us */
755 if (!wPreferences.flags.nodock && wScreen[j]->dock)
756 wScreen[j]->last_dock = wScreen[j]->dock;
757
758 manageAllWindows(wScreen[j], wPreferences.flags.restarting == 2);
759
760 /* restore saved menus */
761 wMenuRestoreState(wScreen[j]);
762
763 /* If we're not restarting, restore session */
764 if (wPreferences.flags.restarting == 0 && !wPreferences.flags.norestore)
765 wSessionRestoreState(wScreen[j]);
766
767 if (!wPreferences.flags.noautolaunch) {
768 /* auto-launch apps */
769 if (!wPreferences.flags.nodock && wScreen[j]->dock) {
770 wScreen[j]->last_dock = wScreen[j]->dock;
771 wDockDoAutoLaunch(wScreen[j]->dock, 0);
772 }
773 /* auto-launch apps in clip */
774 if (!wPreferences.flags.noclip) {
775 int i;
776 for (i = 0; i < wScreen[j]->workspace_count; i++) {
777 if (wScreen[j]->workspaces[i]->clip) {
778 wScreen[j]->last_dock = wScreen[j]->workspaces[i]->clip;
779 wDockDoAutoLaunch(wScreen[j]->workspaces[i]->clip, i);
780 }
781 }
782 }
783 }
784
785 /* go to workspace where we were before restart */
786 if (lastDesktop >= 0) {
787 wWorkspaceForceChange(wScreen[j], lastDesktop);
788 } else {
789 wSessionRestoreLastWorkspace(wScreen[j]);
790 }
791 }
792
793 if (wScreenCount == 0) {
794 wfatal(_("could not manage any screen"));
795 Exit(1);
796 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000797
c7868fa4
TT
Tamas TEVESZ2010-03-18 19:18:18 +0100798#ifndef HAVE_INOTIFY
799 if (!wPreferences.flags.nopolling && !wPreferences.flags.noupdates) {
800 /* setup defaults file polling */
801 WMAddTimerHandler(3000, wDefaultsCheckDomains, NULL);
802 }
803#endif
804
9d2e6ef9 scottc1998-09-29 22:36:29 +0000805}
806
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200807static Bool windowInList(Window window, Window * list, int count)
9af1c6c4 dan1998-10-21 14:43:47 +0000808{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200809 for (; count >= 0; count--) {
810 if (window == list[count])
811 return True;
812 }
813 return False;
9af1c6c4 dan1998-10-21 14:43:47 +0000814}
815
9d2e6ef9 scottc1998-09-29 22:36:29 +0000816/*
817 *-----------------------------------------------------------------------
818 * manageAllWindows--
819 * Manages all windows in the screen.
6830b057 dan2004-10-12 21:28:27 +0000820 *
9d2e6ef9 scottc1998-09-29 22:36:29 +0000821 * Notes:
822 * Called when the wm is being started.
823 * No events can be processed while the windows are being
6830b057 dan2004-10-12 21:28:27 +0000824 * reparented/managed.
825 *-----------------------------------------------------------------------
9d2e6ef9 scottc1998-09-29 22:36:29 +0000826 */
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200827static void manageAllWindows(WScreen * scr, int crashRecovery)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000828{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200829 Window root, parent;
830 Window *children;
831 unsigned int nchildren;
832 unsigned int i, j;
833 WWindow *wwin;
834
835 XGrabServer(dpy);
836 XQueryTree(dpy, scr->root_win, &root, &parent, &children, &nchildren);
837
838 scr->flags.startup = 1;
839
840 /* first remove all icon windows */
841 for (i = 0; i < nchildren; i++) {
842 XWMHints *wmhints;
843
844 if (children[i] == None)
845 continue;
846
847 wmhints = XGetWMHints(dpy, children[i]);
848 if (wmhints && (wmhints->flags & IconWindowHint)) {
849 for (j = 0; j < nchildren; j++) {
850 if (children[j] == wmhints->icon_window) {
851 XFree(wmhints);
852 wmhints = NULL;
853 children[j] = None;
854 break;
855 }
856 }
857 }
858 if (wmhints) {
859 XFree(wmhints);
860 }
861 }
862
863 for (i = 0; i < nchildren; i++) {
864 if (children[i] == None)
865 continue;
866
867 wwin = wManageWindow(scr, children[i]);
868 if (wwin) {
869 /* apply states got from WSavedState */
870 /* shaded + minimized is not restored correctly */
871 if (wwin->flags.shaded) {
872 wwin->flags.shaded = 0;
873 wShadeWindow(wwin);
874 }
875 if (wwin->flags.miniaturized
876 && (wwin->transient_for == None
877 || wwin->transient_for == scr->root_win
878 || !windowInList(wwin->transient_for, children, nchildren))) {
879
880 wwin->flags.skip_next_animation = 1;
881 wwin->flags.miniaturized = 0;
882 wIconifyWindow(wwin);
883 } else {
884 wClientSetState(wwin, NormalState, None);
885 }
886 if (crashRecovery) {
887 int border;
888
889 border = (!HAS_BORDER(wwin) ? 0 : FRAME_BORDER_WIDTH);
890
891 wWindowMove(wwin, wwin->frame_x - border,
892 wwin->frame_y - border -
893 (wwin->frame->titlebar ? wwin->frame->titlebar->height : 0));
894 }
895 }
896 }
897 XUngrabServer(dpy);
898
899 /* hide apps */
900 wwin = scr->focused_window;
901 while (wwin) {
902 if (wwin->flags.hidden) {
903 WApplication *wapp = wApplicationOf(wwin->main_window);
904
905 if (wapp) {
906 wwin->flags.hidden = 0;
907 wHideApplication(wapp);
908 } else {
909 wwin->flags.hidden = 0;
910 }
911 }
912 wwin = wwin->prev;
913 }
914
915 XFree(children);
916 scr->flags.startup = 0;
917 scr->flags.startup2 = 1;
918
919 while (XPending(dpy)) {
920 XEvent ev;
921 WMNextEvent(dpy, &ev);
922 WMHandleEvent(&ev);
923 }
924 wWorkspaceForceChange(scr, 0);
925 if (!wPreferences.flags.noclip)
926 wDockShowIcons(scr->workspaces[scr->current_workspace]->clip);
927 scr->flags.startup2 = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000928}