feat(workspaces): icons

This commit is contained in:
Alexis
2018-08-15 14:48:08 +02:00
parent 767d9dd5b4
commit e3e099f836
12 changed files with 53 additions and 28 deletions

View File

@ -10,7 +10,7 @@ waybar::IModule *waybar::Factory::makeModule(std::string name)
if (name == "battery")
return new waybar::modules::Battery(_config[name]);
if (name == "workspaces")
return new waybar::modules::Workspaces(_bar);
return new waybar::modules::Workspaces(_bar, _config[name]);
if (name == "memory")
return new waybar::modules::Memory(_config[name]);
if (name == "cpu")

View File

@ -23,7 +23,7 @@ waybar::modules::Battery::Battery(Json::Value config)
inotify_add_watch(fd, (bat / "uevent").c_str(), IN_ACCESS);
// Trigger first value
update();
_label.get_style_context()->add_class("battery");
_label.set_name("battery");
_thread = [this, fd] {
struct inotify_event event;
int nbytes = read(fd, &event, sizeof(event));

View File

@ -3,7 +3,7 @@
waybar::modules::Clock::Clock(Json::Value config)
: _config(config)
{
_label.get_style_context()->add_class("clock");
_label.set_name("clock");
_thread = [this] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
auto now = waybar::chrono::clock::now();

View File

@ -3,7 +3,7 @@
waybar::modules::Cpu::Cpu(Json::Value config)
: _config(config)
{
_label.get_style_context()->add_class("cpu");
_label.set_name("cpu");
int interval = _config["interval"] ? _config["inveral"].asInt() : 10;
_thread = [this, interval] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));

View File

@ -34,10 +34,10 @@ auto waybar::modules::Custom::update() -> void
// Hide label if output is empty
if (output.empty()) {
_label.get_style_context()->remove_class("custom-" + _name);
_label.set_name("");
_label.hide();
} else {
_label.get_style_context()->add_class("custom-" + _name);
_label.set_name("custom-" + _name);
auto format = _config["format"] ? _config["format"].asString() : "{}";
_label.set_text(fmt::format(format, output));
_label.show();

View File

@ -3,7 +3,7 @@
waybar::modules::Memory::Memory(Json::Value config)
: _config(config)
{
_label.get_style_context()->add_class("memory");
_label.set_name("memory");
int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
_thread = [this, interval] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Memory::update));

View File

@ -5,7 +5,7 @@ waybar::modules::Network::Network(Json::Value config)
{
if (_ifid == 0)
throw std::runtime_error("Can't found network interface");
_label.get_style_context()->add_class("network");
_label.set_name("network");
int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
_thread = [this, interval] {
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));

View File

@ -4,7 +4,7 @@ waybar::modules::Pulseaudio::Pulseaudio(Json::Value config)
: _config(config), _mainloop(nullptr), _mainloop_api(nullptr),
_context(nullptr), _sinkIdx(0), _volume(0), _muted(false)
{
_label.get_style_context()->add_class("pulseaudio");
_label.set_name("pulseaudio");
_mainloop = pa_threaded_mainloop_new();
if (!_mainloop)
throw std::runtime_error("pa_mainloop_new() failed.");

View File

@ -1,10 +1,10 @@
#include "modules/workspaces.hpp"
#include "ipc/client.hpp"
waybar::modules::Workspaces::Workspaces(Bar &bar)
: _bar(bar), _scrolling(false)
waybar::modules::Workspaces::Workspaces(Bar &bar, Json::Value config)
: _bar(bar), _config(config), _scrolling(false)
{
_box.get_style_context()->add_class("workspaces");
_box.set_name("workspaces");
std::string socketPath = get_socketpath();
_ipcfd = ipc_open_socket(socketPath);
_ipcEventfd = ipc_open_socket(socketPath);
@ -67,7 +67,8 @@ auto waybar::modules::Workspaces::update() -> void
void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
{
auto pair = _buttons.emplace(node["num"].asInt(), node["name"].asString());
auto pair = _buttons.emplace(node["num"].asInt(),
_getIcon(node["name"].asString()));
auto &button = pair.first->second;
_box.pack_start(button, false, false, 0);
button.set_relief(Gtk::RELIEF_NONE);
@ -90,6 +91,15 @@ void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
button.show();
}
std::string waybar::modules::Workspaces::_getIcon(std::string name)
{
if (_config["format-icons"][name])
return _config["format-icons"][name].asString();
if (_config["format-icons"]["default"])
return _config["format-icons"]["default"].asString();
return name;
}
bool waybar::modules::Workspaces::_handleScroll(GdkEventScroll *e)
{
std::lock_guard<std::mutex> lock(_mutex);