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
;
105 Atom _XA_WINDOWMAKER_MENU
;
106 Atom _XA_WINDOWMAKER_WM_PROTOCOLS
;
107 Atom _XA_WINDOWMAKER_STATE
;
109 Atom _XA_WINDOWMAKER_WM_FUNCTION
;
110 Atom _XA_WINDOWMAKER_NOTICEBOARD
;
111 Atom _XA_WINDOWMAKER_COMMAND
;
114 Atom _XA_DND_PROTOCOL
;
115 Atom _XA_DND_SELECTION
;
119 Cursor wCursor
[WCUR_LAST
];
121 /* last event timestamp for XSetInputFocus */
123 /* timestamp on the last time we did XSetInputFocus() */
124 Time LastFocusChange
;
127 Bool wShapeSupported
;
131 #ifdef KEEP_XKB_LOCK_STATUS
137 char WProgramState
= WSTATE_NORMAL
;
138 char WDelayedActionSet
= 0;
140 /* temporary stuff */
144 /******** End Global Variables *****/
146 static char *DisplayName
= NULL
;
148 static char **Arguments
;
152 extern void EventLoop();
153 extern void StartUp();
155 static Bool multiHead
= True
;
157 /* stdi/o for log shell */
158 static int LogStdIn
= -1, LogStdOut
= -1, LogStdErr
= -1;
165 wSessionDisconnectManager();
175 Restart(char *manager
, Bool abortOnFailure
)
178 char *argv
[MAX_RESTART_ARGS
];
181 if (manager
&& manager
[0]!=0) {
182 prog
= argv
[0] = strtok(manager
, " ");
183 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
184 argv
[i
]=strtok(NULL
, " ");
192 wSessionDisconnectManager();
198 execvp(Arguments
[0], Arguments
);
199 wfatal(_("failed to restart Window Maker."));
202 wsyserror(_("could not exec %s"), prog
);
211 SetupEnvironment(WScreen
*scr
)
217 tmp
= wmalloc(strlen(DisplayName
)+64);
218 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
219 ptr
= strchr(strchr(tmp
, ':'), '.');
222 sprintf(buf
, ".%i", scr
->screen
);
227 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
228 scr
->rcontext
->attribs
->colors_per_channel
);
242 shellCommandHandler(pid_t pid
, unsigned char status
, _tuple
*data
)
247 buffer
= wstrappend(_("Could not execute command: "), data
->command
);
249 wMessageDialog(data
->scr
, _("Error"), buffer
, _("OK"), NULL
, NULL
);
251 } else if (status
!= 127) {
253 printf("%s: %i\n", data->command, status);
263 ExecuteShellCommand(WScreen
*scr
, char *command
)
265 static char *shell
= NULL
;
269 * This have a problem: if the shell is tcsh (not sure about others)
270 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
271 * will block and the command will not be executed.
273 shell = getenv("SHELL");
284 SetupEnvironment(scr
);
289 execl(shell
, shell
, "-c", command
, NULL
);
290 wsyserror("could not execute %s -c %s", shell
, command
);
292 } else if (pid
< 0) {
293 wsyserror("cannot fork a new process");
295 _tuple
*data
= wmalloc(sizeof(_tuple
));
298 data
->command
= wstrdup(command
);
300 wAddDeathHandler(pid
, (WDeathHandler
*)shellCommandHandler
, data
);
306 *---------------------------------------------------------------------------
308 * Start a shell that will receive all stdin and stdout from processes
310 *---------------------------------------------------------------------------
313 StartLogShell(WScreen
*scr
)
320 SetupEnvironment(scr
);
322 if (pipe(in_fd
) < 0) {
323 wsyserror("could not create pipe for log shell\n");
326 if (pipe(out_fd
) < 0) {
327 wsyserror("could not create pipe for log shell\n");
332 if (pipe(err_fd
) < 0) {
333 wsyserror("could not create pipe for log shell\n");
343 wsyserror("could not fork a new process for log shell\n");
345 } else if (pid
== 0) {
354 if (dup2(in_fd
[1], 0) < 0) {
355 wsyserror("could not redirect stdin for log shell\n");
358 if (dup2(out_fd
[1], 1) < 0) {
359 wsyserror("could not redirect stdout for log shell\n");
362 if (dup2(err_fd
[1], 2) < 0) {
363 wsyserror("could not redirect stderr for log shell\n");
371 execl("/bin/sh", "/bin/sh", "-c", wPreferences
.logger_shell
, NULL
);
372 wsyserror("could not execute %s\n", wPreferences
.logger_shell
);
380 LogStdOut
= out_fd
[0];
381 LogStdErr
= err_fd
[0];
387 *---------------------------------------------------------------------
389 * Do a major cleanup and exit the program
391 *----------------------------------------------------------------------
394 wAbort(Bool dumpCore
)
399 for (i
=0; i
<wScreenCount
; i
++) {
400 scr
= wScreenWithNumber(i
);
404 printf(_("%s aborted.\n"), ProgName
);
415 printf(_("Usage: %s [options]\n"), ProgName
);
416 puts(_("The Window Maker window manager for the X window system"));
418 puts(_(" -display host:dpy display to use"));
420 puts(_(" --no-cpp disable preprocessing of configuration files"));
422 puts(_(" --no-dock do not open the application Dock"));
423 puts(_(" --no-clip do not open the workspace Clip"));
424 puts(_(" --no-autolaunch do not autolaunch applications"));
426 puts(_(" --locale locale locale to use"));
428 puts(_(" --visual-id visualid visual id of visual to use"));
429 puts(_(" --static do not update or save configurations"));
431 puts(_(" --synchronous turn on synchronous display mode"));
433 puts(_(" --version print version and exit"));
434 puts(_(" --help show this message"));
444 path
= wdefaultspathfordomain("");
445 if (access(path
, R_OK
)!=0) {
446 wfatal(_("could not find user GNUstep directory (%s).\n"
447 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
460 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
462 file
= wfindfile(paths
, DEF_INIT_SCRIPT
);
466 if (system(file
) != 0) {
467 wsyserror(_("%s:could not execute initialization script"), file
);
471 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
472 wsyserror(_("%s:could not execute initialization script"), file
);
485 char *paths
= wstrappend(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
487 file
= wfindfile(paths
, DEF_EXIT_SCRIPT
);
491 if (system(file
) != 0) {
492 wsyserror(_("%s:could not execute exit script"), file
);
496 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
497 wsyserror(_("%s:could not execute exit script"), file
);
507 getFullPath(char *path
)
511 char *basep
= (char*)buffer
;
513 if (*path
!= '/' && getcwd(buffer
, 1023)) {
516 if (strncmp(path
, "../", 3)==0) {
518 basep
= strchr(basep
, '/');
519 if (!basep
|| *path
==0)
523 if (*path
== '/' || strncmp(path
, "./",2)==0) {
536 return wstrappend(path
);
544 main(int argc
, char **argv
)
552 setlocale(LC_ALL
, "");
556 /* for telling WPrefs what's the name of the wmaker binary being ran */
558 str
= wstrappend("WMAKER_BIN_NAME=", argv
[0]);
564 WMInitializeApplication("WindowMaker", &argc
, argv
);
567 ProgName
= strrchr(argv
[0],'/');
576 memset(&wPreferences
, 0, sizeof(WPreferences
));
579 for (i
=1; i
<argc
; i
++) {
581 if (strcmp(argv
[i
], "-nocpp")==0
582 || strcmp(argv
[i
], "--no-cpp")==0) {
583 wPreferences
.flags
.nocpp
=1;
586 if (strcmp(argv
[i
], "-no-autolaunch")==0
587 || strcmp(argv
[i
], "--no-autolaunch")==0) {
588 wPreferences
.flags
.noautolaunch
= 1;
589 } else if (strcmp(argv
[i
], "-nodock")==0
590 || strcmp(argv
[i
], "--no-dock")==0) {
591 wPreferences
.flags
.nodock
=1;
592 } else if (strcmp(argv
[i
], "-noclip")==0
593 || strcmp(argv
[i
], "--no-clip")==0) {
594 wPreferences
.flags
.noclip
=1;
595 } else if (strcmp(argv
[i
], "-version")==0
596 || strcmp(argv
[i
], "--version")==0) {
597 printf("Window Maker %s\n", VERSION
);
599 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
600 printf("%s/WindowMaker\n", SYSCONFDIR
);
603 } else if (strcmp(argv
[i
], "--synchronous")==0) {
606 } else if (strcmp(argv
[i
], "-locale")==0
607 || strcmp(argv
[i
], "--locale")==0) {
610 wwarning(_("too few arguments for %s"), argv
[i
-1]);
614 } else if (strcmp(argv
[i
], "-display")==0) {
617 wwarning(_("too few arguments for %s"), argv
[i
-1]);
620 DisplayName
= argv
[i
];
621 } else if (strcmp(argv
[i
], "-visualid")==0
622 || strcmp(argv
[i
], "--visual-id")==0) {
625 wwarning(_("too few arguments for %s"), argv
[i
-1]);
628 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
629 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
632 } else if (strcmp(argv
[i
], "-static")==0
633 || strcmp(argv
[i
], "--static")==0) {
635 wPreferences
.flags
.noupdates
= 1;
637 } else if (strcmp(argv
[i
], "-clientid")==0
638 || strcmp(argv
[i
], "-restore")==0) {
641 wwarning(_("too few arguments for %s"), argv
[i
-1]);
645 } else if (strcmp(argv
[i
], "--help")==0) {
649 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
650 printf(_("Try '%s --help' for more information\n"), argv
[0]);
656 if (!wPreferences
.flags
.noupdates
) {
657 /* check existence of Defaults DB directory */
663 Locale
= getenv("LC_ALL");
666 Locale
= getenv("LANG");
669 setlocale(LC_ALL
, "");
671 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
674 if (getenv("NLSPATH"))
675 bindtextdomain("WindowMaker", getenv("NLSPATH"));
677 bindtextdomain("WindowMaker", LOCALEDIR
);
678 textdomain("WindowMaker");
680 if (!XSupportsLocale()) {
681 wwarning(_("X server does not support locale"));
684 if (XSetLocaleModifiers("") == NULL
) {
685 wwarning(_("cannot set locale modifiers"));
692 Locale
= wstrdup(Locale
);
693 ptr
= strchr(Locale
, '.');
699 dpy
= XOpenDisplay(DisplayName
);
701 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
705 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
706 wsyserror("error setting close-on-exec flag for X connection");
710 /* check if the user specified a complete display name (with screen).
711 * If so, only manage the specified screen */
713 str
= strchr(DisplayName
, ':');
717 if (str
&& sscanf(str
, "%i.%i", &d
, &s
)==2)
720 DisplayName
= XDisplayName(DisplayName
);
721 str
= wmalloc(strlen(DisplayName
)+64);
722 sprintf(str
, "DISPLAY=%s", DisplayName
);
727 XSynchronize(dpy
, True
);
730 wXModifierInitialize();
733 wSessionConnectManager(argv
, argc
);