2 * Window Maker 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"
54 /****** Global Variables ******/
62 unsigned int ValidModMask
= 0xff;
64 /* locale to use. NULL==POSIX or C */
70 WPreferences wPreferences
;
73 proplist_t wDomainName
;
74 proplist_t wAttributeDomainName
;
76 WShortKey wKeyBindings
[WKBD_LAST
];
78 /* defaults domains */
79 WDDomain
*WDWindowMaker
= NULL
;
80 WDDomain
*WDRootMenu
= NULL
;
81 WDDomain
*WDWindowAttributes
= NULL
;
86 XContext wAppWinContext
;
87 XContext wStackContext
;
91 Atom _XA_WM_CHANGE_STATE
;
92 Atom _XA_WM_PROTOCOLS
;
93 Atom _XA_WM_TAKE_FOCUS
;
94 Atom _XA_WM_DELETE_WINDOW
;
95 Atom _XA_WM_SAVE_YOURSELF
;
96 Atom _XA_WM_CLIENT_LEADER
;
97 Atom _XA_WM_COLORMAP_WINDOWS
;
98 Atom _XA_WM_COLORMAP_NOTIFY
;
100 Atom _XA_GNUSTEP_WM_ATTR
;
101 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
102 Atom _XA_GNUSTEP_WM_RESIZEBAR
;
104 Atom _XA_WINDOWMAKER_MENU
;
105 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
106 Atom _XA_WINDOWMAKER_STATE
;
108 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
111 Atom _XA_DND_PROTOCOL
;
112 Atom _XA_DND_SELECTION
;
115 Atom _XA_XDE_REQUEST
;
118 Atom _XA_XDE_DATA_AVAILABLE
;
125 Cursor wCursor
[WCUR_LAST
];
127 /* last event timestamp for XSetInputFocus */
129 /* timestamp on the last time we did XSetInputFocus() */
130 Time LastFocusChange
;
133 Bool wShapeSupported
;
139 char WProgramState
= WSTATE_NORMAL
;
140 char WDelayedActionSet
= 0;
142 /* temporary stuff */
146 /******** End Global Variables *****/
148 static char *DisplayName
= NULL
;
149 static char **Arguments
;
152 extern void EventLoop();
153 extern void StartUp();
160 wSessionDisconnectManager();
168 Restart(char *manager
)
171 char *argv
[MAX_RESTART_ARGS
];
174 if (manager
&& manager
[0]!=0) {
175 prog
= argv
[0] = strtok(manager
, " ");
176 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
177 argv
[i
]=strtok(NULL
, " ");
184 wSessionDisconnectManager();
188 execvp(Arguments
[0], Arguments
);
192 execv(Arguments
[0], Arguments
);
194 wsyserror(_("could not exec window manager"));
195 wfatal(_("Restart failed!!!"));
202 SetupEnvironment(WScreen
*scr
)
207 if (wScreenCount
> 1) {
208 tmp
= wmalloc(strlen(DisplayName
)+64);
209 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
210 ptr
= strchr(strchr(tmp
, ':'), '.');
213 sprintf(buf
, ".%i", scr
->screen
);
218 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
219 scr
->rcontext
->attribs
->colors_per_channel
);
225 *---------------------------------------------------------------------
227 * Do a major cleanup and exit the program
229 *----------------------------------------------------------------------
232 wAbort(Bool dumpCore
)
237 for (i
=0; i
<wScreenCount
; i
++) {
238 scr
= wScreenWithNumber(i
);
242 printf(_("%s aborted.\n"), ProgName
);
253 printf(_("usage: %s [-options]\n"), ProgName
);
256 puts(_(" -nocpp disable preprocessing of configuration files"));
258 puts(_(" -nodock do not open the application Dock"));
259 puts(_(" -noclip do not open the workspace Clip"));
261 puts(_(" -locale locale locale to use"));
263 puts(_(" -visualid visualid visual id of visual to use"));
264 puts(_(" -display host:dpy display to use"));
265 puts(_(" -static do not update or save configurations"));
266 puts(_(" -version print version and exit"));
276 path
= wdefaultspathfordomain("");
277 if (access(path
, R_OK
)!=0) {
278 wfatal(_("could not find user GNUstep directory (%s).\n"
279 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
293 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
296 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
297 wsyserror(_("%s:could not execute initialization script"), file
);
310 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
313 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
314 wsyserror(_("%s:could not execute exit script"), file
);
324 main(int argc
, char **argv
)
327 Bool multiHead
= True
;
334 WMInitializeApplication("WindowMaker", &argc
, argv
);
337 ProgName
= strrchr(argv
[0],'/');
346 memset(&wPreferences
, 0, sizeof(WPreferences
));
349 for (i
=1; i
<argc
; i
++) {
351 if (strcmp(argv
[i
], "-nocpp")==0) {
352 wPreferences
.flags
.nocpp
=1;
355 if (strcmp(argv
[i
], "-nodock")==0) {
356 wPreferences
.flags
.nodock
=1;
357 } else if (strcmp(argv
[i
], "-noclip")==0) {
358 wPreferences
.flags
.noclip
=1;
359 } else if (strcmp(argv
[i
], "-version")==0) {
360 printf("Window Maker %s\n", VERSION
);
362 } else if (strcmp(argv
[i
], "-global_defaults_path")==0) {
363 printf("%s/Defaults/WindowMaker", PKGDATADIR
);
365 } else if (strcmp(argv
[i
], "-locale")==0) {
368 wwarning(_("too few arguments for %s"), argv
[i
-1]);
372 } else if (strcmp(argv
[i
], "-display")==0) {
375 wwarning(_("too few arguments for %s"), argv
[i
-1]);
378 DisplayName
= argv
[i
];
379 } else if (strcmp(argv
[i
], "-visualid")==0) {
382 wwarning(_("too few arguments for %s"), argv
[i
-1]);
385 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
386 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
389 } else if (strcmp(argv
[i
], "-static")==0) {
390 wPreferences
.flags
.noupdates
= 1;
392 } else if (strcmp(argv
[i
], "-clientid")==0
393 || strcmp(argv
[i
], "-restore")==0) {
396 wwarning(_("too few arguments for %s"), argv
[i
-1]);
407 if (!wPreferences
.flags
.noupdates
) {
408 /* check existence of Defaults DB directory */
413 tmp
= getenv("LANG");
415 if (setlocale(LC_ALL
,"") == NULL
) {
416 wwarning("cannot set locale %s", tmp
);
417 wwarning("falling back to C locale");
418 setlocale(LC_ALL
,"C");
421 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
431 Locale
= getenv("LANG");
433 setlocale(LC_ALL
, Locale
);
434 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
437 if (getenv("NLSPATH"))
438 bindtextdomain("WindowMaker", getenv("NLSPATH"));
440 bindtextdomain("WindowMaker", NLSDIR
);
441 textdomain("WindowMaker");
443 if (!XSupportsLocale()) {
444 wwarning(_("X server does not support locale"));
446 if (XSetLocaleModifiers("") == NULL
) {
447 wwarning(_("cannot set locale modifiers"));
454 Locale
= wstrdup(Locale
);
455 ptr
= strchr(Locale
, '.');
462 dpy
= XOpenDisplay(DisplayName
);
464 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
468 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
469 wsyserror("error setting close-on-exec flag for X connection");
473 /* check if the user specified a complete display name (with screen).
474 * If so, only manage the specified screen */
476 str
= strchr(DisplayName
, ':');
481 if (sscanf(str
, "%i.%i", &d
, &s
)==2)
484 DisplayName
= XDisplayName(DisplayName
);
485 str
= wmalloc(strlen(DisplayName
)+64);
486 sprintf(str
, "DISPLAY=%s", DisplayName
);
490 XSynchronize(dpy
, True
);
493 wXModifierInitialize();
500 wSessionConnectManager(argv
, argc
);