2 * WindowMaker window manager
4 * Copyright (c) 1997, 1998 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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 #include <sys/types.h>
33 #include <X11/Xutil.h>
36 /* Xlocale.h and locale.h are the same if X_LOCALE is undefind in wconfig.h,
37 * and if X_LOCALE is defined, X's locale emulating functions will be used.
38 * See Xlocale.h for more information.
40 #include <X11/Xlocale.h>
42 #include "WindowMaker.h"
47 #include "xmodifier.h"
53 /****** Global Variables ******/
61 unsigned int ValidModMask
= 0xff;
63 /* locale to use. NULL==POSIX or C */
69 WPreferences wPreferences
;
72 proplist_t wDomainName
;
73 proplist_t wAttributeDomainName
;
75 WShortKey wKeyBindings
[WKBD_LAST
];
77 /* defaults domains */
78 WDDomain
*WDWindowMaker
= NULL
;
79 WDDomain
*WDRootMenu
= NULL
;
80 WDDomain
*WDWindowAttributes
= NULL
;
85 XContext wAppWinContext
;
86 XContext wStackContext
;
90 Atom _XA_WM_CHANGE_STATE
;
91 Atom _XA_WM_PROTOCOLS
;
92 Atom _XA_WM_TAKE_FOCUS
;
93 Atom _XA_WM_DELETE_WINDOW
;
94 Atom _XA_WM_SAVE_YOURSELF
;
95 Atom _XA_WM_CLIENT_LEADER
;
96 Atom _XA_WM_COLORMAP_WINDOWS
;
98 Atom _XA_GNUSTEP_WM_ATTR
;
99 Atom _XA_WINDOWMAKER_WM_MINIATURIZE_WINDOW
;
100 Atom _XA_GNUSTEP_WM_RESIZEBAR
;
104 Atom _XA_MOTIF_WM_HINTS
;
107 Atom _XA_WINDOWMAKER_MENU
;
108 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
109 Atom _XA_WINDOWMAKER_STATE
;
111 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
114 Atom _XA_DND_PROTOCOL
;
115 Atom _XA_DND_SELECTION
;
120 Cursor wCursor
[WCUR_LAST
];
122 /* last event timestamp for XSetInputFocus */
124 /* timestamp on the last time we did XSetInputFocus() */
125 Time LastFocusChange
;
133 char WRestartASAP
= 0;
135 char WDelayedActionSet
= 0;
137 /* temporary stuff */
141 /******** End Global Variables *****/
143 static char *DisplayName
= NULL
;
144 static char **Arguments
;
147 extern void EventLoop();
148 extern void StartUp();
153 Restart(char *manager
)
156 char *argv
[MAX_RESTART_ARGS
];
159 if (manager
&& manager
[0]!=0) {
160 prog
= argv
[0] = strtok(manager
, " ");
161 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
162 argv
[i
]=strtok(NULL
, " ");
171 execvp(Arguments
[0], Arguments
);
175 execv(Arguments
[0], Arguments
);
177 wfatal(_("Restart failed!!!"));
184 SetupEnvironment(WScreen
*scr
)
189 if (wScreenCount
== 1)
192 tmp
= wmalloc(strlen(DisplayName
)+64);
193 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
194 ptr
= strchr(strchr(DisplayName
, ':'), '.');
197 sprintf(buf
, ".%i", scr
->screen
);
204 *---------------------------------------------------------------------
206 * Do a major cleanup and exit the program
208 *----------------------------------------------------------------------
211 wAbort(Bool dumpCore
)
216 for (i
=0; i
<wScreenCount
; i
++) {
217 scr
= wScreenWithNumber(i
);
221 printf(_("%s aborted.\n"), ProgName
);
232 printf(_("usage: %s [-options]\n"), ProgName
);
235 puts(_(" -nocpp disable preprocessing of configuration files"));
237 puts(_(" -nodock do not open the application Dock"));
238 puts(_(" -noclip do not open the workspace Clip"));
240 puts(_(" -locale locale locale to use"));
242 puts(_(" -visualid visualid visual id of visual to use"));
243 puts(_(" -display host:dpy display to use"));
244 puts(_(" -version print version and exit"));
254 path
= wdefaultspathfordomain("");
255 if (access(path
, R_OK
)!=0) {
256 wfatal(_("could not find user GNUstep directory.\n"
257 "Make sure you have installed WindowMaker correctly and run wmaker.inst"));
271 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
274 close(ConnectionNumber(dpy
));
276 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
277 wsyserror(_("%s:could not execute initialization script"), file
);
290 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
293 close(ConnectionNumber(dpy
));
295 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
296 wsyserror(_("%s:could not execute exit script"), file
);
306 main(int argc
, char **argv
)
309 Bool multiHead
= True
;
316 WMInitializeApplication("WindowMaker", &argc
, argv
);
319 ProgName
= strrchr(argv
[0],'/');
326 /* check existence of Defaults DB directory */
331 memset(&wPreferences
, 0, sizeof(WPreferences
));
334 for (i
=1; i
<argc
; i
++) {
336 if (strcmp(argv
[i
], "-nocpp")==0) {
337 wPreferences
.flags
.nocpp
=1;
340 if (strcmp(argv
[i
], "-nodock")==0) {
341 wPreferences
.flags
.nodock
=1;
342 } else if (strcmp(argv
[i
], "-noclip")==0) {
343 wPreferences
.flags
.noclip
=1;
344 } else if (strcmp(argv
[i
], "-version")==0) {
345 printf("WindowMaker %s\n", VERSION
);
347 } else if (strcmp(argv
[i
], "-global_defaults_path")==0) {
348 printf("%s/Defaults/WindowMaker", PKGDATADIR
);
350 } else if (strcmp(argv
[i
], "-locale")==0) {
353 wwarning(_("too few arguments for %s"), argv
[i
-1]);
357 } else if (strcmp(argv
[i
], "-display")==0) {
360 wwarning(_("too few arguments for %s"), argv
[i
-1]);
363 DisplayName
= argv
[i
];
364 } else if (strcmp(argv
[i
], "-visualid")==0) {
367 wwarning(_("too few arguments for %s"), argv
[i
-1]);
370 if (sscanf(argv
[i
], "%d", &wVisualID
)!=1) {
371 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
381 tmp
= getenv("LANG");
383 if (setlocale(LC_ALL
,"") == NULL
) {
384 wwarning("cannot set locale %s", tmp
);
385 wwarning("falling back to C locale");
386 setlocale(LC_ALL
,"C");
389 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
399 Locale
= getenv("LANG");
401 setlocale(LC_ALL
, Locale
);
402 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
405 if (getenv("NLSPATH"))
406 bindtextdomain("WindowMaker", getenv("NLSPATH"));
408 bindtextdomain("WindowMaker", NLSDIR
);
409 textdomain("WindowMaker");
411 if (!XSupportsLocale()) {
412 wwarning(_("X server does not support locale"));
414 if (XSetLocaleModifiers("") == NULL
) {
415 wwarning(_("cannot set locale modifiers"));
420 dpy
= XOpenDisplay(DisplayName
);
422 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
426 /* check if the user specified a complete display name (with screen).
427 * If so, only manage the specified screen */
429 str
= strchr(DisplayName
, ':');
434 if (sscanf(str
, "%i.%i", &d
, &s
)==2)
437 DisplayName
= XDisplayName(DisplayName
);
438 str
= wmalloc(strlen(DisplayName
)+64);
439 sprintf(str
, "DISPLAY=%s", DisplayName
);
443 XSynchronize(dpy
, True
);
446 wXModifierInitialize();