GetMwmW.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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: GetMwmW.c /main/5 1996/05/20 16:07:08 drk $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 1990,1993,1994,1996 Hewlett-Packard Company.
  27. * (c) Copyright 1993,1994,1996 International Business Machines Corp.
  28. * (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
  29. * (c) Copyright 1993,1994,1996 Novell, Inc.
  30. * (c) Copyright 1996 FUJITSU LIMITED.
  31. * (c) Copyright 1996 Hitachi.
  32. */
  33. /************************************<+>*************************************
  34. ****************************************************************************
  35. **
  36. ** File: GetMwmW.c
  37. **
  38. ** Project: DT Workspace Manager
  39. **
  40. ** Description: Gets the mwm window id.
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. #include <stdio.h>
  45. #include <X11/Xlib.h>
  46. #include <X11/Xutil.h>
  47. #include <Xm/MwmUtil.h>
  48. #include <Xm/Xm.h>
  49. #include <Xm/AtomMgr.h>
  50. /******** Public Function Declarations ********/
  51. extern int _DtGetMwmWindow(
  52. Display *display,
  53. Window root,
  54. Window *pMwmWindow) ;
  55. /******** End Public Function Declarations ********/
  56. /******** Static Function Declarations ********/
  57. static int _GetMwmWindow(
  58. Display *display,
  59. Window root,
  60. Window *pMwmWindow,
  61. Atom property) ;
  62. /******** End Static Function Declarations ********/
  63. /*************************************<->*************************************
  64. *
  65. * int _GetMwmWindow (display, root, pMwmWindow, property)
  66. *
  67. *
  68. * Description:
  69. * -----------
  70. * Get the Motif Window manager window
  71. *
  72. *
  73. * Inputs:
  74. * ------
  75. * display - display
  76. * root - root window of screen
  77. * pMwmWindow - pointer to a window (to be returned)
  78. * property - the property atom
  79. *
  80. * Outputs:
  81. * --------
  82. * *pMwmWindow - mwm window id, if successful
  83. * Return - status from XGetWindowProperty
  84. *
  85. * Comments:
  86. * --------
  87. * This can fail if mwm is not managing the screen for the root window
  88. * passed in.
  89. *
  90. *************************************<->***********************************/
  91. static int
  92. _GetMwmWindow(
  93. Display *display,
  94. Window root,
  95. Window *pMwmWindow,
  96. Atom property )
  97. {
  98. Atom actualType;
  99. int actualFormat;
  100. unsigned long nitems;
  101. unsigned long leftover;
  102. PropMotifWmInfo *pWmInfo = NULL;
  103. int rcode;
  104. Window wroot, wparent, *pchildren;
  105. unsigned int nchildren;
  106. *pMwmWindow = 0;
  107. if ((rcode=XGetWindowProperty(display,root,
  108. property,0L, PROP_MWM_INFO_ELEMENTS,
  109. False,property,
  110. &actualType,&actualFormat,
  111. &nitems,&leftover,(unsigned char **)&pWmInfo))==Success)
  112. {
  113. if (actualType != property)
  114. {
  115. /* wrong type, force failure */
  116. rcode = BadValue;
  117. }
  118. else
  119. {
  120. rcode = BadWindow; /* assume the worst */
  121. /*
  122. * The mwm window should be a direct child of root
  123. */
  124. if (XQueryTree (display, root, &wroot, &wparent,
  125. &pchildren, &nchildren))
  126. {
  127. int i;
  128. for (i = 0; (i < nchildren) && (rcode != Success); i++)
  129. {
  130. if (pchildren[i] == pWmInfo->wmWindow)
  131. {
  132. rcode = Success;
  133. }
  134. }
  135. }
  136. if (rcode == Success)
  137. {
  138. *pMwmWindow = pWmInfo->wmWindow;
  139. }
  140. if (pchildren)
  141. {
  142. XFree ((char *)pchildren);
  143. }
  144. }
  145. if (pWmInfo)
  146. {
  147. XFree ((char *)pWmInfo);
  148. }
  149. }
  150. return(rcode);
  151. } /* END OF FUNCTION _GetMwmWindow */
  152. /*************************************<->*************************************
  153. *
  154. * int _DtGetMwmWindow (display, root, pMwmWindow)
  155. *
  156. *
  157. * Description:
  158. * -----------
  159. * Get the Motif Window manager window
  160. *
  161. *
  162. * Inputs:
  163. * ------
  164. * display - display
  165. * root - root window of screen
  166. * pMwmWindow - pointer to a window (to be returned)
  167. *
  168. * Outputs:
  169. * --------
  170. * *pMwmWindow - mwm window id, if successful
  171. * Return - status from XGetWindowProperty
  172. *
  173. * Comments:
  174. * --------
  175. * This can fail if mwm is not managing the screen for the root window
  176. * passed in.
  177. *
  178. *************************************<->***********************************/
  179. int
  180. _DtGetMwmWindow(
  181. Display *display,
  182. Window root,
  183. Window *pMwmWindow )
  184. {
  185. Atom xa_MWM_INFO;
  186. xa_MWM_INFO = XmInternAtom (display, _XA_MWM_INFO, False);
  187. return (_GetMwmWindow (display, root, pMwmWindow, xa_MWM_INFO));
  188. }