[comp.sources.x] v07i078: sm - A session manager, Part01/02

mikew@maui.fx.com (Mike Wexler) (05/27/90)

Submitted-by: mikew@maui.fx.com (Mike Wexler)
Posting-number: Volume 7, Issue 78
Archive-name: sm/part01

Here is the newest version of sm. It requires X11R4.
If you were at my talk at Xhibition, this is the program I was
talking about.
#--------------------------Cut Here--------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before the "#! /bin/sh" line,
# then unpack it by saving it in a file and typing "sh file."
#
# Wrapped by Mike Wexler (mikew) at neptune on Thu May 24 09:05:00 1990
#
# unpacks with default permissions
#
# Contents : README TODO AUTHOR COPYRIGHT FontPath INSTALL PROBLEMS
#	Atoms.c Atoms.h Home.h ICC.h ICCUtils.c ICCUtils.h PatchLevel.h
#	PropUtils.c PropUtils.h SM.c SM.h SM.xbm xdefs.h State.h StateGet.c
#	StateMisc.c
#
if `test ! -s README`
then
echo "x - README"
sed 's/^X//' > README << '@EOF'
XThis is my 4th version of sm for version 11 of the X Window System.  I
Xwrote it to experiment with some of the features of the ICCCM.
XThere are a some things that I still want to do with it.  See the TODO
Xfile for more info on these.
XBasically this program will save and restore the state of a X session.
XIt does this using information provided by ICCCM conforming clients.
XIt assumes the window manager put the WM_STATE property on top-level
Xwindow managers, that clients put their startup command in WM_COMMAND.
X(most Xt based application do this automatically), and works best with clients
Xthat support the WM_SAVE_YOURSELF protocol.
XThere are many things that are not done cleanly in this program. For
Xsome of them there is no clean way of doing them(See smpro.tbl.ms).
XSome ICCCM compliant clients will not be restarted properly. 
XHopefully this program will be useful anyway.
XIf you have any suggestions or fixes, please send them to me at mikew@fx.com.
XIf you are interested in doing the window manager side of the protocol
Xin smpro.tbl.ms, please send me email and I will do the session manager side
Xof the protocol.
XRead the file "INSTALL" to for information on how to install sm.
@EOF
else
  echo "shar: Will not over write README"
fi
if `test ! -s TODO`
then
echo "x - TODO"
sed 's/^X//' > TODO << '@EOF'
X1. Create a better way of starting remote clients.
X[If anyone has any idea or code on how to start clients on a remote machine
Xthat is portable, please let me know. -mcw]
X
X2. Have sm Automatically save the session at regular intervals.
X
X3. Support clients that don't handle -geometry by setting up a window
X    manager convention.
X[See proposed protocol in smpro.tbl.ms. -mcw]
X
X4. Save and restore font path, key click volumn, bell volume, etc...
X
X5. Make sure the geometry is right(not off by border width or something).
X
X6. Handle icon positioning.
X
X7. Handle multiple top-level window clients
X[This requires either a SM/WM communcation convention or for the client
Xto restore its own geometry on all windows other then a main one. -mcw]
X
X8. Take window gravity into account.
X
X9. Use the new alloc functions for allocating WM properties.
X
X10. Make sure things which don't have top-level windows die properly.
X[This may not be feasible. An SM, like a WM, may only be able to find out
Xabout things with top-level windows. -mcw]
X
X11. Support other widgets sets (Motif and Xt+)
X
X12. Implement a clone function to allow creating another instance of
X    a currently running client.
X
X13. Implement a restart function that allows you to restart a client that
X    was started by sm.
X
X14. Implement a display state function that displays the current state.
@EOF
else
  echo "shar: Will not over write TODO"
fi
if `test ! -s AUTHOR`
then
echo "x - AUTHOR"
sed 's/^X//' > AUTHOR << '@EOF'
XThis program was created by Mike Wexler (mikew@fx.com).
XParts of this program are based on xtools by Rusty C. Wright, 
Xxplaces by Ken Yap.
X
@EOF
else
  echo "shar: Will not over write AUTHOR"
fi
if `test ! -s COPYRIGHT`
then
echo "x - COPYRIGHT"
sed 's/^X//' > COPYRIGHT << '@EOF'
XCopyright 1990 by Mike Wexler, Santa Clara, CA.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
@EOF
else
  echo "shar: Will not over write COPYRIGHT"
fi
if `test ! -s FontPath`
then
echo "x - FontPath"
sed 's/^X//' > FontPath << '@EOF'
X/usr/share/X11/lib/X11/fonts/75dpi/
X/usr/share/X11/lib/X11/fonts/100dpi/
X/usr/share/X11/lib/X11/fonts/misc/
X/usr/share/X11/lib/X11/fonts/oldx10/
@EOF
else
  echo "shar: Will not over write FontPath"
fi
if `test ! -s INSTALL`
then
echo "x - INSTALL"
sed 's/^X//' > INSTALL << '@EOF'
X1. First use ximake in order to localize the Imakefile.
X2. Build sm using make.
X3. Install sm using make install. This might require root permissions, 
X   depending on the writability of the target directories.
X4. For each user of sm, make the directory sm in each users home directory.
X5. Modifies each users startup to invoke sm.
X   A. For xinit users, modify the .xinitrc so the last line runs sm in
X   the foreground. Applications that create top-level windows with the
X   WM_COMMAND property set can be removed from the .xinitrc.
X   B. For xdm users, modify the .xsession file so that the last line runs
X   sm in the foreground. Applications that create top-level windows with the
X   WM_COMMAND property set can be removed from the .xinitrc.
@EOF
else
  echo "shar: Will not over write INSTALL"
