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
;
106 Atom _XA_MOTIF_WM_HINTS
;
109 Atom _XA_WINDOWMAKER_MENU
;
110 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
111 Atom _XA_WINDOWMAKER_STATE
;
113 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
116 Atom _XA_DND_PROTOCOL
;
117 Atom _XA_DND_SELECTION
;
120 Atom _XA_XDE_REQUEST
;
123 Atom _XA_XDE_DATA_AVAILABLE
;
130 Cursor wCursor
[WCUR_LAST
];
132 /* last event timestamp for XSetInputFocus */
134 /* timestamp on the last time we did XSetInputFocus() */
135 Time LastFocusChange
;
138 Bool wShapeSupported
;
144 char WProgramState
= WSTATE_NORMAL
;
145 char WDelayedActionSet
= 0;
147 /* temporary stuff */
151 /******** End Global Variables *****/
153 static char *DisplayName
= NULL
;
154 static char **Arguments
;
157 extern void EventLoop();
158 extern void StartUp();
165 wSessionDisconnectManager();
173 Restart(char *manager
)
176 char *argv
[MAX_RESTART_ARGS
];
179 if (manager
&& manager
[0]!=0) {
180 prog
= argv
[0] = strtok(manager
, " ");
181 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
182 argv
[i
]=strtok(NULL
, " ");
189 wSessionDisconnectManager();
193 execvp(Arguments
[0], Arguments
);
197 execv(Arguments
[0], Arguments
);
199 wsyserror(_("could not exec window manager"));
200 wfatal(_("Restart failed!!!"));
207 SetupEnvironment(WScreen
*scr
)
212 if (wScreenCount
> 1) {
213 tmp
= wmalloc(strlen(DisplayName
)+64);
214 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
215 ptr
= strchr(strchr(tmp
, ':'), '.');
218 sprintf(buf
, ".%i", scr
->screen
);
223 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
224 scr
->rcontext
->attribs
->colors_per_channel
);
230 *---------------------------------------------------------------------
232 * Do a major cleanup and exit the program
234 *----------------------------------------------------------------------
237 wAbort(Bool dumpCore
)
242 for (i
=0; i
<wScreenCount
; i
++) {
243 scr
= wScreenWithNumber(i
);
247 printf(_("%s aborted.\n"), ProgName
);
258 printf(_("usage: %s [-options]\n"), ProgName
);
261 puts(_(" -nocpp disable preprocessing of configuration files"));
263 puts(_(" -nodock do not open the application Dock"));
264 puts(_(" -noclip do not open the workspace Clip"));
266 puts(_(" -locale locale locale to use"));
268 puts(_(" -visualid visualid visual id of visual to use"));
269 puts(_(" -display host:dpy display to use"));
270 puts(_(" -static do not update or save configurations"));
271 puts(_(" -version print version and exit"));
281 path
= wdefaultspathfordomain("");
282 if (access(path
, R_OK
)!=0) {
283 wfatal(_("could not find user GNUstep directory (%s).\n"
284 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
298 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
303 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
304 wsyserror(_("%s:could not execute initialization script"), file
);
317 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
322 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
323 wsyserror(_("%s:could not execute exit script"), file
);
333 main(int argc
, char **argv
)
336 Bool multiHead
= True
;
343 WMInitializeApplication("WindowMaker", &argc
, argv
);
346 ProgName
= strrchr(argv
[0],'/');
355 memset(&wPreferences
, 0, sizeof(WPreferences
));
358 for (i
=1; i
<argc
; i
++) {
360 if (strcmp(argv
[i
], "-nocpp")==0) {
361 wPreferences
.flags
.nocpp
=1;
364 if (strcmp(argv
[i
], "-nodock")==0) {
365 wPreferences
.flags
.nodock
=1;
366 } else if (strcmp(argv
[i
], "-noclip")==0) {
367 wPreferences
.flags
.noclip
=1;
368 } else if (strcmp(argv
[i
], "-version")==0) {
369 printf("Window Maker %s\n", VERSION
);
371 } else if (strcmp(argv
[i
], "-global_defaults_path")==0) {
372 printf("%s/Defaults/WindowMaker", PKGDATADIR
);
374 } else if (strcmp(argv
[i
], "-locale")==0) {
377 wwarning(_("too few arguments for %s"), argv
[i
-1]);
381 } else if (strcmp(argv
[i
], "-display")==0) {
384 wwarning(_("too few arguments for %s"), argv
[i
-1]);
387 DisplayName
= argv
[i
];
388 } else if (strcmp(argv
[i
], "-visualid")==0) {
391 wwarning(_("too few arguments for %s"), argv
[i
-1]);
394 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
395 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
398 } else if (strcmp(argv
[i
], "-static")==0) {
399 wPreferences
.flags
.noupdates
= 1;
401 } else if (strcmp(argv
[i
], "-clientid")==0
402 || strcmp(argv
[i
], "-restore")==0) {
405 wwarning(_("too few arguments for %s"), argv
[i
-1]);
416 if (!wPreferences
.flags
.noupdates
) {
417 /* check existence of Defaults DB directory */
422 tmp
= getenv("LANG");
424 if (setlocale(LC_ALL
,"") == NULL
) {
425 wwarning("cannot set locale %s", tmp
);
426 wwarning("falling back to C locale");
427 setlocale(LC_ALL
,"C");
430 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
440 Locale
= getenv("LANG");
442 setlocale(LC_ALL
, Locale
);
443 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
446 if (getenv("NLSPATH"))
447 bindtextdomain("WindowMaker", getenv("NLSPATH"));
449 bindtextdomain("WindowMaker", NLSDIR
);
450 textdomain("WindowMaker");
452 if (!XSupportsLocale()) {
453 wwarning(_("X server does not support locale"));
455 if (XSetLocaleModifiers("") == NULL
) {
456 wwarning(_("cannot set locale modifiers"));
463 Locale
= wstrdup(Locale
);
464 ptr
= strchr(Locale
, '.');
471 dpy
= XOpenDisplay(DisplayName
);
473 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
477 /* check if the user specified a complete display name (with screen).
478 * If so, only manage the specified screen */
480 str
= strchr(DisplayName
, ':');
485 if (sscanf(str
, "%i.%i", &d
, &s
)==2)
488 DisplayName
= XDisplayName(DisplayName
);
489 str
= wmalloc(strlen(DisplayName
)+64);
490 sprintf(str
, "DISPLAY=%s", DisplayName
);
494 XSynchronize(dpy
, True
);
497 wXModifierInitialize();
504 wSessionConnectManager(argv
, argc
);