SmProperty.c 5.1 KB

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