New header file event.h
[wmaker-crm.git] / src / main.c
blob11cbded1c2f3eb8a50984f77ac8d35b088199324
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 "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"
59 #include <WINGs/WUtil.h>
61 #ifndef GLOBAL_DEFAULTS_SUBDIR
62 #define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
63 #endif
65 /****** Global Variables ******/
67 /* general info */
69 Display *dpy;
71 char *ProgName;
73 unsigned int ValidModMask = 0xff;
75 #ifdef HAVE_INOTIFY
76 int inotifyFD;
77 int inotifyWD;
78 #endif
79 /* locale to use. NULL==POSIX or C */
80 char *Locale = NULL;
82 int wScreenCount = 0;
84 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 /* cursors */
129 Cursor wCursor[WCUR_LAST];
131 /* last event timestamp for XSetInputFocus */
132 Time LastTimestamp = CurrentTime;
133 /* timestamp on the last time we did XSetInputFocus() */
134 Time LastFocusChange = CurrentTime;
136 #ifdef SHAPE
137 Bool wShapeSupported;
138 int wShapeEventBase;
139 #endif
141 #ifdef KEEP_XKB_LOCK_STATUS
142 Bool wXkbSupported;
143 int wXkbEventBase;
144 #endif
146 /* special flags */
147 char WProgramSigState = 0;
148 char WProgramState = WSTATE_NORMAL;
149 char WDelayedActionSet = 0;
151 /* notifications */
152 const char *WMNManaged = "WMNManaged";
153 const char *WMNUnmanaged = "WMNUnmanaged";
154 const char *WMNChangedWorkspace = "WMNChangedWorkspace";
155 const char *WMNChangedState = "WMNChangedState";
156 const char *WMNChangedFocus = "WMNChangedFocus";
157 const char *WMNChangedStacking = "WMNChangedStacking";
158 const char *WMNChangedName = "WMNChangedName";
160 const char *WMNWorkspaceCreated = "WMNWorkspaceCreated";
161 const char *WMNWorkspaceDestroyed = "WMNWorkspaceDestroyed";
162 const char *WMNWorkspaceChanged = "WMNWorkspaceChanged";
163 const char *WMNWorkspaceNameChanged = "WMNWorkspaceNameChanged";
165 const char *WMNResetStacking = "WMNResetStacking";
167 /******** End Global Variables *****/
169 static char *DisplayName = NULL;
171 static char **Arguments;
173 static int ArgCount;
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 werror(_("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 werror("could not execute %s -c %s", shell, command);
383 Exit(-1);
384 } else if (pid < 0) {
385 werror("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 * RelaunchWindow--
399 * Launch a new instance of the active window
401 *----------------------------------------------------------------------
403 Bool RelaunchWindow(WWindow *wwin)
405 if (! wwin || ! wwin->client_win) {
406 werror("no window to relaunch");
407 return False;
410 char **argv;
411 int argc;
413 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
414 werror("cannot relaunch the application because no WM_COMMAND property is set");
415 return False;
418 pid_t pid = fork();
420 if (pid == 0) {
421 SetupEnvironment(wwin->screen_ptr);
422 #ifdef HAVE_SETSID
423 setsid();
424 #endif
425 /* argv is not null-terminated */
426 char **a = (char **) malloc(argc + 1);
427 if (! a) {
428 werror("out of memory trying to relaunch the application");
429 Exit(-1);
432 int i;
433 for (i = 0; i < argc; i++)
434 a[i] = argv[i];
435 a[i] = NULL;
437 execvp(a[0], a);
438 Exit(-1);
439 } else if (pid < 0) {
440 werror("cannot fork a new process");
442 XFreeStringList(argv);
443 return False;
444 } else {
445 _tuple *data = wmalloc(sizeof(_tuple));
447 data->scr = wwin->screen_ptr;
448 data->command = wtokenjoin(argv, argc);
450 /* not actually a shell command */
451 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
453 XFreeStringList(argv);
456 return True;
460 *---------------------------------------------------------------------
461 * wAbort--
462 * Do a major cleanup and exit the program
464 *----------------------------------------------------------------------
466 void wAbort(Bool dumpCore)
468 int i;
469 WScreen *scr;
471 for (i = 0; i < wScreenCount; i++) {
472 scr = wScreenWithNumber(i);
473 if (scr)
474 RestoreDesktop(scr);
476 printf(_("%s aborted.\n"), ProgName);
477 if (dumpCore)
478 abort();
479 else
480 exit(1);
483 static void print_help(void)
485 printf(_("Usage: %s [options]\n"), ProgName);
486 puts(_("The Window Maker window manager for the X window system"));
487 puts("");
488 puts(_(" -display host:dpy display to use"));
489 puts(_(" --no-dock do not open the application Dock"));
490 puts(_(" --no-clip do not open the workspace Clip"));
491 puts(_(" --no-autolaunch do not autolaunch applications"));
492 puts(_(" --dont-restore do not restore saved session"));
494 puts(_(" --locale locale locale to use"));
496 puts(_(" --visual-id visualid visual id of visual to use"));
497 puts(_(" --static do not update or save configurations"));
498 #ifndef HAVE_INOTIFY
499 puts(_(" --no-polling do not periodically check for configuration updates"));
500 #endif
501 puts(_(" --version print version and exit"));
502 puts(_(" --help show this message"));
505 static void check_defaults(void)
507 char *path;
509 path = wdefaultspathfordomain("WindowMaker");
511 if (access(path, R_OK) != 0) {
512 wwarning(_("could not find user GNUstep directory (%s)."), path);
514 if (system("wmaker.inst --batch") != 0) {
515 wwarning(_("There was an error while creating GNUstep directory, please "
516 "make sure you have installed Window Maker correctly and run wmaker.inst"));
517 } else {
518 wwarning(_("%s directory created with default configuration."), path);
522 wfree(path);
525 #ifdef HAVE_INOTIFY
527 * Add watch here, used to notify if configuration
528 * files have changed, using linux kernel inotify mechanism
531 static void inotifyWatchConfig(void)
533 char *watchPath = NULL;
534 inotifyFD = inotify_init(); /* Initialise an inotify instance */
535 if (inotifyFD < 0) {
536 wwarning(_("could not initialise an inotify instance."
537 " Changes to the defaults database will require"
538 " a restart to take effect. Check your kernel!"));
539 } else {
540 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
541 /* Add the watch; really we are only looking for modify events
542 * but we might want more in the future so check all events for now.
543 * The individual events are checked for in event.c.
545 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
546 if (inotifyWD < 0) {
547 wwarning(_("could not add an inotify watch on path %s."
548 "Changes to the defaults database will require"
549 " a restart to take effect."), watchPath);
550 close(inotifyFD);
553 wfree(watchPath);
555 #endif /* HAVE_INOTIFY */
557 static void execInitScript(void)
559 char *file, *paths;
561 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
562 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
564 file = wfindfile(paths, DEF_INIT_SCRIPT);
565 wfree(paths);
567 if (file) {
568 if (system(file) != 0)
569 werror(_("%s:could not execute initialization script"), file);
571 wfree(file);
575 void ExecExitScript(void)
577 char *file, *paths;
579 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
580 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
582 file = wfindfile(paths, DEF_EXIT_SCRIPT);
583 wfree(paths);
585 if (file) {
586 if (system(file) != 0)
587 werror(_("%s:could not execute exit script"), file);
589 wfree(file);
593 int main(int argc, char **argv)
595 int i_am_the_monitor, i, len;
596 char *str, *alt;
598 /* setup common stuff for the monitor and wmaker itself */
599 WMInitializeApplication("WindowMaker", &argc, argv);
601 memset(&wPreferences, 0, sizeof(WPreferences));
603 wPreferences.fallbackWMs = WMCreateArray(8);
604 alt = getenv("WINDOWMAKER_ALT_WM");
605 if (alt != NULL)
606 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
608 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
609 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
611 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
612 WMAddToArray(wPreferences.fallbackWMs, NULL);
613 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
614 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
616 i_am_the_monitor = 1;
618 for (i = 1; i < argc; i++) {
619 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
620 i_am_the_monitor = 0;
621 break;
622 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
623 i++;
624 if (i >= argc) {
625 wwarning(_("too few arguments for %s"), argv[i - 1]);
626 exit(0);
628 DisplayName = argv[i];
632 DisplayName = XDisplayName(DisplayName);
633 len = strlen(DisplayName) + 64;
634 str = wmalloc(len);
635 snprintf(str, len, "DISPLAY=%s", DisplayName);
636 putenv(str);
638 if (i_am_the_monitor)
639 return MonitorLoop(argc, argv);
640 else
641 return real_main(argc, argv);
644 static int real_main(int argc, char **argv)
646 int i;
647 char *pos;
648 int d, s;
650 setlocale(LC_ALL, "");
651 wsetabort(wAbort);
653 /* for telling WPrefs what's the name of the wmaker binary being ran */
654 setenv("WMAKER_BIN_NAME", argv[0], 1);
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 if (argc > 1) {
672 for (i = 1; i < argc; i++) {
673 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
674 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
675 } else if (strcmp(argv[i], "--for-real") == 0) {
676 wPreferences.flags.restarting = 0;
677 } else if (strcmp(argv[i], "--for-real=") == 0) {
678 wPreferences.flags.restarting = 1;
679 } else if (strcmp(argv[i], "--for-real-") == 0) {
680 wPreferences.flags.restarting = 2;
681 } else if (strcmp(argv[i], "-no-autolaunch") == 0
682 || strcmp(argv[i], "--no-autolaunch") == 0) {
683 wPreferences.flags.noautolaunch = 1;
684 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
685 wPreferences.flags.norestore = 1;
686 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
687 wPreferences.flags.nodock = 1;
688 wPreferences.flags.nodrawer = 1;
689 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
690 wPreferences.flags.noclip = 1;
691 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
692 wPreferences.flags.nodrawer = 1;
693 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
694 printf("Window Maker %s\n", VERSION);
695 exit(0);
696 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
697 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
698 exit(0);
699 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
700 i++;
701 if (i >= argc) {
702 wwarning(_("too few arguments for %s"), argv[i - 1]);
703 exit(0);
705 Locale = argv[i];
706 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
707 i++;
708 if (i >= argc) {
709 wwarning(_("too few arguments for %s"), argv[i - 1]);
710 exit(0);
712 DisplayName = argv[i];
713 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
714 i++;
715 if (i >= argc) {
716 wwarning(_("too few arguments for %s"), argv[i - 1]);
717 exit(0);
719 if (initWVisualID(argv[i]) != 0) {
720 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
721 exit(0);
723 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
724 #ifndef HAVE_INOTIFY
725 || strcmp(argv[i], "--no-polling") == 0
726 #endif
728 wPreferences.flags.noupdates = 1;
729 } else if (strcmp(argv[i], "--help") == 0) {
730 print_help();
731 exit(0);
732 } else {
733 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
734 printf(_("Try '%s --help' for more information\n"), argv[0]);
735 exit(1);
740 if (!wPreferences.flags.noupdates) {
741 /* check existence of Defaults DB directory */
742 check_defaults();
745 if (Locale) {
746 setenv("LANG", Locale, 1);
747 } else {
748 Locale = getenv("LC_ALL");
749 if (!Locale) {
750 Locale = getenv("LANG");
754 setlocale(LC_ALL, "");
756 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
757 Locale = NULL;
758 #ifdef I18N
759 if (getenv("NLSPATH")) {
760 bindtextdomain("WindowMaker", getenv("NLSPATH"));
761 #if defined(MENU_TEXTDOMAIN)
762 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
763 #endif
764 } else {
765 bindtextdomain("WindowMaker", LOCALEDIR);
766 #if defined(MENU_TEXTDOMAIN)
767 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
768 #endif
770 bind_textdomain_codeset("WindowMaker", "UTF-8");
771 #if defined(MENU_TEXTDOMAIN)
772 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
773 #endif
774 textdomain("WindowMaker");
776 if (!XSupportsLocale()) {
777 wwarning(_("X server does not support locale"));
780 if (XSetLocaleModifiers("") == NULL) {
781 wwarning(_("cannot set locale modifiers"));
783 #endif
785 if (Locale) {
786 char *ptr;
788 Locale = wstrdup(Locale);
789 ptr = strchr(Locale, '.');
790 if (ptr)
791 *ptr = 0;
794 /* open display */
795 dpy = XOpenDisplay(DisplayName);
796 if (dpy == NULL) {
797 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
798 exit(1);
801 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
802 werror("error setting close-on-exec flag for X connection");
803 exit(1);
807 if (getWVisualID(0) < 0) {
809 * If unspecified, use default visual instead of waiting
810 * for wrlib/context.c:bestContext() that may end up choosing
811 * the "fake" 24 bits added by the Composite extension.
812 * This is required to avoid all sort of corruptions when
813 * composite is enabled, and at a depth other than 24.
815 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
818 /* check if the user specified a complete display name (with screen).
819 * If so, only manage the specified screen */
820 if (DisplayName)
821 pos = strchr(DisplayName, ':');
822 else
823 pos = NULL;
825 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
826 multiHead = False;
828 DisplayName = XDisplayName(DisplayName);
829 setenv("DISPLAY", DisplayName, 1);
831 wXModifierInitialize();
832 StartUp(!multiHead);
834 if (wScreenCount == 1)
835 multiHead = False;
837 execInitScript();
838 #ifdef HAVE_INOTIFY
839 inotifyWatchConfig();
840 #endif
841 EventLoop();
842 return -1;