diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2017-10-20 11:33:31 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2017-10-20 11:33:31 +0300 |
commit | 3da8bff960177bbbd2dc86849846e3b6ec97bc79 (patch) | |
tree | 1cc343f7dcc8451cf30b6ebcce5d6aeede74d5ae /kms++/src | |
parent | 32255b811edae510304389de4e30fe3e4aaa9ab7 (diff) |
Connector: improve get_mode(string)
Diffstat (limited to 'kms++/src')
-rw-r--r-- | kms++/src/connector.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/kms++/src/connector.cpp b/kms++/src/connector.cpp index 9141431..47759be 100644 --- a/kms++/src/connector.cpp +++ b/kms++/src/connector.cpp @@ -130,11 +130,24 @@ Videomode Connector::get_mode(const string& mode) const { auto c = m_priv->drm_connector; - for (int i = 0; i < c->count_modes; i++) - if (mode == c->modes[i].name) - return drm_mode_to_video_mode(c->modes[i]); + size_t idx = mode.find('@'); - throw invalid_argument(mode + ": mode not found"); + string name = idx == string::npos ? mode : mode.substr(0, idx); + float vrefresh = idx == string::npos ? 0.0 : stod(mode.substr(idx + 1)); + + for (int i = 0; i < c->count_modes; i++) { + Videomode m = drm_mode_to_video_mode(c->modes[i]); + + if (m.name != name) + continue; + + if (vrefresh && vrefresh != m.calculated_vrefresh()) + continue; + + return m; + } + + throw invalid_argument(mode + ": mode not found"); } Videomode Connector::get_mode(unsigned xres, unsigned yres, float vrefresh, bool ilace) const |