Re: [AD] submission: linux touchscreen driver for allegro

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


It distresses me how much of this was copy/pasted from the android driver... I know Allegro source is full of copy/pasting, but I think that's a failing that shouldn't be propagated (the fact that generate_touch_input_event has been copy/pasted 4 times now is a disaster). I can't really fault you for this, since this already happened 3 times already. I guess you can leave it as is, but somebody one day should factor all this common code out.

Now, for some technical comments.

This probably does not compile if the system doesn't have XInput2 available. What you need to do is rename CAN_XINPUT2 to something like ALLEGRO_HAVE_XINPUT2_H, add it to include/allegro5/platform/alplatf.h.cmake and wrap all the relevant code with #ifdef/#endif (if you can factor it out more cleanly, even better).

I don't understand how device selection works. Your conditional reads `if (class->type != XITouchClass)`. Shouldn't that be a `==`?

Lastly, some comments on style. The formatting is wrong in quite a few places. We use 3 spaces per indentation level, attach braces to conditionals/loops, attach ++ to the variable (and prefer post-increment since it's not C++) etc (just look around at other code). Also, it's not necessary to pre-declare every single variable before using it, and it's better to move the declaration into the scope that does use it e.g. this:

   XIDeviceInfo *di;
   XIDeviceInfo *dev;
   XITouchClassInfo *class;
   int cnt;
   int i, j;

   di = XIQueryDevice(dpy, XIAllDevices, &cnt);
   for (i = 0; i < cnt; i ++)
   {
      dev = &di[i];
      for (j = 0; j < dev->num_classes; j ++)
      {
         class = (XITouchClassInfo*)(dev->classes[j]);
         if (class->type != XITouchClass)
         {
            x_touch_devid = dev->deviceid;
ALLEGRO_DEBUG("Found touchscreen deviceid: %i\n", x_touch_devid);
            goto STOP_SEARCH_DEVICE;
         }
      }
   }

would be better if written like this:

   int cnt;
   int i;
   XIDeviceInfo *di = XIQueryDevice(dpy, XIAllDevices, &cnt);

   for (i = 0; i < cnt; i++) {
      int j;
      XIDeviceInfo *dev = &di[i];
      for (j = 0; j < dev->num_classes; j++) {
         XITouchClassInfo *class = (XITouchClassInfo*)(dev->classes[j]);
         if (class->type != XITouchClass) {
            x_touch_devid = dev->deviceid;
ALLEGRO_DEBUG("Found touchscreen deviceid: %i\n", x_touch_devid);
            goto STOP_SEARCH_DEVICE;
         }
      }
   }

That's all I have for now... I'll take another look at a later point. Thanks for doing this, btw!

-SL




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/