fi
if `test ! -s PROBLEMS`
then
echo "x - PROBLEMS"
sed 's/^X//' > PROBLEMS << '@EOF'
X1. Assumes that clients understand -geometry widthXheight+xXy and -iconic
X2. Toolkits clients understand abbreviated geometry options such as -geom,
Xbut sm doesn't
@EOF
else
  echo "shar: Will not over write PROBLEMS"
fi
if `test ! -s Atoms.c`
then
echo "x - Atoms.c"
sed 's/^X//' > Atoms.c << '@EOF'
X/***********************************************************
X
X$Header: Atoms.c,v 3.0 89/11/20 09:24:35 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X#include <X11/Xlib.h>
X#include "Atoms.h"
X
XAtom            wmStateAtom;		/* WM_STATE atom */
XAtom            wmProtocolsAtom;	/* WM_PROTOCOLS atom */
XAtom            wmSaveYourselfAtom;	/* WM_SAVE_YOURSELF atom */
X
X/*
X * Description: Get the bindings for the atoms that SM uses.
X * 
X * Side Effects: Modifies the 3 global variables.
X */
X
X/* This function gets the bindings for the atoms that SM uses. */
XStatus
XInternAtoms(display)
X    Display        *display;	/* pointer to X server */
X{
X    wmStateAtom = XInternAtom(display, "WM_STATE", False);
X    wmProtocolsAtom = XInternAtom(display, "WM_PROTOCOLS", False);
X    wmSaveYourselfAtom = XInternAtom(display, "WM_SAVE_YOURSELF", False);
X    return (SM_SUCCESS);
X}
@EOF
else
  echo "shar: Will not over write Atoms.c"
