xf86drmMode: introduce drmModeGetConnectorTypeName
authorSimon Ser <contact@emersion.fr>
Tue, 1 Feb 2022 13:33:34 +0000 (14:33 +0100)
committerSimon Ser <contact@emersion.fr>
Sat, 2 Jul 2022 20:13:29 +0000 (20:13 +0000)
User-space often needs to print the name of a connector type.
When a new connector type is added, all user-space programs need
to be updated to support the new connector type.

Expose a function to get a connector type name in libdrm.

The names are taken from the kernel [1].

[1]: https://cgit.freedesktop.org/drm/drm/tree/drivers/gpu/drm/drm_connector.c?h=4fc8cb47fcfdc93e274a1291757e478df4f9c39b#n83

Signed-off-by: Simon Ser <contact@emersion.fr>
core-symbols.txt
xf86drmMode.c
xf86drmMode.h

index 31bbcf8..dcf9001 100644 (file)
@@ -126,6 +126,7 @@ drmModeFreePropertyBlob
 drmModeFreeResources
 drmModeGetConnector
 drmModeGetConnectorCurrent
+drmModeGetConnectorTypeName
 drmModeGetCrtc
 drmModeGetEncoder
 drmModeGetFB
index 6b79d76..6d636dc 100644 (file)
@@ -1747,3 +1747,56 @@ drm_public void drmModeFreeFB2(drmModeFB2Ptr ptr)
 {
        drmFree(ptr);
 }
+
+drm_public const char *
+drmModeGetConnectorTypeName(uint32_t connector_type)
+{
+       /* Keep the strings in sync with the kernel's drm_connector_enum_list in
+        * drm_connector.c. */
+       switch (connector_type) {
+       case DRM_MODE_CONNECTOR_Unknown:
+               return "Unknown";
+       case DRM_MODE_CONNECTOR_VGA:
+               return "VGA";
+       case DRM_MODE_CONNECTOR_DVII:
+               return "DVI-I";
+       case DRM_MODE_CONNECTOR_DVID:
+               return "DVI-D";
+       case DRM_MODE_CONNECTOR_DVIA:
+               return "DVI-A";
+       case DRM_MODE_CONNECTOR_Composite:
+               return "Composite";
+       case DRM_MODE_CONNECTOR_SVIDEO:
+               return "SVIDEO";
+       case DRM_MODE_CONNECTOR_LVDS:
+               return "LVDS";
+       case DRM_MODE_CONNECTOR_Component:
+               return "Component";
+       case DRM_MODE_CONNECTOR_9PinDIN:
+               return "DIN";
+       case DRM_MODE_CONNECTOR_DisplayPort:
+               return "DP";
+       case DRM_MODE_CONNECTOR_HDMIA:
+               return "HDMI-A";
+       case DRM_MODE_CONNECTOR_HDMIB:
+               return "HDMI-B";
+       case DRM_MODE_CONNECTOR_TV:
+               return "TV";
+       case DRM_MODE_CONNECTOR_eDP:
+               return "eDP";
+       case DRM_MODE_CONNECTOR_VIRTUAL:
+               return "Virtual";
+       case DRM_MODE_CONNECTOR_DSI:
+               return "DSI";
+       case DRM_MODE_CONNECTOR_DPI:
+               return "DPI";
+       case DRM_MODE_CONNECTOR_WRITEBACK:
+               return "Writeback";
+       case DRM_MODE_CONNECTOR_SPI:
+               return "SPI";
+       case DRM_MODE_CONNECTOR_USB:
+               return "USB";
+       default:
+               return NULL;
+       }
+}
index 0855764..46dc80a 100644 (file)
@@ -475,6 +475,15 @@ extern drmModeObjectListPtr drmModeGetLease(int fd);
 
 extern int drmModeRevokeLease(int fd, uint32_t lessee_id);
 
+/**
+ * Get a string describing a connector type.
+ *
+ * NULL is returned if the connector type is unsupported. Callers should handle
+ * this gracefully, e.g. by falling back to "Unknown" or printing the raw value.
+ */
+extern const char *
+drmModeGetConnectorTypeName(uint32_t connector_type);
+
 #if defined(__cplusplus)
 }
 #endif