1966bf024Smrg/* $XFree86: xc/lib/XTrap/XEConTxt.c,v 1.1 2001/11/02 23:29:27 dawes Exp $ */ 2966bf024Smrg/***************************************************************************** 3966bf024SmrgCopyright 1987, 1988, 1989, 1990, 1991, 1994 by Digital Equipment Corp., 4966bf024SmrgMaynard, MA 5966bf024Smrg 6966bf024SmrgPermission to use, copy, modify, and distribute this software and its 7966bf024Smrgdocumentation for any purpose and without fee is hereby granted, 8966bf024Smrgprovided that the above copyright notice appear in all copies and that 9966bf024Smrgboth that copyright notice and this permission notice appear in 10966bf024Smrgsupporting documentation, and that the name of Digital not be 11966bf024Smrgused in advertising or publicity pertaining to distribution of the 12966bf024Smrgsoftware without specific, written prior permission. 13966bf024Smrg 14966bf024SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15966bf024SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16966bf024SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17966bf024SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18966bf024SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19966bf024SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20966bf024SmrgSOFTWARE. 21966bf024Smrg 22966bf024Smrg*****************************************************************************/ 23966bf024Smrg/* 24966bf024Smrg * 25966bf024Smrg * CONTRIBUTORS: 26966bf024Smrg * 27966bf024Smrg * Dick Annicchiarico 28966bf024Smrg * Robert Chesler 29966bf024Smrg * Dan Coutu 30966bf024Smrg * Gene Durso 31966bf024Smrg * Marc Evans 32966bf024Smrg * Alan Jamison 33966bf024Smrg * Mark Henry 34966bf024Smrg * Ken Miller 35966bf024Smrg * 36966bf024Smrg */ 37966bf024Smrg 38966bf024Smrg#define NEED_REPLIES 39966bf024Smrg#define NEED_EVENTS 40966bf024Smrg 41966bf024Smrg 42966bf024Smrg#include <X11/extensions/xtraplib.h> 43966bf024Smrg#include <X11/extensions/xtraplibp.h> 44966bf024Smrg 45966bf024Smrg#ifndef TRUE 46966bf024Smrg# define TRUE 1L 47966bf024Smrg#endif 48966bf024Smrg#ifndef FALSE 49966bf024Smrg# define FALSE 0L 50966bf024Smrg#endif 51966bf024Smrg 52966bf024Smrgstatic XETC TC; 53966bf024Smrg 54966bf024Smrg/* 55966bf024Smrg * This function is used to create a new XTrap context structure. The new 56966bf024Smrg * context is initialized to a hard coded default, then modified by the 57966bf024Smrg * valuemask and values passed in by the caller. 58966bf024Smrg */ 59966bf024Smrg 60966bf024SmrgXETC *XECreateTC(Display *dpy, CARD32 valuemask, XETCValues *value) 61966bf024Smrg{ 62966bf024Smrg static Bool firsttime = True; 63966bf024Smrg register XETC *tc = &TC; 64966bf024Smrg register XETC *last_tc; 65966bf024Smrg XETrapGetAvailRep rep; 66966bf024Smrg 67966bf024Smrg /* If this is the first time here, then initialize the default TC */ 68966bf024Smrg if (firsttime == True) 69966bf024Smrg { 70966bf024Smrg firsttime = False; 71966bf024Smrg /* The first Trap Context is the Template (default) TC */ 7251b8cbaeSmrg memset(tc,0L,sizeof(*tc)); 73966bf024Smrg tc->eventBase = 0x7FFFFFFFL; 74966bf024Smrg tc->errorBase = 0x7FFFFFFFL; 75966bf024Smrg tc->values.v.max_pkt_size = 0x7FFFL; 76966bf024Smrg } 77966bf024Smrg 78966bf024Smrg /* Position to the end of the list */ 79966bf024Smrg for (;tc->next != NULL; tc = tc->next); 80966bf024Smrg 81966bf024Smrg /* Allocate memory for the new context */ 82966bf024Smrg last_tc = tc; /* save the address of the last on the list */ 83966bf024Smrg if ((tc = (tc->next = (XETC *)XtMalloc(sizeof(*tc)))) == NULL) 84966bf024Smrg { /* No memory to build TC, XtMalloc has already reported the error */ 85966bf024Smrg return(NULL); 86966bf024Smrg } 87966bf024Smrg 88966bf024Smrg /* Use the original TC as the template to start from */ 89966bf024Smrg (void)memcpy(tc,&TC,sizeof(TC)); 90966bf024Smrg tc->next = NULL; 91966bf024Smrg tc->dpy = dpy; 92966bf024Smrg tc->xmax_size = XMaxRequestSize(tc->dpy); 93966bf024Smrg 94966bf024Smrg /* Initialize Extension */ 95966bf024Smrg if (!XETrapQueryExtension(dpy,&(tc->eventBase),&(tc->errorBase), 96966bf024Smrg &(tc->extOpcode))) 97966bf024Smrg { 98966bf024Smrg char *params = XTrapExtName; 99966bf024Smrg unsigned int num_params = 1L; 100966bf024Smrg XtWarningMsg("CantLoadExt", "XECreateTC", "XTrapToolkitError", 101966bf024Smrg "Can't load %s extension", ¶ms, &num_params); 102966bf024Smrg (void)XtFree((XtPointer)tc); 103966bf024Smrg last_tc->next = NULL; /* Clear now nonexistant forward pointer */ 104966bf024Smrg return(NULL); 105966bf024Smrg } 106966bf024Smrg 107966bf024Smrg /* Allocate memory for the XLIB transport */ 108966bf024Smrg if ((tc->xbuff = (BYTE *)XtMalloc(tc->xmax_size * sizeof(CARD32) + 109966bf024Smrg SIZEOF(XETrapHeader))) == NULL) 110966bf024Smrg { /* No memory to build TC, XtMalloc has already reported the error */ 111966bf024Smrg (void)XtFree((XtPointer)tc); /* free the allocated TC */ 112966bf024Smrg last_tc->next = NULL; /* Clear now nonexistant forward pointer */ 113966bf024Smrg return(NULL); 114966bf024Smrg } 115966bf024Smrg 116966bf024Smrg /* Decide on a protocol version to communicate with */ 117966bf024Smrg /* would *like* to use XEGetVersionRequest() but it's broken in V3.1 */ 118966bf024Smrg if (XEGetAvailableRequest(tc,&rep) == True) 119966bf024Smrg { 120966bf024Smrg /* stow the protocol number */ 121966bf024Smrg switch (rep.xtrap_protocol) 122966bf024Smrg { 123966bf024Smrg /* known acceptable protocols */ 124966bf024Smrg case 31: 125966bf024Smrg case XETrapProtocol: 126966bf024Smrg tc->protocol = rep.xtrap_protocol; 127966bf024Smrg break; 128966bf024Smrg /* all else */ 129966bf024Smrg default: /* stay backwards compatible */ 130966bf024Smrg tc->protocol = 31; 131966bf024Smrg break; 132966bf024Smrg } 133966bf024Smrg /* TC to contain *oldest* release/version/revision */ 134966bf024Smrg if (XETrapGetAvailRelease(&rep) <= XETrapRelease) 135966bf024Smrg { 136966bf024Smrg tc->release = XETrapGetAvailRelease(&rep); 137966bf024Smrg if (XETrapGetAvailVersion(&rep) <= XETrapVersion) 138966bf024Smrg { 139966bf024Smrg tc->version = XETrapGetAvailVersion(&rep); 140966bf024Smrg tc->revision = (XETrapGetAvailRevision(&rep) <= XETrapRevision ? 141966bf024Smrg XETrapGetAvailRevision(&rep) : XETrapRevision); 142966bf024Smrg } 143966bf024Smrg else 144966bf024Smrg { 145966bf024Smrg tc->version = XETrapVersion; 146966bf024Smrg tc->revision = XETrapRevision; 147966bf024Smrg } 148966bf024Smrg } 149966bf024Smrg else 150966bf024Smrg { 151966bf024Smrg tc->release = XETrapRelease; 152966bf024Smrg tc->version = XETrapVersion; 153966bf024Smrg tc->revision = XETrapRevision; 154966bf024Smrg } 155966bf024Smrg } 156966bf024Smrg else 157966bf024Smrg { /* We can't seem to communicate with the extension! */ 158966bf024Smrg char *params = XTrapExtName; 159966bf024Smrg unsigned int num_params = 1L; 160966bf024Smrg XtWarningMsg("CantComm", "XECreateTC", "XTrapToolkitError", 161966bf024Smrg "Can't communicate with extension %s", ¶ms, &num_params); 162966bf024Smrg (void)XtFree((XtPointer)tc->xbuff);/* de-allocate memory just alloc'd */ 163966bf024Smrg (void)XtFree((XtPointer)tc); /* free the allocated TC */ 164966bf024Smrg last_tc->next = NULL; /* Clear now nonexistant forward pointer */ 165966bf024Smrg return(NULL); 166966bf024Smrg } 167966bf024Smrg 168966bf024Smrg /* Assign the context values the caller provided */ 169966bf024Smrg (void)XEChangeTC(tc, valuemask, value); 170966bf024Smrg 171966bf024Smrg return (tc); 172966bf024Smrg} 173966bf024Smrg 174966bf024Smrg 175966bf024Smrgstatic int CheckChangeBits(XETrapFlags *dest, XETrapFlags *src, INT32 bit) 176966bf024Smrg{ 177966bf024Smrg int chg_flag = False; 178966bf024Smrg 179966bf024Smrg if (!(BitIsFalse(dest->valid,bit) && BitIsFalse(src->valid,bit)) || 180966bf024Smrg !(BitIsTrue(dest->valid,bit) && BitIsTrue(src->valid,bit))) 181966bf024Smrg { 182966bf024Smrg BitCopy(dest->valid, src->valid, bit); 183966bf024Smrg chg_flag = True; 184966bf024Smrg } 185966bf024Smrg if (!(BitIsFalse(dest->data,bit) && BitIsFalse(src->data,bit)) || 186966bf024Smrg !(BitIsTrue(dest->data,bit) && BitIsTrue(src->data,bit))) 187966bf024Smrg { 188966bf024Smrg BitCopy(dest->data, src->data, bit); 189966bf024Smrg chg_flag = True; 190966bf024Smrg } 191966bf024Smrg return(chg_flag); 192966bf024Smrg} 193966bf024Smrg 194966bf024Smrg/* 195966bf024Smrg * This function is called to change one or more parameters used to define 196966bf024Smrg * a context in which XTrap is or will be running. 197966bf024Smrg */ 198966bf024Smrgint XEChangeTC(XETC *tc, CARD32 mask, XETCValues *values) 199966bf024Smrg{ 200966bf024Smrg int status = True; 201966bf024Smrg register XETCValues *tval = &(tc->values); 202966bf024Smrg register int i; 203966bf024Smrg 204966bf024Smrg if (mask & TCStatistics) 205966bf024Smrg { /* Statistics need changing */ 206966bf024Smrg if(CheckChangeBits(&(tval->v.flags), &(values->v.flags), 207966bf024Smrg XETrapStatistics)) 208966bf024Smrg { 209966bf024Smrg tc->dirty |= TCStatistics; 210966bf024Smrg } 211966bf024Smrg } 212966bf024Smrg if (mask & TCRequests) 213966bf024Smrg { /* Requests need changing */ 214966bf024Smrg CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapRequest); 215966bf024Smrg for (i=0; i<256L; i++) 216966bf024Smrg { 217966bf024Smrg XETrapSetCfgFlagReq(tval, i, BitValue(values->v.flags.req,i)); 218966bf024Smrg } 219966bf024Smrg tc->dirty |= TCRequests; 220966bf024Smrg } 221966bf024Smrg if (mask & TCEvents) 222966bf024Smrg { /* Events need changing */ 223966bf024Smrg CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapEvent); 224966bf024Smrg for (i=KeyPress; i<=MotionNotify; i++) 225966bf024Smrg { 226966bf024Smrg XETrapSetCfgFlagEvt(tval, i, BitValue(values->v.flags.event,i)); 227966bf024Smrg } 228966bf024Smrg tc->dirty |= TCEvents; 229966bf024Smrg } 230966bf024Smrg if (mask & TCMaxPacket) 231966bf024Smrg { /* MaxPacket needs changing */ 232966bf024Smrg CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapMaxPacket); 233966bf024Smrg XETrapSetCfgMaxPktSize(tval, values->v.max_pkt_size); 234966bf024Smrg tc->dirty |= TCMaxPacket; 235966bf024Smrg } 236966bf024Smrg if (mask & TCCmdKey) 237966bf024Smrg { /* CmdKey needs changing */ 238966bf024Smrg CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapCmd); 239966bf024Smrg tval->v.cmd_key = values->v.cmd_key; 240966bf024Smrg CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapCmdKeyMod); 241966bf024Smrg tc->dirty |= TCCmdKey; 242966bf024Smrg } 243966bf024Smrg if (mask & TCTimeStamps) 244966bf024Smrg { /* TimeStamps needs changing */ 245966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapTimestamp)) 246966bf024Smrg { 247966bf024Smrg tc->dirty |= TCTimeStamps; 248966bf024Smrg } 249966bf024Smrg BitCopy(tval->tc_flags, values->tc_flags, XETCDeltaTimes); 250966bf024Smrg } 251966bf024Smrg if (mask & TCWinXY) 252966bf024Smrg { /* Window XY's need changing */ 253966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags), XETrapWinXY)) 254966bf024Smrg { 255966bf024Smrg tc->dirty |= TCWinXY; 256966bf024Smrg } 257966bf024Smrg } 258966bf024Smrg if (mask & TCCursor) 259966bf024Smrg { /* Window XY's need changing */ 260966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags),XETrapCursor)) 261966bf024Smrg { 262966bf024Smrg tc->dirty |= TCCursor; 263966bf024Smrg } 264966bf024Smrg } 265966bf024Smrg if (mask & TCXInput) 266966bf024Smrg { /* XInput flag needs changing */ 267966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags),XETrapXInput)) 268966bf024Smrg { 269966bf024Smrg tc->dirty |= TCXInput; 270966bf024Smrg } 271966bf024Smrg } 272966bf024Smrg if (mask & TCColorReplies) 273966bf024Smrg { /* ColorReplies flag needs changing */ 274966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags), 275966bf024Smrg XETrapColorReplies)) 276966bf024Smrg { 277966bf024Smrg tc->dirty |= TCColorReplies; 278966bf024Smrg } 279966bf024Smrg } 280966bf024Smrg if (mask & TCGrabServer ) 281966bf024Smrg { /* GrabServer flag needs changing */ 282966bf024Smrg if (CheckChangeBits(&(tval->v.flags), &(values->v.flags), 283966bf024Smrg XETrapGrabServer )) 284966bf024Smrg { 285966bf024Smrg tc->dirty |= TCGrabServer; 286966bf024Smrg } 287966bf024Smrg } 288966bf024Smrg if (XETrapGetTCFlagTrapActive(tc)) 289966bf024Smrg { 290966bf024Smrg status = XEFlushConfig(tc); 291966bf024Smrg } 292966bf024Smrg#ifdef VMS 293966bf024Smrg sys$setast(True); /* Make sure AST's are enabled */ 294966bf024Smrg#endif /* VMS */ 295966bf024Smrg return(status); 296966bf024Smrg} 297966bf024Smrg 298966bf024Smrg 299966bf024Smrgvoid XEFreeTC(XETC *tc) 300966bf024Smrg{ 301966bf024Smrg register XETC *list = &TC; 302966bf024Smrg 303966bf024Smrg if (tc) 304966bf024Smrg { 305966bf024Smrg while(list->next != NULL) 306966bf024Smrg { 307966bf024Smrg if (list->next == tc) 308966bf024Smrg list->next = list->next->next; /* Got it, remove from list */ 309966bf024Smrg else 310966bf024Smrg list = list->next; /* Update the list pointer */ 311966bf024Smrg } 312966bf024Smrg if (tc->values.req_cb) 313966bf024Smrg { 314966bf024Smrg XtFree((XtPointer)tc->values.req_cb); 315966bf024Smrg } 316966bf024Smrg if (tc->values.evt_cb) 317966bf024Smrg { 318966bf024Smrg XtFree((XtPointer)tc->values.evt_cb); 319966bf024Smrg } 320966bf024Smrg if (tc->xbuff != NULL) 321966bf024Smrg { 322966bf024Smrg XtFree((XtPointer)tc->xbuff); 323966bf024Smrg } 324966bf024Smrg 325966bf024Smrg XtFree((XtPointer)tc); 326966bf024Smrg } 327966bf024Smrg return; 328966bf024Smrg} 329966bf024Smrg 330966bf024Smrg/* The following are Convenience routines for setting values within 331966bf024Smrg * the Trap Context. These are analogous to the GC's Convenience 332966bf024Smrg * Functions such as XSetState & XSetForeground 333966bf024Smrg */ 334966bf024Smrgint XETrapSetMaxPacket(XETC *tc, Bool set_flag, CARD16 size) 335966bf024Smrg{ 336966bf024Smrg XETCValues tcv; 337966bf024Smrg int status = True; 338966bf024Smrg 33951b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 340966bf024Smrg XETrapSetCfgFlagMaxPacket(&tcv, valid, True); 341966bf024Smrg XETrapSetCfgFlagMaxPacket(&tcv, data, set_flag); 342966bf024Smrg XETrapSetCfgMaxPktSize(&tcv, size); 343966bf024Smrg status = XEChangeTC(tc, TCMaxPacket, &tcv); 344966bf024Smrg return(status); 345966bf024Smrg} 346966bf024Smrgint XETrapSetCommandKey(XETC *tc, Bool set_flag, KeySym cmd_key, Bool mod_flag) 347966bf024Smrg{ 348966bf024Smrg XETCValues tcv; 349966bf024Smrg int status = True; 350966bf024Smrg KeyCode cmd_keycode; 351966bf024Smrg 35251b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 353966bf024Smrg XETrapSetCfgFlagCmd(&tcv, valid, True); 354966bf024Smrg XETrapSetCfgFlagCmd(&tcv, data, set_flag); 355966bf024Smrg if (set_flag == True) 356966bf024Smrg { 357966bf024Smrg XETrapSetCfgFlagCmdKeyMod(&tcv, valid, True); 358966bf024Smrg XETrapSetCfgFlagCmdKeyMod(&tcv, data, mod_flag); 359966bf024Smrg if (!(cmd_keycode = XKeysymToKeycode(XETrapGetDpy(tc), cmd_key))) 360966bf024Smrg { 361966bf024Smrg status = False; 362966bf024Smrg } 363966bf024Smrg else 364966bf024Smrg { 365966bf024Smrg XETrapSetCfgCmdKey(&tcv, cmd_keycode); 366966bf024Smrg } 367966bf024Smrg } 368966bf024Smrg else 369966bf024Smrg { /* Clear command key */ 370966bf024Smrg XETrapSetCfgFlagCmdKeyMod(&tcv, valid, True); 371966bf024Smrg XETrapSetCfgFlagCmdKeyMod(&tcv, data, False); 372966bf024Smrg XETrapSetCfgCmdKey(&tcv, 0); 373966bf024Smrg } 374966bf024Smrg if (status == True) 375966bf024Smrg { 376966bf024Smrg status = XEChangeTC(tc, TCCmdKey, &tcv); 377966bf024Smrg } 378966bf024Smrg return(status); 379966bf024Smrg} 380966bf024Smrg 381966bf024Smrgint XETrapSetTimestamps(XETC *tc, Bool set_flag, Bool delta_flag) 382966bf024Smrg{ 383966bf024Smrg XETCValues tcv; 384966bf024Smrg int status = True; 385966bf024Smrg 38651b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 387966bf024Smrg XETrapSetCfgFlagTimestamp(&tcv, valid, True); 388966bf024Smrg XETrapSetCfgFlagTimestamp(&tcv, data, set_flag); 389966bf024Smrg XETrapSetValFlagDeltaTimes(&tcv, delta_flag); 390966bf024Smrg status = XEChangeTC(tc, TCTimeStamps, &tcv); 391966bf024Smrg return(status); 392966bf024Smrg} 393966bf024Smrg 394966bf024Smrgint XETrapSetWinXY(XETC *tc, Bool set_flag) 395966bf024Smrg{ 396966bf024Smrg XETCValues tcv; 397966bf024Smrg int status = True; 398966bf024Smrg 39951b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 400966bf024Smrg XETrapSetCfgFlagWinXY(&tcv, valid, True); 401966bf024Smrg XETrapSetCfgFlagWinXY(&tcv, data, set_flag); 402966bf024Smrg status = XEChangeTC(tc, TCWinXY, &tcv); 403966bf024Smrg return(status); 404966bf024Smrg} 405966bf024Smrg 406966bf024Smrgint XETrapSetCursor(XETC *tc, Bool set_flag) 407966bf024Smrg{ 408966bf024Smrg XETCValues tcv; 409966bf024Smrg int status = True; 410966bf024Smrg 41151b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 412966bf024Smrg XETrapSetCfgFlagCursor(&tcv, valid, True); 413966bf024Smrg XETrapSetCfgFlagCursor(&tcv, data, set_flag); 414966bf024Smrg status = XEChangeTC(tc, TCCursor, &tcv); 415966bf024Smrg return(status); 416966bf024Smrg} 417966bf024Smrg 418966bf024Smrgint XETrapSetXInput(XETC *tc, Bool set_flag) 419966bf024Smrg{ 420966bf024Smrg XETCValues tcv; 421966bf024Smrg int status = True; 422966bf024Smrg 42351b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 424966bf024Smrg XETrapSetCfgFlagXInput(&tcv, valid, True); 425966bf024Smrg XETrapSetCfgFlagXInput(&tcv, data, set_flag); 426966bf024Smrg status = XEChangeTC(tc, TCXInput, &tcv); 427966bf024Smrg return(status); 428966bf024Smrg} 429966bf024Smrg 430966bf024Smrgint XETrapSetColorReplies(XETC *tc, Bool set_flag) 431966bf024Smrg{ 432966bf024Smrg XETCValues tcv; 433966bf024Smrg int status = True; 434966bf024Smrg 43551b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 436966bf024Smrg XETrapSetCfgFlagColorReplies(&tcv, valid, True); 437966bf024Smrg XETrapSetCfgFlagColorReplies(&tcv, data, set_flag); 438966bf024Smrg status = XEChangeTC(tc, TCColorReplies, &tcv); 439966bf024Smrg return(status); 440966bf024Smrg} 441966bf024Smrg 442966bf024Smrgint XETrapSetGrabServer(XETC *tc, Bool set_flag) 443966bf024Smrg{ 444966bf024Smrg XETCValues tcv; 445966bf024Smrg int status = True; 446966bf024Smrg 44751b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 448966bf024Smrg XETrapSetCfgFlagGrabServer(&tcv, valid, True); 449966bf024Smrg XETrapSetCfgFlagGrabServer(&tcv, data, set_flag); 450966bf024Smrg status = XEChangeTC(tc, TCGrabServer, &tcv); 451966bf024Smrg return(status); 452966bf024Smrg} 453966bf024Smrg 454966bf024Smrgint XETrapSetStatistics(XETC *tc, Bool set_flag) 455966bf024Smrg{ 456966bf024Smrg XETCValues tcv; 457966bf024Smrg int status = True; 458966bf024Smrg 45951b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 460966bf024Smrg XETrapSetCfgFlagStatistics(&tcv, valid, True); 461966bf024Smrg XETrapSetCfgFlagStatistics(&tcv, data, set_flag); 462966bf024Smrg status = XEChangeTC(tc, TCStatistics, &tcv); 463966bf024Smrg return(status); 464966bf024Smrg} 465966bf024Smrg 466966bf024Smrgint XETrapSetRequests(XETC *tc, Bool set_flag, ReqFlags requests) 467966bf024Smrg{ 468966bf024Smrg XETCValues tcv; 469966bf024Smrg int status = True; 470966bf024Smrg int i; 471966bf024Smrg 47251b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 473966bf024Smrg XETrapSetCfgFlagRequest(&tcv, valid, True); 474966bf024Smrg XETrapSetCfgFlagRequest(&tcv, data, set_flag); 475966bf024Smrg for (i=0; i<256L; i++) 476966bf024Smrg { 477966bf024Smrg XETrapSetCfgFlagReq(&tcv, i, BitValue(requests, i)); 478966bf024Smrg } 479966bf024Smrg status = XEChangeTC(tc, TCRequests, &tcv); 480966bf024Smrg return(status); 481966bf024Smrg} 482966bf024Smrg 483966bf024Smrgint XETrapSetEvents(XETC *tc, Bool set_flag, EventFlags events) 484966bf024Smrg{ 485966bf024Smrg XETCValues tcv; 486966bf024Smrg int status = True; 487966bf024Smrg int i; 488966bf024Smrg 48951b8cbaeSmrg memset((char *)&tcv,0L,sizeof(tcv)); 490966bf024Smrg XETrapSetCfgFlagEvent(&tcv, valid, True); 491966bf024Smrg XETrapSetCfgFlagEvent(&tcv, data, set_flag); 492966bf024Smrg for (i=KeyPress; i<=MotionNotify; i++) 493966bf024Smrg { 494966bf024Smrg XETrapSetCfgFlagEvt(&tcv, i, BitValue(events, i)); 495966bf024Smrg } 496966bf024Smrg status = XEChangeTC(tc, (CARD32)TCEvents, &tcv); 497966bf024Smrg return(status); 498966bf024Smrg} 499966bf024Smrg 500966bf024SmrgBool XESetCmdGateState(XETC *tc, CARD8 type, Bool *gate_closed, 501966bf024Smrg CARD8 *next_key, Bool *key_ignore) 502966bf024Smrg{ 503966bf024Smrg 504966bf024Smrg *key_ignore = False; 505966bf024Smrg if (XETrapGetTCFlagCmdKeyMod(tc,data) == True) 506966bf024Smrg { 507966bf024Smrg switch (type) 508966bf024Smrg { 509966bf024Smrg case KeyPress: 510966bf024Smrg if (*next_key == XEKeyIsEcho) 511966bf024Smrg { 512966bf024Smrg break; 513966bf024Smrg } 514966bf024Smrg *gate_closed = True; 515966bf024Smrg *next_key = XEKeyIsClear; 516966bf024Smrg break; 517966bf024Smrg 518966bf024Smrg case KeyRelease: 519966bf024Smrg if (*next_key == XEKeyIsEcho) 520966bf024Smrg { 521966bf024Smrg *next_key = XEKeyIsClear; 522966bf024Smrg break; 523966bf024Smrg } 524966bf024Smrg if (*next_key == XEKeyIsClear) 525966bf024Smrg { 526966bf024Smrg *next_key = XEKeyIsEcho; 527966bf024Smrg } 528966bf024Smrg else 529966bf024Smrg { /* it's XEKeyIsOther, so Clear it */ 530966bf024Smrg *next_key = XEKeyIsClear; 531966bf024Smrg } 532966bf024Smrg *gate_closed = False; 533966bf024Smrg *key_ignore = True; 534966bf024Smrg break; 535966bf024Smrg 536966bf024Smrg default: break; 537966bf024Smrg } 538966bf024Smrg } 539966bf024Smrg else 540966bf024Smrg { 541966bf024Smrg switch (type) 542966bf024Smrg { 543966bf024Smrg case KeyPress: 544966bf024Smrg if (*next_key == XEKeyIsEcho) 545966bf024Smrg { 546966bf024Smrg *gate_closed = False; 547966bf024Smrg break; 548966bf024Smrg } 549966bf024Smrg /* Open gate on cmd key release */ 550966bf024Smrg if ((*next_key == XEKeyIsOther) && 551966bf024Smrg *gate_closed == True) 552966bf024Smrg { 553966bf024Smrg break; 554966bf024Smrg } 555966bf024Smrg *gate_closed = True; 556966bf024Smrg *next_key = XEKeyIsClear; 557966bf024Smrg break; 558966bf024Smrg 559966bf024Smrg case KeyRelease: 560966bf024Smrg if (*next_key == XEKeyIsClear) 561966bf024Smrg { 562966bf024Smrg *next_key = XEKeyIsEcho; 563966bf024Smrg break; 564966bf024Smrg } 565966bf024Smrg 566966bf024Smrg if (*next_key == XEKeyIsEcho) 567966bf024Smrg { 568966bf024Smrg *next_key = XEKeyIsClear; 569966bf024Smrg break; 570966bf024Smrg } 571966bf024Smrg 572966bf024Smrg *gate_closed = False; 573966bf024Smrg *key_ignore = True; 574966bf024Smrg *next_key = XEKeyIsClear; 575966bf024Smrg break; 576966bf024Smrg 577966bf024Smrg default: 578966bf024Smrg break; 579966bf024Smrg } 580966bf024Smrg } 581966bf024Smrg 582966bf024Smrg return(*gate_closed); 583966bf024Smrg} 584