wmaker: Moved the variable for Locale choice (I18N) to the global variable structure
[wmaker-crm.git] / src / main.c
blobc7c8d40769681f53b8dd98be496091332cb93ffe
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 /* 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 WDelayedActionSet = 0;
149 /* notifications */
150 const char WMNManaged[] = "WMNManaged";
151 const char WMNUnmanaged[] = "WMNUnmanaged";
152 const char WMNChangedWorkspace[] = "WMNChangedWorkspace";
153 const char WMNChangedState[] = "WMNChangedState";
154 const char WMNChangedFocus[] = "WMNChangedFocus";
155 const char WMNChangedStacking[] = "WMNChangedStacking";
156 const char WMNChangedName[] = "WMNChangedName";
158 const char WMNWorkspaceCreated[] = "WMNWorkspaceCreated";
159 const char WMNWorkspaceDestroyed[] = "WMNWorkspaceDestroyed";
160 const char WMNWorkspaceChanged[] = "WMNWorkspaceChanged";
161 const char WMNWorkspaceNameChanged[] = "WMNWorkspaceNameChanged";
163 const char WMNResetStacking[] = "WMNResetStacking";
165 /******** End Global Variables *****/
167 static char *DisplayName = NULL;
169 static char **Arguments;
171 static int ArgCount;
173 static Bool multiHead = True;
175 static int *wVisualID = NULL;
176 static int wVisualID_len = 0;
178 static int real_main(int argc, char **argv);
180 int getWVisualID(int screen)
182 if (wVisualID == NULL)
183 return -1;
184 if (screen < 0 || screen >= wVisualID_len)
185 return -1;
187 return wVisualID[screen];
190 static void setWVisualID(int screen, int val)
192 int i;
194 if (screen < 0)
195 return;
197 if (wVisualID == NULL) {
198 /* no array at all, alloc space for screen + 1 entries
199 * and init with default value */
200 wVisualID_len = screen + 1;
201 wVisualID = (int *)malloc(wVisualID_len * sizeof(int));
202 for (i = 0; i < wVisualID_len; i++) {
203 wVisualID[i] = -1;
205 } else if (screen >= wVisualID_len) {
206 /* larger screen number than previously allocated
207 so enlarge array */
208 int oldlen = wVisualID_len;
210 wVisualID_len = screen + 1;
211 wVisualID = (int *)realloc(wVisualID, wVisualID_len * sizeof(int));
212 for (i = oldlen; i < wVisualID_len; i++) {
213 wVisualID[i] = -1;
217 wVisualID[screen] = val;
221 * this function splits a given string at the comma into tokens
222 * and set the wVisualID variable to each parsed number
224 static int initWVisualID(const char *user_str)
226 char *mystr = strdup(user_str);
227 int cur_in_pos = 0;
228 int cur_out_pos = 0;
229 int cur_screen = 0;
230 int error_found = 0;
232 for (;;) {
233 /* check for delimiter */
234 if (user_str[cur_in_pos] == '\0' || user_str[cur_in_pos] == ',') {
235 int v;
237 mystr[cur_out_pos] = '\0';
239 if (sscanf(mystr, "%i", &v) != 1) {
240 error_found = 1;
241 break;
244 setWVisualID(cur_screen, v);
246 cur_screen++;
247 cur_out_pos = 0;
250 /* break in case last char has been consumed */
251 if (user_str[cur_in_pos] == '\0')
252 break;
254 /* if the current char is no delimiter put it into mystr */
255 if (user_str[cur_in_pos] != ',') {
256 mystr[cur_out_pos++] = user_str[cur_in_pos];
258 cur_in_pos++;
261 free(mystr);
263 if (cur_screen == 0||error_found != 0)
264 return 1;
266 return 0;
269 noreturn void Exit(int status)
271 if (dpy)
272 XCloseDisplay(dpy);
274 exit(status);
277 void Restart(char *manager, Bool abortOnFailure)
279 char *prog = NULL;
280 char *argv[MAX_RESTART_ARGS];
281 int i;
283 if (manager && manager[0] != 0) {
284 prog = argv[0] = strtok(manager, " ");
285 for (i = 1; i < MAX_RESTART_ARGS; i++) {
286 argv[i] = strtok(NULL, " ");
287 if (argv[i] == NULL) {
288 break;
292 if (dpy) {
293 XCloseDisplay(dpy);
294 dpy = NULL;
296 if (!prog) {
297 execvp(Arguments[0], Arguments);
298 wfatal(_("failed to restart Window Maker."));
299 } else {
300 execvp(prog, argv);
301 werror(_("could not exec %s"), prog);
303 if (abortOnFailure)
304 exit(7);
307 void SetupEnvironment(WScreen * scr)
309 char *tmp, *ptr;
310 char buf[16];
312 if (multiHead) {
313 int len = strlen(DisplayName) + 64;
314 tmp = wmalloc(len);
315 snprintf(tmp, len, "DISPLAY=%s", XDisplayName(DisplayName));
316 ptr = strchr(strchr(tmp, ':'), '.');
317 if (ptr)
318 *ptr = 0;
319 snprintf(buf, sizeof(buf), ".%i", scr->screen);
320 strcat(tmp, buf);
321 putenv(tmp);
323 tmp = wmalloc(60);
324 snprintf(tmp, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr->screen,
325 scr->rcontext->attribs->colors_per_channel);
326 putenv(tmp);
329 typedef struct {
330 WScreen *scr;
331 char *command;
332 } _tuple;
334 static void shellCommandHandler(pid_t pid, unsigned char status, _tuple * data)
336 if (status == 127) {
337 char *buffer;
339 buffer = wstrconcat(_("Could not execute command: "), data->command);
341 wMessageDialog(data->scr, _("Error"), buffer, _("OK"), NULL, NULL);
342 wfree(buffer);
343 } else if (status != 127) {
345 printf("%s: %i\n", data->command, status);
349 wfree(data->command);
350 wfree(data);
353 void ExecuteShellCommand(WScreen *scr, const char *command)
355 static char *shell = NULL;
356 pid_t pid;
359 * This have a problem: if the shell is tcsh (not sure about others)
360 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
361 * will block and the command will not be executed.
362 if (!shell) {
363 shell = getenv("SHELL");
364 if (!shell)
365 shell = "/bin/sh";
368 shell = "/bin/sh";
370 pid = fork();
372 if (pid == 0) {
374 SetupEnvironment(scr);
376 #ifdef HAVE_SETSID
377 setsid();
378 #endif
379 execl(shell, shell, "-c", command, NULL);
380 werror("could not execute %s -c %s", shell, command);
381 Exit(-1);
382 } else if (pid < 0) {
383 werror("cannot fork a new process");
384 } else {
385 _tuple *data = wmalloc(sizeof(_tuple));
387 data->scr = scr;
388 data->command = wstrdup(command);
390 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
395 *---------------------------------------------------------------------
396 * RelaunchWindow--
397 * Launch a new instance of the active window
399 *----------------------------------------------------------------------
401 Bool RelaunchWindow(WWindow *wwin)
403 if (! wwin || ! wwin->client_win) {
404 werror("no window to relaunch");
405 return False;
408 char **argv;
409 int argc;
411 if (! XGetCommand(dpy, wwin->client_win, &argv, &argc) || argc == 0 || argv == NULL) {
412 werror("cannot relaunch the application because no WM_COMMAND property is set");
413 return False;
416 pid_t pid = fork();
418 if (pid == 0) {
419 SetupEnvironment(wwin->screen_ptr);
420 #ifdef HAVE_SETSID
421 setsid();
422 #endif
423 /* argv is not null-terminated */
424 char **a = (char **) malloc(argc + 1);
425 if (! a) {
426 werror("out of memory trying to relaunch the application");
427 Exit(-1);
430 int i;
431 for (i = 0; i < argc; i++)
432 a[i] = argv[i];
433 a[i] = NULL;
435 execvp(a[0], a);
436 Exit(-1);
437 } else if (pid < 0) {
438 werror("cannot fork a new process");
440 XFreeStringList(argv);
441 return False;
442 } else {
443 _tuple *data = wmalloc(sizeof(_tuple));
445 data->scr = wwin->screen_ptr;
446 data->command = wtokenjoin(argv, argc);
448 /* not actually a shell command */
449 wAddDeathHandler(pid, (WDeathHandler *) shellCommandHandler, data);
451 XFreeStringList(argv);
454 return True;
458 *---------------------------------------------------------------------
459 * wAbort--
460 * Do a major cleanup and exit the program
462 *----------------------------------------------------------------------
464 noreturn void wAbort(Bool dumpCore)
466 int i;
467 WScreen *scr;
469 for (i = 0; i < wScreenCount; i++) {
470 scr = wScreenWithNumber(i);
471 if (scr)
472 RestoreDesktop(scr);
474 printf(_("%s aborted.\n"), ProgName);
475 if (dumpCore)
476 abort();
477 else
478 exit(1);
481 static void print_help(void)
483 printf(_("Usage: %s [options]\n"), ProgName);
484 puts(_("The Window Maker window manager for the X window system"));
485 puts("");
486 puts(_(" -display host:dpy display to use"));
487 puts(_(" --no-dock do not open the application Dock"));
488 puts(_(" --no-clip do not open the workspace Clip"));
489 puts(_(" --no-autolaunch do not autolaunch applications"));
490 puts(_(" --dont-restore do not restore saved session"));
492 puts(_(" --locale locale locale to use"));
494 puts(_(" --visual-id visualid visual id of visual to use"));
495 puts(_(" --static do not update or save configurations"));
496 #ifndef HAVE_INOTIFY
497 puts(_(" --no-polling do not periodically check for configuration updates"));
498 #endif
499 puts(_(" --version print version and exit"));
500 puts(_(" --help show this message"));
503 static void check_defaults(void)
505 char *path;
507 path = wdefaultspathfordomain("WindowMaker");
509 if (access(path, R_OK) != 0) {
510 wwarning(_("could not find user GNUstep directory (%s)."), path);
512 if (system("wmaker.inst --batch") != 0) {
513 wwarning(_("There was an error while creating GNUstep directory, please "
514 "make sure you have installed Window Maker correctly and run wmaker.inst"));
515 } else {
516 wwarning(_("%s directory created with default configuration."), path);
520 wfree(path);
523 #ifdef HAVE_INOTIFY
525 * Add watch here, used to notify if configuration
526 * files have changed, using linux kernel inotify mechanism
529 static void inotifyWatchConfig(void)
531 char *watchPath = NULL;
532 inotifyFD = inotify_init(); /* Initialise an inotify instance */
533 if (inotifyFD < 0) {
534 wwarning(_("could not initialise an inotify instance."
535 " Changes to the defaults database will require"
536 " a restart to take effect. Check your kernel!"));
537 } else {
538 watchPath = wstrconcat(wusergnusteppath(), "/Defaults");
539 /* Add the watch; really we are only looking for modify events
540 * but we might want more in the future so check all events for now.
541 * The individual events are checked for in event.c.
543 inotifyWD = inotify_add_watch(inotifyFD, watchPath, IN_ALL_EVENTS);
544 if (inotifyWD < 0) {
545 wwarning(_("could not add an inotify watch on path %s."
546 "Changes to the defaults database will require"
547 " a restart to take effect."), watchPath);
548 close(inotifyFD);
551 wfree(watchPath);
553 #endif /* HAVE_INOTIFY */
555 static void execInitScript(void)
557 char *file, *paths;
559 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
560 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
562 file = wfindfile(paths, DEF_INIT_SCRIPT);
563 wfree(paths);
565 if (file) {
566 if (system(file) != 0)
567 werror(_("%s:could not execute initialization script"), file);
569 wfree(file);
573 void ExecExitScript(void)
575 char *file, *paths;
577 paths = wstrconcat(wusergnusteppath(), "/Library/WindowMaker");
578 paths = wstrappend(paths, ":" DEF_CONFIG_PATHS);
580 file = wfindfile(paths, DEF_EXIT_SCRIPT);
581 wfree(paths);
583 if (file) {
584 if (system(file) != 0)
585 werror(_("%s:could not execute exit script"), file);
587 wfree(file);
591 int main(int argc, char **argv)
593 int i_am_the_monitor, i, len;
594 char *str, *alt;
596 memset(&w_global, 0, sizeof(w_global));
597 w_global.program.state = WSTATE_NORMAL;
598 w_global.program.signal_state = WSTATE_NORMAL;
600 /* setup common stuff for the monitor and wmaker itself */
601 WMInitializeApplication("WindowMaker", &argc, argv);
603 memset(&wPreferences, 0, sizeof(wPreferences));
605 wPreferences.fallbackWMs = WMCreateArray(8);
606 alt = getenv("WINDOWMAKER_ALT_WM");
607 if (alt != NULL)
608 WMAddToArray(wPreferences.fallbackWMs, wstrdup(alt));
610 WMAddToArray(wPreferences.fallbackWMs, wstrdup("blackbox"));
611 WMAddToArray(wPreferences.fallbackWMs, wstrdup("metacity"));
612 WMAddToArray(wPreferences.fallbackWMs, wstrdup("fvwm"));
613 WMAddToArray(wPreferences.fallbackWMs, wstrdup("twm"));
614 WMAddToArray(wPreferences.fallbackWMs, NULL);
615 WMAddToArray(wPreferences.fallbackWMs, wstrdup("rxvt"));
616 WMAddToArray(wPreferences.fallbackWMs, wstrdup("xterm"));
618 i_am_the_monitor = 1;
620 for (i = 1; i < argc; i++) {
621 if (strncmp(argv[i], "--for-real", strlen("--for-real")) == 0) {
622 i_am_the_monitor = 0;
623 break;
624 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
625 i++;
626 if (i >= argc) {
627 wwarning(_("too few arguments for %s"), argv[i - 1]);
628 exit(0);
630 DisplayName = argv[i];
634 DisplayName = XDisplayName(DisplayName);
635 len = strlen(DisplayName) + 64;
636 str = wmalloc(len);
637 snprintf(str, len, "DISPLAY=%s", DisplayName);
638 putenv(str);
640 if (i_am_the_monitor)
641 return MonitorLoop(argc, argv);
642 else
643 return real_main(argc, argv);
646 static int real_main(int argc, char **argv)
648 int i;
649 char *pos;
650 int d, s;
652 setlocale(LC_ALL, "");
653 wsetabort(wAbort);
655 /* for telling WPrefs what's the name of the wmaker binary being ran */
656 setenv("WMAKER_BIN_NAME", argv[0], 1);
658 ArgCount = argc;
659 Arguments = wmalloc(sizeof(char *) * (ArgCount + 1));
660 for (i = 0; i < argc; i++) {
661 Arguments[i] = argv[i];
663 /* add the extra option to signal that we're just restarting wmaker */
664 Arguments[argc - 1] = "--for-real=";
665 Arguments[argc] = NULL;
667 ProgName = strrchr(argv[0], '/');
668 if (!ProgName)
669 ProgName = argv[0];
670 else
671 ProgName++;
673 if (argc > 1) {
674 for (i = 1; i < argc; i++) {
675 if (strcmp(argv[i], "-nocpp") == 0 || strcmp(argv[i], "--no-cpp") == 0) {
676 wwarning(_("option \"%s\" is deprecated, please remove it from your script"), argv[i]);
677 } else if (strcmp(argv[i], "--for-real") == 0) {
678 wPreferences.flags.restarting = 0;
679 } else if (strcmp(argv[i], "--for-real=") == 0) {
680 wPreferences.flags.restarting = 1;
681 } else if (strcmp(argv[i], "--for-real-") == 0) {
682 wPreferences.flags.restarting = 2;
683 } else if (strcmp(argv[i], "-no-autolaunch") == 0
684 || strcmp(argv[i], "--no-autolaunch") == 0) {
685 wPreferences.flags.noautolaunch = 1;
686 } else if (strcmp(argv[i], "-dont-restore") == 0 || strcmp(argv[i], "--dont-restore") == 0) {
687 wPreferences.flags.norestore = 1;
688 } else if (strcmp(argv[i], "-nodock") == 0 || strcmp(argv[i], "--no-dock") == 0) {
689 wPreferences.flags.nodock = 1;
690 wPreferences.flags.nodrawer = 1;
691 } else if (strcmp(argv[i], "-noclip") == 0 || strcmp(argv[i], "--no-clip") == 0) {
692 wPreferences.flags.noclip = 1;
693 } else if (strcmp(argv[i], "-nodrawer") == 0 || strcmp(argv[i], "--no-drawer") == 0) {
694 wPreferences.flags.nodrawer = 1;
695 } else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
696 printf("Window Maker %s\n", VERSION);
697 exit(0);
698 } else if (strcmp(argv[i], "--global_defaults_path") == 0) {
699 printf("%s/%s\n", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR);
700 exit(0);
701 } else if (strcmp(argv[i], "-locale") == 0 || strcmp(argv[i], "--locale") == 0) {
702 i++;
703 if (i >= argc) {
704 wwarning(_("too few arguments for %s"), argv[i - 1]);
705 exit(0);
707 w_global.locale = argv[i];
708 } else if (strcmp(argv[i], "-display") == 0 || strcmp(argv[i], "--display") == 0) {
709 i++;
710 if (i >= argc) {
711 wwarning(_("too few arguments for %s"), argv[i - 1]);
712 exit(0);
714 DisplayName = argv[i];
715 } else if (strcmp(argv[i], "-visualid") == 0 || strcmp(argv[i], "--visual-id") == 0) {
716 i++;
717 if (i >= argc) {
718 wwarning(_("too few arguments for %s"), argv[i - 1]);
719 exit(0);
721 if (initWVisualID(argv[i]) != 0) {
722 wwarning(_("bad value for visualid: \"%s\""), argv[i]);
723 exit(0);
725 } else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
726 #ifndef HAVE_INOTIFY
727 || strcmp(argv[i], "--no-polling") == 0
728 #endif
730 wPreferences.flags.noupdates = 1;
731 } else if (strcmp(argv[i], "--help") == 0) {
732 print_help();
733 exit(0);
734 } else {
735 printf(_("%s: invalid argument '%s'\n"), argv[0], argv[i]);
736 printf(_("Try '%s --help' for more information\n"), argv[0]);
737 exit(1);
742 if (!wPreferences.flags.noupdates) {
743 /* check existence of Defaults DB directory */
744 check_defaults();
747 if (w_global.locale) {
748 setenv("LANG", w_global.locale, 1);
749 } else {
750 w_global.locale = getenv("LC_ALL");
751 if (!w_global.locale) {
752 w_global.locale = getenv("LANG");
756 setlocale(LC_ALL, "");
758 if (!w_global.locale || strcmp(w_global.locale, "C") == 0 || strcmp(w_global.locale, "POSIX") == 0)
759 w_global.locale = NULL;
760 #ifdef I18N
761 if (getenv("NLSPATH")) {
762 bindtextdomain("WindowMaker", getenv("NLSPATH"));
763 #if defined(MENU_TEXTDOMAIN)
764 bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
765 #endif
766 } else {
767 bindtextdomain("WindowMaker", LOCALEDIR);
768 #if defined(MENU_TEXTDOMAIN)
769 bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
770 #endif
772 bind_textdomain_codeset("WindowMaker", "UTF-8");
773 #if defined(MENU_TEXTDOMAIN)
774 bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
775 #endif
776 textdomain("WindowMaker");
778 if (!XSupportsLocale()) {
779 wwarning(_("X server does not support locale"));
782 if (XSetLocaleModifiers("") == NULL) {
783 wwarning(_("cannot set locale modifiers"));
785 #endif
787 if (w_global.locale) {
788 char *ptr;
790 w_global.locale = wstrdup(w_global.locale);
791 ptr = strchr(w_global.locale, '.');
792 if (ptr)
793 *ptr = 0;
796 /* open display */
797 dpy = XOpenDisplay(DisplayName);
798 if (dpy == NULL) {
799 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName));
800 exit(1);
803 if (fcntl(ConnectionNumber(dpy), F_SETFD, FD_CLOEXEC) < 0) {
804 werror("error setting close-on-exec flag for X connection");
805 exit(1);
809 if (getWVisualID(0) < 0) {
811 * If unspecified, use default visual instead of waiting
812 * for wrlib/context.c:bestContext() that may end up choosing
813 * the "fake" 24 bits added by the Composite extension.
814 * This is required to avoid all sort of corruptions when
815 * composite is enabled, and at a depth other than 24.
817 setWVisualID(0, (int)DefaultVisual(dpy, DefaultScreen(dpy))->visualid);
820 /* check if the user specified a complete display name (with screen).
821 * If so, only manage the specified screen */
822 if (DisplayName)
823 pos = strchr(DisplayName, ':');
824 else
825 pos = NULL;
827 if (pos && sscanf(pos, ":%i.%i", &d, &s) == 2)
828 multiHead = False;
830 DisplayName = XDisplayName(DisplayName);
831 setenv("DISPLAY", DisplayName, 1);
833 wXModifierInitialize();
834 StartUp(!multiHead);
836 if (wScreenCount == 1)
837 multiHead = False;
839 execInitScript();
840 #ifdef HAVE_INOTIFY
841 inotifyWatchConfig();
842 #endif
843 EventLoop();
844 return -1;