f492ac6e4c300fd9cb7a0adecc047c1945950dc3
[wmaker-crm.git] / src / main.c
blobf492ac6e4c300fd9cb7a0adecc047c1945950dc3
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 "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 #ifdef HAVE_INOTIFY
72 int inotifyFD;
73 int inotifyWD;
74 #endif
75 /* locale to use. NULL==POSIX or C */
76 char *Locale = NULL;
78 int wScreenCount = 0;
80 WPreferences wPreferences;
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 #ifdef HAVE_XRANDR
143 Bool has_randr;
144 int randr_event_base;
145 #endif
147 /* special flags */
148 char WProgramSigState = 0;
149 char WProgramState = WSTATE_NORMAL;
150 char WDelayedActionSet = 0;
152 /* notifications */
153 const char *WMNManaged = "WMNManaged";
154 const char *WMNUnmanaged = "WMNUnmanaged";
155 const char *WMNChangedWorkspace = "WMNChangedWorkspace";
156 const char *WMNChangedState = "WMNChangedState";
157 const char *WMNChangedFocus = "WMNChangedFocus";
158 const char *WMNChangedStacking = "WMNChangedStacking";
159 const char *WMNChangedName = "WMNChangedName";
161 const char *WMNWorkspaceCreated = "WMNWorkspaceCreated";
162 const char *WMNWorkspaceDestroyed = "WMNWorkspaceDestroyed";
163 const char *WMNWorkspaceChanged = "WMNWorkspaceChanged";
164 const char *WMNWorkspaceNameChanged = "WMNWorkspaceNameChanged";
166 const char *WMNResetStacking = "WMNResetStacking";
168 /******** End Global Variables *****/
170 static char *DisplayName = NULL;
172 static char **Arguments;
174 static int ArgCount;
176 extern void EventLoop(void);
177 extern void StartUp(Bool defaultScreenOnly);
178 extern int MonitorLoop(int argc, char **argv);
180 static Bool multiHead = True;
182 static int *wVisualID = NULL;
183 static int wVisualID_len = 0;
185 static int real_main(int argc, char **argv);
187 int getWVisualID(int screen)
189 if (wVisualID == NULL)
190 return -1;
191 if (screen < 0 || screen >= wVisualID_len)
192 return -1;
194 return wVisualID[screen];
197 static void setWVisualID(int screen, int val)
199 int i;
201 if (screen < 0)
202 return;
204 if (wVisualID == NULL) {
205 /* no array at all, alloc space for screen + 1 entries
206 * and init with default value */
207 wVisualID_len = screen + 1;
208 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
209 for (i = 0; i < wVisualID_len; i++) {
210 wVisualID[i] = -1;
212 } else if (screen >= wVisualID_len) {
213 /* larger screen number than previously allocated
214 so enlarge array */
215 int oldlen = wVisualID_len;
217 wVisualID_len = screen + 1;
218 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
219 for (i = oldlen; i < wVisualID_len; i++) {
220 wVisualID[i] = -1;
224 wVisualID[screen] = val;
228 * this function splits a given string at the comma into tokens
229 * and set the wVisualID variable to each parsed number
231 static int initWVisualID(const char *user_str)
233 char *mystr = strdup(user_str);
234 int cur_in_pos = 0;
235 int cur_out_pos = 0;
236 int cur_screen = 0;
237 int error_found = 0;
239 for (;;) {
240 /* check for delimiter */
241 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
242 int v;
244 mystr[cur_out_pos] = '\0';
246 if (sscanf(mystr, "%i", &v) != 1) {
247 error_found = 1;
248 break;
251 setWVisualID(cur_screen, v);
253 cur_screen++;
254 cur_out_pos = 0;
257 /* break in case last char has been consumed */
258 if (user_str[cur_in_pos] == '\0')
259 break;
261 /* if the current char is no delimiter put it into mystr */
262 if (user_str[cur_in_pos] != ',') {
263 mystr[cur_out_pos++] = user_str[cur_in_pos];
265 cur_in_pos++;
268 free(mystr);
270 if (cur_screen == 0||error_found != 0)
271 return 1;
273 return 0;
276 void Exit(int status)
278 if (dpy)
279 XCloseDisplay(dpy);
281 exit(status);
284 void Restart(char *manager, Bool abortOnFailure)
286 char *prog = NULL;
287 char *argv[MAX_RESTART_ARGS];
288 int i;
290 if (manager && manager[0] != 0) {
291 prog = argv[0] = strtok(manager, " ");
292 for (i = 1; i < MAX_RESTART_ARGS; i++) {
293 argv[i] = strtok(NULL, " ");
294 if (argv[i] == NULL) {
295 break;
299 if (dpy) {
300 XCloseDisplay(dpy);
301 dpy = NULL;
303 if (!prog) {
304 execvp(Arguments[0], Arguments);
305 wfatal(_("failed to restart Window Maker."));
306 } else {
307 execvp(prog, argv);
308 werror(_("could not exec %s"), prog);
310 if (abortOnFailure)
311 exit(7);
314 void SetupEnvironment(WScreen * scr)
316 char *tmp, *ptr;
317 char buf[16];
319 if (multiHead) {
320 int len = strlen(DisplayName) + 64;
321 tmp = wmalloc(len);
322 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
323 ptr = strchr(strchr(tmp, ':'), '.');
324 if (ptr)
325 *ptr = 0;
326 snprintf(buf, sizeof(buf), ".%i", scr->screen);
327 strcat(tmp, buf);
328 putenv(tmp);
330 tmp = wmalloc(60);
331 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
332 scr->rcontext->attribs->colors_per_channel);
333 putenv(tmp);
336 typedef struct {
337 WScreen *scr;
338 char *command;
339 } _tuple;
341 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
343 if (status == 127) {
344 char *buffer;
346 buffer = wstrconcat(_("Could not execute command: "), data->command);
348 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
349 wfree(buffer);
350 } else if (status != 127) {
352 printf("%s: %i\n", data->command, status);
356 wfree(data->command);
357 wfree(data);
360 void ExecuteShellCommand(WScreen * scr, char *command)
362 static char *shell = NULL;
363 pid_t pid;
366 * This have a problem: if the shell is tcsh (not sure about others)
367 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
368 * will block and the command will not be executed.
369 if (!shell) {
370 shell = getenv("SHELL");
371 if (!shell)
372 shell = "/bin/sh";
375 shell = "/bin/sh";
377 pid = fork();
379 if (pid == 0) {
381 SetupEnvironment(scr);
383 #ifdef HAVE_SETSID
384 setsid();
385 #endif
386 execl(shell, shell, "-c", command, NULL);
387 werror("could not execute %s -c %s", shell, command);
388 Exit(-1);
389 } else if (pid < 0) {
390 werror("cannot fork a new process");
391 } else {
392 _tuple *data = wmalloc(sizeof(_tuple));
394 data->scr = scr;
395 data->command = wstrdup(command);
397 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
402 *---------------------------------------------------------------------
403 * RelaunchWindow--
404 * Launch a new instance of the active window
406 *----------------------------------------------------------------------
408 Bool RelaunchWindow(WWindow *wwin)
410 if (! wwin || ! wwin->client_win) {
411 werror("no window to relaunch");
412 return False;
415 char **argv;
416 int argc;
418 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
419 werror("cannot relaunch the application because no WM_COMMAND property is set");
420 return False;
423 pid_t pid = fork();
425 if (pid == 0) {
426 SetupEnvironment(wwin->screen_ptr);
427 #ifdef HAVE_SETSID
428 setsid();
429 #endif
430 /* argv is not null-terminated */
431 char **a = (char **) malloc(argc + 1);
432 if (! a) {
433 werror("out of memory trying to relaunch the application");
434 Exit(-1);
437 int i;
438 for (i = 0; i < argc; i++)
439 a[i] = argv[i];
440 a[i] = NULL;
442 execvp(a[0], a);
443 Exit(-1);
444 } else if (pid < 0) {
445 werror("cannot fork a new process");
447 XFreeStringList(argv);
448 return False;
449 } else {
450 _tuple *data = wmalloc(sizeof(_tuple));
452 data->scr = wwin->screen_ptr;
453 data->command = wtokenjoin(argv, argc);
455 /* not actually a shell command */
456 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
458 XFreeStringList(argv);
461 return True;
465 *---------------------------------------------------------------------
466 * wAbort--
467 * Do a major cleanup and exit the program
469 *----------------------------------------------------------------------
471 void wAbort(Bool dumpCore)
473 int i;
474 WScreen *scr;
476 for (i = 0; i < wScreenCount; i++) {
477 scr = wScreenWithNumber(i);
478 if (scr)
479 RestoreDesktop(scr);
481 printf(_("%s aborted.\n"), ProgName);
482 if (dumpCore)
483 abort();
484 else
485 exit(1);
488 static void print_help(void)
490 printf(_("Usage: %s [options]\n"), ProgName);
491 puts(_("The Window Maker window manager for the X window system"));
492 puts("");
493 puts(_(" -display host:dpy display to use"));
494 puts(_(" --no-dock do not open the application Dock"));
495 puts(_(" --no-clip do not open the workspace Clip"));
496 puts(_(" --no-autolaunch do not autolaunch applications"));
497 puts(_(" --dont-restore do not restore saved session"));
499 puts(_(" --locale locale locale to use"));
501 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
502 puts(_(" --visual-id visualid visual id of visual to use"));
503 puts(_(" --static do not update or save configurations"));
504 #ifndef HAVE_INOTIFY
505 puts(_(" --no-polling do not periodically check for configuration updates"));
506 #endif
507 puts(_(" --version print version and exit"));
508 puts(_(" --help show this message"));
511 static void check_defaults(void)
513 char *path;
515 path = wdefaultspathfordomain("WindowMaker");
517 if (access(path, R_OK) != 0) {
518 wwarning(_("could not find user GNUstep directory (%s)."), path);
520 if (system("wmaker.inst --batch") != 0) {
521 wwarning(_("There was an error while creating GNUstep directory, please "
522 "make sure you have installed Window Maker correctly and run wmaker.inst"));
523 } else {
524 wwarning(_("%s directory created with default configuration."), path);
528 wfree(path);
531 #ifdef HAVE_INOTIFY
533 * Add watch here, used to notify if configuration
534 * files have changed, using linux kernel inotify mechanism
537 static void inotifyWatchConfig(void)
539 char *watchPath = NULL;
540 inotifyFD = inotify_init(); /* Initialise an inotify instance */
541 if (inotifyFD < 0) {
542 wwarning(_("could not initialise an inotify instance."
543 " Changes to the defaults database will require"
544 " a restart to take effect. Check your kernel!"));
545 } else {
546 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
547 /* Add the watch; really we are only looking for modify events
548 * but we might want more in the future so check all events for now.
549 * The individual events are checked for in event.c.
551 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
552 if (inotifyWD < 0) {
553 wwarning(_("could not add an inotify watch on path %s."
554 "Changes to the defaults database will require"
555 " a restart to take effect."), watchPath);
556 close(inotifyFD);
559 wfree(watchPath);
561 #endif /* HAVE_INOTIFY */
563 static void execInitScript(void)
565 char *file, *paths;
567 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
568 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
570 file = wfindfile(paths, DEF_INIT_SCRIPT);
571 wfree(paths);
573 if (file) {
574 if (system(file) != 0)
575 werror(_("%s:could not execute initialization script"), file);
577 wfree(file);
581 void ExecExitScript(void)
583 char *file, *paths;
585 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
586 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
588 file = wfindfile(paths, DEF_EXIT_SCRIPT);
589 wfree(paths);
591 if (file) {
592 if (system(file) != 0)
593 werror(_("%s:could not execute exit script"), file);
595 wfree(file);
599 int main(int argc, char **argv)
601 int i_am_the_monitor, i, len;
602 char *str, *alt;
604 /* setup common stuff for the monitor and wmaker itself */
605 WMInitializeApplication("WindowMaker", &argc, argv);
607 memset(&wPreferences, 0, sizeof(WPreferences));
609 wPreferences.fallbackWMs = WMCreateArray(8);
610 alt = getenv("WINDOWMAKER_ALT_WM");
611 if (alt != NULL)
612 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
614 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
615 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
616 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
617 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
618 WMAddToArray(wPreferences.fallbackWMs, NULL);
619 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
620 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
622 i_am_the_monitor = 1;
624 for (i = 1; i < argc; i++) {
625 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
626 i_am_the_monitor = 0;
627 break;
628 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
629 i++;
630 if (i >= argc) {
631 wwarning(_("too few arguments for %s"), argv[i - 1]);
632 exit(0);
634 DisplayName = argv[i];
638 DisplayName = XDisplayName(DisplayName);
639 len = strlen(DisplayName) + 64;
640 str = wmalloc(len);
641 snprintf(str, len, "DISPLAY=%s", DisplayName);
642 putenv(str);
644 if (i_am_the_monitor)
645 return MonitorLoop(argc, argv);
646 else
647 return real_main(argc, argv);
650 static int real_main(int argc, char **argv)
652 int i;
653 char *pos;
654 int d, s;
656 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 ArgCount = argc;
663 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
664 for (i = 0; i < argc; i++) {
665 Arguments[i] = argv[i];
667 /* add the extra option to signal that we're just restarting wmaker */
668 Arguments[argc - 1] = "--for-real=";
669 Arguments[argc] = NULL;
671 ProgName = strrchr(argv[0], '/');
672 if (!ProgName)
673 ProgName = argv[0];
674 else
675 ProgName++;
677 if (argc > 1) {
678 for (i = 1; i < argc; i++) {
679 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
680 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
681 } else if (strcmp(argv[i], "--for-real") == 0) {
682 wPreferences.flags.restarting = 0;
683 } else if (strcmp(argv[i], "--for-real=") == 0) {
684 wPreferences.flags.restarting = 1;
685 } else if (strcmp(argv[i], "--for-real-") == 0) {
686 wPreferences.flags.restarting = 2;
687 } else if (strcmp(argv[i], "-no-autolaunch") == 0
688 || strcmp(argv[i], "--no-autolaunch") == 0) {
689 wPreferences.flags.noautolaunch = 1;
690 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
691 wPreferences.flags.norestore = 1;
692 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
693 wPreferences.flags.nodock = 1;
694 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
695 wPreferences.flags.noclip = 1;
696 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
697 printf("Window Maker %s\n", VERSION);
698 exit(0);
699 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
700 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
701 exit(0);
702 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
703 i++;
704 if (i >= argc) {
705 wwarning(_("too few arguments for %s"), argv[i - 1]);
706 exit(0);
708 Locale = argv[i];
709 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
710 i++;
711 if (i >= argc) {
712 wwarning(_("too few arguments for %s"), argv[i - 1]);
713 exit(0);
715 DisplayName = argv[i];
716 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
717 i++;
718 if (i >= argc) {
719 wwarning(_("too few arguments for %s"), argv[i - 1]);
720 exit(0);
722 if (initWVisualID(argv[i]) != 0) {
723 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
724 exit(0);
726 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
727 #ifndef HAVE_INOTIFY
728 || strcmp(argv[i], "--no-polling") == 0
729 #endif
731 wPreferences.flags.noupdates = 1;
732 } else if (strcmp(argv[i], "--help") == 0) {
733 print_help();
734 exit(0);
735 } else {
736 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
737 printf(_("Try '%s --help' for more information\n"), argv[0]);
738 exit(1);
743 if (!wPreferences.flags.noupdates) {
744 /* check existence of Defaults DB directory */
745 check_defaults();
748 if (Locale) {
749 setenv("LANG", Locale, 1);
750 } else {
751 Locale = getenv("LC_ALL");
752 if (!Locale) {
753 Locale = getenv("LANG");
757 setlocale(LC_ALL, "");
759 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
760 Locale = NULL;
761 #ifdef I18N
762 if (getenv("NLSPATH")) {
763 bindtextdomain("WindowMaker", getenv("NLSPATH"));
764 #if defined(MENU_TEXTDOMAIN)
765 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
766 #endif
767 } else {
768 bindtextdomain("WindowMaker", LOCALEDIR);
769 #if defined(MENU_TEXTDOMAIN)
770 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
771 #endif
773 bind_textdomain_codeset("WindowMaker", "UTF-8");
774 #if defined(MENU_TEXTDOMAIN)
775 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
776 #endif
777 textdomain("WindowMaker");
779 if (!XSupportsLocale()) {
780 wwarning(_("X server does not support locale"));
783 if (XSetLocaleModifiers("") == NULL) {
784 wwarning(_("cannot set locale modifiers"));
786 #endif
788 if (Locale) {
789 char *ptr;
791 Locale = wstrdup(Locale);
792 ptr = strchr(Locale, '.');
793 if (ptr)
794 *ptr = 0;
797 /* open display */
798 dpy = XOpenDisplay(DisplayName);
799 if (dpy == NULL) {
800 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
801 exit(1);
804 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
805 werror("error setting close-on-exec flag for X connection");
806 exit(1);
810 if (getWVisualID(0) < 0) {
812 * If unspecified, use default visual instead of waiting
813 * for wrlib/context.c:bestContext() that may end up choosing
814 * the "fake" 24 bits added by the Composite extension.
815 * This is required to avoid all sort of corruptions when
816 * composite is enabled, and at a depth other than 24.
818 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
821 /* check if the user specified a complete display name (with screen).
822 * If so, only manage the specified screen */
823 if (DisplayName)
824 pos = strchr(DisplayName, ':');
825 else
826 pos = NULL;
828 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
829 multiHead = False;
831 DisplayName = XDisplayName(DisplayName);
832 setenv("DISPLAY", DisplayName, 1);
834 wXModifierInitialize();
835 StartUp(!multiHead);
837 if (wScreenCount == 1)
838 multiHead = False;
840 execInitScript();
841 #ifdef HAVE_INOTIFY
842 inotifyWatchConfig();
843 #endif
844 EventLoop();
845 return -1;