summaryrefslogtreecommitdiff
path: root/libwacom
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-03-25 09:34:27 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-03-29 12:42:37 +1000
commit2289d35e0428d1cf6e566102b1b86088ad3d26cb (patch)
tree2af2e421b00d1df142f7a176a9ca451aa59b226b /libwacom
parent06c1088342a349d7494dd8d86a7eca63e936494d (diff)
downloadlibwacom-2289d35e0428d1cf6e566102b1b86088ad3d26cb.tar.gz
Switch the styli to use a GArray
We already did so for the collection of the actual styli but then converted it back to a C array to use internally. Let's just keep the GArray internally everywhere, only exposing the C array in the API. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libwacom')
-rw-r--r--libwacom/libwacom-database.c14
-rw-r--r--libwacom/libwacom.c18
-rw-r--r--libwacom/libwacomint.h3
3 files changed, 18 insertions, 17 deletions
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index 634684c..d3c2366 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -576,7 +576,6 @@ libwacom_parse_styli_list(WacomDeviceDatabase *db, WacomDevice *device,
guint i;
array = g_array_new (FALSE, FALSE, sizeof(int));
- device->num_styli = 0;
for (i = 0; ids[i]; i++) {
const char *id = ids[i];
@@ -584,7 +583,6 @@ libwacom_parse_styli_list(WacomDeviceDatabase *db, WacomDevice *device,
int int_value;
if (safe_atoi_base (ids[i], &int_value, 16)) {
g_array_append_val (array, int_value);
- device->num_styli++;
}
} else if (g_str_has_prefix(id, "@")) {
const char *group = &id[1];
@@ -596,7 +594,6 @@ libwacom_parse_styli_list(WacomDeviceDatabase *db, WacomDevice *device,
WacomStylus *stylus = value;
if (stylus->group && g_str_equal(group, stylus->group)) {
g_array_append_val (array, stylus->id);
- device->num_styli++;
}
}
} else {
@@ -606,7 +603,7 @@ libwacom_parse_styli_list(WacomDeviceDatabase *db, WacomDevice *device,
/* Using groups means we don't get the styli in ascending order.
Sort it so the output is predictable */
g_array_sort(array, styli_id_sort);
- device->supported_styli = (int *) g_array_free (array, FALSE);
+ device->styli = array;
}
static WacomDevice*
@@ -723,10 +720,11 @@ libwacom_parse_tablet_keyfile(WacomDeviceDatabase *db,
libwacom_parse_styli_list(db, device, string_list);
g_strfreev (string_list);
} else {
- device->supported_styli = g_new (int, 2);
- device->supported_styli[0] = WACOM_ERASER_FALLBACK_ID;
- device->supported_styli[1] = WACOM_STYLUS_FALLBACK_ID;
- device->num_styli = 2;
+ int fallback_eraser = WACOM_ERASER_FALLBACK_ID;
+ int fallback_stylus = WACOM_STYLUS_FALLBACK_ID;
+ device->styli = g_array_new(FALSE, FALSE, sizeof(int));
+ g_array_append_val(device->styli, fallback_eraser);
+ g_array_append_val(device->styli, fallback_stylus);
}
/* Features */
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 6b21fbb..b151fb3 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -336,8 +336,12 @@ libwacom_copy(const WacomDevice *device)
d->strips_num_modes = device->strips_num_modes;
d->ring_num_modes = device->ring_num_modes;
d->ring2_num_modes = device->ring2_num_modes;
- d->num_styli = device->num_styli;
- d->supported_styli = g_memdup2 (device->supported_styli, sizeof(int) * device->num_styli);
+ d->styli = g_array_sized_new(FALSE, FALSE, sizeof(int),
+ device->styli->len);
+ for (guint i = 0; i < device->styli->len; i++) {
+ int id = g_array_index(device->styli, int, i);
+ g_array_append_val(d->styli, id);
+ }
d->num_leds = device->num_leds;
d->status_leds = g_memdup2 (device->status_leds, sizeof(WacomStatusLEDs) * device->num_leds);
d->num_buttons = device->num_buttons;
@@ -438,10 +442,10 @@ libwacom_compare(const WacomDevice *a, const WacomDevice *b, WacomCompareFlags f
if (a->num_buttons != b->num_buttons)
return 1;
- if (a->num_styli != b->num_styli)
+ if (a->styli->len != b->styli->len)
return 1;
- if (memcmp(a->supported_styli, b->supported_styli, sizeof(int) * a->num_styli) != 0)
+ if (memcmp(a->styli->data, b->styli->data, sizeof(int) * a->styli->len) != 0)
return 1;
if (a->num_leds != b->num_leds)
@@ -874,7 +878,7 @@ libwacom_unref(WacomDevice *device)
for (guint i = 0; i < device->matches->len; i++)
libwacom_match_unref(g_array_index(device->matches, WacomMatch*, i));
g_array_free (device->matches, TRUE);
- g_free (device->supported_styli);
+ g_array_free (device->styli, TRUE);
g_free (device->status_leds);
g_free (device->buttons);
g_free (device->button_codes);
@@ -1050,8 +1054,8 @@ libwacom_get_num_buttons(const WacomDevice *device)
LIBWACOM_EXPORT const int *
libwacom_get_supported_styli(const WacomDevice *device, int *num_styli)
{
- *num_styli = device->num_styli;
- return device->supported_styli;
+ *num_styli = device->styli->len;
+ return (const int *)device->styli->data;
}
LIBWACOM_EXPORT int
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 23cd999..f5041a2 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -84,8 +84,7 @@ struct _WacomDevice {
int ring_num_modes;
int ring2_num_modes;
- gsize num_styli;
- int *supported_styli;
+ GArray *styli;
int num_buttons;
WacomButtonFlags *buttons;