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"
56 /****** Global Variables ******/
64 unsigned int ValidModMask
= 0xff;
66 /* locale to use. NULL==POSIX or C */
71 WPreferences wPreferences
;
74 proplist_t wDomainName
;
75 proplist_t wAttributeDomainName
;
77 WShortKey wKeyBindings
[WKBD_LAST
];
79 /* defaults domains */
80 WDDomain
*WDWindowMaker
= NULL
;
81 WDDomain
*WDRootMenu
= NULL
;
82 WDDomain
*WDWindowAttributes
= NULL
;
87 XContext wAppWinContext
;
88 XContext wStackContext
;
92 Atom _XA_WM_CHANGE_STATE
;
93 Atom _XA_WM_PROTOCOLS
;
94 Atom _XA_WM_TAKE_FOCUS
;
95 Atom _XA_WM_DELETE_WINDOW
;
96 Atom _XA_WM_SAVE_YOURSELF
;
97 Atom _XA_WM_CLIENT_LEADER
;
98 Atom _XA_WM_COLORMAP_WINDOWS
;
99 Atom _XA_WM_COLORMAP_NOTIFY
;
101 Atom _XA_GNUSTEP_WM_ATTR
;
102 Atom _XA_GNUSTEP_WM_MINIATURIZE_WINDOW
;
103 Atom _XA_GNUSTEP_WM_RESIZEBAR
;
104 Atom _XA_GNUSTEP_TITLEBAR_STATE
;
106 Atom _XA_WINDOWMAKER_MENU
;
107 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
108 Atom _XA_WINDOWMAKER_STATE
;
110 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
111 Atom _XA_WINDOWMAKER_NOTICEBOARD
;
112 Atom _XA_WINDOWMAKER_COMMAND
;
114 Atom _XA_WINDOWMAKER_ICON_SIZE
;
115 Atom _XA_WINDOWMAKER_ICON_TILE
;
119 Atom _XA_DND_PROTOCOL
;
120 Atom _XA_DND_SELECTION
;
124 Cursor wCursor
[WCUR_LAST
];
126 /* last event timestamp for XSetInputFocus */
128 /* timestamp on the last time we did XSetInputFocus() */
129 Time LastFocusChange
;
132 Bool wShapeSupported
;
136 #ifdef KEEP_XKB_LOCK_STATUS
142 char WProgramState
= WSTATE_NORMAL
;
143 char WDelayedActionSet
= 0;
145 /* temporary stuff */
149 /******** End Global Variables *****/
151 static char *DisplayName
= NULL
;
153 static char **Arguments
;
157 extern void EventLoop();
158 extern void StartUp();
160 static Bool multiHead
= True
;
162 /* stdi/o for log shell */
163 static int LogStdIn
= -1, LogStdOut
= -1, LogStdErr
= -1;
170 wSessionDisconnectManager();
180 Restart(char *manager
, Bool abortOnFailure
)
183 char *argv
[MAX_RESTART_ARGS
];
186 if (manager
&& manager
[0]!=0) {
187 prog
= argv
[0] = strtok(manager
, " ");
188 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
189 argv
[i
]=strtok(NULL
, " ");
197 wSessionDisconnectManager();
203 execvp(Arguments
[0], Arguments
);
204 wfatal(_("failed to restart Window Maker."));
207 wsyserror(_("could not exec %s"), prog
);
216 SetupEnvironment(WScreen
*scr
)
222 tmp
= wmalloc(strlen(DisplayName
)+64);
223 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
224 ptr
= strchr(strchr(tmp
, ':'), '.');
227 sprintf(buf
, ".%i", scr
->screen
);
232 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
233 scr
->rcontext
->attribs
->colors_per_channel
);
247 shellCommandHandler(pid_t pid
, unsigned char status
, _tuple
*data
)
252 buffer
= wstrappend(_("Could not execute command: "), data
->command
);
254 wMessageDialog(data
->scr
, _("Error"), buffer
, _("OK"), NULL
, NULL
);
256 } else if (status
!= 127) {
258 printf("%s: %i\n", data->command, status);
268 ExecuteShellCommand(WScreen
*scr
, char *command
)
270 static char *shell
= NULL
;
274 * This have a problem: if the shell is tcsh (not sure about others)
275 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
276 * will block and the command will not be executed.
278 shell = getenv("SHELL");
289 SetupEnvironment(scr
);
294 execl(shell
, shell
, "-c", command
, NULL
);
295 wsyserror("could not execute %s -c %s", shell
, command
);
297 } else if (pid
< 0) {
298 wsyserror("cannot fork a new process");
300 _tuple
*data
= wmalloc(sizeof(_tuple
));
303 data
->command
= wstrdup(command
);
305 wAddDeathHandler(pid
, (WDeathHandler
*)shellCommandHandler
, data
);
311 *---------------------------------------------------------------------------
313 * Start a shell that will receive all stdin and stdout from processes
315 *---------------------------------------------------------------------------
318 StartLogShell(WScreen
*scr
)
325 SetupEnvironment(scr
);
327 if (pipe(in_fd
) < 0) {
328 wsyserror("could not create pipe for log shell\n");
331 if (pipe(out_fd
) < 0) {
332 wsyserror("could not create pipe for log shell\n");
337 if (pipe(err_fd
) < 0) {
338 wsyserror("could not create pipe for log shell\n");
348 wsyserror("could not fork a new process for log shell\n");
350 } else if (pid
== 0) {
359 if (dup2(in_fd
[1], 0) < 0) {
360 wsyserror("could not redirect stdin for log shell\n");
363 if (dup2(out_fd
[1], 1) < 0) {
364 wsyserror("could not redirect stdout for log shell\n");
367 if (dup2(err_fd
[1], 2) < 0) {
368 wsyserror("could not redirect stderr for log shell\n");
376 execl("/bin/sh", "/bin/sh", "-c", wPreferences
.logger_shell
, NULL
);
377 wsyserror("could not execute %s\n", wPreferences
.logger_shell
);
385 LogStdOut
= out_fd
[0];
386 LogStdErr
= err_fd
[0];
392 *---------------------------------------------------------------------
394 * Do a major cleanup and exit the program
396 *----------------------------------------------------------------------
399 wAbort(Bool dumpCore
)
404 for (i
=0; i
<wScreenCount
; i
++) {
405 scr
= wScreenWithNumber(i
);
409 printf(_("%s aborted.\n"), ProgName
);
420 printf(_("Usage: %s [options]\n"), ProgName
);
421 puts(_("The Window Maker window manager for the X window system"));
423 puts(_(" -display host:dpy display to use"));
425 puts(_(" --no-cpp disable preprocessing of configuration files"));
427 puts(_(" --no-dock do not open the application Dock"));
428 puts(_(" --no-clip do not open the workspace Clip"));
429 puts(_(" --no-autolaunch do not autolaunch applications"));
430 puts(_(" --dont-restore do not restore saved session"));
432 puts(_(" --locale locale locale to use"));
434 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
435 puts(_(" --visual-id visualid visual id of visual to use"));
436 puts(_(" --static do not update or save configurations"));
438 puts(_(" --synchronous turn on synchronous display mode"));
440 puts(_(" --version print version and exit"));
441 puts(_(" --help show this message"));
451 path
= wdefaultspathfordomain("");
452 if (access(path
, R_OK
)!=0) {
453 wfatal(_("could not find user GNUstep directory (%s).\n"
454 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
467 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
469 file
= wfindfile(paths
, DEF_INIT_SCRIPT
);
473 if (system(file
) != 0) {
474 wsyserror(_("%s:could not execute initialization script"), file
);
478 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
479 wsyserror(_("%s:could not execute initialization script"), file
);
492 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
494 file
= wfindfile(paths
, DEF_EXIT_SCRIPT
);
498 if (system(file
) != 0) {
499 wsyserror(_("%s:could not execute exit script"), file
);
503 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
504 wsyserror(_("%s:could not execute exit script"), file
);
514 getFullPath(char *path
)
518 char *basep
= (char*)buffer
;
520 if (*path
!= '/' && getcwd(buffer
, 1023)) {
523 if (strncmp(path
, "../", 3)==0) {
525 basep
= strchr(basep
, '/');
526 if (!basep
|| *path
==0)
530 if (*path
== '/' || strncmp(path
, "./",2)==0) {
543 return wstrappend(path
);
551 main(int argc
, char **argv
)
559 setlocale(LC_ALL
, "");
563 /* for telling WPrefs what's the name of the wmaker binary being ran */
565 str
= wstrappend("WMAKER_BIN_NAME=", argv
[0]);
571 WMInitializeApplication("WindowMaker", &argc
, argv
);
574 ProgName
= strrchr(argv
[0],'/');
583 memset(&wPreferences
, 0, sizeof(WPreferences
));
586 for (i
=1; i
<argc
; i
++) {
588 if (strcmp(argv
[i
], "-nocpp")==0
589 || strcmp(argv
[i
], "--no-cpp")==0) {
590 wPreferences
.flags
.nocpp
=1;
593 if (strcmp(argv
[i
], "-no-autolaunch")==0
594 || strcmp(argv
[i
], "--no-autolaunch")==0) {
595 wPreferences
.flags
.noautolaunch
= 1;
596 } else if (strcmp(argv
[i
], "-dont-restore")==0
597 || strcmp(argv
[i
], "--dont-restore")==0) {
598 wPreferences
.flags
.norestore
= 1;
599 } else if (strcmp(argv
[i
], "-nodock")==0
600 || strcmp(argv
[i
], "--no-dock")==0) {
601 wPreferences
.flags
.nodock
=1;
602 } else if (strcmp(argv
[i
], "-noclip")==0
603 || strcmp(argv
[i
], "--no-clip")==0) {
604 wPreferences
.flags
.noclip
=1;
605 } else if (strcmp(argv
[i
], "-version")==0
606 || strcmp(argv
[i
], "--version")==0) {
607 printf("Window Maker %s\n", VERSION
);
609 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
610 printf("%s/WindowMaker\n", SYSCONFDIR
);
613 } else if (strcmp(argv
[i
], "--synchronous")==0) {
616 } else if (strcmp(argv
[i
], "-locale")==0
617 || strcmp(argv
[i
], "--locale")==0) {
620 wwarning(_("too few arguments for %s"), argv
[i
-1]);
624 } else if (strcmp(argv
[i
], "-display")==0) {
627 wwarning(_("too few arguments for %s"), argv
[i
-1]);
630 DisplayName
= argv
[i
];
631 } else if (strcmp(argv
[i
], "-visualid")==0
632 || strcmp(argv
[i
], "--visual-id")==0) {
635 wwarning(_("too few arguments for %s"), argv
[i
-1]);
638 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
639 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
642 } else if (strcmp(argv
[i
], "-static")==0
643 || strcmp(argv
[i
], "--static")==0) {
645 wPreferences
.flags
.noupdates
= 1;
647 } else if (strcmp(argv
[i
], "-clientid")==0
648 || strcmp(argv
[i
], "-restore")==0) {
651 wwarning(_("too few arguments for %s"), argv
[i
-1]);
655 } else if (strcmp(argv
[i
], "--help")==0) {
659 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
660 printf(_("Try '%s --help' for more information\n"), argv
[0]);
666 if (!wPreferences
.flags
.noupdates
) {
667 /* check existence of Defaults DB directory */
673 Locale
= getenv("LC_ALL");
676 Locale
= getenv("LANG");
679 setlocale(LC_ALL
, "");
681 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
684 if (getenv("NLSPATH"))
685 bindtextdomain("WindowMaker", getenv("NLSPATH"));
687 bindtextdomain("WindowMaker", LOCALEDIR
);
688 textdomain("WindowMaker");
690 if (!XSupportsLocale()) {
691 wwarning(_("X server does not support locale"));
694 if (XSetLocaleModifiers("") == NULL
) {
695 wwarning(_("cannot set locale modifiers"));
702 Locale
= wstrdup(Locale
);
703 ptr
= strchr(Locale
, '.');
709 dpy
= XOpenDisplay(DisplayName
);
711 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
715 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
716 wsyserror("error setting close-on-exec flag for X connection");
720 /* check if the user specified a complete display name (with screen).
721 * If so, only manage the specified screen */
723 str
= strchr(DisplayName
, ':');
727 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
730 DisplayName
= XDisplayName(DisplayName
);
731 str
= wmalloc(strlen(DisplayName
)+64);
732 sprintf(str
, "DISPLAY=%s", DisplayName
);
737 XSynchronize(dpy
, True
);
740 wXModifierInitialize();
743 wSessionConnectManager(argv
, argc
);