2
0

WmWsHints.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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: WmWsHints.c /main/5 1996/05/20 16:08:33 drk $
  24. *
  25. * (c) Copyright 1996 Digital Equipment Corporation.
  26. * (c) Copyright 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: WmWsHints.c
  37. **
  38. ** Project: DT Workspace Manager
  39. **
  40. ** Description: Set and Get workspace hints.
  41. **
  42. ****************************************************************************
  43. ************************************<+>*************************************/
  44. #include <stdio.h>
  45. #include <X11/Xlib.h>
  46. #include <X11/Xutil.h>
  47. #include <Dt/Wsm.h>
  48. #include <Dt/WsmP.h>
  49. #include <Xm/Xm.h>
  50. #include <Xm/AtomMgr.h>
  51. /*************************************<->*************************************
  52. *
  53. * _DtWsmSetWorkspaceHints (display, window, pWsHints)
  54. *
  55. *
  56. * Description:
  57. * -----------
  58. * Set the contents of the _DT_WORKSPACE_HINTS property on a window
  59. *
  60. *
  61. * Inputs:
  62. * ------
  63. * display - display
  64. * window - window to get hints from
  65. * pWsHints - pointer to workspace hints
  66. *
  67. * Comments:
  68. * ---------
  69. * The internal form of the property is a structure. The structure
  70. * must be unwound and turned into a simple array of "long"s before
  71. * being written out.
  72. *
  73. * This function currently only deals with version 1 of the property
  74. * structure. The passed in pWsHints->version is ignored.
  75. *
  76. *************************************<->***********************************/
  77. void
  78. _DtWsmSetWorkspaceHints(
  79. Display *display,
  80. Window window,
  81. DtWorkspaceHints *pWsHints)
  82. {
  83. unsigned int iSizeWsHints;
  84. Atom property;
  85. long *pPropValue, *pP;
  86. int i;
  87. /*
  88. * Unwind structure into a simple array of longs.
  89. *
  90. * Compute size of property to write (don't count
  91. * pointer to workspaces, it will be unwound).
  92. */
  93. iSizeWsHints = sizeof(DtWorkspaceHints) - sizeof(long);
  94. if (pWsHints->flags & DT_WORKSPACE_HINTS_WORKSPACES)
  95. {
  96. iSizeWsHints += pWsHints->numWorkspaces * sizeof(long);
  97. }
  98. pP = pPropValue = (long *) XtMalloc (iSizeWsHints);
  99. *pP++ = 1; /* only deals with version 1 !! */
  100. *pP++ = pWsHints->flags;
  101. if (pWsHints->flags & DT_WORKSPACE_HINTS_WSFLAGS)
  102. *pP++ = pWsHints->wsflags;
  103. else
  104. *pP++ = 0L;
  105. if (pWsHints->flags & DT_WORKSPACE_HINTS_WORKSPACES)
  106. {
  107. *pP++ = pWsHints->numWorkspaces;
  108. for (i=0; i<pWsHints->numWorkspaces; i++)
  109. {
  110. *pP++ = pWsHints->pWorkspaces[i];
  111. }
  112. }
  113. else
  114. {
  115. *pP++ = 0L; /* numWorkspaces */
  116. }
  117. property = XmInternAtom (display, _XA_DT_WORKSPACE_HINTS, False);
  118. XChangeProperty (display, window, property,
  119. property, 32, PropModeReplace,
  120. (unsigned char *)pPropValue, (iSizeWsHints/sizeof(long)));
  121. }
  122. /*************************************<->*************************************
  123. *
  124. * int _DtWsmGetWorkspaceHints (display, window, ppWsHints)
  125. *
  126. *
  127. * Description:
  128. * -----------
  129. * Get the contents of the _DT_WORKSPACE_HINTS property from a window
  130. *
  131. *
  132. * Inputs:
  133. * ------
  134. * display - display
  135. * window - window to get hints from
  136. * ppWsHints - pointer to pointer to workspace hints
  137. *
  138. * Outputs:
  139. * *ppWsHints - allocated workspace hints data.
  140. *
  141. * Comments:
  142. * ---------
  143. * The internal form of the property is a structure. The property
  144. * is read in and packed into data allocated for the structure.
  145. * Free the workspace hints by calling _DtWsmFreeWorkspaceHints.
  146. *
  147. * This function currently only deals with version 1 of the property
  148. * structure.
  149. *
  150. *************************************<->***********************************/
  151. int
  152. _DtWsmGetWorkspaceHints(
  153. Display *display,
  154. Window window,
  155. DtWorkspaceHints **ppWsHints)
  156. {
  157. unsigned int iSizeWsHints;
  158. Atom property;
  159. DtWorkspaceHints *pWsH;
  160. long *pP = NULL;
  161. long *pProp = NULL;
  162. int i;
  163. Atom actualType;
  164. int actualFormat;
  165. unsigned long leftover, lcount;
  166. int rcode;
  167. property = XmInternAtom (display, _XA_DT_WORKSPACE_HINTS, False);
  168. if ((rcode = XGetWindowProperty(
  169. display,
  170. window,
  171. property,
  172. 0L,
  173. (long)BUFSIZ,
  174. False,
  175. property,
  176. &actualType,
  177. &actualFormat,
  178. &lcount,
  179. &leftover,
  180. (unsigned char **)&pProp))==Success)
  181. {
  182. if (actualType != property)
  183. {
  184. /* wrong type, force failure */
  185. rcode = BadValue;
  186. }
  187. else
  188. {
  189. pP = pProp;
  190. pWsH = (DtWorkspaceHints *)
  191. XtMalloc (sizeof(DtWorkspaceHints) * sizeof(long));
  192. pWsH->version = *pP++;
  193. /*
  194. * Only handles version 1
  195. *
  196. * (Fudge the test a little so that newer versions
  197. * won't be treated as older versions. This assumes
  198. * that customers will migrate their software after
  199. * a couple of revisions of these hints.)
  200. */
  201. if (pWsH->version > 5)
  202. {
  203. /*
  204. * Assume old version of hints which was a simple
  205. * list of atoms.
  206. */
  207. pWsH->version = 1;
  208. pWsH->flags = DT_WORKSPACE_HINTS_WORKSPACES;
  209. pWsH->wsflags = 0;
  210. pWsH->numWorkspaces = lcount;
  211. /* reset pointer to first atom in list */
  212. pP--;
  213. }
  214. else
  215. {
  216. pWsH->flags = *pP++;
  217. pWsH->wsflags = *pP++;
  218. pWsH->numWorkspaces = *pP++;
  219. }
  220. if (pWsH->flags & DT_WORKSPACE_HINTS_WORKSPACES)
  221. {
  222. pWsH->pWorkspaces = (Atom *)
  223. XtMalloc (pWsH->numWorkspaces * sizeof (Atom));
  224. for (i=0; i<pWsH->numWorkspaces; i++)
  225. {
  226. pWsH->pWorkspaces[i] = *pP++;
  227. }
  228. }
  229. else
  230. {
  231. pWsH->pWorkspaces = NULL;
  232. }
  233. *ppWsHints = pWsH;
  234. }
  235. if (pProp && (actualType != None))
  236. {
  237. XFree ((char *)pProp);
  238. }
  239. }
  240. return (rcode);
  241. }
  242. /*************************************<->*************************************
  243. *
  244. * _DtWsmFreeWorkspaceHints (pWsHints)
  245. *
  246. *
  247. * Description:
  248. * -----------
  249. * Free a workspace hints structure returned from _DtWsmGetWorkspaceHints
  250. *
  251. * Inputs:
  252. * ------
  253. * pWsHints - pointer to workspace hints
  254. *
  255. * Outputs:
  256. *
  257. * Comments:
  258. * ---------
  259. *************************************<->***********************************/
  260. void
  261. _DtWsmFreeWorkspaceHints(
  262. DtWorkspaceHints *pWsHints)
  263. {
  264. if (pWsHints)
  265. {
  266. if (pWsHints->pWorkspaces)
  267. {
  268. XtFree ((char *) pWsHints->pWorkspaces);
  269. }
  270. XtFree ((char *)pWsHints);
  271. }
  272. }