summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-03-25 13:41:37 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2021-03-29 12:42:37 +1000
commitd70da0842ddb086c10cb22679e80a5ab20331490 (patch)
treea94b31e86af94d26ed3704dc3b45032e3d476e7b
parent24221d0f46d5e175dec3a78445a51d130a3d19f9 (diff)
downloadlibwacom-d70da0842ddb086c10cb22679e80a5ab20331490.tar.gz
Switch the status leds to using a GArray
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--libwacom/libwacom-database.c8
-rw-r--r--libwacom/libwacom.c28
-rw-r--r--libwacom/libwacomint.h3
3 files changed, 21 insertions, 18 deletions
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index af3cdf6..6407e26 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -812,24 +812,20 @@ libwacom_parse_tablet_keyfile(WacomDeviceDatabase *db,
if (num_buttons > 0)
libwacom_parse_buttons(device, keyfile);
+ device->status_leds = g_array_new (FALSE, FALSE, sizeof(WacomStatusLEDs));
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; string_list[i]; i++) {
for (n = 0; n < G_N_ELEMENTS (supported_leds); n++) {
if (g_str_equal(string_list[i], supported_leds[n].key)) {
- g_array_append_val (array, supported_leds[n].value);
- device->num_leds++;
+ g_array_append_val (device->status_leds, supported_leds[n].value);
break;
}
}
}
g_strfreev (string_list);
- device->status_leds = (WacomStatusLEDs *) g_array_free (array, FALSE);
}
success = TRUE;
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index f3be49d..1e6a3b1 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -344,8 +344,13 @@ libwacom_copy(const WacomDevice *device)
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->status_leds = g_array_sized_new(FALSE, FALSE,
+ sizeof(WacomStatusLEDs),
+ device->status_leds->len);
+ for (guint i = 0; i < device->status_leds->len; i++) {
+ g_array_append_val(d->status_leds,
+ g_array_index(device->status_leds, WacomStatusLEDs, i));
+ }
d->buttons = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, g_free);
@@ -459,10 +464,11 @@ libwacom_compare(const WacomDevice *a, const WacomDevice *b, WacomCompareFlags f
if (memcmp(a->styli->data, b->styli->data, sizeof(int) * a->styli->len) != 0)
return 1;
- if (a->num_leds != b->num_leds)
+ if (a->status_leds->len != b->status_leds->len)
return 1;
- if (memcmp(a->status_leds, b->status_leds, sizeof(WacomStatusLEDs) * a->num_leds) != 0)
+ if (memcmp(a->status_leds->data, b->status_leds->data,
+ sizeof(WacomStatusLEDs) * a->status_leds->len) != 0)
return 1;
g_hash_table_iter_init(&iter, a->buttons);
@@ -893,7 +899,7 @@ libwacom_unref(WacomDevice *device)
libwacom_match_unref(g_array_index(device->matches, WacomMatch*, i));
g_array_free (device->matches, TRUE);
g_array_free (device->styli, TRUE);
- g_free (device->status_leds);
+ g_array_free (device->status_leds, TRUE);
if (device->buttons)
g_hash_table_destroy (device->buttons);
g_free (device);
@@ -1111,8 +1117,8 @@ libwacom_get_strips_num_modes(const WacomDevice *device)
LIBWACOM_EXPORT const WacomStatusLEDs *
libwacom_get_status_leds(const WacomDevice *device, int *num_leds)
{
- *num_leds = device->num_leds;
- return device->status_leds;
+ *num_leds = device->status_leds->len;
+ return (const WacomStatusLEDs*)device->status_leds->data;
}
static const struct {
@@ -1128,19 +1134,21 @@ static const struct {
LIBWACOM_EXPORT int
libwacom_get_button_led_group (const WacomDevice *device, char button)
{
- int led_index;
WacomButton *b = g_hash_table_lookup(device->buttons,
GINT_TO_POINTER(button));
if (!(b->flags & WACOM_BUTTON_MODESWITCH))
return -1;
- for (led_index = 0; led_index < device->num_leds; led_index++) {
+ for (guint led_index = 0; led_index < device->status_leds->len; led_index++) {
guint n;
for (n = 0; n < G_N_ELEMENTS (button_status_leds); n++) {
+ WacomStatusLEDs led = g_array_index(device->status_leds,
+ WacomStatusLEDs,
+ led_index);
if ((b->flags & button_status_leds[n].button_flags) &&
- (device->status_leds[led_index] == button_status_leds[n].status_leds)) {
+ (led == button_status_leds[n].status_leds)) {
return led_index;
}
}
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 47574b0..07b5175 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -93,8 +93,7 @@ struct _WacomDevice {
GArray *styli;
GHashTable *buttons; /* 'A' : WacomButton */
- int num_leds;
- WacomStatusLEDs *status_leds;
+ GArray *status_leds;
char *layout;