fi
if `test ! -s Atoms.h`
then
echo "x - Atoms.h"
sed 's/^X//' > Atoms.h << '@EOF'
X/***********************************************************
X
X$Header: Atoms.h,v 3.0 89/11/20 09:24:36 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xextern Atom     wmStateAtom;
Xextern Atom     wmProtocolsAtom;
Xextern Atom     wmSaveYourselfAtom;
X
X#ifdef __STDC__
Xextern int      InternAtoms(Display *);
X#else
Xextern int      InternAtoms();
X#endif
@EOF
else
  echo "shar: Will not over write Atoms.h"
fi
if `test ! -s Home.h`
then
echo "x - Home.h"
sed 's/^X//' > Home.h << '@EOF'
X/***********************************************************
X
X$Header: Home.h,v 3.0 89/11/20 09:24:41 mikew Locked $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xextern Widget	confirmPopup;
Xextern Widget	confirmForm;
Xextern Widget   homeForm;
X
Xextern Widget   HomeSetup();
Xextern Widget   ConfirmSetup();
@EOF
else
  echo "shar: Will not over write Home.h"
fi
if `test ! -s ICC.h`
then
echo "x - ICC.h"
sed 's/^X//' > ICC.h << '@EOF'
X/***********************************************************
X
X$Header: ICC.h,v 3.0 89/11/20 09:24:42 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xtypedef struct {
X    int             state;
X    Window          icon;
X}               WM_STATE;
X
X#define WithdrawnState 0
@EOF
else
  echo "shar: Will not over write ICC.h"
fi
if `test ! -s ICCUtils.c`
then
echo "x - ICCUtils.c"
sed 's/^X//' > ICCUtils.c << '@EOF'
X/***********************************************************
X
X$Header: ICCUtils.c,v 3.1 90/04/16 16:39:28 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/Xatom.h>
X#include <X11/Intrinsic.h>
X#include "Atoms.h"
X#include "ICC.h"
X#include "ICCUtils.h"
X#include "xdefs.h"
X#include "WinInfo.h"
X#include "State.h"
X
X/*
X * Description: Given a window that is child of the RootWindow, find the
X * 		corresponding top level window.
X * 
X */
X
Xstatic
XWindow 
XGetTopLevelWindow(display, window)
X    Display        *display;	/* pointer to the X server */
X    Window          window;	/* a window that is either a top-level window
X				   or an ancestor of one. */
X{
X    Window          parent, root, *children;
X    Atom            actualType;
X    int             actualFormat;
X    unsigned long   nitems;
X    unsigned long   leftover;
X    unsigned int    nchildren;
X    WM_STATE        wmState;
X    XWindowAttributes windowAttr;
X
X    XGetWindowAttributes(display, window, &windowAttr);
X    XGetWindowProperty(display, window, wmStateAtom, 0L, (long) BUFSIZ, False,
X		       wmStateAtom, &actualType, &actualFormat, &nitems,
X		       &leftover, (unsigned char **) &wmState);
X    if (actualType == wmStateAtom && !windowAttr.override_redirect)
X	return (window);
X    else {
X	XQueryTree(display, window, &root, &parent, &children, &nchildren);
X	while (nchildren--) {
X	    if (window = GetTopLevelWindow(display, *children++))
X		return (window);
X	}
X	return ((Window) 0);
X    }
X}
X
X/*
X * Description: This functions get a time stamp by update a property and then
X * 		extracting the time stamp for the property notify.
X * 
X * Outputs:	Time - the timestamp
X * 
X */
X
XTime 
XGetTimeStamp(display, window)
X    Display        *display;	/* pointer to the X server */
X    Window          window;	/* the window to put the property on */
X{
X    unsigned long  *data = NULL;
X    XEvent          event;
X    XPropertyEvent *pEvent = (XPropertyEvent *) & event;
X
X    /* do a zero length append to WM_PROTOCOLS to get a time stamp. */
X    XSelectInput(display, window, PropertyChangeMask);
X    XChangeProperty(display, window, wmProtocolsAtom, XA_ATOM, 32,
X	 	    PropModeAppend, data, 0);
X    for (;;) {
X	XtAppNextEvent(myAppContext, &event);
X	if (event.type == PropertyNotify && pEvent->window == window &&
X	    pEvent->atom == wmProtocolsAtom)
X	    break;		/* got the append */
X	XtDispatchEvent(&event);
X    }
X    XSelectInput(display, window, NoEventMask);
X    return (pEvent->time);
X}
X
X/*
X * Description:	Check a window to see if it supports WM_SAVE_YOURSELF.
X * 
X * Outputs:	Boolean - True = protocol supported, False = not supported
X * 
X */
X
XBoolean
XCheckForProtocol(display, window, protocol)
XDisplay        *display;	/* pointer to the X server */
XWindow          window;		/* the window to be checked */
XAtom            protocol;	/* protocol to check for */
X{
X    int             i;
X    Atom *protocols;
X    unsigned long numProtocols;
X
X    protocols = NULL;
X    /* Get the WM_PROTOCOLS property on the clients top-level window. */
X    if (XGetWMProtocols(display, window, &protocols, &numProtocols) != True)
X	return (False);		/* If the client doesn't have a WM_PROTOCOLS
X				 * property,	 */
X    /* Look for protocols atom.  */
X    if (protocols != NULL)
X	    for (i = 0; i < numProtocols; ++i)
X		if (protocols[i] == protocol)
X		    return(True);
X    return (False);		/* doesn't participate in WM_SAVE_YOURSELF */
X}
X
X/*
X * Description:	This function sends the SAVE_YOURSELF message to a window.
X * 
X * Side Effects: Causes the client to update its WM_COMMAND Property.
X *
X */
X
XStatus
XSaveYourself(display, window, time)
X    Display        *display;	/* pointer to the X server */
X    Window          window;	/* window to send WM_SAVE_YOURSELF to */
X    Time            time;	/* timestamp of event causing the save */
X{
X    Status		cc;
X    XClientMessageEvent saveYourselfMessage;
X
X    /* Construct the ClientMessage. */
X    saveYourselfMessage.type = ClientMessage;
X    saveYourselfMessage.window = window;
X    saveYourselfMessage.message_type = wmProtocolsAtom;
X    saveYourselfMessage.format = 32;
X    saveYourselfMessage.data.l[0] = wmSaveYourselfAtom;
X    saveYourselfMessage.data.l[1] = time;
X
X    /* look for changes in WM_COMMAND property */
X    XSelectInput(display, window, PropertyChangeMask);	
X
X    if ((cc = XSendEvent(display, window, False, NoEventMask,
X	 &saveYourselfMessage)) != 1) {
X	Warning("SaveYourself", "XSendEvent failed to send client message.\n");
X	return (cc);
X    }
X    return (SM_SUCCESS);
X}
X
X
X/*
X * Description: Get a list of all the top-level windows.
X * 
X */
X
XStatus
XGetTopLevelWindows(display, state)
X    Display        *display;	/* pointer to the X server */
X    State          *state;	/* anchor for the list of windows */
X{
X    Window          rootWindow, *childList, parentWindow;
X    int             childListLen;
X    WinInfo        *wi;
X    int             i;
X
X    /* get a list of children of the root window */
X    if (XQueryTree(display, DefaultRootWindow(display), &rootWindow, 
X		   &parentWindow, &childList, &childListLen) != 1)
X	Fatal("GetTopLevelWindows", "Can't query window tree");
X    /* scan list */
X    for (i = 0; i < childListLen; ++i, childList++) {
X	Window          topLevelWindow;
X
X	wi = wiAlloc();
X	topLevelWindow = GetTopLevelWindow(display, *childList);
X	if (!topLevelWindow)
X	    topLevelWindow = (*childList);
X	wi->rid = topLevelWindow;
X	wi->parentRid = *childList;
X	StateAddWinInfo(state, wi);
X    }
X    return (SM_SUCCESS);
X}
@EOF
else
  echo "shar: Will not over write ICCUtils.c"
