Style code (#25)

This commit is contained in:
Alex
2018-08-16 14:29:41 +02:00
committed by GitHub
parent 3fdc50163d
commit 6635548d3e
31 changed files with 761 additions and 664 deletions

View File

@ -3,10 +3,12 @@
#include <gtkmm.h>
namespace waybar {
class IModule {
public:
virtual ~IModule() {}
virtual auto update() -> void = 0;
virtual operator Gtk::Widget &() = 0;
};
class IModule {
public:
virtual ~IModule() {}
virtual auto update() -> void = 0;
virtual operator Gtk::Widget &() = 0;
};
}

View File

@ -7,44 +7,47 @@
namespace waybar {
struct Client;
class Client;
struct Bar {
Bar(Client& client, std::unique_ptr<struct wl_output *>&& output);
class Bar {
public:
Bar(Client&, std::unique_ptr<struct wl_output *>&&);
Bar(const Bar&) = delete;
auto setWidth(uint32_t) -> void;
auto toggle() -> void;
Client& client;
Gtk::Window window;
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layerSurface;
struct zwlr_layer_surface_v1 *layer_surface;
std::unique_ptr<struct wl_output *> output;
bool visible = true;
std::string outputName;
auto setWidth(uint32_t) -> void;
auto toggle() -> void;
bool visible = true;
private:
static void _handleLogicalPosition(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t x, int32_t y);
static void _handleLogicalSize(void *data,
struct zxdg_output_v1 *zxdg_output_v1, int32_t width, int32_t height);
static void _handleDone(void *data, struct zxdg_output_v1 *zxdg_output_v1);
static void _handleName(void *data, struct zxdg_output_v1 *xdg_output,
const char *name);
static void _handleDescription(void *data,
struct zxdg_output_v1 *zxdg_output_v1, const char *description);
static void _layerSurfaceHandleConfigure(void *data,
struct zwlr_layer_surface_v1 *surface, uint32_t serial, uint32_t width,
uint32_t height);
static void _layerSurfaceHandleClosed(void *data,
struct zwlr_layer_surface_v1 *surface);
auto _setupConfig() -> void;
auto _setupWidgets() -> void;
auto _setupCss() -> void;
uint32_t _width = 0;
uint32_t _height = 30;
Json::Value _config;
Glib::RefPtr<Gtk::StyleContext> _styleContext;
Glib::RefPtr<Gtk::CssProvider> _cssProvider;
struct zxdg_output_v1 *_xdgOutput;
};
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
int32_t);
static void handleLogicalSize(void *, struct zxdg_output_v1 *, int32_t,
int32_t);
static void handleDone(void *, struct zxdg_output_v1 *);
static void handleName(void *, struct zxdg_output_v1 *, const char *);
static void handleDescription(void *, struct zxdg_output_v1 *,
const char *);
static void layerSurfaceHandleConfigure(void *,
struct zwlr_layer_surface_v1 *, uint32_t, uint32_t, uint32_t);
static void layerSurfaceHandleClosed(void *,
struct zwlr_layer_surface_v1 *);
auto setupConfig() -> void;
auto setupWidgets() -> void;
auto setupCss() -> void;
uint32_t width_ = 0;
uint32_t height_ = 30;
Json::Value config_;
Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
struct zxdg_output_v1 *xdg_output_;
};
}

View File

