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 */
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
;
103 Atom _XA_WINDOWMAKER_MENU
;
104 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
105 Atom _XA_WINDOWMAKER_STATE
;
107 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
108 Atom _XA_WINDOWMAKER_NOTICEBOARD
;
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();
169 Restart(char *manager
)
172 char *argv
[MAX_RESTART_ARGS
];
175 if (manager
&& manager
[0]!=0) {
176 prog
= argv
[0] = strtok(manager
, " ");
177 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
178 argv
[i
]=strtok(NULL
, " ");
185 wSessionDisconnectManager();
189 execvp(Arguments
[0], Arguments
);
193 execv(Arguments
[0], Arguments
);
195 wsyserror(_("could not exec window manager"));
196 wfatal(_("Restart failed!!!"));
203 SetupEnvironment(WScreen
*scr
)
208 if (wScreenCount
> 1) {
209 tmp
= wmalloc(strlen(DisplayName
)+64);
210 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
211 ptr
= strchr(strchr(tmp
, ':'), '.');
214 sprintf(buf
, ".%i", scr
->screen
);
219 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
220 scr
->rcontext
->attribs
->colors_per_channel
);
226 *---------------------------------------------------------------------
228 * Do a major cleanup and exit the program
230 *----------------------------------------------------------------------
233 wAbort(Bool dumpCore
)
238 for (i
=0; i
<wScreenCount
; i
++) {
239 scr
= wScreenWithNumber(i
);
243 printf(_("%s aborted.\n"), ProgName
);
254 printf(_("Usage: %s [options]\n"), ProgName
);
255 puts(_("The Window Maker window manager for the X window system"));
257 puts(_(" -display host:dpy display to use"));
259 puts(_(" --no-cpp disable preprocessing of configuration files"));
261 puts(_(" --no-dock do not open the application Dock"));
262 puts(_(" --no-clip do not open the workspace Clip"));
264 puts(_(" --locale locale locale to use"));
266 puts(_(" --visual-id visualid visual id of visual to use"));
267 puts(_(" --static do not update or save configurations"));
268 puts(_(" --version print version and exit"));
269 puts(_(" --help show this message"));
279 path
= wdefaultspathfordomain("");
280 if (access(path
, R_OK
)!=0) {
281 wfatal(_("could not find user GNUstep directory (%s).\n"
282 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
296 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
299 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
300 wsyserror(_("%s:could not execute initialization script"), file
);
313 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
316 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
317 wsyserror(_("%s:could not execute exit script"), file
);
327 main(int argc
, char **argv
)
330 Bool multiHead
= True
;
339 WMInitializeApplication("WindowMaker", &argc
, argv
);
342 ProgName
= strrchr(argv
[0],'/');
351 memset(&wPreferences
, 0, sizeof(WPreferences
));
354 for (i
=1; i
<argc
; i
++) {
356 if (strcmp(argv
[i
], "-nocpp")==0
357 || strcmp(argv
[i
], "--no-cpp")==0) {
358 wPreferences
.flags
.nocpp
=1;
361 if (strcmp(argv
[i
], "-nodock")==0
362 || strcmp(argv
[i
], "--no-dock")==0) {
363 wPreferences
.flags
.nodock
=1;
364 } else if (strcmp(argv
[i
], "-noclip")==0
365 || strcmp(argv
[i
], "--no-clip")==0) {
366 wPreferences
.flags
.noclip
=1;
367 } else if (strcmp(argv
[i
], "-version")==0
368 || strcmp(argv
[i
], "--version")==0) {
369 printf("Window Maker %s\n", VERSION
);
371 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
374 } else if (strcmp(argv
[i
], "-locale")==0
375 || strcmp(argv
[i
], "--locale")==0) {
378 wwarning(_("too few arguments for %s"), argv
[i
-1]);
382 } else if (strcmp(argv
[i
], "-display")==0) {
385 wwarning(_("too few arguments for %s"), argv
[i
-1]);
388 DisplayName
= argv
[i
];
389 } else if (strcmp(argv
[i
], "-visualid")==0
390 || strcmp(argv
[i
], "--visual-id")==0) {
393 wwarning(_("too few arguments for %s"), argv
[i
-1]);
396 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
397 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
400 } else if (strcmp(argv
[i
], "-static")==0
401 || strcmp(argv
[i
], "--static")==0) {
403 wPreferences
.flags
.noupdates
= 1;
405 } else if (strcmp(argv
[i
], "-clientid")==0
406 || strcmp(argv
[i
], "-restore")==0) {
409 wwarning(_("too few arguments for %s"), argv
[i
-1]);
413 } else if (strcmp(argv
[i
], "--help")==0) {
417 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
418 printf(_("Try '%s --help' for more information\n"), argv
[0]);
424 if (!wPreferences
.flags
.noupdates
) {
425 /* check existence of Defaults DB directory */
430 tmp
= getenv("LANG");
432 if (setlocale(LC_ALL
,"") == NULL
) {
433 wwarning("cannot set locale %s", tmp
);
434 wwarning("falling back to C locale");
435 setlocale(LC_ALL
,"C");
438 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
448 Locale
= getenv("LANG");
450 setlocale(LC_ALL
, Locale
);
451 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
454 if (getenv("NLSPATH"))
455 bindtextdomain("WindowMaker", getenv("NLSPATH"));
457 bindtextdomain("WindowMaker", LOCALEDIR
);
458 textdomain("WindowMaker");
460 if (!XSupportsLocale()) {
461 wwarning(_("X server does not support locale"));
463 if (XSetLocaleModifiers("") == NULL
) {
464 wwarning(_("cannot set locale modifiers"));
471 Locale
= wstrdup(Locale
);
472 ptr
= strchr(Locale
, '.');
479 dpy
= XOpenDisplay(DisplayName
);
481 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
485 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
486 wsyserror("error setting close-on-exec flag for X connection");
490 /* check if the user specified a complete display name (with screen).
491 * If so, only manage the specified screen */
493 str
= strchr(DisplayName
, ':');
497 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
500 DisplayName
= XDisplayName(DisplayName
);
501 str
= wmalloc(strlen(DisplayName
)+64);
502 sprintf(str
, "DISPLAY=%s", DisplayName
);
506 XSynchronize(dpy
, True
);
509 wXModifierInitialize();
516 wSessionConnectManager(argv
, argc
);