fi
if `test ! -s ICCUtils.h`
then
echo "x - ICCUtils.h"
sed 's/^X//' > ICCUtils.h << '@EOF'
X/***********************************************************
X
X$Header: ICCUtils.h,v 3.0 89/11/20 09:24:44 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xextern Status   SaveYourself();
Xextern Status   GetTopLevelWindows();
Xextern Boolean  CheckForProtocol();
Xextern Status   SendSaveYourSelf();
Xextern Time	GetTimeStamp();
Xextern void     WaitForCommand();
@EOF
else
  echo "shar: Will not over write ICCUtils.h"
fi
if `test ! -s PatchLevel.h`
then
echo "x - PatchLevel.h"
sed 's/^X//' > PatchLevel.h << '@EOF'
X/***********************************************************
X
X$Header: PatchLevel.h,v 3.0 89/11/20 09:25:05 mikew Locked $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#define PATCHLEVEL 4
X#define VERSION 4.0
@EOF
else
  echo "shar: Will not over write PatchLevel.h"
fi
if `test ! -s PropUtils.c`
then
echo "x - PropUtils.c"
sed 's/^X//' > PropUtils.c << '@EOF'
X/***********************************************************
X
X$Header: PropUtils.c,v 3.0 89/11/20 09:25:06 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X#include <X11/Xlib.h>
X#include <X11/Xatom.h>
X#include "X11/Xutil.h"
X#include "ICC.h"
X#include "xdefs.h"
X#include "PropUtils.h"
X#include "Atoms.h"
X
X/*
X * Description: The inverse of XSetStandardProperties (pretty much).
X * 
X * Side Effects: None.
X */
X
X/* ARGSUSED */
XStatus 
XXGetStandardProperties(display, window, windowName, iconName,
X		       iconPixmap, argc, argv, hints, clientMachine)
X    Display        *display;	/* pointer to the X server */
X    Window          window;	/* window from which to extract properties */
X    unsigned char **windowName;	/* window name(ISO Latin 1) */
X    unsigned char **iconName;	/* icon name (ISO Latin 1) */
X    Pixmap         *iconPixmap;	/* icon pixmap */
X    unsigned char ***argv;	/* command line argument list */
X    int            *argc;	/* number of command line arguments */
X    XSizeHints     *hints;	/* WM_NORMAL_HINTS */
X    unsigned char **clientMachine;	/* WM_CLIENT_MACHINE */
X{
X    XTextProperty   textProperty;
X    long            supplied;
X
X    if (XGetCommand(display, window, argv, argc) != 1)
X	return (0);
X    if (XGetWMClientMachine(display, window, &textProperty) != 1)
X	return (0);
X    if (textProperty.encoding == XA_STRING)
X	*clientMachine = textProperty.value;
X    else {
X	*clientMachine = NULL;
X	if (textProperty.value)
X	    XFree(textProperty.value);
X    }
X    XGetWMNormalHints(display, window, hints, &supplied);
X    XGetWMName(display, window, &textProperty);
X    if (textProperty.encoding == XA_STRING)
X	*windowName = textProperty.value;
X    else {
X	*windowName = NULL;
X	if (textProperty.value)
X	    XFree(textProperty.value);
X    }
X    return (1);
X}
X
X#define UNSIGNEDINT unsigned long
X#define SIGNEDINT long
X#define RESOURCEID unsigned long
X/* this structure may be extended, but do not change the order */
Xtypedef struct {
X    SIGNEDINT       state;
X    RESOURCEID      icon;
X}               xPropWMState;
X#define NumPropWMStateElements 2/* number of elements in this structure */
X
X/*
X * Description: Retrieve the contents of the WM_STATE property.
X * 
X */
X
XStatus 
XXGetWMState(display, window, wmState)
X    Display        *display;	/* pointer to the X server */
X    Window          window;	/* window from which to get WM_STATE */
X    WM_STATE       *wmState;	/* contents of WM_STATE */
X{
X    xPropWMState   *prop;
X    Atom            actual_type;
X    int             actual_format;
X    unsigned long   nitems;
X    unsigned long   leftover;
X
X    if (XGetWindowProperty(display, window, wmStateAtom,
X				 0L, (long) NumPropWMStateElements,
X			   False, wmStateAtom, &actual_type, &actual_format,
X			      &nitems, &leftover, (unsigned char **) &prop)
X	!= Success)
X	return (0);
X
X    /* If the property is undefined on the window, return null pointer. */
X
X    if ((actual_type != wmStateAtom) ||
X	(nitems < NumPropWMStateElements) || (actual_format != 32)) {
X	if (prop != NULL)
X	    XFree((char *) prop);
X	return (BadMatch);
X    }
X    wmState->state = prop->state;
X    wmState->icon = prop->icon;
X    XFree((char *) prop);
X    return (1);
X}
@EOF
else
  echo "shar: Will not over write PropUtils.c"
