1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 10:35:10 +00:00

Initial ncurses display-output

Some leftovers still, but it still works.
This commit is contained in:
François Revol 2018-10-05 05:46:50 +02:00
parent a4f9474de1
commit f30263c2fc
4 changed files with 106 additions and 41 deletions

View File

@ -171,10 +171,6 @@ static conky::simple_config_setting<bool> disable_auto_reload(
/* two strings for internal use */ /* two strings for internal use */
static char *tmpstring1, *tmpstring2; static char *tmpstring1, *tmpstring2;
#ifdef BUILD_NCURSES
extern WINDOW *ncurses_window;
#endif
enum spacer_state { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER }; enum spacer_state { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
template <> template <>
conky::lua_traits<spacer_state>::Map conky::lua_traits<spacer_state>::map = { conky::lua_traits<spacer_state>::Map conky::lua_traits<spacer_state>::map = {
@ -1059,9 +1055,8 @@ static inline void set_foreground_color(long c) {
XSetForeground(display, window.gc, current_color); XSetForeground(display, window.gc, current_color);
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
#ifdef BUILD_NCURSES for (auto output : conky::active_display_outputs)
if (out_to_ncurses.get(*state)) { attron(COLOR_PAIR(c)); } output->set_foreground_color(c);
#endif /* BUILD_NCURSES */
UNUSED(c); UNUSED(c);
} }
@ -1095,9 +1090,6 @@ static void draw_string(const char *s) {
if (draw_mode == FG && (append_fpointer != nullptr)) { if (draw_mode == FG && (append_fpointer != nullptr)) {
fprintf(append_fpointer, "%s\n", s); fprintf(append_fpointer, "%s\n", s);
} }
#ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state) && draw_mode == FG) { printw("%s", s); }
#endif /* BUILD_NCURSES */
if (conky::active_display_outputs.size() && draw_mode == FG) if (conky::active_display_outputs.size() && draw_mode == FG)
for (auto output : conky::active_display_outputs) for (auto output : conky::active_display_outputs)
output->draw_string(s, width_of_s); output->draw_string(s, width_of_s);
@ -1602,14 +1594,9 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
// make sure shades are 1 pixel to the right of the text // make sure shades are 1 pixel to the right of the text
if (draw_mode == BG) { cur_x++; } if (draw_mode == BG) { cur_x++; }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
cur_x = static_cast<int>(current->arg); cur_x = static_cast<int>(current->arg);
if (out_to_ncurses.get(*state)) { for (auto output : conky::active_display_outputs)
int x, y; output->gotox(cur_x);
getyx(ncurses_window, y, x);
move(y, cur_x);
}
#endif /* BUILD_NCURSES */
} }
break; break;
} }
@ -1632,9 +1619,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) {
cur_y += cur_y_add; cur_y += cur_y_add;
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
draw_string(s); draw_string(s);
#ifdef BUILD_NCURSES for (auto output : display_outputs()) output->line_inner_done();
if (out_to_ncurses.get(*state)) { printw("\n"); }
#endif /* BUILD_NCURSES */
#ifdef BUILD_X11 #ifdef BUILD_X11
if (out_to_x.get(*state)) { cur_y += font_descent(); } if (out_to_x.get(*state)) { cur_y += font_descent(); }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
@ -1647,11 +1632,10 @@ static int draw_line(char *s, int special_index) {
return draw_each_line_inner(s, special_index, -1); return draw_each_line_inner(s, special_index, -1);
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (out_to_ncurses.get(*state)) { if (display_output() && display_output()->draw_line_inner_required()) {
return draw_each_line_inner(s, special_index, -1); return draw_each_line_inner(s, special_index, -1);
} }
#endif /* BUILD_NCURSES */
draw_string(s); draw_string(s);
UNUSED(special_index); UNUSED(special_index);
return 0; return 0;
@ -1688,10 +1672,6 @@ static void draw_text() {
} }
setup_fonts(); setup_fonts();
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(COLOR_WHITE));
#endif /* BUILD_NCURSES */
for_each_line(text_buffer, draw_line); for_each_line(text_buffer, draw_line);
for (auto output : conky::active_display_outputs) output->end_draw_text(); for (auto output : conky::active_display_outputs) output->end_draw_text();
} }
@ -2207,12 +2187,7 @@ void main_loop() {
nanosleep(&req, &rem); nanosleep(&req, &rem);
update_text(); update_text();
draw_stuff(); draw_stuff();
#ifdef BUILD_NCURSES for (auto output : conky::active_display_outputs) output->flush();
if (out_to_ncurses.get(*state)) {
refresh();
clear();
}
#endif
#ifdef BUILD_X11 #ifdef BUILD_X11
} }
#endif /* BUILD_X11 */ #endif /* BUILD_X11 */
@ -2237,12 +2212,7 @@ void main_loop() {
NORM_ERR("received SIGUSR2. refreshing."); NORM_ERR("received SIGUSR2. refreshing.");
update_text(); update_text();
draw_stuff(); draw_stuff();
#ifdef BUILD_NCURSES for (auto output : conky::active_display_outputs) output->flush();
if (out_to_ncurses.get(*state)) {
refresh();
clear();
}
#endif
} }
if (g_sigterm_pending != 0) { if (g_sigterm_pending != 0) {

View File

@ -29,6 +29,13 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <unordered_map> #include <unordered_map>
#ifdef BUILD_NCURSES
#include <ncurses.h>
#endif
#ifdef BUILD_NCURSES
extern WINDOW *ncurses_window;
#endif
namespace conky { namespace conky {
namespace { namespace {
@ -42,7 +49,9 @@ conky::disabled_display_output ncurses_output_disabled("ncurses",
} // namespace } // namespace
namespace priv {} // namespace priv // namespace priv {
//} // namespace priv
#ifdef BUILD_NCURSES #ifdef BUILD_NCURSES
@ -60,10 +69,69 @@ bool display_output_ncurses::detect() {
return false; return false;
} }
bool display_output_ncurses::initialize() { return false; } bool display_output_ncurses::initialize() {
return (ncurses_window != nullptr);
}
bool display_output_ncurses::shutdown() { return false; } bool display_output_ncurses::shutdown() { return false; }
bool display_output_ncurses::set_foreground_color(long c) {
attron(COLOR_PAIR(c));
return true;
}
bool display_output_ncurses::begin_draw_text() {
init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(COLOR_WHITE));
return true;
}
bool display_output_ncurses::end_draw_text() { return true; }
bool display_output_ncurses::draw_string(const char *s, int w) {
printw("%s", s);
return true;
}
void display_output_ncurses::line_inner_done() { printw("\n"); }
int display_output_ncurses::getx() {
int x, y;
getyx(ncurses_window, y, x);
return x;
}
int display_output_ncurses::gety() {
int x, y;
getyx(ncurses_window, y, x);
return y;
}
bool display_output_ncurses::gotox(int x) {
int y, old_x;
getyx(ncurses_window, y, old_x);
move(y, x);
return true;
}
bool display_output_ncurses::gotoy(int y) {
int x, old_y;
getyx(ncurses_window, old_y, x);
move(y, x);
return true;
}
bool display_output_ncurses::gotoxy(int x, int y) {
move(y, x);
return true;
}
bool display_output_ncurses::flush() {
refresh();
clear();
return true;
}
#endif /* BUILD_NCURSES */ #endif /* BUILD_NCURSES */
} // namespace conky } // namespace conky

View File

@ -47,6 +47,22 @@ class display_output_ncurses : public display_output_console {
virtual bool initialize(); virtual bool initialize();
virtual bool shutdown(); virtual bool shutdown();
// drawing primitives
virtual bool set_foreground_color(long c);
virtual bool begin_draw_text();
virtual bool end_draw_text();
virtual bool draw_string(const char *s, int w);
virtual void line_inner_done();
virtual int getx();
virtual int gety();
virtual bool gotox(int x);
virtual bool gotoy(int y);
virtual bool gotoxy(int x, int y);
virtual bool flush();
// ncurses-specific // ncurses-specific
}; };

View File

@ -74,9 +74,20 @@ class display_output_base {
virtual bool shutdown() { return false; }; virtual bool shutdown() { return false; };
// drawing primitives // drawing primitives
virtual bool set_foreground_color(long c) { return false; }
virtual bool begin_draw_text() { return false; }; virtual bool begin_draw_text() { return false; };
virtual bool end_draw_text() { return false; }; virtual bool end_draw_text() { return false; };
virtual bool draw_string(const char *s, int w) { return false; }; virtual bool draw_string(const char *s, int w) { return false; };
virtual void line_inner_done() {}
virtual int getx() { return 0; };
virtual int gety() { return 0; };
virtual bool gotox(int x) { return false; };
virtual bool gotoy(int y) { return false; };
virtual bool gotoxy(int x, int y) { return false; };
virtual bool flush() { return false; };
friend bool conky::initialize_display_outputs(); friend bool conky::initialize_display_outputs();
friend bool conky::shutdown_display_outputs(); friend bool conky::shutdown_display_outputs();