WmWinInfo.c 97 KB

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