Gtk4: Migration. Disk

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
pull/2956/head
Viktar Lukashonak 2024-03-10 12:19:03 +03:00
parent f66e5284dd
commit 0b56c55d8d
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F
4 changed files with 13 additions and 14 deletions

View File

@ -1,12 +1,6 @@
#pragma once #pragma once
#include <fmt/format.h>
#include <sys/statvfs.h>
#include <fstream>
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/format.hpp"
#include "util/sleeper_thread.hpp" #include "util/sleeper_thread.hpp"
namespace waybar::modules { namespace waybar::modules {

View File

@ -130,6 +130,7 @@ src_files = files(
'src/group.cpp', 'src/group.cpp',
'src/ASlider.cpp', 'src/ASlider.cpp',
'src/modules/load.cpp', 'src/modules/load.cpp',
'src/modules/disk.cpp'
) )
man_files = files( man_files = files(

View File

@ -233,10 +233,10 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
gtk4 todo gtk4 todo
if (ref == "user") { if (ref == "user") {
return new waybar::modules::User(id, config_[name]); return new waybar::modules::User(id, config_[name]);
} }*/
if (ref == "disk") { if (ref == "disk") {
return new waybar::modules::Disk(id, config_[name]); return new waybar::modules::Disk(id, config_[name]);
} }/*
if (ref == "image") { if (ref == "image") {
return new waybar::modules::Image(id, config_[name]); return new waybar::modules::Image(id, config_[name]);
} }

View File

@ -1,5 +1,9 @@
#include "modules/disk.hpp" #include "modules/disk.hpp"
#include <fmt/format.h>
#include <sys/statvfs.h>
#include "util/format.hpp"
using namespace waybar::util; using namespace waybar::util;
waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config) waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config)
@ -42,7 +46,7 @@ auto waybar::modules::Disk::update() -> void {
*/ */
if (err != 0) { if (err != 0) {
event_box_.hide(); Gtk::Label::hide();
return; return;
} }
@ -65,10 +69,10 @@ auto waybar::modules::Disk::update() -> void {
} }
if (format.empty()) { if (format.empty()) {
event_box_.hide(); Gtk::Label::hide();
} else { } else {
event_box_.show(); Gtk::Label::show();
label_.set_markup(fmt::format( Gtk::Label::set_markup(fmt::format(
fmt::runtime(format), stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), fmt::runtime(format), stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free),
fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("used", used), fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("used", used),
fmt::arg("percentage_used", percentage_used), fmt::arg("total", total), fmt::arg("percentage_used", percentage_used), fmt::arg("total", total),
@ -81,7 +85,7 @@ auto waybar::modules::Disk::update() -> void {
if (config_["tooltip-format"].isString()) { if (config_["tooltip-format"].isString()) {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
label_.set_tooltip_text(fmt::format( Gtk::Label::set_tooltip_text(fmt::format(
fmt::runtime(tooltip_format), stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free), fmt::runtime(tooltip_format), stats.f_bavail * 100 / stats.f_blocks, fmt::arg("free", free),
fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("used", used), fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks), fmt::arg("used", used),
fmt::arg("percentage_used", percentage_used), fmt::arg("total", total), fmt::arg("percentage_used", percentage_used), fmt::arg("total", total),