wmaker: Reduce wakeups to zero
[wmaker-crm.git] / src / main.c
blobd54a631502cb2e509f253e82316f84805c91091d
1 /*
2 * Window Maker window manager
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 * USA.
22 #define _GNU_SOURCE /* needed to get the defines in glibc 2.2 */
23 #include <fcntl.h> /* this has the needed values defined */
24 #include <signal.h>
26 #include "wconfig.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <fcntl.h>
36 #include <X11/Xlib.h>
37 #include <X11/Xutil.h>
40 /* Xlocale.h and locale.h are the same if X_LOCALE is undefind in wconfig.h,
41 * and if X_LOCALE is defined, X's locale emulating functions will be used.
42 * See Xlocale.h for more information.
44 #include <X11/Xlocale.h>
46 #define MAINFILE
48 #include "WindowMaker.h"
49 #include "window.h"
50 #include "funcs.h"
51 #include "menu.h"
52 #include "keybind.h"
53 #include "xmodifier.h"
54 #include "defaults.h"
55 #include "session.h"
56 #include "dialog.h"
58 #include <WINGs/WUtil.h>
60 /****** Global Variables ******/
62 /* general info */
64 Display *dpy;
66 char *ProgName;
68 unsigned int ValidModMask = 0xff;
69 volatile int filesChanged;
71 /* locale to use. NULL==POSIX or C */
72 char *Locale=NULL;
74 int wScreenCount=0;
76 WPreferences wPreferences;
79 WMPropList *wDomainName;
80 WMPropList *wAttributeDomainName;
82 WShortKey wKeyBindings[WKBD_LAST];
84 /* defaults domains */
85 WDDomain *WDWindowMaker = NULL;
86 WDDomain *WDWindowAttributes = NULL;
87 WDDomain *WDRootMenu = NULL;
89 /* XContexts */
90 XContext wWinContext;
91 XContext wAppWinContext;
92 XContext wStackContext;
93 XContext wVEdgeContext;
95 /* Atoms */
96 Atom _XA_WM_STATE;
97 Atom _XA_WM_CHANGE_STATE;
98 Atom _XA_WM_PROTOCOLS;
99 Atom _XA_WM_TAKE_FOCUS;
100 Atom _XA_WM_DELETE_WINDOW;
101 Atom _XA_WM_SAVE_YOURSELF;
102 Atom _XA_WM_CLIENT_LEADER;
103 Atom _XA_WM_COLORMAP_WINDOWS;
104 Atom _XA_WM_COLORMAP_NOTIFY;
106 Atom _XA_GNUSTEP_WM_ATTR;
107 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
108 Atom _XA_GNUSTEP_WM_RESIZEBAR;
109 Atom _XA_GNUSTEP_TITLEBAR_STATE;
111 Atom _XA_WINDOWMAKER_MENU;
112 Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
113 Atom _XA_WINDOWMAKER_STATE;
115 Atom _XA_WINDOWMAKER_WM_FUNCTION;
116 Atom _XA_WINDOWMAKER_NOTICEBOARD;
117 Atom _XA_WINDOWMAKER_COMMAND;
119 Atom _XA_WINDOWMAKER_ICON_SIZE;
120 Atom _XA_WINDOWMAKER_ICON_TILE;
123 /* cursors */
124 Cursor wCursor[WCUR_LAST];
126 /* last event timestamp for XSetInputFocus */
127 Time LastTimestamp = CurrentTime;
128 /* timestamp on the last time we did XSetInputFocus() */
129 Time LastFocusChange = CurrentTime;
131 #ifdef SHAPE
132 Bool wShapeSupported;
133 int wShapeEventBase;
134 #endif
136 #ifdef KEEP_XKB_LOCK_STATUS
137 Bool wXkbSupported;
138 int wXkbEventBase;
139 #endif
141 /* special flags */
142 char WProgramSigState = 0;
143 char WProgramState = WSTATE_NORMAL;
144 char WDelayedActionSet = 0;
147 /* temporary stuff */
148 int wVisualID = -1;
151 /* notifications */
152 const char *WMNManaged = "WMNManaged";
153 const char *WMNUnmanaged = "WMNUnmanaged";
154 const char *WMNChangedWorkspace = "WMNChangedWorkspace";
155 const char *WMNChangedState = "WMNChangedState";
156 const char *WMNChangedFocus = "WMNChangedFocus";
157 const char *WMNChangedStacking = "WMNChangedStacking";
158 const char *WMNChangedName = "WMNChangedName";
160 const char *WMNWorkspaceCreated = "WMNWorkspaceCreated";
161 const char *WMNWorkspaceDestroyed = "WMNWorkspaceDestroyed";
162 const char *WMNWorkspaceChanged = "WMNWorkspaceChanged";
163 const char *WMNWorkspaceNameChanged = "WMNWorkspaceNameChanged";
165 const char *WMNResetStacking = "WMNResetStacking";
167 /******** End Global Variables *****/
169 static char *DisplayName = NULL;
171 static char **Arguments;
173 static int ArgCount;
175 extern void EventLoop();
176 extern void StartUp();
177 extern int MonitorLoop(int argc, char **argv);
179 static Bool multiHead = True;
181 /* stdi/o for log shell */
182 static int LogStdIn = -1, LogStdOut = -1, LogStdErr = -1;
185 static int real_main(int argc, char **argv);
187 void
188 Exit(int status)
190 #ifdef XSMP_ENABLED
191 wSessionDisconnectManager();
192 #endif
193 if (dpy)
194 XCloseDisplay(dpy);
196 exit(status);
200 void
201 Restart(char *manager, Bool abortOnFailure)
203 char *prog=NULL;
204 char *argv[MAX_RESTART_ARGS];
205 int i;
207 if (manager && manager[0]!=0) {
208 prog = argv[0] = strtok(manager, " ");
209 for (i=1; i<MAX_RESTART_ARGS; i++) {
210 argv[i]=strtok(NULL, " ");
211 if (argv[i]==NULL) {
212 break;
216 if (dpy) {
217 #ifdef XSMP_ENABLED
218 wSessionDisconnectManager();
219 #endif
220 XCloseDisplay(dpy);
221 dpy = NULL;
223 if (!prog) {
224 execvp(Arguments[0], Arguments);
225 wfatal(_("failed to restart Window Maker."));
226 } else {
227 execvp(prog, argv);
228 wsyserror(_("could not exec %s"), prog);
230 if (abortOnFailure)
231 exit(7);
236 void
237 SetupEnvironment(WScreen *scr)
239 char *tmp, *ptr;
240 char buf[16];
242 if (multiHead) {
243 int len = strlen(DisplayName)+64;
244 tmp = wmalloc(len);
245 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
246 ptr = strchr(strchr(tmp, ':'), '.');
247 if (ptr)
248 *ptr = 0;
249 snprintf(buf, sizeof(buf), ".%i", scr->screen);
250 strcat(tmp, buf);
251 putenv(tmp);
253 tmp = wmalloc(60);
254 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
255 scr->rcontext->attribs->colors_per_channel);
256 putenv(tmp);
262 typedef struct {
263 WScreen *scr;
264 char *command;
265 } _tuple;
268 static void
269 shellCommandHandler(pid_t pid, unsigned char status, _tuple *data)
271 if (status == 127) {
272 char *buffer;
274 buffer = wstrconcat(_("Could not execute command: "), data->command);
276 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
277 wfree(buffer);
278 } else if (status != 127) {
280 printf("%s: %i\n", data->command, status);
284 wfree(data->command);
285 wfree(data);
289 void
290 ExecuteShellCommand(WScreen *scr, char *command)
292 static char *shell = NULL;
293 pid_t pid;
296 * This have a problem: if the shell is tcsh (not sure about others)
297 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
298 * will block and the command will not be executed.
299 if (!shell) {
300 shell = getenv("SHELL");
301 if (!shell)
302 shell = "/bin/sh";
305 shell = "/bin/sh";
307 pid = fork();
309 if (pid==0) {
311 SetupEnvironment(scr);
313 #ifdef HAVE_SETSID
314 setsid();
315 #endif
316 execl(shell, shell, "-c", command, NULL);
317 wsyserror("could not execute %s -c %s", shell, command);
318 Exit(-1);
319 } else if (pid < 0) {
320 wsyserror("cannot fork a new process");
321 } else {
322 _tuple *data = wmalloc(sizeof(_tuple));
324 data->scr = scr;
325 data->command = wstrdup(command);
327 wAddDeathHandler(pid, (WDeathHandler*)shellCommandHandler, data);
333 *---------------------------------------------------------------------------
334 * StartLogShell
335 * Start a shell that will receive all stdin and stdout from processes
336 * forked by wmaker.
337 *---------------------------------------------------------------------------
339 void
340 StartLogShell(WScreen *scr)
342 int in_fd[2];
343 int out_fd[2];
344 int err_fd[2];
345 pid_t pid;
347 SetupEnvironment(scr);
349 if (pipe(in_fd) < 0) {
350 wsyserror("could not create pipe for log shell\n");
351 return;
353 if (pipe(out_fd) < 0) {
354 wsyserror("could not create pipe for log shell\n");
355 close(in_fd[0]);
356 close(in_fd[1]);
357 return;
359 if (pipe(err_fd) < 0) {
360 wsyserror("could not create pipe for log shell\n");
361 close(out_fd[0]);
362 close(out_fd[1]);
363 close(in_fd[0]);
364 close(in_fd[1]);
365 return;
368 pid = fork();
369 if (pid < 0) {
370 wsyserror("could not fork a new process for log shell\n");
371 return;
372 } else if (pid == 0) {
373 close(in_fd[0]);
374 close(out_fd[1]);
375 close(err_fd[1]);
377 close(0);
378 close(1);
379 close(2);
381 if (dup2(in_fd[1], 0) < 0) {
382 wsyserror("could not redirect stdin for log shell\n");
383 exit(1);
385 if (dup2(out_fd[1], 1) < 0) {
386 wsyserror("could not redirect stdout for log shell\n");
387 exit(1);
389 if (dup2(err_fd[1], 2) < 0) {
390 wsyserror("could not redirect stderr for log shell\n");
391 exit(1);
394 close(in_fd[1]);
395 close(out_fd[1]);
396 close(err_fd[1]);
398 execl("/bin/sh", "/bin/sh", "-c", wPreferences.logger_shell, NULL);
399 wsyserror("could not execute %s\n", wPreferences.logger_shell);
400 exit(1);
401 } else {
402 close(in_fd[1]);
403 close(out_fd[0]);
404 close(err_fd[0]);
406 LogStdIn = in_fd[1];
407 LogStdOut = out_fd[0];
408 LogStdErr = err_fd[0];
414 *---------------------------------------------------------------------
415 * wAbort--
416 * Do a major cleanup and exit the program
418 *----------------------------------------------------------------------
420 void
421 wAbort(Bool dumpCore)
423 int i;
424 WScreen *scr;
426 for (i=0; i<wScreenCount; i++) {
427 scr = wScreenWithNumber(i);
428 if (scr)
429 RestoreDesktop(scr);
431 printf(_("%s aborted.\n"), ProgName);
432 if (dumpCore)
433 abort();
434 else
435 exit(1);
439 void
440 print_help()
442 printf(_("Usage: %s [options]\n"), ProgName);
443 puts(_("The Window Maker window manager for the X window system"));
444 puts("");
445 puts(_(" -display host:dpy display to use"));
446 #ifdef USECPP
447 puts(_(" --no-cpp disable preprocessing of configuration files"));
448 #endif
449 puts(_(" --no-dock do not open the application Dock"));
450 puts(_(" --no-clip do not open the workspace Clip"));
451 puts(_(" --no-autolaunch do not autolaunch applications"));
452 puts(_(" --dont-restore do not restore saved session"));
454 puts(_(" --locale locale locale to use"));
456 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
457 puts(_(" --visual-id visualid visual id of visual to use"));
458 puts(_(" --static do not update or save configurations"));
459 #ifdef DEBUG
460 puts(_(" --synchronous turn on synchronous display mode"));
461 #endif
462 puts(_(" --version print version and exit"));
463 puts(_(" --help show this message"));
468 void
469 check_defaults()
471 char *path;
473 path = wdefaultspathfordomain("WindowMaker");
475 if (access(path, R_OK)!=0) {
476 #if 0
477 wfatal(_("could not find user GNUstep directory (%s).\n"
478 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
479 path);
480 exit(1);
481 #else
482 wwarning(_("could not find user GNUstep directory (%s)."), path);
484 if (system("wmaker.inst --batch") != 0) {
485 wwarning(_("There was an error while creating GNUstep directory, please "
486 "make sure you have installed Window Maker correctly and run wmaker.inst"));
487 } else {
488 wwarning(_("%s directory created with default configuration."), path);
490 #endif
493 wfree(path);
498 * This is the handler used to notify if configuration
499 * files have changed, using linux kernel'l dnotify
500 * mechanism (from Documentation/dnotify.txt)
502 void handler(int sig, siginfo_t *si, void *data)
504 filesChanged = si->si_fd;
507 static void
508 execInitScript()
510 char *file, *path, *paths;
511 struct sigaction act;
512 volatile int fd;
514 path = wstrconcat(wusergnusteppath(), "/Defaults");
516 act.sa_sigaction = handler;
517 sigemptyset(&act.sa_mask);
518 act.sa_flags = SA_SIGINFO;
519 sigaction(SIGRTMIN + 1, &act, NULL);
521 fd = open(path, O_RDONLY);
522 fcntl(fd, F_SETSIG, SIGRTMIN + 1);
523 fcntl(fd, F_NOTIFY, DN_MODIFY|DN_MULTISHOT);
524 wfree(path);
526 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
527 paths = wstrappend(paths, ":"DEF_CONFIG_PATHS);
529 file = wfindfile(paths, DEF_INIT_SCRIPT);
530 wfree(paths);
532 if (file) {
533 if (system(file) != 0) {
534 wsyserror(_("%s:could not execute initialization script"), file);
536 #if 0
537 if (fork()==0) {
538 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
539 wsyserror(_("%s:could not execute initialization script"), file);
540 exit(1);
542 #endif
543 wfree(file);
548 void
549 ExecExitScript()
551 char *file, *paths;
553 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
554 paths = wstrappend(paths, ":"DEF_CONFIG_PATHS);
556 file = wfindfile(paths, DEF_EXIT_SCRIPT);
557 wfree(paths);
559 if (file) {
560 if (system(file) != 0) {
561 wsyserror(_("%s:could not execute exit script"), file);
563 #if 0
564 if (fork()==0) {
565 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
566 wsyserror(_("%s:could not execute exit script"), file);
567 exit(1);
569 #endif
570 wfree(file);
574 #if 0
575 char*
576 getFullPath(char *path)
578 char buffer[1024];
579 char *tmp;
580 char *basep = (char*)buffer;
582 if (*path != '/' && getcwd(buffer, 1023)) {
584 for (;;) {
585 if (strncmp(path, "../", 3)==0) {
586 path += 3;
587 basep = strchr(basep, '/');
588 if (!basep || *path==0)
589 break;
592 if (*path == '/' || strncmp(path, "./",2)==0) {
593 tmp =
597 * path
598 * ./path
599 * ../path
600 * ../../path
604 } else {
605 return wstrconcat(path);
608 return tmp;
610 #endif
614 main(int argc, char **argv)
616 int i_am_the_monitor, i, len;
617 char *str, *alt;
619 /* setup common stuff for the monitor and wmaker itself */
620 WMInitializeApplication("WindowMaker", &argc, argv);
622 memset(&wPreferences, 0, sizeof(WPreferences));
624 wPreferences.fallbackWMs = WMCreateArray(8);
625 alt = getenv("WINDOWMAKER_ALT_WM");
626 if (alt != NULL)
627 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
629 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
630 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
631 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
632 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
633 WMAddToArray(wPreferences.fallbackWMs, NULL);
634 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
635 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
637 i_am_the_monitor= 1;
639 for (i= 1; i < argc; i++)
641 if (strncmp(argv[i], "--for-real", strlen("--for-real"))==0)
643 i_am_the_monitor= 0;
644 break;
646 else if (strcmp(argv[i], "-display")==0 || strcmp(argv[i], "--display")==0)
648 i++;
649 if (i>=argc) {
650 wwarning(_("too few arguments for %s"), argv[i-1]);
651 exit(0);
653 DisplayName = argv[i];
657 DisplayName = XDisplayName(DisplayName);
658 len = strlen(DisplayName)+64;
659 str = wmalloc(len);
660 snprintf(str, len, "DISPLAY=%s", DisplayName);
661 putenv(str);
663 if (i_am_the_monitor)
664 return MonitorLoop(argc, argv);
665 else
666 return real_main(argc, argv);
670 static int
671 real_main(int argc, char **argv)
673 int i, restart=0;
674 char *str;
675 int d, s;
676 int flag;
677 #ifdef DEBUG
678 Bool doSync = False;
679 #endif
680 setlocale(LC_ALL, "");
682 wsetabort(wAbort);
684 /* for telling WPrefs what's the name of the wmaker binary being ran */
686 str = wstrconcat("WMAKER_BIN_NAME=", argv[0]);
687 putenv(str);
689 flag= 0;
690 ArgCount = argc;
691 Arguments = wmalloc(sizeof(char*)*(ArgCount+1));
692 for (i= 0; i < argc; i++)
694 Arguments[i]= argv[i];
696 /* add the extra option to signal that we're just restarting wmaker */
697 Arguments[argc-1]= "--for-real=";
698 Arguments[argc]= NULL;
700 ProgName = strrchr(argv[0],'/');
701 if (!ProgName)
702 ProgName = argv[0];
703 else
704 ProgName++;
707 restart = 0;
709 if (argc>1) {
710 for (i=1; i<argc; i++) {
711 #ifdef USECPP
712 if (strcmp(argv[i], "-nocpp")==0
713 || strcmp(argv[i], "--no-cpp")==0) {
714 wPreferences.flags.nocpp=1;
715 } else
716 #endif
717 if (strcmp(argv[i], "--for-real")==0) {
718 wPreferences.flags.restarting = 0;
719 } else if (strcmp(argv[i], "--for-real=")==0) {
720 wPreferences.flags.restarting = 1;
721 } else if (strcmp(argv[i], "--for-real-")==0) {
722 wPreferences.flags.restarting = 2;
723 } else if (strcmp(argv[i], "-no-autolaunch")==0
724 || strcmp(argv[i], "--no-autolaunch")==0) {
725 wPreferences.flags.noautolaunch = 1;
726 } else if (strcmp(argv[i], "-dont-restore")==0
727 || strcmp(argv[i], "--dont-restore")==0) {
728 wPreferences.flags.norestore = 1;
729 } else if (strcmp(argv[i], "-nodock")==0
730 || strcmp(argv[i], "--no-dock")==0) {
731 wPreferences.flags.nodock=1;
732 } else if (strcmp(argv[i], "-noclip")==0
733 || strcmp(argv[i], "--no-clip")==0) {
734 wPreferences.flags.noclip=1;
735 } else if (strcmp(argv[i], "-version")==0
736 || strcmp(argv[i], "--version")==0) {
737 printf("Window Maker %s\n", VERSION);
738 exit(0);
739 } else if (strcmp(argv[i], "--global_defaults_path")==0) {
740 printf("%s/WindowMaker\n", SYSCONFDIR);
741 exit(0);
742 #ifdef DEBUG
743 } else if (strcmp(argv[i], "--synchronous")==0) {
744 doSync = 1;
745 #endif
746 } else if (strcmp(argv[i], "-locale")==0
747 || strcmp(argv[i], "--locale")==0) {
748 i++;
749 if (i>=argc) {
750 wwarning(_("too few arguments for %s"), argv[i-1]);
751 exit(0);
753 Locale = argv[i];
754 } else if (strcmp(argv[i], "-display")==0
755 || strcmp(argv[i], "--display")==0) {
756 i++;
757 if (i>=argc) {
758 wwarning(_("too few arguments for %s"), argv[i-1]);
759 exit(0);
761 DisplayName = argv[i];
762 } else if (strcmp(argv[i], "-visualid")==0
763 || strcmp(argv[i], "--visual-id")==0) {
764 i++;
765 if (i>=argc) {
766 wwarning(_("too few arguments for %s"), argv[i-1]);
767 exit(0);
769 if (sscanf(argv[i], "%i", &wVisualID)!=1) {
770 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
771 exit(0);
773 } else if (strcmp(argv[i], "-static")==0
774 || strcmp(argv[i], "--static")==0) {
776 wPreferences.flags.noupdates = 1;
777 #ifdef XSMP_ENABLED
778 } else if (strcmp(argv[i], "-clientid")==0
779 || strcmp(argv[i], "-restore")==0) {
780 i++;
781 if (i>=argc) {
782 wwarning(_("too few arguments for %s"), argv[i-1]);
783 exit(0);
785 #endif
786 } else if (strcmp(argv[i], "--help")==0) {
787 print_help();
788 exit(0);
789 } else {
790 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
791 printf(_("Try '%s --help' for more information\n"), argv[0]);
792 exit(1);
797 if (!wPreferences.flags.noupdates) {
798 /* check existence of Defaults DB directory */
799 check_defaults();
803 if (Locale) {
804 /* return of wstrconcat should not be free-ed! read putenv man page */
805 putenv(wstrconcat("LANG=", Locale));
806 } else {
807 Locale = getenv("LC_ALL");
808 if (!Locale) {
809 Locale = getenv("LANG");
813 setlocale(LC_ALL, "");
815 if (!Locale || strcmp(Locale, "C")==0 || strcmp(Locale, "POSIX")==0)
816 Locale = NULL;
817 #ifdef I18N
818 if (getenv("NLSPATH"))
819 bindtextdomain("WindowMaker", getenv("NLSPATH"));
820 else
821 bindtextdomain("WindowMaker", LOCALEDIR);
822 bind_textdomain_codeset("WindowMaker", "UTF-8");
823 textdomain("WindowMaker");
825 if (!XSupportsLocale()) {
826 wwarning(_("X server does not support locale"));
829 if (XSetLocaleModifiers("") == NULL) {
830 wwarning(_("cannot set locale modifiers"));
832 #endif
834 if (Locale) {
835 char *ptr;
837 Locale = wstrdup(Locale);
838 ptr = strchr(Locale, '.');
839 if (ptr)
840 *ptr = 0;
843 /* open display */
844 dpy = XOpenDisplay(DisplayName);
845 if (dpy == NULL) {
846 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
847 exit(1);
850 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
851 wsyserror("error setting close-on-exec flag for X connection");
852 exit(1);
855 /* check if the user specified a complete display name (with screen).
856 * If so, only manage the specified screen */
857 if (DisplayName)
858 str = strchr(DisplayName, ':');
859 else
860 str = NULL;
862 if (str && sscanf(str, ":%i.%i", &d, &s)==2)
863 multiHead = False;
865 DisplayName = XDisplayName(DisplayName);
867 int len = strlen(DisplayName)+64;
868 str = wmalloc(len);
869 snprintf(str, len, "DISPLAY=%s", DisplayName);
871 putenv(str);
873 #ifdef DEBUG
874 if (doSync)
875 XSynchronize(dpy, True);
876 #endif
878 wXModifierInitialize();
880 #ifdef XSMP_ENABLED
881 wSessionConnectManager(argv, argc);
882 #endif
884 StartUp(!multiHead);
886 if (wScreenCount==1)
887 multiHead = False;
889 execInitScript();
891 EventLoop();
892 return -1;