Cleanup includes of wcore.h, defaults.h and pixmap.h
[wmaker-crm.git] / src / main.c
blob3c9d9f9a9aae512ab0b9489acd161930d313aa6b
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 "session.h"
52 #include "dialog.h"
54 #include <WINGs/WUtil.h>
56 #ifndef GLOBAL_DEFAULTS_SUBDIR
57 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
58 #endif
60 /****** Global Variables ******/
62 /* general info */
64 Display *dpy;
66 char *ProgName;
68 unsigned int ValidModMask = 0xff;
70 int inotifyFD;
71 int inotifyWD;
72 /* locale to use. NULL==POSIX or C */
73 char *Locale = NULL;
75 int wScreenCount = 0;
77 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;
122 Atom _XA_WM_IGNORE_FOCUS_EVENTS;
124 /* cursors */
125 Cursor wCursor[WCUR_LAST];
127 /* last event timestamp for XSetInputFocus */
128 Time LastTimestamp = CurrentTime;
129 /* timestamp on the last time we did XSetInputFocus() */
130 Time LastFocusChange = CurrentTime;
132 #ifdef SHAPE
133 Bool wShapeSupported;
134 int wShapeEventBase;
135 #endif
137 #ifdef KEEP_XKB_LOCK_STATUS
138 Bool wXkbSupported;
139 int wXkbEventBase;
140 #endif
142 /* special flags */
143 char WProgramSigState = 0;
144 char WProgramState = WSTATE_NORMAL;
145 char WDelayedActionSet = 0;
147 /* notifications */
148 const char *WMNManaged = "WMNManaged";
149 const char *WMNUnmanaged = "WMNUnmanaged";
150 const char *WMNChangedWorkspace = "WMNChangedWorkspace";
151 const char *WMNChangedState = "WMNChangedState";
152 const char *WMNChangedFocus = "WMNChangedFocus";
153 const char *WMNChangedStacking = "WMNChangedStacking";
154 const char *WMNChangedName = "WMNChangedName";
156 const char *WMNWorkspaceCreated = "WMNWorkspaceCreated";
157 const char *WMNWorkspaceDestroyed = "WMNWorkspaceDestroyed";
158 const char *WMNWorkspaceChanged = "WMNWorkspaceChanged";
159 const char *WMNWorkspaceNameChanged = "WMNWorkspaceNameChanged";
161 const char *WMNResetStacking = "WMNResetStacking";
163 /******** End Global Variables *****/
165 static char *DisplayName = NULL;
167 static char **Arguments;
169 static int ArgCount;
171 extern void EventLoop();
172 extern void StartUp();
173 extern int MonitorLoop(int argc, char **argv);
175 static Bool multiHead = True;
177 static int *wVisualID = NULL;
178 static int wVisualID_len = 0;
180 static int real_main(int argc, char **argv);
182 int getWVisualID(int screen)
184 if (wVisualID == NULL)
185 return -1;
186 if (screen < 0 || screen >= wVisualID_len)
187 return -1;
189 return wVisualID[screen];
192 static void setWVisualID(int screen, int val)
194 int i;
196 if (screen < 0)
197 return;
199 if (wVisualID == NULL) {
200 /* no array at all, alloc space for screen + 1 entries
201 * and init with default value */
202 wVisualID_len = screen + 1;
203 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
204 for (i = 0; i < wVisualID_len; i++) {
205 wVisualID[i] = -1;
207 } else if (screen >= wVisualID_len) {
208 /* larger screen number than previously allocated
209 so enlarge array */
210 int oldlen = wVisualID_len;
212 wVisualID_len = screen + 1;
213 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
214 for (i = oldlen; i < wVisualID_len; i++) {
215 wVisualID[i] = -1;
219 wVisualID[screen] = val;
223 * this function splits a given string at the comma into tokens
224 * and set the wVisualID variable to each parsed number
226 static int initWVisualID(const char *user_str)
228 char *mystr = strdup(user_str);
229 int cur_in_pos = 0;
230 int cur_out_pos = 0;
231 int cur_screen = 0;
232 int error_found = 0;
234 for (;;) {
235 /* check for delimiter */
236 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
237 int v;
239 mystr[cur_out_pos] = '\0';
241 if (sscanf(mystr, "%i", &v) != 1) {
242 error_found = 1;
243 break;
246 setWVisualID(cur_screen, v);
248 cur_screen++;
249 cur_out_pos = 0;
252 /* break in case last char has been consumed */
253 if (user_str[cur_in_pos] == '\0')
254 break;
256 /* if the current char is no delimiter put it into mystr */
257 if (user_str[cur_in_pos] != ',') {
258 mystr[cur_out_pos++] = user_str[cur_in_pos];
260 cur_in_pos++;
263 free(mystr);
265 if (cur_screen == 0||error_found != 0)
266 return 1;
268 return 0;
271 void Exit(int status)
273 if (dpy)
274 XCloseDisplay(dpy);
276 exit(status);
279 void Restart(char *manager, Bool abortOnFailure)
281 char *prog = NULL;
282 char *argv[MAX_RESTART_ARGS];
283 int i;
285 if (manager && manager[0] != 0) {
286 prog = argv[0] = strtok(manager, " ");
287 for (i = 1; i < MAX_RESTART_ARGS; i++) {
288 argv[i] = strtok(NULL, " ");
289 if (argv[i] == NULL) {
290 break;
294 if (dpy) {
295 XCloseDisplay(dpy);
296 dpy = NULL;
298 if (!prog) {
299 execvp(Arguments[0], Arguments);
300 wfatal(_("failed to restart Window Maker."));
301 } else {
302 execvp(prog, argv);
303 wsyserror(_("could not exec %s"), prog);
305 if (abortOnFailure)
306 exit(7);
309 void SetupEnvironment(WScreen * scr)
311 char *tmp, *ptr;
312 char buf[16];
314 if (multiHead) {
315 int len = strlen(DisplayName) + 64;
316 tmp = wmalloc(len);
317 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
318 ptr = strchr(strchr(tmp, ':'), '.');
319 if (ptr)
320 *ptr = 0;
321 snprintf(buf, sizeof(buf), ".%i", scr->screen);
322 strcat(tmp, buf);
323 putenv(tmp);
325 tmp = wmalloc(60);
326 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
327 scr->rcontext->attribs->colors_per_channel);
328 putenv(tmp);
331 typedef struct {
332 WScreen *scr;
333 char *command;
334 } _tuple;
336 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
338 if (status == 127) {
339 char *buffer;
341 buffer = wstrconcat(_("Could not execute command: "), data->command);
343 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
344 wfree(buffer);
345 } else if (status != 127) {
347 printf("%s: %i\n", data->command, status);
351 wfree(data->command);
352 wfree(data);
355 void ExecuteShellCommand(WScreen * scr, char *command)
357 static char *shell = NULL;
358 pid_t pid;
361 * This have a problem: if the shell is tcsh (not sure about others)
362 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
363 * will block and the command will not be executed.
364 if (!shell) {
365 shell = getenv("SHELL");
366 if (!shell)
367 shell = "/bin/sh";
370 shell = "/bin/sh";
372 pid = fork();
374 if (pid == 0) {
376 SetupEnvironment(scr);
378 #ifdef HAVE_SETSID
379 setsid();
380 #endif
381 execl(shell, shell, "-c", command, NULL);
382 wsyserror("could not execute %s -c %s", shell, command);
383 Exit(-1);
384 } else if (pid < 0) {
385 wsyserror("cannot fork a new process");
386 } else {
387 _tuple *data = wmalloc(sizeof(_tuple));
389 data->scr = scr;
390 data->command = wstrdup(command);
392 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
397 *---------------------------------------------------------------------
398 * wAbort--
399 * Do a major cleanup and exit the program
401 *----------------------------------------------------------------------
403 void wAbort(Bool dumpCore)
405 int i;
406 WScreen *scr;
408 for (i = 0; i < wScreenCount; i++) {
409 scr = wScreenWithNumber(i);
410 if (scr)
411 RestoreDesktop(scr);
413 printf(_("%s aborted.\n"), ProgName);
414 if (dumpCore)
415 abort();
416 else
417 exit(1);
420 void print_help()
422 printf(_("Usage: %s [options]\n"), ProgName);
423 puts(_("The Window Maker window manager for the X window system"));
424 puts("");
425 puts(_(" -display host:dpy display to use"));
426 #ifdef USECPP
427 puts(_(" --no-cpp disable preprocessing of configuration files"));
428 #endif
429 puts(_(" --no-dock do not open the application Dock"));
430 puts(_(" --no-clip do not open the workspace Clip"));
431 puts(_(" --no-autolaunch do not autolaunch applications"));
432 puts(_(" --dont-restore do not restore saved session"));
434 puts(_(" --locale locale locale to use"));
436 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
437 puts(_(" --visual-id visualid visual id of visual to use"));
438 puts(_(" --static do not update or save configurations"));
439 #ifdef DEBUG
440 puts(_(" --synchronous turn on synchronous display mode"));
441 #endif
442 puts(_(" --version print version and exit"));
443 puts(_(" --help show this message"));
446 void check_defaults()
448 char *path;
450 path = wdefaultspathfordomain("WindowMaker");
452 if (access(path, R_OK) != 0) {
453 #if 0
454 wfatal(_("could not find user GNUstep directory (%s).\n"
455 "Make sure you have installed Window Maker correctly and run wmaker.inst"), path);
456 exit(1);
457 #else
458 wwarning(_("could not find user GNUstep directory (%s)."), path);
460 if (system("wmaker.inst --batch") != 0) {
461 wwarning(_("There was an error while creating GNUstep directory, please "
462 "make sure you have installed Window Maker correctly and run wmaker.inst"));
463 } else {
464 wwarning(_("%s directory created with default configuration."), path);
466 #endif
469 wfree(path);
473 * Add watch here, used to notify if configuration
474 * files have changed, using linux kernel inotify mechanism
477 static void inotifyWatchConfig()
479 char *watchPath = NULL;
480 inotifyFD = inotify_init(); /* Initialise an inotify instance */
481 if (inotifyFD < 0) {
482 wwarning(_("could not initialise an inotify instance."
483 " Changes to the defaults database will require"
484 " a restart to take effect. Check your kernel!"));
485 } else {
486 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
487 /* Add the watch; really we are only looking for modify events
488 * but we might want more in the future so check all events for now.
489 * The individual events are checked for in event.c.
491 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
492 if (inotifyWD < 0) {
493 wwarning(_("could not add an inotify watch on path\n."
494 "%s\n"
495 "Changes to the defaults database will require"
496 " a restart to take effect."), watchPath);
497 close(inotifyFD);
500 wfree(watchPath);
503 static void execInitScript()
505 char *file, *paths;
507 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
508 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
510 file = wfindfile(paths, DEF_INIT_SCRIPT);
511 wfree(paths);
513 if (file) {
514 if (system(file) != 0) {
515 wsyserror(_("%s:could not execute initialization script"), file);
517 #if 0
518 if (fork() == 0) {
519 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
520 wsyserror(_("%s:could not execute initialization script"), file);
521 exit(1);
523 #endif
524 wfree(file);
528 void ExecExitScript()
530 char *file, *paths;
532 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
533 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
535 file = wfindfile(paths, DEF_EXIT_SCRIPT);
536 wfree(paths);
538 if (file) {
539 if (system(file) != 0) {
540 wsyserror(_("%s:could not execute exit script"), file);
542 #if 0
543 if (fork() == 0) {
544 execl("/bin/sh", "/bin/sh", "-c", file, NULL);
545 wsyserror(_("%s:could not execute exit script"), file);
546 exit(1);
548 #endif
549 wfree(file);
553 #if 0
554 char *getFullPath(char *path)
556 char buffer[1024];
557 char *tmp;
558 char *basep = (char *)buffer;
560 if (*path != '/' && getcwd(buffer, 1023)) {
562 for (;;) {
563 if (strncmp(path, "../", 3) == 0) {
564 path += 3;
565 basep = strchr(basep, '/');
566 if (!basep || *path == 0)
567 break;
570 if (*path == '/' || strncmp(path, "./", 2) == 0) {
571 tmp =}
574 * path
575 * ./path
576 * ../path
577 * ../../path
580 } else {
581 return wstrconcat(path);
584 return tmp;
586 #endif
588 int main(int argc, char **argv)
590 int i_am_the_monitor, i, len;
591 char *str, *alt;
593 /* setup common stuff for the monitor and wmaker itself */
594 WMInitializeApplication("WindowMaker", &argc, argv);
596 memset(&wPreferences, 0, sizeof(WPreferences));
598 wPreferences.fallbackWMs = WMCreateArray(8);
599 alt = getenv("WINDOWMAKER_ALT_WM");
600 if (alt != NULL)
601 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
603 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
604 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
605 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
606 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
607 WMAddToArray(wPreferences.fallbackWMs, NULL);
608 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
609 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
611 i_am_the_monitor = 1;
613 for (i = 1; i < argc; i++) {
614 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
615 i_am_the_monitor = 0;
616 break;
617 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
618 i++;
619 if (i >= argc) {
620 wwarning(_("too few arguments for %s"), argv[i - 1]);
621 exit(0);
623 DisplayName = argv[i];
627 DisplayName = XDisplayName(DisplayName);
628 len = strlen(DisplayName) + 64;
629 str = wmalloc(len);
630 snprintf(str, len, "DISPLAY=%s", DisplayName);
631 putenv(str);
633 if (i_am_the_monitor)
634 return MonitorLoop(argc, argv);
635 else
636 return real_main(argc, argv);
639 static int real_main(int argc, char **argv)
641 int i, restart = 0;
642 char *pos;
643 int d, s;
644 int flag;
645 #ifdef DEBUG
646 Bool doSync = False;
647 #endif
648 setlocale(LC_ALL, "");
650 wsetabort(wAbort);
652 /* for telling WPrefs what's the name of the wmaker binary being ran */
653 setenv("WMAKER_BIN_NAME", argv[0], 1);
655 flag = 0;
656 ArgCount = argc;
657 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
658 for (i = 0; i < argc; i++) {
659 Arguments[i] = argv[i];
661 /* add the extra option to signal that we're just restarting wmaker */
662 Arguments[argc - 1] = "--for-real=";
663 Arguments[argc] = NULL;
665 ProgName = strrchr(argv[0], '/');
666 if (!ProgName)
667 ProgName = argv[0];
668 else
669 ProgName++;
671 restart = 0;
673 if (argc > 1) {
674 for (i = 1; i < argc; i++) {
675 #ifdef USECPP
676 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
677 wPreferences.flags.nocpp = 1;
678 } else
679 #endif
680 if (strcmp(argv[i], "--for-real") == 0) {
681 wPreferences.flags.restarting = 0;
682 } else if (strcmp(argv[i], "--for-real=") == 0) {
683 wPreferences.flags.restarting = 1;
684 } else if (strcmp(argv[i], "--for-real-") == 0) {
685 wPreferences.flags.restarting = 2;
686 } else if (strcmp(argv[i], "-no-autolaunch") == 0
687 || strcmp(argv[i], "--no-autolaunch") == 0) {
688 wPreferences.flags.noautolaunch = 1;
689 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
690 wPreferences.flags.norestore = 1;
691 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
692 wPreferences.flags.nodock = 1;
693 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
694 wPreferences.flags.noclip = 1;
695 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
696 printf("Window Maker %s\n", VERSION);
697 exit(0);
698 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
699 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
700 exit(0);
701 #ifdef DEBUG
702 } else if (strcmp(argv[i], "--synchronous") == 0) {
703 doSync = 1;
704 #endif
705 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
706 i++;
707 if (i >= argc) {
708 wwarning(_("too few arguments for %s"), argv[i - 1]);
709 exit(0);
711 Locale = argv[i];
712 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
713 i++;
714 if (i >= argc) {
715 wwarning(_("too few arguments for %s"), argv[i - 1]);
716 exit(0);
718 DisplayName = argv[i];
719 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
720 i++;
721 if (i >= argc) {
722 wwarning(_("too few arguments for %s"), argv[i - 1]);
723 exit(0);
725 if (initWVisualID(argv[i]) != 0) {
726 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
727 exit(0);
729 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0) {
730 wPreferences.flags.noupdates = 1;
731 } else if (strcmp(argv[i], "--help") == 0) {
732 print_help();
733 exit(0);
734 } else {
735 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
736 printf(_("Try '%s --help' for more information\n"), argv[0]);
737 exit(1);
742 if (!wPreferences.flags.noupdates) {
743 /* check existence of Defaults DB directory */
744 check_defaults();
747 if (Locale) {
748 setenv("LANG", Locale, 1);
749 } else {
750 Locale = getenv("LC_ALL");
751 if (!Locale) {
752 Locale = getenv("LANG");
756 setlocale(LC_ALL, "");
758 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
759 Locale = NULL;
760 #ifdef I18N
761 if (getenv("NLSPATH"))
762 bindtextdomain("WindowMaker", getenv("NLSPATH"));
763 else
764 bindtextdomain("WindowMaker", LOCALEDIR);
765 bind_textdomain_codeset("WindowMaker", "UTF-8");
766 textdomain("WindowMaker");
768 if (!XSupportsLocale()) {
769 wwarning(_("X server does not support locale"));
772 if (XSetLocaleModifiers("") == NULL) {
773 wwarning(_("cannot set locale modifiers"));
775 #endif
777 if (Locale) {
778 char *ptr;
780 Locale = wstrdup(Locale);
781 ptr = strchr(Locale, '.');
782 if (ptr)
783 *ptr = 0;
786 /* open display */
787 dpy = XOpenDisplay(DisplayName);
788 if (dpy == NULL) {
789 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
790 exit(1);
793 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
794 wsyserror("error setting close-on-exec flag for X connection");
795 exit(1);
799 if (getWVisualID(0) < 0) {
801 * If unspecified, use default visual instead of waiting
802 * for wrlib/context.c:bestContext() that may end up choosing
803 * the "fake" 24 bits added by the Composite extension.
804 * This is required to avoid all sort of corruptions when
805 * composite is enabled, and at a depth other than 24.
807 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
810 /* check if the user specified a complete display name (with screen).
811 * If so, only manage the specified screen */
812 if (DisplayName)
813 pos = strchr(DisplayName, ':');
814 else
815 pos = NULL;
817 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
818 multiHead = False;
820 DisplayName = XDisplayName(DisplayName);
821 setenv("DISPLAY", DisplayName, 1);
823 #ifdef DEBUG
824 if (doSync)
825 XSynchronize(dpy, True);
826 #endif
828 wXModifierInitialize();
829 StartUp(!multiHead);
831 if (wScreenCount == 1)
832 multiHead = False;
834 execInitScript();
835 inotifyWatchConfig();
836 EventLoop();
837 return -1;