105b261ecSmrg/************************************************************
205b261ecSmrg
305b261ecSmrgCopyright 1989, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included in
1205b261ecSmrgall copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2005b261ecSmrg
2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be
2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings
2305b261ecSmrgin this Software without prior written authorization from The Open Group.
2405b261ecSmrg
2505b261ecSmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California.
2605b261ecSmrg
2705b261ecSmrg			All Rights Reserved
2805b261ecSmrg
2905b261ecSmrgPermission to use, copy, modify, and distribute this software and its
3005b261ecSmrgdocumentation for any purpose and without fee is hereby granted,
3105b261ecSmrgprovided that the above copyright notice appear in all copies and that
3205b261ecSmrgboth that copyright notice and this permission notice appear in
3305b261ecSmrgsupporting documentation, and that the name of Hewlett-Packard not be
3405b261ecSmrgused in advertising or publicity pertaining to distribution of the
3505b261ecSmrgsoftware without specific, written prior permission.
3605b261ecSmrg
3705b261ecSmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
3905b261ecSmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
4305b261ecSmrgSOFTWARE.
4405b261ecSmrg
4505b261ecSmrg********************************************************/
4605b261ecSmrg
4705b261ecSmrg/********************************************************************
4805b261ecSmrg *
4905b261ecSmrg *  Dispatch routines and initialization routines for the X input extension.
5005b261ecSmrg *
5105b261ecSmrg */
5205b261ecSmrg#define	 NUMTYPES 15
5305b261ecSmrg
5405b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
5505b261ecSmrg#include <dix-config.h>
5605b261ecSmrg#endif
5705b261ecSmrg
5805b261ecSmrg#include "inputstr.h"
5935c4bbdfSmrg#include "gcstruct.h"           /* pointer for extnsionst.h */
6035c4bbdfSmrg#include "extnsionst.h"         /* extension entry   */
6105b261ecSmrg#include <X11/extensions/XI.h>
6205b261ecSmrg#include <X11/extensions/XIproto.h>
636747b715Smrg#include <X11/extensions/XI2proto.h>
644642e01fSmrg#include <X11/extensions/geproto.h>
6535c4bbdfSmrg#include "geext.h"              /* extension interfaces for ge */
6605b261ecSmrg
6705b261ecSmrg#include "dixevents.h"
6805b261ecSmrg#include "exevents.h"
6905b261ecSmrg#include "extinit.h"
7005b261ecSmrg#include "exglobals.h"
7105b261ecSmrg#include "swaprep.h"
724642e01fSmrg#include "privates.h"
736747b715Smrg#include "protocol-versions.h"
7405b261ecSmrg
7505b261ecSmrg/* modules local to Xi */
7605b261ecSmrg#include "allowev.h"
7705b261ecSmrg#include "chgdctl.h"
7805b261ecSmrg#include "chgfctl.h"
7905b261ecSmrg#include "chgkbd.h"
8005b261ecSmrg#include "chgprop.h"
8105b261ecSmrg#include "chgptr.h"
8205b261ecSmrg#include "closedev.h"
8305b261ecSmrg#include "devbell.h"
8405b261ecSmrg#include "getbmap.h"
8505b261ecSmrg#include "getdctl.h"
8605b261ecSmrg#include "getfctl.h"
8705b261ecSmrg#include "getfocus.h"
8805b261ecSmrg#include "getkmap.h"
8905b261ecSmrg#include "getmmap.h"
9005b261ecSmrg#include "getprop.h"
9105b261ecSmrg#include "getselev.h"
9205b261ecSmrg#include "getvers.h"
9305b261ecSmrg#include "grabdev.h"
9405b261ecSmrg#include "grabdevb.h"
9505b261ecSmrg#include "grabdevk.h"
9605b261ecSmrg#include "gtmotion.h"
9705b261ecSmrg#include "listdev.h"
9805b261ecSmrg#include "opendev.h"
9905b261ecSmrg#include "queryst.h"
10005b261ecSmrg#include "selectev.h"
10105b261ecSmrg#include "sendexev.h"
10205b261ecSmrg#include "chgkmap.h"
10305b261ecSmrg#include "setbmap.h"
10405b261ecSmrg#include "setdval.h"
10505b261ecSmrg#include "setfocus.h"
10605b261ecSmrg#include "setmmap.h"
10705b261ecSmrg#include "setmode.h"
10805b261ecSmrg#include "ungrdev.h"
10905b261ecSmrg#include "ungrdevb.h"
11005b261ecSmrg#include "ungrdevk.h"
1116747b715Smrg#include "xiallowev.h"
1126747b715Smrg#include "xiselectev.h"
1136747b715Smrg#include "xigrabdev.h"
1146747b715Smrg#include "xipassivegrab.h"
1156747b715Smrg#include "xisetdevfocus.h"
1164642e01fSmrg#include "xiproperty.h"
1176747b715Smrg#include "xichangecursor.h"
1186747b715Smrg#include "xichangehierarchy.h"
1196747b715Smrg#include "xigetclientpointer.h"
1206747b715Smrg#include "xiquerydevice.h"
1216747b715Smrg#include "xiquerypointer.h"
1226747b715Smrg#include "xiqueryversion.h"
1236747b715Smrg#include "xisetclientpointer.h"
1246747b715Smrg#include "xiwarppointer.h"
12535c4bbdfSmrg#include "xibarriers.h"
1266747b715Smrg
1276747b715Smrg/* Masks for XI events have to be aligned with core event (partially anyway).
1286747b715Smrg * If DeviceButtonMotionMask is != ButtonMotionMask, event delivery
1296747b715Smrg * breaks down. The device needs the dev->button->motionMask. If DBMM is
1306747b715Smrg * the same as BMM, we can ensure that both core and device events can be
1316747b715Smrg * delivered, without the need for extra structures in the DeviceIntRec. */
13235c4bbdfSmrgconst Mask DeviceProximityMask = (1L << 4);
13335c4bbdfSmrgconst Mask DeviceStateNotifyMask = (1L << 5);
13435c4bbdfSmrgconst Mask DevicePointerMotionHintMask = PointerMotionHintMask;
13535c4bbdfSmrgconst Mask DeviceButton1MotionMask = Button1MotionMask;
13635c4bbdfSmrgconst Mask DeviceButton2MotionMask = Button2MotionMask;
13735c4bbdfSmrgconst Mask DeviceButton3MotionMask = Button3MotionMask;
13835c4bbdfSmrgconst Mask DeviceButton4MotionMask = Button4MotionMask;
13935c4bbdfSmrgconst Mask DeviceButton5MotionMask = Button5MotionMask;
14035c4bbdfSmrgconst Mask DeviceButtonMotionMask = ButtonMotionMask;
14135c4bbdfSmrgconst Mask DeviceFocusChangeMask = (1L << 14);
14235c4bbdfSmrgconst Mask DeviceMappingNotifyMask = (1L << 15);
14335c4bbdfSmrgconst Mask ChangeDeviceNotifyMask = (1L << 16);
14435c4bbdfSmrgconst Mask DeviceButtonGrabMask = (1L << 17);
14535c4bbdfSmrgconst Mask DeviceOwnerGrabButtonMask = (1L << 17);
14635c4bbdfSmrgconst Mask DevicePresenceNotifyMask = (1L << 18);
14735c4bbdfSmrgconst Mask DevicePropertyNotifyMask = (1L << 19);
14835c4bbdfSmrgconst Mask XIAllMasks = (1L << 20) - 1;
1494642e01fSmrg
15005b261ecSmrgint ExtEventIndex;
15105b261ecSmrg
15235c4bbdfSmrgstatic struct dev_type {
15305b261ecSmrg    Atom type;
15435c4bbdfSmrg    const char *name;
15505b261ecSmrg} dev_type[] = {
15635c4bbdfSmrg    {0, XI_KEYBOARD},
15735c4bbdfSmrg    {0, XI_MOUSE},
15835c4bbdfSmrg    {0, XI_TABLET},
15935c4bbdfSmrg    {0, XI_TOUCHSCREEN},
16035c4bbdfSmrg    {0, XI_TOUCHPAD},
16135c4bbdfSmrg    {0, XI_BARCODE},
16235c4bbdfSmrg    {0, XI_BUTTONBOX},
16335c4bbdfSmrg    {0, XI_KNOB_BOX},
16435c4bbdfSmrg    {0, XI_ONE_KNOB},
16535c4bbdfSmrg    {0, XI_NINE_KNOB},
16635c4bbdfSmrg    {0, XI_TRACKBALL},
16735c4bbdfSmrg    {0, XI_QUADRATURE},
16835c4bbdfSmrg    {0, XI_ID_MODULE},
16935c4bbdfSmrg    {0, XI_SPACEBALL},
17035c4bbdfSmrg    {0, XI_DATAGLOVE},
17135c4bbdfSmrg    {0, XI_EYETRACKER},
17235c4bbdfSmrg    {0, XI_CURSORKEYS},
17335c4bbdfSmrg    {0, XI_FOOTMOUSE}
17435c4bbdfSmrg};
17505b261ecSmrg
17605b261ecSmrgCARD8 event_base[numInputClasses];
17705b261ecSmrgXExtEventInfo EventInfo[32];
17805b261ecSmrg
1796747b715Smrgstatic DeviceIntRec xi_all_devices;
1806747b715Smrgstatic DeviceIntRec xi_all_master_devices;
1816747b715Smrg
1824642e01fSmrg/**
1834642e01fSmrg * Dispatch vector. Functions defined in here will be called when the matching
1844642e01fSmrg * request arrives.
1854642e01fSmrg */
18635c4bbdfSmrgstatic int (*ProcIVector[]) (ClientPtr) = {
18735c4bbdfSmrg    NULL,                       /*  0 */
18835c4bbdfSmrg        ProcXGetExtensionVersion,       /*  1 */
18935c4bbdfSmrg        ProcXListInputDevices,  /*  2 */
19035c4bbdfSmrg        ProcXOpenDevice,        /*  3 */
19135c4bbdfSmrg        ProcXCloseDevice,       /*  4 */
19235c4bbdfSmrg        ProcXSetDeviceMode,     /*  5 */
19335c4bbdfSmrg        ProcXSelectExtensionEvent,      /*  6 */
19435c4bbdfSmrg        ProcXGetSelectedExtensionEvents,        /*  7 */
19535c4bbdfSmrg        ProcXChangeDeviceDontPropagateList,     /*  8 */
19635c4bbdfSmrg        ProcXGetDeviceDontPropagateList,        /*  9 */
19735c4bbdfSmrg        ProcXGetDeviceMotionEvents,     /* 10 */
19835c4bbdfSmrg        ProcXChangeKeyboardDevice,      /* 11 */
19935c4bbdfSmrg        ProcXChangePointerDevice,       /* 12 */
20035c4bbdfSmrg        ProcXGrabDevice,        /* 13 */
20135c4bbdfSmrg        ProcXUngrabDevice,      /* 14 */
20235c4bbdfSmrg        ProcXGrabDeviceKey,     /* 15 */
20335c4bbdfSmrg        ProcXUngrabDeviceKey,   /* 16 */
20435c4bbdfSmrg        ProcXGrabDeviceButton,  /* 17 */
20535c4bbdfSmrg        ProcXUngrabDeviceButton,        /* 18 */
20635c4bbdfSmrg        ProcXAllowDeviceEvents, /* 19 */
20735c4bbdfSmrg        ProcXGetDeviceFocus,    /* 20 */
20835c4bbdfSmrg        ProcXSetDeviceFocus,    /* 21 */
20935c4bbdfSmrg        ProcXGetFeedbackControl,        /* 22 */
21035c4bbdfSmrg        ProcXChangeFeedbackControl,     /* 23 */
21135c4bbdfSmrg        ProcXGetDeviceKeyMapping,       /* 24 */
21235c4bbdfSmrg        ProcXChangeDeviceKeyMapping,    /* 25 */
21335c4bbdfSmrg        ProcXGetDeviceModifierMapping,  /* 26 */
21435c4bbdfSmrg        ProcXSetDeviceModifierMapping,  /* 27 */
21535c4bbdfSmrg        ProcXGetDeviceButtonMapping,    /* 28 */
21635c4bbdfSmrg        ProcXSetDeviceButtonMapping,    /* 29 */
21735c4bbdfSmrg        ProcXQueryDeviceState,  /* 30 */
21835c4bbdfSmrg        ProcXSendExtensionEvent,        /* 31 */
21935c4bbdfSmrg        ProcXDeviceBell,        /* 32 */
22035c4bbdfSmrg        ProcXSetDeviceValuators,        /* 33 */
22135c4bbdfSmrg        ProcXGetDeviceControl,  /* 34 */
22235c4bbdfSmrg        ProcXChangeDeviceControl,       /* 35 */
2234642e01fSmrg        /* XI 1.5 */
22435c4bbdfSmrg        ProcXListDeviceProperties,      /* 36 */
22535c4bbdfSmrg        ProcXChangeDeviceProperty,      /* 37 */
22635c4bbdfSmrg        ProcXDeleteDeviceProperty,      /* 38 */
22735c4bbdfSmrg        ProcXGetDeviceProperty, /* 39 */
2286747b715Smrg        /* XI 2 */
22935c4bbdfSmrg        ProcXIQueryPointer,     /* 40 */
23035c4bbdfSmrg        ProcXIWarpPointer,      /* 41 */
23135c4bbdfSmrg        ProcXIChangeCursor,     /* 42 */
23235c4bbdfSmrg        ProcXIChangeHierarchy,  /* 43 */
23335c4bbdfSmrg        ProcXISetClientPointer, /* 44 */
23435c4bbdfSmrg        ProcXIGetClientPointer, /* 45 */
23535c4bbdfSmrg        ProcXISelectEvents,     /* 46 */
23635c4bbdfSmrg        ProcXIQueryVersion,     /* 47 */
23735c4bbdfSmrg        ProcXIQueryDevice,      /* 48 */
23835c4bbdfSmrg        ProcXISetFocus,         /* 49 */
23935c4bbdfSmrg        ProcXIGetFocus,         /* 50 */
24035c4bbdfSmrg        ProcXIGrabDevice,       /* 51 */
24135c4bbdfSmrg        ProcXIUngrabDevice,     /* 52 */
24235c4bbdfSmrg        ProcXIAllowEvents,      /* 53 */
24335c4bbdfSmrg        ProcXIPassiveGrabDevice,        /* 54 */
24435c4bbdfSmrg        ProcXIPassiveUngrabDevice,      /* 55 */
24535c4bbdfSmrg        ProcXIListProperties,   /* 56 */
24635c4bbdfSmrg        ProcXIChangeProperty,   /* 57 */
24735c4bbdfSmrg        ProcXIDeleteProperty,   /* 58 */
24835c4bbdfSmrg        ProcXIGetProperty,      /* 59 */
24935c4bbdfSmrg        ProcXIGetSelectedEvents, /* 60 */
25035c4bbdfSmrg        ProcXIBarrierReleasePointer /* 61 */
2514642e01fSmrg};
2524642e01fSmrg
2534642e01fSmrg/* For swapped clients */
25435c4bbdfSmrgstatic int (*SProcIVector[]) (ClientPtr) = {
25535c4bbdfSmrg    NULL,                       /*  0 */
25635c4bbdfSmrg        SProcXGetExtensionVersion,      /*  1 */
25735c4bbdfSmrg        SProcXListInputDevices, /*  2 */
25835c4bbdfSmrg        SProcXOpenDevice,       /*  3 */
25935c4bbdfSmrg        SProcXCloseDevice,      /*  4 */
26035c4bbdfSmrg        SProcXSetDeviceMode,    /*  5 */
26135c4bbdfSmrg        SProcXSelectExtensionEvent,     /*  6 */
26235c4bbdfSmrg        SProcXGetSelectedExtensionEvents,       /*  7 */
26335c4bbdfSmrg        SProcXChangeDeviceDontPropagateList,    /*  8 */
26435c4bbdfSmrg        SProcXGetDeviceDontPropagateList,       /*  9 */
26535c4bbdfSmrg        SProcXGetDeviceMotionEvents,    /* 10 */
26635c4bbdfSmrg        SProcXChangeKeyboardDevice,     /* 11 */
26735c4bbdfSmrg        SProcXChangePointerDevice,      /* 12 */
26835c4bbdfSmrg        SProcXGrabDevice,       /* 13 */
26935c4bbdfSmrg        SProcXUngrabDevice,     /* 14 */
27035c4bbdfSmrg        SProcXGrabDeviceKey,    /* 15 */
27135c4bbdfSmrg        SProcXUngrabDeviceKey,  /* 16 */
27235c4bbdfSmrg        SProcXGrabDeviceButton, /* 17 */
27335c4bbdfSmrg        SProcXUngrabDeviceButton,       /* 18 */
27435c4bbdfSmrg        SProcXAllowDeviceEvents,        /* 19 */
27535c4bbdfSmrg        SProcXGetDeviceFocus,   /* 20 */
27635c4bbdfSmrg        SProcXSetDeviceFocus,   /* 21 */
27735c4bbdfSmrg        SProcXGetFeedbackControl,       /* 22 */
27835c4bbdfSmrg        SProcXChangeFeedbackControl,    /* 23 */
27935c4bbdfSmrg        SProcXGetDeviceKeyMapping,      /* 24 */
28035c4bbdfSmrg        SProcXChangeDeviceKeyMapping,   /* 25 */
28135c4bbdfSmrg        SProcXGetDeviceModifierMapping, /* 26 */
28235c4bbdfSmrg        SProcXSetDeviceModifierMapping, /* 27 */
28335c4bbdfSmrg        SProcXGetDeviceButtonMapping,   /* 28 */
28435c4bbdfSmrg        SProcXSetDeviceButtonMapping,   /* 29 */
28535c4bbdfSmrg        SProcXQueryDeviceState, /* 30 */
28635c4bbdfSmrg        SProcXSendExtensionEvent,       /* 31 */
28735c4bbdfSmrg        SProcXDeviceBell,       /* 32 */
28835c4bbdfSmrg        SProcXSetDeviceValuators,       /* 33 */
28935c4bbdfSmrg        SProcXGetDeviceControl, /* 34 */
29035c4bbdfSmrg        SProcXChangeDeviceControl,      /* 35 */
29135c4bbdfSmrg        SProcXListDeviceProperties,     /* 36 */
29235c4bbdfSmrg        SProcXChangeDeviceProperty,     /* 37 */
29335c4bbdfSmrg        SProcXDeleteDeviceProperty,     /* 38 */
29435c4bbdfSmrg        SProcXGetDeviceProperty,        /* 39 */
29535c4bbdfSmrg        SProcXIQueryPointer,    /* 40 */
29635c4bbdfSmrg        SProcXIWarpPointer,     /* 41 */
29735c4bbdfSmrg        SProcXIChangeCursor,    /* 42 */
29835c4bbdfSmrg        SProcXIChangeHierarchy, /* 43 */
29935c4bbdfSmrg        SProcXISetClientPointer,        /* 44 */
30035c4bbdfSmrg        SProcXIGetClientPointer,        /* 45 */
30135c4bbdfSmrg        SProcXISelectEvents,    /* 46 */
30235c4bbdfSmrg        SProcXIQueryVersion,    /* 47 */
30335c4bbdfSmrg        SProcXIQueryDevice,     /* 48 */
30435c4bbdfSmrg        SProcXISetFocus,        /* 49 */
30535c4bbdfSmrg        SProcXIGetFocus,        /* 50 */
30635c4bbdfSmrg        SProcXIGrabDevice,      /* 51 */
30735c4bbdfSmrg        SProcXIUngrabDevice,    /* 52 */
30835c4bbdfSmrg        SProcXIAllowEvents,     /* 53 */
30935c4bbdfSmrg        SProcXIPassiveGrabDevice,       /* 54 */
31035c4bbdfSmrg        SProcXIPassiveUngrabDevice,     /* 55 */
31135c4bbdfSmrg        SProcXIListProperties,  /* 56 */
31235c4bbdfSmrg        SProcXIChangeProperty,  /* 57 */
31335c4bbdfSmrg        SProcXIDeleteProperty,  /* 58 */
31435c4bbdfSmrg        SProcXIGetProperty,     /* 59 */
31535c4bbdfSmrg        SProcXIGetSelectedEvents,       /* 60 */
31635c4bbdfSmrg        SProcXIBarrierReleasePointer /* 61 */
3174642e01fSmrg};
3184642e01fSmrg
31905b261ecSmrg/*****************************************************************
32005b261ecSmrg *
32105b261ecSmrg * Globals referenced elsewhere in the server.
32205b261ecSmrg *
32305b261ecSmrg */
32405b261ecSmrg
32505b261ecSmrgint IReqCode = 0;
3264642e01fSmrgint IEventBase = 0;
32705b261ecSmrgint BadDevice = 0;
32805b261ecSmrgstatic int BadEvent = 1;
32905b261ecSmrgint BadMode = 2;
33005b261ecSmrgint DeviceBusy = 3;
33105b261ecSmrgint BadClass = 4;
33205b261ecSmrg
33305b261ecSmrgint DeviceValuator;
33405b261ecSmrgint DeviceKeyPress;
33505b261ecSmrgint DeviceKeyRelease;
33605b261ecSmrgint DeviceButtonPress;
33705b261ecSmrgint DeviceButtonRelease;
33805b261ecSmrgint DeviceMotionNotify;
33905b261ecSmrgint DeviceFocusIn;
34005b261ecSmrgint DeviceFocusOut;
34105b261ecSmrgint ProximityIn;
34205b261ecSmrgint ProximityOut;
34305b261ecSmrgint DeviceStateNotify;
34405b261ecSmrgint DeviceKeyStateNotify;
34505b261ecSmrgint DeviceButtonStateNotify;
34605b261ecSmrgint DeviceMappingNotify;
34705b261ecSmrgint ChangeDeviceNotify;
34805b261ecSmrgint DevicePresenceNotify;
3494642e01fSmrgint DevicePropertyNotify;
35005b261ecSmrg
35135c4bbdfSmrgRESTYPE RT_INPUTCLIENT;
35205b261ecSmrg
35305b261ecSmrg/*****************************************************************
35405b261ecSmrg *
35505b261ecSmrg * Externs defined elsewhere in the X server.
35605b261ecSmrg *
35705b261ecSmrg */
35805b261ecSmrg
3596747b715Smrgextern XExtensionVersion XIVersion;
36005b261ecSmrg
36105b261ecSmrg/*****************************************************************
36205b261ecSmrg *
3634642e01fSmrg * Versioning support
36405b261ecSmrg *
36505b261ecSmrg */
36605b261ecSmrg
3676747b715SmrgDevPrivateKeyRec XIClientPrivateKeyRec;
3684642e01fSmrg
3694642e01fSmrg/*****************************************************************
3704642e01fSmrg *
3714642e01fSmrg * Declarations of local routines.
3724642e01fSmrg *
3734642e01fSmrg */
3744642e01fSmrg
37505b261ecSmrg/*************************************************************************
37605b261ecSmrg *
37705b261ecSmrg * ProcIDispatch - main dispatch routine for requests to this extension.
37805b261ecSmrg * This routine is used if server and client have the same byte ordering.
37905b261ecSmrg *
38005b261ecSmrg */
38105b261ecSmrg
38205b261ecSmrgstatic int
38305b261ecSmrgProcIDispatch(ClientPtr client)
38405b261ecSmrg{
38505b261ecSmrg    REQUEST(xReq);
386475c125cSmrg    if (stuff->data >= ARRAY_SIZE(ProcIVector) || !ProcIVector[stuff->data])
3874642e01fSmrg        return BadRequest;
3884642e01fSmrg
3891b5d61b8Smrg    UpdateCurrentTimeIf();
39035c4bbdfSmrg    return (*ProcIVector[stuff->data]) (client);
39105b261ecSmrg}
39205b261ecSmrg
39305b261ecSmrg/*******************************************************************************
39405b261ecSmrg *
3954642e01fSmrg * SProcXDispatch
39605b261ecSmrg *
39705b261ecSmrg * Main swapped dispatch routine for requests to this extension.
39805b261ecSmrg * This routine is used if server and client do not have the same byte ordering.
39905b261ecSmrg *
40005b261ecSmrg */
40105b261ecSmrg
4021b5d61b8Smrgstatic int _X_COLD
40305b261ecSmrgSProcIDispatch(ClientPtr client)
40405b261ecSmrg{
40505b261ecSmrg    REQUEST(xReq);
406475c125cSmrg    if (stuff->data >= ARRAY_SIZE(SProcIVector) || !SProcIVector[stuff->data])
4074642e01fSmrg        return BadRequest;
4084642e01fSmrg
4091b5d61b8Smrg    UpdateCurrentTimeIf();
41035c4bbdfSmrg    return (*SProcIVector[stuff->data]) (client);
41105b261ecSmrg}
41205b261ecSmrg
41305b261ecSmrg/**********************************************************************
41405b261ecSmrg *
41505b261ecSmrg * SReplyIDispatch
41605b261ecSmrg * Swap any replies defined in this extension.
41705b261ecSmrg *
41805b261ecSmrg */
41905b261ecSmrg
4201b5d61b8Smrgstatic void _X_COLD
42105b261ecSmrgSReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
42235c4bbdfSmrg{
42335c4bbdfSmrg    /* All we look at is the type field */
42435c4bbdfSmrg    /* This is common to all replies    */
42505b261ecSmrg    if (rep->RepType == X_GetExtensionVersion)
42635c4bbdfSmrg        SRepXGetExtensionVersion(client, len,
42735c4bbdfSmrg                                 (xGetExtensionVersionReply *) rep);
42805b261ecSmrg    else if (rep->RepType == X_ListInputDevices)
42935c4bbdfSmrg        SRepXListInputDevices(client, len, (xListInputDevicesReply *) rep);
43005b261ecSmrg    else if (rep->RepType == X_OpenDevice)
43135c4bbdfSmrg        SRepXOpenDevice(client, len, (xOpenDeviceReply *) rep);
43205b261ecSmrg    else if (rep->RepType == X_SetDeviceMode)
43335c4bbdfSmrg        SRepXSetDeviceMode(client, len, (xSetDeviceModeReply *) rep);
43405b261ecSmrg    else if (rep->RepType == X_GetSelectedExtensionEvents)
43535c4bbdfSmrg        SRepXGetSelectedExtensionEvents(client, len,
43635c4bbdfSmrg                                        (xGetSelectedExtensionEventsReply *)
43735c4bbdfSmrg                                        rep);
43805b261ecSmrg    else if (rep->RepType == X_GetDeviceDontPropagateList)
43935c4bbdfSmrg        SRepXGetDeviceDontPropagateList(client, len,
44035c4bbdfSmrg                                        (xGetDeviceDontPropagateListReply *)
44135c4bbdfSmrg                                        rep);
44205b261ecSmrg    else if (rep->RepType == X_GetDeviceMotionEvents)
44335c4bbdfSmrg        SRepXGetDeviceMotionEvents(client, len,
44435c4bbdfSmrg                                   (xGetDeviceMotionEventsReply *) rep);
44505b261ecSmrg    else if (rep->RepType == X_GrabDevice)
44635c4bbdfSmrg        SRepXGrabDevice(client, len, (xGrabDeviceReply *) rep);
44705b261ecSmrg    else if (rep->RepType == X_GetDeviceFocus)
44835c4bbdfSmrg        SRepXGetDeviceFocus(client, len, (xGetDeviceFocusReply *) rep);
44905b261ecSmrg    else if (rep->RepType == X_GetFeedbackControl)
45035c4bbdfSmrg        SRepXGetFeedbackControl(client, len, (xGetFeedbackControlReply *) rep);
45105b261ecSmrg    else if (rep->RepType == X_GetDeviceKeyMapping)
45235c4bbdfSmrg        SRepXGetDeviceKeyMapping(client, len,
45335c4bbdfSmrg                                 (xGetDeviceKeyMappingReply *) rep);
45405b261ecSmrg    else if (rep->RepType == X_GetDeviceModifierMapping)
45535c4bbdfSmrg        SRepXGetDeviceModifierMapping(client, len,
45635c4bbdfSmrg                                      (xGetDeviceModifierMappingReply *) rep);
45705b261ecSmrg    else if (rep->RepType == X_SetDeviceModifierMapping)
45835c4bbdfSmrg        SRepXSetDeviceModifierMapping(client, len,
45935c4bbdfSmrg                                      (xSetDeviceModifierMappingReply *) rep);
46005b261ecSmrg    else if (rep->RepType == X_GetDeviceButtonMapping)
46135c4bbdfSmrg        SRepXGetDeviceButtonMapping(client, len,
46235c4bbdfSmrg                                    (xGetDeviceButtonMappingReply *) rep);
46305b261ecSmrg    else if (rep->RepType == X_SetDeviceButtonMapping)
46435c4bbdfSmrg        SRepXSetDeviceButtonMapping(client, len,
46535c4bbdfSmrg                                    (xSetDeviceButtonMappingReply *) rep);
46605b261ecSmrg    else if (rep->RepType == X_QueryDeviceState)
46735c4bbdfSmrg        SRepXQueryDeviceState(client, len, (xQueryDeviceStateReply *) rep);
46805b261ecSmrg    else if (rep->RepType == X_SetDeviceValuators)
46935c4bbdfSmrg        SRepXSetDeviceValuators(client, len, (xSetDeviceValuatorsReply *) rep);
47005b261ecSmrg    else if (rep->RepType == X_GetDeviceControl)
47135c4bbdfSmrg        SRepXGetDeviceControl(client, len, (xGetDeviceControlReply *) rep);
47205b261ecSmrg    else if (rep->RepType == X_ChangeDeviceControl)
47335c4bbdfSmrg        SRepXChangeDeviceControl(client, len,
47435c4bbdfSmrg                                 (xChangeDeviceControlReply *) rep);
4754642e01fSmrg    else if (rep->RepType == X_ListDeviceProperties)
47635c4bbdfSmrg        SRepXListDeviceProperties(client, len,
47735c4bbdfSmrg                                  (xListDevicePropertiesReply *) rep);
4784642e01fSmrg    else if (rep->RepType == X_GetDeviceProperty)
47935c4bbdfSmrg        SRepXGetDeviceProperty(client, len, (xGetDevicePropertyReply *) rep);
4806747b715Smrg    else if (rep->RepType == X_XIQueryPointer)
48135c4bbdfSmrg        SRepXIQueryPointer(client, len, (xXIQueryPointerReply *) rep);
4826747b715Smrg    else if (rep->RepType == X_XIGetClientPointer)
48335c4bbdfSmrg        SRepXIGetClientPointer(client, len, (xXIGetClientPointerReply *) rep);
4846747b715Smrg    else if (rep->RepType == X_XIQueryVersion)
48535c4bbdfSmrg        SRepXIQueryVersion(client, len, (xXIQueryVersionReply *) rep);
4866747b715Smrg    else if (rep->RepType == X_XIQueryDevice)
48735c4bbdfSmrg        SRepXIQueryDevice(client, len, (xXIQueryDeviceReply *) rep);
4886747b715Smrg    else if (rep->RepType == X_XIGrabDevice)
48935c4bbdfSmrg        SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
4909ace9065Smrg    else if (rep->RepType == X_XIPassiveGrabDevice)
49135c4bbdfSmrg        SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
4926747b715Smrg    else if (rep->RepType == X_XIListProperties)
49335c4bbdfSmrg        SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);
4946747b715Smrg    else if (rep->RepType == X_XIGetProperty)
49535c4bbdfSmrg        SRepXIGetProperty(client, len, (xXIGetPropertyReply *) rep);
4966747b715Smrg    else if (rep->RepType == X_XIGetSelectedEvents)
49735c4bbdfSmrg        SRepXIGetSelectedEvents(client, len, (xXIGetSelectedEventsReply *) rep);
4986747b715Smrg    else if (rep->RepType == X_XIGetFocus)
49935c4bbdfSmrg        SRepXIGetFocus(client, len, (xXIGetFocusReply *) rep);
50005b261ecSmrg    else {
50135c4bbdfSmrg        FatalError("XINPUT confused sending swapped reply");
50205b261ecSmrg    }
50305b261ecSmrg}
50405b261ecSmrg
50505b261ecSmrg/************************************************************************
50605b261ecSmrg *
50705b261ecSmrg * This function swaps the DeviceValuator event.
50805b261ecSmrg *
50905b261ecSmrg */
51005b261ecSmrg
51105b261ecSmrgstatic void
51205b261ecSmrgSEventDeviceValuator(deviceValuator * from, deviceValuator * to)
51305b261ecSmrg{
51405b261ecSmrg    int i;
515ed6184dfSmrg    INT32 *ip;
51605b261ecSmrg
51705b261ecSmrg    *to = *from;
51835c4bbdfSmrg    swaps(&to->sequenceNumber);
51935c4bbdfSmrg    swaps(&to->device_state);
52005b261ecSmrg    ip = &to->valuator0;
52105b261ecSmrg    for (i = 0; i < 6; i++) {
52235c4bbdfSmrg        swapl(ip + i);
52305b261ecSmrg    }
52405b261ecSmrg}
52505b261ecSmrg
52605b261ecSmrgstatic void
52705b261ecSmrgSEventFocus(deviceFocus * from, deviceFocus * to)
52805b261ecSmrg{
52905b261ecSmrg    *to = *from;
53035c4bbdfSmrg    swaps(&to->sequenceNumber);
53135c4bbdfSmrg    swapl(&to->time);
53235c4bbdfSmrg    swapl(&to->window);
53305b261ecSmrg}
53405b261ecSmrg
53505b261ecSmrgstatic void
53605b261ecSmrgSDeviceStateNotifyEvent(deviceStateNotify * from, deviceStateNotify * to)
53705b261ecSmrg{
53805b261ecSmrg    int i;
539ed6184dfSmrg    INT32 *ip;
54005b261ecSmrg
54105b261ecSmrg    *to = *from;
54235c4bbdfSmrg    swaps(&to->sequenceNumber);
54335c4bbdfSmrg    swapl(&to->time);
54405b261ecSmrg    ip = &to->valuator0;
54505b261ecSmrg    for (i = 0; i < 3; i++) {
54635c4bbdfSmrg        swapl(ip + i);
54705b261ecSmrg    }
54805b261ecSmrg}
54905b261ecSmrg
55005b261ecSmrgstatic void
55105b261ecSmrgSDeviceKeyStateNotifyEvent(deviceKeyStateNotify * from,
55235c4bbdfSmrg                           deviceKeyStateNotify * to)
55305b261ecSmrg{
55405b261ecSmrg    *to = *from;
55535c4bbdfSmrg    swaps(&to->sequenceNumber);
55605b261ecSmrg}
55705b261ecSmrg
55805b261ecSmrgstatic void
55905b261ecSmrgSDeviceButtonStateNotifyEvent(deviceButtonStateNotify * from,
56035c4bbdfSmrg                              deviceButtonStateNotify * to)
56105b261ecSmrg{
56205b261ecSmrg    *to = *from;
56335c4bbdfSmrg    swaps(&to->sequenceNumber);
56405b261ecSmrg}
56505b261ecSmrg
56605b261ecSmrgstatic void
56705b261ecSmrgSChangeDeviceNotifyEvent(changeDeviceNotify * from, changeDeviceNotify * to)
56805b261ecSmrg{
56905b261ecSmrg    *to = *from;
57035c4bbdfSmrg    swaps(&to->sequenceNumber);
57135c4bbdfSmrg    swapl(&to->time);
57205b261ecSmrg}
57305b261ecSmrg
57405b261ecSmrgstatic void
57505b261ecSmrgSDeviceMappingNotifyEvent(deviceMappingNotify * from, deviceMappingNotify * to)
57605b261ecSmrg{
57705b261ecSmrg    *to = *from;
57835c4bbdfSmrg    swaps(&to->sequenceNumber);
57935c4bbdfSmrg    swapl(&to->time);
58005b261ecSmrg}
58105b261ecSmrg
58205b261ecSmrgstatic void
58335c4bbdfSmrgSDevicePresenceNotifyEvent(devicePresenceNotify * from,
58435c4bbdfSmrg                           devicePresenceNotify * to)
58505b261ecSmrg{
58605b261ecSmrg    *to = *from;
58735c4bbdfSmrg    swaps(&to->sequenceNumber);
58835c4bbdfSmrg    swapl(&to->time);
58935c4bbdfSmrg    swaps(&to->control);
59005b261ecSmrg}
59105b261ecSmrg
5924642e01fSmrgstatic void
59335c4bbdfSmrgSDevicePropertyNotifyEvent(devicePropertyNotify * from,
59435c4bbdfSmrg                           devicePropertyNotify * to)
5954642e01fSmrg{
5964642e01fSmrg    *to = *from;
59735c4bbdfSmrg    swaps(&to->sequenceNumber);
59835c4bbdfSmrg    swapl(&to->time);
59935c4bbdfSmrg    swapl(&to->atom);
6004642e01fSmrg}
6014642e01fSmrg
6026747b715Smrgstatic void
60335c4bbdfSmrgSDeviceLeaveNotifyEvent(xXILeaveEvent * from, xXILeaveEvent * to)
6046747b715Smrg{
6056747b715Smrg    *to = *from;
60635c4bbdfSmrg    swaps(&to->sequenceNumber);
60735c4bbdfSmrg    swapl(&to->length);
60835c4bbdfSmrg    swaps(&to->evtype);
60935c4bbdfSmrg    swaps(&to->deviceid);
61035c4bbdfSmrg    swapl(&to->time);
61135c4bbdfSmrg    swapl(&to->root);
61235c4bbdfSmrg    swapl(&to->event);
61335c4bbdfSmrg    swapl(&to->child);
61435c4bbdfSmrg    swapl(&to->root_x);
61535c4bbdfSmrg    swapl(&to->root_y);
61635c4bbdfSmrg    swapl(&to->event_x);
61735c4bbdfSmrg    swapl(&to->event_y);
61835c4bbdfSmrg    swaps(&to->sourceid);
61935c4bbdfSmrg    swaps(&to->buttons_len);
62035c4bbdfSmrg    swapl(&to->mods.base_mods);
62135c4bbdfSmrg    swapl(&to->mods.latched_mods);
62235c4bbdfSmrg    swapl(&to->mods.locked_mods);
6236747b715Smrg}
62405b261ecSmrg
62505b261ecSmrgstatic void
62635c4bbdfSmrgSDeviceChangedEvent(xXIDeviceChangedEvent * from, xXIDeviceChangedEvent * to)
6276747b715Smrg{
6286747b715Smrg    int i, j;
6296747b715Smrg    xXIAnyInfo *any;
6306747b715Smrg
6316747b715Smrg    *to = *from;
6326747b715Smrg    memcpy(&to[1], &from[1], from->length * 4);
6336747b715Smrg
63435c4bbdfSmrg    any = (xXIAnyInfo *) &to[1];
63535c4bbdfSmrg    for (i = 0; i < to->num_classes; i++) {
6366747b715Smrg        int length = any->length;
6376747b715Smrg
63835c4bbdfSmrg        switch (any->type) {
63935c4bbdfSmrg        case KeyClass:
6406747b715Smrg        {
64135c4bbdfSmrg            xXIKeyInfo *ki = (xXIKeyInfo *) any;
64235c4bbdfSmrg            uint32_t *key = (uint32_t *) &ki[1];
64335c4bbdfSmrg
64435c4bbdfSmrg            for (j = 0; j < ki->num_keycodes; j++, key++)
64535c4bbdfSmrg                swapl(key);
64635c4bbdfSmrg            swaps(&ki->num_keycodes);
64735c4bbdfSmrg        }
64835c4bbdfSmrg            break;
64935c4bbdfSmrg        case ButtonClass:
65035c4bbdfSmrg        {
65135c4bbdfSmrg            xXIButtonInfo *bi = (xXIButtonInfo *) any;
65235c4bbdfSmrg            Atom *labels = (Atom *) ((char *) bi + sizeof(xXIButtonInfo) +
65335c4bbdfSmrg                                     pad_to_int32(bits_to_bytes
65435c4bbdfSmrg                                                  (bi->num_buttons)));
65535c4bbdfSmrg            for (j = 0; j < bi->num_buttons; j++)
65635c4bbdfSmrg                swapl(&labels[j]);
65735c4bbdfSmrg            swaps(&bi->num_buttons);
65835c4bbdfSmrg        }
65935c4bbdfSmrg            break;
66035c4bbdfSmrg        case ValuatorClass:
66135c4bbdfSmrg        {
66235c4bbdfSmrg            xXIValuatorInfo *ai = (xXIValuatorInfo *) any;
66335c4bbdfSmrg
66435c4bbdfSmrg            swapl(&ai->label);
66535c4bbdfSmrg            swapl(&ai->min.integral);
66635c4bbdfSmrg            swapl(&ai->min.frac);
66735c4bbdfSmrg            swapl(&ai->max.integral);
66835c4bbdfSmrg            swapl(&ai->max.frac);
66935c4bbdfSmrg            swapl(&ai->resolution);
67035c4bbdfSmrg            swaps(&ai->number);
67135c4bbdfSmrg        }
67235c4bbdfSmrg            break;
6736747b715Smrg        }
6746747b715Smrg
67535c4bbdfSmrg        swaps(&any->type);
67635c4bbdfSmrg        swaps(&any->length);
67735c4bbdfSmrg        swaps(&any->sourceid);
6786747b715Smrg
67935c4bbdfSmrg        any = (xXIAnyInfo *) ((char *) any + length * 4);
6806747b715Smrg    }
6816747b715Smrg
68235c4bbdfSmrg    swaps(&to->sequenceNumber);
68335c4bbdfSmrg    swapl(&to->length);
68435c4bbdfSmrg    swaps(&to->evtype);
68535c4bbdfSmrg    swaps(&to->deviceid);
68635c4bbdfSmrg    swapl(&to->time);
68735c4bbdfSmrg    swaps(&to->num_classes);
68835c4bbdfSmrg    swaps(&to->sourceid);
6896747b715Smrg
6906747b715Smrg}
6916747b715Smrg
69235c4bbdfSmrgstatic void
69335c4bbdfSmrgSDeviceEvent(xXIDeviceEvent * from, xXIDeviceEvent * to)
69405b261ecSmrg{
69505b261ecSmrg    int i;
6966747b715Smrg    char *ptr;
6976747b715Smrg    char *vmask;
69805b261ecSmrg
6996747b715Smrg    memcpy(to, from, sizeof(xEvent) + from->length * 4);
7006747b715Smrg
70135c4bbdfSmrg    swaps(&to->sequenceNumber);
70235c4bbdfSmrg    swapl(&to->length);
70335c4bbdfSmrg    swaps(&to->evtype);
70435c4bbdfSmrg    swaps(&to->deviceid);
70535c4bbdfSmrg    swapl(&to->time);
70635c4bbdfSmrg    swapl(&to->detail);
70735c4bbdfSmrg    swapl(&to->root);
70835c4bbdfSmrg    swapl(&to->event);
70935c4bbdfSmrg    swapl(&to->child);
71035c4bbdfSmrg    swapl(&to->root_x);
71135c4bbdfSmrg    swapl(&to->root_y);
71235c4bbdfSmrg    swapl(&to->event_x);
71335c4bbdfSmrg    swapl(&to->event_y);
71435c4bbdfSmrg    swaps(&to->buttons_len);
71535c4bbdfSmrg    swaps(&to->valuators_len);
71635c4bbdfSmrg    swaps(&to->sourceid);
71735c4bbdfSmrg    swapl(&to->mods.base_mods);
71835c4bbdfSmrg    swapl(&to->mods.latched_mods);
71935c4bbdfSmrg    swapl(&to->mods.locked_mods);
72035c4bbdfSmrg    swapl(&to->mods.effective_mods);
72135c4bbdfSmrg    swapl(&to->flags);
72235c4bbdfSmrg
72335c4bbdfSmrg    ptr = (char *) (&to[1]);
7246747b715Smrg    ptr += from->buttons_len * 4;
72535c4bbdfSmrg    vmask = ptr;                /* valuator mask */
7266747b715Smrg    ptr += from->valuators_len * 4;
72735c4bbdfSmrg    for (i = 0; i < from->valuators_len * 32; i++) {
72835c4bbdfSmrg        if (BitIsOn(vmask, i)) {
72935c4bbdfSmrg            swapl(((uint32_t *) ptr));
7306747b715Smrg            ptr += 4;
73135c4bbdfSmrg            swapl(((uint32_t *) ptr));
7326747b715Smrg            ptr += 4;
7336747b715Smrg        }
7346747b715Smrg    }
7356747b715Smrg}
7366747b715Smrg
73735c4bbdfSmrgstatic void
73835c4bbdfSmrgSDeviceHierarchyEvent(xXIHierarchyEvent * from, xXIHierarchyEvent * to)
7396747b715Smrg{
7406747b715Smrg    int i;
7416747b715Smrg    xXIHierarchyInfo *info;
7426747b715Smrg
7436747b715Smrg    *to = *from;
7446747b715Smrg    memcpy(&to[1], &from[1], from->length * 4);
74535c4bbdfSmrg    swaps(&to->sequenceNumber);
74635c4bbdfSmrg    swapl(&to->length);
74735c4bbdfSmrg    swaps(&to->evtype);
74835c4bbdfSmrg    swaps(&to->deviceid);
74935c4bbdfSmrg    swapl(&to->time);
75035c4bbdfSmrg    swapl(&to->flags);
75135c4bbdfSmrg    swaps(&to->num_info);
75235c4bbdfSmrg
75335c4bbdfSmrg    info = (xXIHierarchyInfo *) &to[1];
75435c4bbdfSmrg    for (i = 0; i < from->num_info; i++) {
75535c4bbdfSmrg        swaps(&info->deviceid);
75635c4bbdfSmrg        swaps(&info->attachment);
7576747b715Smrg        info++;
7586747b715Smrg    }
7596747b715Smrg}
7606747b715Smrg
76135c4bbdfSmrgstatic void
76235c4bbdfSmrgSXIPropertyEvent(xXIPropertyEvent * from, xXIPropertyEvent * to)
7636747b715Smrg{
7646747b715Smrg    *to = *from;
76535c4bbdfSmrg    swaps(&to->sequenceNumber);
76635c4bbdfSmrg    swapl(&to->length);
76735c4bbdfSmrg    swaps(&to->evtype);
76835c4bbdfSmrg    swaps(&to->deviceid);
76935c4bbdfSmrg    swapl(&to->property);
7706747b715Smrg}
7716747b715Smrg
77235c4bbdfSmrgstatic void
77335c4bbdfSmrgSRawEvent(xXIRawEvent * from, xXIRawEvent * to)
7746747b715Smrg{
7756747b715Smrg    int i;
7766747b715Smrg    FP3232 *values;
7776747b715Smrg    unsigned char *mask;
7786747b715Smrg
7796747b715Smrg    memcpy(to, from, sizeof(xEvent) + from->length * 4);
7806747b715Smrg
78135c4bbdfSmrg    swaps(&to->sequenceNumber);
78235c4bbdfSmrg    swapl(&to->length);
78335c4bbdfSmrg    swaps(&to->evtype);
78435c4bbdfSmrg    swaps(&to->deviceid);
78535c4bbdfSmrg    swapl(&to->time);
78635c4bbdfSmrg    swapl(&to->detail);
7876747b715Smrg
78835c4bbdfSmrg    mask = (unsigned char *) &to[1];
78935c4bbdfSmrg    values = (FP3232 *) (mask + from->valuators_len * 4);
7906747b715Smrg
79135c4bbdfSmrg    for (i = 0; i < from->valuators_len * 4 * 8; i++) {
79235c4bbdfSmrg        if (BitIsOn(mask, i)) {
7936747b715Smrg            /* for each bit set there are two FP3232 values on the wire, in
7946747b715Smrg             * the order abcABC for data and data_raw. Here we swap as if
7956747b715Smrg             * they were in aAbBcC order because it's easier and really
7966747b715Smrg             * doesn't matter.
7976747b715Smrg             */
79835c4bbdfSmrg            swapl(&values->integral);
79935c4bbdfSmrg            swapl(&values->frac);
8006747b715Smrg            values++;
80135c4bbdfSmrg            swapl(&values->integral);
80235c4bbdfSmrg            swapl(&values->frac);
8036747b715Smrg            values++;
8046747b715Smrg        }
8056747b715Smrg    }
8066747b715Smrg
80735c4bbdfSmrg    swaps(&to->valuators_len);
8086747b715Smrg}
8096747b715Smrg
81035c4bbdfSmrgstatic void
81135c4bbdfSmrgSTouchOwnershipEvent(xXITouchOwnershipEvent * from, xXITouchOwnershipEvent * to)
81235c4bbdfSmrg{
81335c4bbdfSmrg    *to = *from;
81435c4bbdfSmrg    swaps(&to->sequenceNumber);
81535c4bbdfSmrg    swapl(&to->length);
81635c4bbdfSmrg    swaps(&to->evtype);
81735c4bbdfSmrg    swaps(&to->deviceid);
81835c4bbdfSmrg    swapl(&to->time);
81935c4bbdfSmrg    swaps(&to->sourceid);
82035c4bbdfSmrg    swapl(&to->touchid);
82135c4bbdfSmrg    swapl(&to->flags);
82235c4bbdfSmrg    swapl(&to->root);
82335c4bbdfSmrg    swapl(&to->event);
82435c4bbdfSmrg    swapl(&to->child);
82535c4bbdfSmrg}
82635c4bbdfSmrg
82735c4bbdfSmrgstatic void
82835c4bbdfSmrgSBarrierEvent(xXIBarrierEvent * from,
82935c4bbdfSmrg              xXIBarrierEvent * to) {
83035c4bbdfSmrg
83135c4bbdfSmrg    *to = *from;
83235c4bbdfSmrg
83335c4bbdfSmrg    swaps(&to->sequenceNumber);
83435c4bbdfSmrg    swapl(&to->length);
83535c4bbdfSmrg    swaps(&to->evtype);
83635c4bbdfSmrg    swapl(&to->time);
83735c4bbdfSmrg    swaps(&to->deviceid);
83835c4bbdfSmrg    swaps(&to->sourceid);
83935c4bbdfSmrg    swapl(&to->event);
84035c4bbdfSmrg    swapl(&to->root);
84135c4bbdfSmrg    swapl(&to->root_x);
84235c4bbdfSmrg    swapl(&to->root_y);
84335c4bbdfSmrg
84435c4bbdfSmrg    swapl(&to->dx.integral);
84535c4bbdfSmrg    swapl(&to->dx.frac);
84635c4bbdfSmrg    swapl(&to->dy.integral);
84735c4bbdfSmrg    swapl(&to->dy.frac);
84835c4bbdfSmrg    swapl(&to->dtime);
84935c4bbdfSmrg    swapl(&to->barrier);
85035c4bbdfSmrg    swapl(&to->eventid);
85135c4bbdfSmrg}
8526747b715Smrg
853ed6184dfSmrgstatic void
854ed6184dfSmrgSGesturePinchEvent(xXIGesturePinchEvent* from,
855ed6184dfSmrg                   xXIGesturePinchEvent* to)
856ed6184dfSmrg{
857ed6184dfSmrg    *to = *from;
858ed6184dfSmrg
859ed6184dfSmrg    swaps(&to->sequenceNumber);
860ed6184dfSmrg    swapl(&to->length);
861ed6184dfSmrg    swaps(&to->evtype);
862ed6184dfSmrg    swaps(&to->deviceid);
863ed6184dfSmrg    swapl(&to->time);
864ed6184dfSmrg    swapl(&to->detail);
865ed6184dfSmrg    swapl(&to->root);
866ed6184dfSmrg    swapl(&to->event);
867ed6184dfSmrg    swapl(&to->child);
868ed6184dfSmrg    swapl(&to->root_x);
869ed6184dfSmrg    swapl(&to->root_y);
870ed6184dfSmrg    swapl(&to->event_x);
871ed6184dfSmrg    swapl(&to->event_y);
872ed6184dfSmrg
873ed6184dfSmrg    swapl(&to->delta_x);
874ed6184dfSmrg    swapl(&to->delta_y);
875ed6184dfSmrg    swapl(&to->delta_unaccel_x);
876ed6184dfSmrg    swapl(&to->delta_unaccel_y);
877ed6184dfSmrg    swapl(&to->scale);
878ed6184dfSmrg    swapl(&to->delta_angle);
879ed6184dfSmrg    swaps(&to->sourceid);
880ed6184dfSmrg
881ed6184dfSmrg    swapl(&to->mods.base_mods);
882ed6184dfSmrg    swapl(&to->mods.latched_mods);
883ed6184dfSmrg    swapl(&to->mods.locked_mods);
884ed6184dfSmrg    swapl(&to->mods.effective_mods);
885ed6184dfSmrg    swapl(&to->flags);
886ed6184dfSmrg}
887ed6184dfSmrg
888ed6184dfSmrgstatic void
889ed6184dfSmrgSGestureSwipeEvent(xXIGestureSwipeEvent* from,
890ed6184dfSmrg                   xXIGestureSwipeEvent* to)
891ed6184dfSmrg{
892ed6184dfSmrg    *to = *from;
893ed6184dfSmrg
894ed6184dfSmrg    swaps(&to->sequenceNumber);
895ed6184dfSmrg    swapl(&to->length);
896ed6184dfSmrg    swaps(&to->evtype);
897ed6184dfSmrg    swaps(&to->deviceid);
898ed6184dfSmrg    swapl(&to->time);
899ed6184dfSmrg    swapl(&to->detail);
900ed6184dfSmrg    swapl(&to->root);
901ed6184dfSmrg    swapl(&to->event);
902ed6184dfSmrg    swapl(&to->child);
903ed6184dfSmrg    swapl(&to->root_x);
904ed6184dfSmrg    swapl(&to->root_y);
905ed6184dfSmrg    swapl(&to->event_x);
906ed6184dfSmrg    swapl(&to->event_y);
907ed6184dfSmrg
908ed6184dfSmrg    swapl(&to->delta_x);
909ed6184dfSmrg    swapl(&to->delta_y);
910ed6184dfSmrg    swapl(&to->delta_unaccel_x);
911ed6184dfSmrg    swapl(&to->delta_unaccel_y);
912ed6184dfSmrg    swaps(&to->sourceid);
913ed6184dfSmrg
914ed6184dfSmrg    swapl(&to->mods.base_mods);
915ed6184dfSmrg    swapl(&to->mods.latched_mods);
916ed6184dfSmrg    swapl(&to->mods.locked_mods);
917ed6184dfSmrg    swapl(&to->mods.effective_mods);
918ed6184dfSmrg    swapl(&to->flags);
919ed6184dfSmrg}
920ed6184dfSmrg
9216747b715Smrg/** Event swapping function for XI2 events. */
9221b5d61b8Smrgvoid _X_COLD
9236747b715SmrgXI2EventSwap(xGenericEvent *from, xGenericEvent *to)
9246747b715Smrg{
92535c4bbdfSmrg    switch (from->evtype) {
92635c4bbdfSmrg    case XI_Enter:
92735c4bbdfSmrg    case XI_Leave:
92835c4bbdfSmrg    case XI_FocusIn:
92935c4bbdfSmrg    case XI_FocusOut:
93035c4bbdfSmrg        SDeviceLeaveNotifyEvent((xXILeaveEvent *) from, (xXILeaveEvent *) to);
93135c4bbdfSmrg        break;
93235c4bbdfSmrg    case XI_DeviceChanged:
93335c4bbdfSmrg        SDeviceChangedEvent((xXIDeviceChangedEvent *) from,
93435c4bbdfSmrg                            (xXIDeviceChangedEvent *) to);
93535c4bbdfSmrg        break;
93635c4bbdfSmrg    case XI_HierarchyChanged:
93735c4bbdfSmrg        SDeviceHierarchyEvent((xXIHierarchyEvent *) from,
93835c4bbdfSmrg                              (xXIHierarchyEvent *) to);
93935c4bbdfSmrg        break;
94035c4bbdfSmrg    case XI_PropertyEvent:
94135c4bbdfSmrg        SXIPropertyEvent((xXIPropertyEvent *) from, (xXIPropertyEvent *) to);
94235c4bbdfSmrg        break;
94335c4bbdfSmrg    case XI_Motion:
94435c4bbdfSmrg    case XI_KeyPress:
94535c4bbdfSmrg    case XI_KeyRelease:
94635c4bbdfSmrg    case XI_ButtonPress:
94735c4bbdfSmrg    case XI_ButtonRelease:
94835c4bbdfSmrg    case XI_TouchBegin:
94935c4bbdfSmrg    case XI_TouchUpdate:
95035c4bbdfSmrg    case XI_TouchEnd:
95135c4bbdfSmrg        SDeviceEvent((xXIDeviceEvent *) from, (xXIDeviceEvent *) to);
95235c4bbdfSmrg        break;
95335c4bbdfSmrg    case XI_TouchOwnership:
95435c4bbdfSmrg        STouchOwnershipEvent((xXITouchOwnershipEvent *) from,
95535c4bbdfSmrg                             (xXITouchOwnershipEvent *) to);
95635c4bbdfSmrg        break;
95735c4bbdfSmrg    case XI_RawMotion:
95835c4bbdfSmrg    case XI_RawKeyPress:
95935c4bbdfSmrg    case XI_RawKeyRelease:
96035c4bbdfSmrg    case XI_RawButtonPress:
96135c4bbdfSmrg    case XI_RawButtonRelease:
96235c4bbdfSmrg    case XI_RawTouchBegin:
96335c4bbdfSmrg    case XI_RawTouchUpdate:
96435c4bbdfSmrg    case XI_RawTouchEnd:
96535c4bbdfSmrg        SRawEvent((xXIRawEvent *) from, (xXIRawEvent *) to);
96635c4bbdfSmrg        break;
96735c4bbdfSmrg    case XI_BarrierHit:
96835c4bbdfSmrg    case XI_BarrierLeave:
96935c4bbdfSmrg        SBarrierEvent((xXIBarrierEvent *) from,
97035c4bbdfSmrg                      (xXIBarrierEvent *) to);
97135c4bbdfSmrg        break;
972ed6184dfSmrg    case XI_GesturePinchBegin:
973ed6184dfSmrg    case XI_GesturePinchUpdate:
974ed6184dfSmrg    case XI_GesturePinchEnd:
975ed6184dfSmrg        SGesturePinchEvent((xXIGesturePinchEvent*) from,
976ed6184dfSmrg                           (xXIGesturePinchEvent*) to);
977ed6184dfSmrg        break;
978ed6184dfSmrg    case XI_GestureSwipeBegin:
979ed6184dfSmrg    case XI_GestureSwipeUpdate:
980ed6184dfSmrg    case XI_GestureSwipeEnd:
981ed6184dfSmrg        SGestureSwipeEvent((xXIGestureSwipeEvent*) from,
982ed6184dfSmrg                           (xXIGestureSwipeEvent*) to);
983ed6184dfSmrg        break;
98435c4bbdfSmrg    default:
98535c4bbdfSmrg        ErrorF("[Xi] Unknown event type to swap. This is a bug.\n");
98635c4bbdfSmrg        break;
9876747b715Smrg    }
98805b261ecSmrg}
98905b261ecSmrg
99005b261ecSmrg/**************************************************************************
99105b261ecSmrg *
99205b261ecSmrg * Record an event mask where there is no unique corresponding event type.
99305b261ecSmrg * We can't call SetMaskForEvent, since that would clobber the existing
99405b261ecSmrg * mask for that event.  MotionHint and ButtonMotion are examples.
99505b261ecSmrg *
99605b261ecSmrg * Since extension event types will never be less than 64, we can use
99705b261ecSmrg * 0-63 in the EventInfo array as the "type" to be used to look up this
9984642e01fSmrg * mask.  This means that the corresponding macros such as
99905b261ecSmrg * DevicePointerMotionHint must have access to the same constants.
100005b261ecSmrg *
100105b261ecSmrg */
100205b261ecSmrg
100305b261ecSmrgstatic void
100405b261ecSmrgSetEventInfo(Mask mask, int constant)
100505b261ecSmrg{
100605b261ecSmrg    EventInfo[ExtEventIndex].mask = mask;
100705b261ecSmrg    EventInfo[ExtEventIndex++].type = constant;
100805b261ecSmrg}
100905b261ecSmrg
101005b261ecSmrg/**************************************************************************
101105b261ecSmrg *
101205b261ecSmrg * Assign the specified mask to the specified event.
101305b261ecSmrg *
101405b261ecSmrg */
101505b261ecSmrg
101605b261ecSmrgstatic void
101705b261ecSmrgSetMaskForExtEvent(Mask mask, int event)
101805b261ecSmrg{
10194642e01fSmrg    int i;
102005b261ecSmrg
102105b261ecSmrg    EventInfo[ExtEventIndex].mask = mask;
102205b261ecSmrg    EventInfo[ExtEventIndex++].type = event;
102305b261ecSmrg
102405b261ecSmrg    if ((event < LASTEvent) || (event >= 128))
102535c4bbdfSmrg        FatalError("MaskForExtensionEvent: bogus event number");
10264642e01fSmrg
10274642e01fSmrg    for (i = 0; i < MAXDEVICES; i++)
10284642e01fSmrg        SetMaskForEvent(i, mask, event);
102905b261ecSmrg}
103005b261ecSmrg
103105b261ecSmrg/************************************************************************
103205b261ecSmrg *
103305b261ecSmrg * This function sets up extension event types and masks.
103405b261ecSmrg *
103505b261ecSmrg */
103605b261ecSmrg
103705b261ecSmrgstatic void
103805b261ecSmrgFixExtensionEvents(ExtensionEntry * extEntry)
103905b261ecSmrg{
104005b261ecSmrg    DeviceValuator = extEntry->eventBase;
104105b261ecSmrg    DeviceKeyPress = DeviceValuator + 1;
104205b261ecSmrg    DeviceKeyRelease = DeviceKeyPress + 1;
104305b261ecSmrg    DeviceButtonPress = DeviceKeyRelease + 1;
104405b261ecSmrg    DeviceButtonRelease = DeviceButtonPress + 1;
104505b261ecSmrg    DeviceMotionNotify = DeviceButtonRelease + 1;
104605b261ecSmrg    DeviceFocusIn = DeviceMotionNotify + 1;
104705b261ecSmrg    DeviceFocusOut = DeviceFocusIn + 1;
104805b261ecSmrg    ProximityIn = DeviceFocusOut + 1;
104905b261ecSmrg    ProximityOut = ProximityIn + 1;
105005b261ecSmrg    DeviceStateNotify = ProximityOut + 1;
105105b261ecSmrg    DeviceMappingNotify = DeviceStateNotify + 1;
105205b261ecSmrg    ChangeDeviceNotify = DeviceMappingNotify + 1;
105305b261ecSmrg    DeviceKeyStateNotify = ChangeDeviceNotify + 1;
105405b261ecSmrg    DeviceButtonStateNotify = DeviceKeyStateNotify + 1;
105505b261ecSmrg    DevicePresenceNotify = DeviceButtonStateNotify + 1;
10564642e01fSmrg    DevicePropertyNotify = DevicePresenceNotify + 1;
105705b261ecSmrg
105805b261ecSmrg    event_base[KeyClass] = DeviceKeyPress;
105905b261ecSmrg    event_base[ButtonClass] = DeviceButtonPress;
106005b261ecSmrg    event_base[ValuatorClass] = DeviceMotionNotify;
106105b261ecSmrg    event_base[ProximityClass] = ProximityIn;
106205b261ecSmrg    event_base[FocusClass] = DeviceFocusIn;
106305b261ecSmrg    event_base[OtherClass] = DeviceStateNotify;
106405b261ecSmrg
106505b261ecSmrg    BadDevice += extEntry->errorBase;
106605b261ecSmrg    BadEvent += extEntry->errorBase;
106705b261ecSmrg    BadMode += extEntry->errorBase;
106805b261ecSmrg    DeviceBusy += extEntry->errorBase;
106905b261ecSmrg    BadClass += extEntry->errorBase;
107005b261ecSmrg
1071ed6184dfSmrg    SetMaskForExtEvent(KeyPressMask, DeviceKeyPress);
10726747b715Smrg    SetCriticalEvent(DeviceKeyPress);
107305b261ecSmrg
1074ed6184dfSmrg    SetMaskForExtEvent(KeyReleaseMask, DeviceKeyRelease);
10756747b715Smrg    SetCriticalEvent(DeviceKeyRelease);
107605b261ecSmrg
1077ed6184dfSmrg    SetMaskForExtEvent(ButtonPressMask, DeviceButtonPress);
10786747b715Smrg    SetCriticalEvent(DeviceButtonPress);
107905b261ecSmrg
1080ed6184dfSmrg    SetMaskForExtEvent(ButtonReleaseMask, DeviceButtonRelease);
10816747b715Smrg    SetCriticalEvent(DeviceButtonRelease);
108205b261ecSmrg
10836747b715Smrg    SetMaskForExtEvent(DeviceProximityMask, ProximityIn);
10846747b715Smrg    SetMaskForExtEvent(DeviceProximityMask, ProximityOut);
108505b261ecSmrg
10866747b715Smrg    SetMaskForExtEvent(DeviceStateNotifyMask, DeviceStateNotify);
108705b261ecSmrg
1088ed6184dfSmrg    SetMaskForExtEvent(PointerMotionMask, DeviceMotionNotify);
10896747b715Smrg    SetCriticalEvent(DeviceMotionNotify);
109005b261ecSmrg
109105b261ecSmrg    SetEventInfo(DevicePointerMotionHintMask, _devicePointerMotionHint);
10926747b715Smrg    SetEventInfo(DeviceButton1MotionMask, _deviceButton1Motion);
10936747b715Smrg    SetEventInfo(DeviceButton2MotionMask, _deviceButton2Motion);
10946747b715Smrg    SetEventInfo(DeviceButton3MotionMask, _deviceButton3Motion);
10956747b715Smrg    SetEventInfo(DeviceButton4MotionMask, _deviceButton4Motion);
10966747b715Smrg    SetEventInfo(DeviceButton5MotionMask, _deviceButton5Motion);
109705b261ecSmrg    SetEventInfo(DeviceButtonMotionMask, _deviceButtonMotion);
109805b261ecSmrg
109905b261ecSmrg    SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusIn);
110005b261ecSmrg    SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusOut);
110105b261ecSmrg
11026747b715Smrg    SetMaskForExtEvent(DeviceMappingNotifyMask, DeviceMappingNotify);
11036747b715Smrg    SetMaskForExtEvent(ChangeDeviceNotifyMask, ChangeDeviceNotify);
110405b261ecSmrg
110505b261ecSmrg    SetEventInfo(DeviceButtonGrabMask, _deviceButtonGrab);
110605b261ecSmrg    SetEventInfo(DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton);
110705b261ecSmrg    SetEventInfo(DevicePresenceNotifyMask, _devicePresence);
11084642e01fSmrg    SetMaskForExtEvent(DevicePropertyNotifyMask, DevicePropertyNotify);
11094642e01fSmrg
111005b261ecSmrg    SetEventInfo(0, _noExtensionEvent);
111105b261ecSmrg}
111205b261ecSmrg
111305b261ecSmrg/************************************************************************
111405b261ecSmrg *
11154642e01fSmrg * This function restores extension event types and masks to their
111605b261ecSmrg * initial state.
111705b261ecSmrg *
111805b261ecSmrg */
111905b261ecSmrg
112005b261ecSmrgstatic void
112105b261ecSmrgRestoreExtensionEvents(void)
112205b261ecSmrg{
11234642e01fSmrg    int i, j;
112405b261ecSmrg
112505b261ecSmrg    IReqCode = 0;
11264642e01fSmrg    IEventBase = 0;
112705b261ecSmrg
112805b261ecSmrg    for (i = 0; i < ExtEventIndex - 1; i++) {
112935c4bbdfSmrg        if ((EventInfo[i].type >= LASTEvent) && (EventInfo[i].type < 128)) {
11304642e01fSmrg            for (j = 0; j < MAXDEVICES; j++)
11314642e01fSmrg                SetMaskForEvent(j, 0, EventInfo[i].type);
11324642e01fSmrg        }
113335c4bbdfSmrg        EventInfo[i].mask = 0;
113435c4bbdfSmrg        EventInfo[i].type = 0;
113505b261ecSmrg    }
113605b261ecSmrg    ExtEventIndex = 0;
113705b261ecSmrg    DeviceValuator = 0;
113805b261ecSmrg    DeviceKeyPress = 1;
113905b261ecSmrg    DeviceKeyRelease = 2;
114005b261ecSmrg    DeviceButtonPress = 3;
114105b261ecSmrg    DeviceButtonRelease = 4;
114205b261ecSmrg    DeviceMotionNotify = 5;
114305b261ecSmrg    DeviceFocusIn = 6;
114405b261ecSmrg    DeviceFocusOut = 7;
114505b261ecSmrg    ProximityIn = 8;
114605b261ecSmrg    ProximityOut = 9;
114705b261ecSmrg    DeviceStateNotify = 10;
114805b261ecSmrg    DeviceMappingNotify = 11;
114905b261ecSmrg    ChangeDeviceNotify = 12;
115005b261ecSmrg    DeviceKeyStateNotify = 13;
115105b261ecSmrg    DeviceButtonStateNotify = 13;
115205b261ecSmrg    DevicePresenceNotify = 14;
11534642e01fSmrg    DevicePropertyNotify = 15;
115405b261ecSmrg
115505b261ecSmrg    BadDevice = 0;
115605b261ecSmrg    BadEvent = 1;
115705b261ecSmrg    BadMode = 2;
115805b261ecSmrg    DeviceBusy = 3;
115905b261ecSmrg    BadClass = 4;
116005b261ecSmrg
116105b261ecSmrg}
116205b261ecSmrg
116305b261ecSmrg/***********************************************************************
116405b261ecSmrg *
116505b261ecSmrg * IResetProc.
116605b261ecSmrg * Remove reply-swapping routine.
116705b261ecSmrg * Remove event-swapping routine.
116805b261ecSmrg *
116905b261ecSmrg */
117005b261ecSmrg
117105b261ecSmrgstatic void
117205b261ecSmrgIResetProc(ExtensionEntry * unused)
117305b261ecSmrg{
117405b261ecSmrg    ReplySwapVector[IReqCode] = ReplyNotSwappd;
117505b261ecSmrg    EventSwapVector[DeviceValuator] = NotImplemented;
117605b261ecSmrg    EventSwapVector[DeviceKeyPress] = NotImplemented;
117705b261ecSmrg    EventSwapVector[DeviceKeyRelease] = NotImplemented;
117805b261ecSmrg    EventSwapVector[DeviceButtonPress] = NotImplemented;
117905b261ecSmrg    EventSwapVector[DeviceButtonRelease] = NotImplemented;
118005b261ecSmrg    EventSwapVector[DeviceMotionNotify] = NotImplemented;
118105b261ecSmrg    EventSwapVector[DeviceFocusIn] = NotImplemented;
118205b261ecSmrg    EventSwapVector[DeviceFocusOut] = NotImplemented;
118305b261ecSmrg    EventSwapVector[ProximityIn] = NotImplemented;
118405b261ecSmrg    EventSwapVector[ProximityOut] = NotImplemented;
118505b261ecSmrg    EventSwapVector[DeviceStateNotify] = NotImplemented;
118605b261ecSmrg    EventSwapVector[DeviceKeyStateNotify] = NotImplemented;
118705b261ecSmrg    EventSwapVector[DeviceButtonStateNotify] = NotImplemented;
118805b261ecSmrg    EventSwapVector[DeviceMappingNotify] = NotImplemented;
118905b261ecSmrg    EventSwapVector[ChangeDeviceNotify] = NotImplemented;
119005b261ecSmrg    EventSwapVector[DevicePresenceNotify] = NotImplemented;
11914642e01fSmrg    EventSwapVector[DevicePropertyNotify] = NotImplemented;
119205b261ecSmrg    RestoreExtensionEvents();
119305b261ecSmrg
119435c4bbdfSmrg    free(xi_all_devices.name);
119535c4bbdfSmrg    free(xi_all_master_devices.name);
119635c4bbdfSmrg
119735c4bbdfSmrg    XIBarrierReset();
119835c4bbdfSmrg}
11994642e01fSmrg
120005b261ecSmrg/***********************************************************************
120105b261ecSmrg *
120205b261ecSmrg * Assign an id and type to an input device.
120305b261ecSmrg *
120405b261ecSmrg */
120505b261ecSmrg
12064642e01fSmrgvoid
120735c4bbdfSmrgAssignTypeAndName(DeviceIntPtr dev, Atom type, const char *name)
120805b261ecSmrg{
12096747b715Smrg    dev->xinput_type = type;
12109ace9065Smrg    dev->name = strdup(name);
121105b261ecSmrg}
121205b261ecSmrg
121305b261ecSmrg/***********************************************************************
121405b261ecSmrg *
121505b261ecSmrg * Make device type atoms.
121605b261ecSmrg *
121705b261ecSmrg */
121805b261ecSmrg
121905b261ecSmrgstatic void
122005b261ecSmrgMakeDeviceTypeAtoms(void)
122105b261ecSmrg{
122205b261ecSmrg    int i;
122305b261ecSmrg
122405b261ecSmrg    for (i = 0; i < NUMTYPES; i++)
122535c4bbdfSmrg        dev_type[i].type =
122635c4bbdfSmrg            MakeAtom(dev_type[i].name, strlen(dev_type[i].name), 1);
122705b261ecSmrg}
122805b261ecSmrg
122905b261ecSmrg/*****************************************************************************
123005b261ecSmrg *
123105b261ecSmrg *	SEventIDispatch
123205b261ecSmrg *
123305b261ecSmrg *	Swap any events defined in this extension.
123405b261ecSmrg */
123505b261ecSmrg#define DO_SWAP(func,type) func ((type *)from, (type *)to)
123605b261ecSmrg
12371b5d61b8Smrgstatic void _X_COLD
123835c4bbdfSmrgSEventIDispatch(xEvent *from, xEvent *to)
123905b261ecSmrg{
124005b261ecSmrg    int type = from->u.u.type & 0177;
124105b261ecSmrg
124205b261ecSmrg    if (type == DeviceValuator)
124335c4bbdfSmrg        DO_SWAP(SEventDeviceValuator, deviceValuator);
124405b261ecSmrg    else if (type == DeviceKeyPress) {
124535c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
124635c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
124735c4bbdfSmrg    }
124835c4bbdfSmrg    else if (type == DeviceKeyRelease) {
124935c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
125035c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
125135c4bbdfSmrg    }
125235c4bbdfSmrg    else if (type == DeviceButtonPress) {
125335c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
125435c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
125535c4bbdfSmrg    }
125635c4bbdfSmrg    else if (type == DeviceButtonRelease) {
125735c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
125835c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
125935c4bbdfSmrg    }
126035c4bbdfSmrg    else if (type == DeviceMotionNotify) {
126135c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
126235c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
126335c4bbdfSmrg    }
126435c4bbdfSmrg    else if (type == DeviceFocusIn)
126535c4bbdfSmrg        DO_SWAP(SEventFocus, deviceFocus);
126605b261ecSmrg    else if (type == DeviceFocusOut)
126735c4bbdfSmrg        DO_SWAP(SEventFocus, deviceFocus);
126805b261ecSmrg    else if (type == ProximityIn) {
126935c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
127035c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
127135c4bbdfSmrg    }
127235c4bbdfSmrg    else if (type == ProximityOut) {
127335c4bbdfSmrg        SKeyButtonPtrEvent(from, to);
127435c4bbdfSmrg        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
127535c4bbdfSmrg    }
127635c4bbdfSmrg    else if (type == DeviceStateNotify)
127735c4bbdfSmrg        DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
127805b261ecSmrg    else if (type == DeviceKeyStateNotify)
127935c4bbdfSmrg        DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
128005b261ecSmrg    else if (type == DeviceButtonStateNotify)
128135c4bbdfSmrg        DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
128205b261ecSmrg    else if (type == DeviceMappingNotify)
128335c4bbdfSmrg        DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
128405b261ecSmrg    else if (type == ChangeDeviceNotify)
128535c4bbdfSmrg        DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
12864642e01fSmrg    else if (type == DevicePresenceNotify)
128735c4bbdfSmrg        DO_SWAP(SDevicePresenceNotifyEvent, devicePresenceNotify);
12884642e01fSmrg    else if (type == DevicePropertyNotify)
128935c4bbdfSmrg        DO_SWAP(SDevicePropertyNotifyEvent, devicePropertyNotify);
129005b261ecSmrg    else {
129135c4bbdfSmrg        FatalError("XInputExtension: Impossible event!\n");
129205b261ecSmrg    }
129305b261ecSmrg}
129405b261ecSmrg
129505b261ecSmrg/**********************************************************************
129605b261ecSmrg *
129705b261ecSmrg * IExtensionInit - initialize the input extension.
129805b261ecSmrg *
129905b261ecSmrg * Called from InitExtensions in main() or from QueryExtension() if the
130005b261ecSmrg * extension is dynamically loaded.
130105b261ecSmrg *
130205b261ecSmrg * This extension has several events and errors.
130305b261ecSmrg *
13044642e01fSmrg * XI is mandatory nowadays, so if we fail to init XI, we die.
130505b261ecSmrg */
130605b261ecSmrg
130705b261ecSmrgvoid
130805b261ecSmrgXInputExtensionInit(void)
130905b261ecSmrg{
131005b261ecSmrg    ExtensionEntry *extEntry;
131135c4bbdfSmrg
13126747b715Smrg    XExtensionVersion thisversion = { XI_Present,
13136747b715Smrg        SERVER_XI_MAJOR_VERSION,
13146747b715Smrg        SERVER_XI_MINOR_VERSION,
13156747b715Smrg    };
131605b261ecSmrg
131735c4bbdfSmrg    if (!dixRegisterPrivateKey
131835c4bbdfSmrg        (&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)))
13194642e01fSmrg        FatalError("Cannot request private for XI.\n");
13204642e01fSmrg
132135c4bbdfSmrg    if (!XIBarrierInit())
132235c4bbdfSmrg        FatalError("Could not initialize barriers.\n");
132335c4bbdfSmrg
132405b261ecSmrg    extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
132535c4bbdfSmrg                            SProcIDispatch, IResetProc, StandardMinorOpcode);
132605b261ecSmrg    if (extEntry) {
132735c4bbdfSmrg        IReqCode = extEntry->base;
132835c4bbdfSmrg        IEventBase = extEntry->eventBase;
132935c4bbdfSmrg        XIVersion = thisversion;
133035c4bbdfSmrg        MakeDeviceTypeAtoms();
133135c4bbdfSmrg        RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone,
133235c4bbdfSmrg                                               "INPUTCLIENT");
133335c4bbdfSmrg        if (!RT_INPUTCLIENT)
133435c4bbdfSmrg            FatalError("Failed to add resource type for XI.\n");
133535c4bbdfSmrg        FixExtensionEvents(extEntry);
133635c4bbdfSmrg        ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
133735c4bbdfSmrg        EventSwapVector[DeviceValuator] = SEventIDispatch;
133835c4bbdfSmrg        EventSwapVector[DeviceKeyPress] = SEventIDispatch;
133935c4bbdfSmrg        EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
134035c4bbdfSmrg        EventSwapVector[DeviceButtonPress] = SEventIDispatch;
134135c4bbdfSmrg        EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
134235c4bbdfSmrg        EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
134335c4bbdfSmrg        EventSwapVector[DeviceFocusIn] = SEventIDispatch;
134435c4bbdfSmrg        EventSwapVector[DeviceFocusOut] = SEventIDispatch;
134535c4bbdfSmrg        EventSwapVector[ProximityIn] = SEventIDispatch;
134635c4bbdfSmrg        EventSwapVector[ProximityOut] = SEventIDispatch;
134735c4bbdfSmrg        EventSwapVector[DeviceStateNotify] = SEventIDispatch;
134835c4bbdfSmrg        EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
134935c4bbdfSmrg        EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
135035c4bbdfSmrg        EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
135135c4bbdfSmrg        EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
135235c4bbdfSmrg        EventSwapVector[DevicePresenceNotify] = SEventIDispatch;
135335c4bbdfSmrg
135435c4bbdfSmrg        GERegisterExtension(IReqCode, XI2EventSwap);
135535c4bbdfSmrg
135635c4bbdfSmrg        memset(&xi_all_devices, 0, sizeof(xi_all_devices));
135735c4bbdfSmrg        memset(&xi_all_master_devices, 0, sizeof(xi_all_master_devices));
135835c4bbdfSmrg        xi_all_devices.id = XIAllDevices;
135935c4bbdfSmrg        xi_all_devices.name = strdup("XIAllDevices");
136035c4bbdfSmrg        xi_all_master_devices.id = XIAllMasterDevices;
136135c4bbdfSmrg        xi_all_master_devices.name = strdup("XIAllMasterDevices");
136235c4bbdfSmrg
136335c4bbdfSmrg        inputInfo.all_devices = &xi_all_devices;
136435c4bbdfSmrg        inputInfo.all_master_devices = &xi_all_master_devices;
136535c4bbdfSmrg
136635c4bbdfSmrg        XIResetProperties();
136735c4bbdfSmrg    }
136835c4bbdfSmrg    else {
136935c4bbdfSmrg        FatalError("IExtensionInit: AddExtensions failed\n");
137005b261ecSmrg    }
137105b261ecSmrg}
1372