From 5c389ecdb5a4aa06e897b720464ef2f64508f981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 19 Oct 2018 03:14:30 +0200 Subject: [PATCH] add display accessors we want to be able to access either all outputs, or the currently selected one (if any, else return the top one, which ought to be the GUI one if we have one). --- src/display-output.cc | 6 ++++++ src/display-output.hh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/display-output.cc b/src/display-output.cc index 45f03c36..e9c3eb1f 100644 --- a/src/display-output.cc +++ b/src/display-output.cc @@ -54,6 +54,12 @@ display_outputs_t *display_outputs; */ std::vector active_display_outputs; +/* + * the list of the only current output, when inside draw_text, + * else we iterate over each active outputs. + */ +std::vector current_display_outputs; + namespace priv { void do_register_display_output(const std::string &name, display_output_base *output) { diff --git a/src/display-output.hh b/src/display-output.hh index 359bba8c..aa277ba8 100644 --- a/src/display-output.hh +++ b/src/display-output.hh @@ -130,6 +130,12 @@ class display_output_base { */ extern std::vector active_display_outputs; +/* + * the list of the only current output, when inside draw_text, + * else we iterate over each active outputs. + */ +extern std::vector current_display_outputs; + /* * Use this to declare a display output that has been disabled during * compilation. We can then print a nice error message telling the used which @@ -143,4 +149,29 @@ class disabled_display_output : public display_output_base { } // namespace conky +// XXX: move to namespace? + +static inline std::vector &display_outputs() { + if (conky::current_display_outputs.size()) + return conky::current_display_outputs; + return conky::active_display_outputs; +} + +static inline conky::display_output_base *display_output() { + if (conky::current_display_outputs.size()) + return conky::current_display_outputs[0]; + // XXX; not really what intended yet... + return conky::active_display_outputs[0]; + // return nullptr; +} + +static inline void unset_display_output() { + conky::current_display_outputs.clear(); +} + +static inline void set_display_output(conky::display_output_base *output) { + conky::current_display_outputs.clear(); + conky::current_display_outputs.push_back(output); +} + #endif /* DISPLAY_OUTPUT_HH */