WmWinList.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780
  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, 1994 Hewlett-Packard Company
  32. * (c) Copyright 1993, 1994 International Business Machines Corp.
  33. * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  34. * (c) Copyright 1993, 1994 Novell, Inc.
  35. */
  36. /*
  37. * Included Files:
  38. */
  39. #include "WmGlobal.h"
  40. /*
  41. * include extern functions
  42. */
  43. #include "WmWinList.h"
  44. #include "WmCEvent.h"
  45. #include "WmEvent.h"
  46. #include "WmFunction.h"
  47. #include "WmKeyFocus.h"
  48. #include "WmMenu.h"
  49. #include "WmResource.h"
  50. #include "WmWinInfo.h"
  51. #include "WmWrkspace.h"
  52. #include <X11/bitmaps/xm_noenter16>
  53. #include <X11/bitmaps/xm_noenter16m>
  54. #include <X11/bitmaps/xm_noenter32>
  55. #include <X11/bitmaps/xm_noenter32m>
  56. /*
  57. * Global Variables:
  58. */
  59. /*************************************<->*************************************
  60. *
  61. * AddClientToList (pWS, pCD, onTop)
  62. *
  63. *
  64. * Description:
  65. * -----------
  66. * This function adds a client window to the client window list. If it is
  67. * a transient window then it is added to the transient window tree that
  68. * contains its transient leader. The window stacking order is also
  69. * maintained for the cases where there is a system modal window active
  70. * or the window is a transient window. If a system modal window is being
  71. * added then the system modal "input screen" window is setup.
  72. *
  73. *
  74. * Inputs:
  75. * ------
  76. * pCD = pointer to client data for the window to be added to the list
  77. *
  78. * pWS = pointer to workspace data
  79. *
  80. * onTop = if True then the window is displayed on top of the window
  81. * stack and is added to the beginning of the window list, otherwise
  82. * it is added to the end of the window list.
  83. *
  84. *
  85. * Outputs:
  86. * -------
  87. * pWS = (clientList, lastClient)
  88. *
  89. *************************************<->***********************************/
  90. void AddClientToList (WmWorkspaceData *pWS, ClientData *pCD, Boolean onTop)
  91. {
  92. Boolean belowSystemModal = False;
  93. XWindowChanges windowChanges;
  94. WmScreenData *pSD = pWS->pSD;
  95. WsClientData *pWsc = GetWsClientData (pWS, pCD);
  96. if (pCD->inputMode == MWM_INPUT_SYSTEM_MODAL)
  97. {
  98. /*
  99. * Set up the system modal input screen window just below the
  100. * system modal window.
  101. */
  102. SetupSystemModalState (pCD);
  103. if (!wmGD.systemModalActive || (wmGD.systemModalClient != pCD))
  104. {
  105. /*
  106. * If we failed to setup as system modal, then
  107. * back off to MWM_INPUT_FULL_APPLICATION_MODAL.
  108. * This will do *something* if this is a transient
  109. * window.
  110. */
  111. pCD->inputMode = MWM_INPUT_FULL_APPLICATION_MODAL;
  112. }
  113. }
  114. else if (wmGD.systemModalActive &&
  115. ((FindTransientTreeLeader (pCD))->inputMode !=
  116. MWM_INPUT_SYSTEM_MODAL))
  117. {
  118. /*
  119. * If a system modal window is active then place the window below
  120. * the system modal input screen window if the window is not a
  121. * descendant of the system modal window.
  122. */
  123. windowChanges.sibling = pSD->inputScreenWindow;
  124. windowChanges.stack_mode = Below;
  125. XConfigureWindow (DISPLAY, pCD->clientFrameWin,
  126. CWSibling | CWStackMode, &windowChanges);
  127. belowSystemModal = True;
  128. }
  129. if (pCD->transientLeader)
  130. {
  131. AddTransient (pWS, pCD);
  132. }
  133. else
  134. {
  135. pCD->clientEntry.type = NORMAL_STATE;
  136. pCD->clientEntry.pCD = pCD;
  137. if (belowSystemModal && wmGD.systemModalClient)
  138. {
  139. AddEntryToList (pWS, &pCD->clientEntry, False /*below*/,
  140. pSD->clientList);
  141. }
  142. else if (onTop)
  143. {
  144. AddEntryToList (pWS, &pCD->clientEntry, True /*on top*/, NULL);
  145. }
  146. else
  147. {
  148. AddEntryToList (pWS, &pCD->clientEntry, False /*on bottom*/, NULL);
  149. }
  150. if (!pWsc->pIconBox && pWsc->iconFrameWin)
  151. {
  152. /*
  153. * Put the icon on the bottom of the stack.
  154. */
  155. if (pSD->lastClient->type == MINIMIZED_STATE)
  156. {
  157. WsClientData *pWsib;
  158. pWsib = &pSD->lastClient->pCD->pWsList[0];
  159. windowChanges.sibling = pWsib->iconFrameWin;
  160. }
  161. else
  162. {
  163. windowChanges.sibling = pSD->lastClient->pCD->clientFrameWin;
  164. }
  165. windowChanges.stack_mode = Below;
  166. XConfigureWindow (DISPLAY, pWsc->iconFrameWin,
  167. CWSibling | CWStackMode, &windowChanges);
  168. pCD->iconEntry.type = MINIMIZED_STATE;
  169. pCD->iconEntry.pCD = pCD;
  170. pCD->iconEntry.nextSibling = NULL;
  171. pCD->iconEntry.prevSibling = pSD->lastClient;
  172. pSD->lastClient->nextSibling = &pCD->iconEntry;
  173. pSD->lastClient = &pCD->iconEntry;
  174. }
  175. }
  176. } /* END OF FUNCTION AddClientToList */
  177. /*************************************<->*************************************
  178. *
  179. * AddEntryToList (pWS, pEntry, onTop, pStackEntry)
  180. *
  181. *
  182. * Description:
  183. * -----------
  184. * This function adds a client list entry to the client window list.
  185. * This is usually done as part of the process of changing the ordering
  186. * of the window list.
  187. *
  188. *
  189. * Inputs:
  190. * ------
  191. * pWS = pointer to workspace data
  192. * pEntry = pointer to a client list entry to be added to the client list
  193. *
  194. * onTop = if True then the client list entry is added on top of the
  195. * specified client list stack entry (if the stack entry is not
  196. * specified then the entry is added to the front of the list);
  197. * otherwise the entry is added after the specified stacking entry
  198. * (or to the end of the list if the stacking entry is not specified).
  199. *
  200. * pStackEntry = pointer to a client list entry to be used as a reference
  201. * in adding an entry to the client list.
  202. *
  203. * Outputs:
  204. * -------
  205. * pWS = (clientList, lastClient)
  206. *
  207. *************************************<->***********************************/
  208. void AddEntryToList (WmWorkspaceData *pWS, ClientListEntry *pEntry, Boolean onTop, ClientListEntry *pStackEntry)
  209. {
  210. WmScreenData *pSD = pWS->pSD;
  211. if (onTop)
  212. {
  213. if (pStackEntry)
  214. {
  215. if (pEntry != pStackEntry)
  216. {
  217. pEntry->nextSibling = pStackEntry;
  218. pEntry->prevSibling = pStackEntry->prevSibling;
  219. pStackEntry->prevSibling = pEntry;
  220. if (pEntry->prevSibling)
  221. {
  222. pEntry->prevSibling->nextSibling = pEntry;
  223. }
  224. else
  225. {
  226. pSD->clientList = pEntry;
  227. }
  228. }
  229. }
  230. else
  231. {
  232. if (pSD->clientList != pEntry)
  233. {
  234. pEntry->nextSibling = pSD->clientList;
  235. pEntry->prevSibling = NULL;
  236. if (pSD->clientList)
  237. {
  238. pSD->clientList->prevSibling = pEntry;
  239. }
  240. else
  241. {
  242. pSD->lastClient = pEntry;
  243. }
  244. pSD->clientList = pEntry;
  245. }
  246. }
  247. }
  248. else
  249. {
  250. if (pStackEntry)
  251. {
  252. if (pEntry != pStackEntry)
  253. {
  254. pEntry->nextSibling = pStackEntry->nextSibling;
  255. pEntry->prevSibling = pStackEntry;
  256. pStackEntry->nextSibling = pEntry;
  257. if (pEntry->nextSibling)
  258. {
  259. pEntry->nextSibling->prevSibling = pEntry;
  260. }
  261. else
  262. {
  263. pSD->lastClient = pEntry;
  264. }
  265. }
  266. }
  267. else
  268. {
  269. if (pSD->lastClient != pEntry)
  270. {
  271. pEntry->nextSibling = NULL;
  272. pEntry->prevSibling = pSD->lastClient;
  273. if (pSD->clientList)
  274. {
  275. pSD->lastClient->nextSibling = pEntry;
  276. }
  277. else
  278. {
  279. pSD->clientList = pEntry;
  280. }
  281. pSD->lastClient = pEntry;
  282. }
  283. }
  284. }
  285. } /* END OF FUNCTION AddEntryToList */
  286. /*************************************<->*************************************
  287. *
  288. * MoveEntryInList (pWS, pEntry, onTop, pStackEntry)
  289. *
  290. *
  291. * Description:
  292. * -----------
  293. * This function moves a client list entry in the client window list.
  294. *
  295. *
  296. * Inputs:
  297. * ------
  298. * pWS = pointer to workspace data
  299. *
  300. * pEntry = pointer to a client list entry to be moved in the client list
  301. *
  302. * onTop = if True then the client list entry is moved on top of the
  303. * specified client list stack entry (if the stack entry is not
  304. * specified then the entry is moved to the front of the list);
  305. * otherwise the entry is moved after the specified stacking entry
  306. * (or to the end of the list if the stacking entry is not specified).
  307. *
  308. * pStackEntry = pointer to a client list entry to be used as a reference
  309. * in moving an entry in the client list.
  310. *
  311. * Outputs:
  312. * -------
  313. * pWS = (clientList, lastClient)
  314. *
  315. *************************************<->***********************************/
  316. void MoveEntryInList (WmWorkspaceData *pWS, ClientListEntry *pEntry, Boolean onTop, ClientListEntry *pStackEntry)
  317. {
  318. DeleteEntryFromList (pWS, pEntry);
  319. AddEntryToList (pWS, pEntry, onTop, pStackEntry);
  320. } /* END OF FUNCTION MoveEntryInList */
  321. /*************************************<->*************************************
  322. *
  323. * DeleteEntryFromList (pWS, pListEntry)
  324. *
  325. *
  326. * Description:
  327. * -----------
  328. * This function deletes a client list entry from the client window list.
  329. * This is usually done as part of the process of changing the ordering
  330. * of the window list.
  331. *
  332. *
  333. * Inputs:
  334. * ------
  335. * pWS = pointer to workspace data
  336. * listEntry = pointer to a client list entry
  337. *
  338. * Outputs:
  339. * -------
  340. * pWS = (clientList, lastClient)
  341. *
  342. *************************************<->***********************************/
  343. void DeleteEntryFromList (WmWorkspaceData *pWS, ClientListEntry *pListEntry)
  344. {
  345. if (pListEntry->prevSibling)
  346. {
  347. pListEntry->prevSibling->nextSibling = pListEntry->nextSibling;
  348. }
  349. else
  350. {
  351. pWS->pSD->clientList = pListEntry->nextSibling;
  352. }
  353. if (pListEntry->nextSibling)
  354. {
  355. pListEntry->nextSibling->prevSibling = pListEntry->prevSibling;
  356. }
  357. else
  358. {
  359. pWS->pSD->lastClient = pListEntry->prevSibling;
  360. }
  361. } /* END OF FUNCTION DeleteEntryFromList */
  362. /*************************************<->*************************************
  363. *
  364. * DeleteClientFromList (pWS, pCD)
  365. *
  366. *
  367. * Description:
  368. * -----------
  369. * This function deletes a client from the client window list. If this is
  370. * a transient window then it is deleted from its transient window tree.
  371. * If this is a system modal window then clean up the system modal state.
  372. *
  373. *
  374. * Inputs:
  375. * ------
  376. * pCD = pointer to client data for the window to be added to the list
  377. *
  378. * Outputs:
  379. * -------
  380. * pWS = (clientList, lastClient)
  381. *
  382. *************************************<->***********************************/
  383. void DeleteClientFromList (WmWorkspaceData *pWS, ClientData *pCD)
  384. {
  385. WsClientData *pWsc = GetWsClientData (pWS, pCD);
  386. WmScreenData *pSD = pWS->pSD;
  387. if (pCD->transientLeader)
  388. {
  389. DeleteTransient (pCD);
  390. }
  391. else
  392. {
  393. /*
  394. * If this is a system modal window then clean up the system modal
  395. * state.
  396. */
  397. if (pCD->inputMode == MWM_INPUT_SYSTEM_MODAL)
  398. {
  399. UndoSystemModalState ();
  400. }
  401. /*
  402. * Remove the client and icon entries from the window list.
  403. */
  404. if (!pWsc->pIconBox && pWsc->iconFrameWin)
  405. {
  406. if (pCD->iconEntry.prevSibling)
  407. {
  408. pCD->iconEntry.prevSibling->nextSibling =
  409. pCD->iconEntry.nextSibling;
  410. }
  411. else
  412. {
  413. pSD->clientList = pCD->iconEntry.nextSibling;
  414. }
  415. if (pCD->iconEntry.nextSibling)
  416. {
  417. pCD->iconEntry.nextSibling->prevSibling =
  418. pCD->iconEntry.prevSibling;
  419. }
  420. else
  421. {
  422. pSD->lastClient = pCD->iconEntry.prevSibling;
  423. }
  424. }
  425. if (pCD->clientEntry.prevSibling)
  426. {
  427. pCD->clientEntry.prevSibling->nextSibling =
  428. pCD->clientEntry.nextSibling;
  429. }
  430. else
  431. {
  432. pSD->clientList = pCD->clientEntry.nextSibling;
  433. }
  434. if (pCD->clientEntry.nextSibling)
  435. {
  436. pCD->clientEntry.nextSibling->prevSibling =
  437. pCD->clientEntry.prevSibling;
  438. }
  439. else
  440. {
  441. pSD->lastClient = pCD->clientEntry.prevSibling;
  442. }
  443. }
  444. } /* END OF FUNCTION DeleteClientFromList */
  445. /*************************************<->*************************************
  446. *
  447. * AddTransient (pWS, pCD)
  448. *
  449. *
  450. * Description:
  451. * -----------
  452. * This function adds the transient window to the lead window's list of
  453. * transients.
  454. *
  455. *
  456. * Inputs:
  457. * ------
  458. * pWS = pointer to workspace data
  459. * pCD = pointer to client data of a transient window
  460. *
  461. *
  462. * Outputs:
  463. * -------
  464. * pCD->transientLeader = (transientChildren, modalCount)
  465. *
  466. *************************************<->***********************************/
  467. void AddTransient (WmWorkspaceData *pWS, ClientData *pCD)
  468. {
  469. ClientData *pcdLeader = pCD->transientLeader;
  470. ClientData *pcdTop = FindTransientTreeLeader (pCD);
  471. Boolean restackTransients;
  472. WmScreenData *pSD = pWS->pSD;
  473. pCD->transientSiblings = pcdLeader->transientChildren;
  474. pcdLeader->transientChildren = pCD;
  475. /*
  476. * Insure that the new transient window is on top of its siblings
  477. * and that the transient window tree is on top of the window
  478. * stack (this is the standard behavior for newly mapped and
  479. * managed windows). If there is a system modal window that the
  480. * transient window is not associated with then don't raise the
  481. * transient tree.
  482. */
  483. restackTransients = PutTransientOnTop (pCD);
  484. /*
  485. * Handle application modal transient windows
  486. */
  487. if (pCD->inputMode == MWM_INPUT_PRIMARY_APPLICATION_MODAL)
  488. {
  489. /*
  490. * If this is a primary application modal window then increment
  491. * the modal count for transient leaders that are directly up
  492. * the transient tree.
  493. *
  494. * (This is the old MWM_INPUT_APPLICATION_MODAL behavior.)
  495. */
  496. while (pcdLeader)
  497. {
  498. MarkModalTransient (pcdLeader, pCD);
  499. pcdLeader = pcdLeader->transientLeader;
  500. }
  501. }
  502. else if (pCD->inputMode == MWM_INPUT_FULL_APPLICATION_MODAL)
  503. {
  504. /*
  505. * If this is a full application modal window then increment
  506. * the modal count for the rest of the transient tree.
  507. */
  508. MarkModalSubtree (pcdTop, pCD);
  509. }
  510. else if (pcdTop->fullModalCount)
  511. {
  512. /*
  513. * There is already a full application modal window in the tree
  514. */
  515. pcdLeader = pCD->transientLeader;
  516. if ((pcdLeader->inputMode != MWM_INPUT_FULL_APPLICATION_MODAL) ||
  517. (IS_APP_MODALIZED(pcdLeader)))
  518. {
  519. /*
  520. * The immediate parent of this transient is not the
  521. * current full application modal window. Set the full
  522. * modal count to the parent's so that they both become
  523. * unmodalized at the same time. This allows a full
  524. * app modal window to have active, non-modal transients.
  525. */
  526. pCD->fullModalCount = pcdLeader->fullModalCount;
  527. }
  528. }
  529. /*
  530. * Do the actual restacking in the X window stack if necessary.
  531. */
  532. if ((pSD->clientList != &pcdTop->clientEntry) && !wmGD.systemModalActive)
  533. {
  534. F_Raise (NULL, pCD, NULL);
  535. }
  536. else if (restackTransients)
  537. {
  538. RestackTransientsAtWindow (pCD);
  539. }
  540. else if (pCD != FindTransientOnTop (pcdTop))
  541. {
  542. StackTransientWindow (pCD);
  543. }
  544. } /* END OF FUNCTION AddTransient */
  545. /*************************************<->*************************************
  546. *
  547. * MarkModalSubtree (pcdTree, pcdAvoid)
  548. *
  549. *
  550. * Description:
  551. * -----------
  552. * This function marks the transient tree with pcdTree as its leader.
  553. * If pcdAvoid is in the tree, it is not marked.
  554. *
  555. * Inputs:
  556. * ------
  557. * pcdTree = pointer to client data of the tree to mark
  558. * pcdAvoid = pointer to client data to not mark if in tree
  559. *
  560. *
  561. *************************************<->***********************************/
  562. void MarkModalSubtree (ClientData *pcdTree, ClientData *pcdAvoid)
  563. {
  564. /* Mark children, if any */
  565. if (pcdTree->transientChildren)
  566. MarkModalSubtree (pcdTree->transientChildren, pcdAvoid);
  567. /* Mark this node */
  568. if (pcdTree != pcdAvoid)
  569. {
  570. MarkModalTransient (pcdTree, pcdAvoid);
  571. }
  572. /* Mark siblings */
  573. if (pcdTree->transientSiblings)
  574. MarkModalSubtree (pcdTree->transientSiblings, pcdAvoid);
  575. }
  576. /*************************************<->*************************************
  577. *
  578. * MarkModalTransient (pcdLeader, pCD)
  579. *
  580. *
  581. * Description:
  582. * -----------
  583. * This function marks a transient window for application modal processing.
  584. * Grabs are done to eat up pointer button events.
  585. *
  586. * Inputs:
  587. * ------
  588. * pcdLeader = pointer to client data to mark
  589. * pCD = pointer to client data of new transient
  590. *
  591. *
  592. *************************************<->***********************************/
  593. void MarkModalTransient (ClientData *pcdLeader, ClientData *pCD)
  594. {
  595. if (!IS_APP_MODALIZED(pcdLeader))
  596. {
  597. /*
  598. * Eat pointer button events while application modal.
  599. */
  600. XGrabButton (DISPLAY, AnyButton, AnyModifier,
  601. pcdLeader->clientBaseWin, True,
  602. ButtonPressMask | ButtonMotionMask, GrabModeAsync,
  603. GrabModeAsync, None, wmGD.workspaceCursor);
  604. }
  605. /* bump application modal count */
  606. if (pCD->inputMode == MWM_INPUT_FULL_APPLICATION_MODAL)
  607. pcdLeader->fullModalCount++;
  608. else
  609. pcdLeader->primaryModalCount++;
  610. }
  611. /*************************************<->*************************************
  612. *
  613. * DeleteTransient (pCD)
  614. *
  615. *
  616. * Description:
  617. * -----------
  618. * This function deletes the transient window from the lead window's list
  619. * of transients
  620. *
  621. * Much of the complication of this code arises from trying to handle
  622. * mixtures of both full- and primary-application modal transients.
  623. * It also tries to handle the case where a sequence of application
  624. * modal transients appear in different places in the transient tree
  625. * (i.e. not as descendents of a previously existing full app modal
  626. * transient).
  627. *
  628. * Inputs:
  629. * ------
  630. * pCD = pointer to client data of transient.
  631. *
  632. *************************************<->***********************************/
  633. void DeleteTransient (ClientData *pCD)
  634. {
  635. ClientData *pcdLeader;
  636. ClientData *pcdPrev;
  637. int modalCount;
  638. /*
  639. * Handle primary application modality.
  640. * Reset the modal window counts for the leader windows up through the
  641. * transient window tree.
  642. */
  643. modalCount = pCD->primaryModalCount;
  644. if (pCD->inputMode == MWM_INPUT_PRIMARY_APPLICATION_MODAL)
  645. {
  646. modalCount += 1;
  647. }
  648. if (modalCount)
  649. {
  650. pcdLeader = pCD->transientLeader;
  651. while (pcdLeader)
  652. {
  653. if (modalCount)
  654. UnMarkModalTransient (pcdLeader, modalCount, pCD);
  655. pcdLeader = pcdLeader->transientLeader;
  656. }
  657. }
  658. /*
  659. * Handle full application modality.
  660. * Undo application modal windows in a depth first manner.
  661. */
  662. pcdLeader = FindTransientTreeLeader (pCD);
  663. if (pCD->transientChildren)
  664. {
  665. DeleteFullAppModalChildren (pcdLeader, pCD->transientChildren);
  666. }
  667. if (pCD->inputMode == MWM_INPUT_FULL_APPLICATION_MODAL)
  668. {
  669. /*
  670. * If this is a full application modal window then decrement
  671. * the modal count for the rest of the transient tree.
  672. */
  673. FixupFullAppModalCounts (pcdLeader, pCD);
  674. }
  675. /*
  676. * Delete this transient from its parent's list of transient windows.
  677. */
  678. pcdPrev = pCD->transientLeader->transientChildren;
  679. if(pcdPrev)
  680. {
  681. if (pcdPrev == pCD)
  682. {
  683. pCD->transientLeader->transientChildren = pCD->transientSiblings;
  684. }
  685. else
  686. {
  687. while (pcdPrev && (pcdPrev->transientSiblings != pCD))
  688. {
  689. pcdPrev = pcdPrev->transientSiblings;
  690. }
  691. if (pcdPrev)
  692. pcdPrev->transientSiblings = pCD->transientSiblings;
  693. }
  694. }
  695. } /* END OF FUNCTION DeleteTransient */
  696. /*************************************<->*************************************
  697. *
  698. * DeleteFullAppModalChildren (pcdLeader, pCD)
  699. *
  700. *
  701. * Description:
  702. * -----------
  703. * This function handles the clean-up of nested full application modal
  704. * windows. The deletion has to be handled carefully to keep a correct
  705. * fullModalCount on the transients that remain in the tree.
  706. *
  707. * The algorithm is to traverse the transient children depth first and
  708. * fix up the tree's fullModalCount for each full application modal
  709. * window that's found.
  710. *
  711. * Inputs:
  712. * ------
  713. * pcdLeader = pointer to client data of transient tree root.
  714. * pCD = pointer to client data of transient subtree to delete.
  715. *
  716. *************************************<->***********************************/
  717. void DeleteFullAppModalChildren (ClientData *pcdLeader, ClientData *pCD)
  718. {
  719. /* recursively do children first */
  720. if (pCD->transientChildren)
  721. DeleteFullAppModalChildren (pcdLeader, pCD->transientChildren);
  722. /* do fullAppModal fixup for this guy */
  723. FixupFullAppModalCounts (pcdLeader, pCD);
  724. /* do siblings of passed transient */
  725. if (pCD->transientSiblings)
  726. DeleteFullAppModalChildren (pcdLeader, pCD->transientSiblings);
  727. } /* END OF FUNCTION DeleteFullAppModalChildren */
  728. /*************************************<->*************************************
  729. *
  730. * FixupFullAppModalCounts (pcdLeader, pcdDelete)
  731. *
  732. *
  733. * Description:
  734. * -----------
  735. * This function traverses the entire transient tree (pointed to by
  736. * pcdLeader) and fixes up the fullModalCounts to reflect the removal
  737. * of pcdDelete.
  738. *
  739. * The fix-up consists of decrementing the count
  740. * of the remaining full app modal windows in the tree iff the remaining
  741. * window's fullModalCount is greater than the fullModalCount of the
  742. * transient being deleted.
  743. *
  744. * Inputs:
  745. * ------
  746. * pcdLeader = pointer to client data for head of transient tree.
  747. * pcdDelet = pointer to client data of transient being deleted.
  748. *
  749. *************************************<->***********************************/
  750. void
  751. FixupFullAppModalCounts (ClientData *pcdLeader, ClientData *pcdDelete)
  752. {
  753. /* fixup children */
  754. if (pcdLeader->transientChildren)
  755. {
  756. FixupFullAppModalCounts (pcdLeader->transientChildren, pcdDelete);
  757. }
  758. /*
  759. * fixup leader: decrement the count if it is greater than
  760. * the transient being deleted.
  761. *
  762. */
  763. if (pcdLeader->fullModalCount > pcdDelete->fullModalCount)
  764. {
  765. UnMarkModalTransient (pcdLeader, 1, pcdDelete);
  766. }
  767. /* fixup siblings */
  768. if (pcdLeader->transientSiblings)
  769. {
  770. FixupFullAppModalCounts (pcdLeader->transientSiblings, pcdDelete);
  771. }
  772. } /* END OF FUNCTION FixupFullAppModalCounts */
  773. /*************************************<->*************************************
  774. *
  775. * UnMarkModalTransient (pcdModee, modalCount, pcdModal)
  776. *
  777. *
  778. * Description:
  779. * -----------
  780. * This function unmarks a transient window for application modal processing.
  781. * Original grabs are restored.
  782. *
  783. * Inputs:
  784. * ------
  785. * pcdModee = pointer to client data for transient to unmark
  786. * pcdModal = pointer to client data for modal transient
  787. * modalCount = amount to decrement the client's modal count by
  788. *
  789. *
  790. *************************************<->***********************************/
  791. void UnMarkModalTransient (ClientData *pcdModee, int modalCount, ClientData *pcdModal)
  792. {
  793. /* decrement application modal count */
  794. if (pcdModal->inputMode == MWM_INPUT_FULL_APPLICATION_MODAL)
  795. pcdModee->fullModalCount -= modalCount;
  796. else if (pcdModal->inputMode == MWM_INPUT_PRIMARY_APPLICATION_MODAL)
  797. pcdModee->primaryModalCount -= modalCount;
  798. /*
  799. * Restore original button bindings/grabs if not modal anymore
  800. */
  801. if (!IS_APP_MODALIZED(pcdModee))
  802. {
  803. XUngrabButton (DISPLAY, AnyButton, AnyModifier,
  804. pcdModee->clientBaseWin);
  805. SetupCButtonBindings (pcdModee->clientBaseWin, BUTTON_SPECS(pcdModee));
  806. if ((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT) &&
  807. (wmGD.keyboardFocus != pcdModee))
  808. {
  809. DoExplicitSelectGrab (pcdModee->clientBaseWin);
  810. }
  811. }
  812. }
  813. /*************************************<->*************************************
  814. *
  815. * PutTransientOnTop (pcd)
  816. *
  817. *
  818. * Description:
  819. * -----------
  820. * This function changes the transient window list to insure that the
  821. * specified transient window is on top of its siblings and its parent
  822. * is on top of its siblings, etc. The sibling list is ordered such
  823. * that the first window in the list is on top of second window in the
  824. * list, etc.
  825. *
  826. *
  827. * Inputs:
  828. * ------
  829. * pcd = pointer to client data of a transient window
  830. *
  831. *
  832. * Outputs:
  833. * -------
  834. * pcdLeader = (transientSiblings)
  835. *
  836. * RETURN = True if the transient tree needs to be restacked
  837. *
  838. *************************************<->***********************************/
  839. Boolean PutTransientOnTop (ClientData *pcd)
  840. {
  841. ClientData *pcdLeader;
  842. ClientData *pcdPrev;
  843. Boolean restack = False;
  844. pcdLeader = pcd->transientLeader;
  845. if (pcdLeader != NULL)
  846. {
  847. pcdPrev = pcdLeader->transientChildren;
  848. if (pcdPrev != pcd)
  849. {
  850. while (pcdPrev->transientSiblings != pcd)
  851. {
  852. pcdPrev = pcdPrev->transientSiblings;
  853. }
  854. pcdPrev->transientSiblings = pcd->transientSiblings;
  855. pcd->transientSiblings = pcdLeader->transientChildren;
  856. pcdLeader->transientChildren = pcd;
  857. restack = True;
  858. }
  859. if (PutTransientOnTop (pcdLeader))
  860. {
  861. restack = True;
  862. }
  863. if (BumpPrimaryToBottom (pcdLeader))
  864. {
  865. restack = True;
  866. }
  867. }
  868. return (restack);
  869. } /* END OF FUNCTION PutTransientOnTop */
  870. /*************************************<->*************************************
  871. *
  872. * PutTransientBelowSiblings (pcd)
  873. *
  874. *
  875. * Description:
  876. * -----------
  877. * This function changes the transient window list to insure that the
  878. * specified transient window is below its sibling windows.
  879. *
  880. *
  881. * Inputs:
  882. * ------
  883. * pcd = pointer to client data of a transient window
  884. *
  885. *
  886. * Outputs:
  887. * -------
  888. * pcdLeader = (transientSiblings)
  889. *
  890. * RETURN = True if restacking has been done in the transient window tree.
  891. *
  892. *************************************<->***********************************/
  893. Boolean PutTransientBelowSiblings (ClientData *pcd)
  894. {
  895. ClientData *pcdLeader;
  896. ClientData *pcdNext;
  897. Boolean restack = False;
  898. pcdLeader = pcd->transientLeader;
  899. if (pcdLeader)
  900. {
  901. if (pcd->transientSiblings || (pcdLeader->transientChildren != pcd))
  902. {
  903. restack = True;
  904. if (pcdLeader->transientChildren == pcd)
  905. {
  906. pcdLeader->transientChildren = pcd->transientSiblings;
  907. }
  908. pcdNext = pcdLeader->transientChildren;
  909. while (pcdNext->transientSiblings)
  910. {
  911. if (pcdNext->transientSiblings == pcd)
  912. {
  913. pcdNext->transientSiblings = pcd->transientSiblings;
  914. }
  915. else
  916. {
  917. pcdNext = pcdNext->transientSiblings;
  918. }
  919. }
  920. pcdNext->transientSiblings = pcd;
  921. }
  922. pcd->transientSiblings = NULL;
  923. }
  924. return (restack);
  925. } /* END OF FUNCTION PutTransientBelowSiblings */
  926. /*************************************<->*************************************
  927. *
  928. * RestackTransients (pcd)
  929. *
  930. *
  931. * Description:
  932. * -----------
  933. * This function restacks windows in a transient window tree. Secondary
  934. * (transient) windows are stacked on top of their associated primary
  935. * windows and the first secondary window in the transientSiblings list
  936. * is stacked on top of the second window in the list, etc.
  937. *
  938. *
  939. * Inputs:
  940. * ------
  941. * pcd = pointer to client data of a window in a transient tree
  942. *
  943. *************************************<->***********************************/
  944. void RestackTransients (ClientData *pcd)
  945. {
  946. ClientData *pcdLeader;
  947. int count;
  948. static int size = 0;
  949. static Window *windows = NULL;
  950. XWindowChanges windowChanges;
  951. int i;
  952. int leaderIndex;
  953. /*
  954. * Build a restacking list and do the restacking.
  955. */
  956. pcdLeader = FindTransientTreeLeader (pcd);
  957. count = CountTransientChildren (pcdLeader);
  958. /* No work to do if no transient children; count includes leader. */
  959. if (count < 2)
  960. return;
  961. if (count > size)
  962. {
  963. /*
  964. * Expand the (static) windows buffer that is used in restacking.
  965. */
  966. if (!(windows =
  967. (Window *)WmMalloc ((char*)windows, (count + 5) * sizeof (Window))))
  968. {
  969. /* cannot get memory space */
  970. size = 0;
  971. return;
  972. }
  973. size = count + 5;
  974. }
  975. MakeTransientFamilyStackingList (windows, pcdLeader);
  976. /*
  977. * Changes for CDExc19397.
  978. * XRestackWindows may move pcdLeader; that messes up the
  979. * global window stack. Call XConfigureWindow() instead,
  980. * and don't change location of pcdLeader.
  981. */
  982. for (leaderIndex = 0; leaderIndex < count; leaderIndex++)
  983. {
  984. if (windows[leaderIndex] == pcdLeader->clientFrameWin)
  985. break;
  986. }
  987. if (leaderIndex >= count) /* ? Couldn't find leader; should NOT happen. */
  988. leaderIndex = count - 1;
  989. windowChanges.stack_mode = Above;
  990. for (i = leaderIndex; i > 0; i--)
  991. {
  992. windowChanges.sibling = windows[i];
  993. XConfigureWindow (DISPLAY, windows[i - 1],
  994. CWSibling | CWStackMode, &windowChanges);
  995. }
  996. windowChanges.stack_mode = Below;
  997. for (i = leaderIndex; i < count - 1; i++)
  998. {
  999. windowChanges.sibling = windows[i];
  1000. XConfigureWindow (DISPLAY, windows[i + 1],
  1001. CWSibling | CWStackMode, &windowChanges);
  1002. }
  1003. } /* END OF FUNCTION RestackTransients */
  1004. /*************************************<->*************************************
  1005. *
  1006. * RestackTransientsAtWindow (pcd)
  1007. *
  1008. *
  1009. * Description:
  1010. * -----------
  1011. * This function restacks windows in a transient window tree. The
  1012. * "anchor point" in the stack for the transient window tree is the
  1013. * specified window.
  1014. *
  1015. *
  1016. * Inputs:
  1017. * ------
  1018. * pcd = pointer to client data of a window in a transient tree
  1019. *
  1020. *************************************<->***********************************/
  1021. void RestackTransientsAtWindow (ClientData *pcd)
  1022. {
  1023. ClientData *pcdLeader;
  1024. XWindowChanges windowChanges;
  1025. pcdLeader = FindTransientTreeLeader (pcd);
  1026. if (pcdLeader && (pcdLeader != pcd))
  1027. {
  1028. windowChanges.sibling = pcd->clientFrameWin;
  1029. windowChanges.stack_mode = Below;
  1030. XConfigureWindow (DISPLAY, pcdLeader->clientFrameWin,
  1031. CWSibling | CWStackMode, &windowChanges);
  1032. }
  1033. RestackTransients (pcd);
  1034. } /* END OF FUNCTION RestackTransientsAtWindow */
  1035. /*************************************<->*************************************
  1036. *
  1037. * FindTransientTreeLeader (pcd)
  1038. *
  1039. *
  1040. * Description:
  1041. * -----------
  1042. * This function identifies the leader of the transient tree that
  1043. * contains the specified client.
  1044. *
  1045. *
  1046. * Inputs:
  1047. * ------
  1048. * pcd = pointer to client data of a window in a transient tree.
  1049. *
  1050. * Outputs:
  1051. * -------
  1052. * RETURN = pointer to the client data for the transient tree leader.
  1053. *
  1054. *************************************<->***********************************/
  1055. ClientData * FindTransientTreeLeader (ClientData *pcd)
  1056. {
  1057. /*
  1058. * Find the head of the transient window tree.
  1059. */
  1060. while (pcd->transientLeader)
  1061. {
  1062. pcd = pcd->transientLeader;
  1063. }
  1064. return (pcd);
  1065. } /* END OF FUNCTION FindTransientTreeLeader */
  1066. /*************************************<->*************************************
  1067. *
  1068. * CountTransientChildren (pcd)
  1069. *
  1070. *
  1071. * Description:
  1072. * -----------
  1073. * This function returns a count of the number of children in the
  1074. * transient window tree headed by the specified client window.
  1075. *
  1076. *
  1077. * Inputs:
  1078. * ------
  1079. * pcd = pointer to client data of a window in a transient tree
  1080. *
  1081. * Outputs:
  1082. * -------
  1083. * RETURN = count of transient windows in the transient window tree
  1084. *
  1085. *************************************<->***********************************/
  1086. int
  1087. CountTransientChildren (ClientData *pcd)
  1088. {
  1089. ClientData *pcdNext;
  1090. int count = 1;
  1091. pcdNext = pcd->transientChildren;
  1092. while (pcdNext)
  1093. {
  1094. if (pcdNext->transientChildren)
  1095. {
  1096. count += CountTransientChildren (pcdNext);
  1097. }
  1098. else
  1099. {
  1100. count++;
  1101. }
  1102. pcdNext = pcdNext->transientSiblings;
  1103. }
  1104. return (count);
  1105. } /* END OF FUNCTION CountTransientChildren */
  1106. /*************************************<->*************************************
  1107. *
  1108. * MakeTransientWindowList (windows, pcd)
  1109. *
  1110. *
  1111. * Description:
  1112. * -----------
  1113. * This function makes a transient window list of windows in the
  1114. * transient window tree headed by the specified client. This list is
  1115. * to be passed to XRestackWindows.
  1116. *
  1117. *
  1118. * Inputs:
  1119. * ------
  1120. * windows = pointer to the windows list to be filled out
  1121. *
  1122. * pcd = pointer to client data of a window in a transient tree
  1123. *
  1124. * Outputs:
  1125. * -------
  1126. * RETURN = pointer to the next entry in the windows list
  1127. *
  1128. *************************************<->***********************************/
  1129. Window * MakeTransientWindowList (Window *windows, ClientData *pcd)
  1130. {
  1131. ClientData *pcdNext;
  1132. pcdNext = pcd->transientChildren;
  1133. while (pcdNext)
  1134. {
  1135. if (pcdNext->transientChildren)
  1136. {
  1137. windows = MakeTransientWindowList (windows, pcdNext);
  1138. }
  1139. *windows = pcdNext->clientFrameWin;
  1140. windows++;
  1141. pcdNext = pcdNext->transientSiblings;
  1142. }
  1143. return (windows);
  1144. } /* END OF FUNCTION MakeTransientWindowList */
  1145. /*************************************<->*************************************
  1146. *
  1147. * FindTransientFocus (pcd)
  1148. *
  1149. *
  1150. * Description:
  1151. * -----------
  1152. * This function identifies a window in the transient tree that is headed
  1153. * by the specified client that can accept the keyboard input. The
  1154. * effect of application modal windows is taken into account.
  1155. *
  1156. *
  1157. * Inputs:
  1158. * ------
  1159. * pcd = pointer to client data of a window in a transient tree.
  1160. *
  1161. * Outputs:
  1162. * -------
  1163. * RETURN = pointer to the client data for a window that can accept the
  1164. * keyboard input focus.
  1165. *
  1166. *************************************<->***********************************/
  1167. ClientData * FindTransientFocus (ClientData *pcd)
  1168. {
  1169. ClientData *pcdFocus;
  1170. /*
  1171. * Find a window that does not have an application modal subordinate.
  1172. * First, search descendents
  1173. */
  1174. pcdFocus = pcd;
  1175. while (pcdFocus->transientChildren && IS_APP_MODALIZED(pcdFocus))
  1176. {
  1177. pcdFocus = pcdFocus->transientChildren;
  1178. }
  1179. /*
  1180. * If (search of descendents FAILS) then search siblings.
  1181. */
  1182. if (IS_APP_MODALIZED(pcdFocus))
  1183. {
  1184. ClientData *pcdSibling;
  1185. pcdFocus = pcd;
  1186. while (pcdFocus && IS_APP_MODALIZED(pcdFocus))
  1187. {
  1188. pcdSibling = pcdFocus;
  1189. while (pcdSibling->transientSiblings && IS_APP_MODALIZED(pcdFocus))
  1190. {
  1191. pcdSibling = pcdSibling->transientSiblings;
  1192. }
  1193. if (IS_APP_MODALIZED(pcdSibling))
  1194. {
  1195. pcdFocus = pcdFocus->transientChildren;
  1196. }
  1197. else
  1198. {
  1199. pcdFocus = pcdSibling;
  1200. break;
  1201. }
  1202. }
  1203. }
  1204. return (pcdFocus ? pcdFocus : wmGD.keyboardFocus);
  1205. } /* END OF FUNCTION FindTransientFocus */
  1206. /*************************************<->*************************************
  1207. *
  1208. * FindTransientOnTop (pcd)
  1209. *
  1210. *
  1211. * Description:
  1212. * -----------
  1213. * This function identifies the top-most transient window in the
  1214. * transient window tree that contains the specified client.
  1215. *
  1216. *
  1217. * Inputs:
  1218. * ------
  1219. * pcd = pointer to client data of a window in a transient tree.
  1220. *
  1221. * Outputs:
  1222. * -------
  1223. * RETURN = pointer to the client data for the top-most transient window.
  1224. *
  1225. *************************************<->***********************************/
  1226. ClientData * FindTransientOnTop (ClientData *pcd)
  1227. {
  1228. /*
  1229. * Find the head of the transient window tree.
  1230. */
  1231. pcd = FindTransientTreeLeader (pcd);
  1232. if (!(pcd->secondariesOnTop) &&
  1233. (LeaderOnTop (pcd)))
  1234. {
  1235. ClientData *pcdSub;
  1236. if (LeaderOnTop (pcd))
  1237. {
  1238. /* The primary window is on top! */
  1239. return (pcd);
  1240. }
  1241. else
  1242. {
  1243. pcdSub = FindSubLeaderToTop (pcd);
  1244. if (pcdSub)
  1245. return (pcdSub);
  1246. }
  1247. }
  1248. /*
  1249. * Find the top-most transient window (the window in the transient tree
  1250. * that is highest in the window stack).
  1251. */
  1252. while (pcd->transientChildren)
  1253. {
  1254. pcd = pcd->transientChildren;
  1255. }
  1256. return (pcd);
  1257. } /* END OF FUNCTION FindTransientOnTop */
  1258. /*************************************<->*************************************
  1259. *
  1260. * StackWindow (pWS, pEntry, onTop, pStackEntry)
  1261. *
  1262. *
  1263. * Description:
  1264. * -----------
  1265. * This function stacks a window of a particular type (normal or icon)
  1266. * to the top or botton of the window stack on the screen.
  1267. *
  1268. *
  1269. * Inputs:
  1270. * ------
  1271. * pWS = pointer to workspace data
  1272. *
  1273. * pEntry = pointer to the client list entry for the window to be restacked.
  1274. *
  1275. * onTop = if True then the window is to be restacked on top of the
  1276. * specified stack window (if the stack window is not specified then
  1277. * the entry is added to the top of the window stack)
  1278. * otherwise the window is stacked below the specified stack window
  1279. * (or at the bottom of the window stack if the stack window is not
  1280. * specified).
  1281. *
  1282. * pStackEntry = pointer to a client list entry for a window in the window
  1283. * stack that is to be used as a reference in restacking.
  1284. *
  1285. *************************************<->***********************************/
  1286. void StackWindow (WmWorkspaceData *pWS, ClientListEntry *pEntry, Boolean onTop, ClientListEntry *pStackEntry)
  1287. {
  1288. Window stackWindow;
  1289. Boolean stackTransientTreeWindows = False;
  1290. Window activeIconWindow;
  1291. Window window;
  1292. XWindowChanges changes;
  1293. WmScreenData *pSD = pWS->pSD;
  1294. if (pStackEntry)
  1295. {
  1296. if (pStackEntry->type == MINIMIZED_STATE)
  1297. {
  1298. stackWindow = ICON_FRAME_WIN(pStackEntry->pCD);
  1299. }
  1300. else
  1301. {
  1302. stackWindow = pStackEntry->pCD->clientFrameWin;
  1303. }
  1304. }
  1305. else
  1306. {
  1307. stackWindow = (Window)0;
  1308. }
  1309. if (pEntry->type == MINIMIZED_STATE)
  1310. {
  1311. window = ICON_FRAME_WIN(pEntry->pCD);
  1312. }
  1313. else
  1314. {
  1315. /*
  1316. * Restack the transient tree if appropriate.
  1317. */
  1318. if (pEntry->pCD->transientLeader || pEntry->pCD->transientChildren)
  1319. {
  1320. stackTransientTreeWindows = True;
  1321. window = (FindTransientOnTop (pEntry->pCD))->clientFrameWin;
  1322. }
  1323. else
  1324. {
  1325. window = pEntry->pCD->clientFrameWin;
  1326. }
  1327. }
  1328. /*
  1329. * The active icon text label must be restacked along with the associated
  1330. * icon.
  1331. */
  1332. if ((pEntry->type == MINIMIZED_STATE) &&
  1333. (pEntry->pCD == wmGD.keyboardFocus) &&
  1334. (ICON_DECORATION(pEntry->pCD) & ICON_ACTIVE_LABEL_PART) &&
  1335. (ACTIVE_ICON_TEXT_WIN))
  1336. {
  1337. activeIconWindow = ACTIVE_ICON_TEXT_WIN;
  1338. }
  1339. else
  1340. {
  1341. activeIconWindow = (Window)0;
  1342. }
  1343. if (onTop)
  1344. {
  1345. if ((stackWindow == 0) && (pSD->clientList))
  1346. {
  1347. if (pSD->clientList->type == MINIMIZED_STATE)
  1348. {
  1349. stackWindow = ICON_FRAME_WIN(pSD->clientList->pCD);
  1350. }
  1351. else
  1352. {
  1353. if (pSD->clientList->pCD->transientChildren)
  1354. {
  1355. stackWindow =
  1356. (FindTransientOnTop(pSD->clientList->pCD))->clientFrameWin;
  1357. }
  1358. else
  1359. {
  1360. stackWindow = pSD->clientList->pCD->clientFrameWin;
  1361. }
  1362. }
  1363. }
  1364. if (activeIconWindow)
  1365. {
  1366. changes.sibling = stackWindow;
  1367. changes.stack_mode = Above;
  1368. XConfigureWindow (DISPLAY, activeIconWindow,
  1369. (CWSibling | CWStackMode), &changes);
  1370. changes.sibling = activeIconWindow;
  1371. changes.stack_mode = Below;
  1372. XConfigureWindow (DISPLAY, window, (CWSibling | CWStackMode),
  1373. &changes);
  1374. }
  1375. else
  1376. {
  1377. changes.sibling = stackWindow;
  1378. changes.stack_mode = Above;
  1379. XConfigureWindow (DISPLAY, window, (CWSibling | CWStackMode),
  1380. &changes);
  1381. if (stackTransientTreeWindows)
  1382. {
  1383. /* make sure that the leader is in the correct spot */
  1384. changes.sibling = window;
  1385. changes.stack_mode = Below;
  1386. XConfigureWindow (DISPLAY, pEntry->pCD->clientFrameWin,
  1387. (CWSibling | CWStackMode), &changes);
  1388. RestackTransients (pEntry->pCD);
  1389. }
  1390. }
  1391. }
  1392. else
  1393. {
  1394. /*
  1395. * Adjust stack entry window if we're stacking below a
  1396. * transient tree.
  1397. */
  1398. if (pStackEntry && pStackEntry->pCD->transientChildren)
  1399. {
  1400. stackWindow = LowestWindowInTransientFamily (pStackEntry->pCD);
  1401. }
  1402. if (stackWindow == 0)
  1403. {
  1404. if (pSD->lastClient->type == MINIMIZED_STATE)
  1405. {
  1406. stackWindow = ICON_FRAME_WIN(pSD->lastClient->pCD);
  1407. }
  1408. else
  1409. {
  1410. if (pSD->lastClient->pCD->transientChildren)
  1411. {
  1412. stackWindow =
  1413. LowestWindowInTransientFamily (pSD->lastClient->pCD);
  1414. }
  1415. else
  1416. stackWindow = pSD->lastClient->pCD->clientFrameWin;
  1417. }
  1418. }
  1419. if (activeIconWindow)
  1420. {
  1421. changes.sibling = stackWindow;
  1422. changes.stack_mode = Below;
  1423. XConfigureWindow (DISPLAY, activeIconWindow,
  1424. (CWSibling | CWStackMode), &changes);
  1425. changes.sibling = activeIconWindow;
  1426. changes.stack_mode = Below;
  1427. XConfigureWindow (DISPLAY, window, (CWSibling | CWStackMode),
  1428. &changes);
  1429. }
  1430. else
  1431. {
  1432. changes.sibling = stackWindow;
  1433. changes.stack_mode = Below;
  1434. XConfigureWindow (DISPLAY, window, (CWSibling | CWStackMode),
  1435. &changes);
  1436. if (stackTransientTreeWindows)
  1437. {
  1438. /* make sure that the leader is in the correct spot */
  1439. changes.sibling = window;
  1440. changes.stack_mode = Below;
  1441. XConfigureWindow (DISPLAY, pEntry->pCD->clientFrameWin,
  1442. (CWSibling | CWStackMode), &changes);
  1443. RestackTransients (pEntry->pCD);
  1444. }
  1445. }
  1446. }
  1447. } /* END OF FUNCTION StackWindow */
  1448. /*************************************<->*************************************
  1449. *
  1450. * StackTransientWindow (pcd)
  1451. *
  1452. *
  1453. * Description:
  1454. * -----------
  1455. * This function stacks a transient window within its transient window
  1456. * tree on the screen. The transient window tree should indicate the
  1457. * intended stacking position.
  1458. *
  1459. *
  1460. * Inputs:
  1461. * ------
  1462. * pcd = pointer to client data of a window in a transient tree
  1463. *
  1464. *************************************<->***********************************/
  1465. void StackTransientWindow (ClientData *pcd)
  1466. {
  1467. XWindowChanges changes;
  1468. ClientData *pcdPrev;
  1469. if (pcd->transientLeader->transientChildren == pcd)
  1470. {
  1471. if (pcd->transientSiblings)
  1472. {
  1473. changes.sibling = pcd->transientSiblings->clientFrameWin;
  1474. }
  1475. else
  1476. {
  1477. changes.sibling = pcd->transientLeader->clientFrameWin;
  1478. }
  1479. changes.stack_mode = Above;
  1480. }
  1481. else
  1482. {
  1483. pcdPrev = pcd->transientLeader;
  1484. while (pcdPrev->transientSiblings != pcd)
  1485. {
  1486. pcdPrev = pcdPrev->transientSiblings;
  1487. }
  1488. changes.sibling = pcdPrev->clientFrameWin;
  1489. changes.stack_mode = Below;
  1490. }
  1491. XConfigureWindow (DISPLAY, pcd->clientFrameWin, (CWSibling | CWStackMode),
  1492. &changes);
  1493. } /* END OF FUNCTION StackTransientWindow */
  1494. /*************************************<->*************************************
  1495. *
  1496. * CheckIfClientObscuring (pcdTop, pcd)
  1497. *
  1498. *
  1499. * Description:
  1500. * -----------
  1501. * This function determines whether a window or a transient window tree
  1502. * is obscuring (at least partially) a window or a transient window tree
  1503. * that is below it in the window stack.
  1504. *
  1505. *
  1506. * Inputs:
  1507. * ------
  1508. * pcdTop = pointer to client data for a window (it may be the leader of
  1509. * a transient tree; this window is the higher in the window stack
  1510. * than the window it is be checked against.
  1511. *
  1512. * pcd = pointer to client data for a window (it may be the leader of
  1513. * a transient tree.
  1514. *
  1515. *
  1516. * Outputs:
  1517. * -------
  1518. * RETURN = True if the top window(s) overlap the lower window(s)
  1519. *
  1520. *************************************<->***********************************/
  1521. Boolean CheckIfClientObscuring (ClientData *pcdTop, ClientData *pcd)
  1522. {
  1523. Boolean obscuring = False;
  1524. ClientData *pcdNext;
  1525. /*
  1526. * Check only if the top window is visible onscreen.
  1527. */
  1528. if (pcdTop->transientChildren && (pcdTop->clientState != MINIMIZED_STATE))
  1529. {
  1530. pcdNext = pcdTop->transientChildren;
  1531. while (pcdNext && !obscuring)
  1532. {
  1533. obscuring = CheckIfClientObscuring (pcdNext, pcd);
  1534. pcdNext = pcdNext->transientSiblings;
  1535. }
  1536. }
  1537. if (!obscuring && pcd->transientChildren &&
  1538. (pcd->clientState != MINIMIZED_STATE))
  1539. {
  1540. pcdNext = pcd->transientChildren;
  1541. while (pcdNext && !obscuring)
  1542. {
  1543. obscuring = CheckIfClientObscuring (pcdTop, pcdNext);
  1544. pcdNext = pcdNext->transientSiblings;
  1545. }
  1546. }
  1547. if (!obscuring)
  1548. {
  1549. obscuring = CheckIfObscuring (pcdTop, pcd);
  1550. }
  1551. return (obscuring);
  1552. } /* END OF FUNCTION CheckIfClientObscuring */
  1553. /*************************************<->*************************************
  1554. *
  1555. * CheckIfObscuring (pcdA, pcdB)
  1556. *
  1557. *
  1558. * Description:
  1559. * -----------
  1560. * This function determines whether a window (not a transient tree)
  1561. * is obscuring (at least partially) a window (not a transient tree)
  1562. * that is below it in the window stack.
  1563. *
  1564. *
  1565. * Inputs:
  1566. * ------
  1567. * pcdA = pointer to client data for a window; this window is higher in
  1568. * the window stack than the window it is be checked against.
  1569. *
  1570. * pcdB = pointer to client data for a window.
  1571. *
  1572. *
  1573. * Outputs:
  1574. * -------
  1575. * RETURN = True if the top window overlaps the lower window
  1576. *
  1577. *************************************<->***********************************/
  1578. Boolean CheckIfObscuring (ClientData *pcdA, ClientData *pcdB)
  1579. {
  1580. Boolean obscuring = False;
  1581. int aX1;
  1582. int aX2;
  1583. int aY1;
  1584. int aY2;
  1585. int bX1;
  1586. int bX2;
  1587. int bY1;
  1588. int bY2;
  1589. /*
  1590. * For workspace stuff: if either is unseen, then neither
  1591. * is obscured.
  1592. */
  1593. if ((pcdA->clientState & UNSEEN_STATE) ||
  1594. (pcdB->clientState & UNSEEN_STATE))
  1595. {
  1596. return (False);
  1597. }
  1598. if (pcdA->clientState == NORMAL_STATE)
  1599. {
  1600. aX1 = pcdA->clientX - pcdA->clientOffset.x;
  1601. aY1 = pcdA->clientY - pcdA->clientOffset.y;
  1602. aX2 = aX1 + pcdA->clientWidth + (2 * pcdA->clientOffset.x) - 1;
  1603. aY2 = aY1 + pcdA->clientHeight + pcdA->clientOffset.y +
  1604. pcdA->clientOffset.x - 1;
  1605. }
  1606. else if (pcdA->clientState == MINIMIZED_STATE)
  1607. {
  1608. aX1 = ICON_X(pcdA);
  1609. aY1 = ICON_Y(pcdA);
  1610. aX2 = aX1 + ICON_WIDTH(pcdA) - 1;
  1611. aY2 = aY1 + ICON_HEIGHT(pcdA) - 1;
  1612. }
  1613. else /* (pcdA->clientState == MAXIMIZED_STATE) */
  1614. {
  1615. aX1 = pcdA->maxX - pcdA->clientOffset.x;
  1616. aY1 = pcdA->maxY - pcdA->clientOffset.y;
  1617. aX2 = aX1 + pcdA->maxWidth + (2 * pcdA->clientOffset.x) - 1;
  1618. aY2 = aY1 + pcdA->maxHeight + pcdA->clientOffset.y +
  1619. pcdA->clientOffset.x - 1;
  1620. }
  1621. if (pcdB->clientState == NORMAL_STATE)
  1622. {
  1623. bX1 = pcdB->clientX - pcdB->clientOffset.x;
  1624. bY1 = pcdB->clientY - pcdB->clientOffset.y;
  1625. bX2 = bX1 + pcdB->clientWidth + (2 * pcdB->clientOffset.x) - 1;
  1626. bY2 = bY1 + pcdB->clientHeight + pcdB->clientOffset.y +
  1627. pcdB->clientOffset.x - 1;
  1628. }
  1629. else if (pcdB->clientState == MINIMIZED_STATE)
  1630. {
  1631. bX1 = ICON_X(pcdB);
  1632. bY1 = ICON_Y(pcdB);
  1633. bX2 = bX1 + ICON_WIDTH(pcdB) - 1;
  1634. bY2 = bY1 + ICON_HEIGHT(pcdB) - 1;
  1635. }
  1636. else /* (pcdB->clientState == MAXIMIZED_STATE) */
  1637. {
  1638. bX1 = pcdB->maxX - pcdB->clientOffset.x;
  1639. bY1 = pcdB->maxY - pcdB->clientOffset.y;
  1640. bX2 = bX1 + pcdB->maxWidth + (2 * pcdB->clientOffset.x) - 1;
  1641. bY2 = bY1 + pcdB->maxHeight + pcdB->clientOffset.y +
  1642. pcdB->clientOffset.x - 1;
  1643. }
  1644. /*
  1645. * Check if there is overlap in both dimensions.
  1646. */
  1647. if (((aX1 >= bX1) && (aX1 <= bX2)) || ((aX2 >= bX1) && (aX2 <= bX2)) ||
  1648. ((bX1 >= aX1) && (bX1 <= aX2)) || ((bX2 >= aX1) && (bX2 <= aX2)))
  1649. {
  1650. if (((aY1 >= bY1) && (aY1 <= bY2)) || ((aY2 >= bY1) && (aY2 <= bY2)) ||
  1651. ((bY1 >= aY1) && (bY1 <= aY2)) || ((bY2 >= aY1) && (bY2 <= aY2)))
  1652. {
  1653. obscuring = True;
  1654. }
  1655. }
  1656. return (obscuring);
  1657. } /* END OF FUNCTION CheckIfObscuring */
  1658. /*************************************<->*************************************
  1659. *
  1660. * CheckIfClientObscuredByAny (pcd)
  1661. *
  1662. *
  1663. * Description:
  1664. * -----------
  1665. * This function determines whether a window or a transient window tree
  1666. * is obscured (at least partially) by any other window.
  1667. *
  1668. *
  1669. * Inputs:
  1670. * ------
  1671. * pcd = pointer to client data for a window (it may be the leader of
  1672. * a transient tree.
  1673. *
  1674. *
  1675. * Outputs:
  1676. * -------
  1677. * RETURN = True if the window(s) are overlapped.
  1678. *
  1679. *************************************<->***********************************/
  1680. Boolean CheckIfClientObscuredByAny (ClientData *pcd)
  1681. {
  1682. Boolean obscured = False;
  1683. ClientListEntry *pListEntry;
  1684. pListEntry = ACTIVE_PSD->clientList;
  1685. while (pListEntry && !obscured)
  1686. {
  1687. if (pListEntry->pCD == pcd)
  1688. {
  1689. if (((pListEntry->type == MINIMIZED_STATE) &&
  1690. (pListEntry->pCD->clientState == MINIMIZED_STATE)) ||
  1691. ((pListEntry->type != MINIMIZED_STATE) &&
  1692. (pListEntry->pCD->clientState != MINIMIZED_STATE)))
  1693. {
  1694. pListEntry = NULL;
  1695. }
  1696. }
  1697. else if (((pListEntry->type == MINIMIZED_STATE) &&
  1698. (pListEntry->pCD->clientState == MINIMIZED_STATE)) ||
  1699. ((pListEntry->type != MINIMIZED_STATE) &&
  1700. (pListEntry->pCD->clientState != MINIMIZED_STATE)))
  1701. {
  1702. /*
  1703. * The window for the entry is visible on screen. See if it
  1704. * obscures the indicated window.
  1705. */
  1706. obscured = CheckIfClientObscuring (pListEntry->pCD, pcd);
  1707. }
  1708. if (pListEntry)
  1709. {
  1710. pListEntry = pListEntry->nextSibling;
  1711. }
  1712. }
  1713. return (obscured);
  1714. } /* END OF FUNCTION CheckIfClientObscuredByAny */
  1715. /*************************************<->*************************************
  1716. *
  1717. * CheckIfClientObscuringAny (pcd)
  1718. *
  1719. *
  1720. * Description:
  1721. * -----------
  1722. * This function determines whether a window or a transient window tree
  1723. * is obscuring another window.
  1724. *
  1725. *
  1726. * Inputs:
  1727. * ------
  1728. * pcd = pointer to client data for a window (it may be the leader of
  1729. * a transient tree.
  1730. *
  1731. *
  1732. * Outputs:
  1733. * -------
  1734. * RETURN = True if the window(s) overlaps anther window.
  1735. *
  1736. *************************************<->***********************************/
  1737. Boolean CheckIfClientObscuringAny (ClientData *pcd)
  1738. {
  1739. Boolean obscuring = False;
  1740. ClientListEntry *pListEntry;
  1741. pListEntry = (pcd->clientState == MINIMIZED_STATE) ?
  1742. &pcd->iconEntry : &pcd->clientEntry;
  1743. while (pListEntry && !obscuring)
  1744. {
  1745. if ((pListEntry->pCD != pcd) &&
  1746. (((pListEntry->type == MINIMIZED_STATE) &&
  1747. (pListEntry->pCD->clientState == MINIMIZED_STATE)) ||
  1748. ((pListEntry->type != MINIMIZED_STATE) &&
  1749. (pListEntry->pCD->clientState != MINIMIZED_STATE))))
  1750. {
  1751. obscuring = CheckIfClientObscuring (pcd, pListEntry->pCD);
  1752. }
  1753. pListEntry = pListEntry->nextSibling;
  1754. }
  1755. return (obscuring);
  1756. } /* END OF FUNCTION CheckIfClientObscuringAny */
  1757. /*************************************<->*************************************
  1758. *
  1759. * SetupSystemModalState (pCD)
  1760. *
  1761. *
  1762. * Description:
  1763. * -----------
  1764. * This function prepares for mapping a system modal window. An input
  1765. * screen window is mapped below the system modal window to prevent input
  1766. * to the windows not related to the system modal window.
  1767. *
  1768. *
  1769. * Inputs:
  1770. * ------
  1771. * pCD = pointer to client data for the system modal window; if NULL the
  1772. * system modal window is a special window manager dialog box
  1773. *
  1774. *
  1775. * Outputs:
  1776. * -------
  1777. * wmGD = changes to system modal state data
  1778. *
  1779. *************************************<->***********************************/
  1780. void SetupSystemModalState (ClientData *pCD)
  1781. {
  1782. XWindowChanges windowChanges;
  1783. unsigned int width, height;
  1784. unsigned int x_hot, y_hot;
  1785. unsigned char *bits;
  1786. unsigned char *mask_bits;
  1787. WmScreenData *pSD;
  1788. int scr;
  1789. /*
  1790. * If we've got a menu active, then unpost it first
  1791. * so that grabs from the menu don't interfere with
  1792. * the system modal dialog. We want to avoid lock-ups.
  1793. */
  1794. if (wmGD.menuActive != NULL)
  1795. {
  1796. UnpostMenu (wmGD.menuActive);
  1797. XSync (DISPLAY, False);
  1798. }
  1799. /*
  1800. * Try to grab the pointer and keyboard. If either
  1801. * fails because event processing is frozen by another grab, then
  1802. * don't do system modal for fear of leaving the system unusable.
  1803. */
  1804. if (XGrabPointer(DISPLAY,
  1805. ROOT_FOR_CLIENT(pCD),
  1806. FALSE, /* owner_events */
  1807. (unsigned int) 0, /* event mask */
  1808. GrabModeAsync, /* pointer_mode */
  1809. GrabModeAsync, /* keyboard_mode */
  1810. None, /* confine_to window */
  1811. None, /* cursor */
  1812. CurrentTime) == GrabFrozen)
  1813. {
  1814. return;
  1815. }
  1816. else
  1817. {
  1818. XUngrabPointer (DISPLAY, CurrentTime);
  1819. }
  1820. if (XGrabKeyboard(DISPLAY,
  1821. ROOT_FOR_CLIENT(pCD),
  1822. FALSE, /* owner_events */
  1823. GrabModeAsync, /* pointer_mode */
  1824. GrabModeAsync, /* keyboard_mode */
  1825. CurrentTime) == GrabFrozen)
  1826. {
  1827. return;
  1828. }
  1829. else
  1830. {
  1831. XUngrabKeyboard (DISPLAY, CurrentTime);
  1832. }
  1833. #ifdef LARGECURSORS
  1834. if (wmGD.useLargeCursors)
  1835. {
  1836. width = noenter32_width;
  1837. height = noenter32_height;
  1838. x_hot = noenter32_x_hot;
  1839. y_hot = noenter32_y_hot;
  1840. bits = noenter32_bits;
  1841. mask_bits = noenter32m_bits;
  1842. }
  1843. else
  1844. #endif /* LARGECURSORS */
  1845. {
  1846. width = noenter16_width;
  1847. height = noenter16_height;
  1848. x_hot = noenter16_x_hot;
  1849. y_hot = noenter16_y_hot;
  1850. bits = noenter16_bits;
  1851. mask_bits = noenter16m_bits;
  1852. }
  1853. for (scr=0; scr<wmGD.numScreens; scr++)
  1854. {
  1855. pSD = &(wmGD.Screens[scr]);
  1856. /*
  1857. * Make the system modal input screen window if necessary.
  1858. */
  1859. if (pSD->managed && pSD->inputScreenWindow == 0)
  1860. {
  1861. XSetWindowAttributes windowAttributes;
  1862. Pixmap pixmap;
  1863. Pixmap maskPixmap;
  1864. XColor xcolors[2];
  1865. windowAttributes.event_mask = ButtonPressMask;
  1866. if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER)
  1867. {
  1868. windowAttributes.event_mask |= EnterWindowMask;
  1869. }
  1870. windowAttributes.override_redirect = True;
  1871. pixmap = XCreateBitmapFromData (DISPLAY, pSD->rootWindow,
  1872. (char *)bits, width, height);
  1873. maskPixmap = XCreateBitmapFromData (DISPLAY, pSD->rootWindow,
  1874. (char *)mask_bits, width, height);
  1875. xcolors[0].pixel = BlackPixel (DISPLAY, pSD->screen);
  1876. xcolors[1].pixel = WhitePixel (DISPLAY, pSD->screen);
  1877. XQueryColors (DISPLAY, DefaultColormap (DISPLAY, pSD->screen),
  1878. xcolors, 2);
  1879. windowAttributes.cursor =
  1880. XCreatePixmapCursor (DISPLAY, pixmap, maskPixmap,
  1881. &(xcolors[0]), &(xcolors[1]),
  1882. x_hot, y_hot);
  1883. XFreePixmap (DISPLAY, pixmap);
  1884. XFreePixmap (DISPLAY, maskPixmap);
  1885. pSD->inputScreenWindow =
  1886. XCreateWindow (DISPLAY, pSD->rootWindow, 0, 0,
  1887. DisplayWidth (DISPLAY, pSD->screen),
  1888. DisplayHeight (DISPLAY, pSD->screen),
  1889. 0,
  1890. 0,
  1891. InputOnly,
  1892. CopyFromParent,
  1893. CWEventMask | CWOverrideRedirect | CWCursor,
  1894. &windowAttributes);
  1895. }
  1896. if (pSD->managed && pSD != ACTIVE_PSD)
  1897. {
  1898. XMapRaised (DISPLAY, pSD->inputScreenWindow);
  1899. }
  1900. }
  1901. if (pCD)
  1902. {
  1903. wmGD.systemModalWindow = pCD->clientFrameWin;
  1904. }
  1905. else
  1906. {
  1907. /*
  1908. * ELSE: the system modal window is a special window manager dialog
  1909. * box and wmGD.systemModalWindow is set prior to the call to
  1910. * SetupSystemModalState. Set the focus to the special window manager
  1911. * dialog box.
  1912. */
  1913. SetKeyboardFocus (NULL, REFRESH_LAST_FOCUS);
  1914. XSetInputFocus (DISPLAY, wmGD.systemModalWindow, RevertToPointerRoot,
  1915. CurrentTime);
  1916. }
  1917. /*
  1918. * Map the system modal input screen window below the system modal
  1919. * window.
  1920. */
  1921. windowChanges.sibling = wmGD.systemModalWindow;
  1922. windowChanges.stack_mode = Below;
  1923. XConfigureWindow (DISPLAY, ACTIVE_PSD->inputScreenWindow,
  1924. CWSibling | CWStackMode, &windowChanges);
  1925. XMapWindow (DISPLAY, ACTIVE_PSD->inputScreenWindow);
  1926. /*
  1927. * Setup the system modal global data.
  1928. */
  1929. wmGD.systemModalActive = True;
  1930. wmGD.systemModalClient = pCD;
  1931. } /* END OF FUNCTION SetupSystemModalState */
  1932. /*************************************<->*************************************
  1933. *
  1934. * UndoSystemModalState ()
  1935. *
  1936. *
  1937. * Description:
  1938. * -----------
  1939. * This function cleans up after a system modal window goes away.
  1940. *
  1941. *
  1942. * Inputs:
  1943. * ------
  1944. * wmGD = (system modal state data)
  1945. *
  1946. *
  1947. * Outputs:
  1948. * -------
  1949. * wmGD = changes to system modal state data
  1950. *
  1951. *************************************<->***********************************/
  1952. void UndoSystemModalState (void)
  1953. {
  1954. int scr;
  1955. /*
  1956. * Unmap the system modal input screen window.
  1957. */
  1958. for (scr = 0; scr < wmGD.numScreens; scr++)
  1959. {
  1960. if(wmGD.Screens[scr].managed)
  1961. {
  1962. XUnmapWindow (DISPLAY, wmGD.Screens[scr].inputScreenWindow);
  1963. }
  1964. }
  1965. /*
  1966. * Reset the focus if a window manager system modal dialog box was
  1967. * being displayed.
  1968. */
  1969. if (!wmGD.systemModalClient)
  1970. {
  1971. AutoResetKeyFocus (NULL, GetTimestamp());
  1972. }
  1973. /*
  1974. * Reset the system modal global data.
  1975. */
  1976. wmGD.systemModalActive = False;
  1977. wmGD.systemModalClient = NULL;
  1978. wmGD.systemModalWindow = 0;
  1979. } /* END OF FUNCTION UndoSystemModalState */
  1980. /*************************************<->*************************************
  1981. *
  1982. * FindClientNameMatch (pStartingEntry, toNext, clientName, types)
  1983. *
  1984. *
  1985. * Description:
  1986. * -----------
  1987. * This function searches for a client that has a particular name or class.
  1988. * A match will be indicated if the client with the name or class also
  1989. * is in a particular state.
  1990. *
  1991. *
  1992. * Inputs:
  1993. * ------
  1994. * pEntry = pointer to the client list entry where the search is
  1995. * to begin.
  1996. *
  1997. * toNext = if True then search client list from first to last; otherwise
  1998. * search the client list last to first.
  1999. *
  2000. * clientName = string that indicates a client name or class.
  2001. *
  2002. * type = types of objects (icon, window, ...) that are to be matched.
  2003. *
  2004. *
  2005. * Outputs:
  2006. * -------
  2007. * RETURN = pointer to client list entry for matched client.
  2008. *
  2009. *************************************<->***********************************/
  2010. ClientListEntry * FindClientNameMatch (ClientListEntry *pEntry,
  2011. Boolean toNext,
  2012. String clientName,
  2013. unsigned long types)
  2014. {
  2015. Boolean foundMatch = False;
  2016. Boolean checkEntry;
  2017. ClientData *pCD;
  2018. while (!foundMatch && pEntry)
  2019. {
  2020. checkEntry = False;
  2021. pCD = pEntry->pCD;
  2022. if (pEntry->type == MINIMIZED_STATE)
  2023. {
  2024. if ((pCD->clientState == MINIMIZED_STATE) &&
  2025. (types & F_GROUP_ICON))
  2026. {
  2027. checkEntry = True;
  2028. }
  2029. }
  2030. else
  2031. {
  2032. if ((pCD->clientState != MINIMIZED_STATE) &&
  2033. (types & F_GROUP_WINDOW))
  2034. {
  2035. checkEntry = True;
  2036. }
  2037. }
  2038. if (checkEntry &&
  2039. ((pCD->clientName && (strcmp (clientName,pCD->clientName) == 0)) ||
  2040. (pCD->clientClass && (strcmp (clientName,pCD->clientClass) == 0))))
  2041. {
  2042. foundMatch = True;
  2043. }
  2044. else
  2045. {
  2046. pEntry = (toNext) ? pEntry->nextSibling : pEntry->prevSibling;
  2047. }
  2048. }
  2049. return (pEntry);
  2050. } /* END OF FUNCTION FindClientNameMatch */
  2051. /*************************************<->*************************************
  2052. *
  2053. * BumpPrimaryToTop (pcdLeader)
  2054. *
  2055. *
  2056. * Description:
  2057. * -----------
  2058. * This function moves the primary window to the "top" of the transient
  2059. * tree.
  2060. *
  2061. * Inputs:
  2062. * ------
  2063. * pcdLeader = pointer to client data of transient tree root.
  2064. *
  2065. * Returns: True if stacking order of leader window changed.
  2066. * False if not stacking change.
  2067. *
  2068. * Comments:
  2069. * ---------
  2070. * This affects only the clientData structures. There is no immediate
  2071. * effect on the actual stacking order on the display. That is done
  2072. * by StackWindow and/or RestackTransients.
  2073. *
  2074. *************************************<->***********************************/
  2075. Boolean BumpPrimaryToTop (ClientData *pcdLeader)
  2076. {
  2077. int count;
  2078. Boolean rval;
  2079. count = CountTransientChildren (pcdLeader);
  2080. if (pcdLeader->primaryStackPosition != (count-1))
  2081. {
  2082. pcdLeader->primaryStackPosition = count - 1;
  2083. rval = True;
  2084. }
  2085. else
  2086. {
  2087. rval = False;
  2088. }
  2089. return (rval);
  2090. }
  2091. /*************************************<->*************************************
  2092. *
  2093. * BumpPrimaryToBottom (pcdLeader)
  2094. *
  2095. *
  2096. * Description:
  2097. * -----------
  2098. * This function moves the primary window to the "bottom" of the transient
  2099. * tree.
  2100. *
  2101. * Inputs:
  2102. * ------
  2103. * pcdLeader = pointer to client data of transient tree root.
  2104. *
  2105. * Returns: True if stacking order of leader window changed.
  2106. * False if not stacking change.
  2107. *
  2108. * Comments:
  2109. * ---------
  2110. * This affects only the clientData structures. There is no immediate
  2111. * effect on the actual stacking order on the display. That is done
  2112. * by StackWindow and/or RestackTransients.
  2113. *
  2114. *************************************<->***********************************/
  2115. Boolean BumpPrimaryToBottom (ClientData *pcdLeader)
  2116. {
  2117. Boolean rval;
  2118. if (pcdLeader->primaryStackPosition != 0)
  2119. {
  2120. pcdLeader->primaryStackPosition = 0;
  2121. rval = True;
  2122. }
  2123. else
  2124. {
  2125. rval = False;
  2126. }
  2127. return (rval);
  2128. }
  2129. /*************************************<->*************************************
  2130. *
  2131. * LowestWindowInTransientFamily (pcdLeader)
  2132. *
  2133. *
  2134. * Description:
  2135. * -----------
  2136. * This function returns the lowest stacked window in a transient
  2137. * tree family.
  2138. *
  2139. * Inputs:
  2140. * ------
  2141. * pcdLeader = pointer to client data of leader of a transient tree
  2142. *
  2143. * Returns: id of lowest window in the transient tree for this family
  2144. *
  2145. *************************************<->***********************************/
  2146. Window
  2147. LowestWindowInTransientFamily (ClientData *pcdLeader)
  2148. {
  2149. int count;
  2150. static int size = 0;
  2151. static Window *windows = NULL;
  2152. Window wReturn = None;
  2153. /*
  2154. * Build a window list
  2155. */
  2156. count = CountTransientChildren (pcdLeader);
  2157. if (count > size)
  2158. {
  2159. /*
  2160. * Expand the (static) windows buffer
  2161. */
  2162. if (!(windows =
  2163. (Window *)WmMalloc ((char*)windows, (count + 5) * sizeof (Window))))
  2164. {
  2165. /* cannot get memory space */
  2166. size = 0;
  2167. return None;
  2168. }
  2169. size = count + 5;
  2170. }
  2171. MakeTransientFamilyStackingList (windows, pcdLeader);
  2172. if (count > 0)
  2173. {
  2174. wReturn = windows[count-1];
  2175. }
  2176. else
  2177. {
  2178. wReturn = None;
  2179. }
  2180. return (wReturn);
  2181. } /* END OF FUNCTION LowestWindowInTransientFamily */
  2182. /*************************************<->*************************************
  2183. *
  2184. * FindSubLeaderToTop (pcd)
  2185. *
  2186. *
  2187. * Description:
  2188. * -----------
  2189. * This function identifies a candidate window to top within the
  2190. * transient tree that is a local transient leader (the window has
  2191. * transients hanging off of it, too).
  2192. *
  2193. *
  2194. * Inputs:
  2195. * ------
  2196. * pcd = pointer to client data of a transient leader window
  2197. *
  2198. * Return: ptr to client data for client that should be topped, or NULL
  2199. *
  2200. *
  2201. * Comments:
  2202. * --------
  2203. *
  2204. *************************************<->***********************************/
  2205. ClientData *
  2206. FindSubLeaderToTop (
  2207. ClientData *pcd)
  2208. {
  2209. ClientData *pcdRet = NULL;
  2210. ClientData *pcdNext;
  2211. pcdNext = pcd->transientChildren;
  2212. while (pcdNext && (!pcdRet))
  2213. {
  2214. if (pcdNext->transientChildren)
  2215. {
  2216. if (LeaderOnTop (pcdNext))
  2217. {
  2218. pcdRet = pcdNext;
  2219. }
  2220. else
  2221. {
  2222. pcdRet = FindSubLeaderToTop (pcdNext);
  2223. }
  2224. }
  2225. pcdNext = pcdNext->transientSiblings;
  2226. }
  2227. return (pcdRet);
  2228. }
  2229. /*************************************<->*************************************
  2230. *
  2231. * MakeTransientFamilyStackingList (windows, pcdLeader)
  2232. *
  2233. *
  2234. * Description:
  2235. * -----------
  2236. * This function makes a transient window list of windows in the
  2237. * transient window tree headed by the specified client.
  2238. *
  2239. *
  2240. * Inputs:
  2241. * ------
  2242. * windows = pointer to the windows list to be filled out
  2243. *
  2244. * pcdLeader = pointer to client data of a window in a transient tree
  2245. *
  2246. * Outputs:
  2247. * -------
  2248. * The windows array is modified.
  2249. *
  2250. * Comments:
  2251. * --------
  2252. * This function puts the transient leader window in the list in the
  2253. * right place.
  2254. *
  2255. *************************************<->***********************************/
  2256. void
  2257. MakeTransientFamilyStackingList (
  2258. Window *windows,
  2259. ClientData *pcdLeader)
  2260. {
  2261. ClientData *pcdSub;
  2262. Window *nextWindow, wSave, wTemp, wTop;
  2263. int count = CountTransientChildren (pcdLeader);
  2264. int i, j;
  2265. /*
  2266. * Construct the transient stacking list according to
  2267. * normal Motif rules.
  2268. */
  2269. nextWindow = MakeTransientWindowList (windows, pcdLeader);
  2270. if (!(pcdLeader->secondariesOnTop))
  2271. {
  2272. /*
  2273. * If the leader window shouldn't be on the bottom , then
  2274. * adjust the stacking of the list.
  2275. */
  2276. if ((pcdLeader->primaryStackPosition > 0) &&
  2277. (pcdLeader->primaryStackPosition < count))
  2278. {
  2279. for (i=0; i<pcdLeader->primaryStackPosition; i++)
  2280. {
  2281. j = count - i - 1;
  2282. windows[j] = windows[j-1];
  2283. }
  2284. j = count - pcdLeader->primaryStackPosition - 1;
  2285. windows[j] = pcdLeader->clientFrameWin;
  2286. }
  2287. else
  2288. {
  2289. /*
  2290. * Put the leader at the bottom.
  2291. */
  2292. *nextWindow = pcdLeader->clientFrameWin;
  2293. /*
  2294. * If one of the transients is also a local leader
  2295. * and wants to be on top, then adjust the list.
  2296. */
  2297. pcdSub = FindSubLeaderToTop (pcdLeader);
  2298. if (pcdSub && (pcdSub->clientFrameWin != None))
  2299. {
  2300. /* insert this window at top */
  2301. wTop = wSave = pcdSub->clientFrameWin;
  2302. /* shuffle the rest down */
  2303. for (i=0; i<count; i++)
  2304. {
  2305. wTemp = windows[i];
  2306. windows[i] = wSave;
  2307. wSave = wTemp;
  2308. if (wTop == wSave)
  2309. break;
  2310. }
  2311. }
  2312. }
  2313. }
  2314. else
  2315. {
  2316. /*
  2317. * Put the leader at the bottom.
  2318. */
  2319. *nextWindow = pcdLeader->clientFrameWin;
  2320. }
  2321. } /* END OF FUNCTION MakeTransientFamilyStackingList */
  2322. /*************************************<->*************************************
  2323. *
  2324. * NormalizeTransientTreeStacking (pcdLeader)
  2325. *
  2326. *
  2327. * Description:
  2328. * -----------
  2329. * This function traverses the transient tree and cleans up any
  2330. * local primary windows that are above their respective secondary
  2331. * windows.
  2332. *
  2333. *
  2334. * Inputs:
  2335. * ------
  2336. * pcdLeader = pointer to client data of a transient tree leader
  2337. *
  2338. * Return: True if any changes in stacking order were made
  2339. *
  2340. *
  2341. * Comments:
  2342. * --------
  2343. * This only touches the data structures.
  2344. *
  2345. *************************************<->***********************************/
  2346. Boolean
  2347. NormalizeTransientTreeStacking (
  2348. ClientData *pcdLeader)
  2349. {
  2350. ClientData *pcdNext;
  2351. Boolean bChanged = False;
  2352. pcdNext = pcdLeader->transientChildren;
  2353. bChanged = BumpPrimaryToBottom (pcdLeader);
  2354. while (pcdNext)
  2355. {
  2356. if (pcdNext->transientChildren)
  2357. {
  2358. bChanged |= BumpPrimaryToBottom (pcdNext);
  2359. bChanged |= NormalizeTransientTreeStacking (pcdNext);
  2360. }
  2361. pcdNext = pcdNext->transientSiblings;
  2362. }
  2363. return (bChanged);
  2364. }
  2365. /*************************************<->*************************************
  2366. *
  2367. * LeaderOnTop (pcdLeader)
  2368. *
  2369. *
  2370. * Description:
  2371. * -----------
  2372. * This function tests a leader of a transient (sub) tree to see if
  2373. * it should be on top of its transient windows.
  2374. *
  2375. *
  2376. * Inputs:
  2377. * ------
  2378. * pcdLeader = pointer to client data of a transient tree leader
  2379. *
  2380. * Return: True if this leader is on top of its transients
  2381. *
  2382. *
  2383. * Comments:
  2384. * --------
  2385. *
  2386. *************************************<->***********************************/
  2387. Boolean
  2388. LeaderOnTop (
  2389. ClientData *pcdLeader)
  2390. {
  2391. Boolean bOnTop = False;
  2392. int count = CountTransientChildren (pcdLeader);
  2393. if ((pcdLeader->primaryStackPosition > 0) &&
  2394. (pcdLeader->primaryStackPosition < count))
  2395. {
  2396. bOnTop = True;
  2397. }
  2398. return (bOnTop);
  2399. }