On Wed, Nov 07, 2012 at 01:22:11PM +0100, Olivier Fourdan wrote:
> 

> >From 15f93f5d3bd9f2aefd59a5087b2ce44a3c53403c Mon Sep 17 00:00:00 2001
> From: Olivier Fourdan <ofour...@redhat.com>
> Date: Thu, 11 Oct 2012 12:04:45 +0200
> Subject: [PATCH 3/3] lib: add "IntegratedIn" to device group
> 
> to describe integrated system devices and screen tablets.
> 
> A bit field allows to identify the level of integration of
> a device:
> 
>     WACOM_DEVICE_INTEGRATED_NONE    device is a standalone tablet
>     WACOM_DEVICE_INTEGRATED_DISPLAY device is a screen tablet
>     WACOM_DEVICE_INTEGRATED_SYSTEM  device is an ISD such as
>                                     a tablet PC.
> 
> Or -1 (WACOM_DEVICE_INTEGRATED_UNSET) if the information is not
> available

two things:
I'd like to see a test that screams bloody murder when the flag is in fact
unset. presumably if we add new devices we known whether they're built-in
and the test should complain if we forget to add this.

the other thing: having UNSET as -1 for a bitmask is not a good choice, it
requires any user to check for UNSET _and_ check for the mask set, since -1
will always set all bits. 

so either we bump all up by one so UNSET is 0 and NONE is 1, or we leave
NONE at 0 and guarantee that we always define this and drop UNSET.

