Make the partition monitored by disk sensor configurable (#50)

Allows to stat partitions other than the root partition

---------

Co-authored-by: Sebastian Zerbe <zerbe@phil.hhu.de>
This commit is contained in:
Sebastian Zerbe 2023-09-08 16:34:17 +02:00 committed by GitHub
parent 9afbfe3c1d
commit 471bc6e719
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 3 deletions

View file

@ -22,6 +22,9 @@ ExitCommand: killall Hyprland
# The folder, where the battery sensors reside
BatteryFolder: /sys/class/power_supply/BAT1
# The partition to monitor with disk sensor
DiskPartition: /
# Overrides the icon of the nth (in this case the first) workspace.
# Please note the missing space between "," and the symbol. Adding a space here adds it to the bar too!
#WorkspaceSymbol: 1,

View file

@ -58,6 +58,11 @@ in {
default = "/sys/class/power_supply/BAT1";
description = "The folder, where the battery sensors reside";
};
DiskPartition = mkOption {
type = types.str;
default = "/";
description = "The partition to monitor with disk sensor";
};
WorkspaceSymbols = mkOption {
type = types.nullOr (types.listOf types.str);
default = [];

View file

@ -124,7 +124,7 @@ namespace Bar
{
System::DiskInfo info = System::GetDiskInfo();
std::string text = "Disk: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" +
std::string text = "Disk " + info.partition + ": " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" +
Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB";
if (Config::Get().sensorTooltips)
{

View file

@ -201,6 +201,7 @@ void Config::Load()
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
AddConfigVar("DiskPartition", config.diskPartition, lineView, foundProperty);
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);

View file

@ -18,6 +18,7 @@ public:
std::string defaultWorkspaceSymbol = "";
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
std::string dateTimeLocale = ""; // use system locale
std::string diskPartition = "/"; // should be expectable on every linux system
// Script that returns how many packages are out-of-date. The script should only print a number!
// See data/update.sh for a human-readable version

View file

@ -202,10 +202,12 @@ namespace System
DiskInfo GetDiskInfo()
{
struct statvfs stat;
int err = statvfs("/", &stat);
ASSERT(err == 0, "Cannot stat root!");
std::string partition = Config::Get().diskPartition;
int err = statvfs(partition.c_str(), &stat);
ASSERT(err == 0, "Cannot stat " + partition + "!");
DiskInfo out{};
out.partition = partition;
out.totalGiB = (double)(stat.f_blocks * stat.f_frsize) / (1024 * 1024 * 1024);
out.usedGiB = (double)((stat.f_blocks - stat.f_bfree) * stat.f_frsize) / (1024 * 1024 * 1024);
return out;

View file

@ -38,6 +38,7 @@ namespace System
struct DiskInfo
{
std::string partition;
double totalGiB;
double usedGiB;
};