From b4544c5012748194ccc78bcb0feb0ddffe051575 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 10 Jun 2022 19:28:01 +0200 Subject: [PATCH] info: use byte descriptors in di_info_get_product_name() These contain more user-friendly names. Signed-off-by: Simon Ser --- info.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/info.c b/info.c index eacbdd8..76979a0 100644 --- a/info.c +++ b/info.c @@ -43,22 +43,42 @@ di_info_get_edid(const struct di_info *info) char * di_info_get_product_name(const struct di_info *info) { - char name[64], serial[32]; + char name[256], product_code[32], serial_code[32]; + const char *product, *serial; const struct di_edid_vendor_product *edid_vendor_product; + const struct di_edid_display_descriptor *const *display_descs; + size_t i; edid_vendor_product = di_edid_get_vendor_product(info->edid); + snprintf(product_code, sizeof(product_code), "0x%X" PRIu16, + edid_vendor_product->product); if (edid_vendor_product->serial != 0) { - snprintf(serial, sizeof(serial), " 0x%X" PRIu32, + snprintf(serial_code, sizeof(serial), " 0x%X" PRIu32, edid_vendor_product->serial); } else { - serial[0] = '\0'; + serial_code[0] = '\0'; } - /* TODO: use strings from Detailed Timing Descriptors, if any */ - snprintf(name, sizeof(name), "%.3s 0x%X" PRIu16 "%s", - edid_vendor_product->manufacturer, - edid_vendor_product->product, serial); + product = product_code; + serial = serial_code; + display_descs = di_edid_get_display_descriptors(info->edid); + for (i = 0; display_descs[i] != NULL; i++) { + const struct di_edid_display_descriptor *desc = display_descs[i]; + switch (di_edid_display_descriptor_get_tag(desc)) { + case DI_EDID_DISPLAY_DESCRIPTOR_PRODUCT_SERIAL: + serial = di_edid_display_descriptor_get_string(desc); + break; + case DI_EDID_DISPLAY_DESCRIPTOR_PRODUCT_NAME: + product = di_edid_display_descriptor_get_string(desc); + break; + default: + break; /* Ignore */ + } + } + + snprintf(name, sizeof(name), "%.3s %s%s", + edid_vendor_product->manufacturer, product, serial); return strdup(name); }