diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..3d99a247 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "atomic": "cpp" + } +} \ No newline at end of file diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp new file mode 100644 index 00000000..adf21b1b --- /dev/null +++ b/include/modules/cpu.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include +#include "util/chrono.hpp" + +namespace waybar::modules { + + class Cpu { + public: + Cpu(); + operator Gtk::Widget &(); + private: + Gtk::Label _label; + waybar::util::SleeperThread _thread; + }; + +} diff --git a/resources/style.css b/resources/style.css index b42a7e0b..7346452a 100644 --- a/resources/style.css +++ b/resources/style.css @@ -11,11 +11,6 @@ window { color: white; } -.focused-window-title { - padding: 0px 10px; - min-height: 0px; -} - .workspace-selector button { padding: 0 5px; background: transparent; @@ -28,15 +23,16 @@ window { border-bottom: 3px solid white; } -.clock-widget { - background-color: #64727D; +.clock-widget, .battery-status, .cpu-widget, .memory-widget { padding: 0 10px; margin: 0 5px; } +.clock-widget { + background-color: #64727D; +} + .battery-status { - padding: 0 10px; - margin: 0 5px; background-color: #ffffff; color: black; } @@ -46,8 +42,11 @@ window { background-color: #26A65B; } +.cpu-widget { + background: #2ecc71; + color: #000000; +} + .memory-widget { - padding: 0 10px; - margin: 0 5px; background: #9b59b6; } diff --git a/src/bar.cpp b/src/bar.cpp index 79227c4c..02a1d1f4 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -8,6 +8,7 @@ #include "modules/workspaces.hpp" #include "modules/battery.hpp" #include "modules/memory.hpp" +#include "modules/cpu.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, @@ -149,10 +150,12 @@ auto waybar::Bar::setup_widgets() -> void auto &workspace_selector = *new waybar::modules::WorkspaceSelector(*this); auto &battery = *new waybar::modules::Battery(); auto &memory = *new waybar::modules::Memory(); + auto &cpu = *new waybar::modules::Cpu(); 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); + right.pack_end(cpu, false, false, 0); } diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp new file mode 100644 index 00000000..37a2666a --- /dev/null +++ b/src/modules/cpu.cpp @@ -0,0 +1,20 @@ +#include "modules/cpu.hpp" +#include + +waybar::modules::Cpu::Cpu() +{ + _label.get_style_context()->add_class("cpu-widget"); + _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(), 1)); + } + _thread.sleep_for(chrono::seconds(30)); + }; +}; + +waybar::modules::Cpu::operator Gtk::Widget &() { + return _label; +}