wmaker: Moved global var with list of cursors to the preferences variable
[wmaker-crm.git] / src / main.c
blob36e595ac3bc4e60f713967f2980a8f0fe4495591
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 "defaults.h"
49 #include "event.h"
50 #include "startup.h"
51 #include "menu.h"
52 #include "keybind.h"
53 #include "xmodifier.h"
54 #include "session.h"
55 #include "shutdown.h"
56 #include "dialog.h"
57 #include "main.h"
58 #include "monitor.h"
60 #include <WINGs/WUtil.h>
62 #ifndef GLOBAL_DEFAULTS_SUBDIR
63 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
64 #endif
66 /****** Global Variables ******/
67 struct wmaker_global_variables w_global;
69 /* general info */
71 Display *dpy;
73 char *ProgName;
75 unsigned int ValidModMask = 0xff;
77 #ifdef HAVE_INOTIFY
78 int inotifyFD;
79 int inotifyWD;
80 #endif
82 int wScreenCount = 0;
84 struct WPreferences wPreferences;
86 WShortKey wKeyBindings[WKBD_LAST];
88 /* defaults domains */
89 WDDomain *WDWindowMaker = NULL;
90 WDDomain *WDWindowAttributes = NULL;
91 WDDomain *WDRootMenu = NULL;
93 /* XContexts */
94 XContext wWinContext;
95 XContext wAppWinContext;
96 XContext wStackContext;
97 XContext wVEdgeContext;
99 /* Atoms */
100 Atom _XA_WM_STATE;
101 Atom _XA_WM_CHANGE_STATE;
102 Atom _XA_WM_PROTOCOLS;
103 Atom _XA_WM_TAKE_FOCUS;
104 Atom _XA_WM_DELETE_WINDOW;
105 Atom _XA_WM_SAVE_YOURSELF;
106 Atom _XA_WM_CLIENT_LEADER;
107 Atom _XA_WM_COLORMAP_WINDOWS;
108 Atom _XA_WM_COLORMAP_NOTIFY;
110 Atom _XA_GNUSTEP_WM_ATTR;
111 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
112 Atom _XA_GNUSTEP_WM_RESIZEBAR;
113 Atom _XA_GNUSTEP_TITLEBAR_STATE;
115 Atom _XA_WINDOWMAKER_MENU;
116 Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
117 Atom _XA_WINDOWMAKER_STATE;
119 Atom _XA_WINDOWMAKER_WM_FUNCTION;
120 Atom _XA_WINDOWMAKER_NOTICEBOARD;
121 Atom _XA_WINDOWMAKER_COMMAND;
123 Atom _XA_WINDOWMAKER_ICON_SIZE;
124 Atom _XA_WINDOWMAKER_ICON_TILE;
126 Atom _XA_WM_IGNORE_FOCUS_EVENTS;
128 #ifdef SHAPE
129 Bool wShapeSupported;
130 int wShapeEventBase;
131 #endif
133 #ifdef KEEP_XKB_LOCK_STATUS
134 Bool wXkbSupported;
135 int wXkbEventBase;
136 #endif
138 /* special flags */
139 char WDelayedActionSet = 0;
141 /* notifications */
142 const char WMNManaged[] = "WMNManaged";
143 const char WMNUnmanaged[] = "WMNUnmanaged";
144 const char WMNChangedWorkspace[] = "WMNChangedWorkspace";
145 const char WMNChangedState[] = "WMNChangedState";
146 const char WMNChangedFocus[] = "WMNChangedFocus";
147 const char WMNChangedStacking[] = "WMNChangedStacking";
148 const char WMNChangedName[] = "WMNChangedName";
150 const char WMNWorkspaceCreated[] = "WMNWorkspaceCreated";
151 const char WMNWorkspaceDestroyed[] = "WMNWorkspaceDestroyed";
152 const char WMNWorkspaceChanged[] = "WMNWorkspaceChanged";
153 const char WMNWorkspaceNameChanged[] = "WMNWorkspaceNameChanged";
155 const char WMNResetStacking[] = "WMNResetStacking";
157 /******** End Global Variables *****/
159 static char *DisplayName = NULL;
161 static char **Arguments;
163 static int ArgCount;
165 static Bool multiHead = True;
167 static int *wVisualID = NULL;
168 static int wVisualID_len = 0;
170 static int real_main(int argc, char **argv);
172 int getWVisualID(int screen)
174 if (wVisualID == NULL)
175 return -1;
176 if (screen < 0 || screen >= wVisualID_len)
177 return -1;
179 return wVisualID[screen];
182 static void setWVisualID(int screen, int val)
184 int i;
186 if (screen < 0)
187 return;
189 if (wVisualID == NULL) {
190 /* no array at all, alloc space for screen + 1 entries
191 * and init with default value */
192 wVisualID_len = screen + 1;
193 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
194 for (i = 0; i < wVisualID_len; i++) {
195 wVisualID[i] = -1;
197 } else if (screen >= wVisualID_len) {
198 /* larger screen number than previously allocated
199 so enlarge array */
200 int oldlen = wVisualID_len;
202 wVisualID_len = screen + 1;
203 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
204 for (i = oldlen; i < wVisualID_len; i++) {
205 wVisualID[i] = -1;
209 wVisualID[screen] = val;
213 * this function splits a given string at the comma into tokens
214 * and set the wVisualID variable to each parsed number
216 static int initWVisualID(const char *user_str)
218 char *mystr = strdup(user_str);
219 int cur_in_pos = 0;
220 int cur_out_pos = 0;
221 int cur_screen = 0;
222 int error_found = 0;
224 for (;;) {
225 /* check for delimiter */
226 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
227 int v;
229 mystr[cur_out_pos] = '\0';
231 if (sscanf(mystr, "%i", &v) != 1) {
232 error_found = 1;
233 break;
236 setWVisualID(cur_screen, v);
238 cur_screen++;
239 cur_out_pos = 0;
242 /* break in case last char has been consumed */
243 if (user_str[cur_in_pos] == '\0')
244 break;
246 /* if the current char is no delimiter put it into mystr */
247 if (user_str[cur_in_pos] != ',') {
248 mystr[cur_out_pos++] = user_str[cur_in_pos];
250 cur_in_pos++;
253 free(mystr);
255 if (cur_screen == 0||error_found != 0)
256 return 1;
258 return 0;
261 noreturn void Exit(int status)
263 if (dpy)
264 XCloseDisplay(dpy);
266 exit(status);
269 void Restart(char *manager, Bool abortOnFailure)
271 char *prog = NULL;
272 char *argv[MAX_RESTART_ARGS];
273 int i;
275 if (manager && manager[0] != 0) {
276 prog = argv[0] = strtok(manager, " ");
277 for (i = 1; i < MAX_RESTART_ARGS; i++) {
278 argv[i] = strtok(NULL, " ");
279 if (argv[i] == NULL) {
280 break;
284 if (dpy) {
285 XCloseDisplay(dpy);
286 dpy = NULL;
288 if (!prog) {
289 execvp(Arguments[0], Arguments);
290 wfatal(_("failed to restart Window Maker."));
291 } else {
292 execvp(prog, argv);
293 werror(_("could not exec %s"), prog);
295 if (abortOnFailure)
296 exit(7);
299 void SetupEnvironment(WScreen * scr)
301 char *tmp, *ptr;
302 char buf[16];
304 if (multiHead) {
305 int len = strlen(DisplayName) + 64;
306 tmp = wmalloc(len);
307 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
308 ptr = strchr(strchr(tmp, ':'), '.');
309 if (ptr)
310 *ptr = 0;
311 snprintf(buf, sizeof(buf), ".%i", scr->screen);
312 strcat(tmp, buf);
313 putenv(tmp);
315 tmp = wmalloc(60);
316 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
317 scr->rcontext->attribs->colors_per_channel);
318 putenv(tmp);
321 typedef struct {
322 WScreen *scr;
323 char *command;
324 } _tuple;
326 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
328 if (status == 127) {
329 char *buffer;
331 buffer = wstrconcat(_("Could not execute command: "), data->command);
333 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
334 wfree(buffer);
335 } else if (status != 127) {
337 printf("%s: %i\n", data->command, status);
341 wfree(data->command);
342 wfree(data);
345 void ExecuteShellCommand(WScreen *scr, const char *command)
347 static char *shell = NULL;
348 pid_t pid;
351 * This have a problem: if the shell is tcsh (not sure about others)
352 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
353 * will block and the command will not be executed.
354 if (!shell) {
355 shell = getenv("SHELL");
356 if (!shell)
357 shell = "/bin/sh";
360 shell = "/bin/sh";
362 pid = fork();
364 if (pid == 0) {
366 SetupEnvironment(scr);
368 #ifdef HAVE_SETSID
369 setsid();
370 #endif
371 execl(shell, shell, "-c", command, NULL);
372 werror("could not execute %s -c %s", shell, command);
373 Exit(-1);
374 } else if (pid < 0) {
375 werror("cannot fork a new process");
376 } else {
377 _tuple *data = wmalloc(sizeof(_tuple));
379 data->scr = scr;
380 data->command = wstrdup(command);
382 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
387 *---------------------------------------------------------------------
388 * RelaunchWindow--
389 * Launch a new instance of the active window
391 *----------------------------------------------------------------------
393 Bool RelaunchWindow(WWindow *wwin)
395 if (! wwin || ! wwin->client_win) {
396 werror("no window to relaunch");
397 return False;
400 char **argv;
401 int argc;
403 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
404 werror("cannot relaunch the application because no WM_COMMAND property is set");
405 return False;
408 pid_t pid = fork();
410 if (pid == 0) {
411 SetupEnvironment(wwin->screen_ptr);
412 #ifdef HAVE_SETSID
413 setsid();
414 #endif
415 /* argv is not null-terminated */
416 char **a = (char **) malloc(argc + 1);
417 if (! a) {
418 werror("out of memory trying to relaunch the application");
419 Exit(-1);
422 int i;
423 for (i = 0; i < argc; i++)
424 a[i] = argv[i];
425 a[i] = NULL;
427 execvp(a[0], a);
428 Exit(-1);
429 } else if (pid < 0) {
430 werror("cannot fork a new process");
432 XFreeStringList(argv);
433 return False;
434 } else {
435 _tuple *data = wmalloc(sizeof(_tuple));
437 data->scr = wwin->screen_ptr;
438 data->command = wtokenjoin(argv, argc);
440 /* not actually a shell command */
441 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
443 XFreeStringList(argv);
446 return True;
450 *---------------------------------------------------------------------
451 * wAbort--
452 * Do a major cleanup and exit the program
454 *----------------------------------------------------------------------
456 noreturn void wAbort(Bool dumpCore)
458 int i;
459 WScreen *scr;
461 for (i = 0; i < wScreenCount; i++) {
462 scr = wScreenWithNumber(i);
463 if (scr)
464 RestoreDesktop(scr);
466 printf(_("%s aborted.\n"), ProgName);
467 if (dumpCore)
468 abort();
469 else
470 exit(1);
473 static void print_help(void)
475 printf(_("Usage: %s [options]\n"), ProgName);
476 puts(_("The Window Maker window manager for the X window system"));
477 puts("");
478 puts(_(" -display host:dpy display to use"));
479 puts(_(" --no-dock do not open the application Dock"));
480 puts(_(" --no-clip do not open the workspace Clip"));
481 puts(_(" --no-autolaunch do not autolaunch applications"));
482 puts(_(" --dont-restore do not restore saved session"));
484 puts(_(" --locale locale locale to use"));
486 puts(_(" --visual-id visualid visual id of visual to use"));
487 puts(_(" --static do not update or save configurations"));
488 #ifndef HAVE_INOTIFY
489 puts(_(" --no-polling do not periodically check for configuration updates"));
490 #endif
491 puts(_(" --version print version and exit"));
492 puts(_(" --help show this message"));
495 static void check_defaults(void)
497 char *path;
499 path = wdefaultspathfordomain("WindowMaker");
501 if (access(path, R_OK) != 0) {
502 wwarning(_("could not find user GNUstep directory (%s)."), path);
504 if (system("wmaker.inst --batch") != 0) {
505 wwarning(_("There was an error while creating GNUstep directory, please "
506 "make sure you have installed Window Maker correctly and run wmaker.inst"));
507 } else {
508 wwarning(_("%s directory created with default configuration."), path);
512 wfree(path);
515 #ifdef HAVE_INOTIFY
517 * Add watch here, used to notify if configuration
518 * files have changed, using linux kernel inotify mechanism
521 static void inotifyWatchConfig(void)
523 char *watchPath = NULL;
524 inotifyFD = inotify_init(); /* Initialise an inotify instance */
525 if (inotifyFD < 0) {
526 wwarning(_("could not initialise an inotify instance."
527 " Changes to the defaults database will require"
528 " a restart to take effect. Check your kernel!"));
529 } else {
530 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
531 /* Add the watch; really we are only looking for modify events
532 * but we might want more in the future so check all events for now.
533 * The individual events are checked for in event.c.
535 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
536 if (inotifyWD < 0) {
537 wwarning(_("could not add an inotify watch on path %s."
538 "Changes to the defaults database will require"
539 " a restart to take effect."), watchPath);
540 close(inotifyFD);
543 wfree(watchPath);
545 #endif /* HAVE_INOTIFY */
547 static void execInitScript(void)
549 char *file, *paths;
551 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
552 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
554 file = wfindfile(paths, DEF_INIT_SCRIPT);
555 wfree(paths);
557 if (file) {
558 if (system(file) != 0)
559 werror(_("%s:could not execute initialization script"), file);
561 wfree(file);
565 void ExecExitScript(void)
567 char *file, *paths;
569 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
570 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
572 file = wfindfile(paths, DEF_EXIT_SCRIPT);
573 wfree(paths);
575 if (file) {
576 if (system(file) != 0)
577 werror(_("%s:could not execute exit script"), file);
579 wfree(file);
583 int main(int argc, char **argv)
585 int i_am_the_monitor, i, len;
586 char *str, *alt;
588 memset(&w_global, 0, sizeof(w_global));
589 w_global.program.state = WSTATE_NORMAL;
590 w_global.program.signal_state = WSTATE_NORMAL;
591 w_global.timestamp.last_event = CurrentTime;
592 w_global.timestamp.focus_change = CurrentTime;
594 /* setup common stuff for the monitor and wmaker itself */
595 WMInitializeApplication("WindowMaker", &argc, argv);
597 memset(&wPreferences, 0, sizeof(wPreferences));
599 wPreferences.fallbackWMs = WMCreateArray(8);
600 alt = getenv("WINDOWMAKER_ALT_WM");
601 if (alt != NULL)
602 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
604 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
605 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
606 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
607 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
608 WMAddToArray(wPreferences.fallbackWMs, NULL);
609 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
612 i_am_the_monitor = 1;
614 for (i = 1; i < argc; i++) {
615 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
616 i_am_the_monitor = 0;
617 break;
618 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
619 i++;
620 if (i >= argc) {
621 wwarning(_("too few arguments for %s"), argv[i - 1]);
622 exit(0);
624 DisplayName = argv[i];
628 DisplayName = XDisplayName(DisplayName);
629 len = strlen(DisplayName) + 64;
630 str = wmalloc(len);
631 snprintf(str, len, "DISPLAY=%s", DisplayName);
632 putenv(str);
634 if (i_am_the_monitor)
635 return MonitorLoop(argc, argv);
636 else
637 return real_main(argc, argv);
640 static int real_main(int argc, char **argv)
642 int i;
643 char *pos;
644 int d, s;
646 setlocale(LC_ALL, "");
647 wsetabort(wAbort);
649 /* for telling WPrefs what's the name of the wmaker binary being ran */
650 setenv("WMAKER_BIN_NAME", argv[0], 1);
652 ArgCount = argc;
653 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
654 for (i = 0; i < argc; i++) {
655 Arguments[i] = argv[i];
657 /* add the extra option to signal that we're just restarting wmaker */
658 Arguments[argc - 1] = "--for-real=";
659 Arguments[argc] = NULL;
661 ProgName = strrchr(argv[0], '/');
662 if (!ProgName)
663 ProgName = argv[0];
664 else
665 ProgName++;
667 if (argc > 1) {
668 for (i = 1; i < argc; i++) {
669 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
670 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
671 } else if (strcmp(argv[i], "--for-real") == 0) {
672 wPreferences.flags.restarting = 0;
673 } else if (strcmp(argv[i], "--for-real=") == 0) {
674 wPreferences.flags.restarting = 1;
675 } else if (strcmp(argv[i], "--for-real-") == 0) {
676 wPreferences.flags.restarting = 2;
677 } else if (strcmp(argv[i], "-no-autolaunch") == 0
678 || strcmp(argv[i], "--no-autolaunch") == 0) {
679 wPreferences.flags.noautolaunch = 1;
680 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
681 wPreferences.flags.norestore = 1;
682 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
683 wPreferences.flags.nodock = 1;
684 wPreferences.flags.nodrawer = 1;
685 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
686 wPreferences.flags.noclip = 1;
687 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
688 wPreferences.flags.nodrawer = 1;
689 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
690 printf("Window Maker %s\n", VERSION);
691 exit(0);
692 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
693 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
694 exit(0);
695 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
696 i++;
697 if (i >= argc) {
698 wwarning(_("too few arguments for %s"), argv[i - 1]);
699 exit(0);
701 w_global.locale = argv[i];
702 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
703 i++;
704 if (i >= argc) {
705 wwarning(_("too few arguments for %s"), argv[i - 1]);
706 exit(0);
708 DisplayName = argv[i];
709 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
710 i++;
711 if (i >= argc) {
712 wwarning(_("too few arguments for %s"), argv[i - 1]);
713 exit(0);
715 if (initWVisualID(argv[i]) != 0) {
716 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
717 exit(0);
719 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
720 #ifndef HAVE_INOTIFY
721 || strcmp(argv[i], "--no-polling") == 0
722 #endif
724 wPreferences.flags.noupdates = 1;
725 } else if (strcmp(argv[i], "--help") == 0) {
726 print_help();
727 exit(0);
728 } else {
729 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
730 printf(_("Try '%s --help' for more information\n"), argv[0]);
731 exit(1);
736 if (!wPreferences.flags.noupdates) {
737 /* check existence of Defaults DB directory */
738 check_defaults();
741 if (w_global.locale) {
742 setenv("LANG", w_global.locale, 1);
743 } else {
744 w_global.locale = getenv("LC_ALL");
745 if (!w_global.locale) {
746 w_global.locale = getenv("LANG");
750 setlocale(LC_ALL, "");
752 if (!w_global.locale || strcmp(w_global.locale, "C") == 0 || strcmp(w_global.locale, "POSIX") == 0)
753 w_global.locale = NULL;
754 #ifdef I18N
755 if (getenv("NLSPATH")) {
756 bindtextdomain("WindowMaker", getenv("NLSPATH"));
757 #if defined(MENU_TEXTDOMAIN)
758 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
759 #endif
760 } else {
761 bindtextdomain("WindowMaker", LOCALEDIR);
762 #if defined(MENU_TEXTDOMAIN)
763 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
764 #endif
766 bind_textdomain_codeset("WindowMaker", "UTF-8");
767 #if defined(MENU_TEXTDOMAIN)
768 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
769 #endif
770 textdomain("WindowMaker");
772 if (!XSupportsLocale()) {
773 wwarning(_("X server does not support locale"));
776 if (XSetLocaleModifiers("") == NULL) {
777 wwarning(_("cannot set locale modifiers"));
779 #endif
781 if (w_global.locale) {
782 char *ptr;
784 w_global.locale = wstrdup(w_global.locale);
785 ptr = strchr(w_global.locale, '.');
786 if (ptr)
787 *ptr = 0;
790 /* open display */
791 dpy = XOpenDisplay(DisplayName);
792 if (dpy == NULL) {
793 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
794 exit(1);
797 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
798 werror("error setting close-on-exec flag for X connection");
799 exit(1);
803 if (getWVisualID(0) < 0) {
805 * If unspecified, use default visual instead of waiting
806 * for wrlib/context.c:bestContext() that may end up choosing
807 * the "fake" 24 bits added by the Composite extension.
808 * This is required to avoid all sort of corruptions when
809 * composite is enabled, and at a depth other than 24.
811 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
814 /* check if the user specified a complete display name (with screen).
815 * If so, only manage the specified screen */
816 if (DisplayName)
817 pos = strchr(DisplayName, ':');
818 else
819 pos = NULL;
821 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
822 multiHead = False;
824 DisplayName = XDisplayName(DisplayName);
825 setenv("DISPLAY", DisplayName, 1);
827 wXModifierInitialize();
828 StartUp(!multiHead);
830 if (wScreenCount == 1)
831 multiHead = False;
833 execInitScript();
834 #ifdef HAVE_INOTIFY
835 inotifyWatchConfig();
836 #endif
837 EventLoop();
838 return -1;