From ef957bfb9102a2ad69dd6190d37d18f319663523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 5 Oct 2018 05:08:34 +0200 Subject: [PATCH] Actually allow more than one display-output at once We already do this like with HTTP+stdout. --- src/conky.cc | 11 +++++------ src/display-output.cc | 15 +++++++++------ src/display-output.hh | 5 ++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 66d95cce..c45134cc 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -1098,8 +1098,9 @@ static void draw_string(const char *s) { #ifdef BUILD_NCURSES if (out_to_ncurses.get(*state) && draw_mode == FG) { printw("%s", s); } #endif /* BUILD_NCURSES */ - if (conky::active_display_output != nullptr && draw_mode == FG) - conky::active_display_output->draw_string(s, width_of_s); + if (conky::active_display_outputs.size() && draw_mode == FG) + for (auto output : conky::active_display_outputs) + output->draw_string(s, width_of_s); int tbs = text_buffer_size.get(*state); memset(tmpstring1, 0, tbs); memset(tmpstring2, 0, tbs); @@ -1657,8 +1658,7 @@ static int draw_line(char *s, int special_index) { } static void draw_text() { - if (conky::active_display_output) - conky::active_display_output->begin_draw_text(); + for (auto output : conky::active_display_outputs) output->begin_draw_text(); #ifdef BUILD_X11 if (out_to_x.get(*state)) { cur_y = text_start_y; @@ -1693,8 +1693,7 @@ static void draw_text() { attron(COLOR_PAIR(COLOR_WHITE)); #endif /* BUILD_NCURSES */ for_each_line(text_buffer, draw_line); - if (conky::active_display_output) - conky::active_display_output->end_draw_text(); + for (auto output : conky::active_display_outputs) output->end_draw_text(); } static void draw_stuff() { diff --git a/src/display-output.cc b/src/display-output.cc index 4e304bd3..8e1eb0f6 100644 --- a/src/display-output.cc +++ b/src/display-output.cc @@ -27,6 +27,7 @@ #include #include #include +#include namespace conky { namespace { @@ -46,9 +47,8 @@ display_outputs_t *display_outputs; /* * The selected and active display output. - * XXX: do we want to support multiple outputs??? */ -display_output_base *active_display_output = nullptr; +std::vector active_display_outputs; namespace priv { void do_register_display_output(const std::string &name, @@ -94,6 +94,7 @@ bool initialize_display_outputs() { sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare); for (auto output : outputs) { + if (output->priority < 0) continue; std::cerr << "Testing display output '" << output->name << "'... " << std::endl; if (output->detect()) { @@ -103,18 +104,20 @@ bool initialize_display_outputs() { std::cerr << "Initialized display output '" << output->name << "'... " << std::endl; output->is_active = true; - active_display_output = output; - return true; + active_display_outputs.push_back(output); } } } + if (active_display_outputs.size()) return true; + std::cerr << "Unable to find a usable display output." << std::endl; return true; // false; } bool shutdown_display_outputs() { - if (active_display_output) { return active_display_output->shutdown(); } - return false; + bool ret = true; + for (auto output : active_display_outputs) ret = output->shutdown(); + return ret; } } // namespace conky diff --git a/src/display-output.hh b/src/display-output.hh index 8dc6cfcf..2c8cc5a1 100644 --- a/src/display-output.hh +++ b/src/display-output.hh @@ -85,10 +85,9 @@ class display_output_base { }; /* - * The selected and active display output. - * XXX: do we want to support multiple outputs??? + * The selected and active display outputs. */ -extern display_output_base *active_display_output; +extern std::vector active_display_outputs; /* * Use this to declare a display output that has been disabled during