Peter Hutterer said the following on 11/27/2012 12:27 AM:
[...]
+ 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);
+ }
+
a follow-up patch could check for invalid IntegratedIn values and warn about
it.
No need to wait for a follow-up patch really, it's very useful and
trivial to do.
Added :)
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)
please fix up the alignment here, path is misplaced (may look correct in code,
in which case ignore this comment)
Alignment is wrong in the patch because of the tab cars in the
following lines, yet it's just fine in the code.
I left that out.
[...]
/**
+ * Tablet integration.
+ */
+typedef enum {
+ WACOM_DEVICE_INTEGRATED_UNSET = -1,
mark this as internal with
WACOM_DEVICE_INTEGRATED_UNSET = -1, /**< For internal use only */
tough tbh we should not really expose this in the public header if we don't
want clients to use it.
we should be able to
#define WACOM_DEVICE_INTEGRATED_UNSET (WACOM_DEVICE_INTEGRATED_NONE - 1)
in libwacomint.h to avoid having this exposed.
Done.
It works, yet I'm not sure what effect that may have on the compiler
optimization, the enul would be treated as an unsigned yet we use a
neg value. Eanyway, gcc does not seem to complain so I guess it's OK.
[...]
+#ifndef LIBWACOM_DISABLE_DEPRECATED
/**
* @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.
*/
int libwacom_is_builtin(WacomDevice *device);
+#endif
my previous comments about __attribute__((deprecated)) and @deprecated still
stand :)
Oh yeah, I completely missed that in the original review, my bad :(
Done, added a LIBWACOM_DEPRECATED macro. Tested it works as expected.
That allowed me to spot the use of the deprecated function in
test/load.c so that's now fixed as well.
The load tests for both integration fields for the integrated in
device + screen Wacom serial now.
Updated patch attached.
Do you want all 3 patches at once so we don't miss anything?
Cheers,
Olivier.
--
əɔıʌəp əɯos ɥʇıʍ əɹəɥʍəɯos ɯoɹɟ ʇuəs
>From 06748d1e713cf98872bbaabc9b93e7ca68c64ccd 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.
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 | 64 ++++++++++++++++++++++++++++----------
libwacom/libwacom.c | 70 ++++++++++++++++++++++++++++++------------
libwacom/libwacom.h | 29 +++++++++++++++--
libwacom/libwacomint.h | 11 ++-----
test/load.c | 6 ++--
5 files changed, 129 insertions(+), 51 deletions(-)
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index bbea114..e0ee52e 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,55 @@ 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;
+ gboolean found;
+
+ device->integration_flags = WACOM_DEVICE_INTEGRATED_NONE;
+ for (i = 0; string_list[i]; i++) {
+ found = FALSE;
+ 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;
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found)
+ g_warning ("Unrecognized integration flag '%s'", string_list[i]);
+ }
+ 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 +438,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 +462,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..23f3b08 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,7 @@ int libwacom_get_button_led_group (WacomDevice *device,
int libwacom_is_builtin(WacomDevice *device)
{
- return !!(device->features & FEATURE_BUILTIN);
+ return !!(libwacom_get_integration_flags (device) & WACOM_DEVICE_INTEGRATED_DISPLAY);
}
int libwacom_is_reversible(WacomDevice *device)
@@ -932,6 +953,15 @@ int libwacom_is_reversible(WacomDevice *device)
return !!(device->features & FEATURE_REVERSIBLE);
}
+WacomIntegrationFlags libwacom_get_integration_flags (WacomDevice *device)
+{
+ /* "unset" is for internal use only */
+ if (device->integration_flags == WACOM_DEVICE_INTEGRATED_UNSET)
+ return WACOM_DEVICE_INTEGRATED_NONE;
+
+ 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..a7bdba1 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -36,6 +36,13 @@
#include <stdint.h>
#include <stdio.h>
+
+#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)
+#define LIBWACOM_DEPRECATED __attribute__((deprecated))
+#else
+#define LIBWACOM_DEPRECATED
+#endif /* __GNUC__ */
+
/**
@mainpage
@@ -115,6 +122,15 @@ typedef enum {
} WacomBusType;
/**
+ * Tablet integration.
+ */
+typedef enum {
+ WACOM_DEVICE_INTEGRATED_NONE = 0,
+ WACOM_DEVICE_INTEGRATED_DISPLAY = (1 << 0),
+ WACOM_DEVICE_INTEGRATED_SYSTEM = (1 << 1)
+} WacomIntegrationFlags;
+
+/**
* Classes of devices.
*/
typedef enum {
@@ -463,10 +479,11 @@ int libwacom_get_button_led_group (WacomDevice *device,
/**
* @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.
*/
-int libwacom_is_builtin(WacomDevice *device);
+int libwacom_is_builtin(WacomDevice *device) LIBWACOM_DEPRECATED;
/**
* @param device The tablet to query
@@ -477,6 +494,12 @@ int libwacom_is_reversible(WacomDevice *device);
/**
* @param device The tablet to query
+ * @return the integration flags for the device
+ */
+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..4afba4d 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -39,20 +39,14 @@
printf(__VA_ARGS__)
#define GENERIC_DEVICE_MATCH "generic"
-
-typedef enum {
- IS_BUILTIN_UNSET = -1,
- IS_BUILTIN_FALSE = 0,
- IS_BUILTIN_TRUE = 1
-} IsBuiltin;
+#define WACOM_DEVICE_INTEGRATED_UNSET (WACOM_DEVICE_INTEGRATED_NONE - 1)
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 +73,7 @@ struct _WacomDevice {
WacomClass cls;
int num_strips;
uint32_t features;
+ uint32_t integration_flags;
int strips_num_modes;
int ring_num_modes;
diff --git a/test/load.c b/test/load.c
index cf13ba7..e2db1dc 100644
--- a/test/load.c
+++ b/test/load.c
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
assert(libwacom_has_ring(device));
assert(!libwacom_has_ring2(device));
assert(libwacom_get_num_strips(device) == 0);
- assert(!libwacom_is_builtin(device));
+ assert(libwacom_get_integration_flags (device) == WACOM_DEVICE_INTEGRATED_NONE);
assert(libwacom_get_width(device) == 8);
assert(libwacom_get_height(device) == 5);
@@ -124,8 +124,8 @@ int main(int argc, char **argv)
device = libwacom_new_from_name(db, "Wacom Serial Tablet WACf004", NULL);
assert(device);
- assert(libwacom_is_builtin(device));
-
+ assert(libwacom_get_integration_flags (device) & WACOM_DEVICE_INTEGRATED_DISPLAY);
+ assert(libwacom_get_integration_flags (device) & WACOM_DEVICE_INTEGRATED_SYSTEM);
libwacom_database_destroy (db);
return 0;
--
1.7.1
------------------------------------------------------------------------------
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