f1a63b3445d2f3d457de409b51bdb1c595471230
[wmaker-crm.git] / src / main.c
blobf1a63b3445d2f3d457de409b51bdb1c595471230
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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "wconfig.h"
23 #ifdef HAVE_INOTIFY
24 #include <sys/inotify.h>
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <sys/stat.h>
32 #include <sys/types.h>
33 #include <fcntl.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
38 /* Xlocale.h and locale.h are the same if X_LOCALE is undefind in wconfig.h,
39 * and if X_LOCALE is defined, X's locale emulating functions will be used.
40 * See Xlocale.h for more information.
42 #include <X11/Xlocale.h>
44 #define MAINFILE
46 #include "WindowMaker.h"
47 #include "window.h"
48 #include "funcs.h"
49 #include "menu.h"
50 #include "keybind.h"
51 #include "xmodifier.h"
52 #include "session.h"
53 #include "shutdown.h"
54 #include "dialog.h"
56 #include <WINGs/WUtil.h>
58 #ifndef GLOBAL_DEFAULTS_SUBDIR
59 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
60 #endif
62 /****** Global Variables ******/
64 /* general info */
66 Display *dpy;
68 char *ProgName;
70 unsigned int ValidModMask = 0xff;
72 #ifdef HAVE_INOTIFY
73 int inotifyFD;
74 int inotifyWD;
75 #endif
76 /* locale to use. NULL==POSIX or C */
77 char *Locale = NULL;
79 int wScreenCount = 0;
81 WPreferences wPreferences;
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 static Bool multiHead = True;
174 static int *wVisualID = NULL;
175 static int wVisualID_len = 0;
177 static int real_main(int argc, char **argv);
179 int getWVisualID(int screen)
181 if (wVisualID == NULL)
182 return -1;
183 if (screen < 0 || screen >= wVisualID_len)
184 return -1;
186 return wVisualID[screen];
189 static void setWVisualID(int screen, int val)
191 int i;
193 if (screen < 0)
194 return;
196 if (wVisualID == NULL) {
197 /* no array at all, alloc space for screen + 1 entries
198 * and init with default value */
199 wVisualID_len = screen + 1;
200 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
201 for (i = 0; i < wVisualID_len; i++) {
202 wVisualID[i] = -1;
204 } else if (screen >= wVisualID_len) {
205 /* larger screen number than previously allocated
206 so enlarge array */
207 int oldlen = wVisualID_len;
209 wVisualID_len = screen + 1;
210 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
211 for (i = oldlen; i < wVisualID_len; i++) {
212 wVisualID[i] = -1;
216 wVisualID[screen] = val;
220 * this function splits a given string at the comma into tokens
221 * and set the wVisualID variable to each parsed number
223 static int initWVisualID(const char *user_str)
225 char *mystr = strdup(user_str);
226 int cur_in_pos = 0;
227 int cur_out_pos = 0;
228 int cur_screen = 0;
229 int error_found = 0;
231 for (;;) {
232 /* check for delimiter */
233 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
234 int v;
236 mystr[cur_out_pos] = '\0';
238 if (sscanf(mystr, "%i", &v) != 1) {
239 error_found = 1;
240 break;
243 setWVisualID(cur_screen, v);
245 cur_screen++;
246 cur_out_pos = 0;
249 /* break in case last char has been consumed */
250 if (user_str[cur_in_pos] == '\0')
251 break;
253 /* if the current char is no delimiter put it into mystr */
254 if (user_str[cur_in_pos] != ',') {
255 mystr[cur_out_pos++] = user_str[cur_in_pos];
257 cur_in_pos++;
260 free(mystr);
262 if (cur_screen == 0||error_found != 0)
263 return 1;
265 return 0;
268 void Exit(int status)
270 if (dpy)
271 XCloseDisplay(dpy);
273 exit(status);
276 void Restart(char *manager, Bool abortOnFailure)
278 char *prog = NULL;
279 char *argv[MAX_RESTART_ARGS];
280 int i;
282 if (manager && manager[0] != 0) {
283 prog = argv[0] = strtok(manager, " ");
284 for (i = 1; i < MAX_RESTART_ARGS; i++) {
285 argv[i] = strtok(NULL, " ");
286 if (argv[i] == NULL) {
287 break;
291 if (dpy) {
292 XCloseDisplay(dpy);
293 dpy = NULL;
295 if (!prog) {
296 execvp(Arguments[0], Arguments);
297 wfatal(_("failed to restart Window Maker."));
298 } else {
299 execvp(prog, argv);
300 werror(_("could not exec %s"), prog);
302 if (abortOnFailure)
303 exit(7);
306 void SetupEnvironment(WScreen * scr)
308 char *tmp, *ptr;
309 char buf[16];
311 if (multiHead) {
312 int len = strlen(DisplayName) + 64;
313 tmp = wmalloc(len);
314 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
315 ptr = strchr(strchr(tmp, ':'), '.');
316 if (ptr)
317 *ptr = 0;
318 snprintf(buf, sizeof(buf), ".%i", scr->screen);
319 strcat(tmp, buf);
320 putenv(tmp);
322 tmp = wmalloc(60);
323 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
324 scr->rcontext->attribs->colors_per_channel);
325 putenv(tmp);
328 typedef struct {
329 WScreen *scr;
330 char *command;
331 } _tuple;
333 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
335 if (status == 127) {
336 char *buffer;
338 buffer = wstrconcat(_("Could not execute command: "), data->command);
340 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
341 wfree(buffer);
342 } else if (status != 127) {
344 printf("%s: %i\n", data->command, status);
348 wfree(data->command);
349 wfree(data);
352 void ExecuteShellCommand(WScreen * scr, char *command)
354 static char *shell = NULL;
355 pid_t pid;
358 * This have a problem: if the shell is tcsh (not sure about others)
359 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
360 * will block and the command will not be executed.
361 if (!shell) {
362 shell = getenv("SHELL");
363 if (!shell)
364 shell = "/bin/sh";
367 shell = "/bin/sh";
369 pid = fork();
371 if (pid == 0) {
373 SetupEnvironment(scr);
375 #ifdef HAVE_SETSID
376 setsid();
377 #endif
378 execl(shell, shell, "-c", command, NULL);
379 werror("could not execute %s -c %s", shell, command);
380 Exit(-1);
381 } else if (pid < 0) {
382 werror("cannot fork a new process");
383 } else {
384 _tuple *data = wmalloc(sizeof(_tuple));
386 data->scr = scr;
387 data->command = wstrdup(command);
389 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
394 *---------------------------------------------------------------------
395 * RelaunchWindow--
396 * Launch a new instance of the active window
398 *----------------------------------------------------------------------
400 Bool RelaunchWindow(WWindow *wwin)
402 if (! wwin || ! wwin->client_win) {
403 werror("no window to relaunch");
404 return False;
407 char **argv;
408 int argc;
410 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
411 werror("cannot relaunch the application because no WM_COMMAND property is set");
412 return False;
415 pid_t pid = fork();
417 if (pid == 0) {
418 SetupEnvironment(wwin->screen_ptr);
419 #ifdef HAVE_SETSID
420 setsid();
421 #endif
422 /* argv is not null-terminated */
423 char **a = (char **) malloc(argc + 1);
424 if (! a) {
425 werror("out of memory trying to relaunch the application");
426 Exit(-1);
429 int i;
430 for (i = 0; i < argc; i++)
431 a[i] = argv[i];
432 a[i] = NULL;
434 execvp(a[0], a);
435 Exit(-1);
436 } else if (pid < 0) {
437 werror("cannot fork a new process");
439 XFreeStringList(argv);
440 return False;
441 } else {
442 _tuple *data = wmalloc(sizeof(_tuple));
444 data->scr = wwin->screen_ptr;
445 data->command = wtokenjoin(argv, argc);
447 /* not actually a shell command */
448 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
450 XFreeStringList(argv);
453 return True;
457 *---------------------------------------------------------------------
458 * wAbort--
459 * Do a major cleanup and exit the program
461 *----------------------------------------------------------------------
463 void wAbort(Bool dumpCore)
465 int i;
466 WScreen *scr;
468 for (i = 0; i < wScreenCount; i++) {
469 scr = wScreenWithNumber(i);
470 if (scr)
471 RestoreDesktop(scr);
473 printf(_("%s aborted.\n"), ProgName);
474 if (dumpCore)
475 abort();
476 else
477 exit(1);
480 static void print_help(void)
482 printf(_("Usage: %s [options]\n"), ProgName);
483 puts(_("The Window Maker window manager for the X window system"));
484 puts("");
485 puts(_(" -display host:dpy display to use"));
486 puts(_(" --no-dock do not open the application Dock"));
487 puts(_(" --no-clip do not open the workspace Clip"));
488 puts(_(" --no-autolaunch do not autolaunch applications"));
489 puts(_(" --dont-restore do not restore saved session"));
491 puts(_(" --locale locale locale to use"));
493 puts(_(" --visual-id visualid visual id of visual to use"));
494 puts(_(" --static do not update or save configurations"));
495 #ifndef HAVE_INOTIFY
496 puts(_(" --no-polling do not periodically check for configuration updates"));
497 #endif
498 puts(_(" --version print version and exit"));
499 puts(_(" --help show this message"));
502 static void check_defaults(void)
504 char *path;
506 path = wdefaultspathfordomain("WindowMaker");
508 if (access(path, R_OK) != 0) {
509 wwarning(_("could not find user GNUstep directory (%s)."), path);
511 if (system("wmaker.inst --batch") != 0) {
512 wwarning(_("There was an error while creating GNUstep directory, please "
513 "make sure you have installed Window Maker correctly and run wmaker.inst"));
514 } else {
515 wwarning(_("%s directory created with default configuration."), path);
519 wfree(path);
522 #ifdef HAVE_INOTIFY
524 * Add watch here, used to notify if configuration
525 * files have changed, using linux kernel inotify mechanism
528 static void inotifyWatchConfig(void)
530 char *watchPath = NULL;
531 inotifyFD = inotify_init(); /* Initialise an inotify instance */
532 if (inotifyFD < 0) {
533 wwarning(_("could not initialise an inotify instance."
534 " Changes to the defaults database will require"
535 " a restart to take effect. Check your kernel!"));
536 } else {
537 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
538 /* Add the watch; really we are only looking for modify events
539 * but we might want more in the future so check all events for now.
540 * The individual events are checked for in event.c.
542 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
543 if (inotifyWD < 0) {
544 wwarning(_("could not add an inotify watch on path %s."
545 "Changes to the defaults database will require"
546 " a restart to take effect."), watchPath);
547 close(inotifyFD);
550 wfree(watchPath);
552 #endif /* HAVE_INOTIFY */
554 static void execInitScript(void)
556 char *file, *paths;
558 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
559 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
561 file = wfindfile(paths, DEF_INIT_SCRIPT);
562 wfree(paths);
564 if (file) {
565 if (system(file) != 0)
566 werror(_("%s:could not execute initialization script"), file);
568 wfree(file);
572 void ExecExitScript(void)
574 char *file, *paths;
576 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
577 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
579 file = wfindfile(paths, DEF_EXIT_SCRIPT);
580 wfree(paths);
582 if (file) {
583 if (system(file) != 0)
584 werror(_("%s:could not execute exit script"), file);
586 wfree(file);
590 int main(int argc, char **argv)
592 int i_am_the_monitor, i, len;
593 char *str, *alt;
595 /* setup common stuff for the monitor and wmaker itself */
596 WMInitializeApplication("WindowMaker", &argc, argv);
598 memset(&wPreferences, 0, sizeof(WPreferences));
600 wPreferences.fallbackWMs = WMCreateArray(8);
601 alt = getenv("WINDOWMAKER_ALT_WM");
602 if (alt != NULL)
603 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
605 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
606 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
607 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
608 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
609 WMAddToArray(wPreferences.fallbackWMs, NULL);
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
611 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
613 i_am_the_monitor = 1;
615 for (i = 1; i < argc; i++) {
616 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
617 i_am_the_monitor = 0;
618 break;
619 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
620 i++;
621 if (i >= argc) {
622 wwarning(_("too few arguments for %s"), argv[i - 1]);
623 exit(0);
625 DisplayName = argv[i];
629 DisplayName = XDisplayName(DisplayName);
630 len = strlen(DisplayName) + 64;
631 str = wmalloc(len);
632 snprintf(str, len, "DISPLAY=%s", DisplayName);
633 putenv(str);
635 if (i_am_the_monitor)
636 return MonitorLoop(argc, argv);
637 else
638 return real_main(argc, argv);
641 static int real_main(int argc, char **argv)
643 int i;
644 char *pos;
645 int d, s;
647 setlocale(LC_ALL, "");
648 wsetabort(wAbort);
650 /* for telling WPrefs what's the name of the wmaker binary being ran */
651 setenv("WMAKER_BIN_NAME", argv[0], 1);
653 ArgCount = argc;
654 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
655 for (i = 0; i < argc; i++) {
656 Arguments[i] = argv[i];
658 /* add the extra option to signal that we're just restarting wmaker */
659 Arguments[argc - 1] = "--for-real=";
660 Arguments[argc] = NULL;
662 ProgName = strrchr(argv[0], '/');
663 if (!ProgName)
664 ProgName = argv[0];
665 else
666 ProgName++;
668 if (argc > 1) {
669 for (i = 1; i < argc; i++) {
670 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
671 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
672 } else if (strcmp(argv[i], "--for-real") == 0) {
673 wPreferences.flags.restarting = 0;
674 } else if (strcmp(argv[i], "--for-real=") == 0) {
675 wPreferences.flags.restarting = 1;
676 } else if (strcmp(argv[i], "--for-real-") == 0) {
677 wPreferences.flags.restarting = 2;
678 } else if (strcmp(argv[i], "-no-autolaunch") == 0
679 || strcmp(argv[i], "--no-autolaunch") == 0) {
680 wPreferences.flags.noautolaunch = 1;
681 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
682 wPreferences.flags.norestore = 1;
683 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
684 wPreferences.flags.nodock = 1;
685 wPreferences.flags.nodrawer = 1;
686 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
687 wPreferences.flags.noclip = 1;
688 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
689 wPreferences.flags.nodrawer = 1;
690 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
691 printf("Window Maker %s\n", VERSION);
692 exit(0);
693 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
694 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
695 exit(0);
696 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
697 i++;
698 if (i >= argc) {
699 wwarning(_("too few arguments for %s"), argv[i - 1]);
700 exit(0);
702 Locale = argv[i];
703 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
704 i++;
705 if (i >= argc) {
706 wwarning(_("too few arguments for %s"), argv[i - 1]);
707 exit(0);
709 DisplayName = argv[i];
710 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
711 i++;
712 if (i >= argc) {
713 wwarning(_("too few arguments for %s"), argv[i - 1]);
714 exit(0);
716 if (initWVisualID(argv[i]) != 0) {
717 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
718 exit(0);
720 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
721 #ifndef HAVE_INOTIFY
722 || strcmp(argv[i], "--no-polling") == 0
723 #endif
725 wPreferences.flags.noupdates = 1;
726 } else if (strcmp(argv[i], "--help") == 0) {
727 print_help();
728 exit(0);
729 } else {
730 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
731 printf(_("Try '%s --help' for more information\n"), argv[0]);
732 exit(1);
737 if (!wPreferences.flags.noupdates) {
738 /* check existence of Defaults DB directory */
739 check_defaults();
742 if (Locale) {
743 setenv("LANG", Locale, 1);
744 } else {
745 Locale = getenv("LC_ALL");
746 if (!Locale) {
747 Locale = getenv("LANG");
751 setlocale(LC_ALL, "");
753 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
754 Locale = NULL;
755 #ifdef I18N
756 if (getenv("NLSPATH")) {
757 bindtextdomain("WindowMaker", getenv("NLSPATH"));
758 #if defined(MENU_TEXTDOMAIN)
759 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
760 #endif
761 } else {
762 bindtextdomain("WindowMaker", LOCALEDIR);
763 #if defined(MENU_TEXTDOMAIN)
764 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
765 #endif
767 bind_textdomain_codeset("WindowMaker", "UTF-8");
768 #if defined(MENU_TEXTDOMAIN)
769 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
770 #endif
771 textdomain("WindowMaker");
773 if (!XSupportsLocale()) {
774 wwarning(_("X server does not support locale"));
777 if (XSetLocaleModifiers("") == NULL) {
778 wwarning(_("cannot set locale modifiers"));
780 #endif
782 if (Locale) {
783 char *ptr;
785 Locale = wstrdup(Locale);
786 ptr = strchr(Locale, '.');
787 if (ptr)
788 *ptr = 0;
791 /* open display */
792 dpy = XOpenDisplay(DisplayName);
793 if (dpy == NULL) {
794 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
795 exit(1);
798 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
799 werror("error setting close-on-exec flag for X connection");
800 exit(1);
804 if (getWVisualID(0) < 0) {
806 * If unspecified, use default visual instead of waiting
807 * for wrlib/context.c:bestContext() that may end up choosing
808 * the "fake" 24 bits added by the Composite extension.
809 * This is required to avoid all sort of corruptions when
810 * composite is enabled, and at a depth other than 24.
812 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
815 /* check if the user specified a complete display name (with screen).
816 * If so, only manage the specified screen */
817 if (DisplayName)
818 pos = strchr(DisplayName, ':');
819 else
820 pos = NULL;
822 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
823 multiHead = False;
825 DisplayName = XDisplayName(DisplayName);
826 setenv("DISPLAY", DisplayName, 1);
828 wXModifierInitialize();
829 StartUp(!multiHead);
831 if (wScreenCount == 1)
832 multiHead = False;
834 execInitScript();
835 #ifdef HAVE_INOTIFY
836 inotifyWatchConfig();
837 #endif
838 EventLoop();
839 return -1;