@ -14,28 +14,30 @@
namespace waybar {
struct Client {
std::string cssFile;
std::string configFile;
class Client {
public:
Client(int argc, char *argv[]);
int main(int argc, char *argv[]);
Gtk::Main gtk_main;
std::string css_file;
std::string config_file;
Glib::RefPtr<Gdk::Display> gdk_display;
struct wl_display *wlDisplay = nullptr;
struct wl_display *wl_display = nullptr;
struct wl_registry *registry = nullptr;
struct zwlr_layer_shell_v1 *layerShell = nullptr;
struct zxdg_output_manager_v1 *xdgOutputManager = nullptr;
struct zwlr_layer_shell_v1 *layer_shell = nullptr;
struct zxdg_output_manager_v1 *xdg_output_manager = nullptr;
struct wl_seat *seat = nullptr;
std::vector<std::unique_ptr<Bar>> bars;
Client(int argc, char* argv[]);
void bind_interfaces();
auto setup_css();
int main(int argc, char* argv[]);
private:
static void _handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version);
static void _handle_global_remove(void *data,
struct wl_registry *registry, uint32_t name);
};
private:
void bindInterfaces();
auto setupCss();
static void handleGlobal(void *data, struct wl_registry *registry,
uint32_t name, const char *interface, uint32_t version);
static void handleGlobalRemove(void *data,
struct wl_registry *registry, uint32_t name);
};
}

View File

@ -13,13 +13,13 @@
namespace waybar {
class Factory {
public:
Factory(Bar &bar, Json::Value config);
IModule *makeModule(std::string name);
private:
Bar &_bar;
Json::Value _config;
};
class Factory {
public:
Factory(Bar &bar, Json::Value config);
IModule *makeModule(const std::string &name);
private:
Bar &_bar;
Json::Value _config;
};
}

View File

