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
;
97 Atom _XA_WM_COLORMAP_NOTIFY
;
99 Atom _XA_GNUSTEP_WM_ATTR
;
100 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
101 Atom _XA_GNUSTEP_WM_RESIZEBAR
;
105 Atom _XA_MOTIF_WM_HINTS
;
108 Atom _XA_WINDOWMAKER_MENU
;
109 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
110 Atom _XA_WINDOWMAKER_STATE
;
112 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
115 Atom _XA_DND_PROTOCOL
;
116 Atom _XA_DND_SELECTION
;
119 Atom _XA_XDE_REQUEST
;
122 Atom _XA_XDE_DATA_AVAILABLE
;
129 Cursor wCursor
[WCUR_LAST
];
131 /* last event timestamp for XSetInputFocus */
133 /* timestamp on the last time we did XSetInputFocus() */
134 Time LastFocusChange
;
137 Bool wShapeSupported
;
143 char WProgramState
= WSTATE_NORMAL
;
144 char WDelayedActionSet
= 0;
146 /* temporary stuff */
150 /******** End Global Variables *****/
152 static char *DisplayName
= NULL
;
153 static char **Arguments
;
156 extern void EventLoop();
157 extern void StartUp();
162 Restart(char *manager
)
165 char *argv
[MAX_RESTART_ARGS
];
168 if (manager
&& manager
[0]!=0) {
169 prog
= argv
[0] = strtok(manager
, " ");
170 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
171 argv
[i
]=strtok(NULL
, " ");
180 execvp(Arguments
[0], Arguments
);
184 execv(Arguments
[0], Arguments
);
186 wsyserror(_("could not exec window manager"));
187 wfatal(_("Restart failed!!!"));
194 SetupEnvironment(WScreen
*scr
)
199 if (wScreenCount
> 1) {
200 tmp
= wmalloc(strlen(DisplayName
)+64);
201 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
202 ptr
= strchr(strchr(tmp
, ':'), '.');
205 sprintf(buf
, ".%i", scr
->screen
);
210 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
211 scr
->rcontext
->attribs
->colors_per_channel
);
217 *---------------------------------------------------------------------
219 * Do a major cleanup and exit the program
221 *----------------------------------------------------------------------
224 wAbort(Bool dumpCore
)
229 for (i
=0; i
<wScreenCount
; i
++) {
230 scr
= wScreenWithNumber(i
);
234 printf(_("%s aborted.\n"), ProgName
);
245 printf(_("usage: %s [-options]\n"), ProgName
);
248 puts(_(" -nocpp disable preprocessing of configuration files"));
250 puts(_(" -nodock do not open the application Dock"));
251 puts(_(" -noclip do not open the workspace Clip"));
253 puts(_(" -locale locale locale to use"));
255 puts(_(" -visualid visualid visual id of visual to use"));
256 puts(_(" -display host:dpy display to use"));
257 puts(_(" -version print version and exit"));
267 path
= wdefaultspathfordomain("");
268 if (access(path
, R_OK
)!=0) {
269 wfatal(_("could not find user GNUstep directory (%s).\n"
270 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
285 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
288 close(ConnectionNumber(dpy
));
290 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
291 wsyserror(_("%s:could not execute initialization script"), file
);
304 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
307 close(ConnectionNumber(dpy
));
309 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
310 wsyserror(_("%s:could not execute exit script"), file
);
320 main(int argc
, char **argv
)
323 Bool multiHead
= True
;
330 WMInitializeApplication("WindowMaker", &argc
, argv
);
333 ProgName
= strrchr(argv
[0],'/');
340 /* check existence of Defaults DB directory */
345 memset(&wPreferences
, 0, sizeof(WPreferences
));
348 for (i
=1; i
<argc
; i
++) {
350 if (strcmp(argv
[i
], "-nocpp")==0) {
351 wPreferences
.flags
.nocpp
=1;
354 if (strcmp(argv
[i
], "-nodock")==0) {
355 wPreferences
.flags
.nodock
=1;
356 } else if (strcmp(argv
[i
], "-noclip")==0) {
357 wPreferences
.flags
.noclip
=1;
358 } else if (strcmp(argv
[i
], "-version")==0) {
359 printf("Window Maker %s\n", VERSION
);
361 } else if (strcmp(argv
[i
], "-global_defaults_path")==0) {
362 printf("%s/Defaults/WindowMaker", PKGDATADIR
);
364 } else if (strcmp(argv
[i
], "-locale")==0) {
367 wwarning(_("too few arguments for %s"), argv
[i
-1]);
371 } else if (strcmp(argv
[i
], "-display")==0) {
374 wwarning(_("too few arguments for %s"), argv
[i
-1]);
377 DisplayName
= argv
[i
];
378 } else if (strcmp(argv
[i
], "-visualid")==0) {
381 wwarning(_("too few arguments for %s"), argv
[i
-1]);
384 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
385 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
395 tmp
= getenv("LANG");
397 if (setlocale(LC_ALL
,"") == NULL
) {
398 wwarning("cannot set locale %s", tmp
);
399 wwarning("falling back to C locale");
400 setlocale(LC_ALL
,"C");
403 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
413 Locale
= getenv("LANG");
415 setlocale(LC_ALL
, Locale
);
416 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
419 if (getenv("NLSPATH"))
420 bindtextdomain("WindowMaker", getenv("NLSPATH"));
422 bindtextdomain("WindowMaker", NLSDIR
);
423 textdomain("WindowMaker");
425 if (!XSupportsLocale()) {
426 wwarning(_("X server does not support locale"));
428 if (XSetLocaleModifiers("") == NULL
) {
429 wwarning(_("cannot set locale modifiers"));
436 Locale
= wstrdup(Locale
);
437 ptr
= strchr(Locale
, '.');
444 dpy
= XOpenDisplay(DisplayName
);
446 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
450 /* check if the user specified a complete display name (with screen).
451 * If so, only manage the specified screen */
453 str
= strchr(DisplayName
, ':');
458 if (sscanf(str
, "%i.%i", &d
, &s
)==2)
461 DisplayName
= XDisplayName(DisplayName
);
462 str
= wmalloc(strlen(DisplayName
)+64);
463 sprintf(str
, "DISPLAY=%s", DisplayName
);
467 XSynchronize(dpy
, True
);
470 wXModifierInitialize();