feat: add gauge and stacked bar graph type
This commit is contained in:
+14
-5
@@ -11,11 +11,12 @@
|
||||
|
||||
namespace waybar {
|
||||
|
||||
enum class GraphType { LINE, BAR, GAUGE };
|
||||
|
||||
class AGraph : public AModule {
|
||||
public:
|
||||
AGraph(const Json::Value &, const std::string &, const std::string &,
|
||||
uint16_t interval = 0, bool enable_click = false,
|
||||
bool enable_scroll = false);
|
||||
AGraph(const Json::Value &, const std::string &, const std::string &, uint16_t interval = 0,
|
||||
bool enable_click = false, bool enable_scroll = false);
|
||||
virtual ~AGraph() = default;
|
||||
auto update() -> void override;
|
||||
|
||||
@@ -24,6 +25,7 @@ class AGraph : public AModule {
|
||||
std::deque<int> values_;
|
||||
uint16_t datapoints_ = 20;
|
||||
uint16_t y_offset_ = 0;
|
||||
GraphType graph_type_ = GraphType::LINE;
|
||||
|
||||
void addValue(const int n);
|
||||
|
||||
@@ -37,14 +39,21 @@ class AGraph : public AModule {
|
||||
|
||||
private:
|
||||
void drawFilledArea(const Cairo::RefPtr<Cairo::Context> &cr,
|
||||
const std::vector<std::pair<double, double>> &points,
|
||||
double height, const Gdk::RGBA &bg_color);
|
||||
const std::vector<std::pair<double, double>> &points, double height,
|
||||
const Gdk::RGBA &bg_color);
|
||||
|
||||
void drawLine(const Cairo::RefPtr<Cairo::Context> &cr,
|
||||
const std::vector<std::pair<double, double>> &points, const Gdk::RGBA &fg_color);
|
||||
|
||||
void drawPath(const Cairo::RefPtr<Cairo::Context> &cr,
|
||||
const std::vector<std::pair<double, double>> &points);
|
||||
|
||||
void drawBars(const Cairo::RefPtr<Cairo::Context> &cr,
|
||||
double width, double height, int current_value,
|
||||
const Gdk::RGBA &fg_color);
|
||||
|
||||
void drawGauge(const Cairo::RefPtr<Cairo::Context> &cr, double width, double height,
|
||||
int current_value, const Gdk::RGBA &fg_color);
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <csignal>
|
||||
#include <string>
|
||||
|
||||
#include "AGraph.hpp"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class CustomGraph : public AGraph {
|
||||
public:
|
||||
CustomGraph(const std::string&, const std::string&, const Json::Value&, const std::string&);
|
||||
virtual ~CustomGraph();
|
||||
auto update() -> void override;
|
||||
void refresh(int /*signal*/) override;
|
||||
|
||||
private:
|
||||
void delayWorker();
|
||||
void continuousWorker();
|
||||
void waitingWorker();
|
||||
void parseOutputRaw();
|
||||
void parseOutputJson();
|
||||
void handleEvent();
|
||||
bool handleScroll(GdkEventScroll* e) override;
|
||||
bool handleToggle(GdkEventButton* const& e) override;
|
||||
|
||||
const std::string name_;
|
||||
const std::string output_name_;
|
||||
std::string text_;
|
||||
std::string id_;
|
||||
std::string alt_;
|
||||
std::string tooltip_;
|
||||
const bool tooltip_format_enabled_;
|
||||
std::vector<std::string> class_;
|
||||
int percentage_;
|
||||
FILE* fp_;
|
||||
int pid_;
|
||||
util::command::res output_;
|
||||
util::JsonParser parser_;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules
|
||||
Reference in New Issue
Block a user