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"
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_GNUSTEP_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
;
118 Atom _XA_XDE_REQUEST
;
121 Atom _XA_XDE_DATA_AVAILABLE
;
128 Cursor wCursor
[WCUR_LAST
];
130 /* last event timestamp for XSetInputFocus */
132 /* timestamp on the last time we did XSetInputFocus() */
133 Time LastFocusChange
;
136 Bool wShapeSupported
;
142 char WProgramState
= WSTATE_NORMAL
;
143 char WDelayedActionSet
= 0;
145 /* temporary stuff */
149 /******** End Global Variables *****/
151 static char *DisplayName
= NULL
;
152 static char **Arguments
;
155 extern void EventLoop();
156 extern void StartUp();
161 Restart(char *manager
)
164 char *argv
[MAX_RESTART_ARGS
];
167 if (manager
&& manager
[0]!=0) {
168 prog
= argv
[0] = strtok(manager
, " ");
169 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
170 argv
[i
]=strtok(NULL
, " ");
179 execvp(Arguments
[0], Arguments
);
183 execv(Arguments
[0], Arguments
);
185 wsyserror(_("could not exec window manager"));
186 wfatal(_("Restart failed!!!"));
193 SetupEnvironment(WScreen
*scr
)
198 if (wScreenCount
> 1) {
199 tmp
= wmalloc(strlen(DisplayName
)+64);
200 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
201 ptr
= strchr(strchr(tmp
, ':'), '.');
204 sprintf(buf
, ".%i", scr
->screen
);
209 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
210 scr
->rcontext
->attribs
->colors_per_channel
);
216 *---------------------------------------------------------------------
218 * Do a major cleanup and exit the program
220 *----------------------------------------------------------------------
223 wAbort(Bool dumpCore
)
228 for (i
=0; i
<wScreenCount
; i
++) {
229 scr
= wScreenWithNumber(i
);
233 printf(_("%s aborted.\n"), ProgName
);
244 printf(_("usage: %s [-options]\n"), ProgName
);
247 puts(_(" -nocpp disable preprocessing of configuration files"));
249 puts(_(" -nodock do not open the application Dock"));
250 puts(_(" -noclip do not open the workspace Clip"));
252 puts(_(" -locale locale locale to use"));
254 puts(_(" -visualid visualid visual id of visual to use"));
255 puts(_(" -display host:dpy display to use"));
256 puts(_(" -version print version and exit"));
266 path
= wdefaultspathfordomain("");
267 if (access(path
, R_OK
)!=0) {
268 wfatal(_("could not find user GNUstep directory (%s).\n"
269 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
284 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
287 close(ConnectionNumber(dpy
));
289 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
290 wsyserror(_("%s:could not execute initialization script"), file
);
303 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
306 close(ConnectionNumber(dpy
));
308 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
309 wsyserror(_("%s:could not execute exit script"), file
);
319 main(int argc
, char **argv
)
322 Bool multiHead
= True
;
329 WMInitializeApplication("WindowMaker", &argc
, argv
);
332 ProgName
= strrchr(argv
[0],'/');
339 /* check existence of Defaults DB directory */
344 memset(&wPreferences
, 0, sizeof(WPreferences
));
347 for (i
=1; i
<argc
; i
++) {
349 if (strcmp(argv
[i
], "-nocpp")==0) {
350 wPreferences
.flags
.nocpp
=1;
353 if (strcmp(argv
[i
], "-nodock")==0) {
354 wPreferences
.flags
.nodock
=1;
355 } else if (strcmp(argv
[i
], "-noclip")==0) {
356 wPreferences
.flags
.noclip
=1;
357 } else if (strcmp(argv
[i
], "-version")==0) {
358 printf("Window Maker %s\n", VERSION
);
360 } else if (strcmp(argv
[i
], "-global_defaults_path")==0) {
361 printf("%s/Defaults/WindowMaker", PKGDATADIR
);
363 } else if (strcmp(argv
[i
], "-locale")==0) {
366 wwarning(_("too few arguments for %s"), argv
[i
-1]);
370 } else if (strcmp(argv
[i
], "-display")==0) {
373 wwarning(_("too few arguments for %s"), argv
[i
-1]);
376 DisplayName
= argv
[i
];
377 } else if (strcmp(argv
[i
], "-visualid")==0) {
380 wwarning(_("too few arguments for %s"), argv
[i
-1]);
383 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
384 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
394 tmp
= getenv("LANG");
396 if (setlocale(LC_ALL
,"") == NULL
) {
397 wwarning("cannot set locale %s", tmp
);
398 wwarning("falling back to C locale");
399 setlocale(LC_ALL
,"C");
402 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
412 Locale
= getenv("LANG");
414 setlocale(LC_ALL
, Locale
);
415 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
418 if (getenv("NLSPATH"))
419 bindtextdomain("WindowMaker", getenv("NLSPATH"));
421 bindtextdomain("WindowMaker", NLSDIR
);
422 textdomain("WindowMaker");
424 if (!XSupportsLocale()) {
425 wwarning(_("X server does not support locale"));
427 if (XSetLocaleModifiers("") == NULL
) {
428 wwarning(_("cannot set locale modifiers"));
435 Locale
= wstrdup(Locale
);
436 ptr
= strchr(Locale
, '.');
443 dpy
= XOpenDisplay(DisplayName
);
445 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
449 /* check if the user specified a complete display name (with screen).
450 * If so, only manage the specified screen */
452 str
= strchr(DisplayName
, ':');
457 if (sscanf(str
, "%i.%i", &d
, &s
)==2)
460 DisplayName
= XDisplayName(DisplayName
);
461 str
= wmalloc(strlen(DisplayName
)+64);
462 sprintf(str
, "DISPLAY=%s", DisplayName
);
466 XSynchronize(dpy
, True
);
469 wXModifierInitialize();