da69c54193115107d76bc07b3d149c35874025f4
[oweals/cde.git] / cde / programs / dtsession / SmProperty.c
1 /* $XConsortium: SmProperty.c /main/7 1996/02/08 11:27:32 barstow $ */
2 /*                                                                      *
3  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
4  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
5  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
6  * (c) Copyright 1993, 1994 Novell, Inc.                                *
7  */
8 /*************************************<+>*************************************
9  *****************************************************************************
10  **
11  **  File:        SmProperty.c
12  **
13  **  Project:     HP DT Session Manager (dtsession)
14  **
15  **  Description:
16  **  -----------
17  **  This file contains routines that deal with the properties used by the
18  **  session manager to save and restore client information.
19  **
20  **
21  **
22  *******************************************************************
23  **  (c) Copyright Hewlett-Packard Company, 1990.  All rights are  
24  **  reserved.  Copying or other reproduction of this program      
25  **  except for archival purposes is prohibited without prior      
26  **  written consent of Hewlett-Packard Company.                     
27  ********************************************************************
28  **
29  **
30  **
31  *****************************************************************************
32  *************************************<+>*************************************/
33
34 #include <stdio.h>
35 #include <X11/Intrinsic.h>
36 #include <X11/Xutil.h>
37 #include <X11/Xatom.h>
38 #include "Sm.h"
39 #include "SmProtocol.h"
40 #include "SmXSMP.h"
41
42 \f
43 /*************************************<->*************************************
44  *
45  *  GetStandardProperties -
46  *
47  *
48  *  Description: returns information about the specified window
49  *  -----------
50  *
51  *  Inputs:
52  *  ------
53  *  window = window for which we are getting properties
54  * 
55  *  Outputs:
56  *  -------
57  *  argv = data returned from WM_COMMAND property (to restart client)
58  *  argc = number of arguments returned from WM_COMMAND property
59  *  clientMachine = which machine is client running on
60  *  xsmpClient = True if the client is XSMP and False otherwise
61  *  screen = window's screen number
62  *
63  *  Comments:
64  *  --------
65  *  All X (except GetWMHints) were not available until R4 and therefore have
66  *  R4 or greater dependencies.
67  *
68  *  BEWARE OF THESE ROUTINES:  The XGetWindowProperty routine returns 0 if
69  *  it succeeds.  These routines (which were derived from XGetWindowProperty
70  *  return 0 if they FAIL.
71  * 
72  *************************************<->***********************************/
73 Status GetStandardProperties(
74         Window                  window,
75         int                     screen,
76         int                     *argc,                  /* RETURNED */
77         char                    ***argv,                /* RETURNED */
78         char                    **clientMachine,        /* RETURNED */
79         Boolean                 *xsmpClient)            /* RETURNED */
80 {
81   int                           cc;
82   long                          suppliedRet;
83   XTextProperty                 sessProp;
84   Atom                          actType;
85   int                           actFormat;
86   unsigned long                 bytesAfter;
87   unsigned long                 nitems;
88   unsigned char                 *data = NULL;
89
90   /*
91    * If this client is participating in the XSMP, then don't save
92    * it as a proxy (pre-XSMP) client.  However, do cache its
93    * screen number before returning.
94    */
95   if (XGetWindowProperty(smGD.display, window, XaSmClientId, 0L,
96                          (long) BUFSIZ, False, XA_STRING, &actType,
97                          &actFormat, &nitems, &bytesAfter, &data) == Success) 
98   {
99       if (data && actType == XA_STRING)
100       {
101           ClientRecPtr          pClient;
102
103           for (pClient = connectedList; pClient != NULL; 
104                pClient = pClient->next) {
105                if (!strcmp ((char *) data, pClient->clientId)) {
106                    pClient->screenNum = screen;
107                    break;
108                }
109           }
110           *xsmpClient = True;
111           SM_FREE ((char *) data);
112           return (0);
113       }
114       SM_FREE ((char *) data);
115   }
116   *xsmpClient = False;
117
118   /*
119    * Get WM_COMMAND property
120    */
121   if ((cc=XGetCommand(smGD.display,window,argv,argc))==0)
122       return(cc);
123
124   /*
125    * If there is no argc or argv - don't bother going on.  We're not
126    * going to save anything anyway
127    */
128   if(*argc == 0)
129       return(0);
130
131
132   /*
133    * Get WM_CLIENT_MACHINE property
134    */
135   if ((cc=XGetWMClientMachine(smGD.display,window,&sessProp))==0)
136   {
137       *clientMachine = NULL;
138   }
139   else
140   {
141       *clientMachine =  (char *) sessProp.value;
142   }
143
144   return(1);
145 }