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 ******/
63 unsigned int ValidModMask
= 0xff;
65 /* 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
;
104 Atom _XA_WINDOWMAKER_MENU
;
105 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
106 Atom _XA_WINDOWMAKER_STATE
;
108 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
109 Atom _XA_WINDOWMAKER_NOTICEBOARD
;
110 Atom _XA_WINDOWMAKER_COMMAND
;
113 Atom _XA_DND_PROTOCOL
;
114 Atom _XA_DND_SELECTION
;
117 Atom _XA_XDE_REQUEST
;
120 Atom _XA_XDE_DATA_AVAILABLE
;
127 Cursor wCursor
[WCUR_LAST
];
129 /* last event timestamp for XSetInputFocus */
131 /* timestamp on the last time we did XSetInputFocus() */
132 Time LastFocusChange
;
135 Bool wShapeSupported
;
141 char WProgramState
= WSTATE_NORMAL
;
142 char WDelayedActionSet
= 0;
144 /* temporary stuff */
148 /******** End Global Variables *****/
150 static char *DisplayName
= NULL
;
152 static char **Arguments
;
156 extern void EventLoop();
157 extern void StartUp();
164 wSessionDisconnectManager();
174 Restart(char *manager
, Bool abortOnFailure
)
177 char *argv
[MAX_RESTART_ARGS
];
180 if (manager
&& manager
[0]!=0) {
181 prog
= argv
[0] = strtok(manager
, " ");
182 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
183 argv
[i
]=strtok(NULL
, " ");
191 wSessionDisconnectManager();
197 execvp(Arguments
[0], Arguments
);
198 wfatal(_("failed to restart Window Maker."));
201 wsyserror(_("could not exec %s"), prog
);
210 SetupEnvironment(WScreen
*scr
)
215 if (wScreenCount
> 1) {
216 tmp
= wmalloc(strlen(DisplayName
)+64);
217 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
218 ptr
= strchr(strchr(tmp
, ':'), '.');
221 sprintf(buf
, ".%i", scr
->screen
);
226 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
227 scr
->rcontext
->attribs
->colors_per_channel
);
233 *---------------------------------------------------------------------
235 * Do a major cleanup and exit the program
237 *----------------------------------------------------------------------
240 wAbort(Bool dumpCore
)
245 for (i
=0; i
<wScreenCount
; i
++) {
246 scr
= wScreenWithNumber(i
);
250 printf(_("%s aborted.\n"), ProgName
);
261 printf(_("Usage: %s [options]\n"), ProgName
);
262 puts(_("The Window Maker window manager for the X window system"));
264 puts(_(" -display host:dpy display to use"));
266 puts(_(" --no-cpp disable preprocessing of configuration files"));
268 puts(_(" --no-dock do not open the application Dock"));
269 puts(_(" --no-clip do not open the workspace Clip"));
271 puts(_(" --locale locale locale to use"));
273 puts(_(" --visual-id visualid visual id of visual to use"));
274 puts(_(" --static do not update or save configurations"));
276 puts(_(" --synchronous turn on synchronous display mode"));
278 puts(_(" --version print version and exit"));
279 puts(_(" --help show this message"));
289 path
= wdefaultspathfordomain("");
290 if (access(path
, R_OK
)!=0) {
291 wfatal(_("could not find user GNUstep directory (%s).\n"
292 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
306 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_INIT_SCRIPT
);
308 if (system(file
) != 0) {
309 wsyserror(_("%s:could not execute initialization script"), file
);
313 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
314 wsyserror(_("%s:could not execute initialization script"), file
);
328 file
= wfindfile(DEF_CONFIG_PATHS
, DEF_EXIT_SCRIPT
);
330 if (system(file
) != 0) {
331 wsyserror(_("%s:could not execute exit script"), file
);
335 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
336 wsyserror(_("%s:could not execute exit script"), file
);
347 main(int argc
, char **argv
)
350 Bool multiHead
= True
;
362 WMInitializeApplication("WindowMaker", &argc
, argv
);
365 ProgName
= strrchr(argv
[0],'/');
374 memset(&wPreferences
, 0, sizeof(WPreferences
));
377 for (i
=1; i
<argc
; i
++) {
379 if (strcmp(argv
[i
], "-nocpp")==0
380 || strcmp(argv
[i
], "--no-cpp")==0) {
381 wPreferences
.flags
.nocpp
=1;
384 if (strcmp(argv
[i
], "-nodock")==0
385 || strcmp(argv
[i
], "--no-dock")==0) {
386 wPreferences
.flags
.nodock
=1;
387 } else if (strcmp(argv
[i
], "-noclip")==0
388 || strcmp(argv
[i
], "--no-clip")==0) {
389 wPreferences
.flags
.noclip
=1;
390 } else if (strcmp(argv
[i
], "-version")==0
391 || strcmp(argv
[i
], "--version")==0) {
392 printf("Window Maker %s\n", VERSION
);
394 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
398 } else if (strcmp(argv
[i
], "--synchronous")==0) {
401 } else if (strcmp(argv
[i
], "-locale")==0
402 || strcmp(argv
[i
], "--locale")==0) {
405 wwarning(_("too few arguments for %s"), argv
[i
-1]);
409 } else if (strcmp(argv
[i
], "-display")==0) {
412 wwarning(_("too few arguments for %s"), argv
[i
-1]);
415 DisplayName
= argv
[i
];
416 } else if (strcmp(argv
[i
], "-visualid")==0
417 || strcmp(argv
[i
], "--visual-id")==0) {
420 wwarning(_("too few arguments for %s"), argv
[i
-1]);
423 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
424 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
427 } else if (strcmp(argv
[i
], "-static")==0
428 || strcmp(argv
[i
], "--static")==0) {
430 wPreferences
.flags
.noupdates
= 1;
432 } else if (strcmp(argv
[i
], "-clientid")==0
433 || strcmp(argv
[i
], "-restore")==0) {
436 wwarning(_("too few arguments for %s"), argv
[i
-1]);
440 } else if (strcmp(argv
[i
], "--help")==0) {
444 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
445 printf(_("Try '%s --help' for more information\n"), argv
[0]);
451 if (!wPreferences
.flags
.noupdates
) {
452 /* check existence of Defaults DB directory */
457 tmp
= getenv("LANG");
459 if (setlocale(LC_ALL
,"") == NULL
) {
460 wwarning("cannot set locale %s", tmp
);
461 wwarning("falling back to C locale");
462 setlocale(LC_ALL
,"C");
465 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
475 Locale
= getenv("LANG");
477 setlocale(LC_ALL
, Locale
);
478 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
481 if (getenv("NLSPATH"))
482 bindtextdomain("WindowMaker", getenv("NLSPATH"));
484 bindtextdomain("WindowMaker", LOCALEDIR
);
485 textdomain("WindowMaker");
487 if (!XSupportsLocale()) {
488 wwarning(_("X server does not support locale"));
490 if (XSetLocaleModifiers("") == NULL
) {
491 wwarning(_("cannot set locale modifiers"));
498 Locale
= wstrdup(Locale
);
499 ptr
= strchr(Locale
, '.');
506 dpy
= XOpenDisplay(DisplayName
);
508 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
512 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
513 wsyserror("error setting close-on-exec flag for X connection");
517 /* check if the user specified a complete display name (with screen).
518 * If so, only manage the specified screen */
520 str
= strchr(DisplayName
, ':');
524 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
527 DisplayName
= XDisplayName(DisplayName
);
528 str
= wmalloc(strlen(DisplayName
)+64);
529 sprintf(str
, "DISPLAY=%s", DisplayName
);
534 XSynchronize(dpy
, True
);
537 wXModifierInitialize();
540 wSessionConnectManager(argv
, argc
);