Gtk4: Migration memory

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
pull/2956/head
Viktar Lukashonak 2024-03-08 06:02:05 +03:00
parent f9b6f665c1
commit f66e5284dd
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F
5 changed files with 21 additions and 16 deletions

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#include <fmt/format.h>
#include <fstream>
#include <unordered_map> #include <unordered_map>
#include "ALabel.hpp" #include "ALabel.hpp"

View File

@ -187,14 +187,18 @@ inc_dirs = ['include']
if is_linux if is_linux
add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp') add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp')
add_project_arguments('-DHAVE_MEMORY_LINUX', language: 'cpp')
src_files += files('src/modules/battery.cpp', src_files += files('src/modules/battery.cpp',
'src/modules/cpu.cpp', 'src/modules/cpu.cpp',
'src/modules/cpu_frequency/common.cpp', 'src/modules/cpu_frequency/common.cpp',
'src/modules/cpu_frequency/linux.cpp', 'src/modules/cpu_frequency/linux.cpp',
'src/modules/cpu_usage/common.cpp', 'src/modules/cpu_usage/common.cpp',
'src/modules/cpu_usage/linux.cpp') 'src/modules/cpu_usage/linux.cpp',
'src/modules/memory/common.cpp',
'src/modules/memory/linux.cpp')
man_files += files('man/waybar-battery.5.scd', man_files += files('man/waybar-battery.5.scd',
'man/waybar-cpu.5.scd') 'man/waybar-cpu.5.scd',
'man/waybar-memory.5.scd')
elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp') add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp')
add_project_arguments('-DHAVE_MEMORY_BSD', language: 'cpp') add_project_arguments('-DHAVE_MEMORY_BSD', language: 'cpp')
@ -205,13 +209,13 @@ elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
'src/modules/cpu_frequency/common.cpp', 'src/modules/cpu_frequency/common.cpp',
'src/modules/cpu_usage/bsd.cpp', 'src/modules/cpu_usage/bsd.cpp',
'src/modules/cpu_usage/common.cpp', 'src/modules/cpu_usage/common.cpp',
# 'src/modules/memory/bsd.cpp', 'src/modules/memory/bsd.cpp',
# 'src/modules/memory/common.cpp', 'src/modules/memory/common.cpp',
) )
man_files += files( man_files += files(
# 'man/waybar-cffi.5.scd', # 'man/waybar-cffi.5.scd',
'man/waybar-cpu.5.scd', 'man/waybar-cpu.5.scd',
# 'man/waybar-memory.5.scd', 'man/waybar-memory.5.scd'
) )
if is_freebsd if is_freebsd
src_files += files('src/modules/battery.cpp') src_files += files('src/modules/battery.cpp')

View File

@ -204,12 +204,12 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
#endif #endif
if (ref == "idle_inhibitor") { if (ref == "idle_inhibitor") {
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]); return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);
} }*/
#if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD) #if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD)
if (ref == "memory") { if (ref == "memory") {
return new waybar::modules::Memory(id, config_[name]); return new waybar::modules::Memory(id, config_[name]);
} }
#endif*/ #endif
#if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD) #if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD)
if (ref == "cpu") { if (ref == "cpu") {
return new waybar::modules::Cpu(id, config_[name]); return new waybar::modules::Cpu(id, config_[name]);

View File

@ -1,5 +1,7 @@
#include "modules/memory.hpp" #include "modules/memory.hpp"
#include <fmt/format.h>
waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config) waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config)
: ALabel(config, "memory", id, "{}%", 30) { : ALabel(config, "memory", id, "{}%", 30) {
thread_ = [this] { thread_ = [this] {
@ -51,11 +53,11 @@ auto waybar::modules::Memory::update() -> void {
} }
if (format.empty()) { if (format.empty()) {
event_box_.hide(); Gtk::Label::hide();
} else { } else {
event_box_.show(); Gtk::Label::show();
auto icons = std::vector<std::string>{state}; auto icons = std::vector<std::string>{state};
label_.set_markup(fmt::format( Gtk::Label::set_markup(fmt::format(
fmt::runtime(format), used_ram_percentage, fmt::runtime(format), used_ram_percentage,
fmt::arg("icon", getIcon(used_ram_percentage, icons)), fmt::arg("icon", getIcon(used_ram_percentage, icons)),
fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes),
@ -68,7 +70,7 @@ auto waybar::modules::Memory::update() -> void {
if (tooltipEnabled()) { if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
auto tooltip_format = config_["tooltip-format"].asString(); auto tooltip_format = config_["tooltip-format"].asString();
label_.set_tooltip_text(fmt::format( Gtk::Label::set_tooltip_text(fmt::format(
fmt::runtime(tooltip_format), used_ram_percentage, fmt::runtime(tooltip_format), used_ram_percentage,
fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes), fmt::arg("total", total_ram_gigabytes), fmt::arg("swapTotal", total_swap_gigabytes),
fmt::arg("percentage", used_ram_percentage), fmt::arg("percentage", used_ram_percentage),
@ -76,11 +78,11 @@ auto waybar::modules::Memory::update() -> void {
fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes), fmt::arg("swapUsed", used_swap_gigabytes), fmt::arg("avail", available_ram_gigabytes),
fmt::arg("swapAvail", available_swap_gigabytes))); fmt::arg("swapAvail", available_swap_gigabytes)));
} else { } else {
label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1)); Gtk::Label::set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
} }
} }
} else { } else {
event_box_.hide(); Gtk::Label::hide();
} }
// Call parent update // Call parent update
ALabel::update(); ALabel::update();

View File

@ -1,5 +1,7 @@
#include "modules/memory.hpp" #include "modules/memory.hpp"
#include <fstream>
static unsigned zfsArcSize() { static unsigned zfsArcSize() {
std::ifstream zfs_arc_stats{"/proc/spl/kstat/zfs/arcstats"}; std::ifstream zfs_arc_stats{"/proc/spl/kstat/zfs/arcstats"};