wmaker: Replaced local 'extern' definition of wPreferences by proper header usage
[wmaker-crm.git] / src / main.c
blob199033e73e043a199d9a16f877e9054e3959bbcf
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 ******/
68 /* general info */
70 Display *dpy;
72 char *ProgName;
74 unsigned int ValidModMask = 0xff;
76 #ifdef HAVE_INOTIFY
77 int inotifyFD;
78 int inotifyWD;
79 #endif
80 /* locale to use. NULL==POSIX or C */
81 char *Locale = NULL;
83 int wScreenCount = 0;
85 struct WPreferences wPreferences;
87 WShortKey wKeyBindings[WKBD_LAST];
89 /* defaults domains */
90 WDDomain *WDWindowMaker = NULL;
91 WDDomain *WDWindowAttributes = NULL;
92 WDDomain *WDRootMenu = NULL;
94 /* XContexts */
95 XContext wWinContext;
96 XContext wAppWinContext;
97 XContext wStackContext;
98 XContext wVEdgeContext;
100 /* Atoms */
101 Atom _XA_WM_STATE;
102 Atom _XA_WM_CHANGE_STATE;
103 Atom _XA_WM_PROTOCOLS;
104 Atom _XA_WM_TAKE_FOCUS;
105 Atom _XA_WM_DELETE_WINDOW;
106 Atom _XA_WM_SAVE_YOURSELF;
107 Atom _XA_WM_CLIENT_LEADER;
108 Atom _XA_WM_COLORMAP_WINDOWS;
109 Atom _XA_WM_COLORMAP_NOTIFY;
111 Atom _XA_GNUSTEP_WM_ATTR;
112 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW;
113 Atom _XA_GNUSTEP_WM_RESIZEBAR;
114 Atom _XA_GNUSTEP_TITLEBAR_STATE;
116 Atom _XA_WINDOWMAKER_MENU;
117 Atom _XA_WINDOWMAKER_WM_PROTOCOLS;
118 Atom _XA_WINDOWMAKER_STATE;
120 Atom _XA_WINDOWMAKER_WM_FUNCTION;
121 Atom _XA_WINDOWMAKER_NOTICEBOARD;
122 Atom _XA_WINDOWMAKER_COMMAND;
124 Atom _XA_WINDOWMAKER_ICON_SIZE;
125 Atom _XA_WINDOWMAKER_ICON_TILE;
127 Atom _XA_WM_IGNORE_FOCUS_EVENTS;
129 /* cursors */
130 Cursor wCursor[WCUR_LAST];
132 /* last event timestamp for XSetInputFocus */
133 Time LastTimestamp = CurrentTime;
134 /* timestamp on the last time we did XSetInputFocus() */
135 Time LastFocusChange = CurrentTime;
137 #ifdef SHAPE
138 Bool wShapeSupported;
139 int wShapeEventBase;
140 #endif
142 #ifdef KEEP_XKB_LOCK_STATUS
143 Bool wXkbSupported;
144 int wXkbEventBase;
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 static Bool multiHead = True;
178 static int *wVisualID = NULL;
179 static int wVisualID_len = 0;
181 static int real_main(int argc, char **argv);
183 int getWVisualID(int screen)
185 if (wVisualID == NULL)
186 return -1;
187 if (screen < 0 || screen >= wVisualID_len)
188 return -1;
190 return wVisualID[screen];
193 static void setWVisualID(int screen, int val)
195 int i;
197 if (screen < 0)
198 return;
200 if (wVisualID == NULL) {
201 /* no array at all, alloc space for screen + 1 entries
202 * and init with default value */
203 wVisualID_len = screen + 1;
204 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
205 for (i = 0; i < wVisualID_len; i++) {
206 wVisualID[i] = -1;
208 } else if (screen >= wVisualID_len) {
209 /* larger screen number than previously allocated
210 so enlarge array */
211 int oldlen = wVisualID_len;
213 wVisualID_len = screen + 1;
214 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
215 for (i = oldlen; i < wVisualID_len; i++) {
216 wVisualID[i] = -1;
220 wVisualID[screen] = val;
224 * this function splits a given string at the comma into tokens
225 * and set the wVisualID variable to each parsed number
227 static int initWVisualID(const char *user_str)
229 char *mystr = strdup(user_str);
230 int cur_in_pos = 0;
231 int cur_out_pos = 0;
232 int cur_screen = 0;
233 int error_found = 0;
235 for (;;) {
236 /* check for delimiter */
237 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
238 int v;
240 mystr[cur_out_pos] = '\0';
242 if (sscanf(mystr, "%i", &v) != 1) {
243 error_found = 1;
244 break;
247 setWVisualID(cur_screen, v);
249 cur_screen++;
250 cur_out_pos = 0;
253 /* break in case last char has been consumed */
254 if (user_str[cur_in_pos] == '\0')
255 break;
257 /* if the current char is no delimiter put it into mystr */
258 if (user_str[cur_in_pos] != ',') {
259 mystr[cur_out_pos++] = user_str[cur_in_pos];
261 cur_in_pos++;
264 free(mystr);
266 if (cur_screen == 0||error_found != 0)
267 return 1;
269 return 0;
272 noreturn void Exit(int status)
274 if (dpy)
275 XCloseDisplay(dpy);
277 exit(status);
280 void Restart(char *manager, Bool abortOnFailure)
282 char *prog = NULL;
283 char *argv[MAX_RESTART_ARGS];
284 int i;
286 if (manager && manager[0] != 0) {
287 prog = argv[0] = strtok(manager, " ");
288 for (i = 1; i < MAX_RESTART_ARGS; i++) {
289 argv[i] = strtok(NULL, " ");
290 if (argv[i] == NULL) {
291 break;
295 if (dpy) {
296 XCloseDisplay(dpy);
297 dpy = NULL;
299 if (!prog) {
300 execvp(Arguments[0], Arguments);
301 wfatal(_("failed to restart Window Maker."));
302 } else {
303 execvp(prog, argv);
304 werror(_("could not exec %s"), prog);
306 if (abortOnFailure)
307 exit(7);
310 void SetupEnvironment(WScreen * scr)
312 char *tmp, *ptr;
313 char buf[16];
315 if (multiHead) {
316 int len = strlen(DisplayName) + 64;
317 tmp = wmalloc(len);
318 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
319 ptr = strchr(strchr(tmp, ':'), '.');
320 if (ptr)
321 *ptr = 0;
322 snprintf(buf, sizeof(buf), ".%i", scr->screen);
323 strcat(tmp, buf);
324 putenv(tmp);
326 tmp = wmalloc(60);
327 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
328 scr->rcontext->attribs->colors_per_channel);
329 putenv(tmp);
332 typedef struct {
333 WScreen *scr;
334 char *command;
335 } _tuple;
337 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
339 if (status == 127) {
340 char *buffer;
342 buffer = wstrconcat(_("Could not execute command: "), data->command);
344 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
345 wfree(buffer);
346 } else if (status != 127) {
348 printf("%s: %i\n", data->command, status);
352 wfree(data->command);
353 wfree(data);
356 void ExecuteShellCommand(WScreen *scr, const char *command)
358 static char *shell = NULL;
359 pid_t pid;
362 * This have a problem: if the shell is tcsh (not sure about others)
363 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
364 * will block and the command will not be executed.
365 if (!shell) {
366 shell = getenv("SHELL");
367 if (!shell)
368 shell = "/bin/sh";
371 shell = "/bin/sh";
373 pid = fork();
375 if (pid == 0) {
377 SetupEnvironment(scr);
379 #ifdef HAVE_SETSID
380 setsid();
381 #endif
382 execl(shell, shell, "-c", command, NULL);
383 werror("could not execute %s -c %s", shell, command);
384 Exit(-1);
385 } else if (pid < 0) {
386 werror("cannot fork a new process");
387 } else {
388 _tuple *data = wmalloc(sizeof(_tuple));
390 data->scr = scr;
391 data->command = wstrdup(command);
393 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
398 *---------------------------------------------------------------------
399 * RelaunchWindow--
400 * Launch a new instance of the active window
402 *----------------------------------------------------------------------
404 Bool RelaunchWindow(WWindow *wwin)
406 if (! wwin || ! wwin->client_win) {
407 werror("no window to relaunch");
408 return False;
411 char **argv;
412 int argc;
414 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
415 werror("cannot relaunch the application because no WM_COMMAND property is set");
416 return False;
419 pid_t pid = fork();
421 if (pid == 0) {
422 SetupEnvironment(wwin->screen_ptr);
423 #ifdef HAVE_SETSID
424 setsid();
425 #endif
426 /* argv is not null-terminated */
427 char **a = (char **) malloc(argc + 1);
428 if (! a) {
429 werror("out of memory trying to relaunch the application");
430 Exit(-1);
433 int i;
434 for (i = 0; i < argc; i++)
435 a[i] = argv[i];
436 a[i] = NULL;
438 execvp(a[0], a);
439 Exit(-1);
440 } else if (pid < 0) {
441 werror("cannot fork a new process");
443 XFreeStringList(argv);
444 return False;
445 } else {
446 _tuple *data = wmalloc(sizeof(_tuple));
448 data->scr = wwin->screen_ptr;
449 data->command = wtokenjoin(argv, argc);
451 /* not actually a shell command */
452 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
454 XFreeStringList(argv);
457 return True;
461 *---------------------------------------------------------------------
462 * wAbort--
463 * Do a major cleanup and exit the program
465 *----------------------------------------------------------------------
467 noreturn void wAbort(Bool dumpCore)
469 int i;
470 WScreen *scr;
472 for (i = 0; i < wScreenCount; i++) {
473 scr = wScreenWithNumber(i);
474 if (scr)
475 RestoreDesktop(scr);
477 printf(_("%s aborted.\n"), ProgName);
478 if (dumpCore)
479 abort();
480 else
481 exit(1);
484 static void print_help(void)
486 printf(_("Usage: %s [options]\n"), ProgName);
487 puts(_("The Window Maker window manager for the X window system"));
488 puts("");
489 puts(_(" -display host:dpy display to use"));
490 puts(_(" --no-dock do not open the application Dock"));
491 puts(_(" --no-clip do not open the workspace Clip"));
492 puts(_(" --no-autolaunch do not autolaunch applications"));
493 puts(_(" --dont-restore do not restore saved session"));
495 puts(_(" --locale locale locale to use"));
497 puts(_(" --visual-id visualid visual id of visual to use"));
498 puts(_(" --static do not update or save configurations"));
499 #ifndef HAVE_INOTIFY
500 puts(_(" --no-polling do not periodically check for configuration updates"));
501 #endif
502 puts(_(" --version print version and exit"));
503 puts(_(" --help show this message"));
506 static void check_defaults(void)
508 char *path;
510 path = wdefaultspathfordomain("WindowMaker");
512 if (access(path, R_OK) != 0) {
513 wwarning(_("could not find user GNUstep directory (%s)."), path);
515 if (system("wmaker.inst --batch") != 0) {
516 wwarning(_("There was an error while creating GNUstep directory, please "
517 "make sure you have installed Window Maker correctly and run wmaker.inst"));
518 } else {
519 wwarning(_("%s directory created with default configuration."), path);
523 wfree(path);
526 #ifdef HAVE_INOTIFY
528 * Add watch here, used to notify if configuration
529 * files have changed, using linux kernel inotify mechanism
532 static void inotifyWatchConfig(void)
534 char *watchPath = NULL;
535 inotifyFD = inotify_init(); /* Initialise an inotify instance */
536 if (inotifyFD < 0) {
537 wwarning(_("could not initialise an inotify instance."
538 " Changes to the defaults database will require"
539 " a restart to take effect. Check your kernel!"));
540 } else {
541 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
542 /* Add the watch; really we are only looking for modify events
543 * but we might want more in the future so check all events for now.
544 * The individual events are checked for in event.c.
546 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
547 if (inotifyWD < 0) {
548 wwarning(_("could not add an inotify watch on path %s."
549 "Changes to the defaults database will require"
550 " a restart to take effect."), watchPath);
551 close(inotifyFD);
554 wfree(watchPath);
556 #endif /* HAVE_INOTIFY */
558 static void execInitScript(void)
560 char *file, *paths;
562 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
563 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
565 file = wfindfile(paths, DEF_INIT_SCRIPT);
566 wfree(paths);
568 if (file) {
569 if (system(file) != 0)
570 werror(_("%s:could not execute initialization script"), file);
572 wfree(file);
576 void ExecExitScript(void)
578 char *file, *paths;
580 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
581 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
583 file = wfindfile(paths, DEF_EXIT_SCRIPT);
584 wfree(paths);
586 if (file) {
587 if (system(file) != 0)
588 werror(_("%s:could not execute exit script"), file);
590 wfree(file);
594 int main(int argc, char **argv)
596 int i_am_the_monitor, i, len;
597 char *str, *alt;
599 /* setup common stuff for the monitor and wmaker itself */
600 WMInitializeApplication("WindowMaker", &argc, argv);
602 memset(&wPreferences, 0, sizeof(wPreferences));
604 wPreferences.fallbackWMs = WMCreateArray(8);
605 alt = getenv("WINDOWMAKER_ALT_WM");
606 if (alt != NULL)
607 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
609 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
611 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
612 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
613 WMAddToArray(wPreferences.fallbackWMs, NULL);
614 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
615 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
617 i_am_the_monitor = 1;
619 for (i = 1; i < argc; i++) {
620 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
621 i_am_the_monitor = 0;
622 break;
623 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
624 i++;
625 if (i >= argc) {
626 wwarning(_("too few arguments for %s"), argv[i - 1]);
627 exit(0);
629 DisplayName = argv[i];
633 DisplayName = XDisplayName(DisplayName);
634 len = strlen(DisplayName) + 64;
635 str = wmalloc(len);
636 snprintf(str, len, "DISPLAY=%s", DisplayName);
637 putenv(str);
639 if (i_am_the_monitor)
640 return MonitorLoop(argc, argv);
641 else
642 return real_main(argc, argv);
645 static int real_main(int argc, char **argv)
647 int i;
648 char *pos;
649 int d, s;
651 setlocale(LC_ALL, "");
652 wsetabort(wAbort);
654 /* for telling WPrefs what's the name of the wmaker binary being ran */
655 setenv("WMAKER_BIN_NAME", argv[0], 1);
657 ArgCount = argc;
658 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
659 for (i = 0; i < argc; i++) {
660 Arguments[i] = argv[i];
662 /* add the extra option to signal that we're just restarting wmaker */
663 Arguments[argc - 1] = "--for-real=";
664 Arguments[argc] = NULL;
666 ProgName = strrchr(argv[0], '/');
667 if (!ProgName)
668 ProgName = argv[0];
669 else
670 ProgName++;
672 if (argc > 1) {
673 for (i = 1; i < argc; i++) {
674 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
675 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
676 } else if (strcmp(argv[i], "--for-real") == 0) {
677 wPreferences.flags.restarting = 0;
678 } else if (strcmp(argv[i], "--for-real=") == 0) {
679 wPreferences.flags.restarting = 1;
680 } else if (strcmp(argv[i], "--for-real-") == 0) {
681 wPreferences.flags.restarting = 2;
682 } else if (strcmp(argv[i], "-no-autolaunch") == 0
683 || strcmp(argv[i], "--no-autolaunch") == 0) {
684 wPreferences.flags.noautolaunch = 1;
685 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
686 wPreferences.flags.norestore = 1;
687 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
688 wPreferences.flags.nodock = 1;
689 wPreferences.flags.nodrawer = 1;
690 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
691 wPreferences.flags.noclip = 1;
692 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
693 wPreferences.flags.nodrawer = 1;
694 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
695 printf("Window Maker %s\n", VERSION);
696 exit(0);
697 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
698 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
699 exit(0);
700 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
701 i++;
702 if (i >= argc) {
703 wwarning(_("too few arguments for %s"), argv[i - 1]);
704 exit(0);
706 Locale = argv[i];
707 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
708 i++;
709 if (i >= argc) {
710 wwarning(_("too few arguments for %s"), argv[i - 1]);
711 exit(0);
713 DisplayName = argv[i];
714 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
715 i++;
716 if (i >= argc) {
717 wwarning(_("too few arguments for %s"), argv[i - 1]);
718 exit(0);
720 if (initWVisualID(argv[i]) != 0) {
721 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
722 exit(0);
724 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
725 #ifndef HAVE_INOTIFY
726 || strcmp(argv[i], "--no-polling") == 0
727 #endif
729 wPreferences.flags.noupdates = 1;
730 } else if (strcmp(argv[i], "--help") == 0) {
731 print_help();
732 exit(0);
733 } else {
734 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
735 printf(_("Try '%s --help' for more information\n"), argv[0]);
736 exit(1);
741 if (!wPreferences.flags.noupdates) {
742 /* check existence of Defaults DB directory */
743 check_defaults();
746 if (Locale) {
747 setenv("LANG", Locale, 1);
748 } else {
749 Locale = getenv("LC_ALL");
750 if (!Locale) {
751 Locale = getenv("LANG");
755 setlocale(LC_ALL, "");
757 if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
758 Locale = NULL;
759 #ifdef I18N
760 if (getenv("NLSPATH")) {
761 bindtextdomain("WindowMaker", getenv("NLSPATH"));
762 #if defined(MENU_TEXTDOMAIN)
763 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
764 #endif
765 } else {
766 bindtextdomain("WindowMaker", LOCALEDIR);
767 #if defined(MENU_TEXTDOMAIN)
768 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
769 #endif
771 bind_textdomain_codeset("WindowMaker", "UTF-8");
772 #if defined(MENU_TEXTDOMAIN)
773 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
774 #endif
775 textdomain("WindowMaker");
777 if (!XSupportsLocale()) {
778 wwarning(_("X server does not support locale"));
781 if (XSetLocaleModifiers("") == NULL) {
782 wwarning(_("cannot set locale modifiers"));
784 #endif
786 if (Locale) {
787 char *ptr;
789 Locale = wstrdup(Locale);
790 ptr = strchr(Locale, '.');
791 if (ptr)
792 *ptr = 0;
795 /* open display */
796 dpy = XOpenDisplay(DisplayName);
797 if (dpy == NULL) {
798 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
799 exit(1);
802 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
803 werror("error setting close-on-exec flag for X connection");
804 exit(1);
808 if (getWVisualID(0) < 0) {
810 * If unspecified, use default visual instead of waiting
811 * for wrlib/context.c:bestContext() that may end up choosing
812 * the "fake" 24 bits added by the Composite extension.
813 * This is required to avoid all sort of corruptions when
814 * composite is enabled, and at a depth other than 24.
816 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
819 /* check if the user specified a complete display name (with screen).
820 * If so, only manage the specified screen */
821 if (DisplayName)
822 pos = strchr(DisplayName, ':');
823 else
824 pos = NULL;
826 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
827 multiHead = False;
829 DisplayName = XDisplayName(DisplayName);
830 setenv("DISPLAY", DisplayName, 1);
832 wXModifierInitialize();
833 StartUp(!multiHead);
835 if (wScreenCount == 1)
836 multiHead = False;
838 execInitScript();
839 #ifdef HAVE_INOTIFY
840 inotifyWatchConfig();
841 #endif
842 EventLoop();
843 return -1;