fi
if `test ! -s PropUtils.h`
then
echo "x - PropUtils.h"
sed 's/^X//' > PropUtils.h << '@EOF'
X/***********************************************************
X
X$Header: PropUtils.h,v 3.0 89/11/20 09:25:08 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xextern Status   XGetCommand();
Xextern Status   XGetClientMachine();
Xextern Status   XGetStandardProperties();
@EOF
else
  echo "shar: Will not over write PropUtils.h"
fi
if `test ! -s SM.c`
then
echo "x - SM.c"
sed 's/^X//' > SM.c << '@EOF'
X/***********************************************************
X
X$Header: SM.c,v 3.1 90/04/16 16:45:11 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X
X#include "PatchLevel.h"
X#include "Top.h"
X#include "ICC.h"
X#include "WinInfo.h"
X#include "Atoms.h"
X#include "State.h"
X
Xextern ApplicationData applData;
XWidget          homeForm;
X
X/*
X * Description: The main routine for sm
X * 
X * Side Effects: Manages the session
X */
X
Xint
Xmain(argc, argv)
Xint             argc;	/* number of command line argument s*/
Xchar          **argv;	/* command line arguments */
X{
X    Widget          topShell;
X    Arg             args[1];
X    Status	    cc;
X    State	    state;
X
X    StateInit(&state);
X    /* TopSetup calls XtInitialize which parses argv for us. */
X    topShell = InitializeX(argc, argv);
X    if (!applData.ignore) {
X	if (StateRead(&state) < 0) {
X	    Warning("main", 
X		    "Couldn't read saved state, using default state.\n");
X	    if (StateCreateDefault(&state) < 0)
X		exit(1);
X	} 
X	if (state.smState != NULL) {
X	    XtConfigureWidget(topShell, state.smState->x, state.smState->y,
X			      state.smState->width, state.smState->height, 
X			      0);
X	}
X    }
X    if (applData.print) {
X	applData.ignore = True;
X	/*
X	 * The following three lines are a hack to create an unmapped window
X	 * to create time stamps with.
X	 */
X
X	XtSetArg(args[0], XtNmappedWhenManaged, False);
X	XtSetValues(topShell, args, 1);
X    }
X    WidgetSetup();
X    /* Get the bindings for the atoms that we use.  */
X    if (InternAtoms(XtDisplay(topShell)))
X	Fatal("main", "Window manager isn't ICCCM compliant.\n");
X    /* If the user specified -print just print the state and exit. */
X    if (!applData.ignore) {
X	if ((cc = StateExecute(&state)) < 0)
X	    exit(cc);
X    }
X    /* Display the top-level widget. */
X    TopStart();
X    if (applData.print) {
X	if (StateGet(&state, XtDisplay(homeForm)) < 0)
X	  Fatal("main", "Couldn't get state.\n");
X	if (StatePrint(stdout, &state) < 0)
X	  Fatal("main", "Couldn't print state.\n");
X    } else {
X	/* Let Xt handle everything until the user tells us otherwise. */
X	XtAppMainLoop(myAppContext);
X    }
X    StateCleanup(&state);
X    exit(0);
X}
X
X/*
X * Description: Display a nice little usage message
X * 
X * Side Effects: Exits
X */
X
Xvoid 
XUsage()
X{
X    (void) fprintf(stderr, "usage: sm [-print] [-ignore]\n");
X    exit(1);
X}
@EOF
else
  echo "shar: Will not over write SM.c"
fi
if `test ! -s SM.h`
then
echo "x - SM.h"
sed 's/^X//' > SM.h << '@EOF'
X/***********************************************************
X
X$Header: SM.h,v 3.1 90/04/16 17:20:59 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "osdefs.h"
X#include <stdio.h>
X#include <X11/Xos.h>
X#include <X11/Intrinsic.h>
X
X#define LOCAL_HOST	"localhost"
X#define SM_SUCCESS	(0)
X#define SM_FAILURE	(-1)
X
Xtypedef struct {
X    Boolean         print;
X    Boolean         debug;
X    Boolean         ignore;
X    String          smDir;
X    String          defaultDir;
X    String          shell;
X    String          defaultCommand;
X    String          geometry;
X    String          iconic;
X    String	    metaChars;
X}               ApplicationData, *ApplicationDataPtr;
X
Xextern ApplicationData applData;
Xextern XtAppContext    myAppContext;
Xextern void	QuitAction();
Xextern void	ExitAction();
Xextern void	SaveStateAction();
Xextern void	CancelAction();
Xextern void     Fatal();
Xextern void     Warning();
Xextern void     PWarning();
Xextern void     Usage();
Xextern char    *strdup();
@EOF
else
  echo "shar: Will not over write SM.h"
fi
if `test ! -s SM.xbm`
then
echo "x - SM.xbm"
sed 's/^X//' > SM.xbm << '@EOF'
X#define SM_width 64
X#define SM_height 64
Xstatic char SM_bits[] = {
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff,
X   0x1f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00,
X   0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
X   0xff, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
X   0x00, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
X   0xff, 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
X   0xe0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff,
X   0xff, 0x3f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00,
X   0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0x1f, 0x60, 0x00, 0x3e, 0x7c, 0x80, 0x03, 0x00,
X   0xcf, 0x67, 0xe7, 0xde, 0xf9, 0x3c, 0x03, 0x00, 0xe7, 0xef, 0xe7, 0xef,
X   0xf3, 0x7c, 0x02, 0x00, 0xe7, 0xef, 0xe7, 0xef, 0xe7, 0x7c, 0x02, 0x00,
X   0xc7, 0xff, 0xe7, 0xe7, 0xe7, 0x7c, 0x02, 0x00, 0x0f, 0xff, 0xe7, 0xe7,
X   0xe7, 0x3c, 0x03, 0x00, 0x1f, 0xfe, 0xe7, 0xe7, 0xe7, 0x80, 0x03, 0x00,
X   0x7f, 0xf8, 0xe7, 0xe7, 0xe7, 0xfc, 0x03, 0x00, 0xff, 0xf1, 0xe7, 0xe7,
X   0xe7, 0xfc, 0x03, 0x00, 0xff, 0xe3, 0xe7, 0xe7, 0xe7, 0xfc, 0x03, 0x00,
X   0xf7, 0xe7, 0xe7, 0xef, 0xe7, 0xfc, 0x03, 0x00, 0xf7, 0xe7, 0xe7, 0xcf,
X   0xf7, 0xfc, 0x03, 0x00, 0xe7, 0xf3, 0xe7, 0x9f, 0xfb, 0xfc, 0x03, 0x00,
X   0x07, 0xf8, 0x81, 0x3f, 0x7c, 0xf8, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
X   0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff,
X   0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00,
X   0xe0, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff,
X   0xff, 0x0f, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00,
X   0x00, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff,
X   0xff, 0x01, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
X   0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff,
X   0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@EOF
else
  echo "shar: Will not over write SM.xbm"
fi
if `test ! -s xdefs.h`
then
echo "x - xdefs.h"
sed 's/^X//' > xdefs.h << '@EOF'
X/***********************************************************
X
X$Header: xdefs.h,v 2.1 90/04/16 17:22:20 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xextern int      XGetWindowProperty();
Xextern Status   XGetWindowAttributes();
Xextern int      XKillClient();
Xextern Bool     XTranslateCoordinates();
Xextern Status   XQueryTree();
Xextern Status   XGetNormalHints();
Xextern Status   XFetchName();
Xextern Status   XSendEvent();
Xextern int      XSelectInput();
Xextern int      XChangeProperty();
@EOF
else
  echo "shar: Will not over write xdefs.h"
fi
if `test ! -s State.h`
then
echo "x - State.h"
sed 's/^X//' > State.h << '@EOF'
X/***********************************************************
X
X$Header: State.h,v 3.1 90/04/16 17:21:18 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
Xtypedef struct _hostInfoStruct {
X    unsigned char	       *hostName; /* name of host */
X    int				numWinInfos;	/* number of windows on host */
X    WinInfoPtr		       *winInfos; /* array of pointers to windows */
X    FILE		       *outputFile; /* host's output file */
X    struct _hostInfoStruct     *next; /* next host in host list */
X} 		HostInfo, *HostInfoPtr;
X
Xtypedef struct _stateStruct {
X    WinInfoPtr	topList;
X    HostInfoPtr	hostInfo;
X    int      	waitForCount;
X    WinInfoPtr	smState;
X    int		numFontPaths;
X    char      **fontPaths;
X}		State, *StatePtr;
X
X#define HOSTNAME_LEN    100
X#define TEMP_LEN	500
X
Xextern void     	StateInit();
Xextern void     	StateCleanup();
Xextern Status      	StateSave();
Xextern Status      	StatePrint();
Xextern Status      	StateRestore();
Xextern WinInfoPtr	StateGetWinInfoByRid();
@EOF
else
  echo "shar: Will not over write State.h"
