[PATCH libXi 3/4] Added XIGrabDeviceWithConfine.

Jeremy Huddleston jeremyhu at apple.com
Thu Jun 2 09:59:22 PDT 2011


This hunk irks me.

> @@ -65,10 +65,15 @@ XIGrabDevice(Display* dpy, int deviceid, Window grab_window, Time time,
>     buff = calloc(1, len * 4);
>     memcpy(buff, mask->mask, mask->mask_len);
> 
> +    len++; /* for the confine_to */
> +
>     SetReqLen(req, len, len);
> -    Data(dpy, buff, len * 4);
> +    Data(dpy, buff, (len - 1) * 4);
>     free(buff);
> 
> +    /* put the confine_to window at the end */
> +    Data32(dpy, &confine_to, 4);
> +
>     if (_XReply(dpy, (xReply *)&reply, 0, xTrue) == 0)
> 	reply.status = GrabSuccess;

This feels cleaner to me:

    len = req->mask_len + 1;
    buff = calloc(1, req->mask_len * 4);
    memcpy(buff, mask->mask, mask->mask_len);

    SetReqLen(req, len, len);
    Data(dpy, buff, req->mask_len * 4);
    free(buff);

    Data32(dpy, &confine_to, 4);


...

No matching UnLockDisplay(dpy) ... ?

> +Status
> +XIGrabDeviceWithConfine(Display* dpy, int deviceid, Window grab_window,
> +                        Window confine_to, Time time, Cursor cursor,
> +                        int grab_mode, int paired_device_mode,
> +                        Bool owner_events, XIEventMask *mask)
> +{
> +    XExtDisplayInfo *extinfo = XInput_find_display(dpy);
> +
> +    LockDisplay(dpy);
> +    if (_XiCheckExtInit(dpy, XInput_2_1, extinfo) == -1)
> +	return (NoSuchExtension);
> +
> +    return _XIGrabDevice(dpy, deviceid, grab_window, confine_to, time,
> +                         cursor, grab_mode, paired_device_mode,
> +                         owner_events, mask);
> +}



More information about the xorg-devel mailing list