114c0a534Smrg/******************************************************************************
214c0a534Smrg
314c0a534SmrgCopyright 1994, 1998  The Open Group
414c0a534Smrg
514c0a534SmrgPermission to use, copy, modify, distribute, and sell this software and its
614c0a534Smrgdocumentation for any purpose is hereby granted without fee, provided that
714c0a534Smrgthe above copyright notice appear in all copies and that both that
814c0a534Smrgcopyright notice and this permission notice appear in supporting
914c0a534Smrgdocumentation.
1014c0a534Smrg
1114c0a534SmrgThe above copyright notice and this permission notice shall be included in
1214c0a534Smrgall copies or substantial portions of the Software.
1314c0a534Smrg
1414c0a534SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1514c0a534SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1614c0a534SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1714c0a534SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1814c0a534SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1914c0a534SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2014c0a534Smrg
2114c0a534SmrgExcept as contained in this notice, the name of The Open Group shall not be
2214c0a534Smrgused in advertising or otherwise to promote the sale, use or other dealings
2314c0a534Smrgin this Software without prior written authorization from The Open Group.
2414c0a534Smrg
2514c0a534SmrgAuthor:  Ralph Mor, X Consortium
2614c0a534Smrg******************************************************************************/
2714c0a534Smrg
2814c0a534Smrg#ifdef HAVE_CONFIG_H
2914c0a534Smrg# include "config.h"
3014c0a534Smrg#endif
3114c0a534Smrg
3214c0a534Smrg#include <X11/Xosdefs.h>
3314c0a534Smrg#include <X11/Xfuncs.h>
3414c0a534Smrg
3514c0a534Smrg#include <X11/StringDefs.h>
3614c0a534Smrg#include <X11/Intrinsic.h>
3714c0a534Smrg#include <X11/Xatom.h>
3814c0a534Smrg#include <X11/Xlib.h>
3914c0a534Smrg#include <X11/SM/SMlib.h>
4014c0a534Smrg
4114c0a534Smrg#ifndef _POSIX_SOURCE
4214c0a534Smrg#define _POSIX_SOURCE
4314c0a534Smrg#include <stdio.h>
4414c0a534Smrg#undef _POSIX_SOURCE
4514c0a534Smrg#else
4614c0a534Smrg#include <stdio.h>
4714c0a534Smrg#endif
4814c0a534Smrg#include <stdlib.h>
4914c0a534Smrg
5014c0a534Smrg#ifdef _POSIX_SOURCE
5114c0a534Smrg#include <limits.h>
5214c0a534Smrg#else
5314c0a534Smrg#define _POSIX_SOURCE
5414c0a534Smrg#include <limits.h>
5514c0a534Smrg#undef _POSIX_SOURCE
5614c0a534Smrg#endif
5724047306Smrg
5814c0a534Smrg#ifndef PATH_MAX
5914c0a534Smrg#include <sys/param.h>
6014c0a534Smrg#ifndef PATH_MAX
6114c0a534Smrg#ifdef MAXPATHLEN
6214c0a534Smrg#define PATH_MAX MAXPATHLEN
6314c0a534Smrg#else
6414c0a534Smrg#define PATH_MAX 1024
6514c0a534Smrg#endif
6614c0a534Smrg#endif
6714c0a534Smrg#endif /* PATH_MAX */
6814c0a534Smrg
6914c0a534Smrg
7014c0a534Smrgtypedef struct WinInfo {
7114c0a534Smrg    Window window;
7214c0a534Smrg    SmcConn smc_conn;
7314c0a534Smrg    XtInputId input_id;
7414c0a534Smrg    char *client_id;
7514c0a534Smrg    char **wm_command;
7614c0a534Smrg    int wm_command_count;
7714c0a534Smrg    XClassHint class;
7814c0a534Smrg    char *wm_name;
7914c0a534Smrg    XTextProperty wm_client_machine;
8014c0a534Smrg    struct WinInfo *next;
8114c0a534Smrg
8214c0a534Smrg    unsigned int tested_for_sm_client_id : 1;
8314c0a534Smrg    unsigned int has_save_yourself : 1;
8414c0a534Smrg    unsigned int waiting_for_update : 1;
8514c0a534Smrg    unsigned int got_first_save_yourself : 1;
8614c0a534Smrg
8714c0a534Smrg} WinInfo;
8814c0a534Smrg
8914c0a534Smrgtypedef struct ProxyFileEntry
9014c0a534Smrg{
9114c0a534Smrg    struct ProxyFileEntry *next;
9214c0a534Smrg    int tag;
9314c0a534Smrg    char *client_id;
9414c0a534Smrg    XClassHint class;
9514c0a534Smrg    char *wm_name;
9614c0a534Smrg    int wm_command_count;
9714c0a534Smrg    char **wm_command;
9814c0a534Smrg} ProxyFileEntry;
9914c0a534Smrg
10014c0a534Smrgextern int WriteProxyFileEntry ( FILE *proxyFile, WinInfo *theWindow );
10114c0a534Smrgextern int ReadProxyFileEntry ( FILE *proxyFile, ProxyFileEntry **pentry );
10214c0a534Smrgextern void ReadProxyFile ( char *filename );
10314c0a534Smrgextern char * WriteProxyFile ( void );
10414c0a534Smrgextern char * LookupClientID ( WinInfo *theWindow );
10514c0a534Smrg
106bf2eeab3Smrgextern WinInfo *win_head;
10714c0a534Smrg
10814c0a534Smrg#define SAVEFILE_VERSION 1
10924047306Smrg
11024047306Smrg#ifndef HAVE_ASPRINTF
11124047306Smrg_X_HIDDEN int _X_ATTRIBUTE_PRINTF(2,3) asprintf(char ** ret,
11224047306Smrg                                                const char *format, ...);
11324047306Smrg#endif
114