Add get_mode(const char *mode) to Connector class.
[android/external-libkmsxx.git] / libkms++ / connector.cpp
index ee14af9388c34b0741b6cba3d33a2a0ceab899d6..d26d7e16267f6b780fdaae1ab13b09b97d1018bc 100644 (file)
@@ -89,6 +89,18 @@ Videomode Connector::get_default_mode() const
        return drm_mode_to_video_mode(drmmode);
 }
 
+Videomode Connector::get_mode(const char *mode) const
+{
+       auto c = m_priv->drm_connector;
+       string sMode(mode);
+
+       for (int i = 0; i < c->count_modes; i++)
+                if (sMode == c->modes[i].name)
+                        return drm_mode_to_video_mode(c->modes[i]);
+
+        throw invalid_argument((sMode + ": mode not found").c_str());
+}
+
 bool Connector::connected()
 {
        return m_priv->drm_connector->connection == DRM_MODE_CONNECTED;