diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp new file mode 100644 index 00000000..367dfec5 --- /dev/null +++ b/include/modules/memory.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include +#include "util/chrono.hpp" + +namespace waybar::modules { + + class Memory { + public: + Memory(); + operator Gtk::Widget &(); + private: + Gtk::Label _label; + waybar::util::SleeperThread _thread; + }; + +} diff --git a/resources/style.css b/resources/style.css index 518f32a5..b42a7e0b 100644 --- a/resources/style.css +++ b/resources/style.css @@ -32,14 +32,22 @@ window { background-color: #64727D; padding: 0 10px; margin: 0 5px; - border-bottom: 2px solid transparent; } .battery-status { padding: 0 10px; - border-bottom: 2px solid transparent; + margin: 0 5px; + background-color: #ffffff; + color: black; } .battery-status.battery-charging { + color: white; background-color: #26A65B; } + +.memory-widget { + padding: 0 10px; + margin: 0 5px; + background: #9b59b6; +} diff --git a/src/bar.cpp b/src/bar.cpp index 333ee3b3..79227c4c 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -7,6 +7,7 @@ #include "modules/clock.hpp" #include "modules/workspaces.hpp" #include "modules/battery.hpp" +#include "modules/memory.hpp" static void handle_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, @@ -147,9 +148,11 @@ auto waybar::Bar::setup_widgets() -> void auto &clock = *new waybar::modules::Clock(); auto &workspace_selector = *new waybar::modules::WorkspaceSelector(*this); auto &battery = *new waybar::modules::Battery(); + auto &memory = *new waybar::modules::Memory(); left.pack_start(workspace_selector, false, true, 0); // center.pack_start(workspace_selector, true, false, 10); right.pack_end(clock, false, false, 0); right.pack_end(battery, false, false, 0); + right.pack_end(memory, false, false, 0); } diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp new file mode 100644 index 00000000..da9f4396 --- /dev/null +++ b/src/modules/memory.cpp @@ -0,0 +1,20 @@ +#include "modules/memory.hpp" +#include + +waybar::modules::Memory::Memory() +{ + _label.get_style_context()->add_class("memory-widget"); + _thread = [this] { + struct sysinfo info; + if (!sysinfo(&info)) { + double available = (double)info.freeram / (double)info.totalram; + std::cout << available << std::endl; + _label.set_text(fmt::format("{:.{}f}% ", available * 100, 1)); + } + _thread.sleep_for(chrono::seconds(30)); + }; +}; + +waybar::modules::Memory::operator Gtk::Widget &() { + return _label; +}