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 int len
= strlen(DisplayName
)+64;
225 snprintf(tmp
, len
, "DISPLAY=%s", XDisplayName(DisplayName
));
226 ptr
= strchr(strchr(tmp
, ':'), '.');
229 snprintf(buf
, sizeof(buf
), ".%i", scr
->screen
);
234 snprintf(tmp
, 60, "WRASTER_COLOR_RESOLUTION%i=%i", scr
->screen
,
235 scr
->rcontext
->attribs
->colors_per_channel
);
249 shellCommandHandler(pid_t pid
, unsigned char status
, _tuple
*data
)
254 buffer
= wstrconcat(_("Could not execute command: "), data
->command
);
256 wMessageDialog(data
->scr
, _("Error"), buffer
, _("OK"), NULL
, NULL
);
258 } else if (status
!= 127) {
260 printf("%s: %i\n", data->command, status);
264 wfree(data
->command
);
270 ExecuteShellCommand(WScreen
*scr
, char *command
)
272 static char *shell
= NULL
;
276 * This have a problem: if the shell is tcsh (not sure about others)
277 * and ~/.tcshrc have /bin/stty erase ^H somewhere on it, the shell
278 * will block and the command will not be executed.
280 shell = getenv("SHELL");
291 SetupEnvironment(scr
);
296 execl(shell
, shell
, "-c", command
, NULL
);
297 wsyserror("could not execute %s -c %s", shell
, command
);
299 } else if (pid
< 0) {
300 wsyserror("cannot fork a new process");
302 _tuple
*data
= wmalloc(sizeof(_tuple
));
305 data
->command
= wstrdup(command
);
307 wAddDeathHandler(pid
, (WDeathHandler
*)shellCommandHandler
, data
);
313 *---------------------------------------------------------------------------
315 * Start a shell that will receive all stdin and stdout from processes
317 *---------------------------------------------------------------------------
320 StartLogShell(WScreen
*scr
)
327 SetupEnvironment(scr
);
329 if (pipe(in_fd
) < 0) {
330 wsyserror("could not create pipe for log shell\n");
333 if (pipe(out_fd
) < 0) {
334 wsyserror("could not create pipe for log shell\n");
339 if (pipe(err_fd
) < 0) {
340 wsyserror("could not create pipe for log shell\n");
350 wsyserror("could not fork a new process for log shell\n");
352 } else if (pid
== 0) {
361 if (dup2(in_fd
[1], 0) < 0) {
362 wsyserror("could not redirect stdin for log shell\n");
365 if (dup2(out_fd
[1], 1) < 0) {
366 wsyserror("could not redirect stdout for log shell\n");
369 if (dup2(err_fd
[1], 2) < 0) {
370 wsyserror("could not redirect stderr for log shell\n");
378 execl("/bin/sh", "/bin/sh", "-c", wPreferences
.logger_shell
, NULL
);
379 wsyserror("could not execute %s\n", wPreferences
.logger_shell
);
387 LogStdOut
= out_fd
[0];
388 LogStdErr
= err_fd
[0];
394 *---------------------------------------------------------------------
396 * Do a major cleanup and exit the program
398 *----------------------------------------------------------------------
401 wAbort(Bool dumpCore
)
406 for (i
=0; i
<wScreenCount
; i
++) {
407 scr
= wScreenWithNumber(i
);
411 printf(_("%s aborted.\n"), ProgName
);
422 printf(_("Usage: %s [options]\n"), ProgName
);
423 puts(_("The Window Maker window manager for the X window system"));
425 puts(_(" -display host:dpy display to use"));
427 puts(_(" --no-cpp disable preprocessing of configuration files"));
429 puts(_(" --no-dock do not open the application Dock"));
430 puts(_(" --no-clip do not open the workspace Clip"));
431 puts(_(" --no-autolaunch do not autolaunch applications"));
432 puts(_(" --dont-restore do not restore saved session"));
434 puts(_(" --locale locale locale to use"));
436 puts(_(" --create-stdcmap create the standard colormap hint in PseudoColor visuals"));
437 puts(_(" --visual-id visualid visual id of visual to use"));
438 puts(_(" --static do not update or save configurations"));
439 puts(_(" --no-polling do not periodically check for configuration updates"));
441 puts(_(" --synchronous turn on synchronous display mode"));
443 puts(_(" --version print version and exit"));
444 puts(_(" --help show this message"));
454 path
= wdefaultspathfordomain("");
455 if (access(path
, R_OK
)!=0) {
456 wfatal(_("could not find user GNUstep directory (%s).\n"
457 "Make sure you have installed Window Maker correctly and run wmaker.inst"),
470 char *paths
= wstrconcat(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
472 file
= wfindfile(paths
, DEF_INIT_SCRIPT
);
476 if (system(file
) != 0) {
477 wsyserror(_("%s:could not execute initialization script"), file
);
481 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
482 wsyserror(_("%s:could not execute initialization script"), file
);
495 char *paths
= wstrconcat(wusergnusteppath(), ":"DEF_CONFIG_PATHS
);
497 file
= wfindfile(paths
, DEF_EXIT_SCRIPT
);
501 if (system(file
) != 0) {
502 wsyserror(_("%s:could not execute exit script"), file
);
506 execl("/bin/sh", "/bin/sh", "-c", file
, NULL
);
507 wsyserror(_("%s:could not execute exit script"), file
);
517 getFullPath(char *path
)
521 char *basep
= (char*)buffer
;
523 if (*path
!= '/' && getcwd(buffer
, 1023)) {
526 if (strncmp(path
, "../", 3)==0) {
528 basep
= strchr(basep
, '/');
529 if (!basep
|| *path
==0)
533 if (*path
== '/' || strncmp(path
, "./",2)==0) {
546 return wstrconcat(path
);
554 main(int argc
, char **argv
)
562 setlocale(LC_ALL
, "");
566 /* for telling WPrefs what's the name of the wmaker binary being ran */
568 str
= wstrconcat("WMAKER_BIN_NAME=", argv
[0]);
574 WMInitializeApplication("WindowMaker", &argc
, argv
);
577 ProgName
= strrchr(argv
[0],'/');
586 memset(&wPreferences
, 0, sizeof(WPreferences
));
589 for (i
=1; i
<argc
; i
++) {
591 if (strcmp(argv
[i
], "-nocpp")==0
592 || strcmp(argv
[i
], "--no-cpp")==0) {
593 wPreferences
.flags
.nocpp
=1;
596 if (strcmp(argv
[i
], "-no-autolaunch")==0
597 || strcmp(argv
[i
], "--no-autolaunch")==0) {
598 wPreferences
.flags
.noautolaunch
= 1;
599 } else if (strcmp(argv
[i
], "-dont-restore")==0
600 || strcmp(argv
[i
], "--dont-restore")==0) {
601 wPreferences
.flags
.norestore
= 1;
602 } else if (strcmp(argv
[i
], "-nodock")==0
603 || strcmp(argv
[i
], "--no-dock")==0) {
604 wPreferences
.flags
.nodock
=1;
605 } else if (strcmp(argv
[i
], "-noclip")==0
606 || strcmp(argv
[i
], "--no-clip")==0) {
607 wPreferences
.flags
.noclip
=1;
608 } else if (strcmp(argv
[i
], "-version")==0
609 || strcmp(argv
[i
], "--version")==0) {
610 printf("Window Maker %s\n", VERSION
);
612 } else if (strcmp(argv
[i
], "--global_defaults_path")==0) {
613 printf("%s/WindowMaker\n", SYSCONFDIR
);
616 } else if (strcmp(argv
[i
], "--synchronous")==0) {
619 } else if (strcmp(argv
[i
], "-locale")==0
620 || strcmp(argv
[i
], "--locale")==0) {
623 wwarning(_("too few arguments for %s"), argv
[i
-1]);
627 } else if (strcmp(argv
[i
], "-display")==0
628 || strcmp(argv
[i
], "--display")==0) {
631 wwarning(_("too few arguments for %s"), argv
[i
-1]);
634 DisplayName
= argv
[i
];
635 } else if (strcmp(argv
[i
], "-visualid")==0
636 || strcmp(argv
[i
], "--visual-id")==0) {
639 wwarning(_("too few arguments for %s"), argv
[i
-1]);
642 if (sscanf(argv
[i
], "%i", &wVisualID
)!=1) {
643 wwarning(_("bad value for visualid: \"%s\""), argv
[i
]);
646 } else if (strcmp(argv
[i
], "-static")==0
647 || strcmp(argv
[i
], "--static")==0) {
649 wPreferences
.flags
.noupdates
= 1;
650 } else if (strcmp(argv
[i
], "-nopolling")==0
651 || strcmp(argv
[i
], "--no-polling")==0) {
653 wPreferences
.flags
.nopolling
= 1;
655 } else if (strcmp(argv
[i
], "-clientid")==0
656 || strcmp(argv
[i
], "-restore")==0) {
659 wwarning(_("too few arguments for %s"), argv
[i
-1]);
663 } else if (strcmp(argv
[i
], "--help")==0) {
667 printf(_("%s: invalid argument '%s'\n"), argv
[0], argv
[i
]);
668 printf(_("Try '%s --help' for more information\n"), argv
[0]);
674 if (!wPreferences
.flags
.noupdates
) {
675 /* check existence of Defaults DB directory */
681 Locale
= getenv("LC_ALL");
684 Locale
= getenv("LANG");
687 setlocale(LC_ALL
, "");
689 if (!Locale
|| strcmp(Locale
, "C")==0 || strcmp(Locale
, "POSIX")==0)
692 if (getenv("NLSPATH"))
693 bindtextdomain("WindowMaker", getenv("NLSPATH"));
695 bindtextdomain("WindowMaker", LOCALEDIR
);
696 textdomain("WindowMaker");
698 if (!XSupportsLocale()) {
699 wwarning(_("X server does not support locale"));
702 if (XSetLocaleModifiers("") == NULL
) {
703 wwarning(_("cannot set locale modifiers"));
710 Locale
= wstrdup(Locale
);
711 ptr
= strchr(Locale
, '.');
717 dpy
= XOpenDisplay(DisplayName
);
719 wfatal(_("could not open display \"%s\""), XDisplayName(DisplayName
));
723 if (fcntl(ConnectionNumber(dpy
), F_SETFD
, FD_CLOEXEC
) < 0) {
724 wsyserror("error setting close-on-exec flag for X connection");
728 /* check if the user specified a complete display name (with screen).
729 * If so, only manage the specified screen */
731 str
= strchr(DisplayName
, ':');
735 if (str
&& sscanf(str
, ":%i.%i", &d
, &s
)==2)
738 DisplayName
= XDisplayName(DisplayName
);
740 int len
= strlen(DisplayName
)+64;
742 snprintf(str
, len
, "DISPLAY=%s", DisplayName
);
748 XSynchronize(dpy
, True
);
751 wXModifierInitialize();
754 wSessionConnectManager(argv
, argc
);