mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat: basic config file
This commit is contained in:
@ -4,17 +4,22 @@ waybar::modules::Clock::Clock()
|
||||
{
|
||||
_label.get_style_context()->add_class("clock");
|
||||
_thread = [this] {
|
||||
update();
|
||||
auto now = waybar::chrono::clock::now();
|
||||
auto t = std::time(nullptr);
|
||||
auto localtime = std::localtime(&t);
|
||||
_label.set_text(
|
||||
fmt::format("{:02}:{:02}", localtime->tm_hour, localtime->tm_min));
|
||||
auto timeout =
|
||||
std::chrono::floor<std::chrono::minutes>(now + std::chrono::minutes(1));
|
||||
_thread.sleep_until(timeout);
|
||||
};
|
||||
};
|
||||
|
||||
auto waybar::modules::Clock::update() -> void
|
||||
{
|
||||
auto t = std::time(nullptr);
|
||||
auto localtime = std::localtime(&t);
|
||||
_label.set_text(
|
||||
fmt::format("{:02}:{:02}", localtime->tm_hour, localtime->tm_min));
|
||||
}
|
||||
|
||||
waybar::modules::Clock::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
}
|
||||
|
@ -5,16 +5,21 @@ waybar::modules::Cpu::Cpu()
|
||||
{
|
||||
_label.get_style_context()->add_class("cpu");
|
||||
_thread = [this] {
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
||||
_label.set_text(fmt::format("{:.{}f}% ",
|
||||
info.loads[0] * f_load * 100 / get_nprocs(), 0));
|
||||
}
|
||||
update();
|
||||
_thread.sleep_for(chrono::seconds(10));
|
||||
};
|
||||
};
|
||||
|
||||
auto waybar::modules::Cpu::update() -> void
|
||||
{
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
float f_load = 1.f / (1 << SI_LOAD_SHIFT);
|
||||
_label.set_text(fmt::format("{:.{}f}% ",
|
||||
info.loads[0] * f_load * 100 / get_nprocs(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
waybar::modules::Cpu::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
}
|
||||
|
@ -5,15 +5,20 @@ waybar::modules::Memory::Memory()
|
||||
{
|
||||
_label.get_style_context()->add_class("memory");
|
||||
_thread = [this] {
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
double available = (double)info.freeram / (double)info.totalram;
|
||||
_label.set_text(fmt::format("{:.{}f}% ", available * 100, 0));
|
||||
}
|
||||
update();
|
||||
_thread.sleep_for(chrono::seconds(30));
|
||||
};
|
||||
};
|
||||
|
||||
auto waybar::modules::Memory::update() -> void
|
||||
{
|
||||
struct sysinfo info;
|
||||
if (!sysinfo(&info)) {
|
||||
double available = (double)info.freeram / (double)info.totalram;
|
||||
_label.set_text(fmt::format("{:.{}f}% ", available * 100, 0));
|
||||
}
|
||||
}
|
||||
|
||||
waybar::modules::Memory::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "ipc/client.hpp"
|
||||
|
||||
static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
|
||||
auto o = reinterpret_cast<waybar::modules::WorkspaceSelector *>(data);
|
||||
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
|
||||
if (o->thread) {
|
||||
delete o->thread;
|
||||
o->thread = nullptr;
|
||||
@ -10,7 +10,7 @@ static void handle_idle(void *data, struct org_kde_kwin_idle_timeout *timer) {
|
||||
}
|
||||
|
||||
static void handle_resume(void *data, struct org_kde_kwin_idle_timeout *timer) {
|
||||
auto o = reinterpret_cast<waybar::modules::WorkspaceSelector *>(data);
|
||||
auto o = reinterpret_cast<waybar::modules::Workspaces *>(data);
|
||||
if (!o->thread) {
|
||||
o->updateThread();
|
||||
}
|
||||
@ -21,7 +21,7 @@ static const struct org_kde_kwin_idle_timeout_listener idle_timer_listener = {
|
||||
.resumed = handle_resume,
|
||||
};
|
||||
|
||||
waybar::modules::WorkspaceSelector::WorkspaceSelector(Bar &bar)
|
||||
waybar::modules::Workspaces::Workspaces(Bar &bar)
|
||||
: thread(nullptr), _bar(bar), _box(Gtk::manage(new Gtk::Box))
|
||||
{
|
||||
_box->get_style_context()->add_class("workspaces");
|
||||
@ -39,7 +39,7 @@ waybar::modules::WorkspaceSelector::WorkspaceSelector(Bar &bar)
|
||||
updateThread();
|
||||
}
|
||||
|
||||
void waybar::modules::WorkspaceSelector::updateThread()
|
||||
void waybar::modules::Workspaces::updateThread()
|
||||
{
|
||||
thread = new waybar::util::SleeperThread([this] {
|
||||
update();
|
||||
@ -47,7 +47,7 @@ void waybar::modules::WorkspaceSelector::updateThread()
|
||||
});
|
||||
}
|
||||
|
||||
auto waybar::modules::WorkspaceSelector::update() -> void
|
||||
auto waybar::modules::Workspaces::update() -> void
|
||||
{
|
||||
Json::Value workspaces = _getWorkspaces();
|
||||
for (auto it = _buttons.begin(); it != _buttons.end(); ++it) {
|
||||
@ -74,7 +74,7 @@ auto waybar::modules::WorkspaceSelector::update() -> void
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::WorkspaceSelector::_addWorkspace(Json::Value node)
|
||||
void waybar::modules::Workspaces::_addWorkspace(Json::Value node)
|
||||
{
|
||||
auto pair = _buttons.emplace(node["num"].asInt(), node["name"].asString());
|
||||
auto &button = pair.first->second;
|
||||
@ -92,7 +92,7 @@ void waybar::modules::WorkspaceSelector::_addWorkspace(Json::Value node)
|
||||
button.show();
|
||||
}
|
||||
|
||||
Json::Value waybar::modules::WorkspaceSelector::_getWorkspaces()
|
||||
Json::Value waybar::modules::Workspaces::_getWorkspaces()
|
||||
{
|
||||
uint32_t len = 0;
|
||||
Json::Value root;
|
||||
@ -110,6 +110,6 @@ Json::Value waybar::modules::WorkspaceSelector::_getWorkspaces()
|
||||
return root;
|
||||
}
|
||||
|
||||
waybar::modules::WorkspaceSelector::operator Gtk::Widget &() {
|
||||
waybar::modules::Workspaces::operator Gtk::Widget &() {
|
||||
return *_box;
|
||||
}
|
||||
|
Reference in New Issue
Block a user