[PATCH (v5) xserver 3/8] Input: Simply CheckPassiveGrabsOnWindow loop

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 20 15:36:13 PST 2011


On Wed, Jan 19, 2011 at 11:11:45PM +0000, Daniel Stone wrote:
> Instead of a mega never-ending if branch with no else, just continue
> to the next iteration of the loop if the conditions aren't met - pretty
> much entirely reindentation.
> 
> Signed-off-by: Daniel Stone <daniel at fooishbar.org>
> ---

screams for more simplification but this patch is a great start.
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

Cheers,
  Peter
> 
> v5: New.
> 
>  dix/events.c |  209 ++++++++++++++++++++++++++++-----------------------------
>  1 files changed, 103 insertions(+), 106 deletions(-)
> 
> diff --git a/dix/events.c b/dix/events.c
> index dfe938b..38e9a08 100644
> --- a/dix/events.c
> +++ b/dix/events.c
> @@ -3445,129 +3445,126 @@ CheckPassiveGrabsOnWindow(
>                  match = CORE_MATCH;
>          }
>  
> -        if (match && (!grab->confineTo ||
> -	     (grab->confineTo->realized &&
> -				BorderSizeNotEmpty(device, grab->confineTo))))
> -	{
> -            grabinfo = &device->deviceGrab;
> -            /* In some cases a passive core grab may exist, but the client
> -             * already has a core grab on some other device. In this case we
> -             * must not get the grab, otherwise we may never ungrab the
> -             * device.
> -             */
> -
> -            if (grab->grabtype == GRABTYPE_CORE)
> +        if (!match || (grab->confineTo &&
> +                       (!grab->confineTo->realized ||
> +                        !BorderSizeNotEmpty(device, grab->confineTo))))
> +            continue;
> +
> +        grabinfo = &device->deviceGrab;
> +        /* In some cases a passive core grab may exist, but the client
> +         * already has a core grab on some other device. In this case we
> +         * must not get the grab, otherwise we may never ungrab the
> +         * device.
> +         */
> +
> +        if (grab->grabtype == GRABTYPE_CORE)
> +        {
> +            DeviceIntPtr other;
> +            BOOL interfering = FALSE;
> +
> +            /* A passive grab may have been created for a different device
> +               than it is assigned to at this point in time.
> +               Update the grab's device and modifier device to reflect the
> +               current state.
> +               Since XGrabDeviceButton requires to specify the
> +               modifierDevice explicitly, we don't override this choice.
> +               */
> +            if (tempGrab.type < GenericEvent)
>              {
> -                DeviceIntPtr other;
> -                BOOL interfering = FALSE;
> -
> -                /* A passive grab may have been created for a different device
> -                   than it is assigned to at this point in time.
> -                   Update the grab's device and modifier device to reflect the
> -                   current state.
> -                   Since XGrabDeviceButton requires to specify the
> -                   modifierDevice explicitly, we don't override this choice.
> -                   */
> -                if (tempGrab.type < GenericEvent)
> -                {
> -                    grab->device = device;
> -                    grab->modifierDevice = GetPairedDevice(device);
> -                }
> +                grab->device = device;
> +                grab->modifierDevice = GetPairedDevice(device);
> +            }
>  
> -                for (other = inputInfo.devices; other; other = other->next)
> +            for (other = inputInfo.devices; other; other = other->next)
> +            {
> +                GrabPtr othergrab = other->deviceGrab.grab;
> +                if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
> +                    SameClient(grab, rClient(othergrab)) &&
> +                    ((IsPointerDevice(grab->device) &&
> +                     IsPointerDevice(othergrab->device)) ||
> +                     (IsKeyboardDevice(grab->device) &&
> +                      IsKeyboardDevice(othergrab->device))))
>                  {
> -                    GrabPtr othergrab = other->deviceGrab.grab;
> -                    if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
> -                        SameClient(grab, rClient(othergrab)) &&
> -                        ((IsPointerDevice(grab->device) &&
> -                         IsPointerDevice(othergrab->device)) ||
> -                         (IsKeyboardDevice(grab->device) &&
> -                          IsKeyboardDevice(othergrab->device))))
> -                    {
> -                        interfering = TRUE;
> -                        break;
> -                    }
> +                    interfering = TRUE;
> +                    break;
>                  }
> -                if (interfering)
> -                    continue;
>              }
> +            if (interfering)
> +                continue;
> +        }
>  
> -            if (!activate)
> -                return grab;
> -            else if (!GetXIType(event) && !GetCoreType(event))
> -                FatalError("Event type %d in CheckPassiveGrabsOnWindow is"
> -                           " neither XI 1.x nor core\n", event->any.type);
> +        if (!activate)
> +            return grab;
> +        else if (!GetXIType(event) && !GetCoreType(event))
> +            FatalError("Event type %d in CheckPassiveGrabsForWindow is neither"
> +                       " XI 1.x nor core\n", event->any.type);
>  
> -            /* The only consumers of corestate are Xi 1.x and core events,
> -             * which are guaranteed to come from DeviceEvents. */
> -            if (match & (XI_MATCH | CORE_MATCH))
> -            {
> -                event->device_event.corestate &= 0x1f00;
> -                event->device_event.corestate |=
> -                    tempGrab.modifiersDetail.exact & (~0x1f00);
> -            }
> +        /* The only consumers of corestate are Xi 1.x and core events, which
> +         * are guaranteed to come from DeviceEvents. */
> +        if (match & (XI_MATCH | CORE_MATCH))
> +        {
> +            event->device_event.corestate &= 0x1f00;
> +            event->device_event.corestate |= tempGrab.modifiersDetail.exact &
> +                                              (~0x1f00);
> +        }
>  
> -            if (match & CORE_MATCH)
> +        if (match & CORE_MATCH)
> +        {
> +            rc = EventToCore(event, &core);
> +            if (rc != Success)
>              {
> -                rc = EventToCore(event, &core);
> -                if (rc != Success)
> -                {
> -                    if (rc != BadMatch)
> -                        ErrorF("[dix] %s: core conversion failed in CPGFW "
> -                                "(%d, %d).\n", device->name, event->any.type,
> -                                rc);
> -                    continue;
> -                }
> -                xE = &core;
> -                count = 1;
> -            } else if (match & XI2_MATCH)
> +                if (rc != BadMatch)
> +                    ErrorF("[dix] %s: core conversion failed in CPGFW "
> +                            "(%d, %d).\n", device->name, event->any.type, rc);
> +                continue;
> +            }
> +            xE = &core;
> +            count = 1;
> +        } else if (match & XI2_MATCH)
> +        {
> +            rc = EventToXI2(event, &xE);
> +            if (rc != Success)
>              {
> -                rc = EventToXI2(event, &xE);
> -                if (rc != Success)
> -                {
> -                    if (rc != BadMatch)
> -                        ErrorF("[dix] %s: XI2 conversion failed in CPGFW "
> -                                "(%d, %d).\n", device->name, event->any.type,
> -                                rc);
> -                    continue;
> -                }
> -                count = 1;
> -            } else
> +                if (rc != BadMatch)
> +                    ErrorF("[dix] %s: XI2 conversion failed in CPGFW "
> +                            "(%d, %d).\n", device->name, event->any.type, rc);
> +                continue;
> +            }
> +            count = 1;
> +        } else
> +        {
> +            rc = EventToXI(event, &xE, &count);
> +            if (rc != Success)
>              {
> -                rc = EventToXI(event, &xE, &count);
> -                if (rc != Success)
> -                {
> -                    if (rc != BadMatch)
> -                        ErrorF("[dix] %s: XI conversion failed in CPGFW "
> -                                "(%d, %d).\n", device->name, event->any.type,
> -                                rc);
> -                    continue;
> -                }
> +                if (rc != BadMatch)
> +                    ErrorF("[dix] %s: XI conversion failed in CPGFW "
> +                            "(%d, %d).\n", device->name, event->any.type, rc);
> +                continue;
>              }
> +        }
>  
> -	    (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
> +        (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE);
>  
> -            if (xE)
> -            {
> -                FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
> +        if (xE)
> +        {
> +            FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
>  
> -                TryClientEvents(rClient(grab), device, xE, count,
> -                                       GetEventFilter(device, xE),
> -                                       GetEventFilter(device, xE), grab);
> -            }
> +            TryClientEvents(rClient(grab), device, xE, count,
> +                            GetEventFilter(device, xE),
> +                            GetEventFilter(device, xE), grab);
> +        }
>  
> -	    if (grabinfo->sync.state == FROZEN_NO_EVENT)
> -	    {
> -                if (!grabinfo->sync.event)
> -                    grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
> -                *grabinfo->sync.event = event->device_event;
> -		grabinfo->sync.state = FROZEN_WITH_EVENT;
> -            }
> +        if (grabinfo->sync.state == FROZEN_NO_EVENT)
> +        {
> +            if (!grabinfo->sync.event)
> +                grabinfo->sync.event = calloc(1, sizeof(DeviceEvent));
> +            *grabinfo->sync.event = event->device_event;
> +            grabinfo->sync.state = FROZEN_WITH_EVENT;
> +        }
>  
> -            if (match & (XI_MATCH | XI2_MATCH))
> -                free(xE); /* on core match xE == &core */
> -	    return grab;
> -	}
> +        if (match & (XI_MATCH | XI2_MATCH))
> +            free(xE); /* on core match xE == &core */
> +        return grab;
>      }
>      return NULL;
>  #undef CORE_MATCH
> -- 
> 1.7.2.3
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list