fixed problem with default visual ID for multi-screen setups by using multiple IDs...
[wmaker-crm.git] / src / main.c
blob98badde99a83375bb3a8d65130c83e2d4686ffa4
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 #include <sys/inotify.h>
24 #include "wconfig.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <fcntl.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
37 /* Xlocale.h and locale.h are the same if X_LOCALE is undefind in wconfig.h,
38 * and if X_LOCALE is defined, X's locale emulating functions will be used.
39 * See Xlocale.h for more information.
41 #include <X11/Xlocale.h>
43 #define MAINFILE
45 #include "WindowMaker.h"
46 #include "window.h"
47 #include "funcs.h"
48 #include "menu.h"
49 #include "keybind.h"
50 #include "xmodifier.h"
51 #include "defaults.h"
52 #include "session.h"
53 #include "dialog.h"
55 #include <WINGs/WUtil.h>
57 #ifndef GLOBAL_DEFAULTS_SUBDIR
58 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
59 #endif
61 /****** Global Variables ******/
63 /* general info */
65 Display *dpy;
67 char *ProgName;
69 unsigned int ValidModMask = 0xff;
71 int inotifyFD;
72 int inotifyWD;
73 /* locale to use. NULL==POSIX or C */
74 char *Locale = NULL;
76 int wScreenCount = 0;
78 WPreferences wPreferences;
80 WMPropList *wDomainName;
81 WMPropList *wAttributeDomainName;
83 WShortKey wKeyBindings[WKBD_LAST];
85 /* defaults domains */
86 WDDomain *WDWindowMaker = NULL;
87 WDDomain *WDWindowAttributes = NULL;
88 WDDomain *WDRootMenu = NULL;
90 /* XContexts */
91 XContext wWinContext;
92 XContext wAppWinContext;
93 XContext wStackContext;
94 XContext wVEdgeContext;
96 /* Atoms */
97 Atom _XA_WM_STATE;
98 Atom _XA_WM_CHANGE_STATE;
99 Atom _XA_WM_PROTOCOLS;
100 Atom _XA_WM_TAKE_FOCUS;
101 Atom _XA_WM_DELETE_WINDOW;
102 Atom _XA_WM_SAVE_YOURSELF;
103 Atom _XA_WM_CLIENT_LEADER;
104 Atom _XA_WM_COLORMAP_WINDOWS;
105 Atom _XA_WM_COLORMAP_NOTIFY;
107 Atom _XA_GNUSTEP_WM_ATTR;
108 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
109 Atom _XA_GNUSTEP_WM_RESIZEBAR;
110 Atom _XA_GNUSTEP_TITLEBAR_STATE;
112 Atom _XA_WINDOWMAKER_MENU;
113 Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
114 Atom _XA_WINDOWMAKER_STATE;
116 Atom _XA_WINDOWMAKER_WM_FUNCTION;
117 Atom _XA_WINDOWMAKER_NOTICEBOARD;
118 Atom _XA_WINDOWMAKER_COMMAND;
120 Atom _XA_WINDOWMAKER_ICON_SIZE;
121 Atom _XA_WINDOWMAKER_ICON_TILE;
123 Atom _XA_WM_IGNORE_FOCUS_EVENTS;
125 /* cursors */
126 Cursor wCursor[WCUR_LAST];
128 /* last event timestamp for XSetInputFocus */
129 Time LastTimestamp = CurrentTime;
130 /* timestamp on the last time we did XSetInputFocus() */
131 Time LastFocusChange = CurrentTime;
133 #ifdef SHAPE
134 Bool wShapeSupported;
135 int wShapeEventBase;
136 #endif
138 #ifdef KEEP_XKB_LOCK_STATUS
139 Bool wXkbSupported;
140 int wXkbEventBase;
141 #endif
143 /* special flags */
144 char WProgramSigState = 0;
145 char WProgramState = WSTATE_NORMAL;
146 char WDelayedActionSet = 0;
148 /* notifications */
149 const char *WMNManaged = "WMNManaged";
150 const char *WMNUnmanaged = "WMNUnmanaged";
151 const char *WMNChangedWorkspace = "WMNChangedWorkspace";
152 const char *WMNChangedState = "WMNChangedState";
153 const char *WMNChangedFocus = "WMNChangedFocus";
154 const char *WMNChangedStacking = "WMNChangedStacking";
155 const char *WMNChangedName = "WMNChangedName";
157 const char *WMNWorkspaceCreated = "WMNWorkspaceCreated";
158 const char *WMNWorkspaceDestroyed = "WMNWorkspaceDestroyed";
159 const char *WMNWorkspaceChanged = "WMNWorkspaceChanged";
160 const char *WMNWorkspaceNameChanged = "WMNWorkspaceNameChanged";
162 const char *WMNResetStacking = "WMNResetStacking";
164 /******** End Global Variables *****/
166 static char *DisplayName = NULL;
168 static char **Arguments;
170 static int ArgCount;
172 extern void EventLoop();
173 extern void StartUp();
174 extern int MonitorLoop(int argc, char **argv);
176 static Bool multiHead = True;
178 static int *wVisualID = NULL;
179 static int wVisualID_len = 0;
181 static int real_main(int argc, char **argv);
183 int getWVisualID(int screen)
185 if (wVisualID == NULL)
186 return -1;
187 if (screen < 0 || screen >= wVisualID_len)
188 return -1;
190 return wVisualID[screen];
193 static void setWVisualID(int screen, int val)
195 int i;
197 if (screen < 0)
198 return;
200 if (wVisualID == NULL) {
201 /* no array at all, alloc space for screen + 1 entries
202 * and init with default value */
203 wVisualID_len = screen + 1;
204 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
205 for (i = 0; i < wVisualID_len; i++) {
206 wVisualID[i] = -1;
208 } else if (screen >= wVisualID_len) {
209 /* larger screen number than previously allocated
210 so enlarge array */
211 int oldlen = wVisualID_len;
213 wVisualID_len = screen + 1;
214 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
215 for (i = oldlen; i < wVisualID_len; i++) {
216 wVisualID[i] = -1;
220 wVisualID[screen] = val;
224 * this function splits a given string at the comma into tokens
225 * and set the wVisualID variable to each parsed number
227 static int initWVisualID(const char *user_str)
229 char *mystr = strdup(user_str);
230 int cur_in_pos = 0;
231 int cur_out_pos = 0;
232 int cur_screen = 0;
233 int error_found = 0;
235 for (;;) {
236 /* check for delimiter */
237 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
238 int v;
240 mystr[cur_out_pos] = '\0';
242 if (sscanf(mystr, "%i", &v) != 1) {
243 error_found = 1;
244 break;
247 setWVisualID(cur_screen, v);
249 cur_screen++;
250 cur_out_pos = 0;
253 /* break in case last char has been consumed */
254 if (user_str[cur_in_pos] == '\0')
255 break;
257 /* if the current char is no delimiter put it into mystr */
258 if (user_str[cur_in_pos] != ',') {
259 mystr[cur_out_pos++] = user_str[cur_in_pos];
261 cur_in_pos++;
264 free(mystr);
266 if (cur_screen == 0||error_found != 0)
267 return 1;
269 return 0;
272 void Exit(int status)
274 #ifdef XSMP_ENABLED
275 wSessionDisconnectManager();
276 #endif
277 if (dpy)
278 XCloseDisplay(dpy);
280 exit(status);
283 void Restart(char *manager, Bool abortOnFailure)
285 char *prog = NULL;
286 char *argv[MAX_RESTART_ARGS];
287 int i;
289 if (manager && manager[0] != 0) {
290 prog = argv[0] = strtok(manager, " ");
291 for (i = 1; i < MAX_RESTART_ARGS; i++) {
292 argv[i] = strtok(NULL, " ");
293 if (argv[i] == NULL) {
294 break;
298 if (dpy) {
299 #ifdef XSMP_ENABLED
300 wSessionDisconnectManager();
301 #endif
302 XCloseDisplay(dpy);
303 dpy = NULL;
305 if (!prog) {
306 execvp(Arguments[0], Arguments);
307 wfatal(_("failed to restart Window Maker."));
308 } else {
309 execvp(prog, argv);
310 wsyserror(_("could not exec %s"), prog);
312 if (abortOnFailure)
313 exit(7);
316 void SetupEnvironment(WScreen * scr)
318 char *tmp, *ptr;
319 char buf[16];
321 if (multiHead) {
322 int len = strlen(DisplayName) + 64;
323 tmp = wmalloc(len);
324 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
325 ptr = strchr(strchr(tmp, ':'), '.');
326 if (ptr)
327 *ptr = 0;
328 snprintf(buf, sizeof(buf), ".%i", scr->screen);
329 strcat(tmp, buf);
330 putenv(tmp);
332 tmp = wmalloc(60);
333 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
334 scr->rcontext->attribs->colors_per_channel);
335 putenv(tmp);
338 typedef struct {
339 WScreen *scr;
340 char *command;
341 } _tuple;
343 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
345 if (status == 127) {
346 char *buffer;
348 buffer = wstrconcat(_("Could not execute command: "), data->command);
350 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
351 wfree(buffer);
352 } else if (status != 127) {
354 printf("%s: %i\n", data->command, status);
358 wfree(data->command);
359 wfree(data);
362 void ExecuteShellCommand(WScreen * scr, char *command)
364 static char *shell = NULL;
365 pid_t pid;
368 * This have a problem: if the shell is tcsh (not sure about others)
369 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
370 * will block and the command will not be executed.
371 if (!shell) {
372 shell = getenv("SHELL");
373 if (!shell)
374 shell = "/bin/sh";
377 shell = "/bin/sh";
379 pid = fork();
381 if (pid == 0) {
383 SetupEnvironment(scr);
385 #ifdef HAVE_SETSID
386 setsid();
387 #endif
388 execl(shell, shell, "-c", command, NULL);
389 wsyserror("could not execute %s -c %s", shell, command);
390 Exit(-1);
391 } else if (pid < 0) {
392 wsyserror("cannot fork a new process");
393 } else {
394 _tuple *data = wmalloc(sizeof(_tuple));
396 data->scr = scr;
397 data->command = wstrdup(command);
399 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
404 *---------------------------------------------------------------------
405 * wAbort--
406 * Do a major cleanup and exit the program
408 *----------------------------------------------------------------------
410 void wAbort(Bool dumpCore)
412 int i;
413 WScreen *scr;
415 for (i = 0; i < wScreenCount; i++) {
416 scr = wScreenWithNumber(i);
417 if (scr)
418 RestoreDesktop(scr);
420 printf(_("%s aborted.\n"), ProgName);
421 if (dumpCore)
422 abort();
423 else
424 exit(1);
427 void print_help()
429 printf(_("Usage: %s [options]\n"), ProgName);
430 puts(_("The Window Maker window manager for the X window system"));
431 puts("");
432 puts(_(" -display host:dpy display to use"));
433 #ifdef USECPP
434 puts(_(" --no-cpp disable preprocessing of configuration files"));
435 #endif
436 puts(_(" --no-dock do not open the application Dock"));
437 puts(_(" --no-clip do not open the workspace Clip"));
438 puts(_(" --no-autolaunch do not autolaunch applications"));
439 puts(_(" --dont-restore do not restore saved session"));
441 puts(_(" --locale locale locale to use"));
443 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
444 puts(_(" --visual-id visualid visual id of visual to use"));
445 puts(_(" --static do not update or save configurations"));
446 #ifdef DEBUG
447 puts(_(" --synchronous turn on synchronous display mode"));
448 #endif
449 puts(_(" --version print version and exit"));
450 puts(_(" --help show this message"));
453 void check_defaults()
455 char *path;
457 path = wdefaultspathfordomain("WindowMaker");
459 if (access(path, R_OK) != 0) {
460 #if 0
461 wfatal(_("could not find user GNUstep directory (%s).\n"
462 "Make sure you have installed Window Maker correctly and run wmaker.inst"), path);
463 exit(1);
464 #else
465 wwarning(_("could not find user GNUstep directory (%s)."), path);
467 if (system("wmaker.inst --batch") != 0) {
468 wwarning(_("There was an error while creating GNUstep directory, please "
469 "make sure you have installed Window Maker correctly and run wmaker.inst"));
470 } else {
471 wwarning(_("%s directory created with default configuration."), path);
473 #endif
476 wfree(path);
480 * Add watch here, used to notify if configuration
481 * files have changed, using linux kernel inotify mechanism
484 static void inotifyWatchConfig()
486 char *watchPath = NULL;
487 inotifyFD = inotify_init(); /* Initialise an inotify instance */
488 if (inotifyFD < 0) {
489 wwarning(_("could not initialise an inotify instance."
490 " Changes to the defaults database will require"
491 " a restart to take effect. Check your kernel!"));
492 } else {
493 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
494 /* Add the watch; really we are only looking for modify events
495 * but we might want more in the future so check all events for now.
496 * The individual events are checked for in event.c.
498 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
499 if (inotifyWD < 0) {
500 wwarning(_("could not add an inotify watch on path\n."
501 "%s\n"
502 "Changes to the defaults database will require"
503 " a restart to take effect."), watchPath);
504 close(inotifyFD);
507 wfree(watchPath);
510 static void execInitScript()
512 char *file, *paths;
514 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
515 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
517 file = wfindfile(paths, DEF_INIT_SCRIPT);
518 wfree(paths);
520 if (file) {
521 if (system(file) != 0) {
522 wsyserror(_("%s:could not execute initialization script"), file);
524 #if 0
525 if (fork() == 0) {
526 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
527 wsyserror(_("%s:could not execute initialization script"), file);
528 exit(1);
530 #endif
531 wfree(file);
535 void ExecExitScript()
537 char *file, *paths;
539 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
540 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
542 file = wfindfile(paths, DEF_EXIT_SCRIPT);
543 wfree(paths);
545 if (file) {
546 if (system(file) != 0) {
547 wsyserror(_("%s:could not execute exit script"), file);
549 #if 0
550 if (fork() == 0) {
551 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
552 wsyserror(_("%s:could not execute exit script"), file);
553 exit(1);
555 #endif
556 wfree(file);
560 #if 0
561 char *getFullPath(char *path)
563 char buffer[1024];
564 char *tmp;
565 char *basep = (char *)buffer;
567 if (*path != '/' && getcwd(buffer, 1023)) {
569 for (;;) {
570 if (strncmp(path, "../", 3) == 0) {
571 path += 3;
572 basep = strchr(basep, '/');
573 if (!basep || *path == 0)
574 break;
577 if (*path == '/' || strncmp(path, "./", 2) == 0) {
578 tmp =}
581 * path
582 * ./path
583 * ../path
584 * ../../path
587 } else {
588 return wstrconcat(path);
591 return tmp;
593 #endif
595 int main(int argc, char **argv)
597 int i_am_the_monitor, i, len;
598 char *str, *alt;
600 /* setup common stuff for the monitor and wmaker itself */
601 WMInitializeApplication("WindowMaker", &argc, argv);
603 memset(&wPreferences, 0, sizeof(WPreferences));
605 wPreferences.fallbackWMs = WMCreateArray(8);
606 alt = getenv("WINDOWMAKER_ALT_WM");
607 if (alt != NULL)
608 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
611 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
612 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
613 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
614 WMAddToArray(wPreferences.fallbackWMs, NULL);
615 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
616 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
618 i_am_the_monitor = 1;
620 for (i = 1; i < argc; i++) {
621 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
622 i_am_the_monitor = 0;
623 break;
624 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
625 i++;
626 if (i >= argc) {
627 wwarning(_("too few arguments for %s"), argv[i - 1]);
628 exit(0);
630 DisplayName = argv[i];
634 DisplayName = XDisplayName(DisplayName);
635 len = strlen(DisplayName) + 64;
636 str = wmalloc(len);
637 snprintf(str, len, "DISPLAY=%s", DisplayName);
638 putenv(str);
640 if (i_am_the_monitor)
641 return MonitorLoop(argc, argv);
642 else
643 return real_main(argc, argv);
646 static int real_main(int argc, char **argv)
648 int i, restart = 0;
649 char *pos;
650 int d, s;
651 int flag;
652 #ifdef DEBUG
653 Bool doSync = False;
654 #endif
655 setlocale(LC_ALL, "");
657 wsetabort(wAbort);
659 /* for telling WPrefs what's the name of the wmaker binary being ran */
660 setenv("WMAKER_BIN_NAME", argv[0], 1);
662 flag = 0;
663 ArgCount = argc;
664 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
665 for (i = 0; i < argc; i++) {
666 Arguments[i] = argv[i];
668 /* add the extra option to signal that we're just restarting wmaker */
669 Arguments[argc - 1] = "--for-real=";
670 Arguments[argc] = NULL;
672 ProgName = strrchr(argv[0], '/');
673 if (!ProgName)
674 ProgName = argv[0];
675 else
676 ProgName++;
678 restart = 0;
680 if (argc > 1) {
681 for (i = 1; i < argc; i++) {
682 #ifdef USECPP
683 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
684 wPreferences.flags.nocpp = 1;
685 } else
686 #endif
687 if (strcmp(argv[i], "--for-real") == 0) {
688 wPreferences.flags.restarting = 0;
689 } else if (strcmp(argv[i], "--for-real=") == 0) {
690 wPreferences.flags.restarting = 1;
691 } else if (strcmp(argv[i], "--for-real-") == 0) {
692 wPreferences.flags.restarting = 2;
693 } else if (strcmp(argv[i], "-no-autolaunch") == 0
694 || strcmp(argv[i], "--no-autolaunch") == 0) {
695 wPreferences.flags.noautolaunch = 1;
696 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
697 wPreferences.flags.norestore = 1;
698 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
699 wPreferences.flags.nodock = 1;
700 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
701 wPreferences.flags.noclip = 1;
702 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
703 printf("Window Maker %s\n", VERSION);
704 exit(0);
705 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
706 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
707 exit(0);
708 #ifdef DEBUG
709 } else if (strcmp(argv[i], "--synchronous") == 0) {
710 doSync = 1;
711 #endif
712 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
713 i++;
714 if (i >= argc) {
715 wwarning(_("too few arguments for %s"), argv[i - 1]);
716 exit(0);
718 Locale = argv[i];
719 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
720 i++;
721 if (i >= argc) {
722 wwarning(_("too few arguments for %s"), argv[i - 1]);
723 exit(0);
725 DisplayName = argv[i];
726 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
727 i++;
728 if (i >= argc) {
729 wwarning(_("too few arguments for %s"), argv[i - 1]);
730 exit(0);
732 if (initWVisualID(argv[i]) != 0) {
733 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
734 exit(0);
736 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0) {
738 wPreferences.flags.noupdates = 1;
739 #ifdef XSMP_ENABLED
740 } else if (strcmp(argv[i], "-clientid") == 0 || strcmp(argv[i], "-restore") == 0) {
741 i++;
742 if (i >= argc) {
743 wwarning(_("too few arguments for %s"), argv[i - 1]);
744 exit(0);
746 #endif
747 } else if (strcmp(argv[i], "--help") == 0) {
748 print_help();
749 exit(0);
750 } else {
751 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
752 printf(_("Try '%s --help' for more information\n"), argv[0]);
753 exit(1);
758 if (!wPreferences.flags.noupdates) {
759 /* check existence of Defaults DB directory */
760 check_defaults();
763 if (Locale) {
764 setenv("LANG", Locale, 1);
765 } else {
766 Locale = getenv("LC_ALL");
767 if (!Locale) {
768 Locale = getenv("LANG");
772 setlocale(LC_ALL, "");
774 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
775 Locale = NULL;
776 #ifdef I18N
777 if (getenv("NLSPATH"))
778 bindtextdomain("WindowMaker", getenv("NLSPATH"));
779 else
780 bindtextdomain("WindowMaker", LOCALEDIR);
781 bind_textdomain_codeset("WindowMaker", "UTF-8");
782 textdomain("WindowMaker");
784 if (!XSupportsLocale()) {
785 wwarning(_("X server does not support locale"));
788 if (XSetLocaleModifiers("") == NULL) {
789 wwarning(_("cannot set locale modifiers"));
791 #endif
793 if (Locale) {
794 char *ptr;
796 Locale = wstrdup(Locale);
797 ptr = strchr(Locale, '.');
798 if (ptr)
799 *ptr = 0;
802 /* open display */
803 dpy = XOpenDisplay(DisplayName);
804 if (dpy == NULL) {
805 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
806 exit(1);
809 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
810 wsyserror("error setting close-on-exec flag for X connection");
811 exit(1);
815 if (getWVisualID(0) < 0) {
817 * If unspecified, use default visual instead of waiting
818 * for wrlib/context.c:bestContext() that may end up choosing
819 * the "fake" 24 bits added by the Composite extension.
820 * This is required to avoid all sort of corruptions when
821 * composite is enabled, and at a depth other than 24.
823 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
826 /* check if the user specified a complete display name (with screen).
827 * If so, only manage the specified screen */
828 if (DisplayName)
829 pos = strchr(DisplayName, ':');
830 else
831 pos = NULL;
833 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
834 multiHead = False;
836 DisplayName = XDisplayName(DisplayName);
837 setenv("DISPLAY", DisplayName, 1);
839 #ifdef DEBUG
840 if (doSync)
841 XSynchronize(dpy, True);
842 #endif
844 wXModifierInitialize();
846 #ifdef XSMP_ENABLED
847 wSessionConnectManager(argv, argc);
848 #endif
850 StartUp(!multiHead);
852 if (wScreenCount == 1)
853 multiHead = False;
855 execInitScript();
856 inotifyWatchConfig();
857 EventLoop();
858 return -1;