Skip to content

Commit

Permalink
Organization and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerryliu committed May 28, 2017
1 parent 413ae96 commit 3d7a352
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Window::Window() : m_vbox(Gtk::ORIENTATION_VERTICAL) {
tree = std::make_unique<Tree>(all_readings, device_names);

// Start a new worker thread:
m_Dispatcher.connect(sigc::mem_fun(*this, &Window::update_all));
m_Dispatcher.connect(sigc::mem_fun(*this, &Window::update_all_components));

set_border_width(1);
set_default_size(500, 600);
Expand Down Expand Up @@ -87,7 +87,8 @@ Window::Window() : m_vbox(Gtk::ORIENTATION_VERTICAL) {

Window::~Window() { on_button_quit(); }

void Window::update_vals() {
void Window::update_device_vals() {
// Refresh values every second
while (1) {
if (stop_work) {
break;
Expand All @@ -102,7 +103,8 @@ void Window::update_vals() {
}
}

void Window::update_all() {
void Window::update_all_components() {
// Update the values on the tree and graphs
tree->update_tree_view(all_readings);
for (auto &page : m_notebook_graphs) {
for (auto &graph : page) {
Expand All @@ -114,6 +116,8 @@ void Window::update_all() {
}

vector<Gdk::RGBA> Window::gen_colors(unsigned int size) {
// This could probably go somewhere else, but the colors are shared between
// the graphs and legends...
vector<Gdk::RGBA> rainbow;
static const vector<string> m_colors = {
"green", "red", "blue", "orange", "violet", "brown",
Expand Down
22 changes: 12 additions & 10 deletions src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,33 @@ class Window : public Gtk::Window {

private:
const std::string file_path = "/sys/class/hwmon/";
bool stop_work = false;

// Computer Devices:
vector<Device> devices;
vector<vector<vector<Device::sensor_reading>>> all_readings;
vector<string> device_names;

// Summary tree
Gtk::ScrolledWindow m_scrolledwindow;
std::unique_ptr<Tree> tree;
// Notebook:
Gtk::Notebook m_notebook;
vector<Gtk::Box> m_Notebook_Boxes;
vector<vector<std::unique_ptr<Graph>>> m_notebook_graphs;
vector<vector<std::unique_ptr<Legend>>> m_notebook_legends;
vector<vector<vector<Gdk::RGBA>>> m_colors;

// Async value updates to prevent stalls:
Glib::Dispatcher m_Dispatcher;
bool stop_work = false;
std::unique_ptr<std::thread> m_WorkerThread =
std::make_unique<std::thread>([this] { update_vals(); });

std::unique_ptr<Tree> tree;
std::make_unique<std::thread>([this] { update_device_vals(); });
// Other important stuffs:
Gtk::Box m_vbox;
Gtk::HeaderBar m_headerbar;
Gtk::StackSwitcher m_stackswitcher;
Gtk::Stack m_stack;
Gtk::Notebook m_notebook;
Gtk::ScrolledWindow m_scrolledwindow;

void update_vals();
void update_all();
void update_device_vals();
void update_all_components();
vector<Gdk::RGBA> gen_colors(unsigned int size);
void on_button_quit();
};
Expand Down

0 comments on commit 3d7a352

Please sign in to comment.