feat(modules): generic label module to allow max-length on all labels

This commit is contained in:
Alexis
2018-08-18 11:43:48 +02:00
parent c128562284
commit b1fd4d7b82
19 changed files with 76 additions and 99 deletions

19
include/ALabel.hpp Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#include <json/json.h>
#include "IModule.hpp"
namespace waybar {
class ALabel : public IModule {
public:
ALabel(Json::Value);
virtual ~ALabel();
virtual auto update() -> void;
virtual operator Gtk::Widget &();
protected:
Gtk::Label label_;
Json::Value config_;
};
}

View File

@ -1,6 +1,5 @@
#pragma once
#include <json/json.h>
#include <filesystem>
#include <fstream>
#include <iostream>
@ -8,24 +7,21 @@
#include <sys/inotify.h>
#include <algorithm>
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
namespace fs = std::filesystem;
class Battery : public IModule {
class Battery : public ALabel {
public:
Battery(Json::Value);
auto update() -> void;
operator Gtk::Widget&();
private:
std::string getIcon(uint16_t percentage);
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
Gtk::Label label_;
Json::Value config_;
util::SleeperThread thread_;
std::vector<fs::path> batteries_;
};

View File

@ -1,22 +1,18 @@
#pragma once
#include <json/json.h>
#include <fmt/format.h>
#include "fmt/time.h"
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Clock : public IModule {
class Clock : public ALabel {
public:
Clock(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -1,22 +1,18 @@
#pragma once
#include <json/json.h>
#include <fmt/format.h>
#include <sys/sysinfo.h>
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Cpu : public IModule {
class Cpu : public ALabel {
public:
Cpu(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -1,22 +1,18 @@
#pragma once
#include <json/json.h>
#include <fmt/format.h>
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Custom : public IModule {
class Custom : public ALabel {
public:
Custom(const std::string&, Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
const std::string name_;
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -1,22 +1,18 @@
#pragma once
#include <json/json.h>
#include <fmt/format.h>
#include <sys/sysinfo.h>
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Memory : public IModule {
class Memory : public ALabel {
public:
Memory(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -5,18 +5,16 @@
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <linux/nl80211.h>
#include <json/json.h>
#include <fmt/format.h>
#include "util/chrono.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Network : public IModule {
class Network : public ALabel {
public:
Network(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
static uint64_t netlinkRequest(int, void*, uint32_t, uint32_t groups = 0);
static uint64_t netlinkResponse(int, void*, uint32_t, uint32_t groups = 0);
@ -29,10 +27,7 @@ class Network : public IModule {
bool associatedOrJoined(struct nlattr**);
auto getInfo() -> void;
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
int ifid_;
sa_family_t family_;
int sock_fd_;

View File

@ -1,18 +1,16 @@
#pragma once
#include <pulse/pulseaudio.h>
#include <json/json.h>
#include <fmt/format.h>
#include <algorithm>
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules {
class Pulseaudio : public IModule {
class Pulseaudio : public ALabel {
public:
Pulseaudio(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
static void subscribeCb(pa_context*, pa_subscription_event_type_t,
uint32_t, void*);
@ -22,8 +20,6 @@ class Pulseaudio : public IModule {
std::string getIcon(uint16_t);
Gtk::Label label_;
Json::Value config_;
pa_threaded_mainloop* mainloop_;
pa_mainloop_api* mainloop_api_;
pa_context* context_;

View File

@ -5,23 +5,20 @@
#include "client.hpp"
#include "util/chrono.hpp"
#include "util/json.hpp"
#include "IModule.hpp"
#include "ALabel.hpp"
namespace waybar::modules::sway {
class Window : public IModule {
class Window : public ALabel {
public:
Window(waybar::Bar&, Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
std::string getFocusedNode(Json::Value nodes);
void getFocusedWindow();
Bar& bar_;
Json::Value config_;
waybar::util::SleeperThread thread_;
Gtk::Label label_;
util::JsonParser parser_;
int ipcfd_;
int ipc_eventfd_;