[PATCH] Added processing of confine protocol.

Peter Hutterer peter.hutterer at who-t.net
Sun May 8 19:42:23 PDT 2011


On Thu, May 05, 2011 at 04:26:19PM +0200, Philipp Reh wrote:
> ---
>  Xi/extinit.c       |    8 ++-
>  Xi/xigrabdev.c     |  101 +++++++++++++++++++++++++++++--------
>  Xi/xigrabdev.h     |    3 +
>  Xi/xipassivegrab.c |  139 +++++++++++++++++++++++++++++++++++++++-------------
>  Xi/xipassivegrab.h |    2 +
>  5 files changed, 194 insertions(+), 59 deletions(-)
> 
> diff --git a/Xi/extinit.c b/Xi/extinit.c
> index 51e0078..4a6f4cc 100644
> --- a/Xi/extinit.c
> +++ b/Xi/extinit.c
> @@ -259,7 +259,9 @@ static int (*ProcIVector[])(ClientPtr) = {
>          ProcXIChangeProperty,                   /* 57 */
>          ProcXIDeleteProperty,                   /* 58 */
>          ProcXIGetProperty,                      /* 59 */
> -        ProcXIGetSelectedEvents                 /* 60 */
> +        ProcXIGetSelectedEvents,                /* 60 */
> +        ProcXIGrabDeviceWithConfine,            /* 61 */
> +        ProcXIPassiveGrabDeviceWithConfine      /* 62 */
>  };
>  
>  /* For swapped clients */
> @@ -324,7 +326,9 @@ static int (*SProcIVector[])(ClientPtr) = {
>          SProcXIChangeProperty,                   /* 57 */
>          SProcXIDeleteProperty,                   /* 58 */
>          SProcXIGetProperty,                      /* 59 */
> -        SProcXIGetSelectedEvents                 /* 60 */
> +        SProcXIGetSelectedEvents,                /* 60 */
> +        SProcXIGrabDeviceWithConfine,            /* 61 */
> +        SProcXIPassiveGrabDeviceWithConfine      /* 62 */
>  };
>  
>  /*****************************************************************
> diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
> index 0adc878..25b19aa 100644
> --- a/Xi/xigrabdev.c
> +++ b/Xi/xigrabdev.c
> @@ -42,25 +42,25 @@
>  #include "exevents.h"
>  #include "xigrabdev.h"
>  
> -int
> -SProcXIGrabDevice(ClientPtr client)
> +static void
> +XIConvertGrabDeviceReq(xXIGrabDeviceWithConfineReq *result, xXIGrabDeviceReq *source)
>  {
> -    char n;
> -
> -    REQUEST(xXIGrabDeviceReq);
> -
> -    swaps(&stuff->length, n);
> -    swaps(&stuff->deviceid, n);
> -    swapl(&stuff->grab_window, n);
> -    swapl(&stuff->cursor, n);
> -    swapl(&stuff->time, n);
> -    swaps(&stuff->mask_len, n);
> -
> -    return ProcXIGrabDevice(client);
> +    result->reqType = X_XIGrabDeviceWithConfine;
> +    result->length = source->length + 1; /* length is always in 4 bytes, + 1 for confine_to field */
> +    result->grab_window = source->grab_window;
> +    result->confine_to = None;
> +    result->time = source->time;
> +    result->cursor = source->cursor;
> +    result->deviceid = source->deviceid;
> +    result->grab_mode = source->grab_mode;
> +    result->paired_device_mode = source->paired_device_mode;
> +    result->owner_events = source->owner_events;
> +    /*result->pad*/
> +    result->mask_len = source->mask_len;
>  }
>  
> -int
> -ProcXIGrabDevice(ClientPtr client)
> +static int
> +XIGrabDeviceImpl(ClientPtr client, xXIGrabDeviceWithConfineReq *stuff, unsigned char *extra)
>  {
>      DeviceIntPtr dev;
>      xXIGrabDeviceReply rep;
> @@ -69,9 +69,6 @@ ProcXIGrabDevice(ClientPtr client)
>      GrabMask mask;
>      int mask_len;
>  
> -    REQUEST(xXIGrabDeviceReq);
> -    REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq);
> -

this is where you have to hook in, check which XI version the client
supports and then do length detection based on that.
if the confine_to data is tacked on to the request, you don't have to do the
struct swapping, you can simply have a

    if (supported)
            confine_to = *(Window*)&stuff[1];

