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>
44 #include "WindowMaker.h"
49 #include "xmodifier.h"
55 /****** Global Variables ******/
66 unsigned int ValidModMask
= 0xff;
68 /* locale to use. NULL==POSIX or C */
73 WPreferences wPreferences
;
76 proplist_t wDomainName
;
77 proplist_t wAttributeDomainName
;
79 WShortKey wKeyBindings
[WKBD_LAST
];
81 /* defaults domains */
82 WDDomain
*WDWindowMaker
= NULL
;
83 WDDomain
*WDRootMenu
= NULL
;
84 WDDomain
*WDWindowAttributes
= NULL
;
89 XContext wAppWinContext
;
90 XContext wStackContext
;
94 Atom _XA_WM_CHANGE_STATE
;
95 Atom _XA_WM_PROTOCOLS
;
96 Atom _XA_WM_TAKE_FOCUS
;
97 Atom _XA_WM_DELETE_WINDOW
;
98 Atom _XA_WM_SAVE_YOURSELF
;
99 Atom _XA_WM_CLIENT_LEADER
;
100 Atom _XA_WM_COLORMAP_WINDOWS
;
101 Atom _XA_WM_COLORMAP_NOTIFY
;
103 Atom _XA_GNUSTEP_WM_ATTR
;
104 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
105 Atom _XA_GNUSTEP_WM_RESIZEBAR
;
107 Atom _XA_WINDOWMAKER_MENU
;
108 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
109 Atom _XA_WINDOWMAKER_STATE
;
111 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
112 Atom _XA_WINDOWMAKER_NOTICEBOARD
;
113 Atom _XA_WINDOWMAKER_COMMAND
;
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
;
155 extern void EventLoop();
156 extern void StartUp();
163 wSessionDisconnectManager();
172 Restart(char *manager
)
175 char *argv
[MAX_RESTART_ARGS
];
178 if (manager
&& manager
[0]!=0) {
179 prog
= argv
[0] = strtok(manager
, " ");
180 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
181 argv
[i
]=strtok(NULL
, " ");
188 wSessionDisconnectManager();
192 execvp(Arguments
[0], Arguments
);
196 execv(Arguments
[0], Arguments
);
198 wsyserror(_("could not exec window manager"));
199 wfatal(_("Restart failed!!!"));
206 SetupEnvironment(WScreen
*scr
)
211 if (wScreenCount
> 1) {
212 tmp
= wmalloc(strlen(DisplayName
)+64);
213 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
214 ptr
= strchr(strchr(tmp
, ':'), '.');
217 sprintf(buf
, ".%i", scr
->screen
);
222 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
223 scr
->rcontext
->attribs
->colors_per_channel
);
229 *---------------------------------------------------------------------
231 * Do a major cleanup and exit the program
233 *----------------------------------------------------------------------
236 wAbort(Bool dumpCore
)
241 for (i
=0; i
<wScreenCount
; i
++) {
242 scr
= wScreenWithNumber(i
);
246 printf(_("%s aborted.\n"), ProgName
);
257 printf(_("Usage: %s [options]\n"), ProgName
);
258 puts(_("The Window Maker window manager for the X window system"));
260 puts(_(" -display host:dpy display to use"));
262 puts(_(" --no-cpp disable preprocessing of configuration files"));
264 puts(_(" --no-dock do not open the application Dock"));
265 puts(_(" --no-clip do not open the workspace Clip"));
267 puts(_(" --locale locale locale to use"));
269 puts(_(" --visual-id visualid visual id of visual to use"));
270 puts(_(" --static do not update or save configurations"));
272 puts(_(" --synchronous turn on synchronous display mode"));
274 puts(_(" --version print version and exit"));
275 puts(_(" --help show this message"));
285 path
= wdefaultspathfordomain("");
286 if (access(path
, R_OK
)!=0) {
287 wfatal(_("could not find user GNUstep directory (%s).\n"
288 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
302 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
304 if (system(file
) != 0) {
305 wsyserror(_("%s:could not execute initialization script"), file
);
309 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
310 wsyserror(_("%s:could not execute initialization script"), file
);
324 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
326 if (system(file
) != 0) {
327 wsyserror(_("%s:could not execute exit script"), file
);
331 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
332 wsyserror(_("%s:could not execute exit script"), file
);
343 main(int argc
, char **argv
)
346 Bool multiHead
= True
;
358 WMInitializeApplication("WindowMaker", &argc
, argv
);
361 ProgName
= strrchr(argv
[0],'/');
370 memset(&wPreferences
, 0, sizeof(WPreferences
));
373 for (i
=1; i
<argc
; i
++) {
375 if (strcmp(argv
[i
], "-nocpp")==0
376 || strcmp(argv
[i
], "--no-cpp")==0) {
377 wPreferences
.flags
.nocpp
=1;
380 if (strcmp(argv
[i
], "-nodock")==0
381 || strcmp(argv
[i
], "--no-dock")==0) {
382 wPreferences
.flags
.nodock
=1;
383 } else if (strcmp(argv
[i
], "-noclip")==0
384 || strcmp(argv
[i
], "--no-clip")==0) {
385 wPreferences
.flags
.noclip
=1;
386 } else if (strcmp(argv
[i
], "-version")==0
387 || strcmp(argv
[i
], "--version")==0) {
388 printf("Window Maker %s\n", VERSION
);
390 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
394 } else if (strcmp(argv
[i
], "--synchronous")==0) {
397 } else if (strcmp(argv
[i
], "-locale")==0
398 || strcmp(argv
[i
], "--locale")==0) {
401 wwarning(_("too few arguments for %s"), argv
[i
-1]);
405 } else if (strcmp(argv
[i
], "-display")==0) {
408 wwarning(_("too few arguments for %s"), argv
[i
-1]);
411 DisplayName
= argv
[i
];
412 } else if (strcmp(argv
[i
], "-visualid")==0
413 || strcmp(argv
[i
], "--visual-id")==0) {
416 wwarning(_("too few arguments for %s"), argv
[i
-1]);
419 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
420 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
423 } else if (strcmp(argv
[i
], "-static")==0
424 || strcmp(argv
[i
], "--static")==0) {
426 wPreferences
.flags
.noupdates
= 1;
428 } else if (strcmp(argv
[i
], "-clientid")==0
429 || strcmp(argv
[i
], "-restore")==0) {
432 wwarning(_("too few arguments for %s"), argv
[i
-1]);
436 } else if (strcmp(argv
[i
], "--help")==0) {
440 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
441 printf(_("Try '%s --help' for more information\n"), argv
[0]);
447 if (!wPreferences
.flags
.noupdates
) {
448 /* check existence of Defaults DB directory */
453 tmp
= getenv("LANG");
455 if (setlocale(LC_ALL
,"") == NULL
) {
456 wwarning("cannot set locale %s", tmp
);
457 wwarning("falling back to C locale");
458 setlocale(LC_ALL
,"C");
461 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
471 Locale
= getenv("LANG");
473 setlocale(LC_ALL
, Locale
);
474 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
477 if (getenv("NLSPATH"))
478 bindtextdomain("WindowMaker", getenv("NLSPATH"));
480 bindtextdomain("WindowMaker", LOCALEDIR
);
481 textdomain("WindowMaker");
483 if (!XSupportsLocale()) {
484 wwarning(_("X server does not support locale"));
486 if (XSetLocaleModifiers("") == NULL
) {
487 wwarning(_("cannot set locale modifiers"));
494 Locale
= wstrdup(Locale
);
495 ptr
= strchr(Locale
, '.');
502 dpy
= XOpenDisplay(DisplayName
);
504 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
508 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
509 wsyserror("error setting close-on-exec flag for X connection");
513 /* check if the user specified a complete display name (with screen).
514 * If so, only manage the specified screen */
516 str
= strchr(DisplayName
, ':');
520 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
523 DisplayName
= XDisplayName(DisplayName
);
524 str
= wmalloc(strlen(DisplayName
)+64);
525 sprintf(str
, "DISPLAY=%s", DisplayName
);
530 XSynchronize(dpy
, True
);
533 wXModifierInitialize();
536 wSessionConnectManager(argv
, argc
);