mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(workspaces): icons
This commit is contained in:
parent
767d9dd5b4
commit
e3e099f836
@ -11,16 +11,18 @@ namespace waybar::modules {
|
|||||||
|
|
||||||
class Workspaces : public IModule {
|
class Workspaces : public IModule {
|
||||||
public:
|
public:
|
||||||
Workspaces(waybar::Bar &bar);
|
Workspaces(waybar::Bar &bar, Json::Value config);
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget &();
|
operator Gtk::Widget &();
|
||||||
private:
|
private:
|
||||||
void _addWorkspace(Json::Value node);
|
void _addWorkspace(Json::Value node);
|
||||||
|
std::string _getIcon(std::string name);
|
||||||
Json::Value _getWorkspaces(const std::string data);
|
Json::Value _getWorkspaces(const std::string data);
|
||||||
bool _handleScroll(GdkEventScroll *e);
|
bool _handleScroll(GdkEventScroll *e);
|
||||||
int _getPrevWorkspace();
|
int _getPrevWorkspace();
|
||||||
int _getNextWorkspace();
|
int _getNextWorkspace();
|
||||||
Bar &_bar;
|
Bar &_bar;
|
||||||
|
Json::Value _config;
|
||||||
waybar::util::SleeperThread _thread;
|
waybar::util::SleeperThread _thread;
|
||||||
Gtk::Box _box;
|
Gtk::Box _box;
|
||||||
util::JsonParser _parser;
|
util::JsonParser _parser;
|
||||||
|
@ -7,6 +7,15 @@
|
|||||||
"modules-left": ["workspaces", "custom/spotify"],
|
"modules-left": ["workspaces", "custom/spotify"],
|
||||||
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock"],
|
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock"],
|
||||||
// Modules configuration
|
// Modules configuration
|
||||||
|
"workspaces": {
|
||||||
|
"format-icons": {
|
||||||
|
"1": "",
|
||||||
|
"2": "",
|
||||||
|
"3": "",
|
||||||
|
"4": "",
|
||||||
|
"5": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
"cpu": {
|
"cpu": {
|
||||||
"format": "{}% "
|
"format": "{}% "
|
||||||
},
|
},
|
||||||
|
@ -11,33 +11,37 @@ window {
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspaces button {
|
#workspaces button {
|
||||||
padding: 0 5px;
|
padding: 0 8px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: white;
|
color: white;
|
||||||
border-bottom: 3px solid transparent;
|
border-bottom: 3px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.workspaces button.current {
|
#workspaces button label {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#workspaces button.current {
|
||||||
background: #64727D;
|
background: #64727D;
|
||||||
border-bottom: 3px solid white;
|
border-bottom: 3px solid white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clock, .battery, .cpu, .memory, .network, .pulseaudio, .custom-spotify {
|
#clock, #battery, #cpu, #memory, #network, #pulseaudio, #custom-spotify {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin: 0 5px;
|
margin: 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.clock {
|
#clock {
|
||||||
background-color: #64727D;
|
background-color: #64727D;
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery {
|
#battery {
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery.charging {
|
#battery.charging {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: #26A65B;
|
background-color: #26A65B;
|
||||||
}
|
}
|
||||||
@ -49,7 +53,7 @@ window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.battery.warning {
|
#battery.warning {
|
||||||
background: #f53c3c;
|
background: #f53c3c;
|
||||||
color: white;
|
color: white;
|
||||||
animation-name: blink;
|
animation-name: blink;
|
||||||
@ -59,30 +63,30 @@ window {
|
|||||||
animation-direction: alternate;
|
animation-direction: alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cpu {
|
#cpu {
|
||||||
background: #2ecc71;
|
background: #2ecc71;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.memory {
|
#memory {
|
||||||
background: #9b59b6;
|
background: #9b59b6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.network {
|
#network {
|
||||||
background: #2980b9;
|
background: #2980b9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pulseaudio {
|
#pulseaudio {
|
||||||
background: #f1c40f;
|
background: #f1c40f;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pulseaudio.muted {
|
#pulseaudio.muted {
|
||||||
background: #90b1b1;
|
background: #90b1b1;
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-spotify {
|
#custom-spotify {
|
||||||
background: #66cc99;
|
background: #66cc99;
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ waybar::IModule *waybar::Factory::makeModule(std::string name)
|
|||||||
if (name == "battery")
|
if (name == "battery")
|
||||||
return new waybar::modules::Battery(_config[name]);
|
return new waybar::modules::Battery(_config[name]);
|
||||||
if (name == "workspaces")
|
if (name == "workspaces")
|
||||||
return new waybar::modules::Workspaces(_bar);
|
return new waybar::modules::Workspaces(_bar, _config[name]);
|
||||||
if (name == "memory")
|
if (name == "memory")
|
||||||
return new waybar::modules::Memory(_config[name]);
|
return new waybar::modules::Memory(_config[name]);
|
||||||
if (name == "cpu")
|
if (name == "cpu")
|
||||||
|
@ -23,7 +23,7 @@ waybar::modules::Battery::Battery(Json::Value config)
|
|||||||
inotify_add_watch(fd, (bat / "uevent").c_str(), IN_ACCESS);
|
inotify_add_watch(fd, (bat / "uevent").c_str(), IN_ACCESS);
|
||||||
// Trigger first value
|
// Trigger first value
|
||||||
update();
|
update();
|
||||||
_label.get_style_context()->add_class("battery");
|
_label.set_name("battery");
|
||||||
_thread = [this, fd] {
|
_thread = [this, fd] {
|
||||||
struct inotify_event event;
|
struct inotify_event event;
|
||||||
int nbytes = read(fd, &event, sizeof(event));
|
int nbytes = read(fd, &event, sizeof(event));
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
waybar::modules::Clock::Clock(Json::Value config)
|
waybar::modules::Clock::Clock(Json::Value config)
|
||||||
: _config(config)
|
: _config(config)
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("clock");
|
_label.set_name("clock");
|
||||||
_thread = [this] {
|
_thread = [this] {
|
||||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
|
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Clock::update));
|
||||||
auto now = waybar::chrono::clock::now();
|
auto now = waybar::chrono::clock::now();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
waybar::modules::Cpu::Cpu(Json::Value config)
|
waybar::modules::Cpu::Cpu(Json::Value config)
|
||||||
: _config(config)
|
: _config(config)
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("cpu");
|
_label.set_name("cpu");
|
||||||
int interval = _config["interval"] ? _config["inveral"].asInt() : 10;
|
int interval = _config["interval"] ? _config["inveral"].asInt() : 10;
|
||||||
_thread = [this, interval] {
|
_thread = [this, interval] {
|
||||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));
|
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Cpu::update));
|
||||||
|
@ -34,10 +34,10 @@ auto waybar::modules::Custom::update() -> void
|
|||||||
|
|
||||||
// Hide label if output is empty
|
// Hide label if output is empty
|
||||||
if (output.empty()) {
|
if (output.empty()) {
|
||||||
_label.get_style_context()->remove_class("custom-" + _name);
|
_label.set_name("");
|
||||||
_label.hide();
|
_label.hide();
|
||||||
} else {
|
} else {
|
||||||
_label.get_style_context()->add_class("custom-" + _name);
|
_label.set_name("custom-" + _name);
|
||||||
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
||||||
_label.set_text(fmt::format(format, output));
|
_label.set_text(fmt::format(format, output));
|
||||||
_label.show();
|
_label.show();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
waybar::modules::Memory::Memory(Json::Value config)
|
waybar::modules::Memory::Memory(Json::Value config)
|
||||||
: _config(config)
|
: _config(config)
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("memory");
|
_label.set_name("memory");
|
||||||
int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
|
int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
|
||||||
_thread = [this, interval] {
|
_thread = [this, interval] {
|
||||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Memory::update));
|
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Memory::update));
|
||||||
|
@ -5,7 +5,7 @@ waybar::modules::Network::Network(Json::Value config)
|
|||||||
{
|
{
|
||||||
if (_ifid == 0)
|
if (_ifid == 0)
|
||||||
throw std::runtime_error("Can't found network interface");
|
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;
|
int interval = _config["interval"] ? _config["inveral"].asInt() : 30;
|
||||||
_thread = [this, interval] {
|
_thread = [this, interval] {
|
||||||
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));
|
Glib::signal_idle().connect_once(sigc::mem_fun(*this, &Network::update));
|
||||||
|
@ -4,7 +4,7 @@ waybar::modules::Pulseaudio::Pulseaudio(Json::Value config)
|
|||||||
: _config(config), _mainloop(nullptr), _mainloop_api(nullptr),
|
: _config(config), _mainloop(nullptr), _mainloop_api(nullptr),
|
||||||
_context(nullptr), _sinkIdx(0), _volume(0), _muted(false)
|
_context(nullptr), _sinkIdx(0), _volume(0), _muted(false)
|
||||||
{
|
{
|
||||||
_label.get_style_context()->add_class("pulseaudio");
|
_label.set_name("pulseaudio");
|
||||||
_mainloop = pa_threaded_mainloop_new();
|
_mainloop = pa_threaded_mainloop_new();
|
||||||
if (!_mainloop)
|
if (!_mainloop)
|
||||||
throw std::runtime_error("pa_mainloop_new() failed.");
|
throw std::runtime_error("pa_mainloop_new() failed.");
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "modules/workspaces.hpp"
|
#include "modules/workspaces.hpp"
|
||||||
#include "ipc/client.hpp"
|
#include "ipc/client.hpp"
|
||||||
|
|
||||||
waybar::modules::Workspaces::Workspaces(Bar &bar)
|
waybar::modules::Workspaces::Workspaces(Bar &bar, Json::Value config)
|
||||||
: _bar(bar), _scrolling(false)
|
: _bar(bar), _config(config), _scrolling(false)
|
||||||
{
|
{
|
||||||
_box.get_style_context()->add_class("workspaces");
|
_box.set_name("workspaces");
|
||||||
std::string socketPath = get_socketpath();
|
std::string socketPath = get_socketpath();
|
||||||
_ipcfd = ipc_open_socket(socketPath);
|
_ipcfd = ipc_open_socket(socketPath);
|
||||||
_ipcEventfd = 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)
|
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;
|
auto &button = pair.first->second;
|
||||||
_box.pack_start(button, false, false, 0);
|
_box.pack_start(button, false, false, 0);
|
||||||
button.set_relief(Gtk::RELIEF_NONE);
|
button.set_relief(Gtk::RELIEF_NONE);
|
||||||
@ -90,6 +91,15 @@ void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
|
|||||||
button.show();
|
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)
|
bool waybar::modules::Workspaces::_handleScroll(GdkEventScroll *e)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_mutex);
|
std::lock_guard<std::mutex> lock(_mutex);
|
||||||
|
Loading…
Reference in New Issue
Block a user