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
;
118 Cursor wCursor
[WCUR_LAST
];
120 /* last event timestamp for XSetInputFocus */
122 /* timestamp on the last time we did XSetInputFocus() */
123 Time LastFocusChange
;
126 Bool wShapeSupported
;
130 #ifdef KEEP_XKB_LOCK_STATUS
136 char WProgramState
= WSTATE_NORMAL
;
137 char WDelayedActionSet
= 0;
139 /* temporary stuff */
143 /******** End Global Variables *****/
145 static char *DisplayName
= NULL
;
147 static char **Arguments
;
151 extern void EventLoop();
152 extern void StartUp();
159 wSessionDisconnectManager();
169 Restart(char *manager
, Bool abortOnFailure
)
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
, " ");
186 wSessionDisconnectManager();
192 execvp(Arguments
[0], Arguments
);
193 wfatal(_("failed to restart Window Maker."));
196 wsyserror(_("could not exec %s"), prog
);
205 SetupEnvironment(WScreen
*scr
)
210 if (wScreenCount
> 1) {
211 tmp
= wmalloc(strlen(DisplayName
)+64);
212 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
213 ptr
= strchr(strchr(tmp
, ':'), '.');
216 sprintf(buf
, ".%i", scr
->screen
);
221 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
222 scr
->rcontext
->attribs
->colors_per_channel
);
228 *---------------------------------------------------------------------
230 * Do a major cleanup and exit the program
232 *----------------------------------------------------------------------
235 wAbort(Bool dumpCore
)
240 for (i
=0; i
<wScreenCount
; i
++) {
241 scr
= wScreenWithNumber(i
);
245 printf(_("%s aborted.\n"), ProgName
);
256 printf(_("Usage: %s [options]\n"), ProgName
);
257 puts(_("The Window Maker window manager for the X window system"));
259 puts(_(" -display host:dpy display to use"));
261 puts(_(" --no-cpp disable preprocessing of configuration files"));
263 puts(_(" --no-dock do not open the application Dock"));
264 puts(_(" --no-clip do not open the workspace Clip"));
266 puts(_(" --locale locale locale to use"));
268 puts(_(" --visual-id visualid visual id of visual to use"));
269 puts(_(" --static do not update or save configurations"));
271 puts(_(" --synchronous turn on synchronous display mode"));
273 puts(_(" --version print version and exit"));
274 puts(_(" --help show this message"));
284 path
= wdefaultspathfordomain("");
285 if (access(path
, R_OK
)!=0) {
286 wfatal(_("could not find user GNUstep directory (%s).\n"
287 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
300 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
302 file
= wfindfile(paths
, DEF_INIT_SCRIPT
);
306 if (system(file
) != 0) {
307 wsyserror(_("%s:could not execute initialization script"), file
);
311 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
312 wsyserror(_("%s:could not execute initialization script"), file
);
325 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
327 file
= wfindfile(paths
, DEF_EXIT_SCRIPT
);
331 if (system(file
) != 0) {
332 wsyserror(_("%s:could not execute exit script"), file
);
336 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
337 wsyserror(_("%s:could not execute exit script"), file
);
347 getFullPath(char *path
)
351 char *basep
= (char*)buffer
;
353 if (*path
!= '/' && getcwd(buffer
, 1023)) {
356 if (strncmp(path
, "../", 3)==0) {
358 basep
= strchr(basep
, '/');
359 if (!basep
|| *path
==0)
363 if (*path
== '/' || strncmp(path
, "./",2)==0) {
376 return wstrappend(path
);
384 main(int argc
, char **argv
)
387 Bool multiHead
= True
;
396 /* for telling WPrefs what's the name of the wmaker binary being ran */
400 tmp = getFullPath(argv[0]);*/
401 str
= wstrappend("WMAKER_BIN_NAME=", argv
[0]);
409 WMInitializeApplication("WindowMaker", &argc
, argv
);
412 ProgName
= strrchr(argv
[0],'/');
421 memset(&wPreferences
, 0, sizeof(WPreferences
));
424 for (i
=1; i
<argc
; i
++) {
426 if (strcmp(argv
[i
], "-nocpp")==0
427 || strcmp(argv
[i
], "--no-cpp")==0) {
428 wPreferences
.flags
.nocpp
=1;
431 if (strcmp(argv
[i
], "-nodock")==0
432 || strcmp(argv
[i
], "--no-dock")==0) {
433 wPreferences
.flags
.nodock
=1;
434 } else if (strcmp(argv
[i
], "-noclip")==0
435 || strcmp(argv
[i
], "--no-clip")==0) {
436 wPreferences
.flags
.noclip
=1;
437 } else if (strcmp(argv
[i
], "-version")==0
438 || strcmp(argv
[i
], "--version")==0) {
439 printf("Window Maker %s\n", VERSION
);
441 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
442 printf("%s/WindowMaker\n", SYSCONFDIR
);
445 } else if (strcmp(argv
[i
], "--synchronous")==0) {
448 } else if (strcmp(argv
[i
], "-locale")==0
449 || strcmp(argv
[i
], "--locale")==0) {
452 wwarning(_("too few arguments for %s"), argv
[i
-1]);
456 } else if (strcmp(argv
[i
], "-display")==0) {
459 wwarning(_("too few arguments for %s"), argv
[i
-1]);
462 DisplayName
= argv
[i
];
463 } else if (strcmp(argv
[i
], "-visualid")==0
464 || strcmp(argv
[i
], "--visual-id")==0) {
467 wwarning(_("too few arguments for %s"), argv
[i
-1]);
470 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
471 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
474 } else if (strcmp(argv
[i
], "-static")==0
475 || strcmp(argv
[i
], "--static")==0) {
477 wPreferences
.flags
.noupdates
= 1;
479 } else if (strcmp(argv
[i
], "-clientid")==0
480 || strcmp(argv
[i
], "-restore")==0) {
483 wwarning(_("too few arguments for %s"), argv
[i
-1]);
487 } else if (strcmp(argv
[i
], "--help")==0) {
491 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
492 printf(_("Try '%s --help' for more information\n"), argv
[0]);
498 if (!wPreferences
.flags
.noupdates
) {
499 /* check existence of Defaults DB directory */
504 tmp
= getenv("LANG");
506 if (setlocale(LC_ALL
,"") == NULL
) {
507 wwarning("cannot set locale %s", tmp
);
508 wwarning("falling back to C locale");
509 setlocale(LC_ALL
,"C");
512 if (strcmp(tmp
, "C")==0 || strcmp(tmp
, "POSIX")==0)
522 Locale
= getenv("LANG");
524 setlocale(LC_ALL
, Locale
);
525 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
528 if (getenv("NLSPATH"))
529 bindtextdomain("WindowMaker", getenv("NLSPATH"));
531 bindtextdomain("WindowMaker", LOCALEDIR
);
532 textdomain("WindowMaker");
534 if (!XSupportsLocale()) {
535 wwarning(_("X server does not support locale"));
537 if (XSetLocaleModifiers("") == NULL
) {
538 wwarning(_("cannot set locale modifiers"));
545 Locale
= wstrdup(Locale
);
546 ptr
= strchr(Locale
, '.');
553 dpy
= XOpenDisplay(DisplayName
);
555 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
559 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
560 wsyserror("error setting close-on-exec flag for X connection");
564 /* check if the user specified a complete display name (with screen).
565 * If so, only manage the specified screen */
567 str
= strchr(DisplayName
, ':');
571 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
574 DisplayName
= XDisplayName(DisplayName
);
575 str
= wmalloc(strlen(DisplayName
)+64);
576 sprintf(str
, "DISPLAY=%s", DisplayName
);
581 XSynchronize(dpy
, True
);
584 wXModifierInitialize();
587 wSessionConnectManager(argv
, argc
);