fi
if `test ! -s StateGet.c`
then
echo "x - StateGet.c"
sed 's/^X//' > StateGet.c << '@EOF'
X/***********************************************************
X
X$Header: StateGet.c,v 3.1 90/04/16 17:19:06 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X
X#include <X11/Xlib.h>
X#include "ICC.h"
X#include <X11/Xutil.h>
X#include <X11/Xatom.h>
X
X#include "xdefs.h"
X#include "Top.h"
X#include "PropUtils.h"
X#include "ICCUtils.h"
X#include "WinInfo.h"
X#include "State.h"
X#include "Atoms.h"
X
Xstatic int	PropertiesGet();
X
X/*
X * Description: Retrieve the properties for all the top-level windows.
X * 
X * 
X */
X
Xstatic
XStatus
XAllGetProperties(state, display)
XState	       *state;		/* pointer to the state */
XDisplay        *display;	/* pointer to the X server */
X{
X    WinInfo        *wi;
X    WinInfo        *nextWi;
X
X    for (wi = state->topList; wi != NULL; wi = nextWi) {
X	nextWi = wi->next;
X	if (PropertiesGet(wi, display) != SM_SUCCESS) {
X	    StateRemoveWinInfo(state, wi);
X	    wiFree(wi);
X	}
X    }
X    return (SM_SUCCESS);
X}
X
X/*
X * Description: Send WM_SAVE_YOURSELF to all top-level windows who want it.
X * 
X */
X
Xstatic
XStatus
XAllSaveYourself(state, display)
X    State	   *state;	/* pointer to the state */
X    Display        *display;	/* pointer to the display */
X{
X    Status	cc;
X    Time	time;
X    WinInfo    *wi;
X    WinInfo    *nextWi;
X
X    time = GetTimeStamp(display, XtWindow(topShell));
X    for (wi = state->topList; wi != NULL; wi = nextWi) {
X	nextWi = wi->next;
X	/*
X	 * If the client participates in the WM_SAVE_YOURSELF protocol, send
X	 * him the appopriate messages and wait for the proper responses
X	 */
X	if (!CheckForProtocol(display, wi->rid, wmSaveYourselfAtom))
X	  continue;
X	state->waitForCount++;
X	wi->saveYourselfState = Saving;
X	if ((cc = SaveYourself(display, wi->rid, time)) != SM_SUCCESS)
X	  return(cc);
X    }
X    return (SM_SUCCESS);
X}
X
X/*
X * Description: Wait For WM_COMMAND to be updated on all windows who received
X *		WM_SAVE_YOURSELF.
X * 
X * Side Effects: 
X */
X
Xstatic
XStatus 
XAllWaitForCommand(state, display)
X    StatePtr	    state;	/* pointer to the state */
X    Display        *display;	/* pointer to the X server */
X{
X    WinInfo        *wi;
X
X    while (state->waitForCount > 0) {
X	XEvent	event;
X	XPropertyEvent *pEvent = (XPropertyEvent *) & event;
X
X	XtAppNextEvent(myAppContext, &event);
X	if (event.type == PropertyNotify && pEvent->atom == XA_WM_COMMAND) {
X	    wi = StateGetWinInfoByRid(state, pEvent->window);
X	    if (wi && wi->saveYourselfState == Saving) {
X		if (XGetCommand(display, wi->rid, &wi->argv, &wi->argc) != 1) {
X		    StateRemoveWinInfo(state, wi);
X		    wiFree(wi);
X		}
X		else
X		  wi->saveYourselfState = Saved;
X		state->waitForCount--;
X	    }
X	}
X	XtDispatchEvent(&event);
X	XSelectInput(display, wi->rid, NoEventMask);
X    }
X    return (SM_SUCCESS);
X}
X
X/*
X * Description: Gather up the current state
X * 
X * Side Effects: Can cause the clients to update WM_COMMAND 
X *
X */
X
Xint 
XStateGet(state, display)
X    State      *state;		/* pointer to the state */
X    Display    *display;	/* pointer to the X server */
X{
X    /* Get a list of children of the root window. */
X    if (GetTopLevelWindows(display, state))
X	return (1);
X    AllSaveYourself(state,display);
X    AllGetProperties(state,display);
X    AllWaitForCommand(state,display);
X    state->fontPaths = XGetFontPath(display, &state->numFontPaths);
X    return (0);
X}
X
X
X/*
X * Description:	Compute the geometry argument for a command based on its
X *		window attributes, parent attributes, and WM_NORMAL_HINTS.
X *
X */
X
Xstatic
Xvoid
XComputeGeometry(attr, parentAttr, wmNormalHints, x, y, height, width)
X    XWindowAttributes	*attr;	/* window attributes*/
X    XWindowAttributes	*parentAttr; /* parent window attributes */
X    XSizeHints      	*wmNormalHints;	/* contents of WM_NORMAL_HINTS */
X    int			*x;	/* returned x location */
X    int			*y;	/* returned y location */
X    int			*width;	/* returned width */
X    int			*height; /* returned height */
X{
X    *width = attr->width;
X    *height = attr->height;
X    *x = parentAttr->x + parentAttr->border_width;
X    *y = parentAttr->y + parentAttr->border_width;
X    /*
X     * The width in pixels is base_width + (width * width_inc).	
X     * The height in pixels is base_height + (width * height_inc).
X     * Xlib current doesn't know about Base Size.
X     */
X    if (wmNormalHints->flags & PBaseSize) {
X	*width -= wmNormalHints->base_width;
X	*height -= wmNormalHints->base_height;
X    } else if (wmNormalHints->flags & PMinSize) {
X	*width -= wmNormalHints->min_width;
X	*height -= wmNormalHints->min_height;
X    }
X    if (wmNormalHints->flags & PResizeInc) {
X	*width = *width / wmNormalHints->width_inc;
X	*height = *height / wmNormalHints->height_inc;
X    }
X    return;
X}
X
X/*
X * Description: Get the properties of a top-level window.
X * 
X * Side Effects: Updates many properties in the WinInfo structure.
X */
X
Xstatic
XStatus
XPropertiesGet(wi, display)
X    Display        *display;	/* pointer to the X server */
X    WinInfo        *wi;		/* pointer to window information */
X{
X    Pixmap         	iconPixmap;
X    unsigned char      *fakeargv[1];
X    XWindowAttributes	attr;
X    unsigned char      *wmIconName = NULL;
X    unsigned char      *wmName = NULL;
X    XWindowAttributes	parentAttr;
X    XSizeHints      	wmNormalHints;
X
X    XGetWindowAttributes(display, wi->rid, &attr);
X    XGetWindowAttributes(display, wi->parentRid, &parentAttr);
X    if (XGetStandardProperties(display, wi->rid, &wmName, &wmIconName,
X			       &iconPixmap, &wi->argc, &wi->argv,
X		       &wmNormalHints, &wi->wmClientMachine) != 1)
X	return (SM_FAILURE);
X    ComputeGeometry(&attr, &parentAttr, &wmNormalHints, 
X		    &wi->x, &wi->y, &wi->height, &wi->width);
X    if (wmIconName) 
X	XFree(wmIconName);
X    /* If the guy doesn't have a WM_COMMAND property, we can't restart him. */
X    if (!wi->argv != NULL || !wi->argv[0]) {
X	if (!wmName)
X	    return (SM_FAILURE);
X	wi->argv = fakeargv;
X	fakeargv[0] = wmName;
X	wi->argc = 1;
X    }
X    if (wmName)
X	XFree(wmName);
X    (void) XGetClassHint(display, wi->rid, &wi->wmClass);
X    if ( XGetWMState(display, wi->rid, &wi->wmState) != 1)
X	return (SM_FAILURE);
X    if (wi->wmState.state == WithdrawnState)
X	return (SM_FAILURE);
X    return (SM_SUCCESS);
X}
@EOF
else
  echo "shar: Will not over write StateGet.c"
