feat(monitor): use primary monitor as default (#1426)
If the monitor option isn't set, the primary monitor (if connected) is chosen as the default display.
This commit is contained in:
parent
b03f14400a
commit
1145681cf5
@ -36,6 +36,7 @@ struct randr_output {
|
|||||||
short int y{0};
|
short int y{0};
|
||||||
xcb_randr_output_t output;
|
xcb_randr_output_t output;
|
||||||
backlight_values backlight;
|
backlight_values backlight;
|
||||||
|
bool primary{false};
|
||||||
|
|
||||||
bool match(const string& o, bool exact = true) const;
|
bool match(const string& o, bool exact = true) const;
|
||||||
bool match(const position& p) const;
|
bool match(const position& p) const;
|
||||||
@ -48,7 +49,8 @@ namespace randr_util {
|
|||||||
|
|
||||||
bool check_monitor_support();
|
bool check_monitor_support();
|
||||||
|
|
||||||
monitor_t make_monitor(xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y);
|
monitor_t make_monitor(xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y,
|
||||||
|
bool primary);
|
||||||
vector<monitor_t> get_monitors(connection& conn, xcb_window_t root, bool connected_only = false, bool realloc = false);
|
vector<monitor_t> get_monitors(connection& conn, xcb_window_t root, bool connected_only = false, bool realloc = false);
|
||||||
monitor_t match_monitor(vector<monitor_t> monitors, const string& name, bool exact_match);
|
monitor_t match_monitor(vector<monitor_t> monitors, const string& name, bool exact_match);
|
||||||
|
|
||||||
|
@ -80,6 +80,17 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
throw application_error("No monitors found");
|
throw application_error("No monitors found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if monitor_name is not defined, first check for primary monitor
|
||||||
|
if (monitor_name.empty()) {
|
||||||
|
for (auto&& mon : monitors) {
|
||||||
|
if (mon->primary) {
|
||||||
|
monitor_name = mon->name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if still not found (and not strict matching), get first connected monitor
|
||||||
if (monitor_name.empty() && !m_opts.monitor_strict) {
|
if (monitor_name.empty() && !m_opts.monitor_strict) {
|
||||||
auto connected_monitors = randr_util::get_monitors(m_connection, m_connection.screen()->root, true);
|
auto connected_monitors = randr_util::get_monitors(m_connection, m_connection.screen()->root, true);
|
||||||
if (!connected_monitors.empty()) {
|
if (!connected_monitors.empty()) {
|
||||||
@ -88,11 +99,13 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if still not found, get first monitor
|
||||||
if (monitor_name.empty()) {
|
if (monitor_name.empty()) {
|
||||||
monitor_name = monitors[0]->name;
|
monitor_name = monitors[0]->name;
|
||||||
m_log.warn("No monitor specified, using \"%s\"", monitor_name);
|
m_log.warn("No monitor specified, using \"%s\"", monitor_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the monitor data based on the name
|
||||||
m_opts.monitor = randr_util::match_monitor(monitors, monitor_name, m_opts.monitor_exact);
|
m_opts.monitor = randr_util::match_monitor(monitors, monitor_name, m_opts.monitor_exact);
|
||||||
monitor_t fallback{};
|
monitor_t fallback{};
|
||||||
|
|
||||||
|
@ -78,9 +78,10 @@ int main(int argc, char** argv) {
|
|||||||
if (cli->has("list-monitors")) {
|
if (cli->has("list-monitors")) {
|
||||||
for (auto&& mon : randr_util::get_monitors(conn, conn.root(), true)) {
|
for (auto&& mon : randr_util::get_monitors(conn, conn.root(), true)) {
|
||||||
if (WITH_XRANDR_MONITORS && mon->output == XCB_NONE) {
|
if (WITH_XRANDR_MONITORS && mon->output == XCB_NONE) {
|
||||||
printf("%s: %ix%i+%i+%i (XRandR monitor)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y);
|
printf("%s: %ix%i+%i+%i (XRandR monitor%s)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y,
|
||||||
|
mon->primary ? ", primary" : "");
|
||||||
} else {
|
} else {
|
||||||
printf("%s: %ix%i+%i+%i\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y);
|
printf("%s: %ix%i+%i+%i%s\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y, mon->primary ? " (primary)" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -64,7 +64,8 @@ namespace randr_util {
|
|||||||
* Define monitor
|
* Define monitor
|
||||||
*/
|
*/
|
||||||
monitor_t make_monitor(
|
monitor_t make_monitor(
|
||||||
xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y) {
|
xcb_randr_output_t randr, string name, unsigned short int w, unsigned short int h, short int x, short int y,
|
||||||
|
bool primary) {
|
||||||
monitor_t mon{new monitor_t::element_type{}};
|
monitor_t mon{new monitor_t::element_type{}};
|
||||||
mon->output = randr;
|
mon->output = randr;
|
||||||
mon->name = move(name);
|
mon->name = move(name);
|
||||||
@ -72,6 +73,7 @@ namespace randr_util {
|
|||||||
mon->y = y;
|
mon->y = y;
|
||||||
mon->h = h;
|
mon->h = h;
|
||||||
mon->w = w;
|
mon->w = w;
|
||||||
|
mon->primary = primary;
|
||||||
return mon;
|
return mon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,13 +94,17 @@ namespace randr_util {
|
|||||||
for (auto&& mon : conn.get_monitors(root, true).monitors()) {
|
for (auto&& mon : conn.get_monitors(root, true).monitors()) {
|
||||||
try {
|
try {
|
||||||
auto name = conn.get_atom_name(mon.name).name();
|
auto name = conn.get_atom_name(mon.name).name();
|
||||||
monitors.emplace_back(make_monitor(XCB_NONE, move(name), mon.width, mon.height, mon.x, mon.y));
|
monitors.emplace_back(make_monitor(XCB_NONE, move(name), mon.width, mon.height, mon.x, mon.y, mon.primary));
|
||||||
} catch (const exception&) {
|
} catch (const exception&) {
|
||||||
// silently ignore output
|
// silently ignore output
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
auto primary_output = conn.get_output_primary(root).output();
|
||||||
|
auto primary_info = conn.get_output_info(primary_output);
|
||||||
|
auto name_iter = primary_info.name();
|
||||||
|
string primary_name = {name_iter.begin(), name_iter.end()};
|
||||||
|
|
||||||
for (auto&& output : conn.get_screen_resources(root).outputs()) {
|
for (auto&& output : conn.get_screen_resources(root).outputs()) {
|
||||||
try {
|
try {
|
||||||
@ -124,7 +130,8 @@ namespace randr_util {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto crtc = conn.get_crtc_info(info->crtc);
|
auto crtc = conn.get_crtc_info(info->crtc);
|
||||||
monitors.emplace_back(make_monitor(output, move(name), crtc->width, crtc->height, crtc->x, crtc->y));
|
auto primary = (primary_name == name);
|
||||||
|
monitors.emplace_back(make_monitor(output, move(name), crtc->width, crtc->height, crtc->x, crtc->y, primary));
|
||||||
} catch (const exception&) {
|
} catch (const exception&) {
|
||||||
// silently ignore output
|
// silently ignore output
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user