Connector: add get_mode(xres, yres, refresh)
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 13 Nov 2015 17:26:02 +0000 (19:26 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 13 Nov 2015 20:12:41 +0000 (22:12 +0200)
libkms++/connector.cpp
libkms++/connector.h

index e507c9e91cb159c17683882f0c798657d44cda58..5a6fdd93108f90bb9e14438a430a838786f92966 100644 (file)
@@ -114,6 +114,25 @@ Videomode Connector::get_mode(const string& mode) const
         throw invalid_argument(mode + ": mode not found");
 }
 
+Videomode Connector::get_mode(unsigned xres, unsigned yres, unsigned refresh) const
+{
+       auto c = m_priv->drm_connector;
+
+       for (int i = 0; i < c->count_modes; i++) {
+               drmModeModeInfo& m = c->modes[i];
+
+               if (m.hdisplay != xres || m.vdisplay != yres)
+                       continue;
+
+               if (refresh && m.vrefresh != refresh)
+                       continue;
+
+               return drm_mode_to_video_mode(c->modes[i]);
+       }
+
+       throw invalid_argument("mode not found");
+}
+
 bool Connector::connected() const
 {
        return m_priv->drm_connector->connection == DRM_MODE_CONNECTED ||
index a897d31d7d79bfad828b57bfd23298a480d94ac0..cc04d522279e91941922c7e95ebdf0ce5193a95f 100644 (file)
@@ -17,6 +17,7 @@ public:
        Videomode get_default_mode() const;
 
        Videomode get_mode(const std::string& mode) const;
+       Videomode get_mode(unsigned xres, unsigned yres, unsigned refresh) const;
 
        Crtc* get_current_crtc() const;
        std::vector<Crtc*> get_possible_crtcs() const;