randr: Add separate key for exact monitor matching

This adds `monitor-exact = true` in the bar section

This also properly does best-match instead of first-match if multiple
matches exists. For example if there are two monitors HDMI2 and HDMI-2
and we try to match HDMI-2 with monitor-exact = false, until now HDMI2
would be matched. Now exact matches are always preferred.

Fixes 
This commit is contained in:
patrick96 2018-12-03 01:21:20 +01:00 committed by Patrick Ziegler
parent ea5fc22c7d
commit e793082008
5 changed files with 48 additions and 28 deletions
src/components

View file

@ -73,6 +73,7 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
auto monitor_name = m_conf.get(bs, "monitor", ""s);
auto monitor_name_fallback = m_conf.get(bs, "monitor-fallback", ""s);
auto monitor_strictmode = m_conf.get(bs, "monitor-strict", false);
m_opts.monitor_exact = m_conf.get(bs, "monitor-exact", m_opts.monitor_exact);
auto monitors = randr_util::get_monitors(m_connection, m_connection.screen()->root, monitor_strictmode);
if (monitors.empty()) {
@ -92,26 +93,17 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
m_log.warn("No monitor specified, using \"%s\"", monitor_name);
}
bool name_found{false};
bool fallback_found{monitor_name_fallback.empty()};
m_opts.monitor = randr_util::match_monitor(monitors, monitor_name, m_opts.monitor_exact);
monitor_t fallback{};
for (auto&& monitor : monitors) {
if (!name_found && (name_found = monitor->match(monitor_name, monitor_strictmode))) {
m_opts.monitor = move(monitor);
} else if (!fallback_found && (fallback_found = monitor->match(monitor_name_fallback, monitor_strictmode))) {
fallback = move(monitor);
}
if (name_found && fallback_found) {
break;
}
if(!monitor_name_fallback.empty()) {
fallback = randr_util::match_monitor(monitors, monitor_name_fallback, m_opts.monitor_exact);
}
if (!m_opts.monitor) {
if (fallback) {
m_opts.monitor = move(fallback);
m_log.warn("Monitor \"%s\" not found, reverting to fallback \"%s\"", monitor_name, monitor_name_fallback);
m_log.warn("Monitor \"%s\" not found, reverting to fallback \"%s\"", monitor_name, m_opts.monitor->name);
} else {
throw application_error("Monitor \"" + monitor_name + "\" not found or disconnected");
}