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
|
2024-02-22 13:33:31 +00:00
|
|
|
* Copyright (c) 2005-2024 Brenden Matthews, Philip Kovacs, et. al.
|
2018-10-18 22:51:08 +00:00
|
|
|
* (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"
|
2020-12-26 17:49:30 +00:00
|
|
|
#include "logging.h"
|
2018-10-05 01:48:59 +00:00
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
#include <algorithm>
|
2018-10-05 01:48:59 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-10-26 00:09:35 +00:00
|
|
|
// HACK: force the linker to link all the objects in with test enabled
|
|
|
|
extern void init_console_output();
|
|
|
|
extern void init_ncurses_output();
|
|
|
|
extern void init_file_output();
|
|
|
|
extern void init_http_output();
|
|
|
|
extern void init_x11_output();
|
2022-11-28 19:23:23 +00:00
|
|
|
extern void init_wayland_output();
|
2021-10-26 00:09:35 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
/*
|
|
|
|
* 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?
|
2020-12-26 17:49:30 +00:00
|
|
|
DBGP(
|
|
|
|
"Support for display output '%s' has been disabled during compilation. "
|
|
|
|
"Please recompile with '%s'",
|
|
|
|
name.c_str(), define.c_str());
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool initialize_display_outputs() {
|
2021-10-26 00:09:35 +00:00
|
|
|
init_console_output();
|
|
|
|
init_ncurses_output();
|
|
|
|
init_file_output();
|
|
|
|
init_http_output();
|
|
|
|
init_x11_output();
|
2022-11-28 19:23:23 +00:00
|
|
|
init_wayland_output();
|
2021-10-26 00:09:35 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
std::vector<display_output_base *> outputs;
|
|
|
|
outputs.reserve(display_outputs->size());
|
|
|
|
|
|
|
|
for (auto &output : *display_outputs) { outputs.push_back(output.second); }
|
2018-10-18 23:14:03 +00:00
|
|
|
// Sort display outputs by descending priority, to try graphical ones first.
|
2018-10-05 01:48:59 +00:00
|
|
|
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);
|
|
|
|
|
2018-10-18 23:14:03 +00:00
|
|
|
int graphical_count = 0;
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
for (auto output : outputs) {
|
2018-10-05 03:08:34 +00:00
|
|
|
if (output->priority < 0) continue;
|
2020-12-26 17:49:30 +00:00
|
|
|
DBGP2("Testing display output '%s'... ", output->name.c_str());
|
2018-10-05 01:48:59 +00:00
|
|
|
if (output->detect()) {
|
2020-12-26 17:49:30 +00:00
|
|
|
DBGP2("Detected display output '%s'... ", output->name.c_str());
|
2018-10-18 23:14:03 +00:00
|
|
|
|
|
|
|
if (graphical_count && output->graphical()) continue;
|
|
|
|
|
|
|
|
// X11 init needs to draw, so we must add it to the list first.
|
|
|
|
active_display_outputs.push_back(output);
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
if (output->initialize()) {
|
2020-12-26 17:49:30 +00:00
|
|
|
DBGP("Initialized display output '%s'... ", output->name.c_str());
|
2018-10-18 23:14:03 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
output->is_active = true;
|
2018-10-18 23:14:03 +00:00
|
|
|
if (output->graphical()) graphical_count++;
|
|
|
|
/*
|
|
|
|
* We only support a single graphical display for now.
|
|
|
|
* More than one text display (ncurses + http, ...) should be ok.
|
|
|
|
*/
|
|
|
|
// if (graphical_count)
|
|
|
|
// return true;
|
|
|
|
} else {
|
|
|
|
// failed, so remove from list
|
|
|
|
active_display_outputs.pop_back();
|
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;
|
2023-03-31 16:52:48 +00:00
|
|
|
return true;
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool shutdown_display_outputs() {
|
2018-10-05 03:08:34 +00:00
|
|
|
bool ret = true;
|
2018-10-18 23:14:03 +00:00
|
|
|
for (auto output : active_display_outputs) {
|
|
|
|
output->is_active = false;
|
|
|
|
ret = output->shutdown();
|
|
|
|
}
|
|
|
|
active_display_outputs.clear();
|
2018-10-05 03:08:34 +00:00
|
|
|
return ret;
|
2018-10-05 01:48:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace conky
|