2018-10-05 01:48:59 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
2018-10-18 22:51:08 +00:00
|
|
|
* Copyright (C) 2018 François Revol et al.
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
|
|
|
* Copyright (c) 2005-2019 Brenden Matthews, Philip Kovacs, et. al.
|
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
2018-10-05 01:48:59 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "display-output.hh"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <unordered_map>
|
2018-10-05 03:08:34 +00:00
|
|
|
#include <vector>
|
2018-10-05 01:48:59 +00:00
|
|
|
|
|
|
|
namespace conky {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef std::unordered_map<std::string, display_output_base *>
|
|
|
|
display_outputs_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We cannot construct this object statically, because order of object
|
|
|
|
* construction in different modules is not defined, so register_source could be
|
|
|
|
* called before this object is constructed. Therefore, we create it on the
|
|
|
|
* first call to register_source.
|
|
|
|
*/
|
|
|
|
display_outputs_t *display_outputs;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The selected and active display output.
|
|
|
|
*/
|
2018-10-05 03:08:34 +00:00
|
|
|
std::vector<display_output_base *> active_display_outputs;
|
2018-10-05 01:48:59 +00:00
|
|
|
|
2018-10-19 01:14:30 +00:00
|
|
|
/*
|
|
|
|
* the list of the only current output, when inside draw_text,
|
|
|
|
* else we iterate over each active outputs.
|
|
|
|
*/
|
|
|
|
std::vector<conky::display_output_base *> current_display_outputs;
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
namespace priv {
|
|
|
|
void do_register_display_output(const std::string &name,
|
|
|
|
display_output_base *output) {
|
|
|
|
struct display_output_constructor {
|
|
|
|
display_output_constructor() { display_outputs = new display_outputs_t(); }
|
|
|
|
~display_output_constructor() {
|
|
|
|
delete display_outputs;
|
|
|
|
display_outputs = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static display_output_constructor constructor;
|
|
|
|
|
|
|
|
bool inserted = display_outputs->insert({name, output}).second;
|
|
|
|
if (!inserted) {
|
|
|
|
throw std::logic_error("Display output with name '" + name +
|
|
|
|
"' already registered");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace priv
|
|
|
|
|
|
|
|
display_output_base::display_output_base(const std::string &name_)
|
2018-10-05 03:51:56 +00:00
|
|
|
: name(name_), is_active(false), is_graphical(false), priority(-1) {
|
2018-10-05 01:48:59 +00:00
|
|
|
priv::do_register_display_output(name, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
disabled_display_output::disabled_display_output(const std::string &name,
|
|
|
|
const std::string &define)
|
|
|
|
: display_output_base(name) {
|
|
|
|
priority = -2;
|
|
|
|
// XXX some generic way of reporting errors? NORM_ERR?
|
|
|
|
std::cerr << "Support for display output '" << name
|
|
|
|
<< "' has been disabled during compilation. Please recompile with '"
|
|
|
|
<< define << "'" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initialize_display_outputs() {
|
|
|
|
std::vector<display_output_base *> outputs;
|
|
|
|
outputs.reserve(display_outputs->size());
|
|
|
|
|
|
|
|
for (auto &output : *display_outputs) { outputs.push_back(output.second); }
|
|
|
|
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);
|
|
|
|
|
|
|
|
for (auto output : outputs) {
|
2018-10-05 03:08:34 +00:00
|
|
|
if (output->priority < 0) continue;
|
2018-10-05 01:48:59 +00:00
|
|
|
std::cerr << "Testing display output '" << output->name << "'... "
|
|
|
|
<< std::endl;
|
|
|
|
if (output->detect()) {
|
|
|
|
std::cerr << "Detected display output '" << output->name << "'... "
|
|
|
|
<< std::endl;
|
|
|
|
if (output->initialize()) {
|
|
|
|
std::cerr << "Initialized display output '" << output->name << "'... "
|
|
|
|
<< std::endl;
|
|
|
|
output->is_active = true;
|
2018-10-05 03:08:34 +00:00
|
|
|
active_display_outputs.push_back(output);
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 03:08:34 +00:00
|
|
|
if (active_display_outputs.size()) return true;
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
std::cerr << "Unable to find a usable display output." << std::endl;
|
|
|
|
return true; // false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shutdown_display_outputs() {
|
2018-10-05 03:08:34 +00:00
|
|
|
bool ret = true;
|
|
|
|
for (auto output : active_display_outputs) ret = output->shutdown();
|
|
|
|
return ret;
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace conky
|