fi
if `test ! -s StateMisc.c`
then
echo "x - StateMisc.c"
sed 's/^X//' > StateMisc.c << '@EOF'
X/***********************************************************
X
X$Header: StateMisc.c,v 1.1 90/04/16 17:19:20 mikew Exp $
X
XCopyright 1989 by Mike Wexler, Santa Clara, Ca.
Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
X
X                        All Rights Reserved
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation, and that the name of Mike Wexler or not be
Xused in advertising or publicity pertaining to distribution of the
Xsoftware without specific, written prior permission.
X
XMIKE WEXLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
XSOFTWARE.
X
X******************************************************************/
X
X#include "SM.h"
X#include "X11/Xlib.h"
X#include "X11/Xutil.h"
X#include "ICC.h"
X#include "WinInfo.h"
X#include "State.h"
X
X
X/*
X * Description: Initialize a window list data structure
X * 
X */
X
Xvoid
XStateInit(state)
XStatePtr	state;	/* pointer to the state */
X{
X    state->smState = NULL;
X    state->topList = NULL;
X    state->waitForCount = 0;
X    state->hostInfo = NULL;
X    state->numFontPaths = 0;
X    state->fontPaths = NULL;
X    return;
X}
X/*
X * Description: Cleanup the a State
X * 
X * Inputs:	state - a pointer a State
X * 
X */
X
X/*ARGSUSED*/
Xvoid
XStateCleanup(state)
XStatePtr	state;	/* pointer to the state */
X{
X    return;
X}
X
X/* 
X * Description: Add a window information structure to the state. 
X *
X */
X
XStatus
XStateAddWinInfo(state, winInfo)
X    StatePtr	state;		/* pointer to the state */
X    WinInfoPtr	winInfo;	/* pointer to window information structure */
X{
X    winInfo->prev = NULL;
X    winInfo->next = state->topList;
X    if (state->topList)
X	state->topList->prev = winInfo;
X    state->topList = winInfo;
X    return(SM_SUCCESS);
X}
X
XStatus
XStateAddToHostList(state, winInfo)
X    StatePtr	state;
X    WinInfoPtr	winInfo;
X{
X    HostInfoPtr	hostInfo;
X
X    for (hostInfo = state->hostInfo; hostInfo != NULL; 
X	 hostInfo = hostInfo->next) {
X	if (strcmp(hostInfo->hostName, winInfo->wmClientMachine) == 0)
X	    break;
X    }
X    if (hostInfo == NULL) {
X	hostInfo = (HostInfoPtr) XtMalloc(sizeof(*hostInfo));
X	hostInfo->next = state->hostInfo;
X	hostInfo->hostName = (unsigned char *)
X	    XtMalloc(strlen(winInfo->wmClientMachine) + 1);
X	strcpy(hostInfo->hostName, winInfo->wmClientMachine);
X	hostInfo->numWinInfos = 1;
X	hostInfo->winInfos = (WinInfoPtr *)
X	    XtMalloc(sizeof(*hostInfo->winInfos) * 1);
X	if (hostInfo->winInfos == NULL)
X	    return(SM_FAILURE);
X	state->hostInfo = hostInfo;
X    } else {
X	++hostInfo->numWinInfos;
X	hostInfo->winInfos = (WinInfoPtr *) 
X	    XtRealloc(hostInfo->winInfos,
X		    sizeof(*hostInfo->winInfos) * hostInfo->numWinInfos);
X	if (hostInfo->winInfos == NULL)
X	    return(SM_FAILURE);
X    }
X    hostInfo->winInfos[hostInfo->numWinInfos - 1] = winInfo;
X    return(SM_SUCCESS);
X}
X
XStatus
XStateRemoveWinInfo(state, winInfo)
X    StatePtr	state;
X    WinInfoPtr	winInfo;
X{
X    if (winInfo->prev != NULL)
X	winInfo->prev->next = winInfo->next;
X    else
X	state->topList = winInfo->next;
X    if (winInfo->next != NULL)
X	winInfo->next->prev = winInfo->prev;
X    return(SM_SUCCESS);
X}
X
X/*
X * Description: Get a WinInfo structure give the Resource ID for the window.
X * 
X * Outputs:	WinInfo * - the WinInfo structure that matches or NULL if
X * 			    there is no match.
X * 
X */
X
XWinInfo        *
XStateGetWinInfoByRid(state, rid)
X    StatePtr	state;	/* a pointer to the state */
X    Window      rid;	/* resource id of the window to find */
X{
X    WinInfo        *wi;
X
X    for (wi = state->topList; wi != NULL; wi = wi->next)
X	if (wi->rid == rid)
X	    return (wi);
X    return (NULL);
X}
X
X/*
X * Description:	Startup the system in the default state
X */ 
X
XStatus
XStateCreateDefault(state)
XState	*state;	/* pointer to the current state */
X{
X    Status 	cc;
X    WinInfo	*wi;
X
X    wi = wiAlloc();
X    if (wi == NULL)
X	return(SM_FAILURE);
X    wi->win_gravity = NorthWestGravity;
X    wi->wmState.state = NormalState;
X    wi->width = 80;
X    wi->height = 24;
X    wi->x = 0;
X    wi->y = 0;
X    wi->wmClientMachine = (unsigned char *) strdup(LOCAL_HOST);
X    if (wi->wmClientMachine == NULL)
X	return(SM_FAILURE);
X    wi->wmClass.res_class = NULL;
X    wi->wmClass.res_name = NULL;
X    wi->argc = 1;
X    wi->argv = (unsigned char **) 
X	XtMalloc((wi->argc) * sizeof(*wi->argv));
X    if (wi->argv == NULL)
X	return(SM_FAILURE);
X    wi->argv[0] = (unsigned char *) strdup(applData.defaultCommand);
X    if (wi->argv[0] == NULL)
X	return(SM_FAILURE);
X    if ((cc = StateAddWinInfo(state, wi)) < 0)
X	return(cc);
X    if ((cc = StateAddToHostList(state, wi)) < 0)
X	return(cc);
X    return (SM_SUCCESS);
X}
X
X
@EOF
else
  echo "shar: Will not over write StateMisc.c"
fi
echo "Finished archive 1 of 2"
# to concatenate archives, remove anything after this line
exit 0

dan
----------------------------------------------------
O'Reilly && Associates   argv@sun.com / argv@ora.com
Opinions expressed reflect those of the author only.