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.
|
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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DISPLAY_OUTPUT_HH
|
|
|
|
#define DISPLAY_OUTPUT_HH
|
|
|
|
|
2018-10-18 22:54:55 +00:00
|
|
|
#include <string.h>
|
2018-10-05 01:48:59 +00:00
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
2018-10-18 23:14:03 +00:00
|
|
|
#include <vector>
|
2018-10-05 01:48:59 +00:00
|
|
|
|
|
|
|
#include "luamm.hh"
|
|
|
|
|
|
|
|
namespace conky {
|
|
|
|
|
|
|
|
bool initialize_display_outputs();
|
|
|
|
|
|
|
|
bool shutdown_display_outputs();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A base class for all display outputs.
|
|
|
|
* API consists of two functions:
|
|
|
|
* - get_number should return numeric representation of the data (if available).
|
|
|
|
* This can then be used when drawing graphs, bars, ... The default
|
|
|
|
* implementation returns NaN.
|
|
|
|
* - get_text should return textual representation of the data. This is used
|
|
|
|
* when simple displaying the value of the data source. The default
|
|
|
|
* implementation converts get_number() to a string, but you can override to
|
|
|
|
* return anything (e.g. add units)
|
|
|
|
*/
|
|
|
|
class display_output_base {
|
|
|
|
private:
|
|
|
|
// copying is a REALLY bad idea
|
|
|
|
display_output_base(const display_output_base &) = delete;
|
|
|
|
display_output_base &operator=(const display_output_base &) = delete;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const std::string name;
|
|
|
|
bool is_active;
|
2018-10-05 03:51:56 +00:00
|
|
|
bool is_graphical;
|
2018-10-05 01:48:59 +00:00
|
|
|
int priority;
|
|
|
|
|
|
|
|
explicit display_output_base(const std::string &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
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual bool detect() { return false; }
|
2018-10-05 01:48:59 +00:00
|
|
|
// connect to DISPLAY and other stuff
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual bool initialize() { return false; }
|
|
|
|
virtual bool shutdown() { return false; }
|
|
|
|
|
|
|
|
virtual bool graphical() { return is_graphical; };
|
|
|
|
virtual bool draw_line_inner_required() { return is_graphical; }
|
|
|
|
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual bool main_loop_wait(double /*t*/) { return false; }
|
2018-10-18 22:54:55 +00:00
|
|
|
|
|
|
|
virtual void sigterm_cleanup() {}
|
|
|
|
virtual void cleanup() {}
|
2018-10-05 01:48:59 +00:00
|
|
|
|
2018-10-05 02:47:27 +00:00
|
|
|
// drawing primitives
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void set_foreground_color(long /*c*/) {}
|
2018-10-05 03:46:50 +00:00
|
|
|
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual int calc_text_width(const char *s) { return strlen(s); }
|
2018-10-05 03:46:50 +00:00
|
|
|
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual void begin_draw_text() {}
|
|
|
|
virtual void end_draw_text() {}
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void draw_string(const char * /*s*/, int /*w*/) {}
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual void line_inner_done() {}
|
2018-10-05 03:46:50 +00:00
|
|
|
|
2018-10-18 22:54:55 +00:00
|
|
|
// GUI interface
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void draw_string_at(int /*x*/, int /*y*/, const char * /*s*/,
|
|
|
|
int /*w*/) {}
|
2018-10-18 22:54:55 +00:00
|
|
|
// X11 lookalikes
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void set_line_style(int /*w*/, bool /*solid*/) {}
|
|
|
|
virtual void set_dashes(char * /*s*/) {}
|
|
|
|
virtual void draw_line(int /*x1*/, int /*y1*/, int /*x2*/, int /*y2*/) {}
|
|
|
|
virtual void draw_rect(int /*x*/, int /*y*/, int /*w*/, int /*h*/) {}
|
|
|
|
virtual void fill_rect(int /*x*/, int /*y*/, int /*w*/, int /*h*/) {}
|
|
|
|
virtual void draw_arc(int /*x*/, int /*y*/, int /*w*/, int /*h*/, int /*a1*/,
|
|
|
|
int /*a2*/) {}
|
|
|
|
virtual void move_win(int /*x*/, int /*y*/) {}
|
2018-10-18 23:14:03 +00:00
|
|
|
virtual int dpi_scale(int value) { return value; }
|
2018-10-18 22:54:55 +00:00
|
|
|
|
|
|
|
virtual void begin_draw_stuff() {}
|
|
|
|
virtual void end_draw_stuff() {}
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void clear_text(int /*exposures*/) {}
|
2020-12-26 01:37:29 +00:00
|
|
|
|
|
|
|
// font stuff
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual int font_height(unsigned int) { return 0; }
|
|
|
|
virtual int font_ascent(unsigned int) { return 0; }
|
|
|
|
virtual int font_descent(unsigned int) { return 0; }
|
2020-12-26 01:37:29 +00:00
|
|
|
virtual void setup_fonts(void) {}
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void set_font(unsigned int) {}
|
|
|
|
virtual void free_fonts(bool /*utf8*/) {}
|
|
|
|
virtual void load_fonts(bool /*utf8*/) {}
|
2018-10-18 22:54:55 +00:00
|
|
|
|
|
|
|
// tty interface
|
|
|
|
virtual int getx() { return 0; }
|
|
|
|
virtual int gety() { return 0; }
|
2021-10-25 18:17:19 +00:00
|
|
|
virtual void gotox(int /*x*/) {}
|
|
|
|
virtual void gotoy(int /*y*/) {}
|
|
|
|
virtual void gotoxy(int /*x*/, int /*y*/) {}
|
2018-10-18 22:54:55 +00:00
|
|
|
|
|
|
|
virtual void flush() {}
|
2018-10-05 02:47:27 +00:00
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
friend bool conky::initialize_display_outputs();
|
|
|
|
friend bool conky::shutdown_display_outputs();
|
|
|
|
|
|
|
|
protected:
|
2018-10-18 22:54:55 +00:00
|
|
|
virtual bool active() { return is_active; }
|
2018-10-05 01:48:59 +00:00
|
|
|
};
|
|
|
|
|
2018-10-05 02:47:27 +00:00
|
|
|
/*
|
2018-10-05 03:08:34 +00:00
|
|
|
* The selected and active display outputs.
|
2018-10-05 02:47:27 +00:00
|
|
|
*/
|
2018-10-05 03:08:34 +00:00
|
|
|
extern std::vector<display_output_base *> active_display_outputs;
|
2018-10-05 02:47:27 +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.
|
|
|
|
*/
|
|
|
|
extern std::vector<conky::display_output_base *> current_display_outputs;
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* setting to enable.
|
|
|
|
*/
|
|
|
|
class disabled_display_output : public display_output_base {
|
|
|
|
public:
|
|
|
|
const std::string define;
|
|
|
|
disabled_display_output(const std::string &name, const std::string &define);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace conky
|
|
|
|
|
2018-10-19 01:14:30 +00:00
|
|
|
// XXX: move to namespace?
|
|
|
|
|
|
|
|
static inline std::vector<conky::display_output_base *> &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...
|
2022-09-04 12:11:41 +00:00
|
|
|
if (conky::active_display_outputs.size())
|
|
|
|
return conky::active_display_outputs[0];
|
|
|
|
return nullptr;
|
2018-10-19 01:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
#endif /* DISPLAY_OUTPUT_HH */
|