WmCEvent.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738
  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, 1994 OPEN SOFTWARE FOUNDATION, INC.
  25. * ALL RIGHTS RESERVED
  26. */
  27. /*
  28. * Motif Release 1.2.4
  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 <X11/Xatom.h>
  38. /*
  39. * include extern functions
  40. */
  41. #include "WmCEvent.h"
  42. #include "WmCDecor.h"
  43. #include "WmColormap.h"
  44. #include "WmEvent.h"
  45. #include "WmFeedback.h"
  46. #include "WmFunction.h"
  47. #include "WmIDecor.h"
  48. #include "WmKeyFocus.h"
  49. #include "WmPanelP.h"
  50. #include "WmManage.h"
  51. #include "WmMenu.h"
  52. #include "WmProperty.h"
  53. #include "WmProtocol.h"
  54. #include "WmWinConf.h"
  55. #include "WmWinInfo.h"
  56. #include "WmWinList.h"
  57. #include "WmWinState.h"
  58. #include "WmWrkspace.h"
  59. /*
  60. * Global Variables:
  61. */
  62. extern unsigned int buttonModifierMasks[];
  63. /*************************************<->*************************************
  64. *
  65. * SetupCButtonBindings (window, buttonSpecs)
  66. *
  67. *
  68. * Description:
  69. * -----------
  70. * This function sets up the event handling necessary to support user
  71. * specified button bindings for window manager functions that apply to
  72. * the client window.
  73. *
  74. *
  75. * Inputs:
  76. * ------
  77. * window = grab window id
  78. *
  79. * buttonSpecs = list of button bindings for window manager functions
  80. *
  81. *************************************<->***********************************/
  82. void SetupCButtonBindings (Window window, ButtonSpec *buttonSpecs)
  83. {
  84. ButtonSpec *buttonSpec;
  85. unsigned int eventMask;
  86. unsigned int grabState;
  87. /*
  88. * If the context of the button binding includes "window" do button
  89. * grabs to get the button events that invoke window manger functions.
  90. * !!! don't do redundant grabs !!!
  91. */
  92. buttonSpec = buttonSpecs;
  93. while (buttonSpec)
  94. {
  95. if ((buttonSpec->context & F_CONTEXT_WINDOW) &&
  96. (buttonSpec->subContext & F_SUBCONTEXT_W_CLIENT))
  97. {
  98. eventMask = ButtonMotionMask | ButtonReleaseMask;
  99. if (buttonSpec->eventType == ButtonRelease)
  100. {
  101. /*
  102. * Don't include the button down in the grab state.
  103. */
  104. grabState = buttonSpec->state &
  105. ~(buttonModifierMasks[buttonSpec->button]);
  106. }
  107. else
  108. {
  109. grabState = buttonSpec->state;
  110. }
  111. WmGrabButton (DISPLAY, buttonSpec->button, grabState,
  112. window, False, eventMask, GrabModeSync,
  113. GrabModeAsync, None, None);
  114. }
  115. /*
  116. * If the window context is not "window" a general grab is not
  117. * necessary.
  118. */
  119. buttonSpec = buttonSpec->nextButtonSpec;
  120. }
  121. } /* END OF FUNCTION SetupCButtonBindings */
  122. /*************************************<->*************************************
  123. *
  124. * WmDispatchClientEvent (event)
  125. *
  126. *
  127. * Description:
  128. * -----------
  129. * This function detects and dispatches events that are reported to a client
  130. * frame or icon window that are not widget-related (i.e. they would not be
  131. * dispatched by the Xtk intrinsics).
  132. *
  133. *
  134. * Inputs:
  135. * ------
  136. * event = This is an X event that has been retrieved by XtNextEvent.
  137. *
  138. *
  139. * Outputs:
  140. * -------
  141. * RETURN = If True the event should be dispatched by the toolkit,
  142. * otherwise the event should not be dispatched.
  143. *
  144. *************************************<->***********************************/
  145. Boolean WmDispatchClientEvent (XEvent *event)
  146. {
  147. ClientData * pCD = NULL;
  148. #ifndef IBM_169380
  149. ClientData **cmap_window_data = NULL;
  150. #endif
  151. Boolean dispatchEvent = False;
  152. /*
  153. * Detect and dispatch non-widget events that have been reported to
  154. * an icon or a client window frame.
  155. */
  156. #ifndef IBM_169380
  157. if ((XFindContext (DISPLAY, event->xany.window, wmGD.windowContextType,
  158. (caddr_t *)&pCD)) &&
  159. (XFindContext (DISPLAY, event->xany.window, wmGD.cmapWindowContextType,
  160. (caddr_t *)&cmap_window_data)))
  161. #else
  162. if (XFindContext (DISPLAY, event->xany.window, wmGD.windowContextType,
  163. (caddr_t *)&pCD))
  164. #endif
  165. {
  166. /*
  167. * Set active screen if we're not sure.
  168. */
  169. if (wmGD.queryScreen)
  170. DetermineActiveScreen (event);
  171. /*
  172. * Handle events on windows that are made by mwm for
  173. * non-client-specific functions. Also handle "leftover"
  174. * events on windows that used to be managed by mwm
  175. * (e.g. ConfigureRequest events).
  176. */
  177. return (HandleEventsOnSpecialWindows (event));
  178. }
  179. #ifndef IBM_169380
  180. if (cmap_window_data)
  181. /*
  182. * Event is on a subwindow that is specified in one or more toplevel
  183. * window's WM_COLORMAP_WINDOWS property. (Most likely this is a
  184. * ColormapNotify event.) It could have more than one pCD associated
  185. * with it, so we have to choose one. If one of the pCD's currently has
  186. * the Colormap Focus, then let's use that one. Otherwise, just use
  187. * the 1st one.
  188. */
  189. {
  190. int j;
  191. for (j = 0; cmap_window_data[j]; j++)
  192. {
  193. if (ACTIVE_PSD->colormapFocus == cmap_window_data[j])
  194. {
  195. pCD = cmap_window_data[j];
  196. break;
  197. }
  198. }
  199. /*
  200. * None of the pCD's in the list have Colormap Focus. So, just
  201. * set pCD to the 1st one in the list.
  202. */
  203. if (!pCD)
  204. pCD = cmap_window_data[0];
  205. }
  206. #endif
  207. /*
  208. * Set active screen if this is not a FocusOut event.
  209. * We don't need to set it on focus out AND we use
  210. * (SCREEN_FOR_CLIENT(pCD) != ACTIVE_SCREEN) in
  211. * in HandleCFocusOut to determine if a new colormap needs
  212. * to be installed.
  213. */
  214. if (!(event->type == FocusOut))
  215. {
  216. SetActiveScreen (PSD_FOR_CLIENT(pCD));
  217. }
  218. /* Get workspace specific client data */
  219. SetClientWsIndex (pCD);
  220. /*
  221. * Handle events on top-level client windows.
  222. */
  223. if (event->xany.window == pCD->client)
  224. {
  225. return (HandleEventsOnClientWindow (pCD, event));
  226. }
  227. /*
  228. * Handle events on windows created by mwm (for icons and client window
  229. * frames) and on non-top-level client windows (e.g., colormap
  230. * windows).
  231. */
  232. switch (event->type)
  233. {
  234. case ButtonPress:
  235. {
  236. dispatchEvent = HandleCButtonPress (pCD, (XButtonEvent *)event);
  237. break;
  238. }
  239. case ButtonRelease:
  240. {
  241. if (wmGD.menuActive)
  242. {
  243. dispatchEvent = True; /* have the toolkit dispatch the event */
  244. }
  245. else
  246. {
  247. HandleCButtonRelease (pCD, (XButtonEvent *)event);
  248. }
  249. break;
  250. }
  251. case KeyPress:
  252. {
  253. dispatchEvent = HandleCKeyPress (pCD, (XKeyEvent *)event);
  254. break;
  255. }
  256. case MotionNotify:
  257. {
  258. HandleCMotionNotify (pCD, (XMotionEvent *)event);
  259. break;
  260. }
  261. case Expose:
  262. {
  263. /*
  264. * If multiple expose events, wait for last one.
  265. */
  266. if (event->xexpose.count == 0)
  267. {
  268. if (event->xexpose.window == ICON_FRAME_WIN(pCD))
  269. {
  270. IconExposureProc (pCD, True);
  271. if (P_ICON_BOX(pCD))
  272. {
  273. dispatchEvent = True;
  274. }
  275. }
  276. else if (event->xexpose.window ==
  277. pCD->pSD->activeIconTextWin)
  278. {
  279. PaintActiveIconText (pCD, FALSE);
  280. }
  281. else if (!(pCD->clientFlags & CLIENT_DESTROYED))
  282. {
  283. if ((event->xexpose.window == pCD->clientFrameWin) ||
  284. (event->xexpose.window == pCD->clientTitleWin))
  285. {
  286. FrameExposureProc (pCD);
  287. }
  288. if (event->xexpose.window == pCD->clientBaseWin)
  289. {
  290. BaseWinExposureProc (pCD);
  291. }
  292. }
  293. else if (pCD->clientFlags & FRONT_PANEL_BOX)
  294. {
  295. /*
  296. *
  297. * Then this client is the shell for the
  298. * front panel and we want the toolkit to repaint
  299. * it.
  300. *
  301. */
  302. dispatchEvent = True;
  303. }
  304. }
  305. break;
  306. }
  307. case EnterNotify:
  308. {
  309. HandleCEnterNotify (pCD, (XEnterWindowEvent *)event);
  310. break;
  311. }
  312. case LeaveNotify:
  313. {
  314. HandleCLeaveNotify (pCD, (XLeaveWindowEvent *)event);
  315. break;
  316. }
  317. case FocusIn:
  318. {
  319. dispatchEvent = HandleCFocusIn (pCD, (XFocusChangeEvent *)event);
  320. break;
  321. }
  322. case FocusOut:
  323. {
  324. dispatchEvent = HandleCFocusOut (pCD, (XFocusChangeEvent *)event);
  325. break;
  326. }
  327. case DestroyNotify:
  328. {
  329. if (((XDestroyWindowEvent *)event)->window == pCD->client)
  330. {
  331. pCD->clientFlags |= CLIENT_DESTROYED;
  332. UnManageWindow (pCD);
  333. }
  334. break;
  335. }
  336. case UnmapNotify:
  337. {
  338. /*
  339. * This event is generated when a managed client window is
  340. * unmapped by the client or when the window manager unmaps the
  341. * client window; check the wmMapCount to determine if this is
  342. * the result of a window manager unmap. If this is a client
  343. * unmap then the window is to be withdrawn from window manager
  344. * control.
  345. */
  346. if (((XUnmapEvent *)event)->window == pCD->client)
  347. {
  348. if (pCD->wmUnmapCount)
  349. {
  350. pCD->wmUnmapCount--;
  351. }
  352. else
  353. {
  354. UnManageWindow (pCD);
  355. }
  356. }
  357. break;
  358. }
  359. case MapRequest:
  360. {
  361. /*
  362. * This is a request to change the state of the client window from
  363. * iconic (minimized) to normal.
  364. */
  365. if (!ClientInWorkspace (ACTIVE_WS, pCD))
  366. {
  367. if (pCD->absentMapBehavior == AMAP_BEHAVIOR_IGNORE)
  368. {
  369. SetClientState (pCD, NORMAL_STATE|UNSEEN_STATE,
  370. GetTimestamp ());
  371. }
  372. else
  373. {
  374. HonorAbsentMapBehavior(pCD);
  375. SetClientState (pCD, NORMAL_STATE, GetTimestamp ());
  376. }
  377. }
  378. else
  379. {
  380. SetClientState (pCD, NORMAL_STATE, GetTimestamp ());
  381. }
  382. break;
  383. }
  384. case ConfigureRequest:
  385. {
  386. HandleCConfigureRequest (pCD, (XConfigureRequestEvent *)event);
  387. break;
  388. }
  389. case ColormapNotify:
  390. {
  391. /*
  392. * Process changes to client window colormaps:
  393. */
  394. HandleCColormapNotify (pCD, (XColormapEvent *)event);
  395. break;
  396. }
  397. case ClientMessage:
  398. {
  399. /*
  400. * Handle client message events.
  401. */
  402. HandleClientMessage (pCD, (XClientMessageEvent *)event);
  403. break;
  404. }
  405. case ReparentNotify:
  406. {
  407. if ((((XReparentEvent *)event)->window == pCD->client) &&
  408. (((XReparentEvent *)event)->parent != pCD->clientBaseWin))
  409. {
  410. /*
  411. * The window was reparented away from the frame.
  412. * Unmanage to clean up the now empty frame.
  413. *
  414. * Note: We get here when the reparent is done while
  415. * the client is unmapped (e.g. iconified). Otherwise
  416. * the reparent will generate an UnmapNotify which
  417. * will also cause us to unmanage the client.
  418. */
  419. UnManageWindow (pCD);
  420. }
  421. break;
  422. }
  423. } /* end of event.type switch */
  424. return (dispatchEvent);
  425. } /* END OF FUNCTION WmDispatchClientEvent */
  426. /*************************************<->*************************************
  427. *
  428. * HandleEventsOnSpecialWindows (pEvent)
  429. *
  430. *
  431. * Description:
  432. * -----------
  433. * Handles events on special window manager windows and "leftover" events
  434. * from destroyed client window frames.
  435. *
  436. *
  437. * Inputs:
  438. * ------
  439. * pEvent = pointer to an XEvent structure
  440. *
  441. *
  442. * Outputs:
  443. * -------
  444. * RETURN = If True the event should be dispatched by the toolkit,
  445. * otherwise the event should not be dispatched.
  446. *
  447. *************************************<->***********************************/
  448. Boolean HandleEventsOnSpecialWindows (XEvent *pEvent)
  449. {
  450. Boolean dispatchEvent = True;
  451. WmScreenData *pSD;
  452. /*
  453. * The window is not a root window or a client frame window. Check for
  454. * a special window manager window. Have the toolkit dispatch the event
  455. * if the event is not on a special window.
  456. */
  457. if (pEvent->xany.window == ACTIVE_ROOT)
  458. {
  459. if (pEvent->type == FocusIn)
  460. {
  461. SetKeyboardFocus ((ClientData *) NULL, REFRESH_LAST_FOCUS);
  462. }
  463. }
  464. else if (pEvent->xany.window == ACTIVE_PSD->feedbackWin)
  465. {
  466. if (pEvent->type == Expose)
  467. {
  468. if (pEvent->xexpose.count == 0)
  469. {
  470. PaintFeedbackWindow(ACTIVE_PSD);
  471. }
  472. }
  473. dispatchEvent = False; /* don't have the toolkit dispatch the event */
  474. }
  475. else if (pEvent->xany.window == ACTIVE_PSD->inputScreenWindow)
  476. {
  477. if (pEvent->type == ButtonPress)
  478. {
  479. F_Beep (NULL, (ClientData *) NULL, (XEvent *) NULL);
  480. }
  481. else if ((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) &&
  482. (pEvent->type == EnterNotify))
  483. {
  484. HandleWsEnterNotify ((XEnterWindowEvent *)pEvent);
  485. }
  486. dispatchEvent = False; /* don't have the toolkit dispatch the event */
  487. }
  488. else if (!XFindContext (DISPLAY, pEvent->xany.window,
  489. wmGD.mwmWindowContextType, (caddr_t *)&pSD))
  490. {
  491. if ((pEvent->type == PropertyNotify) &&
  492. (pEvent->xproperty.atom == wmGD.xa_DT_WM_REQUEST) &&
  493. (pEvent->xproperty.state == PropertyNewValue))
  494. {
  495. HandleDtWmRequest (pSD, pEvent);
  496. }
  497. if (pEvent->type == ClientMessage)
  498. {
  499. HandleDtWmClientMessage ((XClientMessageEvent *)pEvent);
  500. }
  501. }
  502. else
  503. {
  504. /*
  505. * Events may come in for a client frame base window that no
  506. * longer exists (the client window was just unmanaged but the
  507. * the client did some action before the un-reparenting was
  508. * actually done). Confirm that this is the case and then
  509. * handle the request as if it came in as a root window event.
  510. */
  511. switch (pEvent->type)
  512. {
  513. case ConfigureRequest:
  514. {
  515. if (GetParentWindow (pEvent->xconfigurerequest.window) ==
  516. ACTIVE_ROOT)
  517. {
  518. /*
  519. * This is an event for a client base window that
  520. * no longer exists. Handle the event as if it is a
  521. * root window event.
  522. */
  523. dispatchEvent = WmDispatchWsEvent (pEvent);
  524. }
  525. break;
  526. }
  527. case MapRequest:
  528. {
  529. if (GetParentWindow (pEvent->xmaprequest.window) ==
  530. ACTIVE_ROOT)
  531. {
  532. /*
  533. * This is an event for a client base window that
  534. * no longer exists. Handle the event as if it is a
  535. * root window event.
  536. */
  537. dispatchEvent = WmDispatchWsEvent (pEvent);
  538. }
  539. break;
  540. }
  541. }
  542. }
  543. return (dispatchEvent);
  544. } /* END OF FUNCTION HandleEventsOnSpecialWindows */
  545. /*************************************<->*************************************
  546. *
  547. * HandleEventsOnClientWindow (pCD, pEvent)
  548. *
  549. *
  550. * Description:
  551. * -----------
  552. * Handles events on a client top-level window.
  553. *
  554. *
  555. * Inputs:
  556. * ------
  557. * pCD = pointer to client data
  558. *
  559. * pEvent = pointer to an XEvent structure
  560. *
  561. *
  562. * Outputs:
  563. * -------
  564. * RETURN = If True the event should be dispatched by the toolkit,
  565. * otherwise the event should not be dispatched.
  566. *
  567. *************************************<->***********************************/
  568. Boolean HandleEventsOnClientWindow (ClientData *pCD, XEvent *pEvent)
  569. {
  570. Boolean doXtDispatchEvent = True;
  571. if (pEvent->type == (wmGD.shapeEventBase+ShapeNotify))
  572. {
  573. HandleCShapeNotify (pCD, (XShapeEvent *)pEvent);
  574. }
  575. else
  576. switch (pEvent->type)
  577. {
  578. case ColormapNotify:
  579. {
  580. /*
  581. * Process changes to top-level client window colormaps:
  582. */
  583. HandleCColormapNotify (pCD, (XColormapEvent *)pEvent);
  584. doXtDispatchEvent = False;
  585. break;
  586. }
  587. case PropertyNotify:
  588. {
  589. /*
  590. * Process property changes on managed client windows:
  591. */
  592. HandleCPropertyNotify (pCD, (XPropertyEvent *)pEvent);
  593. doXtDispatchEvent = False;
  594. break;
  595. }
  596. case ClientMessage:
  597. {
  598. /*
  599. * Handle client message events.
  600. */
  601. HandleClientMessage (pCD, (XClientMessageEvent *)pEvent);
  602. break;
  603. }
  604. }
  605. return (doXtDispatchEvent);
  606. } /* END OF FUNCTION HandleEventsOnClientWindow */
  607. /*************************************<->*************************************
  608. *
  609. * HandleCPropertyNotify (pCD, propertyEvent)
  610. *
  611. *
  612. * Description:
  613. * -----------
  614. * This function handles propertyNotify events (indicating window property
  615. * changes) that are reported to the client window.
  616. *
  617. *
  618. * Inputs:
  619. * ------
  620. * pCD = pointer to the client data for the client window that got the event
  621. *
  622. * propertyEvent = propertyNotify event that was received
  623. *
  624. *************************************<->***********************************/
  625. void HandleCPropertyNotify (ClientData *pCD, XPropertyEvent *propertyEvent)
  626. {
  627. switch (propertyEvent->atom)
  628. {
  629. case XA_WM_HINTS:
  630. {
  631. ProcessWmHints (pCD, FALSE /*not first time*/);
  632. break;
  633. }
  634. case XA_WM_NORMAL_HINTS:
  635. {
  636. ProcessWmNormalHints (pCD, FALSE /*not first time*/, 0);
  637. break;
  638. }
  639. case XA_WM_NAME:
  640. {
  641. ProcessWmWindowTitle (pCD, FALSE /*not first time*/);
  642. break;
  643. }
  644. case XA_WM_ICON_NAME:
  645. {
  646. ProcessWmIconTitle (pCD, FALSE /*not first time*/);
  647. break;
  648. }
  649. case XA_WM_CLASS:
  650. {
  651. break;
  652. }
  653. case XA_WM_COMMAND:
  654. {
  655. if (pCD->clientFlags & CLIENT_TERMINATING)
  656. {
  657. DeleteClientWmTimers (pCD);
  658. XKillClient (DISPLAY, pCD->client);
  659. }
  660. break;
  661. }
  662. case XA_WM_TRANSIENT_FOR:
  663. {
  664. /*
  665. * here we handle the special case of dialogs that are
  666. * mapped before the windows they are transient for are
  667. * mapped. Xm handles this case by waiting for the
  668. * transient_for window to appear before setting the
  669. * WM_TRANSIENT_FOR property on the dialog. Mwm has to
  670. * notice this property change and re-organize things
  671. * so the dialog is treated as a transient window.
  672. *
  673. * Note that we also handle the case of the WM_TRANSIENT_FOR
  674. * property being removed.
  675. */
  676. DeleteClientFromList (pCD->pSD->pActiveWS, pCD);
  677. ProcessWmTransientFor(pCD);
  678. AddClientToList(pCD->pSD->pActiveWS, pCD, True);
  679. if (pCD->transientLeader != NULL)
  680. StackTransientWindow(pCD);
  681. break;
  682. }
  683. default:
  684. {
  685. if (propertyEvent->atom == wmGD.xa_WM_PROTOCOLS)
  686. {
  687. ProcessWmProtocols (pCD);
  688. }
  689. else if (propertyEvent->atom == wmGD.xa_DT_WORKSPACE_HINTS)
  690. {
  691. (void) ProcessWorkspaceHints (pCD);
  692. }
  693. else if (propertyEvent->atom == wmGD.xa_MWM_MESSAGES)
  694. {
  695. if (pCD->protocolFlags & PROTOCOL_MWM_MESSAGES)
  696. {
  697. ProcessMwmMessages (pCD);
  698. }
  699. }
  700. else if (propertyEvent->atom == wmGD.xa_SM_CLIENT_ID)
  701. {
  702. ProcessSmClientID(pCD);
  703. }
  704. else if (propertyEvent->atom == wmGD.xa_WMSAVE_HINT)
  705. {
  706. ProcessWmSaveHint(pCD);
  707. }
  708. else if (propertyEvent->atom == wmGD.xa_WM_COLORMAP_WINDOWS)
  709. {
  710. if (propertyEvent->state == PropertyNewValue)
  711. {
  712. ProcessWmColormapWindows (pCD);
  713. }
  714. else
  715. {
  716. /* property was deleted */
  717. ResetColormapData (pCD, NULL, 0);
  718. }
  719. if ((ACTIVE_PSD->colormapFocus == pCD) &&
  720. ((pCD->clientState == NORMAL_STATE) ||
  721. (pCD->clientState == MAXIMIZED_STATE)))
  722. {
  723. /*
  724. * The client window has the colormap focus, install the
  725. * colormap.
  726. */
  727. /*
  728. * We just changed the colormaps list,
  729. * so we need to re-run the whole thing.
  730. */
  731. pCD->clientCmapFlagsInitialized = 0;
  732. ProcessColormapList (ACTIVE_PSD, pCD);
  733. }
  734. }
  735. break;
  736. }
  737. }
  738. } /* END OF FUNCTION HandleCPropertyNotify */
  739. /*************************************<->*************************************
  740. *
  741. * HandleCButtonPress (pCD, buttonEvent)
  742. *
  743. *
  744. * Description:
  745. * -----------
  746. * This function does window management actions associated with a button
  747. * press event on the client window (including frame) or icon.
  748. *
  749. *
  750. * Inputs:
  751. * ------
  752. * pCD = pointer to client data (identifies client window)
  753. *
  754. * buttonEvent = ButtonPress event on client window
  755. *
  756. *
  757. * Outputs:
  758. * -------
  759. * RETURN = True if the event should be dispatched by XtDispatchEvent
  760. *
  761. *************************************<->***********************************/
  762. Boolean HandleCButtonPress (ClientData *pCD, XButtonEvent *buttonEvent)
  763. {
  764. Boolean dispatchEvent = False;
  765. Boolean replayEvent = True;
  766. Context context;
  767. int partContext;
  768. Context subContext;
  769. static Time baseWinTime = 0;
  770. static unsigned int baseWinButton = 0;
  771. wmGD.passButtonsCheck = True;
  772. /*
  773. * Find out the event context and process the event accordingly.
  774. * If the event is due to a key focus selection grab or an application
  775. * modal grab then handle the grab (only these types of grabs are
  776. * done on the client window frame base window)..
  777. */
  778. if (wmGD.menuActive)
  779. {
  780. dispatchEvent = True; /* have the toolkit dispatch the event */
  781. }
  782. else
  783. {
  784. IdentifyEventContext (buttonEvent, pCD, &context, &partContext);
  785. subContext = (1L << partContext);
  786. if (buttonEvent->window == pCD->clientBaseWin)
  787. {
  788. /* save time of event caught by base window grab */
  789. baseWinTime = buttonEvent->time;
  790. baseWinButton = buttonEvent->button;
  791. }
  792. /*
  793. * If this event was caught by the base window grab and
  794. * replayed, then don't reprocess if caught by the frame
  795. * window. (Replayed events have the same time.)
  796. */
  797. if (!((buttonEvent->window == pCD->clientFrameWin) &&
  798. (buttonEvent->button == baseWinButton) &&
  799. (buttonEvent->time == baseWinTime)))
  800. {
  801. /*
  802. * Motif 1.2, ignore replayed events UNPOST_AND_REPLAY events
  803. * generated from the menu system (time stamps are exactly
  804. * the same for the replayed event)
  805. */
  806. if (wmGD.clickData.time == buttonEvent->time)
  807. {
  808. dispatchEvent = False;
  809. }
  810. else
  811. {
  812. ProcessClickBPress (buttonEvent, pCD, context, subContext);
  813. }
  814. if (CheckForButtonAction (buttonEvent, context, subContext, pCD))
  815. {
  816. /*
  817. * Button bindings have been processed, now check for bindings
  818. * that associated with the built-in semantics of the window
  819. * frame decorations.
  820. */
  821. CheckButtonPressBuiltin (buttonEvent, context, subContext,
  822. partContext, pCD);
  823. /*
  824. * For case where button action causes lower, but
  825. * builtin causes focus - disable auto raise until
  826. * we receive focusIn or focusOut.
  827. */
  828. pCD->focusAutoRaiseDisablePending = False;
  829. }
  830. else
  831. {
  832. /*
  833. * Else skip built-in processing due to execution of a function
  834. * that does on-going event processing or that has changed the
  835. * client state (e.g., f.move or f.minimize).
  836. */
  837. replayEvent = False;
  838. }
  839. }
  840. }
  841. if (buttonEvent->window == pCD->clientBaseWin)
  842. {
  843. ProcessButtonGrabOnClient (pCD, buttonEvent, replayEvent);
  844. }
  845. return (dispatchEvent);
  846. } /* END OF FUNCTION HandleCButtonPress */
  847. /*************************************<->*************************************
  848. *
  849. * ProcessButtonGrabOnClient (pCD, buttonEvent, replayEvent)
  850. *
  851. *
  852. * Description:
  853. * -----------
  854. * This function handles an activated button grab on the client window
  855. * frame base window.
  856. *
  857. *
  858. * Inputs:
  859. * ------
  860. * pCD = pointer to client data of window associated with the grab
  861. *
  862. * buttonEvent = ButtonPress event on client window
  863. *
  864. * replayEvent = True if event should be replayed
  865. *
  866. *************************************<->***********************************/
  867. void ProcessButtonGrabOnClient (ClientData *pCD, XButtonEvent *buttonEvent, Boolean replayEvent)
  868. {
  869. ButtonSpec *buttonSpec;
  870. Boolean passButton;
  871. if ((buttonEvent->button == SELECT_BUTTON) &&
  872. ((buttonEvent->state == 0) ||
  873. (NOLOCKMOD(buttonEvent->state) == 0)))
  874. {
  875. passButton = wmGD.passSelectButton;
  876. }
  877. else
  878. {
  879. passButton = wmGD.passButtons;
  880. }
  881. if (IS_APP_MODALIZED(pCD) || !passButton)
  882. {
  883. replayEvent = False;
  884. }
  885. else if (replayEvent)
  886. {
  887. /*
  888. * Replay the event as long as there is not another button binding
  889. * for the button release.
  890. */
  891. buttonSpec = ACTIVE_PSD->buttonSpecs;
  892. while (buttonSpec)
  893. {
  894. if ((buttonSpec->eventType == ButtonRelease) &&
  895. ((buttonEvent->state == buttonSpec->state) ||
  896. (NOLOCKMOD(buttonEvent->state) == buttonSpec->state)) &&
  897. (buttonEvent->button == buttonSpec->button))
  898. {
  899. replayEvent = False;
  900. break;
  901. }
  902. buttonSpec = buttonSpec->nextButtonSpec;
  903. }
  904. }
  905. if (replayEvent && wmGD.passButtonsCheck)
  906. {
  907. XAllowEvents (DISPLAY, ReplayPointer, CurrentTime);
  908. }
  909. else
  910. {
  911. if (IS_APP_MODALIZED(pCD))
  912. {
  913. /*
  914. * The grab is done on a window that has an application modal
  915. * secondary window. Beep to indicate no client processing of
  916. * the event.
  917. */
  918. F_Beep (NULL, pCD, (XEvent *) NULL);
  919. }
  920. XAllowEvents (DISPLAY, AsyncPointer, CurrentTime);
  921. }
  922. XAllowEvents (DISPLAY, AsyncKeyboard, CurrentTime);
  923. } /* END OF FUNCTION ProcessButtonGrabOnClient */
  924. /*************************************<->*************************************
  925. *
  926. * CheckButtonPressBuiltin (buttonEvent, context, subContext, partContext, pCD)
  927. *
  928. *
  929. * Description:
  930. * -----------
  931. * This function checks to see if a built-in window manager function
  932. * has been selected. If yes, then the function is done.
  933. *
  934. *
  935. * Inputs:
  936. * ------
  937. * buttonEvent = pointer to button event
  938. *
  939. * context = button event context (root, icon, window)
  940. *
  941. * subContext = button event subcontext (title, system button, ...)
  942. *
  943. * partContext = part context within a window manager component
  944. *
  945. *************************************<->***********************************/
  946. void CheckButtonPressBuiltin (XButtonEvent *buttonEvent, Context context, Context subContext, int partContext, ClientData *pCD)
  947. {
  948. /*
  949. * All builtin button bindings are based on button 1 with no
  950. * modifiers. (Ignore locking modifiers)
  951. */
  952. if (((buttonEvent->button != SELECT_BUTTON) &&
  953. (buttonEvent->button != DMANIP_BUTTON)) ||
  954. NOLOCKMOD(buttonEvent->state))
  955. {
  956. return;
  957. }
  958. /*
  959. * Process the builtin button bindings based on the window manager
  960. * component that was selected.
  961. */
  962. if (context & F_CONTEXT_ICON)
  963. {
  964. HandleIconButtonPress (pCD, buttonEvent);
  965. }
  966. else if (context & F_CONTEXT_ICONBOX)
  967. {
  968. HandleIconBoxButtonPress (pCD, buttonEvent, subContext);
  969. }
  970. else if (context & F_CONTEXT_WINDOW)
  971. {
  972. /*
  973. * A client window frame component was selected.
  974. */
  975. /*
  976. * If the keyboard focus policy is explicit then all window frame
  977. * components set the keyboard input focus when selected.
  978. */
  979. if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT)
  980. {
  981. /* If we've just done f.lower, disable focusAutoRaise. */
  982. if (pCD && pCD->focusAutoRaiseDisablePending)
  983. pCD->focusAutoRaiseDisabled = True;
  984. Do_Focus_Key (pCD, buttonEvent->time,
  985. (long)((partContext == FRAME_CLIENT) ? CLIENT_AREA_FOCUS : 0));
  986. }
  987. /*
  988. * Process the builtin button bindings based on the client window
  989. * frame component that was selected.
  990. */
  991. if ((buttonEvent->button == SELECT_BUTTON) &&
  992. (subContext == F_SUBCONTEXT_W_SYSTEM))
  993. {
  994. int flags = 0;
  995. /*
  996. * System menu button component:
  997. * SELECT_BUTTON Press - post the system menu.
  998. * SELECT_BUTTON double-click - close the window.
  999. */
  1000. PushGadgetIn (pCD, partContext);
  1001. if ((wmGD.clickData.doubleClickContext == F_SUBCONTEXT_W_SYSTEM) &&
  1002. wmGD.systemButtonClick2 &&
  1003. (pCD->clientFunctions & MWM_FUNC_CLOSE))
  1004. {
  1005. /*
  1006. * Close the client window. Don't do any of the other
  1007. * system menu button actions.
  1008. */
  1009. wmGD.clickData.clickPending = False;
  1010. wmGD.clickData.doubleClickPending = False;
  1011. F_Kill (NULL, pCD, (XEvent *) buttonEvent);
  1012. return;
  1013. }
  1014. if (pCD->clientState == NORMAL_STATE)
  1015. {
  1016. context = F_CONTEXT_NORMAL;
  1017. }
  1018. else if (pCD->clientState == MAXIMIZED_STATE)
  1019. {
  1020. context = F_CONTEXT_MAXIMIZE;
  1021. }
  1022. else
  1023. {
  1024. context = F_CONTEXT_ICON;
  1025. }
  1026. /*
  1027. * Set up for "sticky" menu processing if specified.
  1028. */
  1029. if (wmGD.systemButtonClick)
  1030. {
  1031. wmGD.checkHotspot = True;
  1032. flags |= POST_STICKY;
  1033. }
  1034. pCD->grabContext = context;
  1035. PostMenu (pCD->systemMenuSpec, pCD, 0, 0, SELECT_BUTTON,
  1036. context, flags, (XEvent *)buttonEvent);
  1037. }
  1038. else if (subContext == F_SUBCONTEXT_W_TITLE)
  1039. {
  1040. /*
  1041. * Title component:
  1042. * SELECT_BUTTON or DMANIP_BUTTON Press -
  1043. * start looking for a move.
  1044. */
  1045. PushGadgetIn (pCD, partContext);
  1046. /*
  1047. * Fix for 5075 - Check to make sure that MWM_FUNC_MOVE is set in the
  1048. * clientFunctions. This is necessary because the title
  1049. * bar is added based on a number of decorations even if
  1050. * the resources or the user has specifically requested
  1051. * that "move" not be one of them.
  1052. */
  1053. if (pCD && (pCD->clientFunctions & MWM_FUNC_MOVE))
  1054. {
  1055. wmGD.preMove = True;
  1056. wmGD.preMoveX = buttonEvent->x_root;
  1057. wmGD.preMoveY = buttonEvent->y_root;
  1058. wmGD.configButton = buttonEvent->button;
  1059. wmGD.configAction = MOVE_CLIENT;
  1060. }
  1061. /*
  1062. * End fix 5075
  1063. */
  1064. }
  1065. else if (subContext & F_SUBCONTEXT_W_RBORDER)
  1066. {
  1067. /*
  1068. * Resize border handle components:
  1069. * SELECT_BUTTON or DMANIP_BUTTON Press -
  1070. * start looking for a resize.
  1071. */
  1072. wmGD.preMove = True;
  1073. wmGD.preMoveX = buttonEvent->x_root;
  1074. wmGD.preMoveY = buttonEvent->y_root;
  1075. wmGD.configButton = buttonEvent->button;
  1076. wmGD.configAction = RESIZE_CLIENT;
  1077. wmGD.configPart = partContext;
  1078. wmGD.configSet = True;
  1079. }
  1080. else if ((buttonEvent->button == SELECT_BUTTON) &&
  1081. (subContext & (F_SUBCONTEXT_W_MINIMIZE|F_SUBCONTEXT_W_MAXIMIZE)))
  1082. {
  1083. /*
  1084. * Minimize and maximize button components:
  1085. * SELECT_BUTTON Press - start of a click.
  1086. */
  1087. PushGadgetIn (pCD, partContext);
  1088. }
  1089. /*
  1090. * Other components: no action
  1091. */
  1092. }
  1093. } /* END OF FUNCTION CheckButtonPressBuiltin */
  1094. /*************************************<->*************************************
  1095. *
  1096. * HandleIconButtonPress (pCD, buttonEvent)
  1097. *
  1098. *
  1099. * Description:
  1100. * -----------
  1101. * This function handles builtin functions in the icon context.
  1102. *
  1103. *
  1104. * Inputs:
  1105. * ------
  1106. * pCD = pointer to client data of the icon that received the button event
  1107. *
  1108. * buttonEvent = pointer to the button event that occurred
  1109. *
  1110. *************************************<->***********************************/
  1111. void HandleIconButtonPress (ClientData *pCD, XButtonEvent *buttonEvent)
  1112. {
  1113. int newState;
  1114. /*
  1115. * Do icon component button press actions:
  1116. * Button 1 press - set the keyboard input focus if policy is explicit
  1117. * Button 1 double-click - normalize the icon
  1118. */
  1119. if (wmGD.clickData.doubleClickContext == F_SUBCONTEXT_I_ALL)
  1120. {
  1121. /*
  1122. * A double-click was done, normalize the icon.
  1123. */
  1124. if (pCD->maxConfig)
  1125. {
  1126. newState = MAXIMIZED_STATE;
  1127. }
  1128. else
  1129. {
  1130. newState = NORMAL_STATE;
  1131. }
  1132. SetClientState (pCD, newState, buttonEvent->time);
  1133. wmGD.clickData.clickPending = False;
  1134. wmGD.clickData.doubleClickPending = False;
  1135. }
  1136. else
  1137. {
  1138. /*
  1139. * This is a regular button press (it may be the start of a
  1140. * double-click). Set the focus and top the icon if appropriate.
  1141. */
  1142. if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT)
  1143. {
  1144. Do_Focus_Key (pCD, buttonEvent->time, ALWAYS_SET_FOCUS);
  1145. }
  1146. /*
  1147. * Indicate that a move may be starting; wait for button motion
  1148. * events before moving the icon.
  1149. */
  1150. wmGD.preMove = True;
  1151. wmGD.preMoveX = buttonEvent->x_root;
  1152. wmGD.preMoveY = buttonEvent->y_root;
  1153. wmGD.configButton = buttonEvent->button;
  1154. wmGD.configAction = MOVE_CLIENT;
  1155. }
  1156. } /* END OF FUNCTION HandleIconButtonPress */
  1157. /*************************************<->*************************************
  1158. *
  1159. * HandleIconBoxButtonPress (pCD, buttonEvent, subContext)
  1160. *
  1161. *
  1162. * Description:
  1163. * -----------
  1164. * This function handles builtin functions in the iconbox context.
  1165. *
  1166. *
  1167. * Inputs:
  1168. * ------
  1169. * pCD = pointer to client data of the icon that received the button event
  1170. *
  1171. * buttonEvent = pointer to the button event that occurred
  1172. *
  1173. * subContext = context id of event location inside icon box
  1174. *
  1175. *************************************<->***********************************/
  1176. void HandleIconBoxButtonPress (ClientData *pCD, XButtonEvent *buttonEvent, Context subContext)
  1177. {
  1178. /*
  1179. * Do iconbox icon component button press actions:
  1180. * Button 1 press - select the icon
  1181. * Button 1 double-click - normalize the icon or raise the window
  1182. */
  1183. if ((wmGD.clickData.doubleClickContext == F_SUBCONTEXT_IB_IICON) ||
  1184. (wmGD.clickData.doubleClickContext == F_SUBCONTEXT_IB_WICON))
  1185. {
  1186. F_Restore_And_Raise ((String)NULL, pCD, (XEvent *)NULL);
  1187. }
  1188. else if ((subContext == F_SUBCONTEXT_IB_IICON) ||
  1189. (subContext == F_SUBCONTEXT_IB_WICON))
  1190. {
  1191. /*
  1192. * Indicate that a move may be starting; wait for button motion
  1193. * events before moving the icon.
  1194. */
  1195. wmGD.preMove = True;
  1196. wmGD.preMoveX = buttonEvent->x_root;
  1197. wmGD.preMoveY = buttonEvent->y_root;
  1198. wmGD.configButton = buttonEvent->button;
  1199. wmGD.configAction = MOVE_CLIENT;
  1200. }
  1201. /*
  1202. * Do icon box icon actions:
  1203. * Button 1 press - select the icon in the icon box
  1204. */
  1205. /*
  1206. * XmProcessTraversal will move the selection cursor to the
  1207. * widget that was "boinked" with the mouse
  1208. */
  1209. if ((P_ICON_BOX(pCD)->pCD_iconBox == wmGD.keyboardFocus) ||
  1210. (P_ICON_BOX(pCD)->pCD_iconBox == wmGD.nextKeyboardFocus))
  1211. {
  1212. XmProcessTraversal (XtWindowToWidget(DISPLAY, ICON_FRAME_WIN(pCD)),
  1213. XmTRAVERSE_CURRENT);
  1214. }
  1215. } /* END OF FUNCTION HandleIconBoxButtonPress */
  1216. /*************************************<->*************************************
  1217. *
  1218. * HandleCButtonRelease (pCD, buttonEvent)
  1219. *
  1220. *
  1221. * Description:
  1222. * -----------
  1223. * This function does window management actions associated with a button
  1224. * release event on the client window (including frame) or icon.
  1225. *
  1226. *
  1227. * Inputs:
  1228. * ------
  1229. * pCD = pointer to client data for the window/icon that got the event
  1230. *
  1231. * buttonEvent = pointer to the button event that occurred
  1232. *
  1233. * Comments:
  1234. * ---------
  1235. * Skip builtin processing if move or resize button actions were started
  1236. * due to button-up bindings.
  1237. *
  1238. *************************************<->***********************************/
  1239. void HandleCButtonRelease (ClientData *pCD, XButtonEvent *buttonEvent)
  1240. {
  1241. Context context;
  1242. Context subContext;
  1243. int partContext;
  1244. /*
  1245. * Find out whether the event was on the client window frame or the icon
  1246. * and process the event accordingly.
  1247. */
  1248. IdentifyEventContext (buttonEvent, pCD, &context, &partContext);
  1249. subContext = (1L << partContext);
  1250. ProcessClickBRelease (buttonEvent, pCD, context, subContext);
  1251. if (CheckForButtonAction (buttonEvent, context, subContext, pCD) && pCD)
  1252. {
  1253. /*
  1254. * Button bindings have been processed, now check for bindings
  1255. * that associated with the built-in semantics of the window
  1256. * frame decorations.
  1257. */
  1258. CheckButtonReleaseBuiltin (buttonEvent, context, subContext, pCD);
  1259. }
  1260. /*
  1261. * Else skip built-in processing due to execution of a function that
  1262. * does on-going event processing or that has changed the client state
  1263. * (e.g., f.move or f.minimize).
  1264. */
  1265. /* clear preMove state */
  1266. wmGD.preMove = False;
  1267. } /* END OF FUNCTION HandleCButtonRelease */
  1268. /*************************************<->*************************************
  1269. *
  1270. * HandleCKeyPress (pCD, keyEvent)
  1271. *
  1272. *
  1273. * Description:
  1274. * -----------
  1275. * This function does window management actions associated with a key
  1276. * press event on the client window (including frame) or icon.
  1277. *
  1278. *
  1279. * Inputs:
  1280. * ------
  1281. * pCD = pointer to client data for the window/icon that got the event
  1282. *
  1283. * keyEvent = pointer to the key event that occurred
  1284. *
  1285. *
  1286. * Outputs:
  1287. * -------
  1288. * RETURN = True if the event should be dispatched by XtDispatchEvent
  1289. *
  1290. *************************************<->***********************************/
  1291. Boolean HandleCKeyPress (ClientData *pCD, XKeyEvent *keyEvent)
  1292. {
  1293. Boolean dispatchEvent = False;
  1294. Boolean checkKeyEvent = True;
  1295. if (wmGD.menuActive)
  1296. {
  1297. /*
  1298. * The active menu accelerators have been checked and keyEvent was
  1299. * not one of them. We will check for an iconbox icon widget key and
  1300. * for pass keys mode and then have the toolkit dispatch the event,
  1301. * without rechecking the client accelerator list.
  1302. */
  1303. dispatchEvent = True;
  1304. checkKeyEvent = False;
  1305. }
  1306. /*
  1307. * If pass keys is active then only check for getting out of the pass
  1308. * keys mode if the event is on the client frame or icon frame window.
  1309. * Unfreeze the keyboard and replay the key if pass keys is active.
  1310. */
  1311. if (((keyEvent->window == ICON_FRAME_WIN(pCD)) ||
  1312. (keyEvent->window == pCD->pSD->activeIconTextWin)) &&
  1313. P_ICON_BOX(pCD))
  1314. {
  1315. /*
  1316. * This is a non-grabbed key that is intended for the icon widget
  1317. * in the iconbox.
  1318. */
  1319. dispatchEvent = True; /* have the toolkit dispatch the event */
  1320. checkKeyEvent = False;
  1321. if (keyEvent->window == pCD->pSD->activeIconTextWin)
  1322. {
  1323. /*
  1324. * The event is really for the icon, not the active
  1325. * label, so ... correct the window id
  1326. */
  1327. keyEvent->window = ICON_FRAME_WIN(pCD);
  1328. }
  1329. }
  1330. else if (wmGD.passKeysActive)
  1331. {
  1332. if (wmGD.passKeysKeySpec &&
  1333. ((wmGD.passKeysKeySpec->state == keyEvent->state) ||
  1334. (wmGD.passKeysKeySpec->state == NOLOCKMOD(keyEvent->state))) &&
  1335. (wmGD.passKeysKeySpec->keycode == keyEvent->keycode))
  1336. {
  1337. /*
  1338. * Get out of the pass keys mode.
  1339. */
  1340. F_Pass_Key (NULL, (ClientData *) NULL, (XEvent *) NULL);
  1341. XAllowEvents (DISPLAY, AsyncKeyboard, CurrentTime);
  1342. }
  1343. else
  1344. {
  1345. XAllowEvents (DISPLAY, ReplayKeyboard, CurrentTime);
  1346. }
  1347. checkKeyEvent = False;
  1348. }
  1349. else
  1350. {
  1351. XAllowEvents (DISPLAY, AsyncKeyboard, CurrentTime);
  1352. }
  1353. /*
  1354. * Check for a "general" key binding that has been set only for the
  1355. * icon context. These key bindings are set with the keyBinding
  1356. * resource or as accelerators in icon context menus.
  1357. */
  1358. if (checkKeyEvent && (keyEvent->window == ICON_FRAME_WIN(pCD)))
  1359. {
  1360. if ((checkKeyEvent = HandleKeyPress (keyEvent,
  1361. ACTIVE_PSD->keySpecs, True,
  1362. F_CONTEXT_ICON, False,
  1363. (ClientData *)NULL))
  1364. && ACTIVE_PSD->acceleratorMenuCount)
  1365. {
  1366. int n;
  1367. for (n = 0; ((keyEvent->keycode != 0) &&
  1368. (n < ACTIVE_PSD->acceleratorMenuCount)); n++)
  1369. {
  1370. if (!HandleKeyPress (keyEvent,
  1371. ACTIVE_PSD->acceleratorMenuSpecs[n]->accelKeySpecs,
  1372. True, F_CONTEXT_ICON, True,(ClientData *)NULL))
  1373. {
  1374. checkKeyEvent = False;
  1375. break;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. /*
  1381. * Check for a key binding that has been set as an accelerator in the
  1382. * system menu. We only do the first accelerator found.
  1383. */
  1384. if (checkKeyEvent && pCD->systemMenuSpec &&
  1385. (pCD->systemMenuSpec->accelKeySpecs))
  1386. {
  1387. HandleKeyPress (keyEvent, pCD->systemMenuSpec->accelKeySpecs,
  1388. FALSE, 0, TRUE,(ClientData *)NULL );
  1389. }
  1390. return (dispatchEvent);
  1391. } /* END OF FUNCTION HandleCKeyPress */
  1392. /*************************************<->*************************************
  1393. *
  1394. * CheckButtonReleaseBuiltin (buttonEvent, context, subContext, pCD)
  1395. *
  1396. *
  1397. * Description:
  1398. * -----------
  1399. * This function checks to see if a built-in window manager function
  1400. * has been activated as a result of a button release. If yes, then the
  1401. * associated function is done.
  1402. *
  1403. *
  1404. * Inputs:
  1405. * ------
  1406. * buttonEvent = pointer to a button release event
  1407. *
  1408. * context = button event context (root, icon, window)
  1409. *
  1410. * subContext = button event subcontext (title, system button, ...)
  1411. *
  1412. * pCD = pointer to client data for the window/icon that got the event
  1413. *
  1414. *************************************<->***********************************/
  1415. void CheckButtonReleaseBuiltin (XButtonEvent *buttonEvent, Context context, Context subContext, ClientData *pCD)
  1416. {
  1417. /*
  1418. * All builtin button buindings are based on button 1 with no modifiers.
  1419. * (Ignore locking modifiers).
  1420. *
  1421. * Test the event for a ``button up'' transition on buttons we are
  1422. * interested in.
  1423. */
  1424. if (!((buttonEvent->button == SELECT_BUTTON) &&
  1425. (NOLOCKMOD(buttonEvent->state) == SELECT_BUTTON_MASK)) &&
  1426. !((buttonEvent->button == DMANIP_BUTTON) &&
  1427. (NOLOCKMOD(buttonEvent->state) == DMANIP_BUTTON_MASK)))
  1428. {
  1429. return;
  1430. }
  1431. /*
  1432. * Process the builtin button bindings based on the window manager
  1433. * component that was selected.
  1434. */
  1435. if ((buttonEvent->button == SELECT_BUTTON) &&
  1436. (context & F_CONTEXT_ICON))
  1437. {
  1438. /*
  1439. * Do the icon component button release actions:
  1440. * SELECT_BUTTON click - post the system menu if specified.
  1441. */
  1442. if (wmGD.iconClick &&
  1443. (wmGD.clickData.clickContext == F_SUBCONTEXT_I_ALL))
  1444. {
  1445. wmGD.checkHotspot = True;
  1446. /*
  1447. * Post the system menu with traversal on (Button 1 should be
  1448. * used to manipulate the menu).
  1449. */
  1450. pCD->grabContext = F_CONTEXT_ICON;
  1451. PostMenu (pCD->systemMenuSpec, pCD, 0, 0, NoButton,
  1452. F_CONTEXT_ICON, POST_STICKY, (XEvent *)buttonEvent);
  1453. }
  1454. }
  1455. /* post menu from icon in iconbox */
  1456. else if ((buttonEvent->button == SELECT_BUTTON) &&
  1457. (context & F_CONTEXT_ICONBOX))
  1458. {
  1459. if ((wmGD.iconClick) &&
  1460. (((pCD->clientState == MINIMIZED_STATE) &&
  1461. (wmGD.clickData.clickContext == F_SUBCONTEXT_IB_IICON)) ||
  1462. (wmGD.clickData.clickContext == F_SUBCONTEXT_IB_WICON)) )
  1463. {
  1464. wmGD.checkHotspot = True;
  1465. /*
  1466. * Post the system menu with traversal on (Button 1 should be
  1467. * used to manipulate the menu.
  1468. */
  1469. if ((wmGD.clickData.clickContext == F_SUBCONTEXT_IB_IICON) &&
  1470. (pCD->clientState == MINIMIZED_STATE))
  1471. {
  1472. pCD->grabContext = F_SUBCONTEXT_IB_IICON;
  1473. PostMenu (pCD->systemMenuSpec, pCD, 0, 0, NoButton,
  1474. F_SUBCONTEXT_IB_IICON, POST_STICKY, (XEvent *)buttonEvent);
  1475. }
  1476. else
  1477. {
  1478. pCD->grabContext = F_SUBCONTEXT_IB_WICON;
  1479. PostMenu (pCD->systemMenuSpec, pCD, 0, 0, NoButton,
  1480. F_SUBCONTEXT_IB_WICON, POST_STICKY, (XEvent *)buttonEvent);
  1481. }
  1482. }
  1483. }
  1484. /* end of post menu from icon in iconbox */
  1485. else if (context & F_CONTEXT_WINDOW)
  1486. {
  1487. /*
  1488. * The button release is on a client window frame component.
  1489. */
  1490. if ((buttonEvent->button == SELECT_BUTTON) &&
  1491. (subContext == F_SUBCONTEXT_W_MINIMIZE))
  1492. {
  1493. /*
  1494. * Minimize button:
  1495. * Button 1 click - minimize the window.
  1496. */
  1497. if (wmGD.clickData.clickContext == F_SUBCONTEXT_W_MINIMIZE)
  1498. {
  1499. SetClientState (pCD, MINIMIZED_STATE, buttonEvent->time);
  1500. }
  1501. }
  1502. else if ((buttonEvent->button == SELECT_BUTTON) &&
  1503. (subContext == F_SUBCONTEXT_W_MAXIMIZE))
  1504. {
  1505. /*
  1506. * Maximize button:
  1507. * Button 1 click - maximize the window.
  1508. */
  1509. if (wmGD.clickData.clickContext == F_SUBCONTEXT_W_MAXIMIZE)
  1510. {
  1511. if (pCD->clientState == NORMAL_STATE)
  1512. {
  1513. SetClientState (pCD, MAXIMIZED_STATE, buttonEvent->time);
  1514. }
  1515. else
  1516. {
  1517. SetClientState (pCD, NORMAL_STATE, buttonEvent->time);
  1518. }
  1519. }
  1520. }
  1521. }
  1522. /*
  1523. * Clear the pre-configuration info that supports the move threshold.
  1524. */
  1525. wmGD.preMove = False;
  1526. } /* END OF FUNCTION CheckButtonReleaseBuiltin */
  1527. /*************************************<->*************************************
  1528. *
  1529. * HandleCMotionNotify (pCD, motionEvent)
  1530. *
  1531. *
  1532. * Description:
  1533. * -----------
  1534. * This function does window management actions associated with a motion
  1535. * notify event on the client window (including frame) or icon.
  1536. *
  1537. *
  1538. * Inputs:
  1539. * ------
  1540. * pCD = pointer to the client data for the window/icon that got the motion
  1541. *
  1542. * motionEvent = pointer to the motion event
  1543. *
  1544. *************************************<->***********************************/
  1545. void HandleCMotionNotify (ClientData *pCD, XMotionEvent *motionEvent)
  1546. {
  1547. int diffX;
  1548. int diffY;
  1549. /*
  1550. * Do pre-move processing (to support the move threshold) if appropriate:
  1551. */
  1552. if (wmGD.preMove)
  1553. {
  1554. diffX = motionEvent->x_root - wmGD.preMoveX;
  1555. if (diffX < 0) diffX = -diffX;
  1556. diffY = motionEvent->y_root - wmGD.preMoveY;
  1557. if (diffY < 0) diffY = -diffY;
  1558. if ((diffX >= wmGD.moveThreshold) || (diffY >= wmGD.moveThreshold))
  1559. {
  1560. /*
  1561. * The move threshold has been exceeded; start the config action.
  1562. */
  1563. wmGD.clickData.clickPending = False;
  1564. wmGD.clickData.doubleClickPending = False;
  1565. wmGD.preMove = False;
  1566. if (wmGD.configAction == MOVE_CLIENT)
  1567. {
  1568. HandleClientFrameMove (pCD, (XEvent *) motionEvent);
  1569. }
  1570. else if (wmGD.configAction == RESIZE_CLIENT)
  1571. {
  1572. HandleClientFrameResize (pCD, (XEvent *) motionEvent);
  1573. }
  1574. }
  1575. }
  1576. } /* END OF FUNCTION HandleCMotionNotify */
  1577. /*************************************<->*************************************
  1578. *
  1579. * HandleCEnterNotify (pCD, enterEvent)
  1580. *
  1581. *
  1582. * Description:
  1583. * -----------
  1584. * This function does window management actions associated with an enter
  1585. * window event on the client window.
  1586. *
  1587. *
  1588. * Inputs:
  1589. * ------
  1590. * pCD = pointer to the client data for the window/icon that was entered
  1591. *
  1592. * enterEvent = pointer to the enter event
  1593. *
  1594. *************************************<->***********************************/
  1595. void HandleCEnterNotify (ClientData *pCD, XEnterWindowEvent *enterEvent)
  1596. {
  1597. XEvent report;
  1598. Boolean MatchFound;
  1599. Window enterWindow;
  1600. /*
  1601. * If a client is being configured don't change the keyboard input
  1602. * focus. The input focus is "fixed" after the configuration has been
  1603. * completed.
  1604. */
  1605. if (pCD->clientState == MINIMIZED_STATE)
  1606. {
  1607. enterWindow = ICON_FRAME_WIN(pCD);
  1608. }
  1609. else
  1610. {
  1611. enterWindow = pCD->clientFrameWin;
  1612. }
  1613. MatchFound = XCheckTypedWindowEvent(DISPLAY, enterWindow,
  1614. LeaveNotify, &report);
  1615. /*
  1616. * NOTE: Handle focus change for when user clicks button in the
  1617. * process of moving focus the matching event will be NotifyGrab.
  1618. *
  1619. * IF (((no_match) ||
  1620. * (another window has focus and button grabbed)) &&
  1621. * pointer_mode)
  1622. */
  1623. if ((enterEvent->detail != NotifyInferior) &&
  1624. (((!MatchFound || (report.xcrossing.detail == NotifyInferior)) &&
  1625. ((enterEvent->mode == NotifyNormal) ||
  1626. (enterEvent->mode == NotifyUngrab)) &&
  1627. !wmGD.menuActive) ||
  1628. (wmGD.keyboardFocus &&
  1629. (wmGD.keyboardFocus->clientFrameWin != enterWindow) &&
  1630. (enterEvent->mode == NotifyGrab))) &&
  1631. ((wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER) ||
  1632. (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER)))
  1633. {
  1634. /*
  1635. * Make sure that EnterNotify is applicable; don't do anything if
  1636. * the window is minimized (not currently visible) or the event is
  1637. * associated with an icon in the icon box.
  1638. */
  1639. if (!(((enterEvent->window == pCD->clientFrameWin) &&
  1640. (pCD->clientState == MINIMIZED_STATE)) ||
  1641. (((enterEvent->window == ICON_FRAME_WIN(pCD)) &&
  1642. P_ICON_BOX(pCD)) ||
  1643. (enterEvent->window == pCD->pSD->activeIconTextWin))))
  1644. {
  1645. if (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_POINTER)
  1646. {
  1647. /*
  1648. * Set the focus only if the window does not currently have
  1649. * or if another window is in the process of getting the
  1650. * focus (this check avoids redundant focus setting).
  1651. */
  1652. if ((pCD != wmGD.keyboardFocus) ||
  1653. (pCD != wmGD.nextKeyboardFocus))
  1654. {
  1655. Do_Focus_Key (pCD, enterEvent->time, ALWAYS_SET_FOCUS);
  1656. /* Does the event need to be replayed for modalized windows ? */
  1657. if ( wmGD.replayEnterEvent )
  1658. /* Yes, save the event. */
  1659. memcpy( &wmGD.savedEnterEvent, enterEvent,
  1660. sizeof( XEnterWindowEvent ) );
  1661. /*
  1662. * The original code counted on getting a focus out event as a result
  1663. * of setting the input focus in Do_Focus_key. That would cause
  1664. * SetkeyboardFocus to get called. Unfortunately, you cannot depend on
  1665. * getting a focus out. You may have already had focus yourself.
  1666. *
  1667. * This bug can be produced by:
  1668. * * bring up a menu and leave it posted
  1669. * * move to a different window and click
  1670. * * the menu comes unposted, the new window has input focus, but no
  1671. * client active decorations are changed.
  1672. */
  1673. }
  1674. }
  1675. if (wmGD.colormapFocusPolicy == CMAP_FOCUS_POINTER)
  1676. {
  1677. SetColormapFocus (ACTIVE_PSD, pCD);
  1678. }
  1679. }
  1680. }
  1681. } /* END OF FUNCTION HandleCEnterNotify */
  1682. /*************************************<->*************************************
  1683. *
  1684. * HandleCLeaveNotify (pCD, leaveEvent)
  1685. *
  1686. *
  1687. * Description:
  1688. * -----------
  1689. * This function does window management actions associated with an leave
  1690. * window event on the client window.
  1691. *
  1692. *
  1693. * Inputs:
  1694. * ------
  1695. * pCD = pointer to the client data for the window/icon that was leaveed
  1696. *
  1697. * leaveEvent = pointer to the leave event
  1698. *
  1699. *************************************<->***********************************/
  1700. void HandleCLeaveNotify (ClientData *pCD, XLeaveWindowEvent *leaveEvent)
  1701. {
  1702. XEvent report;
  1703. Window leaveWindow;
  1704. if (pCD->clientState == MINIMIZED_STATE)
  1705. {
  1706. leaveWindow = ICON_FRAME_WIN(pCD);
  1707. }
  1708. else
  1709. {
  1710. leaveWindow = pCD->clientFrameWin;
  1711. }
  1712. /*
  1713. * Don't remove enterEvents when user double clicks on an icon in
  1714. * an iconbox. Otherwise the window that gets normalized will get
  1715. * matching enter events and not get the focus.
  1716. */
  1717. if (P_ICON_BOX(pCD) &&
  1718. (P_ICON_BOX(pCD)->pCD_iconBox != wmGD.keyboardFocus) &&
  1719. (P_ICON_BOX(pCD)->pCD_iconBox != wmGD.nextKeyboardFocus))
  1720. {
  1721. XCheckTypedWindowEvent(DISPLAY, leaveWindow, EnterNotify, &report);
  1722. }
  1723. } /* END OF FUNCTION HandleCLeaveNotify */
  1724. /*************************************<->*************************************
  1725. *
  1726. * HandleCFocusIn (pCD, focusChangeEvent)
  1727. *
  1728. *
  1729. * Description:
  1730. * -----------
  1731. * This function does window management actions associated with a focus
  1732. * in event.
  1733. *
  1734. *
  1735. * Inputs:
  1736. * ------
  1737. * pCD = pointer to the client data for the window/icon that was entered
  1738. *
  1739. * enterEvent = pointer to the focus in event
  1740. *
  1741. *
  1742. * Outputs:
  1743. * -------
  1744. * RETURN = True if event is to be dispatched by the toolkit
  1745. *
  1746. *************************************<->***********************************/
  1747. Boolean HandleCFocusIn (ClientData *pCD, XFocusChangeEvent *focusChangeEvent)
  1748. {
  1749. Boolean setupNextFocus;
  1750. Boolean doXtDispatchEvent = False;
  1751. /*
  1752. * Ignore the event if it is for a window that is no longer viewable.
  1753. * This is the case for a client window FocusIn event that is being
  1754. * processed for a window that has been minimized.
  1755. */
  1756. if ((focusChangeEvent->window == ICON_FRAME_WIN(pCD)) &&
  1757. P_ICON_BOX(pCD))
  1758. {
  1759. doXtDispatchEvent = True;
  1760. }
  1761. else if (((focusChangeEvent->mode == NotifyNormal) ||
  1762. (focusChangeEvent->mode == NotifyWhileGrabbed)) &&
  1763. !((focusChangeEvent->window == pCD->clientBaseWin) &&
  1764. (pCD->clientState == MINIMIZED_STATE)) &&
  1765. !((focusChangeEvent->window == ICON_FRAME_WIN(pCD)) &&
  1766. (pCD->clientState != MINIMIZED_STATE)))
  1767. {
  1768. setupNextFocus = (wmGD.keyboardFocus == wmGD.nextKeyboardFocus);
  1769. if (wmGD.keyboardFocus != pCD)
  1770. {
  1771. if ((focusChangeEvent->detail == NotifyNonlinear) ||
  1772. (focusChangeEvent->detail == NotifyNonlinearVirtual))
  1773. {
  1774. SetKeyboardFocus (pCD, REFRESH_LAST_FOCUS);
  1775. if (setupNextFocus)
  1776. {
  1777. wmGD.nextKeyboardFocus = wmGD.keyboardFocus;
  1778. }
  1779. }
  1780. /* Re: CR 4896 */
  1781. /* this part added to try and fix the %#$!@!!&* focus bug. */
  1782. /* this seems to solve most of the problem. This still leaves */
  1783. /* times when clicking on an icon toggles the focus back to the */
  1784. /* the previous focus window. */
  1785. /* Another patch was added to WmEvent.c to fix that problem. */
  1786. else
  1787. {
  1788. SetKeyboardFocus (pCD, REFRESH_LAST_FOCUS);
  1789. if (setupNextFocus) wmGD.nextKeyboardFocus = wmGD.keyboardFocus;
  1790. }
  1791. }
  1792. else if ((focusChangeEvent->detail == NotifyInferior) &&
  1793. (wmGD.keyboardFocusPolicy == KEYBOARD_FOCUS_EXPLICIT))
  1794. {
  1795. /*
  1796. * The client window was withdrawn (unmapped or destroyed).
  1797. * Reset the focus.
  1798. * !!! pointer focus !!!
  1799. */
  1800. if (wmGD.autoKeyFocus)
  1801. {
  1802. /* !!! fix this up to handle transient windows !!! */
  1803. AutoResetKeyFocus (wmGD.keyboardFocus, GetTimestamp ());
  1804. }
  1805. else
  1806. {
  1807. Do_Focus_Key ((ClientData *) NULL, GetTimestamp (),
  1808. ALWAYS_SET_FOCUS);
  1809. }
  1810. }
  1811. }
  1812. pCD->focusAutoRaiseDisabled = False;
  1813. return (doXtDispatchEvent);
  1814. } /* END OF FUNCTION HandleCFocusIn */
  1815. /*************************************<->*************************************
  1816. *
  1817. * HandleCFocusOut (pCD, focusChangeEvent)
  1818. *
  1819. *
  1820. * Description:
  1821. * -----------
  1822. * This function does window management actions associated with a focus
  1823. * out event that applies to a client window.
  1824. *
  1825. *
  1826. * Inputs:
  1827. * ------
  1828. * pCD = pointer to the client data for the window/icon that was entered
  1829. *
  1830. * enterEvent = pointer to the focus out event
  1831. *
  1832. *
  1833. * Outputs:
  1834. * -------
  1835. * RETURN = True if event is to be dispatched by the toolkit
  1836. *
  1837. *************************************<->***********************************/
  1838. Boolean HandleCFocusOut (ClientData *pCD, XFocusChangeEvent *focusChangeEvent)
  1839. {
  1840. Boolean doXtDispatchEvent = False;
  1841. long focusFlags = REFRESH_LAST_FOCUS ;
  1842. pCD->focusAutoRaiseDisabled = False;
  1843. /*
  1844. * Ignore the event if it is for a window that is no longer viewable.
  1845. * This is the case for a client window FocusOut event that is being
  1846. * processed for a window that has been minimized. Also, ignore focus
  1847. * out events for clients that aren't on the current screen.
  1848. */
  1849. if (((focusChangeEvent->window == ICON_FRAME_WIN(pCD)) &&
  1850. P_ICON_BOX(pCD)) ||
  1851. (SCREEN_FOR_CLIENT(pCD) != ACTIVE_SCREEN))
  1852. {
  1853. doXtDispatchEvent = True;
  1854. }
  1855. else if ((wmGD.keyboardFocus == pCD) &&
  1856. (focusChangeEvent->mode == NotifyNormal) &&
  1857. ((focusChangeEvent->detail == NotifyNonlinear) ||
  1858. (focusChangeEvent->detail == NotifyNonlinearVirtual)) &&
  1859. !((focusChangeEvent->window == pCD->clientBaseWin) &&
  1860. (pCD->clientState == MINIMIZED_STATE)) &&
  1861. !((focusChangeEvent->window == ICON_FRAME_WIN(pCD)) &&
  1862. (pCD->clientState != MINIMIZED_STATE)))
  1863. {
  1864. /*
  1865. * The keyboard focus was shifted to another window, maybe on
  1866. * another screen. Clear the focus indication and reset focus
  1867. * handling for the client window.
  1868. */
  1869. /*
  1870. * use SCREEN_SWITCH_FOCUS in SetKeyboardFocus to
  1871. * not call SetColormapFocus if we are moveing
  1872. * to another screen
  1873. */
  1874. if (SCREEN_FOR_CLIENT(pCD) != ACTIVE_SCREEN)
  1875. {
  1876. focusFlags |= SCREEN_SWITCH_FOCUS;
  1877. }
  1878. SetKeyboardFocus ((ClientData *) NULL, focusFlags);
  1879. if (wmGD.nextKeyboardFocus == pCD)
  1880. {
  1881. wmGD.nextKeyboardFocus = NULL;
  1882. }
  1883. }
  1884. return (doXtDispatchEvent);
  1885. } /* END OF FUNCTION HandleCFocusOut */
  1886. /*************************************<->*************************************
  1887. *
  1888. * HandleCConfigureRequest (pCD, configureRequest)
  1889. *
  1890. *
  1891. * Description:
  1892. * -----------
  1893. * This functions handles ConfigureRequest events that are for client windows.
  1894. *
  1895. *
  1896. * Inputs:
  1897. * ------
  1898. * pCD = pointer to client data
  1899. *
  1900. * configureRequest = a pointer to a ConfigureRequest event
  1901. *
  1902. *************************************<->***********************************/
  1903. void HandleCConfigureRequest (ClientData *pCD, XConfigureRequestEvent *configureRequest)
  1904. {
  1905. unsigned int mask = configureRequest->value_mask;
  1906. int stackMode = configureRequest->detail;
  1907. unsigned int changeMask;
  1908. ClientData *pcdLeader;
  1909. ClientData *pcdSibling;
  1910. ClientListEntry *pStackEntry;
  1911. /*
  1912. * Call ProcessNewConfiguration to handle window moving and resizing.
  1913. * Send ConfigureNotify event (based on ICCCM conventions).
  1914. * Then process the request for stacking.
  1915. */
  1916. if ((configureRequest->window == pCD->client) &&
  1917. (mask & (CWX | CWY | CWWidth | CWHeight | CWBorderWidth)))
  1918. {
  1919. if (pCD->maxConfig) {
  1920. ProcessNewConfiguration (pCD,
  1921. (mask & CWX) ? configureRequest->x : pCD->maxX,
  1922. (mask & CWY) ? configureRequest->y : pCD->maxY,
  1923. (unsigned int) ((mask & CWWidth) ?
  1924. configureRequest->width : pCD->maxWidth),
  1925. (unsigned int) ((mask & CWHeight) ?
  1926. configureRequest->height : pCD->maxHeight),
  1927. True /*client request*/);
  1928. }
  1929. else {
  1930. int xOff, yOff;
  1931. /* CDExc21094 - ProcessNewConfiguration() offsets the */
  1932. /* x and y positions passed in; in order to keep them */
  1933. /* the same, we offset them in the opposite direction. */
  1934. if (wmGD.positionIsFrame)
  1935. {
  1936. xOff = pCD->clientOffset.x;
  1937. yOff = pCD->clientOffset.y;
  1938. }
  1939. else
  1940. {
  1941. xOff = yOff = 0;
  1942. }
  1943. ProcessNewConfiguration (pCD,
  1944. (mask & CWX) ? configureRequest->x : pCD->clientX - xOff,
  1945. (mask & CWY) ? configureRequest->y : pCD->clientY - yOff,
  1946. (unsigned int) ((mask & CWWidth) ?
  1947. configureRequest->width : pCD->clientWidth),
  1948. (unsigned int) ((mask & CWHeight) ?
  1949. configureRequest->height : pCD->clientHeight),
  1950. True /*client request*/);
  1951. }
  1952. }
  1953. if (mask & CWStackMode)
  1954. {
  1955. changeMask = mask & (CWSibling | CWStackMode);
  1956. if (changeMask & CWSibling)
  1957. {
  1958. if (XFindContext (DISPLAY, configureRequest->above,
  1959. wmGD.windowContextType, (caddr_t *)&pcdSibling))
  1960. {
  1961. changeMask &= ~CWSibling;
  1962. }
  1963. else
  1964. {
  1965. /*
  1966. * For client requests only primary windows can be
  1967. * restacked relative to one another.
  1968. */
  1969. pcdLeader = FindTransientTreeLeader (pCD);
  1970. pcdSibling = FindTransientTreeLeader (pcdSibling);
  1971. if (pcdLeader == pcdSibling)
  1972. {
  1973. changeMask &= ~CWSibling;
  1974. }
  1975. else
  1976. {
  1977. pStackEntry = &pcdSibling->clientEntry;
  1978. if ((stackMode == Above) || (stackMode == TopIf))
  1979. {
  1980. /* lower the window to just above the sibling */
  1981. Do_Lower (pcdLeader, pStackEntry, STACK_NORMAL);
  1982. }
  1983. else if ((stackMode == Below) || (stackMode == BottomIf))
  1984. {
  1985. /* raise the window to just below the sibling */
  1986. Do_Raise (pcdLeader, pStackEntry, STACK_NORMAL);
  1987. }
  1988. else if (stackMode == Opposite)
  1989. {
  1990. F_Raise_Lower (NULL, pCD, (XEvent *)configureRequest);
  1991. }
  1992. }
  1993. }
  1994. }
  1995. if (!(changeMask & CWSibling))
  1996. {
  1997. if ((stackMode == Above) || (stackMode == TopIf))
  1998. {
  1999. Do_Raise (pCD, (ClientListEntry *) NULL, STACK_NORMAL);
  2000. }
  2001. else if ((stackMode == Below) || (stackMode == BottomIf))
  2002. {
  2003. Do_Lower (pCD, (ClientListEntry *) NULL, STACK_NORMAL);
  2004. }
  2005. else if (stackMode == Opposite)
  2006. {
  2007. F_Raise_Lower (NULL, pCD, (XEvent *) configureRequest);
  2008. }
  2009. }
  2010. /* !!! should a synthetic ConfigureNotify be sent? !!! */
  2011. if ((configureRequest->window == pCD->client) &&
  2012. !(mask & (CWX | CWY | CWWidth | CWHeight | CWBorderWidth)))
  2013. {
  2014. SendConfigureNotify (pCD);
  2015. }
  2016. }
  2017. } /* END OF FUNCTION HandleCConfigureRequest */
  2018. /*************************************<->*************************************
  2019. *
  2020. * HandleCColormapNotify (pCD, colorEvent)
  2021. *
  2022. *
  2023. * Description:
  2024. * -----------
  2025. * This function does window management actions associated with a colormap
  2026. * notify event on the client window.
  2027. *
  2028. *
  2029. * Inputs:
  2030. * ------
  2031. * pCD = pointer to client data
  2032. *
  2033. * colorEvent = a ColormapNotify event
  2034. *
  2035. *************************************<->***********************************/
  2036. void HandleCColormapNotify (ClientData *pCD, XColormapEvent *colorEvent)
  2037. {
  2038. int i;
  2039. #ifndef IBM_169380
  2040. ClientData **cmap_window_data;
  2041. #endif
  2042. Boolean newClientColormap = False;
  2043. /*
  2044. * The colormap of the top-level client window or one of its subwindows
  2045. * has been changed.
  2046. */
  2047. if (colorEvent->new)
  2048. {
  2049. /*
  2050. * The colormap has been changed.
  2051. */
  2052. /*
  2053. * !!! when the server ColormapNotify problem is fixed !!!
  2054. * !!! use the colormap id from the event !!!
  2055. */
  2056. if (WmGetWindowAttributes (colorEvent->window))
  2057. {
  2058. colorEvent->colormap = wmGD.windowAttributes.colormap;
  2059. }
  2060. else
  2061. {
  2062. return;
  2063. }
  2064. /*
  2065. * !!! remove the above code when the problem is fixed !!!
  2066. */
  2067. /*
  2068. * Identify the colormap that the window manager has associated
  2069. * with the window.
  2070. */
  2071. #ifndef IBM_169380
  2072. if ((pCD->clientCmapCount == 0) && (colorEvent->window == pCD->client))
  2073. #endif
  2074. if (pCD->clientCmapCount == 0)
  2075. {
  2076. /* no subwindow colormaps; change top-level window colormap */
  2077. #ifdef IBM_169380
  2078. if (colorEvent->window == pCD->client)
  2079. {
  2080. #endif
  2081. if (colorEvent->colormap == None)
  2082. {
  2083. /* use the workspace colormap */
  2084. pCD->clientColormap =
  2085. ACTIVE_PSD->workspaceColormap;
  2086. }
  2087. else
  2088. {
  2089. pCD->clientColormap = colorEvent->colormap;
  2090. }
  2091. newClientColormap = True;
  2092. #ifdef IBM_169380
  2093. }
  2094. #endif
  2095. }
  2096. #ifndef IBM_169380
  2097. if (!XFindContext (DISPLAY, colorEvent->window,
  2098. wmGD.cmapWindowContextType, (caddr_t *)&cmap_window_data))
  2099. {
  2100. /*
  2101. * The WM_COLORMAP_WINDOWS property of a toplevel window may
  2102. * specify colorEvent->window. If so, we must update the
  2103. * colormap information it holds in clientCmapList.
  2104. */
  2105. ClientData *any_pCD;
  2106. int j;
  2107. for (j = 0; cmap_window_data[j] != NULL; j++)
  2108. {
  2109. any_pCD = cmap_window_data[j];
  2110. for (i = 0; i < any_pCD->clientCmapCount; i++)
  2111. {
  2112. if (any_pCD->cmapWindows[i] == colorEvent->window)
  2113. {
  2114. if (colorEvent->colormap == None)
  2115. {
  2116. /* use the workspace colormap */
  2117. any_pCD->clientCmapList[i] =
  2118. ACTIVE_PSD->workspaceColormap;
  2119. }
  2120. else
  2121. {
  2122. any_pCD->clientCmapList[i] = colorEvent->colormap;
  2123. }
  2124. if (i == any_pCD->clientCmapIndex)
  2125. {
  2126. any_pCD->clientColormap =
  2127. any_pCD->clientCmapList[i];
  2128. if (any_pCD == pCD)
  2129. {
  2130. newClientColormap = True;
  2131. }
  2132. }
  2133. break;
  2134. }
  2135. }
  2136. }
  2137. }
  2138. #else
  2139. else
  2140. {
  2141. /* there are subwindow colormaps */
  2142. for (i = 0; i < pCD->clientCmapCount; i++)
  2143. {
  2144. if (pCD->cmapWindows[i] == colorEvent->window)
  2145. {
  2146. if (colorEvent->colormap == None)
  2147. {
  2148. /* use the workspace colormap */
  2149. pCD->clientCmapList[i] =
  2150. ACTIVE_PSD->workspaceColormap;
  2151. }
  2152. else
  2153. {
  2154. pCD->clientCmapList[i] = colorEvent->colormap;
  2155. }
  2156. if (i == pCD->clientCmapIndex)
  2157. {
  2158. newClientColormap = True;
  2159. pCD->clientColormap = pCD->clientCmapList[i];
  2160. }
  2161. break;
  2162. }
  2163. }
  2164. }
  2165. #endif /* IBM_169380 */
  2166. if ((ACTIVE_PSD->colormapFocus == pCD) && newClientColormap &&
  2167. ((pCD->clientState == NORMAL_STATE) ||
  2168. (pCD->clientState == MAXIMIZED_STATE)))
  2169. {
  2170. /*
  2171. * The client window has the colormap focus, install the
  2172. * colormap.
  2173. */
  2174. WmInstallColormap (ACTIVE_PSD, pCD->clientColormap);
  2175. }
  2176. }
  2177. } /* END OF FUNCTION HandleCColormapNotify */
  2178. /*************************************<->*************************************
  2179. *
  2180. * HandleClientMessage (pCD, clientEvent)
  2181. *
  2182. *
  2183. * Description:
  2184. * -----------
  2185. * This function handles client message events that are sent to the root
  2186. * window. The window manager action that is taken depends on the
  2187. * message_type of the event.
  2188. *
  2189. *
  2190. * Inputs:
  2191. * ------
  2192. * pCD = pointer to client data
  2193. *
  2194. * clientEvent = pointer to a client message event on the root window
  2195. *
  2196. *************************************<->***********************************/
  2197. void HandleClientMessage (ClientData *pCD, XClientMessageEvent *clientEvent)
  2198. {
  2199. unsigned int newState = WITHDRAWN_STATE;
  2200. /*
  2201. * Process the client message event based on the message_type.
  2202. */
  2203. if (clientEvent->message_type == wmGD.xa_WM_CHANGE_STATE)
  2204. {
  2205. if ((clientEvent->data.l[0] == IconicState) &&
  2206. (pCD->clientFunctions & MWM_FUNC_MINIMIZE))
  2207. {
  2208. newState = MINIMIZED_STATE;
  2209. }
  2210. else if (clientEvent->data.l[0] == NormalState)
  2211. {
  2212. newState = NORMAL_STATE;
  2213. }
  2214. if (!ClientInWorkspace (ACTIVE_WS, pCD))
  2215. {
  2216. newState |= UNSEEN_STATE;
  2217. }
  2218. SetClientState (pCD, newState, GetTimestamp ());
  2219. }
  2220. } /* END OF FUNCTION HandleClientMessage */
  2221. /*************************************<->*************************************
  2222. *
  2223. * HandleCShapeNotify (pCD, shapeEvent)
  2224. *
  2225. *
  2226. * Description:
  2227. * -----------
  2228. * Handle a shape notify event on a client window. Keeps track of
  2229. * the shaped state of the client window and calls
  2230. * SetFrameShape() to reshape the frame accordingly.
  2231. *
  2232. * Inputs:
  2233. * ------
  2234. * shapeEvent = pointer to a shape notify in event on the client window.
  2235. *
  2236. *************************************<->***********************************/
  2237. void
  2238. HandleCShapeNotify (ClientData *pCD, XShapeEvent *shapeEvent)
  2239. {
  2240. if (pCD)
  2241. {
  2242. if (shapeEvent->kind != ShapeBounding)
  2243. {
  2244. return;
  2245. }
  2246. pCD->wShaped = shapeEvent->shaped;
  2247. SetFrameShape (pCD);
  2248. }
  2249. } /* END OF FUNCTION HandleCShapeNotify */
  2250. /*************************************<->*************************************
  2251. *
  2252. * GetParentWindow (window)
  2253. *
  2254. *
  2255. * Description:
  2256. * -----------
  2257. * This function identifies the parent window of the specified window.
  2258. *
  2259. *
  2260. * Inputs:
  2261. * ------
  2262. * window = find the parent of this window
  2263. *
  2264. * Outputs:
  2265. * -------
  2266. * Return = return the window id of the parent of the specified window
  2267. *
  2268. *************************************<->***********************************/
  2269. Window GetParentWindow (Window window)
  2270. {
  2271. Window root;
  2272. Window parent;
  2273. Window *children;
  2274. unsigned int nchildren;
  2275. if (XQueryTree (DISPLAY, window, &root, &parent, &children, &nchildren))
  2276. {
  2277. if (nchildren)
  2278. {
  2279. XFree ((char *)children);
  2280. }
  2281. }
  2282. else
  2283. {
  2284. parent = (Window)0L;
  2285. }
  2286. return (parent);
  2287. } /* END OF FUNCTION GetParentWindow */
  2288. /*************************************<->*************************************
  2289. *
  2290. * DetermineActiveScreen (pEvent)
  2291. *
  2292. *
  2293. * Description:
  2294. * -----------
  2295. * This function determines the currently active screen
  2296. *
  2297. *
  2298. * Inputs:
  2299. * ------
  2300. * pEvent = pointer to an event structure
  2301. *
  2302. * Outputs:
  2303. * -------
  2304. * ACTIVE_PSD = set to point to the screen data for the currently
  2305. * active scree;
  2306. * wmGD.queryScreen = set to False if we're sure about the ACTIVE_PSD
  2307. * setting
  2308. *
  2309. *************************************<->***********************************/
  2310. void DetermineActiveScreen (XEvent *pEvent)
  2311. {
  2312. WmScreenData *pSD;
  2313. switch (pEvent->type)
  2314. {
  2315. case NoExpose:
  2316. case GraphicsExpose:
  2317. break; /* ignore these events */
  2318. default:
  2319. /*
  2320. * Get the screen that the event occurred on.
  2321. */
  2322. pSD = GetScreenForWindow (pEvent->xany.window);
  2323. if (pSD)
  2324. {
  2325. /*
  2326. * Set the ACTIVE_PSD to the event's screen to
  2327. * make sure the event gets handled correctly.
  2328. */
  2329. SetActiveScreen (pSD);
  2330. }
  2331. break;
  2332. }
  2333. } /* END OF FUNCTION DetermineActiveScreen */
  2334. /*************************************<->*************************************
  2335. *
  2336. * GetScreenForWindow (win)
  2337. *
  2338. *
  2339. * Description:
  2340. * -----------
  2341. * This function determines the screen for a window
  2342. *
  2343. *
  2344. * Inputs:
  2345. * ------
  2346. * win = window id
  2347. *
  2348. * Outputs:
  2349. * -------
  2350. * value of function = pointer to screen data (pSD) or NULL on failure
  2351. *
  2352. *************************************<->***********************************/
  2353. WmScreenData * GetScreenForWindow (Window win)
  2354. {
  2355. XWindowAttributes attribs;
  2356. WmScreenData *pSD = NULL;
  2357. /*
  2358. * Get the screen that the event occurred on.
  2359. */
  2360. if (XGetWindowAttributes (DISPLAY, win, &attribs))
  2361. {
  2362. if (!XFindContext (DISPLAY, attribs.root, wmGD.screenContextType,
  2363. (caddr_t *)&pSD))
  2364. {
  2365. if (pSD && !pSD->screenTopLevelW)
  2366. {
  2367. pSD = NULL;
  2368. }
  2369. }
  2370. }
  2371. return (pSD);
  2372. } /* END OF FUNCTION GetScreenForWindow */