WmWinInfo.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935
  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 HEWLETT-PACKARD COMPANY */
  32. /*
  33. * Included Files:
  34. */
  35. #include "WmGlobal.h"
  36. #include "WmICCC.h"
  37. #include "WmResNames.h"
  38. #define MWM_NEED_ICONBOX
  39. #include "WmIBitmap.h"
  40. #include <Xm/Xm.h>
  41. #include <locale.h>
  42. #include "WmPanelP.h"
  43. #define makemult(a, b) ((b==1) ? (a) : (((int)((a) / (b))) * (b)) )
  44. /*
  45. * include extern functions
  46. */
  47. #include "WmWinInfo.h"
  48. #include "WmCDInfo.h"
  49. #include "WmCDecor.h"
  50. #include "WmCPlace.h"
  51. #include "WmError.h"
  52. #include "WmIDecor.h"
  53. #include "WmIPlace.h"
  54. #include "WmIconBox.h"
  55. #include "WmImage.h"
  56. #include "WmManage.h"
  57. #include "WmMenu.h"
  58. #include "WmOL.h"
  59. #include "WmProperty.h"
  60. #include "WmResource.h"
  61. #include "WmWrkspace.h"
  62. #include "WmWinList.h"
  63. #include "WmPresence.h"
  64. #include "WmXSMP.h"
  65. #include "WmMultiHead.h"
  66. static void AdjustSlideOutGeometry (ClientData *pCD);
  67. static void FixSubpanelEmbeddedClientGeometry (ClientData *pCD);
  68. #ifndef NO_MESSAGE_CATALOG
  69. # define LOCALE_MSG GETMESSAGE(70, 7, "[XmbTextPropertyToTextList]:\n Locale (%.100s) not supported. (Check $LANG).")
  70. #else
  71. # define LOCALE_MSG "[XmbTextPropertyToTextList]:\n Locale (%.100s) not supported. (Check $LANG)."
  72. #endif
  73. /*
  74. * Global Variables:
  75. */
  76. WmWorkspaceData *pIconBoxInitialWS;
  77. /*************************************<->*************************************
  78. *
  79. * GetClientInfo (pSD, clientWindow, manageFlags)
  80. *
  81. *
  82. * Description:
  83. * -----------
  84. * This function is used to initialize client window data based on the
  85. * contents of client window properties and the client window configuration.
  86. *
  87. *
  88. * Inputs:
  89. * ------
  90. * pSD = pointer to screen data for screen that client lives in
  91. *
  92. * clientWindow = window id for the client window that is to be managed
  93. *
  94. * manageFlags = flags that indicate wm state info
  95. *
  96. *
  97. * Outputs:
  98. * -------
  99. * Return = pointer to an initialized client data structure for the
  100. * specified client window
  101. *
  102. *************************************<->***********************************/
  103. ClientData *
  104. GetClientInfo (WmScreenData *pSD, Window clientWindow, long manageFlags)
  105. {
  106. ClientData *pCD;
  107. XSetWindowAttributes sAttributes;
  108. /*
  109. * Allocate and initialize a client data structure:
  110. */
  111. if (!(pCD = (ClientData *)XtMalloc (sizeof (ClientData))))
  112. {
  113. /* unable to allocate space */
  114. Warning (((char *)GETMESSAGE(70, 1, "Insufficient memory for client data")));
  115. return (NULL);
  116. }
  117. /*
  118. * Initialize the data structure:
  119. */
  120. pCD->client = clientWindow;
  121. pCD->clientID = ++(pSD->clientCounter);
  122. pCD->clientFlags = WM_INITIALIZATION;
  123. pCD->iconFlags = 0;
  124. pCD->thisIconBox = NULL;
  125. pCD->pECD = NULL;
  126. pCD->pPRCD = NULL;
  127. pCD->pSOR = NULL;
  128. pCD->wmUnmapCount = 0;
  129. pCD->transientFor = (Window)0L;
  130. pCD->transientLeader = NULL;
  131. pCD->transientChildren = NULL;
  132. pCD->transientSiblings = NULL;
  133. pCD->primaryStackPosition = 0;
  134. pCD->fullModalCount = 0;
  135. pCD->primaryModalCount = 0;
  136. pCD->focusPriority = 0;
  137. pCD->focusAutoRaiseDisabled = False;
  138. pCD->focusAutoRaiseDisablePending = False;
  139. pCD->clientClass = NULL;
  140. pCD->clientName = NULL;
  141. pCD->clientFrameWin = (Window)0L;
  142. pCD->iconWindow = (Window)0L;
  143. pCD->iconPixmap = (Pixmap)0L;
  144. pCD->clientProtocols = NULL;
  145. pCD->clientProtocolCount = 0;
  146. pCD->mwmMessages = NULL;
  147. pCD->mwmMessagesCount = 0;
  148. pCD->clientCmapCount = 0;
  149. pCD->clientCmapIndex = 0;
  150. pCD->clientCmapFlagsInitialized = FALSE;
  151. pCD->systemMenuSpec = NULL;
  152. pCD->putInAll = False;
  153. pCD->pWorkspaceHints = NULL;
  154. pCD->numInhabited = 0;
  155. pCD->pWsList = NULL;
  156. pCD->dtwmFunctions = DtWM_FUNCTION_OCCUPY_WS;
  157. pCD->dtwmBehaviors = 0L;
  158. pCD->paInitialProperties = NULL;
  159. pCD->numInitialProperties = 0;
  160. pCD->decorFlags = 0L;
  161. pCD->pTitleGadgets = NULL;
  162. pCD->cTitleGadgets = 0;
  163. pCD->pResizeGadgets = NULL;
  164. pCD->clientTitleWin = (Window)0L;
  165. pCD->pclientTopShadows = NULL;
  166. pCD->pclientBottomShadows = NULL;
  167. pCD->pclientTitleTopShadows = NULL;
  168. pCD->pclientTitleBottomShadows = NULL;
  169. pCD->pclientMatteTopShadows = NULL;
  170. pCD->pclientMatteBottomShadows = NULL;
  171. pCD->piconTopShadows = NULL;
  172. pCD->piconBottomShadows = NULL;
  173. pCD->internalBevel = (wmGD.frameStyle == WmSLAB) ? 0 :
  174. FRAME_INTERNAL_SHADOW_WIDTH;
  175. pCD->bPseudoTransient = False;
  176. pCD->maxWidth = pCD->maxWidthLimit = BIGSIZE;
  177. pCD->maxHeight = pCD->maxHeightLimit = BIGSIZE;
  178. pCD->maxConfig = FALSE;
  179. pCD->pSD = pSD;
  180. pCD->dataType = CLIENT_DATA_TYPE;
  181. pCD->window_status = 0L;
  182. pCD->clientEntry.nextSibling = NULL;
  183. pCD->clientEntry.prevSibling = NULL;
  184. pCD->clientEntry.pCD = NULL;
  185. pCD->smClientID = (String)NULL;
  186. /*
  187. * Do special processing for client windows that are controlled by
  188. * the window manager.
  189. */
  190. if (manageFlags & MANAGEW_WM_CLIENTS)
  191. {
  192. WmWorkspaceData *pWS;
  193. if (manageFlags & MANAGEW_ICON_BOX)
  194. {
  195. pWS = pIconBoxInitialWS;
  196. }
  197. else
  198. {
  199. pWS = pSD->pActiveWS;
  200. }
  201. return (GetWmClientInfo (pWS, pCD, manageFlags));
  202. }
  203. /*
  204. * Register the client window to facilitate event handling:
  205. */
  206. XSaveContext (DISPLAY, clientWindow, wmGD.windowContextType, (caddr_t)pCD);
  207. /*
  208. * Listen for property change events on the window so that we keep
  209. * in sync with the hints.
  210. */
  211. sAttributes.event_mask = (PropertyChangeMask | ColormapChangeMask);
  212. XChangeWindowAttributes (DISPLAY, pCD->client, CWEventMask,
  213. &sAttributes);
  214. /*
  215. * Get window configuration attributes. WmGetWindowAttributes sets
  216. * up the global window attributes cache with the client window
  217. * attributes.
  218. */
  219. if (!WmGetWindowAttributes (clientWindow))
  220. {
  221. /*
  222. * Cannot get window attributes. Do not manage window.
  223. * (error message within WmGetWindowAttributes)
  224. */
  225. UnManageWindow (pCD);
  226. return (NULL);
  227. }
  228. pCD->xBorderWidth = wmGD.windowAttributes.border_width;
  229. /*
  230. * Get the initial list of properties on this window.
  231. * Save it to optimize subsequent property fetching.
  232. */
  233. GetInitialPropertyList (pCD);
  234. /*
  235. * Retrieve and process WM_CLASS hints client window property info:
  236. */
  237. ProcessWmClass (pCD);
  238. /*
  239. * Retrieve and process WM_TRANSIENT_FOR client window property info:
  240. */
  241. ProcessWmTransientFor (pCD);
  242. /*
  243. * Get client window resource data (from resources, .mwmrc):
  244. * Moved prior to GetClientWorkspaceInfo() because the
  245. * ignoreWMSaveHints resource may affect that function.
  246. */
  247. ProcessClientResources (pCD);
  248. /*
  249. * Retreive and process SM_CLIENT_ID client window property info
  250. * and WMSAVE_HINT client window property info:
  251. * must be done prior to calling GetClientWorkspaceInfo().
  252. */
  253. ProcessSmClientID (pCD);
  254. ProcessWmSaveHint (pCD);
  255. /*
  256. * Set client's workspace information. NOTE: this also may
  257. * set the geometry, initial state, etc. For Sm-aware clients,
  258. * this info will be in private DB; for older clients, it will
  259. * be contained in the screen's pDtSessionItems.
  260. */
  261. if (!GetClientWorkspaceInfo (pCD, manageFlags))
  262. {
  263. XtFree ((char *)pCD);
  264. return (NULL);
  265. }
  266. /*
  267. * Restore client's per-workspace icon information.
  268. */
  269. LoadClientIconPositions(pCD);
  270. /*
  271. * Retrieve and process _DT_WM_HINTS client window property
  272. * (results are used in ProcessMwmHints)
  273. */
  274. ProcessDtWmHints (pCD);
  275. /*
  276. * Retrieve and process M_CLIENT_DECOR client window property info:
  277. */
  278. ProcessMwmHints (pCD);
  279. /*
  280. * Retrieve and process WM_HINTS client window property info:
  281. */
  282. ProcessWmHints (pCD, True /*first time*/);
  283. /*
  284. * Set offset from frame of client window
  285. */
  286. SetClientOffset (pCD);
  287. /*
  288. * Retrieve and process WM_NORMAL_HINTS client window property info:
  289. *
  290. */
  291. ProcessWmNormalHints (pCD, True /*first time*/, manageFlags);
  292. /*
  293. * Retrieve and process WM_NAME client window property info (this
  294. * property contains the window title NOT the window resource name):
  295. */
  296. ProcessWmWindowTitle (pCD, TRUE);
  297. /*
  298. * Retrieve and process WM_ICON_NAME client window property info:
  299. */
  300. ProcessWmIconTitle (pCD, TRUE);
  301. /*
  302. * Retrieve and process the WM_PROTOCOLS property.
  303. */
  304. ProcessWmProtocols (pCD);
  305. /*
  306. * If necessary retrieve and process the _MWM_MESSAGES property.
  307. */
  308. if (pCD->protocolFlags & PROTOCOL_MWM_MESSAGES)
  309. {
  310. ProcessMwmMessages (pCD);
  311. }
  312. /*
  313. * Make or find a system menu for the client.
  314. */
  315. if (pCD->systemMenu)
  316. {
  317. MakeSystemMenu (pCD);
  318. }
  319. else
  320. {
  321. pCD->systemMenuSpec = NULL;
  322. }
  323. /*
  324. * Setup the colormap data for the client window. This includes
  325. * retrieving and processing client window properties that deal with
  326. * subwindow colormaps.
  327. */
  328. InitCColormapData (pCD);
  329. /* successful return */
  330. return (pCD);
  331. } /* END OF FUNCTION GetClientInfo */
  332. /*************************************<->*************************************
  333. *
  334. * GetWmClientInfo (pWS, pCD, manageFlags)
  335. *
  336. *
  337. * Description:
  338. * -----------
  339. * This function is used to initialize client window data for a window
  340. * that is controlled by the window manager (e.g., the icon box). The
  341. * client window may get made in the process.
  342. *
  343. *
  344. * Inputs:
  345. * ------
  346. * pWS = pointer to workspace data
  347. *
  348. * pCD = pointer to client window data structure
  349. *
  350. * manageFlags = flags that indicate wm state info
  351. *
  352. *
  353. * Outputs:
  354. * -------
  355. * Return = pointer to an initialized client data structure or NULL
  356. * if the client data could not be initialized
  357. *
  358. *************************************<->***********************************/
  359. ClientData *
  360. GetWmClientInfo (WmWorkspaceData *pWS,
  361. ClientData * pCD,
  362. long manageFlags)
  363. {
  364. Pixmap iconBitmap;
  365. int i;
  366. /*
  367. * Set up the client class and name for resource retrieval.
  368. * Get client specific resource data (from resources, .mwmrc).
  369. */
  370. if (manageFlags & MANAGEW_ICON_BOX)
  371. {
  372. SetIconBoxInfo (pWS, pCD);
  373. }
  374. else if (manageFlags & MANAGEW_CONFIRM_BOX)
  375. {
  376. pCD->clientClass = WmCConfirmbox;
  377. pCD->clientName = WmNconfirmbox;
  378. pCD->iconImage = NULL;
  379. pCD->useClientIcon = False;
  380. pCD->focusAutoRaise = True;
  381. pCD->internalBevel = (wmGD.frameStyle == WmSLAB) ? 0 :
  382. FRAME_INTERNAL_SHADOW_WIDTH;
  383. pCD->matteWidth = 0;
  384. pCD->maximumClientSize.width = 0;
  385. pCD->maximumClientSize.height = 0;
  386. pCD->systemMenu = NULL;
  387. }
  388. /*
  389. * Set up transient for data.
  390. */
  391. if (manageFlags & MANAGEW_ICON_BOX)
  392. {
  393. }
  394. /*
  395. * Set up WM_HINTS type information.
  396. */
  397. pCD->inputFocusModel = True;
  398. pCD->clientState = NORMAL_STATE;
  399. if (ICON_DECORATION(pCD) & ICON_IMAGE_PART)
  400. {
  401. if (manageFlags & MANAGEW_ICON_BOX)
  402. {
  403. pCD->clientFlags |= ICON_BOX;
  404. }
  405. if (!pCD->useClientIcon && pCD->iconImage)
  406. {
  407. /*
  408. * Make a client supplied icon image.
  409. * Do not use the default icon image if iconImage is not found.
  410. */
  411. pCD->iconPixmap = MakeNamedIconPixmap (pCD, pCD->iconImage);
  412. }
  413. if (!pCD->iconPixmap)
  414. {
  415. /*
  416. * Use a built-in icon image for the window manager client.
  417. * The image may differ from the default icon image, depending on
  418. * the particular client (eg the iconbox).
  419. */
  420. if (manageFlags & MANAGEW_ICON_BOX)
  421. {
  422. /*
  423. * Make a default iconBox icon image.
  424. */
  425. iconBitmap = XCreateBitmapFromData (DISPLAY,
  426. ROOT_FOR_CLIENT(pCD), (char *)iconBox_bits,
  427. iconBox_width, iconBox_height);
  428. pCD->iconPixmap = MakeIconPixmap (pCD,
  429. iconBitmap, (Pixmap)0L,
  430. iconBox_width, iconBox_height, 1);
  431. }
  432. }
  433. }
  434. /*
  435. * Allocate initial workspace ID list
  436. * fill with NULL IDs
  437. */
  438. if ((pCD->pWsList = (WsClientData *)
  439. XtMalloc(pCD->pSD->numWorkspaces * sizeof(WsClientData))) == NULL)
  440. {
  441. Warning (((char *)GETMESSAGE(70, 2, "Insufficient memory for client data")));
  442. return (NULL);
  443. }
  444. pCD->sizeWsList = pCD->pSD->numWorkspaces;
  445. for (i = 0; i < pCD->pSD->numWorkspaces; i++)
  446. {
  447. pCD->pWsList[i].wsID = 0L;
  448. pCD->pWsList[i].iconPlace = NO_ICON_PLACE;
  449. pCD->pWsList[i].iconX = 0;
  450. pCD->pWsList[i].iconY = 0;
  451. pCD->pWsList[i].iconFrameWin = (Window)0L;
  452. pCD->pWsList[i].pIconBox = NULL;
  453. }
  454. /*
  455. * Internally managed clients must be specifically inserted
  456. * into workspaces the first time by calling
  457. * PutClientIntoWorkspace.
  458. */
  459. pCD->numInhabited = 0;
  460. pCD->windowGroup = 0L;
  461. pCD->bPseudoTransient = False;
  462. /*
  463. * Set up _MWM_HINTS data.
  464. */
  465. /*
  466. * Fix the client functions and decorations fields if they have
  467. * default resource values.
  468. */
  469. if (manageFlags & MANAGEW_CONFIRM_BOX)
  470. {
  471. pCD->clientFunctions = WM_FUNC_NONE;
  472. pCD->clientDecoration = WM_DECOR_BORDER;
  473. }
  474. else
  475. {
  476. if (pCD->clientFunctions & WM_FUNC_DEFAULT)
  477. {
  478. pCD->clientFunctions = WM_FUNC_ALL;
  479. }
  480. if (pCD->clientDecoration & WM_DECOR_DEFAULT)
  481. {
  482. pCD->clientDecoration = WM_DECOR_ALL;
  483. }
  484. if (manageFlags & MANAGEW_ICON_BOX)
  485. {
  486. pCD->clientFunctions &= ICON_BOX_FUNCTIONS;
  487. pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
  488. if (wmGD.useFrontPanel && pCD->pSD->iconBoxControl)
  489. {
  490. /*
  491. * If there's a front panel button for the icon
  492. * box, then use it to "hide" the box on "close"
  493. */
  494. pCD->clientFunctions &= ~MWM_FUNC_MINIMIZE;
  495. pCD->clientFunctions |= MWM_FUNC_CLOSE;
  496. }
  497. }
  498. if (!(pCD->clientFunctions & MWM_FUNC_RESIZE))
  499. {
  500. pCD->clientDecoration &= ~MWM_DECOR_RESIZEH;
  501. }
  502. if (!(pCD->clientFunctions & MWM_FUNC_MINIMIZE))
  503. {
  504. pCD->clientDecoration &= ~MWM_DECOR_MINIMIZE;
  505. }
  506. if (!(pCD->clientFunctions & MWM_FUNC_MAXIMIZE))
  507. {
  508. pCD->clientDecoration &= ~MWM_DECOR_MAXIMIZE;
  509. }
  510. }
  511. pCD->decor = pCD->clientDecoration;
  512. if (manageFlags & MANAGEW_ICON_BOX)
  513. {
  514. pCD->inputMode = MWM_INPUT_MODELESS;
  515. }
  516. else if (manageFlags & MANAGEW_CONFIRM_BOX)
  517. {
  518. pCD->inputMode = MWM_INPUT_SYSTEM_MODAL;
  519. }
  520. /*
  521. * Set up WM_NORMAL_HINTS data.
  522. */
  523. pCD->icccVersion = ICCC_CURRENT;
  524. pCD->sizeFlags = US_POSITION | US_SIZE;
  525. /*
  526. * Any calls to create Window Manager clients should
  527. * return with the values for the following fields set.
  528. * If it fails, it should free any space allocated and
  529. * set pCD = NULL
  530. *
  531. * pCD->clientX =
  532. * pCD->clientY =
  533. * pCD->clientWidth =
  534. * pCD->clientHeight =
  535. * pCD->minWidth =
  536. * pCD->minHeight =
  537. * pCD->widthInc =
  538. * pCD->heightInc =
  539. * pCD->baseWidth =
  540. * pCD->baseHeight =
  541. * pCD->maxWidth =
  542. * pCD->maxHeight =
  543. * pCD->oldMaxWidth =
  544. * pCD->oldMaxHeight =
  545. *
  546. * AND PROBABLY SHOULD SET
  547. * pCD->client = THE_WINDOW_THE_FUNCTION_CREATES
  548. */
  549. pCD->windowGravity = NorthWestGravity;
  550. /*
  551. * Create IconBox window
  552. */
  553. if (manageFlags & MANAGEW_ICON_BOX)
  554. {
  555. if (!MakeIconBox (pWS, pCD))
  556. {
  557. /*
  558. * May want a more verbose message here
  559. */
  560. Warning (((char *)GETMESSAGE(70, 3, "Couldn't make icon box")));
  561. return (NULL);
  562. }
  563. PutClientIntoWorkspace (pWS, pCD);
  564. }
  565. else if (manageFlags & MANAGEW_CONFIRM_BOX)
  566. {
  567. Window root;
  568. unsigned int cbWidth, cbHeight;
  569. unsigned int depth;
  570. XGetGeometry (DISPLAY, pCD->client, &root,
  571. &(pCD->clientX), &(pCD->clientY),
  572. &cbWidth, &cbHeight,
  573. (unsigned int*)&(pCD->xBorderWidth), &depth);
  574. pCD->clientWidth = cbWidth;
  575. pCD->clientHeight = cbHeight;
  576. pCD->minWidth = pCD->baseWidth = pCD->maxWidth = pCD->clientWidth;
  577. pCD->minHeight = pCD->baseHeight = pCD->maxHeight = pCD->clientHeight;
  578. pCD->oldMaxWidth = pCD->maxWidth;
  579. pCD->oldMaxHeight = pCD->maxHeight;
  580. pCD->widthInc = 1;
  581. pCD->heightInc = 1;
  582. pCD->clientFlags |= CONFIRM_BOX;
  583. PutClientIntoWorkspace (ACTIVE_WS, pCD);
  584. }
  585. /*
  586. * Set offset from frame of client window (need client size information).
  587. */
  588. SetFrameInfo (pCD);
  589. /*
  590. * Register the client window to facilitate event handling.
  591. */
  592. XSaveContext (DISPLAY, pCD->client, wmGD.windowContextType, (caddr_t)pCD);
  593. /*
  594. * Set up WM_PROTOCOLS data.
  595. */
  596. pCD->clientProtocolCount = 0;
  597. pCD->protocolFlags = 0;
  598. /*
  599. * Make the system menu.
  600. */
  601. if (manageFlags & MANAGEW_ICON_BOX)
  602. {
  603. pCD->systemMenuSpec =
  604. MAKE_MENU (PSD_FOR_CLIENT(pCD), pCD, pCD->systemMenu,
  605. F_CONTEXT_WINDOW, F_CONTEXT_WINDOW|F_CONTEXT_ICON,
  606. GetIconBoxMenuItems(PSD_FOR_CLIENT(pCD)),
  607. TRUE);
  608. }
  609. /*
  610. * Setup the colormap data.
  611. */
  612. pCD->clientColormap = PSD_FOR_CLIENT(pCD)->workspaceColormap;
  613. /*
  614. * Return the pointer to the client data.
  615. */
  616. return (pCD);
  617. } /* END OF FUNCTION GetWmClientInfo */
  618. /*************************************<->*************************************
  619. *
  620. * ProcessWmClass (pCD)
  621. *
  622. *
  623. * Description:
  624. * -----------
  625. * This function retrieves the contents of the WM_CLASS property on the
  626. * cient window. The resource class and the resource name are saved in
  627. * the ClientData structure (note that the space for the strings is
  628. * allocated using Xmalloc).
  629. *
  630. *
  631. * Inputs:
  632. * ------
  633. * pCD - pointer to client data
  634. *
  635. *
  636. * Outputs:
  637. * -------
  638. *
  639. * Comments:
  640. * --------
  641. *
  642. *************************************<->***********************************/
  643. void
  644. ProcessWmClass (ClientData *pCD)
  645. {
  646. XClassHint classHint;
  647. if ((HasProperty (pCD, XA_WM_CLASS)) &&
  648. (XGetClassHint (DISPLAY, pCD->client, &classHint)))
  649. {
  650. /* the WM_CLASS property exists for the client window */
  651. pCD->clientClass = classHint.res_class;
  652. pCD->clientName = classHint.res_name;
  653. }
  654. /* else no WM_CLASS property; assume clientClass, clientName are NULL */
  655. } /* END OF FUNCTION ProcessWmClass */
  656. /*************************************<->*************************************
  657. *
  658. * ProcessSmClientID (pCD)
  659. *
  660. *
  661. * Description:
  662. * -----------
  663. * This function retrieves the contents of the SM_CLIENT_ID property on the
  664. * cient window. The value is saved in the ClientData structure
  665. * (note that the space for the strings is allocated using Xmalloc).
  666. *
  667. *
  668. * Inputs:
  669. * ------
  670. * pCD - pointer to client data
  671. *
  672. *
  673. * Outputs:
  674. * -------
  675. *
  676. * Comments:
  677. * --------
  678. *
  679. *************************************<->***********************************/
  680. void
  681. ProcessSmClientID (ClientData *pCD)
  682. {
  683. Atom actualType;
  684. int actualFormat;
  685. unsigned long nitems, leftover;
  686. char *clientID;
  687. if (pCD->smClientID != (String)NULL)
  688. {
  689. XFree(pCD->smClientID);
  690. pCD->smClientID = (String)NULL;
  691. }
  692. if ((XGetWindowProperty(DISPLAY, pCD->client, wmGD.xa_SM_CLIENT_ID,
  693. 0L, (long)1000000, False, AnyPropertyType,
  694. &actualType, &actualFormat, &nitems,
  695. &leftover, (unsigned char **)&clientID)
  696. == Success) &&
  697. (actualType != None) && (actualFormat == 8))
  698. {
  699. /* the SM_CLIENT_ID property exists for the client window */
  700. pCD->smClientID = clientID;
  701. }
  702. } /* END OF FUNCTION ProcessSmClientID */
  703. /*************************************<->*************************************
  704. *
  705. * ProcessWmSaveHint (pCD)
  706. *
  707. *
  708. * Description:
  709. * -----------
  710. * This function retrieves the contents of the WMSAVE_HINT property on the
  711. * cient window. The value is saved in the ClientData structure.
  712. *
  713. *
  714. * Inputs:
  715. * ------
  716. * pCD - pointer to client data
  717. *
  718. *
  719. * Outputs:
  720. * -------
  721. *
  722. * Comments:
  723. * --------
  724. *
  725. *************************************<->***********************************/
  726. void
  727. ProcessWmSaveHint (ClientData *pCD)
  728. {
  729. Atom actualType;
  730. int actualFormat;
  731. unsigned long nitems, leftover;
  732. BITS32 *saveHintFlags = (BITS32 *)NULL;
  733. if ((XGetWindowProperty(DISPLAY, pCD->client, wmGD.xa_WMSAVE_HINT,
  734. 0L, (long)1000000, False, AnyPropertyType,
  735. &actualType, &actualFormat, &nitems,
  736. &leftover, (unsigned char **)&saveHintFlags)
  737. == Success) &&
  738. (actualType != None) && (actualFormat == 32))
  739. {
  740. /* the WMSAVE_HINT property exists for the client window */
  741. pCD->wmSaveHintFlags = (int)*saveHintFlags;
  742. }
  743. else pCD->wmSaveHintFlags = 0;
  744. if (saveHintFlags)
  745. XFree(saveHintFlags);
  746. } /* END OF FUNCTION ProcessWmSaveHint */
  747. /*************************************<->*************************************
  748. *
  749. * ProcessWmHints (pCD, firstTime)
  750. *
  751. *
  752. * Description:
  753. * -----------
  754. * This function retrieves the contents of the WM_HINTS property on the
  755. * cient window.
  756. *
  757. *
  758. * Inputs:
  759. * ------
  760. * pCD = pointer to client data for the window with the property
  761. *
  762. * firstTime = if True this is the first time the property has been processed
  763. *
  764. *
  765. * Outputs:
  766. * -------
  767. * pCD = initialize various WM_HINTS related fields
  768. *
  769. *
  770. * Comments:
  771. * --------
  772. *
  773. *************************************<->***********************************/
  774. void
  775. ProcessWmHints (ClientData *pCD, Boolean firstTime)
  776. {
  777. XWMHints *pXWMHints;
  778. long flags;
  779. Pixmap iconPixmap;
  780. Pixmap iconMask;
  781. WmWorkspaceData *pWsTmp;
  782. WsClientData *pWsc;
  783. int iws;
  784. int tmpIconX, tmpIconY;
  785. /*
  786. * If the WM_HINTS property does not exist the flags field will be
  787. * set to 0. If flags is 0 don't reference the WMHints structure
  788. * since they may be none.
  789. */
  790. if (firstTime && !HasProperty (pCD, XA_WM_HINTS))
  791. pXWMHints = NULL;
  792. else
  793. pXWMHints = XGetWMHints (DISPLAY, pCD->client);
  794. if (pXWMHints)
  795. {
  796. flags = pXWMHints->flags;
  797. }
  798. else
  799. {
  800. flags = 0;
  801. }
  802. /*
  803. * Parse the WM_HINTS information. If this is the first time the hints
  804. * have been processed then parse all fields and set defaults where hint
  805. * fields are not set. If this is not the first time do selective
  806. * parsing.
  807. */
  808. if (firstTime)
  809. {
  810. ClientData *leader;
  811. Atom *pIDs;
  812. unsigned int numIDs = 0;
  813. /*
  814. * Save the window group.
  815. */
  816. if (flags & WindowGroupHint)
  817. {
  818. pCD->windowGroup = pXWMHints->window_group;
  819. /*
  820. * Pretend this is a transient window
  821. */
  822. if ((pCD->bPseudoTransient) &&
  823. (pCD->transientFor == (Window)0L))
  824. {
  825. pCD->clientFlags |= CLIENT_TRANSIENT;
  826. /*
  827. * Treat this like a transient window. This is transient
  828. * for the window group window.
  829. */
  830. if ((pCD->client != pCD->windowGroup) &&
  831. !XFindContext (DISPLAY, pCD->windowGroup,
  832. wmGD.windowContextType, (caddr_t *)&leader))
  833. {
  834. pCD->transientFor = pCD->windowGroup;
  835. pCD->transientLeader = leader;
  836. /*
  837. * Insure it is in the same set of workspaces
  838. * as the leader.
  839. */
  840. if (pCD->transientLeader &&
  841. GetLeaderPresence(pCD, &pIDs, &numIDs))
  842. {
  843. ProcessWorkspaceHintList (pCD, pIDs, numIDs);
  844. }
  845. }
  846. }
  847. }
  848. else
  849. {
  850. pCD->windowGroup = 0L;
  851. }
  852. /*
  853. * The window manger does not do anything with the input hint. Input
  854. * always goes to the selected window.
  855. */
  856. if (flags & InputHint)
  857. {
  858. pCD->inputFocusModel = pXWMHints->input;
  859. }
  860. else
  861. {
  862. pCD->inputFocusModel = True;
  863. }
  864. /*
  865. * The default state is NORMAL_STATE. States other than iconic
  866. * (e.g., ZoomState from the R2 ICCC) indicate to the window manager
  867. * that the NORMAL_STATE is to be used.
  868. */
  869. if (pCD->clientFlags & SM_CLIENT_STATE)
  870. {
  871. if ((pCD->clientState == MINIMIZED_STATE) &&
  872. (!(pCD->clientFunctions & MWM_FUNC_MINIMIZE)))
  873. {
  874. pCD->clientState = NORMAL_STATE;
  875. }
  876. }
  877. else
  878. if ((flags & StateHint) && (pXWMHints->initial_state == IconicState) &&
  879. (pCD->clientFunctions & MWM_FUNC_MINIMIZE))
  880. {
  881. pCD->clientState = MINIMIZED_STATE;
  882. }
  883. else
  884. {
  885. /*
  886. * States other than iconic are treated as normal.
  887. */
  888. pCD->clientState = NORMAL_STATE;
  889. }
  890. if (!ClientInWorkspace (PSD_FOR_CLIENT(pCD)->pActiveWS, pCD))
  891. {
  892. pCD->clientState |= UNSEEN_STATE;
  893. }
  894. /*
  895. * If an icon is to be made for the client then ...
  896. * save the icon image if useClientIcon is True or there is no
  897. * user specified icon image. A client supplied image may be a
  898. * pixmap or a window (a client icon window takes precedence over
  899. * a pixmap).
  900. */
  901. if ((pCD->clientFunctions & MWM_FUNC_MINIMIZE) &&
  902. (pCD->transientLeader == NULL))
  903. {
  904. if ((ICON_DECORATION(pCD) & ICON_IMAGE_PART) &&
  905. (pCD->useClientIcon || !pCD->iconImage))
  906. {
  907. if ((flags & IconWindowHint) &&
  908. (pXWMHints->icon_window != pCD->client))
  909. {
  910. /*
  911. * An icon window has been supplied that is different from
  912. * the client window. Check out the window and get it
  913. * ready to be reparented to the window manager supplied
  914. * icon frame.
  915. */
  916. if (!SetupClientIconWindow (pCD, pXWMHints->icon_window))
  917. {
  918. /*
  919. * Cannot use the client supplied icon window. Use
  920. * an icon image if specified or a default image.
  921. */
  922. }
  923. }
  924. if (!pCD->iconWindow && (flags & IconPixmapHint))
  925. {
  926. iconMask = (flags & IconMaskHint) ?
  927. pXWMHints->icon_mask : (Pixmap) NULL;
  928. /*
  929. * A client supplied icon window is NOT
  930. * available so use the client supplied icon image.
  931. */
  932. if ((pCD->iconPixmap =
  933. MakeClientIconPixmap (pCD,
  934. pXWMHints->icon_pixmap, iconMask)) != None)
  935. {
  936. /*
  937. * Indicate that a client supplied icon image is being
  938. * used.
  939. */
  940. pCD->iconFlags |= ICON_HINTS_PIXMAP;
  941. }
  942. else
  943. {
  944. /*
  945. * Cannot make a client supplied image. Use a user
  946. * specified icon image if it is available or a default
  947. * icon image.
  948. */
  949. }
  950. }
  951. }
  952. if ((ICON_DECORATION(pCD) & ICON_IMAGE_PART) && !pCD->iconPixmap)
  953. {
  954. /*
  955. * Use a user supplied icon image if it is available or a
  956. * default icon image.
  957. */
  958. if (pCD->iconImage)
  959. {
  960. /*
  961. * Try to make a user specified icon image.
  962. */
  963. pCD->iconPixmap =
  964. MakeNamedIconPixmap (pCD, pCD->iconImage);
  965. }
  966. if (!pCD->iconPixmap)
  967. {
  968. /*
  969. * The icon image was not provided or not available.
  970. * Use the default icon image.
  971. */
  972. pCD->iconPixmap = MakeNamedIconPixmap (pCD, NULL);
  973. }
  974. }
  975. /*
  976. * Save the client (user?) supplied icon position:
  977. */
  978. if ((flags & IconPositionHint) ||
  979. (pCD->clientFlags & (SM_ICON_X | SM_ICON_Y)))
  980. {
  981. pCD->iconFlags |= ICON_HINTS_POSITION;
  982. if (wmGD.iconAutoPlace)
  983. {
  984. /*
  985. * Initialize icon placement data in all inhabited
  986. * workspaces
  987. */
  988. for (iws = 0; iws< pCD->numInhabited; iws++)
  989. {
  990. pWsc = &(pCD->pWsList[iws]);
  991. if ((pWsTmp=GetWorkspaceData(pCD->pSD, pWsc->wsID)))
  992. {
  993. tmpIconX = (pCD->clientFlags & SM_ICON_X) ?
  994. pWsc->iconX : pXWMHints->icon_x;
  995. tmpIconY = (pCD->clientFlags & SM_ICON_Y) ?
  996. pWsc->iconY : pXWMHints->icon_y;
  997. pWsc->iconPlace =
  998. FindIconPlace (pCD, &(pWsTmp->IPData),
  999. tmpIconX, tmpIconY);
  1000. if (pWsc->iconPlace != NO_ICON_PLACE)
  1001. {
  1002. CvtIconPlaceToPosition ( &(pWsTmp->IPData),
  1003. pWsc->iconPlace,
  1004. &pWsc->iconX,
  1005. &pWsc->iconY);
  1006. }
  1007. }
  1008. }
  1009. }
  1010. else
  1011. {
  1012. for (iws = 0; iws< pCD->numInhabited; iws++)
  1013. {
  1014. pWsc = &(pCD->pWsList[iws]);
  1015. if ((pWsTmp=GetWorkspaceData(pCD->pSD, pWsc->wsID)))
  1016. {
  1017. if (!(pCD->clientFlags & SM_ICON_X))
  1018. pWsc->iconX = pXWMHints->icon_x;
  1019. if (!(pCD->clientFlags & SM_ICON_Y))
  1020. pWsc->iconY = pXWMHints->icon_y;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. else
  1026. {
  1027. if (wmGD.iconAutoPlace)
  1028. {
  1029. /*
  1030. * Initialize icon placement data in all inhabited
  1031. * workspaces
  1032. */
  1033. for (iws = 0; iws< pCD->numInhabited; iws++)
  1034. {
  1035. pWsc = &(pCD->pWsList[iws]);
  1036. pWsc->iconPlace = NO_ICON_PLACE;
  1037. pWsc->iconX = 0;
  1038. pWsc->iconY = 0;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. else /* not the first time the hints are processed */
  1045. {
  1046. if (flags & IconPixmapHint)
  1047. {
  1048. /*
  1049. * Process an icon image change if the icon image was initially
  1050. * set up with a client supplied icon image OR, if the client
  1051. * now wants to supply an image.
  1052. */
  1053. iconMask = (flags & IconMaskHint)?
  1054. pXWMHints->icon_mask : (Pixmap) NULL;
  1055. if ((iconPixmap =
  1056. MakeClientIconPixmap (pCD, pXWMHints->icon_pixmap,
  1057. iconMask)) != None)
  1058. {
  1059. /*
  1060. * Made new icon image; free up the old image and display
  1061. * the new image.
  1062. */
  1063. if (pCD->iconFlags & ICON_HINTS_PIXMAP)
  1064. {
  1065. /*
  1066. * ICON_HINTS_PIXMAP was set either initally or
  1067. * below because a new pixmap was made for the client.
  1068. * It is now safe to free the previous pixmap since it
  1069. * is not the shared default iconPixmap
  1070. */
  1071. if (pCD->iconPixmap)
  1072. {
  1073. XFreePixmap (DISPLAY, pCD->iconPixmap);
  1074. }
  1075. }
  1076. else
  1077. {
  1078. pCD->iconFlags |= ICON_HINTS_PIXMAP;
  1079. }
  1080. pCD->iconPixmap = iconPixmap;
  1081. /*
  1082. * Display new icon image if the icon is showing:
  1083. */
  1084. if (((pCD->clientState == MINIMIZED_STATE) ||
  1085. ((pCD->pSD->useIconBox) && (P_ICON_BOX(pCD)))) &&
  1086. ICON_FRAME_WIN(pCD))
  1087. {
  1088. IconExposureProc (pCD, True);
  1089. }
  1090. }
  1091. }
  1092. }
  1093. if (pXWMHints)
  1094. {
  1095. XFree ((char*)pXWMHints);
  1096. }
  1097. } /* END OF FUNCTION ProcessWmHints */
  1098. /*************************************<->*************************************
  1099. *
  1100. * ProcessWmNormalHints (pCD, firstTime, manageFlags)
  1101. *
  1102. *
  1103. * Description:
  1104. * -----------
  1105. * This function retrieves the contents of the WM_NORMAL_HINTS property on
  1106. * the cient window. There are several versions of the property that must be
  1107. * handled (currently R2 and CURRENT).
  1108. *
  1109. *
  1110. * Inputs:
  1111. * ------
  1112. * pCD = pointer to client data for the window with the property
  1113. *
  1114. * firstTime = if True this is the first time the property has been processed
  1115. *
  1116. * manageFlags = flags that indicate wm state information
  1117. *
  1118. *
  1119. * Outputs:
  1120. * -------
  1121. * pCD = client location and size fields set
  1122. *
  1123. *
  1124. * Comments:
  1125. * --------
  1126. * If the hints are being reprocessed (!firstTime) the configuration values
  1127. * will be ignored. The size constraint values will be processed but the
  1128. * client configuration will not be changed even if it is not in line with
  1129. * the new values. Reconfigurations subsequent to the hints changes will
  1130. * be done with the new constraints.
  1131. *
  1132. *************************************<->***********************************/
  1133. void
  1134. ProcessWmNormalHints (ClientData *pCD, Boolean firstTime, long manageFlags)
  1135. {
  1136. SizeHints *pNormalHints;
  1137. long flags;
  1138. int diff;
  1139. unsigned long decoration;
  1140. unsigned int boxdim, tmpMin;
  1141. unsigned int oldWidthInc, oldHeightInc;
  1142. unsigned int oldBaseWidth, oldBaseHeight;
  1143. unsigned int incWidth, incHeight;
  1144. /*
  1145. * Use a custom verion of the Xlib routine to get WM_NORMAL_HINTS.
  1146. * A custom version is necessary to handle the different versions
  1147. * of WM_NORMAL_HINTS that may be encountered. If the WM_NORMAL_HINTS
  1148. * property does not exist the flags field will be set to 0.
  1149. */
  1150. pNormalHints = GetNormalHints (pCD);
  1151. pCD->icccVersion = pNormalHints->icccVersion;
  1152. /*
  1153. * Parse the WM_NORMAL_HINTS information:
  1154. */
  1155. if (((flags = pNormalHints->flags) == 0) && !firstTime)
  1156. {
  1157. return;
  1158. }
  1159. /*
  1160. * Process the size only if this is the first time the hints are
  1161. * being processed for the window.
  1162. */
  1163. if (firstTime)
  1164. {
  1165. /*
  1166. * Process client window size flags and information:
  1167. */
  1168. pCD->sizeFlags = flags & (US_POSITION | US_SIZE | P_POSITION | P_SIZE);
  1169. /*
  1170. * The R2 conventions and Xlib manual indicate that the window size
  1171. * and position should be taken out of the WM_NORMAL_HINTS property
  1172. * if they are specified there. The current conventions indicate that
  1173. * the size and position information should be gotten from the window
  1174. * configuration. Mwm 1.1 always uses the current conventions.
  1175. */
  1176. #ifdef R2_COMPAT
  1177. /*
  1178. * Maintain R2 compatiblity code for CND product xnm
  1179. */
  1180. if ((pNormalHints->icccVersion == ICCC_R2) &&
  1181. (flags & (US_POSITION | P_POSITION)) &&
  1182. !(manageFlags & MANAGEW_WM_RESTART))
  1183. {
  1184. if (!(pCD->clientFlags & SM_X))
  1185. pCD->clientX = pNormalHints->x;
  1186. if (!(pCD->clientFlags & SM_Y))
  1187. pCD->clientY = pNormalHints->y;
  1188. }
  1189. else
  1190. {
  1191. if (!(pCD->clientFlags & SM_X))
  1192. pCD->clientX = wmGD.windowAttributes.x;
  1193. if (!(pCD->clientFlags & SM_Y))
  1194. pCD->clientY = wmGD.windowAttributes.y;
  1195. }
  1196. #else /* R2_COMPAT */
  1197. if (!(pCD->clientFlags & SM_X))
  1198. pCD->clientX = wmGD.windowAttributes.x;
  1199. if (!(pCD->clientFlags & SM_Y))
  1200. pCD->clientY = wmGD.windowAttributes.y;
  1201. #endif /* R2_COMPAT */
  1202. /*
  1203. * Use current conventions for initial window dimensions.
  1204. */
  1205. #ifdef R2_COMPAT
  1206. /*
  1207. * Maintain R2 compatiblity code for CND product xnm
  1208. */
  1209. if ((pNormalHints->icccVersion == ICCC_R2) &&
  1210. (flags & (US_SIZE | P_SIZE)) &&
  1211. !(manageFlags & MANAGEW_WM_RESTART))
  1212. {
  1213. if (!(pCD->clientFlags & SM_WIDTH))
  1214. pCD->clientWidth = pNormalHints->width;
  1215. if (!(pCD->clientFlags & SM_HEIGHT))
  1216. pCD->clientHeight = pNormalHints->height;
  1217. }
  1218. else
  1219. {
  1220. if (!(pCD->clientFlags & SM_WIDTH))
  1221. pCD->clientWidth = wmGD.windowAttributes.width;
  1222. if (!(pCD->clientFlags & SM_HEIGHT))
  1223. pCD->clientHeight = wmGD.windowAttributes.height;
  1224. }
  1225. #else /* R2_COMPAT */
  1226. if (!(pCD->clientFlags & SM_WIDTH))
  1227. pCD->clientWidth = wmGD.windowAttributes.width;
  1228. if (!(pCD->clientFlags & SM_HEIGHT))
  1229. pCD->clientHeight = wmGD.windowAttributes.height;
  1230. #endif /* R2_COMPAT */
  1231. }
  1232. /*
  1233. * Process the minimum size:
  1234. */
  1235. if (flags & P_MIN_SIZE)
  1236. {
  1237. pCD->minWidth =
  1238. (pNormalHints->min_width < 0) ? 0 : pNormalHints->min_width;
  1239. pCD->minHeight =
  1240. (pNormalHints->min_height < 0) ? 0 : pNormalHints->min_height;
  1241. if (pCD->minWidth > MAX_MAX_SIZE(pCD).width)
  1242. {
  1243. pCD->minWidth = MAX_MAX_SIZE(pCD).width;
  1244. }
  1245. if (pCD->minHeight > MAX_MAX_SIZE(pCD).height)
  1246. {
  1247. pCD->minHeight = MAX_MAX_SIZE(pCD).height;
  1248. }
  1249. }
  1250. else if (firstTime)
  1251. {
  1252. pCD->minWidth = 0;
  1253. pCD->minHeight = 0;
  1254. }
  1255. /*
  1256. * Process the resizing increments:
  1257. */
  1258. if (!firstTime)
  1259. {
  1260. oldWidthInc = (pCD->widthInc == 0) ? 1 : pCD->widthInc;
  1261. oldHeightInc = (pCD->heightInc == 0) ? 1 : pCD->heightInc;
  1262. }
  1263. if (flags & P_RESIZE_INC)
  1264. {
  1265. pCD->widthInc =
  1266. (pNormalHints->width_inc < 1) ? 1 : pNormalHints->width_inc;
  1267. pCD->heightInc =
  1268. (pNormalHints->height_inc < 1) ? 1 : pNormalHints->height_inc;
  1269. }
  1270. else if (firstTime)
  1271. {
  1272. pCD->widthInc = 1;
  1273. pCD->heightInc = 1;
  1274. }
  1275. /*
  1276. * Process the base size:
  1277. */
  1278. if (!firstTime)
  1279. {
  1280. oldBaseWidth = pCD->baseWidth;
  1281. oldBaseHeight = pCD->baseHeight;
  1282. }
  1283. if (flags & P_BASE_SIZE)
  1284. {
  1285. pCD->baseWidth =
  1286. (pNormalHints->base_width < 0) ? 0 : pNormalHints->base_width;
  1287. pCD->baseHeight =
  1288. (pNormalHints->base_height < 0) ? 0 : pNormalHints->base_height;
  1289. }
  1290. else if ((pNormalHints->icccVersion == ICCC_R2) &&
  1291. ((firstTime) ||
  1292. (!firstTime && (flags & P_MIN_SIZE))))
  1293. {
  1294. /*
  1295. * In this version of the hints the minimum size was effectively
  1296. * the base size.
  1297. */
  1298. pCD->baseWidth = pCD->minWidth;
  1299. pCD->baseHeight = pCD->minHeight;
  1300. }
  1301. else if (firstTime)
  1302. {
  1303. if (flags & P_MIN_SIZE)
  1304. {
  1305. pCD->baseWidth = pCD->minWidth;
  1306. pCD->baseHeight = pCD->minHeight;
  1307. }
  1308. else
  1309. {
  1310. pCD->baseWidth = 0;
  1311. pCD->baseHeight = 0;
  1312. }
  1313. }
  1314. if (firstTime)
  1315. {
  1316. if (pCD->clientFlags & SM_WIDTH)
  1317. {
  1318. pCD->clientWidth = ((pCD->clientWidth * pCD->widthInc) +
  1319. pCD->baseWidth);
  1320. }
  1321. if (pCD->clientFlags & SM_HEIGHT)
  1322. {
  1323. pCD->clientHeight =((pCD->clientHeight * pCD->heightInc) +
  1324. pCD->baseHeight);
  1325. }
  1326. }
  1327. /*
  1328. * Process the maximum width. NOTE: maximumClientSize.width
  1329. * and maximumClientSize.height will be set to BIGSIZE if
  1330. * maximumClientSize is either set to 'horizontal' or 'vertical'.
  1331. */
  1332. pCD->oldMaxWidth = pCD->maxWidth;
  1333. if (pCD->maximumClientSize.width)
  1334. {
  1335. /* If maximumClientSize is full 'horizontal' */
  1336. if (IS_MAXIMIZE_HORIZONTAL(pCD))
  1337. {
  1338. /* go to min (full screen width, max maximum width) */
  1339. pCD->maxWidth = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1340. (2 * pCD->clientOffset.x);
  1341. /*
  1342. * Hack to set max client to the current client height, maxHeight
  1343. * will be kept up to date whenever the window is reconfigured
  1344. */
  1345. pCD->maxHeight = pCD->clientHeight;
  1346. }
  1347. else
  1348. {
  1349. pCD->maxWidth = (pCD->maximumClientSize.width *
  1350. pCD->widthInc) + pCD->baseWidth;
  1351. }
  1352. }
  1353. else
  1354. {
  1355. if (flags & P_MAX_SIZE)
  1356. {
  1357. if (pNormalHints->max_width < 0)
  1358. {
  1359. /* go to min (full screen width, max maximum width) */
  1360. pCD->maxWidth = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1361. (2 * pCD->clientOffset.x);
  1362. }
  1363. else
  1364. {
  1365. pCD->maxWidth = pNormalHints->max_width;
  1366. }
  1367. }
  1368. /* Don't reset maxWidth if it has been set earlier */
  1369. else if (!IS_MAXIMIZE_VERTICAL(pCD))
  1370. {
  1371. if (firstTime)
  1372. {
  1373. /* go to min (full screen width, max maximum width) */
  1374. pCD->maxWidth = DisplayWidth (DISPLAY,
  1375. SCREEN_FOR_CLIENT(pCD)) -
  1376. (2 * pCD->clientOffset.x);
  1377. }
  1378. else
  1379. {
  1380. /* reset the maxHeight before further processing */
  1381. pCD->maxWidth = pCD->maxWidthLimit;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. /*
  1387. * If the hints changed we need to adjust the maximum
  1388. * size (if not specified in the hints).
  1389. */
  1390. if (!firstTime &&
  1391. ((oldBaseWidth != pCD->baseWidth) ||
  1392. (oldWidthInc != pCD->widthInc)))
  1393. {
  1394. incWidth = (pCD->maxWidth - oldBaseWidth) / oldWidthInc;
  1395. pCD->maxWidth =
  1396. (incWidth * pCD->widthInc) + pCD->baseWidth;
  1397. }
  1398. else
  1399. {
  1400. /* reset the maxHeight before further processing */
  1401. pCD->maxWidth = pCD->maxWidthLimit;
  1402. }
  1403. }
  1404. if (pCD->maxWidth > MAX_MAX_SIZE(pCD).width)
  1405. {
  1406. pCD->maxWidth = MAX_MAX_SIZE(pCD).width;
  1407. }
  1408. }
  1409. /*
  1410. * Process the maximum height.
  1411. */
  1412. pCD->oldMaxHeight = pCD->maxHeight;
  1413. if (pCD->maximumClientSize.height)
  1414. {
  1415. /* If maximumClientSize is full 'vertical' */
  1416. if (IS_MAXIMIZE_VERTICAL(pCD))
  1417. {
  1418. /* go to min (full screen height, max maximum height) */
  1419. pCD->maxHeight = DisplayHeight (DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1420. (pCD->clientOffset.x +
  1421. pCD->clientOffset.y);
  1422. /*
  1423. * Hack to set max client to the current client width, maxWidth
  1424. * will be kept up to date whenever the window is reconfigured
  1425. */
  1426. pCD->maxWidth = pCD->clientWidth;
  1427. }
  1428. else
  1429. {
  1430. pCD->maxHeight = (pCD->maximumClientSize.height *
  1431. pCD->heightInc) + pCD->baseHeight;
  1432. }
  1433. }
  1434. else
  1435. {
  1436. if (flags & P_MAX_SIZE)
  1437. {
  1438. if (pNormalHints->max_height < 0)
  1439. {
  1440. /* go to min (full screen height, max maximum height) */
  1441. pCD->maxHeight = DisplayHeight (
  1442. DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1443. (pCD->clientOffset.x +
  1444. pCD->clientOffset.y);
  1445. }
  1446. else
  1447. {
  1448. pCD->maxHeight = pNormalHints->max_height;
  1449. }
  1450. }
  1451. /* Don't reset maxHeight if it has been set above */
  1452. else if (!IS_MAXIMIZE_HORIZONTAL(pCD))
  1453. {
  1454. if (firstTime)
  1455. {
  1456. /* go to min (full screen height, max maximum height) */
  1457. pCD->maxHeight = DisplayHeight (DISPLAY,
  1458. SCREEN_FOR_CLIENT(pCD)) -
  1459. (pCD->clientOffset.x +
  1460. pCD->clientOffset.y);
  1461. }
  1462. else
  1463. {
  1464. /* reset the maxHeight before further processing */
  1465. pCD->maxHeight = pCD->maxHeightLimit;
  1466. }
  1467. }
  1468. else
  1469. {
  1470. /*
  1471. * If the hints changed we need to adjust the maximum
  1472. * size (if not specified in the hints).
  1473. */
  1474. if (!firstTime &&
  1475. ((oldBaseHeight != pCD->baseHeight) ||
  1476. (oldHeightInc != pCD->heightInc)))
  1477. {
  1478. incHeight = (pCD->maxHeight - oldBaseHeight) / oldHeightInc;
  1479. pCD->maxHeight =
  1480. (incHeight * pCD->heightInc) + pCD->baseHeight;
  1481. }
  1482. else
  1483. {
  1484. /* reset the maxHeight before further processing */
  1485. pCD->maxHeight = pCD->maxHeightLimit;
  1486. }
  1487. }
  1488. if (pCD->maxHeight > MAX_MAX_SIZE(pCD).height)
  1489. {
  1490. pCD->maxHeight = MAX_MAX_SIZE(pCD).height;
  1491. }
  1492. }
  1493. /*
  1494. * Make sure not to exceed the maximumMaximumSize (width and height)
  1495. */
  1496. if (pCD->maxWidth > MAX_MAX_SIZE(pCD).width)
  1497. {
  1498. pCD->maxWidth = MAX_MAX_SIZE(pCD).width;
  1499. }
  1500. if (pCD->maxHeight > MAX_MAX_SIZE(pCD).height)
  1501. {
  1502. pCD->maxHeight = MAX_MAX_SIZE(pCD).height;
  1503. }
  1504. /*
  1505. * Get the initial aspect ratios, if available. Only use them if:
  1506. *
  1507. * minAspect.y > 0
  1508. * maxAspect.y > 0
  1509. * 0 <= minAspect.x / minAspect.y <= maxAspect.x / maxAspect.y
  1510. */
  1511. if (flags & P_ASPECT)
  1512. {
  1513. pCD->minAspect.x = pNormalHints->min_aspect.x;
  1514. pCD->minAspect.y = pNormalHints->min_aspect.y;
  1515. pCD->maxAspect.x = pNormalHints->max_aspect.x;
  1516. pCD->maxAspect.y = pNormalHints->max_aspect.y;
  1517. if (pCD->minAspect.y > 0 &&
  1518. pCD->maxAspect.y > 0 &&
  1519. pCD->minAspect.x > 0 &&
  1520. pCD->maxAspect.x > 0 &&
  1521. (pCD->minAspect.x * pCD->maxAspect.y <=
  1522. pCD->maxAspect.x * pCD->minAspect.y))
  1523. {
  1524. pCD->sizeFlags |= P_ASPECT;
  1525. }
  1526. else
  1527. {
  1528. pCD->sizeFlags &= ~P_ASPECT;
  1529. }
  1530. }
  1531. /* compute for minimum frame size */
  1532. if ((decoration = pCD->decor) & MWM_DECOR_TITLE)
  1533. {
  1534. boxdim = TitleBarHeight(pCD);
  1535. tmpMin = boxdim +
  1536. ((decoration & MWM_DECOR_MENU) ? boxdim : 0) +
  1537. ((decoration & MWM_DECOR_MINIMIZE) ? boxdim : 0) +
  1538. ((decoration & MWM_DECOR_MAXIMIZE) ? boxdim : 0) -
  1539. 2*(pCD->matteWidth);
  1540. }
  1541. else {
  1542. tmpMin = 0;
  1543. }
  1544. /*
  1545. * Process the window gravity (for positioning):
  1546. */
  1547. if (flags & P_WIN_GRAVITY)
  1548. {
  1549. pCD->windowGravity = pNormalHints->win_gravity;
  1550. }
  1551. else
  1552. {
  1553. if (pNormalHints->icccVersion == ICCC_R2)
  1554. {
  1555. pCD->windowGravity = wmGD.windowAttributes.win_gravity;
  1556. }
  1557. else
  1558. {
  1559. pCD->windowGravity = NorthWestGravity;
  1560. }
  1561. }
  1562. /*
  1563. * Make sure that all the window sizing constraints are compatible:
  1564. */
  1565. /*
  1566. * Make:
  1567. *
  1568. * minWidth >= tmpMin
  1569. * minWidth >= max (baseWidth, widthInc) > 0
  1570. * & an integral number of widthInc from baseWidth.
  1571. * minHeight >= max (baseHeight, heightInc) > 0
  1572. * & an integral number of heightInc from baseHeight.
  1573. */
  1574. if (pCD->minWidth < tmpMin)
  1575. {
  1576. if ((diff = ((tmpMin - pCD->baseWidth)%pCD->widthInc)) != 0)
  1577. {
  1578. pCD->minWidth = tmpMin + pCD->widthInc - diff;
  1579. }
  1580. else
  1581. {
  1582. pCD->minWidth = tmpMin;
  1583. }
  1584. }
  1585. if (pCD->minWidth < pCD->baseWidth)
  1586. {
  1587. pCD->minWidth = pCD->baseWidth;
  1588. }
  1589. if (pCD->minWidth == 0)
  1590. {
  1591. pCD->minWidth = pCD->widthInc;
  1592. }
  1593. else if ((diff = ((pCD->minWidth - pCD->baseWidth)%pCD->widthInc)) != 0)
  1594. {
  1595. pCD->minWidth += pCD->widthInc - diff;
  1596. }
  1597. if (pCD->minHeight < pCD->baseHeight)
  1598. {
  1599. pCD->minHeight = pCD->baseHeight;
  1600. }
  1601. if (pCD->minHeight == 0)
  1602. {
  1603. pCD->minHeight = pCD->heightInc;
  1604. }
  1605. else if ((diff = ((pCD->minHeight - pCD->baseHeight) % pCD->heightInc)) !=0)
  1606. {
  1607. pCD->minHeight += pCD->heightInc - diff;
  1608. }
  1609. /*
  1610. * Make:
  1611. *
  1612. * maxWidth >= minWidth
  1613. * & an integral number of widthInc from baseWidth.
  1614. * maxHeight >= minHeight
  1615. * & an integral number of heightInc from baseHeight.
  1616. */
  1617. if (pCD->maxWidth < pCD->minWidth)
  1618. {
  1619. pCD->maxWidth = pCD->minWidth;
  1620. }
  1621. /*
  1622. * Hack to use maxWidthLimit as the real maxWidth when maximumClientSize
  1623. * set to 'vertical'.
  1624. */
  1625. if (IS_MAXIMIZE_VERTICAL(pCD))
  1626. {
  1627. /* go to min (full screen width, max maximum width) */
  1628. pCD->maxWidthLimit = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1629. (2 * pCD->clientOffset.x);
  1630. }
  1631. else
  1632. {
  1633. pCD->maxWidthLimit = pCD->maxWidth;
  1634. }
  1635. pCD->maxWidth -= ((pCD->maxWidth - pCD->baseWidth) % pCD->widthInc);
  1636. if (firstTime)
  1637. {
  1638. pCD->oldMaxWidth = pCD->maxWidth;
  1639. }
  1640. if (pCD->maxHeight < pCD->minHeight)
  1641. {
  1642. pCD->maxHeight = pCD->minHeight;
  1643. }
  1644. /*
  1645. * Hack to use maxHeightLimit as the real maxHeight when maximumClientSize
  1646. * set to 'horizontal'.
  1647. */
  1648. if (IS_MAXIMIZE_HORIZONTAL(pCD))
  1649. {
  1650. /* go to min (full screen height, max maximum height) */
  1651. pCD->maxHeightLimit = DisplayHeight (DISPLAY, SCREEN_FOR_CLIENT(pCD)) -
  1652. (pCD->clientOffset.x +
  1653. pCD->clientOffset.y);
  1654. }
  1655. else
  1656. {
  1657. pCD->maxHeightLimit = pCD->maxHeight;
  1658. }
  1659. pCD->maxHeight -= ((pCD->maxHeight - pCD->baseHeight) % pCD->heightInc);
  1660. if (firstTime)
  1661. {
  1662. pCD->oldMaxHeight = pCD->maxHeight;
  1663. }
  1664. if (!firstTime && pCD->maxConfig)
  1665. {
  1666. /*
  1667. * If the hints changed while we were maximized then
  1668. * we may need to adjust the normalized size of the window.
  1669. */
  1670. if (!firstTime &&
  1671. ((oldBaseWidth != pCD->baseWidth) ||
  1672. (oldBaseHeight != pCD->baseHeight) ||
  1673. (oldWidthInc != pCD->widthInc) ||
  1674. (oldHeightInc != pCD->heightInc)))
  1675. {
  1676. incWidth = (pCD->clientWidth - oldBaseWidth) / oldWidthInc;
  1677. incHeight = (pCD->clientHeight - oldBaseHeight) / oldHeightInc;
  1678. pCD->clientWidth =
  1679. (incWidth * pCD->widthInc) + pCD->baseWidth;
  1680. pCD->clientHeight =
  1681. (incHeight * pCD->heightInc) + pCD->baseHeight;
  1682. }
  1683. }
  1684. /*
  1685. * If using aspect ratios, make:
  1686. *
  1687. * minWidth / maxHeight <= minAspect.x / minAspect.y
  1688. * <= maxAspect.x / maxAspect.y
  1689. * <= maxWidth / minHeight
  1690. */
  1691. if (pCD->sizeFlags & P_ASPECT)
  1692. {
  1693. if (pCD->minWidth * pCD->minAspect.y >
  1694. pCD->minAspect.x * pCD->maxHeight)
  1695. {
  1696. pCD->minAspect.x = pCD->minWidth;
  1697. pCD->minAspect.y = pCD->maxHeight;
  1698. }
  1699. if (pCD->maxAspect.x * pCD->minHeight >
  1700. pCD->maxWidth * pCD->maxAspect.y)
  1701. {
  1702. pCD->maxAspect.x = pCD->maxWidth;
  1703. pCD->maxAspect.y = pCD->minHeight;
  1704. }
  1705. FixWindowSize (pCD, (unsigned int *) &(pCD->maxWidth),
  1706. (unsigned int *) &(pCD->maxHeight),
  1707. (unsigned int) (pCD->widthInc),
  1708. (unsigned int) (pCD->heightInc));
  1709. }
  1710. /*
  1711. * If this is the first time, make sure the client dimensions are within
  1712. * range and that they satisfy any aspect ratio constraints:
  1713. *
  1714. * 0 < minWidth <= clientWidth <= maxWidth
  1715. * 0 < minHeight <= clientHeight <= maxHeight
  1716. *
  1717. * minAspect.x / minAspect.y <= clientWidth / clientHeight
  1718. * <= maxAspect.x / maxAspect.y
  1719. *
  1720. * Initial max width/height are set to max of max size or normal
  1721. * client size unless a maximumClientSize was specified.
  1722. */
  1723. if (firstTime)
  1724. {
  1725. if (!pCD->maximumClientSize.width)
  1726. {
  1727. if (pCD->clientWidth > pCD->pSD->maximumMaximumSize.width)
  1728. {
  1729. pCD->clientWidth = pCD->pSD->maximumMaximumSize.width;
  1730. }
  1731. }
  1732. if (!pCD->maximumClientSize.height)
  1733. {
  1734. if (pCD->clientHeight > pCD->pSD->maximumMaximumSize.height)
  1735. {
  1736. pCD->clientHeight = pCD->pSD->maximumMaximumSize.height;
  1737. }
  1738. }
  1739. FixWindowSize (pCD, (unsigned int *) &(pCD->clientWidth),
  1740. (unsigned int *) &(pCD->clientHeight),
  1741. (unsigned int) (pCD->widthInc),
  1742. (unsigned int) (pCD->heightInc));
  1743. }
  1744. } /* END OF FUNCTION ProcessWmNormalHints */
  1745. /*************************************<->*************************************
  1746. *
  1747. * WmICCCMToXmString (wmNameProp)
  1748. *
  1749. *
  1750. * Description:
  1751. * -----------
  1752. * This function uses a property (WM_NAME or WM_ICON_NAME) that was
  1753. * retrieved from the window, and converts it to XmString.
  1754. *
  1755. * Inputs:
  1756. * ------
  1757. * wmNameProp - the text property
  1758. *
  1759. * Outputs:
  1760. * -------
  1761. * Return = new XmString, or NULL if the property didn't have a value.
  1762. *
  1763. *************************************<->***********************************/
  1764. static XmString
  1765. WmICCCMToXmString (XTextProperty *wmNameProp)
  1766. {
  1767. int status;
  1768. XmString xms_return;
  1769. XmStringTable xmsTable;
  1770. int i, nStrings = -1;
  1771. char msg[200];
  1772. if (wmNameProp->value == 0 || strlen((char *)wmNameProp->value) == 0)
  1773. {
  1774. return (XmString)NULL;
  1775. }
  1776. if (((status = XmCvtTextPropertyToXmStringTable(DISPLAY, wmNameProp,
  1777. &xmsTable, &nStrings))
  1778. != Success) || (nStrings <= 0))
  1779. {
  1780. switch (status)
  1781. {
  1782. case XConverterNotFound:
  1783. sprintf(msg, GETMESSAGE (70,5,
  1784. "Window manager cannot convert property %.100s as clientTitle/iconTitle: XmbTextPropertyToTextList"),
  1785. XGetAtomName (DISPLAY,wmNameProp->encoding));
  1786. Warning(msg);
  1787. break;
  1788. case XNoMemory:
  1789. sprintf(msg, GETMESSAGE (70, 6,
  1790. "insufficient memory to convert property %.100s as clientTitle/iconTitle: XmbTextPropertyToTextList"),
  1791. XGetAtomName(DISPLAY,wmNameProp->encoding));
  1792. Warning(msg);
  1793. break;
  1794. case XLocaleNotSupported:
  1795. if ((wmNameProp->encoding == XA_STRING) ||
  1796. (wmNameProp->encoding == wmGD.xa_COMPOUND_TEXT))
  1797. {
  1798. sprintf(msg, LOCALE_MSG, setlocale(LC_ALL, NULL));
  1799. }
  1800. else
  1801. {
  1802. /* Atom was neither STRING nor COMPOUND_TEXT */
  1803. sprintf(msg, GETMESSAGE(70, 8,
  1804. "Window manager received unknown property as clientTitle/iconTitle: %.100s. Property ignored."),
  1805. XGetAtomName(DISPLAY, wmNameProp->encoding));
  1806. }
  1807. Warning(msg);
  1808. break;
  1809. }
  1810. /* Couldn't convert using Xm; apply a default */
  1811. return XmCvtCTToXmString((char*)wmNameProp->value);
  1812. }
  1813. xms_return = xmsTable[0];
  1814. for (i = 1; i < nStrings; i++)
  1815. {
  1816. XmStringFree(xmsTable[i]);
  1817. }
  1818. XtFree((char *)xmsTable);
  1819. return xms_return;
  1820. }
  1821. /*************************************<->*************************************
  1822. *
  1823. * ProcessWmWindowTitle (pCD, firstTime)
  1824. *
  1825. *
  1826. * Description:
  1827. * -----------
  1828. * This function retrieves the contents of the WM_NAME property on the
  1829. * cient window. A default name is set if the property does not exist.
  1830. *
  1831. *
  1832. * Inputs:
  1833. * ------
  1834. * pCD - pointer to client data structure
  1835. * firstTime - false if the window is already managed and the title
  1836. * is being changed.
  1837. *
  1838. *
  1839. * Outputs:
  1840. * -------
  1841. * pCD - clientTitle, iconTitle
  1842. *
  1843. *************************************<->***********************************/
  1844. void
  1845. ProcessWmWindowTitle (ClientData *pCD, Boolean firstTime)
  1846. {
  1847. XTextProperty wmNameProp;
  1848. XmString title_xms = NULL;
  1849. if ((pCD->clientDecoration & MWM_DECOR_TITLE) &&
  1850. (!firstTime || HasProperty (pCD, XA_WM_NAME)) &&
  1851. XGetWMName(DISPLAY, pCD->client, &wmNameProp))
  1852. {
  1853. title_xms = WmICCCMToXmString(&wmNameProp);
  1854. if (wmNameProp.value)
  1855. XFree ((char*)wmNameProp.value);
  1856. }
  1857. if (title_xms)
  1858. {
  1859. if (!firstTime && (pCD->iconTitle == pCD->clientTitle))
  1860. {
  1861. /*
  1862. * The client window title is being used for the icon title so
  1863. * change the icon title with the window title.
  1864. */
  1865. pCD->iconTitle = title_xms;
  1866. RedisplayIconTitle (pCD);
  1867. }
  1868. if ((pCD->clientFlags & CLIENT_HINTS_TITLE) &&
  1869. pCD->clientTitle != wmGD.clientDefaultTitle)
  1870. {
  1871. XmStringFree (pCD->clientTitle);
  1872. }
  1873. pCD->clientTitle = title_xms;
  1874. pCD->clientFlags |= CLIENT_HINTS_TITLE;
  1875. if (!firstTime)
  1876. {
  1877. DrawWindowTitle (pCD, True);
  1878. }
  1879. }
  1880. /*
  1881. * The client frame does not have a place to put the title or the WM_NAME
  1882. * property does not exist or there was some error in getting
  1883. * the property information, so use a default value.
  1884. */
  1885. else if (firstTime)
  1886. {
  1887. if (pCD->clientName)
  1888. {
  1889. pCD->clientTitle = XmStringCreateLocalized(pCD->clientName);
  1890. }
  1891. else
  1892. {
  1893. pCD->clientTitle = wmGD.clientDefaultTitle;
  1894. }
  1895. }
  1896. /*
  1897. * If this is a tear-off menu, then make sure title text is not clipped
  1898. */
  1899. if ((pCD->window_status & MWM_TEAROFF_WINDOW) ||
  1900. (pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL))
  1901. {
  1902. unsigned int boxdim = TitleBarHeight (pCD);
  1903. unsigned long decor = pCD->decor;
  1904. XmFontList fontList;
  1905. int minWidth;
  1906. if (DECOUPLE_TITLE_APPEARANCE(pCD))
  1907. fontList = CLIENT_TITLE_APPEARANCE(pCD).fontList;
  1908. else
  1909. fontList = CLIENT_APPEARANCE(pCD).fontList;
  1910. /*
  1911. * Calculations derived from GetTextBox() and GetFramePartInfo()
  1912. */
  1913. minWidth = XmStringWidth(fontList, pCD->clientTitle) +
  1914. ((pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL) ? 4 : 0) +
  1915. ((decor & MWM_DECOR_MENU) ? boxdim : 0) +
  1916. ((decor & MWM_DECOR_MINIMIZE) ? boxdim : 0) +
  1917. ((decor & MWM_DECOR_MAXIMIZE) ? boxdim : 0) +
  1918. WM_TOP_TITLE_SHADOW + WM_BOTTOM_TITLE_SHADOW +
  1919. WM_TOP_TITLE_PADDING + WM_BOTTOM_TITLE_PADDING;
  1920. if (minWidth > pCD->minWidth)
  1921. {
  1922. pCD->minWidth = minWidth;
  1923. }
  1924. if ((pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL) &&
  1925. (pCD->clientWidth < pCD->minWidth))
  1926. {
  1927. FixSubpanelEmbeddedClientGeometry (pCD);
  1928. }
  1929. }
  1930. } /* END OF FUNCTION ProcessWmWindowTitle */
  1931. /*************************************<->*************************************
  1932. *
  1933. * FixSubpanelEmbeddedClientGeometry ( pCD )
  1934. *
  1935. *
  1936. * Description:
  1937. * -----------
  1938. * This function adjusts the embedded clients in a subpanel if the
  1939. * geometry of the subpanel is adjusted.
  1940. *
  1941. *
  1942. * Inputs:
  1943. * ------
  1944. * pCD - pointer to client data structure
  1945. *
  1946. *
  1947. * Outputs:
  1948. * -------
  1949. *
  1950. * Comment:
  1951. * -------
  1952. * Only handles change in width right now.
  1953. *
  1954. *************************************<->***********************************/
  1955. static void
  1956. FixSubpanelEmbeddedClientGeometry (ClientData *pCD)
  1957. {
  1958. WmScreenData *pSD = PSD_FOR_CLIENT(pCD);
  1959. Widget wSubpanel;
  1960. Arg al[5];
  1961. int ac;
  1962. /*
  1963. * Get the widget for the subpanel
  1964. */
  1965. wSubpanel = WmPanelistWindowToSubpanel (DISPLAY1, pCD->client);
  1966. if (pSD->wPanelist && wSubpanel)
  1967. {
  1968. WmFpEmbeddedClientData *pECD;
  1969. int i;
  1970. /*
  1971. * set new shell width to minimum width
  1972. */
  1973. if (pCD->clientWidth < pCD->minWidth)
  1974. {
  1975. ac = 0;
  1976. XtSetArg (al[ac], XmNwidth, pCD->minWidth); ac++;
  1977. XtSetValues (wSubpanel, al, ac);
  1978. }
  1979. /*
  1980. * Cause update of client geometries.
  1981. */
  1982. /* WmPanelistSetClientGeometry (pSD->wPanelist); */
  1983. /*
  1984. * Update all affected reparented controls.
  1985. */
  1986. for (i=0; i<pSD->numEmbeddedClients; i++)
  1987. {
  1988. pECD = &(((WmFpEmbeddedClientData *) pSD->pECD)[i]);
  1989. if (pECD->pCD)
  1990. {
  1991. ClientData *pCD2 = pECD->pCD;
  1992. if ((pCD2->clientWidth != pECD->width) ||
  1993. (pCD2->clientHeight != pECD->height) ||
  1994. (pCD2->clientX != pECD->x) ||
  1995. (pCD2->clientY != pECD->y))
  1996. {
  1997. pCD2->clientX = pECD->x;
  1998. pCD2->clientY = pECD->y;
  1999. pCD2->clientWidth = pECD->width;
  2000. pCD2->clientHeight = pECD->height;
  2001. XMoveResizeWindow (DISPLAY1, pCD2->client,
  2002. pECD->x, pECD->y, pECD->width, pECD->height);
  2003. }
  2004. }
  2005. }
  2006. }
  2007. } /* END OF FUNCTION FixEmbeddedClientGeometry */
  2008. /*************************************<->*************************************
  2009. *
  2010. * ProcessWmIconTitle (pCD, firstTime)
  2011. *
  2012. *
  2013. * Description:
  2014. * -----------
  2015. * This function retrieves the contents of the WM_ICON_NAME property on the
  2016. * cient window. The value of the property is a string that is used for the
  2017. * icon title. A default title is set if the property does not exist.
  2018. *
  2019. *
  2020. * Inputs:
  2021. * ------
  2022. * pCD - pointer to client data structure
  2023. *
  2024. * firstTime - false if the window is already managed and the title
  2025. * is being changed.
  2026. *
  2027. *
  2028. * Outputs:
  2029. * -------
  2030. * pCD - iconTitle
  2031. *
  2032. *************************************<->***********************************/
  2033. void
  2034. ProcessWmIconTitle (ClientData *pCD, Boolean firstTime)
  2035. {
  2036. XTextProperty wmIconNameProp;
  2037. XmString icon_xms = NULL;
  2038. if ((pCD->clientFunctions & MWM_FUNC_MINIMIZE) &&
  2039. (pCD->transientLeader == NULL) &&
  2040. (!firstTime || HasProperty(pCD, XA_WM_ICON_NAME)) &&
  2041. XGetWMIconName (DISPLAY, pCD->client, &wmIconNameProp))
  2042. {
  2043. icon_xms = WmICCCMToXmString(&wmIconNameProp);
  2044. if (wmIconNameProp.value)
  2045. XFree ((char*)wmIconNameProp.value);
  2046. }
  2047. if (icon_xms)
  2048. {
  2049. if ((pCD->iconFlags & ICON_HINTS_TITLE) &&
  2050. pCD->iconTitle != wmGD.iconDefaultTitle)
  2051. {
  2052. XmStringFree (pCD->iconTitle);
  2053. }
  2054. pCD->iconTitle = icon_xms;
  2055. pCD->iconFlags |= ICON_HINTS_TITLE;
  2056. if (!firstTime)
  2057. {
  2058. RedisplayIconTitle (pCD);
  2059. }
  2060. }
  2061. /*
  2062. * The WM_ICON_NAME property does not exist (or there was some error
  2063. * in getting * the property information), so use a default value.
  2064. */
  2065. else if (firstTime)
  2066. {
  2067. if (pCD->clientTitle && (pCD->clientTitle != wmGD.clientDefaultTitle))
  2068. {
  2069. pCD->iconTitle = pCD->clientTitle;
  2070. }
  2071. else
  2072. {
  2073. pCD->iconTitle = wmGD.iconDefaultTitle;
  2074. }
  2075. }
  2076. } /* END OF FUNCTION ProcessWmIconTitle */
  2077. /*************************************<->*************************************
  2078. *
  2079. * ProcessWmTransientFor (pCD)
  2080. *
  2081. *
  2082. * Description:
  2083. * -----------
  2084. * This function retrieves the contents of the WM_TRANSIENT_FOR property on
  2085. * the cient window.
  2086. *
  2087. *
  2088. * Inputs:
  2089. * ------
  2090. * pCD = pointer to the client data structure for the window with the property
  2091. *
  2092. *
  2093. * Outputs:
  2094. * -------
  2095. * pCD.transientFor = if tranient then this is the associated main window
  2096. *
  2097. * pCD.clientFlags = indicate that this is a transient window
  2098. *
  2099. *************************************<->***********************************/
  2100. void
  2101. ProcessWmTransientFor (ClientData *pCD)
  2102. {
  2103. Window window;
  2104. ClientData *leader;
  2105. if ((HasProperty (pCD, XA_WM_TRANSIENT_FOR)) &&
  2106. (XGetTransientForHint (DISPLAY, pCD->client, &window)))
  2107. {
  2108. pCD->clientFlags |= CLIENT_TRANSIENT;
  2109. /*
  2110. * Only save the (leader) transientFor window if it is NOT the
  2111. * client window and it is already managed by the window manager.
  2112. */
  2113. if ((pCD->client != window) &&
  2114. !XFindContext (DISPLAY, window, wmGD.windowContextType,
  2115. (caddr_t *)&leader))
  2116. {
  2117. pCD->transientFor = window;
  2118. pCD->transientLeader = leader;
  2119. }
  2120. }
  2121. else { /* else this is not a transient window */
  2122. pCD->clientFlags &= ~CLIENT_TRANSIENT;
  2123. pCD->transientFor = (Window)0L;
  2124. pCD->transientLeader = NULL;
  2125. }
  2126. } /* END OF FUNCTION ProcessWmTransientFor */
  2127. /*************************************<->*************************************
  2128. *
  2129. * MakeSystemMenu (pCD)
  2130. *
  2131. *
  2132. * Description:
  2133. * -----------
  2134. * This function finds or makes a system menu for the client. A check
  2135. * is made for the _MWM_MENU property and, if present, client-specific
  2136. * items are added to the custom system menu. Any custom system menu
  2137. * must be destroyed when the client is unmanaged (or killed).
  2138. *
  2139. *
  2140. * Inputs:
  2141. * ------
  2142. * pCD = pointer to the client data structure for the managed window
  2143. *
  2144. *
  2145. * Outputs:
  2146. * -------
  2147. * pCD.systemMenuSpec = system menu specification for the client, not added
  2148. * to wmGD.acceleratorMenuSpecs
  2149. *
  2150. *************************************<->***********************************/
  2151. void
  2152. MakeSystemMenu (ClientData *pCD)
  2153. {
  2154. pCD->mwmMenuItems = GetMwmMenuItems(pCD);
  2155. pCD->systemMenuSpec =
  2156. MAKE_MENU (PSD_FOR_CLIENT(pCD), pCD, pCD->systemMenu, F_CONTEXT_WINDOW,
  2157. F_CONTEXT_WINDOW|F_CONTEXT_ICON, pCD->mwmMenuItems, TRUE);
  2158. #ifdef NO_MESSAGE_CATALOG
  2159. if (pCD->systemMenuSpec == NULL)
  2160. {
  2161. /*
  2162. * As the lookup has failed, let's try just one more time.
  2163. */
  2164. Warning("Retrying - using builtin window menu\n");
  2165. pCD->systemMenuSpec =
  2166. MAKE_MENU(PSD_FOR_CLIENT(pCD), pCD, builtinSystemMenuName,
  2167. F_CONTEXT_WINDOW,
  2168. F_CONTEXT_WINDOW|F_CONTEXT_ICON, pCD->mwmMenuItems, TRUE);
  2169. }
  2170. #endif
  2171. } /* END OF FUNCTION MakeSystemMenu */
  2172. /*************************************<->*************************************
  2173. *
  2174. * InitCColormapData (pCD)
  2175. *
  2176. *
  2177. * Description:
  2178. * -----------
  2179. * This function initializes colormap data for the client window that is
  2180. * by the window manager in maintaining the colormap focus. This may
  2181. * involve retrieving and processing properties that deal with subwindow
  2182. * colormaps.
  2183. *
  2184. *
  2185. * Inputs:
  2186. * ------
  2187. * pCD = pointer to the client data structure for the managed window
  2188. *
  2189. *
  2190. * Outputs:
  2191. * -------
  2192. * pCD.clientColormap = client colormap to be installed when the client
  2193. * window gets the colormap focus
  2194. *
  2195. * pCD = (cmapWindows, clientCmapList, clientCmapCount, clientCmapIndex)
  2196. *
  2197. *************************************<->***********************************/
  2198. void
  2199. InitCColormapData (ClientData *pCD)
  2200. {
  2201. if (wmGD.windowAttributes.colormap == None)
  2202. {
  2203. pCD->clientColormap = WORKSPACE_COLORMAP(pCD);
  2204. }
  2205. else
  2206. {
  2207. pCD->clientColormap = wmGD.windowAttributes.colormap;
  2208. }
  2209. /*
  2210. * Process subwindow colormap windows if they are specified.
  2211. */
  2212. ProcessWmColormapWindows (pCD);
  2213. } /* END OF FUNCTION InitCColormapData */
  2214. /*************************************<->*************************************
  2215. *
  2216. * CalculateGravityOffset (pCD, xoff, yoff)
  2217. *
  2218. *
  2219. * Description:
  2220. * -----------
  2221. * This function calculates the window offsets based on the window gravity
  2222. * and the window frame client offset.
  2223. *
  2224. *
  2225. * Inputs:
  2226. * ------
  2227. * pCD = pointer to client data (client window configuration fields)
  2228. * xoff = pointer to xoffset
  2229. * yoff = pointer to yoffset
  2230. *
  2231. *
  2232. * Outputs:
  2233. * -------
  2234. * xoff = pointer to xoffset set
  2235. * yoff = pointer to yoffset set
  2236. *
  2237. *************************************<->***********************************/
  2238. void
  2239. CalculateGravityOffset (ClientData *pCD, int *xoff, int *yoff)
  2240. {
  2241. int borderWidth = pCD->xBorderWidth;
  2242. if (pCD->windowGravity < ForgetGravity ||
  2243. pCD->windowGravity > StaticGravity)
  2244. {
  2245. *xoff = 0;
  2246. *yoff = 0;
  2247. }
  2248. else
  2249. {
  2250. switch (pCD->windowGravity)
  2251. {
  2252. case NorthWestGravity:
  2253. default:
  2254. {
  2255. *xoff = pCD->clientOffset.x;
  2256. *yoff = pCD->clientOffset.y;
  2257. break;
  2258. }
  2259. case NorthGravity:
  2260. {
  2261. *xoff = borderWidth;
  2262. *yoff = pCD->clientOffset.y;
  2263. break;
  2264. }
  2265. case NorthEastGravity:
  2266. {
  2267. *xoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2268. *yoff = pCD->clientOffset.y;
  2269. break;
  2270. }
  2271. case EastGravity:
  2272. {
  2273. *xoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2274. *yoff = borderWidth +
  2275. (pCD->clientOffset.y - pCD->clientOffset.x)/2;
  2276. break;
  2277. }
  2278. case SouthEastGravity:
  2279. {
  2280. *xoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2281. *yoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2282. break;
  2283. }
  2284. case SouthGravity:
  2285. {
  2286. *xoff = borderWidth;
  2287. *yoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2288. break;
  2289. }
  2290. case SouthWestGravity:
  2291. {
  2292. *xoff = pCD->clientOffset.x;
  2293. *yoff = -(pCD->clientOffset.x - (2 * borderWidth));
  2294. break;
  2295. }
  2296. case WestGravity:
  2297. {
  2298. *xoff = pCD->clientOffset.x;
  2299. *yoff = borderWidth +
  2300. (pCD->clientOffset.y - pCD->clientOffset.x)/2;
  2301. break;
  2302. }
  2303. case CenterGravity:
  2304. {
  2305. *xoff = 0;
  2306. *yoff = 0;
  2307. break;
  2308. }
  2309. }
  2310. }
  2311. } /* END OF FUNCTION CalculateGravityOffset */
  2312. /*************************************<->*************************************
  2313. *
  2314. * InitClientPlacement (pCD, manageFlags)
  2315. *
  2316. *
  2317. * Description:
  2318. * -----------
  2319. * This function sets up the initial client window placement (for both
  2320. * the normal and maximized state).
  2321. *
  2322. *
  2323. * Inputs:
  2324. * ------
  2325. * pCD = pointer to client data (client window configuration fields)
  2326. *
  2327. * manageFlags = flags that indicate wm state information (e.g. whether
  2328. * the window manager is starting up or restarting)
  2329. *
  2330. *
  2331. * Outputs:
  2332. * -------
  2333. * Return = True if position changed by this routine.
  2334. * pCD = changes to the client window configuration fields
  2335. *
  2336. *************************************<->***********************************/
  2337. Boolean
  2338. InitClientPlacement (ClientData *pCD, long manageFlags)
  2339. {
  2340. Boolean interactivelyPlaced = False;
  2341. Boolean autoPlaced = False;
  2342. Boolean rval = False;
  2343. int xoff, yoff;
  2344. int origX, origY, origWidth, origHeight;
  2345. int iwsc;
  2346. /*
  2347. * Save initial client values
  2348. */
  2349. origX = pCD->clientX;
  2350. origY = pCD->clientY;
  2351. origWidth = pCD->clientWidth;
  2352. origHeight = pCD->clientHeight;
  2353. /*
  2354. * Do interactive placement if...
  2355. * + the resource is turned on
  2356. * + the window's coming up on the active screen
  2357. *
  2358. * Don't do it if...
  2359. * + position specified in DB or by Session Manager
  2360. * + the user has specified a position
  2361. * + the window is coming up iconic
  2362. * + the window is transient
  2363. * + we're system modal
  2364. */
  2365. if (wmGD.interactivePlacement &&
  2366. (!(pCD->clientFlags & (SM_X | SM_Y))) &&
  2367. !(pCD->sizeFlags & US_POSITION) &&
  2368. (pCD->clientState != MINIMIZED_STATE) &&
  2369. (manageFlags == MANAGEW_NORMAL) &&
  2370. !(pCD->clientFlags & CLIENT_TRANSIENT) &&
  2371. (pCD->inputMode != MWM_INPUT_SYSTEM_MODAL) &&
  2372. (ClientInWorkspace(PSD_FOR_CLIENT(pCD)->pActiveWS, pCD)))
  2373. {
  2374. /*
  2375. * Interactively place the window on the screen.
  2376. */
  2377. interactivelyPlaced = True;
  2378. PlaceWindowInteractively (pCD);
  2379. }
  2380. /*
  2381. * Check out the configuration values to insure that they are within
  2382. * the constraints.
  2383. */
  2384. FixWindowConfiguration (pCD, (unsigned int *) &(pCD->clientWidth),
  2385. (unsigned int *) &(pCD->clientHeight),
  2386. (unsigned int) (pCD->widthInc),
  2387. (unsigned int) (pCD->heightInc));
  2388. /*
  2389. * Do autoplacement of the client window if appropriate.
  2390. */
  2391. if ((manageFlags == MANAGEW_NORMAL) && !interactivelyPlaced &&
  2392. (!(pCD->clientFlags & (SM_X | SM_Y))) &&
  2393. !(pCD->sizeFlags & US_POSITION) &&
  2394. !(pCD->clientFlags & CLIENT_TRANSIENT) &&
  2395. (pCD->inputMode != MWM_INPUT_SYSTEM_MODAL) && wmGD.clientAutoPlace)
  2396. {
  2397. /*
  2398. * if (PPosition is on or nonzero), then use current value for
  2399. * clientX and clientY which was set to windowAttributes.x,y
  2400. * by ProcessWmNormalHints(), else autoplace client.
  2401. */
  2402. if ((pCD->sizeFlags & P_POSITION) &&
  2403. ((pCD->usePPosition == USE_PPOSITION_ON) ||
  2404. ((pCD->usePPosition == USE_PPOSITION_NONZERO) &&
  2405. ((pCD->clientX != 0) || (pCD->clientY != 0)))))
  2406. {
  2407. /* do nothing */
  2408. }
  2409. else
  2410. {
  2411. FindClientPlacement (pCD);
  2412. autoPlaced = True;
  2413. }
  2414. }
  2415. /*
  2416. * Do PositionIsFrame processing:
  2417. * Use window gravity to allow the user to specify the window
  2418. * position on the screen without having to know the dimensions
  2419. * of the decoration that mwm is adding.
  2420. */
  2421. if ((wmGD.positionIsFrame) &&
  2422. !interactivelyPlaced && !autoPlaced)
  2423. {
  2424. CalculateGravityOffset (pCD, &xoff, &yoff);
  2425. if (!(pCD->clientFlags & SM_X))
  2426. pCD->clientX += xoff;
  2427. if (!(pCD->clientFlags & SM_Y))
  2428. pCD->clientY += yoff;
  2429. }
  2430. /*
  2431. * Do PositionOnScreen processing:
  2432. */
  2433. if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL)
  2434. {
  2435. if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUB_RESTORED)
  2436. {
  2437. SetFrameInfo (pCD);
  2438. }
  2439. else
  2440. {
  2441. AdjustSlideOutGeometry (pCD);
  2442. }
  2443. }
  2444. else if (((wmGD.positionOnScreen) && !interactivelyPlaced) &&
  2445. (!(pCD->clientFlags & (SM_X | SM_Y))))
  2446. {
  2447. PlaceFrameOnScreen (pCD, &pCD->clientX, &pCD->clientY,
  2448. pCD->clientWidth, pCD->clientHeight);
  2449. }
  2450. /*
  2451. * Position the maximized frame:
  2452. */
  2453. pCD->maxX = pCD->clientX;
  2454. pCD->maxY = pCD->clientY;
  2455. PlaceFrameOnScreen (pCD, &pCD->maxX, &pCD->maxY, pCD->maxWidth,
  2456. pCD->maxHeight);
  2457. if (!wmGD.iconAutoPlace)
  2458. {
  2459. if (!(pCD->iconFlags & ICON_HINTS_POSITION))
  2460. {
  2461. for (iwsc=0; iwsc<pCD->numInhabited; iwsc++)
  2462. {
  2463. pCD->pWsList[iwsc].iconX = pCD->clientX;
  2464. pCD->pWsList[iwsc].iconY = pCD->clientY;
  2465. PlaceIconOnScreen (pCD, &pCD->pWsList[iwsc].iconX,
  2466. &pCD->pWsList[iwsc].iconY);
  2467. }
  2468. }
  2469. }
  2470. /*
  2471. * if client size or position has been changed by this routine,
  2472. * then indicate in return value
  2473. */
  2474. if ((origX != pCD->clientX) || (origY != pCD->clientY) ||
  2475. (origWidth != pCD->clientWidth) || (origHeight != pCD->clientHeight))
  2476. {
  2477. rval = True;
  2478. }
  2479. return (rval);
  2480. } /* END OF FUNCTION InitClientPlacement */
  2481. /******************************<->*************************************
  2482. *
  2483. * void AdjustSlideOutGeometry (pCD)
  2484. *
  2485. * Description:
  2486. * -----------
  2487. * Adjusts the geometry of the slide out panel
  2488. *
  2489. * Inputs:
  2490. * ------
  2491. * pCD = pointer to a client data of slide out
  2492. *
  2493. * Outputs:
  2494. * -------
  2495. *
  2496. * Comments:
  2497. * --------
  2498. * Subpanel is to appear above or below the front panel, centered
  2499. * on the vertical axis of the spawning control.
  2500. ******************************<->***********************************/
  2501. static void
  2502. AdjustSlideOutGeometry ( ClientData *pCD)
  2503. {
  2504. ClientData *pCD_FP = NULL;
  2505. WmPanelistObject pPanelist;
  2506. pCD->slideDirection = SLIDE_NORTH; /* assume up for now */
  2507. pPanelist = (WmPanelistObject) pCD->pSD->wPanelist;
  2508. (void) XFindContext (DISPLAY, XtWindow(O_Shell(pPanelist)),
  2509. wmGD.windowContextType, (caddr_t *)&pCD_FP);
  2510. if (pCD_FP)
  2511. {
  2512. /*
  2513. * Adjust slide up position if coming from front
  2514. * panel.
  2515. * (Assumes no nesting of panels !!!)
  2516. * (Assumes horizontal oriented front panel!!!)
  2517. */
  2518. if (pCD->transientLeader == pCD_FP)
  2519. {
  2520. /*
  2521. * Subpanel should be sort-of centered already,
  2522. * adjust by width of window manager frame.
  2523. */
  2524. pCD->clientX -= pCD->frameInfo.lowerBorderWidth;
  2525. /*
  2526. * Adjust to slide up above front panel.
  2527. */
  2528. pCD->clientY = pCD_FP->frameInfo.y -
  2529. pCD->frameInfo.lowerBorderWidth -
  2530. pCD->clientHeight + 3;
  2531. /* RICK -- added the (+ 3) */
  2532. if (pCD->clientY < 0)
  2533. {
  2534. /*
  2535. * Adjust to slide down below front panel.
  2536. */
  2537. pCD->clientY = pCD_FP->frameInfo.y +
  2538. pCD_FP->frameInfo.height +
  2539. pCD->frameInfo.titleBarHeight +
  2540. pCD->frameInfo.upperBorderWidth - 3;
  2541. pCD->slideDirection = SLIDE_SOUTH;
  2542. /* RICK -- added the (- 3) */
  2543. }
  2544. if ((pCD->clientY + pCD->clientHeight +
  2545. pCD->frameInfo.lowerBorderWidth) >
  2546. XDisplayHeight (DISPLAY, pCD->pSD->screen))
  2547. {
  2548. /*
  2549. * If the bottom of the slide-up is off the bottom
  2550. * of the screen, then don't slide, just pop it up.
  2551. */
  2552. pCD->slideDirection = SLIDE_NOT;
  2553. }
  2554. PlaceFrameOnScreen (pCD, &pCD->clientX, &pCD->clientY,
  2555. pCD->clientWidth, pCD->clientHeight);
  2556. }
  2557. SetFrameInfo (pCD);
  2558. }
  2559. }
  2560. /*************************************<->*************************************
  2561. *
  2562. * PlaceFrameOnScreen (pCD, pX, pY, w, h)
  2563. *
  2564. *
  2565. * Description:
  2566. * -----------
  2567. * This function is used to nudge a client window so that it is totally
  2568. * onscreen if possible. At least the top left corner will be onscreen.
  2569. *
  2570. *
  2571. * Inputs:
  2572. * ------
  2573. * pCD - pointer to client data
  2574. * pX - pointer to x-coord
  2575. * pY - pointer to y-coord
  2576. * w - width of window
  2577. * h - height of window
  2578. *
  2579. *
  2580. * Outputs:
  2581. * -------
  2582. * *pX - new x-coord
  2583. * *pY - new y-coord
  2584. *
  2585. *
  2586. * Comments:
  2587. * --------
  2588. *
  2589. *************************************<->***********************************/
  2590. void
  2591. PlaceFrameOnScreen (ClientData *pCD, int *pX, int *pY, int w, int h)
  2592. {
  2593. int clientOffsetX;
  2594. int clientOffsetY;
  2595. int frameX;
  2596. int frameY;
  2597. int frameWidth;
  2598. int frameHeight;
  2599. int screenHeight;
  2600. int screenWidth;
  2601. clientOffsetX = pCD->clientOffset.x;
  2602. clientOffsetY = pCD->clientOffset.y;
  2603. frameX = *pX - clientOffsetX;
  2604. frameY = *pY - clientOffsetY;
  2605. frameWidth = w + (2 * clientOffsetX);
  2606. frameHeight = h + clientOffsetX + clientOffsetY;
  2607. screenWidth = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  2608. screenHeight = DisplayHeight (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  2609. if ((frameX + frameWidth) > screenWidth)
  2610. {
  2611. frameX -= (frameX + frameWidth) - screenWidth;
  2612. }
  2613. if ((frameY + frameHeight) > screenHeight)
  2614. {
  2615. frameY -= (frameY + frameHeight) - screenHeight;
  2616. }
  2617. if (frameX < 0)
  2618. {
  2619. frameX = 0;
  2620. }
  2621. if (frameY < 0)
  2622. {
  2623. frameY = 0;
  2624. }
  2625. *pX = frameX + clientOffsetX;
  2626. *pY = frameY + clientOffsetY;
  2627. } /* END OF FUNCTION PlaceFrameOnScreen */
  2628. /*************************************<->*************************************
  2629. *
  2630. * PlaceIconOnScreen (pCD, pX, pY)
  2631. *
  2632. *
  2633. * Description:
  2634. * -----------
  2635. * This function positions an icon on-screen.
  2636. *
  2637. *
  2638. * Inputs:
  2639. * ------
  2640. * pCD - pointer to client data
  2641. * pX - pointer to x-coord
  2642. * pY - pointer to y-coord
  2643. *
  2644. * Outputs:
  2645. * -------
  2646. * *pX - new x-coord
  2647. * *pY - new y-coord
  2648. *
  2649. * Comments:
  2650. * --------
  2651. *
  2652. *************************************<->***********************************/
  2653. void
  2654. PlaceIconOnScreen (ClientData *pCD, int *pX, int *pY)
  2655. {
  2656. int screenWidth;
  2657. int screenHeight;
  2658. int iconX;
  2659. int iconY;
  2660. screenWidth = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  2661. screenHeight = DisplayHeight (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  2662. iconX = *pX;
  2663. iconY = *pY;
  2664. if ((iconX + ICON_WIDTH(pCD)) > screenWidth)
  2665. {
  2666. iconX = screenWidth - ICON_WIDTH(pCD);
  2667. }
  2668. else if (iconX < 0)
  2669. {
  2670. iconX = 0;
  2671. }
  2672. if ((iconY + ICON_HEIGHT(pCD)) > screenHeight)
  2673. {
  2674. iconY = screenHeight - ICON_HEIGHT(pCD);
  2675. }
  2676. else if (iconY < 0)
  2677. {
  2678. iconY = 0;
  2679. }
  2680. *pX = iconX;
  2681. *pY = iconY;
  2682. } /* END OF FUNCTION PlaceIconOnScreen */
  2683. /*************************************<->*************************************
  2684. *
  2685. * FixWindowConfiguration (pCD, pWidth, pHeight, widthInc, heightInc)
  2686. *
  2687. *
  2688. * Description:
  2689. * -----------
  2690. * This function adjusts the configuration for the client window so that
  2691. * it is in line with the client window's sizing constraints.
  2692. *
  2693. *
  2694. * Inputs:
  2695. * ------
  2696. * pCD = a pointer to the client window data
  2697. * pWidth, pHeight = pointers to the window configuration values
  2698. * widthInc, heightInc = window size increment values
  2699. *
  2700. *
  2701. * Outputs:
  2702. * -------
  2703. * pWidth, pHeight = adjusted configuration values are returned here
  2704. *
  2705. *
  2706. *************************************<->***********************************/
  2707. void
  2708. FixWindowConfiguration (ClientData *pCD, unsigned int *pWidth, unsigned int *pHeight, unsigned int widthInc, unsigned int heightInc)
  2709. {
  2710. int delta;
  2711. /*
  2712. * Make sure we're on width/height increment boundaries.
  2713. */
  2714. if ((int) *pWidth < pCD->minWidth)
  2715. {
  2716. *pWidth = pCD->minWidth;
  2717. }
  2718. else if ((delta = (*pWidth - pCD->baseWidth) % pCD->widthInc))
  2719. {
  2720. *pWidth -= delta;
  2721. }
  2722. if ((int) *pHeight < pCD->minHeight)
  2723. {
  2724. *pHeight = pCD->minHeight;
  2725. }
  2726. else if ((delta = (*pHeight - pCD->baseHeight) % pCD->heightInc))
  2727. {
  2728. *pHeight -= delta;
  2729. }
  2730. /*
  2731. * Constrain size within bounds.
  2732. */
  2733. FixWindowSize (pCD, pWidth, pHeight, widthInc, heightInc);
  2734. } /* END OF FUNCTION FixWindowConfiguration */
  2735. /*************************************<->*************************************
  2736. *
  2737. * FixWindowSize (pCD, pWidth, pHeight, widthInc, heightInc)
  2738. *
  2739. *
  2740. * Description:
  2741. * -----------
  2742. * This function adjusts the client window width and height so that
  2743. * it is in line with its sizing constraints.
  2744. *
  2745. *
  2746. * Inputs:
  2747. * ------
  2748. * pCD = a pointer to the client window data
  2749. * pWidth, pHeight = pointers to the window size values
  2750. * widthInc, heightInc = window size increment values
  2751. * pWS->limitResize
  2752. *
  2753. *
  2754. * Outputs:
  2755. * -------
  2756. * pWidth, pHeight = adjusted size values.
  2757. *
  2758. *
  2759. *************************************<->***********************************/
  2760. void
  2761. FixWindowSize (ClientData *pCD, unsigned int *pWidth, unsigned int *pHeight, unsigned int widthInc, unsigned int heightInc)
  2762. {
  2763. int deltaW;
  2764. int deltaH;
  2765. WmScreenData *pSD = pCD->pSD;
  2766. /*
  2767. * All occurrences of maxHeight and maxWidth in this routing has been
  2768. * hacked to use maxHeightLimit and maxWidthLimit as the real max when
  2769. * maximumClientSize is set to 'horizontal' or 'vertical', since
  2770. * pCD->maxHeight and pCD->maxWidth is fiddle to on reconfiguration.
  2771. */
  2772. if ((int) *pWidth < pCD->minWidth)
  2773. {
  2774. *pWidth = pCD->minWidth;
  2775. }
  2776. else if (*pWidth > pCD->maxWidthLimit &&
  2777. pSD->limitResize &&
  2778. !(pCD->clientFlags & CLIENT_WM_CLIENTS))
  2779. {
  2780. *pWidth = pCD->maxWidthLimit;
  2781. }
  2782. if ((int) *pHeight < pCD->minHeight)
  2783. {
  2784. *pHeight = pCD->minHeight;
  2785. }
  2786. else if (*pHeight > pCD->maxHeightLimit &&
  2787. pSD->limitResize &&
  2788. !(pCD->clientFlags & CLIENT_WM_CLIENTS))
  2789. {
  2790. *pHeight = pCD->maxHeightLimit;
  2791. }
  2792. if ((pCD->sizeFlags & P_ASPECT) &&
  2793. *pWidth * pCD->maxAspect.y > *pHeight * pCD->maxAspect.x)
  2794. /*
  2795. * Client aspect is too big.
  2796. * Candidate height >= client height:
  2797. * Try to increase the client's height without violating bounds.
  2798. * If this fails, use maximum height and try to decrease its width.
  2799. * Candidate height < client height:
  2800. * Try to decrease the client's width without violating bounds.
  2801. * If this fails, use minimum width and try to increase its height.
  2802. */
  2803. {
  2804. if ((*pHeight >= pCD->clientHeight) ||
  2805. (*pWidth > pCD->clientWidth))
  2806. /*
  2807. * Candidate height >= client height:
  2808. * Try to increase the client's height without violating bounds.
  2809. * If this fails, use maximum height and try to decrease its width.
  2810. */
  2811. {
  2812. deltaH = makemult (*pWidth * pCD->maxAspect.y / pCD->maxAspect.x -
  2813. *pHeight, heightInc);
  2814. if (*pHeight + deltaH <= pCD->maxHeightLimit ||
  2815. !pSD->limitResize ||
  2816. pCD->clientFlags & CLIENT_WM_CLIENTS)
  2817. {
  2818. *pHeight += deltaH;
  2819. }
  2820. else
  2821. {
  2822. *pHeight = pCD->maxHeightLimit;
  2823. deltaW = makemult (*pWidth - *pHeight * pCD->maxAspect.x /
  2824. pCD->maxAspect.y, widthInc);
  2825. if (*pWidth - deltaW >= pCD->minWidth)
  2826. {
  2827. *pWidth -= deltaW;
  2828. }
  2829. else
  2830. {
  2831. *pWidth = pCD->minWidth;
  2832. }
  2833. }
  2834. }
  2835. else
  2836. /*
  2837. * Candidate height < client height and candidate width <= client width.
  2838. * Try to decrease the client's width without violating bounds.
  2839. * If this fails, use minimum width and try to increase its height.
  2840. */
  2841. {
  2842. deltaW = makemult (*pWidth - *pHeight * pCD->maxAspect.x /
  2843. pCD->maxAspect.y, widthInc);
  2844. if (*pWidth - deltaW >= pCD->minWidth)
  2845. {
  2846. *pWidth -= deltaW;
  2847. }
  2848. else
  2849. {
  2850. *pWidth = pCD->minWidth;
  2851. deltaH = makemult (*pWidth * pCD->maxAspect.y /
  2852. pCD->maxAspect.x - *pHeight, heightInc);
  2853. if (*pHeight + deltaH <= pCD->maxHeightLimit ||
  2854. !pSD->limitResize ||
  2855. pCD->clientFlags & CLIENT_WM_CLIENTS)
  2856. {
  2857. *pHeight += deltaH;
  2858. }
  2859. else
  2860. {
  2861. *pHeight = pCD->maxHeightLimit;
  2862. }
  2863. }
  2864. }
  2865. }
  2866. else if ((pCD->sizeFlags & P_ASPECT) &&
  2867. *pHeight * pCD->minAspect.x > *pWidth * pCD->minAspect.y)
  2868. /*
  2869. * Client aspect is too small.
  2870. * Candidate width >= client width:
  2871. * Try to increase the client's width without violating bounds.
  2872. * If this fails, use maximum width and try to decrease its height.
  2873. * Candidate width < client width:
  2874. * Try to decrease the client's height without violating bounds.
  2875. * If this fails, use minimum height and try to increase its width.
  2876. */
  2877. {
  2878. if ((*pWidth >= pCD->clientWidth) ||
  2879. (*pHeight > pCD->clientHeight))
  2880. /*
  2881. * Candidate width >= client width:
  2882. * Try to increase the client's width without violating bounds.
  2883. * If this fails, use maximum width and try to decrease its height.
  2884. */
  2885. {
  2886. deltaW = makemult (*pHeight * pCD->minAspect.x / pCD->minAspect.y -
  2887. *pWidth, widthInc);
  2888. if (*pWidth + deltaW <= pCD->maxWidthLimit ||
  2889. !pSD->limitResize ||
  2890. pCD->clientFlags & CLIENT_WM_CLIENTS)
  2891. {
  2892. *pWidth += deltaW;
  2893. }
  2894. else
  2895. {
  2896. *pWidth = pCD->maxWidthLimit;
  2897. deltaH = makemult (*pHeight - *pWidth * pCD->minAspect.y /
  2898. pCD->minAspect.x, heightInc);
  2899. if (*pHeight - deltaH >= pCD->minHeight)
  2900. {
  2901. *pHeight -= deltaH;
  2902. }
  2903. else
  2904. {
  2905. *pHeight = pCD->minHeight;
  2906. }
  2907. }
  2908. }
  2909. else
  2910. /*
  2911. * Candidate width < client width and Candidate height <= client height:
  2912. * Try to decrease the client's height without violating bounds.
  2913. * If this fails, use minimum height and try to increase its width.
  2914. */
  2915. {
  2916. deltaH = makemult (*pHeight - *pWidth * pCD->minAspect.y /
  2917. pCD->minAspect.x, heightInc);
  2918. if (*pHeight - deltaH >= pCD->minHeight)
  2919. {
  2920. *pHeight -= deltaH;
  2921. }
  2922. else
  2923. {
  2924. *pHeight = pCD->minHeight;
  2925. deltaW = makemult (*pHeight * pCD->minAspect.x /
  2926. pCD->minAspect.y - *pWidth, widthInc);
  2927. if (*pWidth + deltaW <= pCD->maxWidthLimit ||
  2928. !pSD->limitResize ||
  2929. pCD->clientFlags & CLIENT_WM_CLIENTS)
  2930. {
  2931. *pWidth += deltaW;
  2932. }
  2933. else
  2934. {
  2935. *pWidth = pCD->maxWidthLimit;
  2936. }
  2937. }
  2938. }
  2939. }
  2940. } /* END OF FUNCTION FixWindowSize */
  2941. /*************************************<->*************************************
  2942. *
  2943. * FindClientPlacement (pCD)
  2944. *
  2945. *
  2946. * Description:
  2947. * -----------
  2948. * This function finds a position for the client window on the screen.
  2949. * Windows positions are stepped down the screen. An attempt is made
  2950. * to keep windows from being clipped by the edge of the screen.
  2951. *
  2952. *
  2953. * Inputs:
  2954. * ------
  2955. * pCD = pointer to client data (client window configuration fields)
  2956. *
  2957. *
  2958. * Outputs:
  2959. * -------
  2960. * pCD = changes to the client window configuration fields
  2961. *
  2962. *************************************<->***********************************/
  2963. void
  2964. FindClientPlacement (ClientData *pCD)
  2965. {
  2966. static Boolean clientPlacementInitialized = False;
  2967. static int clientPlacementOffset;
  2968. static int clientPlacementX;
  2969. static int clientPlacementY;
  2970. static int clientPlacementOrigin;
  2971. static int clientPlacementXOrigin;
  2972. Boolean placed = False;
  2973. int frameWidth;
  2974. int frameHeight;
  2975. int screenX;
  2976. int screenY;
  2977. int screenWidth;
  2978. int screenHeight;
  2979. int borderWidth = 0;
  2980. Boolean offScreenX;
  2981. Boolean offScreenY;
  2982. WmHeadInfo_t *WmHI = NULL;
  2983. if (!clientPlacementInitialized)
  2984. {
  2985. if (pCD->clientDecoration & WM_DECOR_RESIZEH)
  2986. {
  2987. borderWidth = ((RESIZE_BORDER_WIDTH(pCD) > FRAME_BORDER_WIDTH(pCD))
  2988. ? RESIZE_BORDER_WIDTH(pCD) : FRAME_BORDER_WIDTH(pCD));
  2989. }
  2990. else
  2991. {
  2992. borderWidth = pCD->matteWidth;
  2993. }
  2994. clientPlacementOffset = TitleTextHeight(pCD) + borderWidth;
  2995. clientPlacementOrigin = clientPlacementOffset;
  2996. clientPlacementX = clientPlacementOrigin;
  2997. clientPlacementY = clientPlacementOrigin;
  2998. clientPlacementXOrigin = clientPlacementX;
  2999. clientPlacementInitialized = True;
  3000. }
  3001. frameWidth = pCD->clientWidth + (2 * pCD->clientOffset.x);
  3002. frameHeight = pCD->clientHeight + pCD->clientOffset.y + pCD->clientOffset.x;
  3003. if (WmHI = GetHeadInfo(wmGD.keyboardFocus)) {
  3004. /* Use Head metrics for placeable area */
  3005. screenX = WmHI->x_org;
  3006. screenY = WmHI->y_org;
  3007. screenWidth = WmHI->width;
  3008. screenHeight = WmHI->height;
  3009. free(WmHI);
  3010. } else {
  3011. /* Use X Screen metrics for placeable area */
  3012. screenX = 0;
  3013. screenY = 0;
  3014. screenWidth = DisplayWidth (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  3015. screenHeight = DisplayHeight (DISPLAY, SCREEN_FOR_CLIENT(pCD));
  3016. }
  3017. while (!placed)
  3018. {
  3019. if ((clientPlacementX - pCD->clientOffset.x + frameWidth)
  3020. > screenWidth)
  3021. {
  3022. offScreenX = True;
  3023. }
  3024. else
  3025. {
  3026. offScreenX = False;
  3027. }
  3028. if ((clientPlacementY - pCD->clientOffset.y + frameHeight)
  3029. > screenHeight)
  3030. {
  3031. offScreenY = True;
  3032. }
  3033. else
  3034. {
  3035. offScreenY = False;
  3036. }
  3037. if (offScreenX || offScreenY)
  3038. {
  3039. if (clientPlacementX == clientPlacementOrigin)
  3040. {
  3041. /*
  3042. * Placement location is already as far to the NW as it is
  3043. * going to go.
  3044. */
  3045. placed = True;
  3046. }
  3047. else if (clientPlacementY == clientPlacementOrigin)
  3048. {
  3049. /*
  3050. * Placement location is as far to the N as it is going to go.
  3051. * Use the current placement if the window is not off the
  3052. * screen in the x coordinate otherwise reset the placement
  3053. * back to the NW origin.
  3054. */
  3055. if (offScreenX)
  3056. {
  3057. clientPlacementXOrigin = clientPlacementOrigin;
  3058. clientPlacementX = clientPlacementXOrigin;
  3059. }
  3060. placed = True;
  3061. }
  3062. else
  3063. {
  3064. /*
  3065. * If window is off the right edge of screen, just move
  3066. * window in the X direction onto screen. Process similarly
  3067. * for windows that are off the bottom of the screen.
  3068. */
  3069. if (offScreenX && !offScreenY)
  3070. {
  3071. clientPlacementX = clientPlacementOrigin;
  3072. }
  3073. else if (offScreenY && !offScreenX)
  3074. {
  3075. clientPlacementY = clientPlacementOrigin;
  3076. }
  3077. else
  3078. {
  3079. /*
  3080. * Reset the placement location back to the NW of the
  3081. * current location. Go as far N as possible and step the
  3082. * x coordinate to the E.
  3083. */
  3084. clientPlacementXOrigin += clientPlacementOffset;
  3085. clientPlacementX = clientPlacementXOrigin;
  3086. clientPlacementY = clientPlacementOrigin;
  3087. }
  3088. }
  3089. }
  3090. else
  3091. {
  3092. placed = True;
  3093. }
  3094. }
  3095. /*
  3096. * The window has been placed, now update the placement information.
  3097. */
  3098. pCD->clientX = clientPlacementX + screenX;
  3099. pCD->clientY = clientPlacementY + screenY;
  3100. clientPlacementX += clientPlacementOffset;
  3101. if (clientPlacementX >= screenWidth)
  3102. {
  3103. clientPlacementXOrigin = clientPlacementOrigin;
  3104. clientPlacementX = clientPlacementXOrigin;
  3105. }
  3106. clientPlacementY += clientPlacementOffset;
  3107. /*
  3108. * Reset Y position to top of screen so that windows start new column of
  3109. * placement that is offset from the previous column. Previously, the new
  3110. * column was place right over the old column, obscuring it.
  3111. * NOTE: column == diagonal
  3112. */
  3113. if (clientPlacementY >= (screenHeight / 3))
  3114. {
  3115. clientPlacementY = clientPlacementOrigin;
  3116. }
  3117. } /* END OF FUNCTION FindClientPlacement */
  3118. /*************************************<->*************************************
  3119. *
  3120. * WmGetWindowAttributes (window)
  3121. *
  3122. *
  3123. * Description:
  3124. * -----------
  3125. * This function gets window attributes if necessary and saves them in the
  3126. * global window attribute cache. If the window attributes are already
  3127. * there then no X call is made.
  3128. *
  3129. *
  3130. * Inputs:
  3131. * ------
  3132. * window = get attributes for window with this id
  3133. *
  3134. *
  3135. * Outputs:
  3136. * -------
  3137. * wmGD.attributesWindow = set to window that matches windowAttributes
  3138. *
  3139. * wmGD.windowAttributes = XWindowAttributes of window
  3140. *
  3141. *
  3142. * Comments:
  3143. * --------
  3144. * The attributes in the global cache are (known) current only for a
  3145. * single pass through the wm event processing loop. They (should be)
  3146. * regularly cleared.
  3147. *
  3148. *************************************<->***********************************/
  3149. Boolean
  3150. WmGetWindowAttributes (Window window)
  3151. {
  3152. if (wmGD.attributesWindow != window)
  3153. {
  3154. if (!XGetWindowAttributes (DISPLAY, window, &wmGD.windowAttributes))
  3155. {
  3156. /*
  3157. * Cannot get window attributes.
  3158. */
  3159. wmGD.attributesWindow = (Window)0L;
  3160. return (False);
  3161. }
  3162. wmGD.attributesWindow = window;
  3163. }
  3164. return (True);
  3165. } /* END OF FUNCTION WmGetWindowAttributes */
  3166. /*************************************<->*************************************
  3167. *
  3168. * SetupClientIconWindow (pCD, window)
  3169. *
  3170. *
  3171. * Description:
  3172. * -----------
  3173. * This function prepares a client supplied icon window for insertion into
  3174. * a window manager icon frame.
  3175. *
  3176. *
  3177. * Inputs:
  3178. * ------
  3179. * pCD = pointer to client data
  3180. *
  3181. * window = client supplied icon window
  3182. *
  3183. *
  3184. * Outputs:
  3185. * -------
  3186. * pCD = (iconWindow)
  3187. *
  3188. * Return = True if the icon window can be used
  3189. *
  3190. *************************************<->***********************************/
  3191. Boolean
  3192. SetupClientIconWindow (ClientData *pCD, Window window)
  3193. {
  3194. ClientData *pcd;
  3195. /*
  3196. * Check to see if the icon window can be used (i.e there is no conflict
  3197. * of interest.
  3198. */
  3199. if (!XFindContext (DISPLAY, window, wmGD.windowContextType,
  3200. (caddr_t *)&pcd))
  3201. {
  3202. if (window == pCD->client)
  3203. {
  3204. /*
  3205. * The proposed icon window is the same as the client!
  3206. */
  3207. return (False);
  3208. }
  3209. /*
  3210. * The proposed icon window is already being managed.
  3211. * Assume that we managed it by mistake. Unmanage the
  3212. * window and use it as the icon window for this client.
  3213. */
  3214. UnManageWindow (pcd);
  3215. }
  3216. /* update client data */
  3217. pCD->iconWindow = window;
  3218. /* put in window manager's save set */
  3219. XChangeSaveSet (DISPLAY, pCD->iconWindow, SetModeInsert);
  3220. pCD->clientFlags |= ICON_IN_SAVE_SET;
  3221. return (True);
  3222. } /* END OF FUNCTION SetupClientIconWindow */
  3223. /*************************************<->*************************************
  3224. *
  3225. * ProcessMwmHints (pCD)
  3226. *
  3227. *
  3228. * Description:
  3229. * -----------
  3230. * Process the _MWM_HINTS property on the window (if any). Setup the
  3231. * applicable function and decoration masks.
  3232. *
  3233. *
  3234. * Inputs:
  3235. * ------
  3236. * pCD = pointer to client data
  3237. *
  3238. *
  3239. * Outputs:
  3240. * -------
  3241. * pCD = may be changed.
  3242. *
  3243. *************************************<->***********************************/
  3244. void
  3245. ProcessMwmHints (ClientData *pCD)
  3246. {
  3247. PropMwmHints *pHints;
  3248. /*
  3249. * Fix the client functions and decorations fields if they have
  3250. * default resource values.
  3251. */
  3252. if (pCD->clientFunctions & WM_FUNC_DEFAULT)
  3253. {
  3254. if (pCD->clientFlags & CLIENT_TRANSIENT)
  3255. {
  3256. pCD->clientFunctions = TRANSIENT_FUNCTIONS(pCD);
  3257. }
  3258. else
  3259. {
  3260. pCD->clientFunctions = WM_FUNC_ALL;
  3261. }
  3262. if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL)
  3263. {
  3264. pCD->clientFunctions &= WM_FUNC_SUBPANEL_DEFAULT;
  3265. pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
  3266. }
  3267. else if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_PANEL)
  3268. {
  3269. pCD->clientFunctions &= WM_FUNC_PANEL_DEFAULT;
  3270. pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
  3271. }
  3272. }
  3273. if (pCD->clientDecoration & WM_DECOR_DEFAULT)
  3274. {
  3275. if (pCD->clientFlags & CLIENT_TRANSIENT)
  3276. {
  3277. pCD->clientDecoration = TRANSIENT_DECORATION(pCD);
  3278. }
  3279. else
  3280. {
  3281. pCD->clientDecoration = WM_DECOR_ALL;
  3282. }
  3283. if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_SUBPANEL)
  3284. {
  3285. pCD->clientDecoration = pCD->pSD->subpanelDecoration;
  3286. }
  3287. else if (pCD->dtwmBehaviors & DtWM_BEHAVIOR_PANEL)
  3288. {
  3289. pCD->clientDecoration &= WM_DECOR_PANEL_DEFAULT;
  3290. }
  3291. }
  3292. /*
  3293. * Retrieve the _MWM_HINTS property if it exists.
  3294. */
  3295. pCD->inputMode = MWM_INPUT_MODELESS;
  3296. if ((pHints = GetMwmHints (pCD)) != NULL)
  3297. {
  3298. if (pHints->flags & MWM_HINTS_FUNCTIONS)
  3299. {
  3300. if (pHints->functions & MWM_FUNC_ALL)
  3301. {
  3302. /* client indicating inapplicable functions */
  3303. pCD->clientFunctions &= ~(pHints->functions);
  3304. }
  3305. else
  3306. {
  3307. /* client indicating applicable functions */
  3308. pCD->clientFunctions &= pHints->functions;
  3309. }
  3310. #if 0
  3311. if (!(pCD->clientFlags & GOT_DT_WM_HINTS) &&
  3312. !pHints->functions)
  3313. {
  3314. /*
  3315. * !!! Backward compatibility heurisitic !!!
  3316. *
  3317. * If client doesn't want any functions and
  3318. * no DT_WM_HINTS specified, then remove
  3319. * workspace functions.
  3320. */
  3321. pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
  3322. }
  3323. #endif
  3324. /* !!! check for some minimal level of functionality? !!! */
  3325. }
  3326. if (pHints->flags & MWM_HINTS_DECORATIONS)
  3327. {
  3328. if (pHints->decorations & MWM_DECOR_ALL)
  3329. {
  3330. /* client indicating decorations to be removed */
  3331. pCD->clientDecoration &= ~(pHints->decorations);
  3332. }
  3333. else
  3334. {
  3335. /* client indicating decorations to be added */
  3336. pCD->clientDecoration &= pHints->decorations;
  3337. }
  3338. /*
  3339. * Fix up decoration configuration.
  3340. */
  3341. if (pCD->clientDecoration &
  3342. (MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE))
  3343. {
  3344. pCD->clientDecoration |= MWM_DECOR_TITLE;
  3345. }
  3346. if (pCD->clientDecoration & MWM_DECOR_RESIZEH)
  3347. {
  3348. pCD->clientDecoration |= MWM_DECOR_BORDER;
  3349. }
  3350. }
  3351. if (pHints->flags & MWM_HINTS_INPUT_MODE)
  3352. {
  3353. if ((pHints->inputMode == MWM_INPUT_PRIMARY_APPLICATION_MODAL) ||
  3354. (pHints->inputMode == MWM_INPUT_FULL_APPLICATION_MODAL) ||
  3355. ((pHints->inputMode == MWM_INPUT_SYSTEM_MODAL) &&
  3356. !wmGD.systemModalActive))
  3357. {
  3358. pCD->inputMode = pHints->inputMode;
  3359. }
  3360. /*
  3361. * Don't allow a system modal window to be a secondary window
  3362. * (except with respect to applicable functions and frame
  3363. * decorations). Also, don't allow system modal window to
  3364. * be minimized.
  3365. */
  3366. if (pCD->inputMode == MWM_INPUT_SYSTEM_MODAL)
  3367. {
  3368. pCD->transientLeader = NULL;
  3369. if (pCD->clientFunctions & MWM_FUNC_MINIMIZE)
  3370. {
  3371. pCD->clientFunctions &= ~(MWM_FUNC_MINIMIZE);
  3372. }
  3373. }
  3374. }
  3375. if (pHints->flags & MWM_HINTS_STATUS)
  3376. {
  3377. pCD->window_status = pHints->status;
  3378. }
  3379. XFree ((char*)pHints);
  3380. }
  3381. else
  3382. {
  3383. ProcessOLDecoration (pCD);
  3384. }
  3385. /*
  3386. * If primary window can't move between workspaces, then
  3387. * secondary window shouldn't either.
  3388. */
  3389. if (pCD->transientLeader &&
  3390. !(pCD->transientLeader->dtwmFunctions & DtWM_FUNCTION_OCCUPY_WS))
  3391. {
  3392. pCD->dtwmFunctions &= ~DtWM_FUNCTION_OCCUPY_WS;
  3393. }
  3394. /*
  3395. * Fix up functions based on system modal settings. System modal
  3396. * windows and their descendents cannot be minimized.
  3397. */
  3398. if (!((FindTransientTreeLeader (pCD))->clientFunctions&MWM_FUNC_MINIMIZE))
  3399. {
  3400. pCD->clientFunctions &= ~MWM_FUNC_MINIMIZE;
  3401. }
  3402. /*
  3403. * Fix up decoration configuration based on applicable functions.
  3404. */
  3405. if (!(pCD->clientFunctions & MWM_FUNC_RESIZE))
  3406. {
  3407. pCD->clientDecoration &= ~MWM_DECOR_RESIZEH;
  3408. }
  3409. if (!(pCD->clientFunctions & MWM_FUNC_MINIMIZE))
  3410. {
  3411. pCD->clientDecoration &= ~MWM_DECOR_MINIMIZE;
  3412. }
  3413. if (!(pCD->clientFunctions & MWM_FUNC_MAXIMIZE))
  3414. {
  3415. pCD->clientDecoration &= ~MWM_DECOR_MAXIMIZE;
  3416. }
  3417. pCD->decor = pCD->clientDecoration; /* !!! combine decor ... !!! */
  3418. } /* END OF ProcessMwmHints */