Use explicit output ordering (#2103)

Removed output sorting by `priority` in favor of explicit output ordering. Fixes some Wayland initialization bugs.
This commit is contained in:
Willow
2024-12-07 20:13:00 +01:00
committed by GitHub
parent 0624b756f1
commit 2b7e4b250f
8 changed files with 13 additions and 27 deletions

View File

@@ -50,10 +50,7 @@ void register_output<output_t::CONSOLE>(display_outputs_t &outputs) {
}
display_output_console::display_output_console(const std::string &name_)
: display_output_base(name_) {
// lowest priority, it's a fallback
priority = 0;
}
: display_output_base(name_) {}
bool display_output_console::detect() {
if ((out_to_stdout.get(*state) || out_to_stderr.get(*state))

View File

@@ -56,8 +56,6 @@ void register_output<output_t::FILE>(display_outputs_t &outputs) {
display_output_file::display_output_file(const std::string &name_)
: display_output_base(name_) {
// lowest priority, it's a fallback
priority = 0;
}
bool display_output_file::detect() {

View File

@@ -127,7 +127,6 @@ std::string string_replace_all(std::string original, const std::string &oldpart,
//} // namespace priv
display_output_http::display_output_http() : display_output_base("http") {
priority = 0;
httpd = NULL;
}

View File

@@ -91,9 +91,7 @@ Colour from_ncurses(int nccolor) {
}
display_output_ncurses::display_output_ncurses()
: display_output_console("ncurses") {
priority = 1;
}
: display_output_console("ncurses") {}
bool display_output_ncurses::detect() {
if (out_to_ncurses.get(*state)) {

View File

@@ -80,22 +80,24 @@ std::vector<conky::display_output_base *> current_display_outputs;
bool initialize_display_outputs() {
std::vector<display_output_base *> outputs;
outputs.reserve(static_cast<size_t>(output_t::OUTPUT_COUNT));
register_output<output_t::CONSOLE>(outputs);
register_output<output_t::NCURSES>(outputs);
register_output<output_t::FILE>(outputs);
register_output<output_t::HTTP>(outputs);
register_output<output_t::X11>(outputs);
// Order of registration is important!
// - Graphical outputs go before textual (e.g. X11 before NCurses).
// - Optional outputs go before non-optional (e.g. Wayland before X11).
// - Newer outputs go before older (e.g. NCurses before (hypothetical) Curses).
// - Fallbacks go last (in group)
register_output<output_t::WAYLAND>(outputs);
register_output<output_t::X11>(outputs);
register_output<output_t::HTTP>(outputs);
register_output<output_t::FILE>(outputs);
register_output<output_t::NCURSES>(outputs);
register_output<output_t::CONSOLE>(outputs); // global fallback - always works
for (auto out : outputs) { NORM_ERR("FOUND: %s", out->name.c_str()); }
// Sort display outputs by descending priority, to try graphical ones first.
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);
int graphical_count = 0;
for (auto output : outputs) {
if (output->priority < 0) continue;
DBGP2("Testing display output '%s'... ", output->name.c_str());
if (output->detect()) {
DBGP2("Detected display output '%s'... ", output->name.c_str());

View File

@@ -61,17 +61,11 @@ class display_output_base {
const std::string name;
bool is_active = false;
bool is_graphical = false;
int priority = -1;
explicit display_output_base(const std::string &name) : name(name){};
virtual ~display_output_base() {}
static bool priority_compare(const display_output_base *a,
const display_output_base *b) {
return a->priority > b->priority;
}
// check if available and enabled in settings
virtual bool detect() { return false; }
// connect to DISPLAY and other stuff

View File

@@ -243,7 +243,6 @@ void register_output<output_t::WAYLAND>(display_outputs_t &outputs) {
display_output_wayland::display_output_wayland()
: display_output_base("wayland") {
is_graphical = true;
priority = 2;
}
bool display_output_wayland::detect() {

View File

@@ -226,7 +226,6 @@ void register_output<output_t::X11>(display_outputs_t &outputs) {
display_output_x11::display_output_x11() : display_output_base("x11") {
is_graphical = true;
priority = 2;
}
bool display_output_x11::detect() {