WmProperty.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  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. /*
  24. * (c) Copyright 1989, 1990, 1991, 1992, 1993 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2.3
  29. */
  30. /*
  31. * (c) Copyright 1987, 1988, 1989, 1990, 1993 HEWLETT-PACKARD COMPANY */
  32. /*
  33. * Included Files:
  34. */
  35. #include "WmGlobal.h"
  36. #include "WmICCC.h"
  37. #include <stdio.h>
  38. #include <Dt/WsmP.h>
  39. #include <X11/Xatom.h>
  40. #include <Xm/AtomMgr.h>
  41. /*
  42. * include extern functions
  43. */
  44. #include "WmColormap.h"
  45. #include "WmError.h"
  46. #include "WmResParse.h"
  47. #include "WmIconBox.h"
  48. /*
  49. * Function Declarations:
  50. */
  51. #include "WmProperty.h"
  52. /*
  53. * Global Variables:
  54. */
  55. static SizeHints sizeHints;
  56. /*************************************<->*************************************
  57. *
  58. * SizeHints *
  59. * GetNormalHints (pCD)
  60. *
  61. *
  62. * Description:
  63. * -----------
  64. * This function replaces the XGetNormalHints Xlib function. This function
  65. * gets the information in the WM_NORMAL_HINTS property on the client window.
  66. * The property encoding can be any of the supported versions (R2, R3+).
  67. *
  68. *
  69. * Inputs:
  70. * ------
  71. * pCD = (client)
  72. *
  73. *
  74. * Outputs:
  75. * -------
  76. * Return = A pointer to a filled out SizeHints structure is returned.
  77. * Default values are set if the WM_NORMAL_HINTS property could
  78. * not be retrieved.
  79. *
  80. *************************************<->***********************************/
  81. SizeHints *
  82. GetNormalHints(
  83. ClientData *pCD )
  84. {
  85. PropSizeHints *property = NULL;
  86. Atom actualType;
  87. int actualFormat;
  88. unsigned long leftover;
  89. unsigned long nitems;
  90. /*
  91. * Retrieve the property data.
  92. *
  93. * ICCC_R2 version: nitems = PROP_SIZE_HINTS_ELEMENTS - 3
  94. * ICCC_CURRENT version: nitems = PROP_SIZE_HINTS_ELEMENTS
  95. */
  96. if ((!HasProperty (pCD, XA_WM_NORMAL_HINTS)) ||
  97. ((Success != XGetWindowProperty (DISPLAY, pCD->client,
  98. XA_WM_NORMAL_HINTS, 0L, (long)PROP_SIZE_HINTS_ELEMENTS,
  99. False, XA_WM_SIZE_HINTS, &actualType, &actualFormat,
  100. &nitems, &leftover, (unsigned char **)&property)) ||
  101. (actualType != XA_WM_SIZE_HINTS) ||
  102. (nitems < (PROP_SIZE_HINTS_ELEMENTS - 3)) ||
  103. (actualFormat != 32)))
  104. {
  105. /*
  106. * Indicate no property values were retrieved:
  107. */
  108. sizeHints.icccVersion = ICCC_UNKNOWN;
  109. sizeHints.flags = 0;
  110. }
  111. else
  112. {
  113. /*
  114. * Parse the hint values out of the property data:
  115. */
  116. sizeHints.flags = property->flags;
  117. sizeHints.x = property->x;
  118. sizeHints.y = property->y;
  119. sizeHints.width = property->width;
  120. sizeHints.height = property->height;
  121. sizeHints.min_width = property->minWidth;
  122. sizeHints.min_height = property->minHeight;
  123. sizeHints.max_width = property->maxWidth;
  124. sizeHints.max_height = property->maxHeight;
  125. sizeHints.width_inc = property->widthInc;
  126. sizeHints.height_inc = property->heightInc;
  127. sizeHints.min_aspect.x = (int)property->minAspectX;
  128. sizeHints.min_aspect.y = (int)property->minAspectY;
  129. sizeHints.max_aspect.x = (int)property->maxAspectX;
  130. sizeHints.max_aspect.y = (int)property->maxAspectY;
  131. if (nitems == (PROP_SIZE_HINTS_ELEMENTS - 3))
  132. {
  133. /*
  134. * This is ICCC_R2.
  135. */
  136. sizeHints.icccVersion = ICCC_R2;
  137. }
  138. else
  139. {
  140. /*
  141. * This is ICCC_CURRENT.
  142. */
  143. sizeHints.icccVersion = ICCC_CURRENT;
  144. sizeHints.base_width = property->baseWidth;
  145. sizeHints.base_height = property->baseHeight;
  146. sizeHints.win_gravity = property->winGravity;
  147. }
  148. }
  149. /*
  150. * Free the property data buffer:
  151. */
  152. if (property)
  153. {
  154. XFree ((char *)property);
  155. }
  156. /*
  157. * Return the hints values:
  158. */
  159. return (&sizeHints);
  160. } /* END OF FUNCTION GetNormalHints */
  161. /*************************************<->*************************************
  162. *
  163. * ProcessWmProtocols (pCD)
  164. *
  165. *
  166. * Description:
  167. * -----------
  168. * This function reads and processes the WM_PROTOCOLS property that is
  169. * associated with a client window.
  170. *
  171. * ICCC_COMPLIANT check added to allow older clients to work, for now...
  172. * eventually, this code should be removed.
  173. *
  174. * Inputs:
  175. * ------
  176. * pCD = pointer to client data
  177. *
  178. *
  179. * Outputs:
  180. * -------
  181. * pCD = (clientProtocols, clientProtocolCount, protocolFlags)
  182. *
  183. *************************************<->***********************************/
  184. void ProcessWmProtocols (ClientData *pCD)
  185. {
  186. int rValue;
  187. Atom *property = NULL;
  188. #ifndef ICCC_COMPLIANT
  189. Atom actualType;
  190. int actualFormat;
  191. unsigned long leftover;
  192. unsigned long nitems;
  193. #else
  194. int nitems;
  195. #endif /* ICCC_COMPLIANT */
  196. int i;
  197. if (pCD->clientProtocols)
  198. {
  199. XtFree ((char *)pCD->clientProtocols);
  200. pCD->clientProtocols = NULL;
  201. }
  202. pCD->clientProtocolCount = 0;
  203. pCD->protocolFlags = 0;
  204. /*
  205. * Read the WM_PROTOCOLS property.
  206. */
  207. #ifndef ICCC_COMPLIANT
  208. if (!HasProperty (pCD, wmGD.xa_WM_PROTOCOLS))
  209. rValue = -1;
  210. else
  211. rValue = XGetWindowProperty (DISPLAY, pCD->client, wmGD.xa_WM_PROTOCOLS, 0L,
  212. (long)MAX_CLIENT_PROTOCOL_COUNT, False, AnyPropertyType,
  213. &actualType, &actualFormat, &nitems, &leftover,
  214. (unsigned char **)&property);
  215. if ((rValue != Success) || (actualType == None) || (actualFormat != 32))
  216. #else
  217. if (!HasProperty (pCD, wmGD.xa_WM_PROTOCOLS))
  218. rValue = -1;
  219. else
  220. rValue = XGetWMProtocols (DISPLAY, pCD->client,
  221. (Atom **)&property, &nitems);
  222. if (0 == rValue)
  223. #endif /* ICCC_COMPLIANT */
  224. {
  225. /*
  226. * WM_PROTOCOLS does not exist or it is an invalid type or size.
  227. */
  228. pCD->clientProtocols = NULL;
  229. }
  230. else
  231. {
  232. if (!(pCD->clientProtocols = (Atom *)XtMalloc (nitems * sizeof (Atom))))
  233. {
  234. /* unable to allocate space */
  235. Warning (((char *)GETMESSAGE(54, 1, "Insufficient memory for window management data")));
  236. }
  237. else
  238. {
  239. /*
  240. * Save the protocols in the client data and look for predefined
  241. * protocols.
  242. */
  243. pCD->clientProtocolCount = nitems;
  244. for (i = 0; i < nitems; i++)
  245. {
  246. pCD->clientProtocols[i] = property[i];
  247. if (property[i] == wmGD.xa_WM_SAVE_YOURSELF)
  248. {
  249. pCD->protocolFlags |= PROTOCOL_WM_SAVE_YOURSELF;
  250. }
  251. else if (property[i] == wmGD.xa_WM_TAKE_FOCUS)
  252. {
  253. pCD->protocolFlags |= PROTOCOL_WM_TAKE_FOCUS;
  254. }
  255. else if (property[i] == wmGD.xa_WM_DELETE_WINDOW)
  256. {
  257. pCD->protocolFlags |= PROTOCOL_WM_DELETE_WINDOW;
  258. }
  259. else if (property[i] == wmGD.xa_MWM_MESSAGES)
  260. {
  261. pCD->protocolFlags |= PROTOCOL_MWM_MESSAGES;
  262. }
  263. }
  264. }
  265. }
  266. if (property)
  267. {
  268. XFree ((char *)property);
  269. }
  270. } /* END OF FUNCTION ProcessWmProtocols */
  271. /*************************************<->*************************************
  272. *
  273. * ProcessMwmMessages (pCD)
  274. *
  275. *
  276. * Description:
  277. * -----------
  278. * This function reads and processes the _MWM_MESSAGES property that is
  279. * associated with a client window.
  280. *
  281. *
  282. * Inputs:
  283. * ------
  284. * pCD = pointer to client data
  285. *
  286. *
  287. * Outputs:
  288. * -------
  289. * pCD = (mwmMessagesCount, mwmMessages)
  290. *
  291. *************************************<->***********************************/
  292. void ProcessMwmMessages (ClientData *pCD)
  293. {
  294. int rValue;
  295. long *property = NULL;
  296. Atom actualType;
  297. int actualFormat;
  298. unsigned long leftover;
  299. unsigned long nitems;
  300. int i;
  301. if (pCD->mwmMessages)
  302. {
  303. XtFree ((char *)pCD->mwmMessages);
  304. pCD->mwmMessages = NULL;
  305. }
  306. pCD->mwmMessagesCount = 0;
  307. /*
  308. * Read the _MWM_MESSAGES property.
  309. */
  310. if (!HasProperty (pCD, wmGD.xa_MWM_MESSAGES))
  311. rValue = ~Success;
  312. else
  313. rValue = XGetWindowProperty (DISPLAY, pCD->client, wmGD.xa_MWM_MESSAGES, 0L,
  314. (long)MAX_MWM_MESSAGES_COUNT, False, AnyPropertyType,
  315. &actualType, &actualFormat, &nitems, &leftover,
  316. (unsigned char **)&property);
  317. if ((rValue != Success) || (actualType == None) || (actualFormat != 32)
  318. || (nitems == 0))
  319. {
  320. /*
  321. * _MWM_MESSAGES does not exist or it is an invalid type.
  322. */
  323. pCD->mwmMessages = NULL;
  324. }
  325. else
  326. {
  327. if (!(pCD->mwmMessages = (long *)XtMalloc (nitems * sizeof (long))))
  328. {
  329. /* unable to allocate space */
  330. Warning (((char *)GETMESSAGE(54, 2, "Insufficient memory for window management data")));
  331. }
  332. else
  333. {
  334. /*
  335. * Save the protocols in the client data and look for predefined
  336. * protocols.
  337. */
  338. pCD->mwmMessagesCount = nitems;
  339. for (i = 0; i < nitems; i++)
  340. {
  341. if ((pCD->mwmMessages[i] = property[i]) == wmGD.xa_MWM_OFFSET)
  342. {
  343. pCD->protocolFlags |= PROTOCOL_MWM_OFFSET;
  344. }
  345. }
  346. }
  347. }
  348. if (property)
  349. {
  350. XFree ((char *)property);
  351. }
  352. } /* END OF FUNCTION ProcessMwmMessages */
  353. /*************************************<->*************************************
  354. *
  355. * SetMwmInfo (propWindow, flags, wmWindow)
  356. *
  357. *
  358. * Description:
  359. * -----------
  360. * This function sets up the _MOTIF_WM_INFO property on the specified (usually
  361. * the root) window.
  362. *
  363. *
  364. * Inputs:
  365. * ------
  366. * propWindow = window on which the _MOTIF_WM_INFO property is to be set
  367. *
  368. * flags = motifWmInfo.flags value
  369. *
  370. * wmWindow = motifWmInfo.wmWindow value
  371. *
  372. *
  373. * Outputs:
  374. * -------
  375. * _MWM_INFO = this property is set on the specified window
  376. *
  377. *************************************<->***********************************/
  378. void SetMwmInfo (Window propWindow, long flags, Window wmWindow)
  379. {
  380. PropMwmInfo property;
  381. property.flags = flags;
  382. property.wmWindow = wmWindow;
  383. XChangeProperty (DISPLAY, propWindow, wmGD.xa_MWM_INFO, wmGD.xa_MWM_INFO,
  384. 32, PropModeReplace, (unsigned char *)&property,
  385. PROP_MWM_INFO_ELEMENTS);
  386. } /* END OF FUNCTION SetMwmInfo */
  387. /*************************************<->*************************************
  388. *
  389. * SetMwmSaveSessionInfo (wmWindow)
  390. *
  391. *
  392. * Description:
  393. * -----------
  394. * This function sets up the WM_SAVE_YOURSELF property on the wm window
  395. *
  396. *
  397. * Inputs:
  398. * ------
  399. * wmWindow = motifWmInfo.wmWindow
  400. *
  401. *
  402. * Outputs:
  403. * -------
  404. * WM_SAVE_YOURSELF = this property is set on the wm window
  405. *
  406. *************************************<->***********************************/
  407. void SetMwmSaveSessionInfo (Window wmWindow)
  408. {
  409. Atom property;
  410. property = wmGD.xa_WM_SAVE_YOURSELF;
  411. XChangeProperty (DISPLAY, wmWindow,
  412. wmGD.xa_WM_PROTOCOLS, XA_ATOM,
  413. 32, PropModeReplace,
  414. (unsigned char *) &property, 1);
  415. SetWMState(wmWindow, NORMAL_STATE, 0);
  416. } /* END OF FUNCTION SetMwmSaveSessionInfo */
  417. /*************************************<->*************************************
  418. *
  419. * GetWMState (window)
  420. *
  421. *
  422. * Description:
  423. * -----------
  424. * This function gets the WM_STATE property on a client top-level
  425. * window.
  426. *
  427. *
  428. * Inputs:
  429. * ------
  430. * window = client window from which the WM_STATE property is to be retrieved
  431. *
  432. *
  433. * Outputs:
  434. * -------
  435. * RETURN = a pointer to the WM_STATE property value (NULL if not defined)
  436. *
  437. *
  438. * Comments:
  439. * --------
  440. * This function will eventually be superseded when WM_STATE support is
  441. * added to the official X release.
  442. *
  443. *************************************<->***********************************/
  444. PropWMState *
  445. GetWMState(
  446. Window window )
  447. {
  448. int ret_val;
  449. PropWMState *property = NULL;
  450. Atom actual_type;
  451. int actual_format;
  452. unsigned long nitems;
  453. unsigned long leftover;
  454. ret_val = XGetWindowProperty (DISPLAY, window, wmGD.xa_WM_STATE,
  455. 0L, PROP_WM_STATE_ELEMENTS,
  456. False, wmGD.xa_WM_STATE,
  457. &actual_type, &actual_format,
  458. &nitems, &leftover, (unsigned char **)&property);
  459. if (!((ret_val == Success) && (actual_type == wmGD.xa_WM_STATE) &&
  460. (nitems == PROP_WM_STATE_ELEMENTS)))
  461. {
  462. /*
  463. * The property could not be retrieved or is not correctly set up.
  464. */
  465. if (property)
  466. {
  467. XFree ((char *)property);
  468. property = NULL;
  469. }
  470. }
  471. return (property);
  472. } /* END OF FUNCTION GetWMState */
  473. /*************************************<->*************************************
  474. *
  475. * SetWMState (window, state, icon)
  476. *
  477. *
  478. * Description:
  479. * -----------
  480. * This function sets up the WM_STATE property on a client top-level
  481. * window.
  482. *
  483. *
  484. * Inputs:
  485. * ------
  486. * window = client window on which the WM_STATE property is to be set
  487. *
  488. * state = state of the client application
  489. *
  490. * icon = window manager's icon window
  491. *
  492. *
  493. * Outputs:
  494. * -------
  495. * WM_STATE = this property is set on the client window
  496. *
  497. *
  498. * Comments:
  499. * --------
  500. * This function will eventually be superseded when WM_STATE support is
  501. * added to the official X release.
  502. *
  503. *************************************<->***********************************/
  504. void SetWMState (Window window, int state, Window icon)
  505. {
  506. PropWMState property;
  507. property.state = state;
  508. property.icon = icon;
  509. XChangeProperty (DISPLAY, window, wmGD.xa_WM_STATE, wmGD.xa_WM_STATE, 32,
  510. PropModeReplace, (unsigned char *)&property, PROP_WM_STATE_ELEMENTS);
  511. } /* END OF FUNCTION SetWMState */
  512. /*************************************<->*************************************
  513. *
  514. * PropMwmHints *
  515. * GetMwmHints (pCD)
  516. *
  517. *
  518. * Description:
  519. * -----------
  520. * This function reads any _MWM_HINTS property that is associated with a
  521. * client window.
  522. *
  523. * Inputs:
  524. * ------
  525. * pCD = pointer to client data
  526. *
  527. * Outputs:
  528. * -------
  529. * RETURN = ptr to mwm hints property, or NULL ptr if failure
  530. *
  531. *************************************<->***********************************/
  532. PropMwmHints *
  533. GetMwmHints(
  534. ClientData *pCD )
  535. {
  536. int ret_val;
  537. PropMwmHints *property = NULL;
  538. Atom actual_type;
  539. int actual_format;
  540. unsigned long nitems;
  541. unsigned long leftover;
  542. if (!HasProperty(pCD, wmGD.xa_MWM_HINTS))
  543. ret_val = ~Success;
  544. else
  545. ret_val = XGetWindowProperty (DISPLAY, pCD->client, wmGD.xa_MWM_HINTS,
  546. 0L, PROP_MWM_HINTS_ELEMENTS,
  547. False, wmGD.xa_MWM_HINTS,
  548. &actual_type, &actual_format,
  549. &nitems, &leftover, (unsigned char **)&property);
  550. /*
  551. * Retrieve the property data.
  552. *
  553. * Motif 1.1.n clients: nitems = PROP_MWM_HINTS_ELEMENTS
  554. * Motif 1.2 clients: nitems = PROP_MWM_HINTS_ELEMENTS + 2
  555. *
  556. * NOTES: We don't need to check (nitems == PROP_MWM_HINTS_ELEMENTS)
  557. * since...
  558. *
  559. * If running Motif 1.1.n client with Mwm 1.2, then ignore extra elements
  560. * since property.flags won't have extra elements set.
  561. *
  562. * If running Motif 1.2 client with Mwm 1.1.n, then ignore extra elements
  563. * since Mwm 1.1.n won't try to access the extra elements.
  564. */
  565. if ((ret_val == Success) && (actual_type == wmGD.xa_MWM_HINTS))
  566. {
  567. return (property); /* indicate success */
  568. }
  569. /*
  570. * The property could not be retrieved or is not correctly set up.
  571. */
  572. if (property)
  573. {
  574. XFree ((char *)property);
  575. }
  576. return (NULL); /* indicate failure */
  577. } /* END OF FUNCTION GetMwmHints */
  578. /*************************************<->*************************************
  579. *
  580. * PropMwmInfo *
  581. * GetMwmInfo (rootWindowOfScreen)
  582. *
  583. *
  584. * Description:
  585. * -----------
  586. * This function reads the _MOTIF_WM_INFO property from the root window if
  587. * it is setup.
  588. *
  589. * Inputs:
  590. * ------
  591. * pSD = pointer to screen data
  592. *
  593. * Outputs:
  594. * -------
  595. * RETURN = ptr to motif wm info property, or NULL ptr if no property
  596. *
  597. *************************************<->***********************************/
  598. PropMwmInfo *GetMwmInfo (Window rootWindowOfScreen)
  599. {
  600. int ret_val;
  601. PropMwmInfo *property = NULL;
  602. Atom actual_type;
  603. int actual_format;
  604. unsigned long nitems;
  605. unsigned long leftover;
  606. ret_val = XGetWindowProperty (DISPLAY, rootWindowOfScreen,
  607. wmGD.xa_MWM_INFO,
  608. 0L, PROP_MWM_INFO_ELEMENTS,
  609. False, wmGD.xa_MWM_INFO,
  610. &actual_type, &actual_format,
  611. &nitems, &leftover,
  612. (unsigned char **)&property);
  613. if ((ret_val == Success) && (actual_type == wmGD.xa_MWM_INFO) &&
  614. (nitems == PROP_MWM_INFO_ELEMENTS))
  615. {
  616. return (property); /* indicate success */
  617. }
  618. /*
  619. * The property could not be retrieved or is not correctly set up.
  620. */
  621. if (property)
  622. {
  623. XFree ((char *)property);
  624. }
  625. return (NULL); /* indicate failure */
  626. } /* END OF FUNCTION GetMwmInfo */
  627. /*************************************<->*************************************
  628. *
  629. * ProcessWmColormapWindows (pCD)
  630. *
  631. *
  632. * Description:
  633. * -----------
  634. * This function retrieves and processes the WM_COLORMAP_WINDOWS client
  635. * window property.
  636. *
  637. *
  638. * Inputs:
  639. * ------
  640. * pCD = pointer to client data
  641. *
  642. *
  643. * Outputs:
  644. * -------
  645. * pCD = (cmapWindows, clientCmapList, clientCmapCount, clientCmapIndex)
  646. *
  647. *************************************<->***********************************/
  648. void ProcessWmColormapWindows (ClientData *pCD)
  649. {
  650. int rValue;
  651. Window *property = NULL;
  652. Atom actualType;
  653. int actualFormat;
  654. unsigned long leftover;
  655. unsigned long nitems;
  656. int i;
  657. Window *pWindows;
  658. Colormap *pColormaps;
  659. int colormapCount;
  660. XWindowAttributes wAttributes;
  661. ClientData *pcd;
  662. XSetWindowAttributes sAttributes;
  663. int *pCmapFlags;
  664. /*
  665. * pCD->clientCmapCount and pCD->clientCmapIndex are initialized in
  666. * WmWinInfo.c.
  667. */
  668. /*
  669. * Read the WM_COLORMAP_WINDOWS property.
  670. */
  671. rValue = XGetWindowProperty (DISPLAY, pCD->client,
  672. wmGD.xa_WM_COLORMAP_WINDOWS, 0L,
  673. (long)MAX_COLORMAP_WINDOWS_COUNT, False, AnyPropertyType,
  674. &actualType, &actualFormat, &nitems, &leftover,
  675. (unsigned char **)&property);
  676. if ((rValue == Success) && (actualType != None) && (actualFormat == 32) &&
  677. (nitems > 0))
  678. {
  679. /*
  680. * WM_COLORMAP_WINDOWS exists and is a valid type.
  681. */
  682. if (!(pWindows = (Window *)XtMalloc ((nitems * sizeof (Window)) + 1)) ||
  683. !(pColormaps = (Colormap *)XtMalloc ((nitems*sizeof(Colormap)) + 1)))
  684. {
  685. /* unable to allocate space */
  686. Warning (((char *)GETMESSAGE(54, 3, "Insufficient memory for window management data")));
  687. if (pWindows)
  688. {
  689. XtFree ((char *)pWindows);
  690. }
  691. }
  692. /* Is the above OSF code a bug -- allocates one extra byte, rather */
  693. /* than one extra element, for the top window if needed? */
  694. else if ( ! (pCmapFlags = (int *)XtCalloc(nitems+1,sizeof(int)))) {
  695. /* unable to allocate space */
  696. Warning (((char *)GETMESSAGE(54, 4, "Insufficient memory for window manager flags")));
  697. XtFree ((char *)pWindows); XtFree ((char *)pColormaps);
  698. }
  699. else
  700. {
  701. /*
  702. * Check to see if the top-level client window is in the list.
  703. * If it is not then add it to the head of the list.
  704. */
  705. for (i = 0; i < nitems; i++)
  706. {
  707. if (property[i] == pCD->client)
  708. {
  709. break;
  710. }
  711. }
  712. colormapCount = 0;
  713. if (i == nitems)
  714. {
  715. /* add the client window to the colormap window list */
  716. pWindows[0] = pCD->client;
  717. pColormaps[0] = FindColormap (pCD, pCD->client);
  718. colormapCount++;
  719. }
  720. sAttributes.event_mask = (ColormapChangeMask);
  721. for (i = 0; i < nitems; i++)
  722. {
  723. if ((pColormaps[colormapCount] =
  724. FindColormap (pCD, property[i])) != None)
  725. {
  726. pWindows[colormapCount] = property[i];
  727. colormapCount++;
  728. }
  729. else if (XFindContext (DISPLAY, property[i],
  730. wmGD.windowContextType, (caddr_t *)&pcd))
  731. {
  732. /*
  733. * The window is not a top level window or a window that
  734. * is already being tracked for colormap changes.
  735. * Track colormap attribute changes.
  736. */
  737. XChangeWindowAttributes (DISPLAY, property[i], CWEventMask,
  738. &sAttributes);
  739. if (XGetWindowAttributes (DISPLAY, property[i],
  740. &wAttributes))
  741. {
  742. pWindows[colormapCount] = property[i];
  743. pColormaps[colormapCount] = wAttributes.colormap;
  744. colormapCount++;
  745. }
  746. }
  747. }
  748. /*
  749. * Free up the old colormap window data if it has been set. Set
  750. * new window contexts.
  751. */
  752. ResetColormapData (pCD, pWindows, colormapCount);
  753. /*
  754. * Set the colormap window data.
  755. */
  756. pCD->clientColormap = pColormaps[0];
  757. if (colormapCount > 1)
  758. {
  759. /*
  760. * The top level window and at least one other window is in
  761. * the colormap windows list.
  762. */
  763. pCD->clientCmapCount = colormapCount;
  764. pCD->cmapWindows = pWindows;
  765. pCD->clientCmapList = pColormaps;
  766. pCD->clientCmapIndex = 0;
  767. pCD->clientCmapFlags = pCmapFlags;
  768. }
  769. else
  770. {
  771. /*
  772. * Only the top level window is being tracked for colormap
  773. * data.
  774. */
  775. pCD->clientCmapCount = 0;
  776. XtFree ((char *)pWindows);
  777. XtFree ((char *)pColormaps);
  778. XtFree((char *)pCmapFlags);
  779. }
  780. }
  781. }
  782. if (property)
  783. {
  784. XFree ((char *)property);
  785. }
  786. } /* END OF FUNCTION ProcessWmColormapWindows */
  787. /*************************************<->*************************************
  788. *
  789. * FindColormap (pCD, window)
  790. *
  791. *
  792. * Description:
  793. * -----------
  794. * This function checks colormap information that is currently saved in
  795. * the client data for the colormap of the specified window.
  796. *
  797. *
  798. * Inputs:
  799. * ------
  800. * pCD = pointer to client data
  801. *
  802. * window = get the colormap id for this window
  803. *
  804. *
  805. * Outputs:
  806. * -------
  807. * RETURN = colormap id for window (NULL if no colormap information)
  808. *
  809. *************************************<->***********************************/
  810. Colormap FindColormap (ClientData *pCD, Window window)
  811. {
  812. Colormap colormap = (Colormap)0;
  813. int i;
  814. if (pCD->clientCmapCount == 0)
  815. {
  816. /*
  817. * If the colormap count is 0 there is no list of colormaps and
  818. * clientColormap is the colormap of the top-level window.
  819. */
  820. if (window == pCD->client)
  821. {
  822. colormap = pCD->clientColormap;
  823. }
  824. }
  825. else
  826. {
  827. for (i = 0; i < pCD->clientCmapCount; i++)
  828. {
  829. if (pCD->cmapWindows[i] == window)
  830. {
  831. colormap = pCD->clientCmapList[i];
  832. break;
  833. }
  834. }
  835. }
  836. return (colormap);
  837. } /* END OF FUNCTION FindColormap */
  838. /*************************************<->*************************************
  839. *
  840. * GetMwmMenuItems (pCD)
  841. *
  842. *
  843. * Description:
  844. * -----------
  845. * This function reads and processes any _MWM_MENU property that is
  846. * associated with a client window and returns a list of MenuItem structures
  847. * specified by the property, or NULL.
  848. *
  849. *
  850. * Inputs:
  851. * ------
  852. * pCD = pointer to client data
  853. *
  854. *
  855. * Outputs:
  856. * -------
  857. * Return = MenuItem list or NULL.
  858. *
  859. *************************************<->***********************************/
  860. MenuItem *
  861. GetMwmMenuItems(
  862. ClientData *pCD )
  863. {
  864. int rValue;
  865. XTextProperty textProperty;
  866. MenuItem *menuItems;
  867. /*
  868. * Read the _MWM_MENU property.
  869. */
  870. textProperty.value = (unsigned char *)NULL;
  871. rValue = XGetTextProperty(DISPLAY, pCD->client, &textProperty,
  872. wmGD.xa_MWM_MENU);
  873. if ((rValue == 0) || (textProperty.value == (unsigned char *)NULL))
  874. /* _MWM_MENU does not exist or it is an invalid type. */
  875. {
  876. menuItems = NULL;
  877. }
  878. else
  879. /* parse the property string */
  880. {
  881. char **textList;
  882. int nItems;
  883. if (XmbTextPropertyToTextList(DISPLAY, &textProperty,
  884. &textList, &nItems) != Success)
  885. {
  886. menuItems = NULL;
  887. }
  888. else
  889. {
  890. menuItems = ParseMwmMenuStr (PSD_FOR_CLIENT(pCD),
  891. (unsigned char *)textList[0]);
  892. XFreeStringList(textList);
  893. }
  894. XFree((void *)textProperty.value);
  895. }
  896. return (menuItems);
  897. } /* END OF FUNCTION GetMwmMenuItems */
  898. /*************************************<->*************************************
  899. *
  900. * GetWorkspaceHints (display, window, ppWsAtoms, pCount, pbAll)
  901. *
  902. *
  903. * Description:
  904. * -----------
  905. * Get the contents of the WM_COMMAND property on a window
  906. *
  907. *
  908. * Inputs:
  909. * ------
  910. * display - X display
  911. * window - window to get hints from
  912. * ppWsAtoms - pointer to a list of workspace atoms (to be returned)
  913. * pCount - ptr to a number of atoms (to be returned)
  914. * pbAll - ptr to a boolean (to be returned)
  915. *
  916. *
  917. * Returns:
  918. * --------
  919. * Success if suceeded, otherwise failure code.
  920. *
  921. *
  922. * Outputs:
  923. * -------
  924. * *ppWsAtoms - list of workspace atoms
  925. * *pCount - number of atoms in *ppWsAtoms
  926. * *pbAll - True if should put in all workspaces
  927. *
  928. *
  929. * Comments:
  930. * --------
  931. * The caller must XtFree *ppWsAtoms when done!!!
  932. *
  933. *************************************<->***********************************/
  934. Status GetWorkspaceHints (Display *display, Window window,
  935. Atom **ppWsAtoms, unsigned int *pCount,
  936. Boolean *pbAll)
  937. {
  938. int rcode;
  939. DtWorkspaceHints *pWsHints;
  940. Atom *paWs;
  941. rcode = _DtWsmGetWorkspaceHints(display, window, &pWsHints);
  942. if (rcode == Success)
  943. {
  944. if (pWsHints->flags & DT_WORKSPACE_HINTS_WORKSPACES)
  945. {
  946. paWs = (Atom *)
  947. XtMalloc (pWsHints->numWorkspaces * sizeof(Atom));
  948. memcpy (paWs,
  949. pWsHints->pWorkspaces,
  950. (pWsHints->numWorkspaces * sizeof(Atom)));
  951. *pCount = pWsHints->numWorkspaces;
  952. *ppWsAtoms = paWs;
  953. }
  954. else
  955. {
  956. *pCount = 0;
  957. *ppWsAtoms = NULL;
  958. }
  959. if ((pWsHints->flags & DT_WORKSPACE_HINTS_WSFLAGS) &&
  960. (pWsHints->wsflags & DT_WORKSPACE_FLAGS_OCCUPY_ALL))
  961. {
  962. *pbAll = True;
  963. }
  964. else
  965. {
  966. *pbAll = False;
  967. }
  968. _DtWsmFreeWorkspaceHints (pWsHints);
  969. }
  970. return(rcode);
  971. } /* END OF FUNCTION GetWorkspaceHints */
  972. /*************************************<->*************************************
  973. *
  974. * SetEmbeddedClientsProperty (propWindow, pEmbeddedClients,
  975. * cEmbeddedCLients)
  976. *
  977. *
  978. * Description:
  979. * -----------
  980. * This function writes the _DT_WORKSPACE_EMBEDDED_CLIENTS property
  981. *
  982. *
  983. * Inputs:
  984. * ------
  985. * propWindow = window on which the property is to be written
  986. * pEmbeddedClients = pointer to data (array of window IDs)
  987. * cEmbeddedClients = number of window IDs in the array
  988. *
  989. *************************************<->***********************************/
  990. void SetEmbeddedClientsProperty (Window propWindow,
  991. Window *pEmbeddedClients, unsigned long cEmbeddedClients)
  992. {
  993. XChangeProperty (DISPLAY, propWindow, wmGD.xa_DT_EMBEDDED_CLIENTS,
  994. wmGD.xa_DT_EMBEDDED_CLIENTS,
  995. 32, PropModeReplace, (unsigned char *)pEmbeddedClients,
  996. cEmbeddedClients);
  997. } /* END OF FUNCTION SetEmbeddedClientsProperty */
  998. /*************************************<->*************************************
  999. *
  1000. * SetWorkspaceListProperty (pSD)
  1001. *
  1002. *
  1003. * Description:
  1004. * -----------
  1005. * This function sets up the _DT_WORKSPACE_LIST property
  1006. *
  1007. *
  1008. * Inputs:
  1009. * ------
  1010. * pSD = ptr to screen data
  1011. *
  1012. *
  1013. *************************************<->***********************************/
  1014. void
  1015. SetWorkspaceListProperty (WmScreenData *pSD)
  1016. {
  1017. WmWorkspaceData *pws;
  1018. Atom *pWsList;
  1019. int count;
  1020. pWsList = (Atom *)
  1021. XtMalloc (pSD->numWorkspaces * sizeof(Atom));
  1022. pws = pSD->pWS;
  1023. for (count = 0; count < pSD->numWorkspaces; count++)
  1024. {
  1025. pWsList[count] = pws->id;
  1026. pws++;
  1027. }
  1028. XChangeProperty (DISPLAY, pSD->wmWorkspaceWin,
  1029. wmGD.xa_DT_WORKSPACE_LIST,
  1030. XA_ATOM,
  1031. 32, PropModeReplace, (unsigned char *)pWsList,
  1032. (pSD->numWorkspaces * sizeof(Atom))/sizeof(long));
  1033. XtFree ((char *) pWsList);
  1034. } /* END OF FUNCTION SetWorkspaceListProperty */
  1035. /*************************************<->*************************************
  1036. *
  1037. * SetCurrentWorkspaceProperty (pSD)
  1038. *
  1039. *
  1040. * Description:
  1041. * -----------
  1042. * This function sets up the _DT_WORKSPACE_CURRENT property
  1043. *
  1044. *
  1045. * Inputs:
  1046. * ------
  1047. * pSD = ptr to screen data
  1048. *
  1049. *
  1050. *************************************<->***********************************/
  1051. void
  1052. SetCurrentWorkspaceProperty (WmScreenData *pSD)
  1053. {
  1054. Atom aCurrent;
  1055. aCurrent = pSD->pActiveWS->id;
  1056. XChangeProperty (DISPLAY, pSD->wmWorkspaceWin,
  1057. wmGD.xa_DT_WORKSPACE_CURRENT,
  1058. XA_ATOM,
  1059. 32, PropModeReplace, (unsigned char *)&aCurrent,
  1060. (sizeof(Atom))/sizeof(long));
  1061. XSync (DISPLAY, False); /* XFlush didn't work here, why? */
  1062. } /* END OF FUNCTION SetCurrentWorkspaceProperty */
  1063. /*************************************<->*************************************
  1064. *
  1065. * SetWorkspaceInfoProperty (pWS)
  1066. *
  1067. *
  1068. * Description:
  1069. * -----------
  1070. * This function sets up the _DT_WORKSPACE_INFO_<name> property
  1071. * for a particular workspace
  1072. *
  1073. *
  1074. * Inputs:
  1075. * ------
  1076. * pWS = ptr to workspace data
  1077. *
  1078. *
  1079. *************************************<->***********************************/
  1080. void
  1081. SetWorkspaceInfoProperty (WmWorkspaceData *pWS)
  1082. {
  1083. char *pch;
  1084. Atom aProperty;
  1085. String sTitle;
  1086. char **ppchList;
  1087. int iNumStrings;
  1088. int count;
  1089. int i, ix;
  1090. Status status;
  1091. XTextProperty tp;
  1092. #define WIP_NUMBER_SIZE 16
  1093. /*
  1094. * Construct our property name
  1095. */
  1096. pch = WorkspacePropertyName (pWS);
  1097. aProperty = XmInternAtom (DISPLAY, pch, FALSE);
  1098. XtFree ((char *) pch);
  1099. /*
  1100. * Determine the number of strings in our vector. One for each of
  1101. *
  1102. * workspace title
  1103. * pixel set id
  1104. * backdrop background
  1105. * backdrop foreground
  1106. * backdrop name
  1107. * number of backdrop windows
  1108. * list of backdrop windows
  1109. */
  1110. iNumStrings = 6; /* number of fields minus backdrop window(s) */
  1111. count = 1; /* number of backdrop windows */
  1112. iNumStrings += count;
  1113. /* allocate string vector */
  1114. ppchList = (char **) XtMalloc (iNumStrings * sizeof (char *));
  1115. pch = (char *) XtMalloc (iNumStrings * WIP_NUMBER_SIZE * sizeof(char));
  1116. i = 0;
  1117. /* Convert workspace title to ascii */
  1118. sTitle = (String) WmXmStringToString (pWS->title);
  1119. ppchList[i++] = (char *) sTitle;
  1120. /* Pixel set id */
  1121. ix = (i * WIP_NUMBER_SIZE);
  1122. sprintf (&pch[ix], "%d", pWS->backdrop.colorSet);
  1123. ppchList[i++] = &pch[ix];
  1124. /* backdrop background */
  1125. ix = (i * WIP_NUMBER_SIZE);
  1126. sprintf (&pch[ix], "0x%lx", pWS->backdrop.background);
  1127. ppchList[i++] = &pch[ix];
  1128. /* backdrop foreground */
  1129. ix = (i * WIP_NUMBER_SIZE);
  1130. sprintf (&pch[ix], "0x%lx", pWS->backdrop.foreground);
  1131. ppchList[i++] = &pch[ix];
  1132. /* backdrop name */
  1133. ix = (i * WIP_NUMBER_SIZE);
  1134. sprintf (&pch[ix], "0x%lx", pWS->backdrop.nameAtom);
  1135. ppchList[i++] = &pch[ix];
  1136. /* number of backdrop windows */
  1137. ix = (i * WIP_NUMBER_SIZE);
  1138. if (pWS->backdrop.window == None)
  1139. {
  1140. strcpy (&pch[ix], "0");
  1141. }
  1142. else
  1143. {
  1144. sprintf (&pch[ix], "%d", count);
  1145. }
  1146. ppchList[i++] = &pch[ix];
  1147. /* backdrop windows */
  1148. /*
  1149. * One or zero backdrop windows
  1150. * (NULL written if zero)
  1151. */
  1152. ix = (i * WIP_NUMBER_SIZE);
  1153. sprintf (&pch[ix], "0x%lx", pWS->backdrop.window);
  1154. ppchList[i++] = &pch[ix];
  1155. /*
  1156. * Write out the property
  1157. */
  1158. status = XmbTextListToTextProperty (DISPLAY, ppchList, iNumStrings,
  1159. XStdICCTextStyle, &tp);
  1160. if ((status == Success) || (status > 0))
  1161. {
  1162. /*
  1163. * Complete or partial conversion
  1164. */
  1165. XSetTextProperty (DISPLAY, pWS->pSD->wmWorkspaceWin, &tp, aProperty);
  1166. XFree (tp.value);
  1167. }
  1168. XtFree ((char *) ppchList);
  1169. XtFree (pch);
  1170. if (sTitle) XtFree ((char *)sTitle);
  1171. } /* END OF FUNCTION SetWorkspaceInfoProperty */
  1172. /*************************************<->*************************************
  1173. *
  1174. * DeleteWorkspaceInfoProperty (pWS)
  1175. *
  1176. *
  1177. * Description:
  1178. * -----------
  1179. * This function deletes a _DT_WORKSPACE_INFO_<name> property
  1180. * for a particular workspace
  1181. *
  1182. *
  1183. * Inputs:
  1184. * ------
  1185. * pWS = ptr to workspace data
  1186. *
  1187. *
  1188. *************************************<->***********************************/
  1189. void
  1190. DeleteWorkspaceInfoProperty (WmWorkspaceData *pWS)
  1191. {
  1192. char *pch;
  1193. Atom aProperty;
  1194. /*
  1195. * Get the atom for the workspace property.
  1196. */
  1197. pch = WorkspacePropertyName (pWS);
  1198. aProperty = XmInternAtom (DISPLAY, pch, FALSE);
  1199. XtFree ((char *) pch);
  1200. /*
  1201. * Do the property deletion
  1202. */
  1203. XDeleteProperty (DISPLAY, pWS->pSD->wmWorkspaceWin, aProperty);
  1204. XFlush (DISPLAY);
  1205. } /* END OF FUNCTION DeleteWorkspaceInfoProperty */
  1206. /*************************************<->*************************************
  1207. *
  1208. * WorkspacePropertyName (pWS)
  1209. *
  1210. *
  1211. * Description:
  1212. * -----------
  1213. * This function returns a string containing the property name for a
  1214. * workspace.
  1215. *
  1216. *
  1217. * Inputs:
  1218. * ------
  1219. * pWS = ptr to workspace data
  1220. *
  1221. * Returns
  1222. * -------
  1223. * string containing the workspace property name (Free with XtFree)
  1224. *
  1225. *
  1226. *************************************<->***********************************/
  1227. char *
  1228. WorkspacePropertyName (WmWorkspaceData *pWS)
  1229. {
  1230. char *pch;
  1231. char *pchName;
  1232. int len;
  1233. /*
  1234. * Construct our property name
  1235. */
  1236. pchName = pWS->name;
  1237. len = strlen(pchName) + strlen (_XA_DT_WORKSPACE_INFO) + 4;
  1238. pch = (char *) XtMalloc (len);
  1239. strcpy (pch, _XA_DT_WORKSPACE_INFO);
  1240. strcat (pch, "_");
  1241. strcat (pch, pchName);
  1242. return (pch);
  1243. } /* END OF FUNCTION WorkspacePropertyName */
  1244. /*************************************<->*************************************
  1245. *
  1246. * SetWorkspacePresence (propWindow, pWsPresence, cPresence)
  1247. *
  1248. *
  1249. * Description:
  1250. * -----------
  1251. * This function sets up the _DT_WORKSPACE_PRESENCE property
  1252. *
  1253. *
  1254. * Inputs:
  1255. * ------
  1256. * propWindow = window on which the _DT_WORKSPACE_PRESENCE property
  1257. * is to be set
  1258. * pWsPresence = pointer to workspace presence data
  1259. * cPresence = size of workspace presence data
  1260. *
  1261. *
  1262. *************************************<->***********************************/
  1263. void SetWorkspacePresence (Window propWindow, Atom *pWsPresence, unsigned long cPresence)
  1264. {
  1265. XChangeProperty (DISPLAY, propWindow, wmGD.xa_DT_WORKSPACE_PRESENCE,
  1266. wmGD.xa_DT_WORKSPACE_PRESENCE, 32, PropModeReplace,
  1267. (unsigned char *)pWsPresence, cPresence);
  1268. XFlush (DISPLAY);
  1269. } /* END OF FUNCTION SetWorkspacePresence */
  1270. /*************************************<->*************************************
  1271. *
  1272. * GetDtSessionHints (pSD, sNum)
  1273. *
  1274. *
  1275. * Description:
  1276. * -----------
  1277. * This function reads and processes _DT_SESSION_HINTS property that is
  1278. * associated with the root window of each screen managed by dtwm
  1279. *
  1280. *
  1281. * Inputs:
  1282. * ------
  1283. *
  1284. *
  1285. * Outputs:
  1286. * -------
  1287. *
  1288. *************************************<->***********************************/
  1289. void GetDtSessionHints (WmScreenData *pSD, int sNum)
  1290. {
  1291. int rValue;
  1292. char *property = NULL;
  1293. Atom actualType;
  1294. int actualFormat;
  1295. unsigned long leftover;
  1296. unsigned long nitems;
  1297. /*
  1298. * Read the property.
  1299. */
  1300. rValue = XGetWindowProperty (DISPLAY, pSD->rootWindow,
  1301. wmGD.xa_DT_SESSION_HINTS, 0L,
  1302. (long)1000000, False, AnyPropertyType,
  1303. &actualType, &actualFormat, &nitems,
  1304. &leftover, (unsigned char **)&property);
  1305. if ((rValue != Success) || (actualType == None) || (actualFormat != 8))
  1306. /* _DT_SESSION_HINTS does not exist or it is an invalid type. */
  1307. {
  1308. pSD->pDtSessionItems = NULL;
  1309. }
  1310. else
  1311. /* parse the property string */
  1312. {
  1313. ParseDtSessionHints (pSD, (unsigned char *)property);
  1314. }
  1315. if (property)
  1316. {
  1317. XFree ((char *)property);
  1318. }
  1319. /*
  1320. * Delete the property so we don't see it if the user
  1321. * restarts dtwm.
  1322. */
  1323. #ifndef DEBUG_SESSION_HINTS
  1324. XDeleteProperty (DISPLAY, pSD->rootWindow, wmGD.xa_DT_SESSION_HINTS);
  1325. #endif /* DEBUG_SESSION_HINTS */
  1326. } /* END OF FUNCTION GetDtSessionHints */
  1327. /*************************************<->*************************************
  1328. *
  1329. * GetDtWmRequest (pSD, pszReq, pmore)
  1330. *
  1331. *
  1332. * Description:
  1333. * -----------
  1334. * This function returns the next request
  1335. *
  1336. *
  1337. * Inputs:
  1338. * ------
  1339. * pSD - pointer to screen data
  1340. * psdReq - pointer to a char pointer
  1341. *
  1342. *
  1343. * Outputs:
  1344. * -------
  1345. * *pszReq - pointer to null terminated string containing next
  1346. * request
  1347. * *pmore - set to true if more data is left in the property
  1348. *
  1349. * Comments:
  1350. * ---------
  1351. * The data for pszReq is allocated in here. The caller must free up
  1352. * this space using XtFree.
  1353. *
  1354. *
  1355. *************************************<->***********************************/
  1356. void
  1357. GetDtWmRequest (
  1358. WmScreenData *pSD,
  1359. char **pszReq,
  1360. Boolean *pmore)
  1361. {
  1362. int rValue;
  1363. char *chRequest = NULL;
  1364. static char *property = NULL;
  1365. static int iNext = -1;
  1366. int i;
  1367. Atom actualType;
  1368. int actualFormat;
  1369. unsigned long leftover;
  1370. static unsigned long nitems = 0;
  1371. /*
  1372. * We need to read the property again if we have no data left
  1373. * over from last time;
  1374. */
  1375. if (property == NULL)
  1376. {
  1377. /*
  1378. * Read the property and delete it.
  1379. */
  1380. rValue = XGetWindowProperty (DISPLAY, pSD->wmWorkspaceWin,
  1381. wmGD.xa_DT_WM_REQUEST, 0L,
  1382. (long)1000000, True, AnyPropertyType,
  1383. &actualType, &actualFormat, &nitems,
  1384. &leftover, (unsigned char **)&property);
  1385. /*
  1386. * Validate the property that we've read
  1387. */
  1388. if ((rValue != Success) ||
  1389. (actualType == None) ||
  1390. (actualFormat != 8))
  1391. {
  1392. /* The property does not exist or it is an invalid type. */
  1393. property = NULL;
  1394. iNext = -1;
  1395. nitems = 0;
  1396. }
  1397. else
  1398. {
  1399. /* the property is fine, set the index of the next char. */
  1400. iNext = 0;
  1401. }
  1402. }
  1403. /*
  1404. * If we've got something, then extract and return the next
  1405. * request.
  1406. */
  1407. if (property && iNext >= 0)
  1408. {
  1409. int len = 0;
  1410. for (i=iNext; i<nitems; i++)
  1411. {
  1412. if (property [i] == '\0')
  1413. {
  1414. break;
  1415. }
  1416. }
  1417. if (i>=nitems) i=nitems;
  1418. len = i - iNext + 1 + ((property[i] == '\0') ? 0 : 1);
  1419. chRequest = (char *) XtMalloc (len);
  1420. if (chRequest == NULL)
  1421. {
  1422. Warning (((char *)GETMESSAGE(54, 2, "Insufficient memory for window management data")));
  1423. }
  1424. else
  1425. {
  1426. /* dequeue the request */
  1427. strncpy (chRequest, &property[iNext], len);
  1428. if (property[i] != '\0')
  1429. {
  1430. chRequest[len-1]='\0';
  1431. }
  1432. iNext = i+1;
  1433. }
  1434. if (iNext >= nitems)
  1435. {
  1436. /*
  1437. * Extracted the last request, free up the storage
  1438. * and reset for next time.
  1439. */
  1440. XFree ((char *)property);
  1441. iNext = -1;
  1442. property = NULL;
  1443. }
  1444. }
  1445. *pmore = (property != NULL);
  1446. *pszReq = chRequest;
  1447. } /* END OF FUNCTION GetDtWmRequest */
  1448. /*************************************<->*************************************
  1449. *
  1450. * GetIntialPropertyList (ClientData *)
  1451. *
  1452. *
  1453. * Description:
  1454. * -----------
  1455. * Get the list of initial properties on the window
  1456. *
  1457. *
  1458. * Inputs:
  1459. * ------
  1460. * pCD - pointer to client data
  1461. *
  1462. *
  1463. * Outputs:
  1464. * -------
  1465. * pCD - paInitialProperties member is updated
  1466. *
  1467. *
  1468. * Comments:
  1469. * --------
  1470. * The caller must XFree the paIntialialProperties member!
  1471. *
  1472. *************************************<->***********************************/
  1473. void
  1474. GetInitialPropertyList (ClientData *pCD)
  1475. {
  1476. Atom *paList;
  1477. int iProps;
  1478. paList = XListProperties (DISPLAY, pCD->client, &iProps);
  1479. if (paList)
  1480. {
  1481. pCD->paInitialProperties = paList;
  1482. pCD->numInitialProperties = iProps;
  1483. }
  1484. else
  1485. {
  1486. pCD->paInitialProperties = NULL;
  1487. pCD->numInitialProperties = 0;
  1488. }
  1489. } /* END OF FUNCTION GetInitialPropertyList */
  1490. /*************************************<->*************************************
  1491. *
  1492. * DiscardIntialPropertyList (ClientData *)
  1493. *
  1494. *
  1495. * Description:
  1496. * -----------
  1497. * Tosses out the intial property list for a client, frees data
  1498. *
  1499. *
  1500. * Inputs:
  1501. * ------
  1502. * pCD - pointer to client data
  1503. *
  1504. *
  1505. * Outputs:
  1506. * -------
  1507. * pCD - paInitialProperties member is updated
  1508. *
  1509. *
  1510. * Comments:
  1511. * --------
  1512. *
  1513. *
  1514. *************************************<->***********************************/
  1515. void
  1516. DiscardInitialPropertyList (ClientData *pCD)
  1517. {
  1518. if (pCD->paInitialProperties)
  1519. {
  1520. /*
  1521. * Free the initial property list.
  1522. * (see HasProperty() function)
  1523. */
  1524. XFree ((char *) pCD->paInitialProperties);
  1525. pCD->paInitialProperties = NULL;
  1526. pCD->numInitialProperties = 0;
  1527. }
  1528. } /* END OF FUNCTION DiscardInitialPropertyList */
  1529. /*************************************<->*************************************
  1530. *
  1531. * HasProperty (pCD, aProperty)
  1532. *
  1533. *
  1534. * Description:
  1535. * -----------
  1536. * Returns True if this client had this property when it was mapped
  1537. *
  1538. *
  1539. * Inputs:
  1540. * ------
  1541. * pCD - pointer to client data
  1542. * aProperty - atom of property to test for
  1543. *
  1544. *
  1545. * Outputs:
  1546. * -------
  1547. * Return - True if this property was on the initial list for this
  1548. * client; False otherwise.
  1549. *
  1550. *
  1551. * Comments:
  1552. * --------
  1553. *
  1554. *************************************<->***********************************/
  1555. Boolean
  1556. HasProperty (
  1557. ClientData * pCD,
  1558. Atom aProperty)
  1559. {
  1560. Boolean bFound = False;
  1561. Atom * paList;
  1562. int count;
  1563. paList = pCD->paInitialProperties;
  1564. if (paList)
  1565. {
  1566. count = pCD->numInitialProperties;
  1567. while ((!bFound) && (count > 0))
  1568. {
  1569. bFound = (*paList == aProperty);
  1570. count--;
  1571. paList++;
  1572. }
  1573. }
  1574. else
  1575. {
  1576. /*
  1577. * The property list doesn't exist. Return
  1578. * True to force a read of this property. The most likely
  1579. * case is that this property was updated after the
  1580. * window was managed and needs to be read.
  1581. */
  1582. bFound = True;
  1583. }
  1584. return (bFound);
  1585. } /* END OF FUNCTION HasProperty */