On Tue, Oct 9, 2012 at 2:14 AM, Olivier Fourdan <ofour...@redhat.com> wrote:
> Hi all,
>
> I've been wondering, the BuiltIn flag (discussed earlier) is also set
> automatically on Linux in get_device_info() in libwacom/libwacom.c:
>
>    113 static gboolean
>    114 get_device_info (const char   *path,
>    ...
>    121 {
>    ...
>    157         /* Is the device builtin? */
>    158         devname = g_udev_device_get_name (device);
>    159         if (devname != NULL) {
>    160                 char *sysfs_path, *contents;
>    161
>    162                 sysfs_path = g_build_filename
> ("/sys/class/input", devname, "device/properties", NULL);
>    163                 if (g_file_get_contents (sysfs_path, &contents,
> NULL, NULL)) {
>    164                         int flag;
>    165
>    166                         /* 0x01: POINTER flag
>    167                          * 0x02: DIRECT flag */
>    168                         flag = atoi(contents);
>    169                         *builtin = (flag & 0x02) == 0x02 ?
> IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;
>    170                         g_free (contents);
>    171                 }
>    172                 g_free (sysfs_path);
>    173         }
>
> So I have been wondering about that flag 0x02used here.
>
> /usr/include/linux/input.h has the following:
>
>    155 /*
>    156  * Device properties and quirks
>    157  */
>    158
>    159 #define INPUT_PROP_POINTER              0x00    /* needs a
> pointer */
>    160 #define INPUT_PROP_DIRECT               0x01    /* direct input
> devices */
>    161 #define INPUT_PROP_BUTTONPAD            0x02    /* has
> button(s) under pad */
>    162 #define INPUT_PROP_SEMI_MT              0x03    /* touch
> rectangle only */
>    163
>    164 #define INPUT_PROP_MAX                  0x1f
>    165 #define INPUT_PROP_CNT                  (INPUT_PROP_MAX + 1)
>    166
>
> But there INPUT_PROP_DIRECT is 0x01 not 0x02 (0x02 is BUTTONPAD).
>
> Is really 0x02 what we want here? And if I am misunderstanding, why
> not using definitions names rather than cryptic bit flags directly?
>
> Cheers,
> Olivier
>

INPUT_PROP_* aren't bit flags -- they're bit positions. That is, if
bit number INPUT_PROP_DIRECT is set, then it's a direct input device.
Or, put differently (and grabbing descriptions from event-codes.txt):

if (flag & (1 << INPUT_PROP_POINTER)) {
// The INPUT_PROP_POINTER property indicates that the device is not transposed
// on the screen and thus requires use of an on-screen pointer to trace user's
// movements.  Typical pointer devices: touchpads, tablets, mice; non-pointer
// device: touchscreen.
}
if (flag & (1 << INPUT_PROP_DIRECT)) {
// The INPUT_PROP_DIRECT property indicates that device coordinates should be
// directly mapped to screen coordinates (not taking into account trivial
// transformations, such as scaling, flipping and rotating). Non-direct input
// devices require non-trivial transformation, such as absolute to relative
// transformation for touchpads. Typical direct input devices: touchscreens,
// drawing tablets; non-direct devices: touchpads, mice.
}

Note that INPUT_PROP_DIRECT is specified to be set for both
touchscreens (e.g. Cintiq, tablet PC) *and* for drawing tablets (e.g.
Intuos, Bamboo). To properly ensure that you're getting a touchscreen,
you need to make sure that its DIRECT and non-POINTER. Because of
this, the libwacom code technically isn't correct; the only reason it
doesn't think an Intuos is built-in is because the guidelines weren't
clear when my kernel patches were accepted and so they don't have the
DIRECT flag set.

To be correct and use the defines instead of hex codes, it should
probably be written more like:

int hw_flags = atoi(contents);
int direct_flag = (1  << INPUT_PROP_DIRECT);
int pointer_flag = (1 << INPUT_PROP_POINTER);

*builtin = (hw_flags & (direct_flag | pointer_flag) == direct_flag) ?
IS_BUILTIN_TRUE : IS_BUILTIN_FALSE;

Jason

---
When you're rife with devastation / There's a simple explanation:
You're a toymaker's creation / Trapped inside a crystal ball.
And whichever way he tilts it / Know that we must be resilient
We won't let them break our spirits / As we sing our silly song.

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to