@ -12,20 +12,22 @@
namespace waybar::modules {
namespace fs = std::filesystem;
namespace fs = std::filesystem;
class Battery : public IModule {
public:
Battery(Json::Value config);
auto update() -> void;
operator Gtk::Widget&();
private:
std::string _getIcon(uint16_t percentage);
static inline const fs::path _data_dir = "/sys/class/power_supply/";
std::vector<fs::path> _batteries;
util::SleeperThread _thread;
Gtk::Label _label;
Json::Value _config;
};
class Battery : public IModule {
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

@ -8,15 +8,15 @@
namespace waybar::modules {
class Clock : public IModule {
public:
Clock(Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label _label;
waybar::util::SleeperThread _thread;
Json::Value _config;
};
class Clock : public IModule {
public:
Clock(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -8,15 +8,15 @@
namespace waybar::modules {
class Cpu : public IModule {
public:
Cpu(Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label _label;
waybar::util::SleeperThread _thread;
Json::Value _config;
};
class Cpu : public IModule {
public:
Cpu(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -7,16 +7,16 @@
namespace waybar::modules {
class Custom : public IModule {
public:
Custom(std::string name, Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label _label;
waybar::util::SleeperThread _thread;
const std::string _name;
Json::Value _config;
};
class Custom : public IModule {
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

@ -8,15 +8,15 @@
namespace waybar::modules {
class Memory : public IModule {
public:
Memory(Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label _label;
waybar::util::SleeperThread _thread;
Json::Value _config;
};
class Memory : public IModule {
public:
Memory(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
};
}

View File

@ -12,24 +12,26 @@
namespace waybar::modules {
class Network : public IModule {
public:
Network(Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
void _parseEssid(struct nlattr **bss);
void _parseSignal(struct nlattr **bss);
bool _associatedOrJoined(struct nlattr **bss);
static int _scanCb(struct nl_msg *msg, void *data);
auto _getInfo() -> void;
Gtk::Label _label;
waybar::util::SleeperThread _thread;
Json::Value _config;
std::size_t _ifid;
std::string _essid;
int _signalStrengthdBm;
int _signalStrength;
};
class Network : public IModule {
public:
Network(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
static int scanCb(struct nl_msg*, void*);
void parseEssid(struct nlattr**);
void parseSignal(struct nlattr**);
bool associatedOrJoined(struct nlattr**);
auto getInfo() -> void;
Gtk::Label label_;
waybar::util::SleeperThread thread_;
Json::Value config_;
std::size_t ifid_;
std::string essid_;
int signal_strength_dbm_;
uint16_t signal_strength_;
};
}

View File

@ -8,29 +8,29 @@
namespace waybar::modules {
class Pulseaudio : public IModule {
public:
Pulseaudio(Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
std::string _getIcon(uint16_t percentage);
static void _subscribeCb(pa_context *context,
pa_subscription_event_type_t type, uint32_t idx, void *data);
static void _contextStateCb(pa_context *c, void *data);
static void _sinkInfoCb(pa_context *context, const pa_sink_info *i,
int eol, void *data);
static void _serverInfoCb(pa_context *context, const pa_server_info *i,
void *data);
Gtk::Label _label;
Json::Value _config;
pa_threaded_mainloop *_mainloop;
pa_mainloop_api *_mainloop_api;
pa_context *_context;
uint32_t _sinkIdx{0};
int _volume;
bool _muted;
std::string _desc;
};
class Pulseaudio : public IModule {
public:
Pulseaudio(Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
static void subscribeCb(pa_context*, pa_subscription_event_type_t,
uint32_t, void*);
static void contextStateCb(pa_context*, void*);
static void sinkInfoCb(pa_context*, const pa_sink_info*, int, void*);
static void serverInfoCb(pa_context*, const pa_server_info*, void*);
std::string getIcon(uint16_t);
Gtk::Label label_;
Json::Value config_;
pa_threaded_mainloop* mainloop_;
pa_mainloop_api* mainloop_api_;
pa_context* context_;
uint32_t sink_idx_{0};
uint16_t volume_;
bool muted_;
std::string desc_;
};
}

View File

@ -16,17 +16,17 @@ struct ipc_response {
/**
* Gets the path to the IPC socket from sway.
*/
std::string get_socketpath(void);
std::string getSocketPath(void);
/**
* Opens the sway socket.
*/
int ipc_open_socket(std::string socket_path);
int ipcOpenSocket(const std::string &socketPath);
/**
* Issues a single IPC command and returns the buffer. len will be updated with
* the length of the buffer returned from sway.
*/
std::string ipc_single_command(int socketfd, uint32_t type, const char *payload, uint32_t *len);
std::string ipcSingleCommand(int socketfd, uint32_t type, const char *payload, uint32_t *len);
/**
* Receives a single IPC response and returns an ipc_response.
*/
struct ipc_response ipc_recv_response(int socketfd);
struct ipc_response ipcRecvResponse(int socketfd);

View File

@ -9,22 +9,23 @@
namespace waybar::modules::sway {
class Window : public IModule {
public:
Window(waybar::Bar &bar, Json::Value config);
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 _ipcEventfd;
std::string _window;
};
class Window : public IModule {
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_;
std::string window_;
};
}

View File

@ -9,28 +9,29 @@
namespace waybar::modules::sway {
class Workspaces : public IModule {
public:
Workspaces(waybar::Bar &bar, Json::Value config);
auto update() -> void;
operator Gtk::Widget &();
private:
void _addWorkspace(Json::Value node);
std::string _getIcon(std::string name);
bool _handleScroll(GdkEventScroll *e);
int _getPrevWorkspace();
int _getNextWorkspace();
Bar &_bar;
Json::Value _config;
waybar::util::SleeperThread _thread;
Gtk::Box _box;
util::JsonParser _parser;
std::mutex _mutex;
bool _scrolling;
std::unordered_map<int, Gtk::Button> _buttons;
Json::Value _workspaces;
int _ipcfd;
int _ipcEventfd;
};
class Workspaces : public IModule {
public:
Workspaces(waybar::Bar&, Json::Value);
auto update() -> void;
operator Gtk::Widget &();
private:
void addWorkspace(Json::Value);
std::string getIcon(std::string);
bool handleScroll(GdkEventScroll*);
int getPrevWorkspace();
int getNextWorkspace();
Bar& bar_;
Json::Value config_;
waybar::util::SleeperThread thread_;
Gtk::Box box_;
util::JsonParser parser_;
std::mutex mutex_;
bool scrolling_;
std::unordered_map<int, Gtk::Button> buttons_;
Json::Value workspaces_;
int ipcfd_;
int ipc_eventfd_;
};
}