Skip to content

Commit

Permalink
WIP: move X11 stuff from conky.cc to display-x11
Browse files Browse the repository at this point in the history
Still not complete, but seems to work.

A lot of variables and calls had to be made non-static.
  • Loading branch information
mmuman committed Oct 7, 2018
1 parent d7b3e26 commit 233a875
Show file tree
Hide file tree
Showing 10 changed files with 1,050 additions and 171 deletions.
440 changes: 298 additions & 142 deletions src/conky.cc

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/conky.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ extern conky::range_config_setting<double> update_interval;
extern conky::range_config_setting<double> update_interval_on_battery;
double active_update_interval();

extern conky::simple_config_setting<bool> show_graph_scale;
extern conky::simple_config_setting<bool> show_graph_range;
extern conky::simple_config_setting<int> gap_x;
extern conky::simple_config_setting<int> gap_y;
extern conky::simple_config_setting<bool> draw_borders;
extern conky::simple_config_setting<bool> draw_graph_borders;
extern conky::range_config_setting<char> stippled_borders;
extern conky::simple_config_setting<bool> draw_shades;
extern conky::simple_config_setting<bool> draw_outline;

void set_current_text_color(long colour);
long get_current_text_color(void);
Expand All @@ -327,6 +335,9 @@ void extract_object_args_to_sub(struct text_object *, const char *);

void generate_text_internal(char *, int, struct text_object);

void update_text_area();
void draw_stuff();

int percent_print(char *, int, unsigned);
void human_readable(long long, char *, int);

Expand Down
3 changes: 2 additions & 1 deletion src/display-ncurses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ bool display_output_ncurses::detect() {
}

bool display_output_ncurses::initialize() {
return (ncurses_window != nullptr);
is_active = ncurses_window != nullptr;
return is_active;
}

bool display_output_ncurses::shutdown() {
Expand Down
1 change: 1 addition & 0 deletions src/display-ncurses.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class display_output_ncurses : public display_output_console {
// connect to DISPLAY and other stuff
virtual bool initialize();
virtual bool shutdown();
virtual bool draw_line_inner_required() { return true; };

// drawing primitives
virtual bool set_foreground_color(long c);
Expand Down
27 changes: 25 additions & 2 deletions src/display-output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ bool initialize_display_outputs() {
for (auto &output : *display_outputs) {
outputs.push_back(output.second);
}
// Sort display outputs by descending priority, to try graphical ones first.
sort(outputs.begin(), outputs.end(), &display_output_base::priority_compare);

int graphical_count = 0;

for (auto output : outputs) {
if (output->priority < 0)
Expand All @@ -104,11 +106,29 @@ bool initialize_display_outputs() {
if (output->detect()) {
std::cerr << "Detected display output '" << output->name
<< "'... " << std::endl;

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);

if (output->initialize()) {
std::cerr << "Initialized display output '" << output->name
<< "'... " << std::endl;

output->is_active = true;
active_display_outputs.push_back(output);
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();
}
}
}
Expand All @@ -121,8 +141,11 @@ bool initialize_display_outputs() {

bool shutdown_display_outputs() {
bool ret = true;
for (auto output : active_display_outputs)
for (auto output : active_display_outputs) {
output->is_active = false;
ret = output->shutdown();
}
active_display_outputs.clear();
return ret;
}

Expand Down
30 changes: 29 additions & 1 deletion src/display-output.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <limits>
#include <string>
#include <type_traits>
#include <string.h>

#include "luamm.hh"

Expand Down Expand Up @@ -73,13 +74,41 @@ class display_output_base {
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; };

virtual bool main_loop_wait(double t) { return false; };

virtual bool sigterm_cleanup() { return false; };
virtual bool cleanup() { return false; };

// drawing primitives
virtual bool set_foreground_color(long c) { return false; }

virtual int calc_text_width(const char *s) { return strlen(s); };

virtual bool begin_draw_text() { return false; };
virtual bool end_draw_text() { return false; };
virtual bool draw_string(const char *s, int w) { return false; };

// GUI interface
virtual bool draw_string_at(int x, int y, const char *s, int w) { return false; };
// X11 lookalikes
virtual bool set_line_style(int w, bool solid) { return false; };
virtual bool set_dashes(char *s) { return false; };
virtual bool draw_line(int x1, int y1, int x2, int y2) { return false; };
virtual bool draw_rect(int x, int y, int w, int h) { return false; };
virtual bool fill_rect(int x, int y, int w, int h) { return false; };
virtual bool draw_arc(int x, int y, int w, int h, int a1, int a2) { return false; };
virtual bool move_win(int x, int y) { return false; };

virtual bool begin_draw_stuff() { return false; };
virtual bool end_draw_stuff() { return false; };
virtual bool swap_buffers() { return false; };
virtual bool clear_text(int exposures) { return false; };
virtual bool load_fonts(bool utf8) { return false; };

// tty interface
virtual int getx() { return 0; };
virtual int gety() { return 0; };
virtual bool gotox(int x) { return false; };
Expand All @@ -94,7 +123,6 @@ class display_output_base {

protected:
virtual bool active() { return is_active; };
virtual bool graphical() { return is_graphical; };
};

/*
Expand Down
Loading

0 comments on commit 233a875

Please sign in to comment.