Skip to content

Commit

Permalink
Remove priority
Browse files Browse the repository at this point in the history
Made registration order explicit, this keeps output ordering in a single file
and easier to keep track of.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Dec 7, 2024
1 parent 808397b commit 2190ae7
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 26 deletions.
5 changes: 1 addition & 4 deletions src/display-console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions src/display-file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion src/display-http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 1 addition & 3 deletions src/display-ncurses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
18 changes: 10 additions & 8 deletions src/display-output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 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::NCURSES>(outputs);
register_output<output_t::FILE>(outputs);
register_output<output_t::HTTP>(outputs);
register_output<output_t::X11>(outputs);
register_output<output_t::WAYLAND>(outputs);
register_output<output_t::FILE>(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());
Expand Down
6 changes: 0 additions & 6 deletions src/display-output.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/display-wayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 3;
}

bool display_output_wayland::detect() {
Expand Down
1 change: 0 additions & 1 deletion src/display-x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2190ae7

Please sign in to comment.