> 
> These definitions supersede the previous libwacom_is_builtin()
> API which is now deprecated.
> 
> Signed-off-by: Olivier Fourdan <ofour...@redhat.com>
> ---
>  libwacom/libwacom-database.c |   59 ++++++++++++++++++++++++++----------
>  libwacom/libwacom.c          |   67 +++++++++++++++++++++++++++++------------
>  libwacom/libwacom.h          |   24 ++++++++++++++-
>  libwacom/libwacomint.h       |   10 +-----
>  4 files changed, 113 insertions(+), 47 deletions(-)
> 
> diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
> index bbea114..ae73239 100644
> --- a/libwacom/libwacom-database.c
> +++ b/libwacom/libwacom-database.c
> @@ -256,6 +256,14 @@ struct {
>       { "Touchstrip2",        WACOM_STATUS_LED_TOUCHSTRIP2 }
>  };
>  
> +struct {
> +     const char             *key;
> +     WacomIntegrationFlags   value;
> +} integration_flags[] = {
> +     { "Display",            WACOM_DEVICE_INTEGRATED_DISPLAY },
> +     { "System",             WACOM_DEVICE_INTEGRATED_SYSTEM }
> +};
> +
>  static void
>  libwacom_parse_buttons_key(WacomDevice      *device,
>                          GKeyFile         *keyfile,
> @@ -329,8 +337,7 @@ libwacom_parse_tablet_keyfile(const char *datadir, const 
> char *filename)
>       char *layout;
>       char *class;
>       char *match;
> -     char **styli_list;
> -     char **leds_list;
> +     char **string_list;
>  
>       keyfile = g_key_file_new();
>  
> @@ -361,31 +368,50 @@ libwacom_parse_tablet_keyfile(const char *datadir, 
> const char *filename)
>       device->name = g_key_file_get_string(keyfile, DEVICE_GROUP, "Name", 
> NULL);
>       device->width = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Width", 
> NULL);
>       device->height = g_key_file_get_integer(keyfile, DEVICE_GROUP, 
> "Height", NULL);
> +
> +     device->integration_flags = WACOM_DEVICE_INTEGRATED_UNSET;
> +     string_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, 
> "IntegratedIn", NULL, NULL);
> +     if (string_list) {
> +             guint i, n;
> +
> +             device->integration_flags = WACOM_DEVICE_INTEGRATED_NONE;
> +             for (i = 0; string_list[i]; i++) {
> +                     for (n = 0; n < G_N_ELEMENTS (integration_flags); n++) {
> +                             if (!strcmp(string_list[i], 
> integration_flags[n].key)) {
> +                                     device->integration_flags |= 
> integration_flags[n].value;
> +                                     break;
> +                             }
> +                     }
> +             }
> +             g_strfreev (string_list);
> +     }
> +
>       layout = g_key_file_get_string(keyfile, DEVICE_GROUP, "Layout", NULL);
>       if (layout) {
>               /* For the layout, we store the full path to the SVG layout */
>               device->layout = g_build_filename (datadir, "layouts", layout, 
> NULL);
>               g_free (layout);
>       }
> +
>       class = g_key_file_get_string(keyfile, DEVICE_GROUP, "Class", NULL);
>       device->cls = libwacom_class_string_to_enum(class);
>       g_free(class);
>  
> -     styli_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, "Styli", 
> NULL, NULL);
> -     if (styli_list) {
> +     string_list = g_key_file_get_string_list(keyfile, DEVICE_GROUP, 
> "Styli", NULL, NULL);
> +     if (string_list) {
>               GArray *array;
>               guint i;
>  
>               array = g_array_new (FALSE, FALSE, sizeof(int));
>               device->num_styli = 0;
> -             for (i = 0; styli_list[i]; i++) {
> -                     glong long_value = strtol (styli_list[i], NULL, 0);
> +             for (i = 0; string_list[i]; i++) {
> +                     glong long_value = strtol (string_list[i], NULL, 0);
>                       int int_value = long_value;
>  
>                       g_array_append_val (array, int_value);
>                       device->num_styli++;
>               }
> -             g_strfreev (styli_list);
> +             g_strfreev (string_list);
>               device->supported_styli = (int *) g_array_free (array, FALSE);
>       } else {
>               device->supported_styli = g_new (int, 2);
> @@ -407,15 +433,13 @@ libwacom_parse_tablet_keyfile(const char *datadir, 
> const char *filename)
>       if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "Ring2", NULL))
>               device->features |= FEATURE_RING2;
>  
> -     if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "BuiltIn", NULL))
> -             device->features |= FEATURE_BUILTIN;
> -
>       if (g_key_file_get_boolean(keyfile, FEATURES_GROUP, "Reversible", NULL))
>               device->features |= FEATURE_REVERSIBLE;
>  
> -     if (device->features & FEATURE_BUILTIN &&
> +     if (device->integration_flags != WACOM_DEVICE_INTEGRATED_UNSET &&
> +         device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY &&
>           device->features & FEATURE_REVERSIBLE)
> -             g_warning ("Tablet '%s' is both reversible and builtin. This is 
> impossible", libwacom_get_match(device));
> +             g_warning ("Tablet '%s' is both reversible and integrated in 
> screen. This is impossible", libwacom_get_match(device));
>  
>       if (!(device->features & FEATURE_RING) &&
>           (device->features & FEATURE_RING2))
> @@ -433,22 +457,23 @@ libwacom_parse_tablet_keyfile(const char *datadir, 
> const char *filename)
>               libwacom_parse_buttons(device, keyfile);
>       }
>  
> -     leds_list = g_key_file_get_string_list(keyfile, FEATURES_GROUP, 
> "StatusLEDs", NULL, NULL);
> -     if (leds_list) {
> +     string_list = g_key_file_get_string_list(keyfile, FEATURES_GROUP, 
> "StatusLEDs", NULL, NULL);
> +     if (string_list) {
>               GArray *array;
>               guint i, n;
> +
>               array = g_array_new (FALSE, FALSE, sizeof(WacomStatusLEDs));
>               device->num_leds = 0;
> -             for (i = 0; leds_list[i]; i++) {
> +             for (i = 0; string_list[i]; i++) {
>                       for (n = 0; n < G_N_ELEMENTS (supported_leds); n++) {
> -                             if (!strcmp(leds_list[i], 
> supported_leds[n].key)) {
> +                             if (!strcmp(string_list[i], 
> supported_leds[n].key)) {
>                                       g_array_append_val (array, 
> supported_leds[n].value);
>                                       device->num_leds++;
>                                       break;
>                               }
>                       }
>               }
> -             g_strfreev (leds_list);
> +             g_strfreev (string_list);
>               device->status_leds = (WacomStatusLEDs *) g_array_free (array, 
> FALSE);
>       }
>  
> diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
> index eeeed1a..1f567de 100644
> --- a/libwacom/libwacom.c
> +++ b/libwacom/libwacom.c
> @@ -124,13 +124,13 @@ get_bus (GUdevDevice *device)
>  }
>  
>  static gboolean
> -get_device_info (const char   *path,
> -              int          *vendor_id,
> -              int          *product_id,
> -              char        **name,
> -              WacomBusType *bus,
> -              IsBuiltin    *builtin,
> -              WacomError   *error)
> +get_device_info (const char            *path,
> +              int                   *vendor_id,
> +              int                   *product_id,
> +              char                 **name,
> +              WacomBusType          *bus,
> +              WacomIntegrationFlags *integration_flags,
> +              WacomError            *error)
>  {
>       GUdevClient *client;
>       GUdevDevice *device;
> @@ -142,7 +142,7 @@ get_device_info (const char   *path,
>       g_type_init();
>  
>       retval = FALSE;
> -     *builtin = IS_BUILTIN_UNSET;
> +     *integration_flags = WACOM_DEVICE_INTEGRATED_UNSET;
>       *name = NULL;
>       bus_str = NULL;
>       client = g_udev_client_new (subsystems);
> @@ -167,7 +167,7 @@ get_device_info (const char   *path,
>  
>       bus_str = get_bus (device);
>  
> -     /* Is the device builtin? */
> +     /* Is the device integrated in display? */
>       devname = g_udev_device_get_name (device);
>       if (devname != NULL) {
>               char *sysfs_path, *contents;
> @@ -185,9 +185,9 @@ get_device_info (const char   *path,
>                        * tablets as well)
>                        */
>                       if (flag == (1 << INPUT_PROP_DIRECT))
> -                             *builtin = IS_BUILTIN_TRUE;
> +                             *integration_flags = 
> WACOM_DEVICE_INTEGRATED_DISPLAY;
>                       else
> -                             *builtin = IS_BUILTIN_FALSE;
> +                             *integration_flags = 
> WACOM_DEVICE_INTEGRATED_NONE;
>  
>                       g_free (contents);
>               }
> @@ -312,6 +312,7 @@ libwacom_copy(const WacomDevice *device)
>       d->name = g_strdup (device->name);
>       d->width = device->width;
>       d->height = device->height;
> +     d->integration_flags = device->integration_flags;
>       d->layout = g_strdup(device->layout);
>       d->nmatches = device->nmatches;
>       d->matches = g_malloc((d->nmatches + 1) * sizeof(WacomMatch*));
> @@ -393,6 +394,9 @@ libwacom_compare(WacomDevice *a, WacomDevice *b, 
> WacomCompareFlags flags)
>       if (!libwacom_same_layouts (a, b))
>               return 1;
>  
> +     if (a->integration_flags != b->integration_flags)
> +             return 1;
> +
>       if (a->cls != b->cls)
>               return 1;
>  
> @@ -462,7 +466,7 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const 
> char *path, WacomFallbackF
>       WacomBusType bus;
>       const WacomDevice *device;
>       WacomDevice *ret;
> -     IsBuiltin builtin;
> +     WacomIntegrationFlags integration_flags;
>       char *name;
>  
>       if (!db) {
> @@ -475,7 +479,7 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const 
> char *path, WacomFallbackF
>               return NULL;
>       }
>  
> -     if (!get_device_info (path, &vendor_id, &product_id, &name, &bus, 
> &builtin, error))
> +     if (!get_device_info (path, &vendor_id, &product_id, &name, &bus, 
> &integration_flags, error))
>               return NULL;
>  
>       device = libwacom_new (db, vendor_id, product_id, bus, error);
> @@ -503,10 +507,10 @@ libwacom_new_from_path(WacomDeviceDatabase *db, const 
> char *path, WacomFallbackF
>       libwacom_update_match(ret, bus, vendor_id, product_id);
>  
>       if (device) {
> -             if (builtin == IS_BUILTIN_TRUE)
> -                     ret->features |= FEATURE_BUILTIN;
> -             else if (builtin == IS_BUILTIN_FALSE)
> -                     ret->features &= ~FEATURE_BUILTIN;
> +             if (integration_flags == WACOM_DEVICE_INTEGRATED_DISPLAY)
> +                     ret->integration_flags |= 
> WACOM_DEVICE_INTEGRATED_DISPLAY;
> +             else if (integration_flags == WACOM_DEVICE_INTEGRATED_NONE)
> +                     ret->integration_flags &= 
> ~WACOM_DEVICE_INTEGRATED_DISPLAY;
>  
>               return ret;
>       }
> @@ -652,6 +656,24 @@ static void print_buttons_for_device (int fd, 
> WacomDevice *device)
>       dprintf(fd, "\n");
>  }
>  
> +static void print_integrated_flags_for_device (int fd, WacomDevice *device)
> +{
> +     /*
> +      * If flag is WACOM_DEVICE_INTEGRATED_UNSET, the info is not provided
> +      * by the tablet database but deduced otherwise (e.g. from sysfs device
> +      * properties on Linux)
> +      */
> +     if (device->integration_flags == WACOM_DEVICE_INTEGRATED_UNSET)
> +             return;
> +     dprintf(fd, "IntegratedIn=");
> +     if (device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY)
> +             dprintf(fd, "Display;");
> +     if (device->integration_flags & WACOM_DEVICE_INTEGRATED_SYSTEM)
> +             dprintf(fd, "System;");
> +     dprintf(fd, "\n");
> +}
> +
> +
>  void
>  libwacom_print_device_description(int fd, WacomDevice *device)
>  {
> @@ -697,6 +719,7 @@ libwacom_print_device_description(int fd, WacomDevice 
> *device)
>       dprintf(fd, "Class=%s\n",               class_name);
>       dprintf(fd, "Width=%d\n",               libwacom_get_width(device));
>       dprintf(fd, "Height=%d\n",              libwacom_get_height(device));
> +     print_integrated_flags_for_device(fd, device);
>       print_layout_for_device(fd, device);
>       print_styli_for_device(fd, device);
>       dprintf(fd, "\n");
> @@ -706,7 +729,6 @@ libwacom_print_device_description(int fd, WacomDevice 
> *device)
>       dprintf(fd, "Stylus=%s\n",       libwacom_has_stylus(device)    ? 
> "true" : "false");
>       dprintf(fd, "Ring=%s\n",         libwacom_has_ring(device)      ? 
> "true" : "false");
>       dprintf(fd, "Ring2=%s\n",        libwacom_has_ring2(device)     ? 
> "true" : "false");
> -     dprintf(fd, "BuiltIn=%s\n",      libwacom_is_builtin(device)    ? 
> "true" : "false");
>       dprintf(fd, "Touch=%s\n",        libwacom_has_touch(device)     ? 
> "true" : "false");
>       print_supported_leds(fd, device);
>  
> @@ -875,7 +897,6 @@ int libwacom_get_strips_num_modes(WacomDevice *device)
>       return device->strips_num_modes;
>  }
>  
> -
>  const WacomStatusLEDs *libwacom_get_status_leds(WacomDevice *device, int 
> *num_leds)
>  {
>       *num_leds = device->num_leds;
> @@ -924,7 +945,8 @@ int libwacom_get_button_led_group (WacomDevice *device,
>  
>  int libwacom_is_builtin(WacomDevice *device)
>  {
> -     return !!(device->features & FEATURE_BUILTIN);
> +     return !!(device->integration_flags != WACOM_DEVICE_INTEGRATED_UNSET &&
> +               device->integration_flags & WACOM_DEVICE_INTEGRATED_DISPLAY);
>  }
>  
>  int libwacom_is_reversible(WacomDevice *device)
> @@ -932,6 +954,11 @@ int libwacom_is_reversible(WacomDevice *device)
>       return !!(device->features & FEATURE_REVERSIBLE);
>  }
>  
> +WacomIntegrationFlags libwacom_get_integration_flags (WacomDevice *device)
> +{
> +     return device->integration_flags;
> +}
> +
>  WacomBusType libwacom_get_bustype(WacomDevice *device)
>  {
>       g_return_val_if_fail(device->match >= 0, -1);
> diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
> index 30968f2..9d6777f 100644
> --- a/libwacom/libwacom.h
> +++ b/libwacom/libwacom.h
> @@ -115,6 +115,16 @@ typedef enum {
>  } WacomBusType;
>  
>  /**
> + * Tablet integration.
> + */
> +typedef enum {
> +     WACOM_DEVICE_INTEGRATED_UNSET   = -1,
> +     WACOM_DEVICE_INTEGRATED_NONE    = 0,
> +     WACOM_DEVICE_INTEGRATED_DISPLAY = (1 << 0),
> +     WACOM_DEVICE_INTEGRATED_SYSTEM  = (1 << 1)
> +} WacomIntegrationFlags;
> +
> +/**
>   * Classes of devices.
>   */
>  typedef enum {
> @@ -461,12 +471,15 @@ const WacomStatusLEDs 
> *libwacom_get_status_leds(WacomDevice *device, int *num_le
>  int libwacom_get_button_led_group (WacomDevice *device,
>                                  char         button);
>  
> +#ifndef LIBWACOM_DISABLE_DEPRECATED

where is this set?
I don't think this gives us much a benefit, especially if it's hidden away
like this.

Mark the function as deprecated in the doxygen comments and with
__attribute__ ((deprecated)) (search for _X_DEPRECATED and define a similar
define for us to use here)

>  /**
>   * @param device The tablet to query
> - * @return non-zero if the device is built-in or zero if the device is an
> - * external tablet
> + * @return non-zero if the device is built into the screen (ie a screen 
> tablet)
> + * or zero if the device is an external tablet
> + * Deprecated: 0.7: Use libwacom_get_integration_flags() instead.

doxygen says this should be @deprecated, the current doxygen config should
mark these properly then (haven't tried it but it's enabled)

Cheers,
   Peter

>   */
>  int libwacom_is_builtin(WacomDevice *device);
> +#endif
>  
>  /**
>   * @param device The tablet to query
> @@ -477,6 +490,13 @@ int libwacom_is_reversible(WacomDevice *device);
>  
>  /**
>   * @param device The tablet to query
> + * @return the integration flags for the device, or -1 if the value is
> + * unavailable (WACOM_DEVICE_INTEGRATED_UNSET)
> + */
> +WacomIntegrationFlags libwacom_get_integration_flags (WacomDevice *device);
> +
> +/**
> + * @param device The tablet to query
>   * @return The bustype of this device.
>   */
>  WacomBusType libwacom_get_bustype(WacomDevice *device);
> diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
> index 20c40f8..a0eb7cc 100644
> --- a/libwacom/libwacomint.h
> +++ b/libwacom/libwacomint.h
> @@ -40,19 +40,12 @@
>  
>  #define GENERIC_DEVICE_MATCH "generic"
>  
> -typedef enum {
> -     IS_BUILTIN_UNSET        = -1,
> -     IS_BUILTIN_FALSE        = 0,
> -     IS_BUILTIN_TRUE         = 1
> -} IsBuiltin;
> -
>  enum WacomFeature {
>       FEATURE_STYLUS          = (1 << 0),
>       FEATURE_TOUCH           = (1 << 1),
>       FEATURE_RING            = (1 << 2),
>       FEATURE_RING2           = (1 << 3),
> -     FEATURE_BUILTIN         = (1 << 4),
> -     FEATURE_REVERSIBLE      = (1 << 5)
> +     FEATURE_REVERSIBLE      = (1 << 4)
>  };
>  
>  /* WARNING: When adding new members to this struct
> @@ -79,6 +72,7 @@ struct _WacomDevice {
>       WacomClass cls;
>       int num_strips;
>       uint32_t features;
> +     uint32_t integration_flags;
>  
>       int strips_num_modes;
>       int ring_num_modes;
> -- 
> 1.7.1
> 

> ------------------------------------------------------------------------------
> LogMeIn Central: Instant, anywhere, Remote PC access and management.
> Stay in control, update software, and manage PCs from one command center
> Diagnose problems and improve visibility into emerging IT issues
> Automate, monitor and manage. Do more in less time with Central
> http://p.sf.net/sfu/logmein12331_d2d

> _______________________________________________
> Linuxwacom-devel mailing list
> Linuxwacom-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to