(well, there's the mask before, but you get the point.)

should make the patch a lot simpler.

Cheers,
  Peter

>      ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
>      if (ret != Success)
>  	return ret;
> @@ -79,13 +76,13 @@ ProcXIGrabDevice(ClientPtr client)
>      if (!IsMaster(dev))
>          stuff->paired_device_mode = GrabModeAsync;
>  
> -    if (XICheckInvalidMaskBits(client, (unsigned char*)&stuff[1],
> +    if (XICheckInvalidMaskBits(client, extra,
>                                 stuff->mask_len * 4) != Success)
>          return BadValue;
>  
>      mask_len = min(sizeof(mask.xi2mask[stuff->deviceid]), stuff->mask_len * 4);
>      memset(mask.xi2mask, 0, sizeof(mask.xi2mask));
> -    memcpy(mask.xi2mask, (char*)&stuff[1], mask_len);
> +    memcpy(mask.xi2mask, extra, mask_len);
>  
>      ret = GrabDevice(client, dev, stuff->grab_mode,
>                       stuff->paired_device_mode,
> @@ -95,7 +92,7 @@ ProcXIGrabDevice(ClientPtr client)
>                       &mask,
>                       GRABTYPE_XI2,
>                       stuff->cursor,
> -                     None /* confineTo */,
> +                     stuff->confine_to,
>                       &status);
>  
>      if (ret != Success)
> @@ -112,6 +109,66 @@ ProcXIGrabDevice(ClientPtr client)
>      return ret;
>  }
>  
> +static int
> +SXIGrabDeviceImpl(ClientPtr client, xXIGrabDeviceWithConfineReq *stuff, unsigned char *extra)
> +{
> +    char n;
> +
> +    swaps(&stuff->length, n);
> +    swaps(&stuff->deviceid, n);
> +    swapl(&stuff->grab_window, n);
> +    swapl(&stuff->confine_to, n);
> +    swapl(&stuff->cursor, n);
> +    swapl(&stuff->time, n);
> +    swaps(&stuff->mask_len, n);
> +
> +    return XIGrabDeviceImpl(client, stuff, extra);
> +}
> +
> +int
> +SProcXIGrabDevice(ClientPtr client)
> +{
> +    xXIGrabDeviceWithConfineReq new_stuff;
> +
> +    REQUEST(xXIGrabDeviceReq);
> +    REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq);
> +
> +    XIConvertGrabDeviceReq(&new_stuff, stuff);
> +
> +    return SXIGrabDeviceImpl(client, &new_stuff, (unsigned char*)&stuff[1]);
> +}
> +
> +int
> +ProcXIGrabDevice(ClientPtr client)
> +{
> +    xXIGrabDeviceWithConfineReq new_stuff;
> +
> +    REQUEST(xXIGrabDeviceReq);
> +    REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq);
> +
> +    XIConvertGrabDeviceReq(&new_stuff, stuff);
> +
> +    return XIGrabDeviceImpl(client, &new_stuff, (unsigned char*)&stuff[1]);
> +}
> +
> +int
> +SProcXIGrabDeviceWithConfine(ClientPtr client)
> +{
> +    REQUEST(xXIGrabDeviceWithConfineReq);
> +    REQUEST_AT_LEAST_SIZE(xXIGrabDeviceWithConfineReq);
> +
> +    return SXIGrabDeviceImpl(client, stuff, (unsigned char*)&stuff[1]);
> +}
> +
> +int
> +ProcXIGrabDeviceWithConfine(ClientPtr client)
> +{
> +    REQUEST(xXIGrabDeviceWithConfineReq);
> +    REQUEST_AT_LEAST_SIZE(xXIGrabDeviceWithConfineReq);
> +
> +    return XIGrabDeviceImpl(client, stuff, (unsigned char*)&stuff[1]);
> +}
> +
>  int
>  SProcXIUngrabDevice(ClientPtr client)
>  {
> diff --git a/Xi/xigrabdev.h b/Xi/xigrabdev.h
> index 08309c9..b951786 100644
> --- a/Xi/xigrabdev.h
> +++ b/Xi/xigrabdev.h
> @@ -33,6 +33,9 @@
>  int ProcXIGrabDevice(ClientPtr client);
>  int SProcXIGrabDevice(ClientPtr client);
>  
> +int ProcXIGrabDeviceWithConfine(ClientPtr client);
> +int SProcXIGrabDeviceWithConfine(ClientPtr client);
> +
>  int ProcXIUngrabDevice(ClientPtr client);
>  int SProcXIUngrabDevice(ClientPtr client);
>  
> diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
> index ae43433..c3b9910 100644
> --- a/Xi/xipassivegrab.c
> +++ b/Xi/xipassivegrab.c
> @@ -45,38 +45,29 @@
>  #include "dixgrabs.h"
>  #include "misc.h"
>  
> -int
> -SProcXIPassiveGrabDevice(ClientPtr client)
> -{
> -    int i;
> -    char n;
> -    xXIModifierInfo *mods;
> -
> -    REQUEST(xXIPassiveGrabDeviceReq);
> -
> -    swaps(&stuff->length, n);
> -    swaps(&stuff->deviceid, n);
> -    swapl(&stuff->grab_window, n);
> -    swapl(&stuff->cursor, n);
> -    swapl(&stuff->time, n);
> -    swapl(&stuff->detail, n);
> -    swaps(&stuff->mask_len, n);
> -    swaps(&stuff->num_modifiers, n);
> -
> -    mods = (xXIModifierInfo*)&stuff[1];
> -
> -    for (i = 0; i < stuff->num_modifiers; i++, mods++)
> -    {
> -        swapl(&mods->base_mods, n);
> -        swapl(&mods->latched_mods, n);
> -        swapl(&mods->locked_mods, n);
> -    }
>  
> -    return ProcXIPassiveGrabDevice(client);
> +static void
> +XIConvertPassiveGrabDeviceReq(xXIPassiveGrabDeviceWithConfineReq *result, xXIPassiveGrabDeviceReq *source)
> +{
> +    result->reqType = X_XIPassiveGrabDeviceWithConfine; 
> +    result->length = source->length + 1; /* length is always in 4 bytes, + 1 for confine_to field */
> +    result->time = source->time;
> +    result->grab_window = source->grab_window;
> +    result->confine_to = None;
> +    result->cursor = source->cursor;
> +    result->detail = source->detail;
> +    result->deviceid = source->deviceid;
> +    result->num_modifiers = source->num_modifiers;
> +    result->mask_len = source->mask_len;
> +    result->grab_type = source->grab_type;
> +    result->grab_mode = source->grab_mode;
> +    result->paired_device_mode = source->paired_device_mode;
> +    result->owner_events = source->owner_events;
> +    /*result->pad*/
>  }
>  
> -int
> -ProcXIPassiveGrabDevice(ClientPtr client)
> +static int
> +XIPassiveGrabDeviceImpl(ClientPtr client, xXIPassiveGrabDeviceWithConfineReq *stuff, unsigned char *extra)
>  {
>      DeviceIntPtr dev, mod_dev;
>      xXIPassiveGrabDeviceReply rep;
> @@ -90,9 +81,6 @@ ProcXIPassiveGrabDevice(ClientPtr client)
>      int mask_len;
>      int n;
>  
> -    REQUEST(xXIPassiveGrabDeviceReq);
> -    REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
> -
>      if (stuff->deviceid == XIAllDevices)
>          dev = inputInfo.all_devices;
>      else if (stuff->deviceid == XIAllMasterDevices)
> @@ -123,13 +111,13 @@ ProcXIPassiveGrabDevice(ClientPtr client)
>          return BadValue;
>      }
>  
> -    if (XICheckInvalidMaskBits(client, (unsigned char*)&stuff[1],
> +    if (XICheckInvalidMaskBits(client, extra,
>                                 stuff->mask_len * 4) != Success)
>          return BadValue;
>  
>      mask_len = min(sizeof(mask.xi2mask[stuff->deviceid]), stuff->mask_len * 4);
>      memset(mask.xi2mask, 0, sizeof(mask.xi2mask));
> -    memcpy(mask.xi2mask[stuff->deviceid], &stuff[1], mask_len * 4);
> +    memcpy(mask.xi2mask[stuff->deviceid], extra, mask_len * 4);
>  
>      rep.repType = X_Reply;
>      rep.RepType = X_XIPassiveGrabDevice;
> @@ -143,6 +131,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
>      param.this_device_mode = stuff->grab_mode;
>      param.other_devices_mode = stuff->paired_device_mode;
>      param.grabWindow = stuff->grab_window;
> +    param.confineTo = stuff->confine_to;
>      param.cursor = stuff->cursor;
>  
>      if (stuff->cursor != None)
> @@ -160,11 +149,18 @@ ProcXIPassiveGrabDevice(ClientPtr client)
>      if (status != Success)
>  	return status;
>  
> +    if (stuff->confine_to != None)
> +    {
> +        status = dixLookupWindow((WindowPtr*)&tmp, stuff->confine_to, client, DixSetAttrAccess);
> +        if (status != Success)
> +            return status;
> +    }
> +
>      status = CheckGrabValues(client, &param);
>      if (status != Success)
>          return status;
>  
> -    modifiers = (uint32_t*)&stuff[1] + stuff->mask_len;
> +    modifiers = (uint32_t*)extra + stuff->mask_len;
>      modifiers_failed = calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo));
>      if (!modifiers_failed)
>          return BadAlloc;
> @@ -213,6 +209,79 @@ ProcXIPassiveGrabDevice(ClientPtr client)
>      return ret;
>  }
>  
> +static int
> +SXIPassiveGrabDeviceImpl(ClientPtr client, xXIPassiveGrabDeviceWithConfineReq *stuff, unsigned char *extra)
> +{
> +    int i;
> +    char n;
> +    xXIModifierInfo *mods;
> +
> +    swaps(&stuff->length, n);
> +    swaps(&stuff->deviceid, n);
> +    swapl(&stuff->grab_window, n);
> +    swapl(&stuff->confine_to, n);
> +    swapl(&stuff->cursor, n);
> +    swapl(&stuff->time, n);
> +    swapl(&stuff->detail, n);
> +    swaps(&stuff->mask_len, n);
> +    swaps(&stuff->num_modifiers, n);
> +
> +    mods = (xXIModifierInfo*)extra;
> +
> +    for (i = 0; i < stuff->num_modifiers; i++, mods++)
> +    {
> +        swapl(&mods->base_mods, n);
> +        swapl(&mods->latched_mods, n);
> +        swapl(&mods->locked_mods, n);
> +    }
> +
> +    return XIPassiveGrabDeviceImpl(client, stuff, extra);
> +}
> +
> +int
> +ProcXIPassiveGrabDevice(ClientPtr client)
> +{
> +    xXIPassiveGrabDeviceWithConfineReq new_stuff;
> +
> +    REQUEST(xXIPassiveGrabDeviceReq);
> +    REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
> +
> +    XIConvertPassiveGrabDeviceReq(&new_stuff, stuff);
> +
> +    return XIPassiveGrabDeviceImpl(client, &new_stuff, (unsigned char *)&stuff[1]);
> +}
> +
> +int
> +SProcXIPassiveGrabDevice(ClientPtr client)
> +{
> +    xXIPassiveGrabDeviceWithConfineReq new_stuff;
> +
> +    REQUEST(xXIPassiveGrabDeviceReq);
> +    REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
> +
> +    XIConvertPassiveGrabDeviceReq(&new_stuff, stuff);
> +
> +    return SXIPassiveGrabDeviceImpl(client, &new_stuff, (unsigned char *)&stuff[1]);
> +}
> +
> +int
> +ProcXIPassiveGrabDeviceWithConfine(ClientPtr client)
> +{
> +    REQUEST(xXIPassiveGrabDeviceWithConfineReq);
> +    REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceWithConfineReq);
> +
> +    return XIPassiveGrabDeviceImpl(client, stuff, (unsigned char *)&stuff[1]);
> +}
> +
> +int
> +SProcXIPassiveGrabDeviceWithConfine(ClientPtr client)
> +{
> +    REQUEST(xXIPassiveGrabDeviceWithConfineReq);
> +    REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceWithConfineReq);
> +
> +    return SXIPassiveGrabDeviceImpl(client, stuff, (unsigned char *)&stuff[1]);
> +}
> +
>  void
>  SRepXIPassiveGrabDevice(ClientPtr client, int size,
>                          xXIPassiveGrabDeviceReply * rep)
> diff --git a/Xi/xipassivegrab.h b/Xi/xipassivegrab.h
> index 079e7c6..a60f5c8 100644
> --- a/Xi/xipassivegrab.h
> +++ b/Xi/xipassivegrab.h
> @@ -35,5 +35,7 @@ int ProcXIPassiveUngrabDevice(ClientPtr client);
>  void SRepXIPassiveGrabDevice(ClientPtr client, int size, xXIPassiveGrabDeviceReply * rep);
>  int ProcXIPassiveGrabDevice(ClientPtr client);
>  int SProcXIPassiveGrabDevice(ClientPtr client);
> +int ProcXIPassiveGrabDeviceWithConfine(ClientPtr client);
> +int SProcXIPassiveGrabDeviceWithConfine(ClientPtr client);
>  
>  #endif /* XIPASSIVEGRAB_H */
> -- 
> 1.7.5.rc3


More information about the xorg-devel mailing list