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
*WDWindowAttributes
= NULL
;
82 WDDomain
*WDRootMenu
= 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
;
103 Atom _XA_GNUSTEP_TITLEBAR_STATE
;
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
;
113 Atom _XA_WINDOWMAKER_ICON_SIZE
;
114 Atom _XA_WINDOWMAKER_ICON_TILE
;
118 Atom _XA_DND_PROTOCOL
;
119 Atom _XA_DND_SELECTION
;
123 Cursor wCursor
[WCUR_LAST
];
125 /* last event timestamp for XSetInputFocus */
127 /* timestamp on the last time we did XSetInputFocus() */
128 Time LastFocusChange
;
131 Bool wShapeSupported
;
135 #ifdef KEEP_XKB_LOCK_STATUS
141 char WProgramSigState
= 0;
142 char WProgramState
= WSTATE_NORMAL
;
143 char WDelayedActionSet
= 0;
146 /* temporary stuff */
150 /******** End Global Variables *****/
152 static char *DisplayName
= NULL
;
154 static char **Arguments
;
158 extern void EventLoop();
159 extern void StartUp();
161 static Bool multiHead
= True
;
163 /* stdi/o for log shell */
164 static int LogStdIn
= -1, LogStdOut
= -1, LogStdErr
= -1;
171 wSessionDisconnectManager();
181 Restart(char *manager
, Bool abortOnFailure
)
184 char *argv
[MAX_RESTART_ARGS
];
187 if (manager
&& manager
[0]!=0) {
188 prog
= argv
[0] = strtok(manager
, " ");
189 for (i
=1; i
<MAX_RESTART_ARGS
; i
++) {
190 argv
[i
]=strtok(NULL
, " ");
198 wSessionDisconnectManager();
204 execvp(Arguments
[0], Arguments
);
205 wfatal(_("failed to restart Window Maker."));
208 wsyserror(_("could not exec %s"), prog
);
217 SetupEnvironment(WScreen
*scr
)
223 tmp
= wmalloc(strlen(DisplayName
)+64);
224 sprintf(tmp
, "DISPLAY=%s", XDisplayName(DisplayName
));
225 ptr
= strchr(strchr(tmp
, ':'), '.');
228 sprintf(buf
, ".%i", scr
->screen
);
233 sprintf(tmp
, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
234 scr
->rcontext
->attribs
->colors_per_channel
);
248 shellCommandHandler(pid_t pid
, unsigned char status
, _tuple
*data
)
253 buffer
= wstrconcat(_("Could not execute command: "), data
->command
);
255 wMessageDialog(data
->scr
, _("Error"), buffer
, _("OK"), NULL
, NULL
);
257 } else if (status
!= 127) {
259 printf("%s: %i\n", data->command, status);
263 wfree(data
->command
);
269 ExecuteShellCommand(WScreen
*scr
, char *command
)
271 static char *shell
= NULL
;
275 * This have a problem: if the shell is tcsh (not sure about others)
276 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
277 * will block and the command will not be executed.
279 shell = getenv("SHELL");
290 SetupEnvironment(scr
);
295 execl(shell
, shell
, "-c", command
, NULL
);
296 wsyserror("could not execute %s -c %s", shell
, command
);
298 } else if (pid
< 0) {
299 wsyserror("cannot fork a new process");
301 _tuple
*data
= wmalloc(sizeof(_tuple
));
304 data
->command
= wstrdup(command
);
306 wAddDeathHandler(pid
, (WDeathHandler
*)shellCommandHandler
, data
);
312 *---------------------------------------------------------------------------
314 * Start a shell that will receive all stdin and stdout from processes
316 *---------------------------------------------------------------------------
319 StartLogShell(WScreen
*scr
)
326 SetupEnvironment(scr
);
328 if (pipe(in_fd
) < 0) {
329 wsyserror("could not create pipe for log shell\n");
332 if (pipe(out_fd
) < 0) {
333 wsyserror("could not create pipe for log shell\n");
338 if (pipe(err_fd
) < 0) {
339 wsyserror("could not create pipe for log shell\n");
349 wsyserror("could not fork a new process for log shell\n");
351 } else if (pid
== 0) {
360 if (dup2(in_fd
[1], 0) < 0) {
361 wsyserror("could not redirect stdin for log shell\n");
364 if (dup2(out_fd
[1], 1) < 0) {
365 wsyserror("could not redirect stdout for log shell\n");
368 if (dup2(err_fd
[1], 2) < 0) {
369 wsyserror("could not redirect stderr for log shell\n");
377 execl("/bin/sh", "/bin/sh", "-c", wPreferences
.logger_shell
, NULL
);
378 wsyserror("could not execute %s\n", wPreferences
.logger_shell
);
386 LogStdOut
= out_fd
[0];
387 LogStdErr
= err_fd
[0];
393 *---------------------------------------------------------------------
395 * Do a major cleanup and exit the program
397 *----------------------------------------------------------------------
400 wAbort(Bool dumpCore
)
405 for (i
=0; i
<wScreenCount
; i
++) {
406 scr
= wScreenWithNumber(i
);
410 printf(_("%s aborted.\n"), ProgName
);
421 printf(_("Usage: %s [options]\n"), ProgName
);
422 puts(_("The Window Maker window manager for the X window system"));
424 puts(_(" -display host:dpy display to use"));
426 puts(_(" --no-cpp disable preprocessing of configuration files"));
428 puts(_(" --no-dock do not open the application Dock"));
429 puts(_(" --no-clip do not open the workspace Clip"));
430 puts(_(" --no-autolaunch do not autolaunch applications"));
431 puts(_(" --dont-restore do not restore saved session"));
433 puts(_(" --locale locale locale to use"));
435 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
436 puts(_(" --visual-id visualid visual id of visual to use"));
437 puts(_(" --static do not update or save configurations"));
438 puts(_(" --no-polling do not periodically check for configuration updates"));
440 puts(_(" --synchronous turn on synchronous display mode"));
442 puts(_(" --version print version and exit"));
443 puts(_(" --help show this message"));
453 path
= wdefaultspathfordomain("");
454 if (access(path
, R_OK
)!=0) {
455 wfatal(_("could not find user GNUstep directory (%s).\n"
456 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
469 char *paths
= wstrconcat(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
471 file
= wfindfile(paths
, DEF_INIT_SCRIPT
);
475 if (system(file
) != 0) {
476 wsyserror(_("%s:could not execute initialization script"), file
);
480 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
481 wsyserror(_("%s:could not execute initialization script"), file
);
494 char *paths
= wstrconcat(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
496 file
= wfindfile(paths
, DEF_EXIT_SCRIPT
);
500 if (system(file
) != 0) {
501 wsyserror(_("%s:could not execute exit script"), file
);
505 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
506 wsyserror(_("%s:could not execute exit script"), file
);
516 getFullPath(char *path
)
520 char *basep
= (char*)buffer
;
522 if (*path
!= '/' && getcwd(buffer
, 1023)) {
525 if (strncmp(path
, "../", 3)==0) {
527 basep
= strchr(basep
, '/');
528 if (!basep
|| *path
==0)
532 if (*path
== '/' || strncmp(path
, "./",2)==0) {
545 return wstrconcat(path
);
553 main(int argc
, char **argv
)
561 setlocale(LC_ALL
, "");
565 /* for telling WPrefs what's the name of the wmaker binary being ran */
567 str
= wstrconcat("WMAKER_BIN_NAME=", argv
[0]);
573 WMInitializeApplication("WindowMaker", &argc
, argv
);
576 ProgName
= strrchr(argv
[0],'/');
585 memset(&wPreferences
, 0, sizeof(WPreferences
));
588 for (i
=1; i
<argc
; i
++) {
590 if (strcmp(argv
[i
], "-nocpp")==0
591 || strcmp(argv
[i
], "--no-cpp")==0) {
592 wPreferences
.flags
.nocpp
=1;
595 if (strcmp(argv
[i
], "-no-autolaunch")==0
596 || strcmp(argv
[i
], "--no-autolaunch")==0) {
597 wPreferences
.flags
.noautolaunch
= 1;
598 } else if (strcmp(argv
[i
], "-dont-restore")==0
599 || strcmp(argv
[i
], "--dont-restore")==0) {
600 wPreferences
.flags
.norestore
= 1;
601 } else if (strcmp(argv
[i
], "-nodock")==0
602 || strcmp(argv
[i
], "--no-dock")==0) {
603 wPreferences
.flags
.nodock
=1;
604 } else if (strcmp(argv
[i
], "-noclip")==0
605 || strcmp(argv
[i
], "--no-clip")==0) {
606 wPreferences
.flags
.noclip
=1;
607 } else if (strcmp(argv
[i
], "-version")==0
608 || strcmp(argv
[i
], "--version")==0) {
609 printf("Window Maker %s\n", VERSION
);
611 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
612 printf("%s/WindowMaker\n", SYSCONFDIR
);
615 } else if (strcmp(argv
[i
], "--synchronous")==0) {
618 } else if (strcmp(argv
[i
], "-locale")==0
619 || strcmp(argv
[i
], "--locale")==0) {
622 wwarning(_("too few arguments for %s"), argv
[i
-1]);
626 } else if (strcmp(argv
[i
], "-display")==0
627 || strcmp(argv
[i
], "--display")==0) {
630 wwarning(_("too few arguments for %s"), argv
[i
-1]);
633 DisplayName
= argv
[i
];
634 } else if (strcmp(argv
[i
], "-visualid")==0
635 || strcmp(argv
[i
], "--visual-id")==0) {
638 wwarning(_("too few arguments for %s"), argv
[i
-1]);
641 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
642 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
645 } else if (strcmp(argv
[i
], "-static")==0
646 || strcmp(argv
[i
], "--static")==0) {
648 wPreferences
.flags
.noupdates
= 1;
649 } else if (strcmp(argv
[i
], "-nopolling")==0
650 || strcmp(argv
[i
], "--no-polling")==0) {
652 wPreferences
.flags
.nopolling
= 1;
654 } else if (strcmp(argv
[i
], "-clientid")==0
655 || strcmp(argv
[i
], "-restore")==0) {
658 wwarning(_("too few arguments for %s"), argv
[i
-1]);
662 } else if (strcmp(argv
[i
], "--help")==0) {
666 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
667 printf(_("Try '%s --help' for more information\n"), argv
[0]);
673 if (!wPreferences
.flags
.noupdates
) {
674 /* check existence of Defaults DB directory */
680 Locale
= getenv("LC_ALL");
683 Locale
= getenv("LANG");
686 setlocale(LC_ALL
, "");
688 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
691 if (getenv("NLSPATH"))
692 bindtextdomain("WindowMaker", getenv("NLSPATH"));
694 bindtextdomain("WindowMaker", LOCALEDIR
);
695 textdomain("WindowMaker");
697 if (!XSupportsLocale()) {
698 wwarning(_("X server does not support locale"));
701 if (XSetLocaleModifiers("") == NULL
) {
702 wwarning(_("cannot set locale modifiers"));
709 Locale
= wstrdup(Locale
);
710 ptr
= strchr(Locale
, '.');
716 dpy
= XOpenDisplay(DisplayName
);
718 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
722 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
723 wsyserror("error setting close-on-exec flag for X connection");
727 /* check if the user specified a complete display name (with screen).
728 * If so, only manage the specified screen */
730 str
= strchr(DisplayName
, ':');
734 if (str
&& sscanf(str
, ":%i.%i", &d
, &s
)==2)
737 DisplayName
= XDisplayName(DisplayName
);
738 str
= wmalloc(strlen(DisplayName
)+64);
739 sprintf(str
, "DISPLAY=%s", DisplayName
);
744 XSynchronize(dpy
, True
);
747 wXModifierInitialize();
750 wSessionConnectManager(argv
, argc
);