mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 11:12:49 +00:00
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:
parent
9afbfe3c1d
commit
471bc6e719
7 changed files with 16 additions and 3 deletions
|
@ -22,6 +22,9 @@ ExitCommand: killall Hyprland
|
||||||
# The folder, where the battery sensors reside
|
# The folder, where the battery sensors reside
|
||||||
BatteryFolder: /sys/class/power_supply/BAT1
|
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.
|
# 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!
|
# Please note the missing space between "," and the symbol. Adding a space here adds it to the bar too!
|
||||||
#WorkspaceSymbol: 1,
|
#WorkspaceSymbol: 1,
|
||||||
|
|
|
@ -58,6 +58,11 @@ in {
|
||||||
default = "/sys/class/power_supply/BAT1";
|
default = "/sys/class/power_supply/BAT1";
|
||||||
description = "The folder, where the battery sensors reside";
|
description = "The folder, where the battery sensors reside";
|
||||||
};
|
};
|
||||||
|
DiskPartition = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/";
|
||||||
|
description = "The partition to monitor with disk sensor";
|
||||||
|
};
|
||||||
WorkspaceSymbols = mkOption {
|
WorkspaceSymbols = mkOption {
|
||||||
type = types.nullOr (types.listOf types.str);
|
type = types.nullOr (types.listOf types.str);
|
||||||
default = [];
|
default = [];
|
||||||
|
|
|
@ -124,7 +124,7 @@ namespace Bar
|
||||||
{
|
{
|
||||||
System::DiskInfo info = System::GetDiskInfo();
|
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";
|
Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB";
|
||||||
if (Config::Get().sensorTooltips)
|
if (Config::Get().sensorTooltips)
|
||||||
{
|
{
|
||||||
|
|
|
@ -201,6 +201,7 @@ void Config::Load()
|
||||||
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
|
AddConfigVar("DateTimeStyle", config.dateTimeStyle, lineView, foundProperty);
|
||||||
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
|
AddConfigVar("DateTimeLocale", config.dateTimeLocale, lineView, foundProperty);
|
||||||
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
|
AddConfigVar("CheckPackagesCommand", config.checkPackagesCommand, lineView, foundProperty);
|
||||||
|
AddConfigVar("DiskPartition", config.diskPartition, lineView, foundProperty);
|
||||||
|
|
||||||
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
AddConfigVar("CenterTime", config.centerTime, lineView, foundProperty);
|
||||||
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
AddConfigVar("AudioInput", config.audioInput, lineView, foundProperty);
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
std::string defaultWorkspaceSymbol = "";
|
std::string defaultWorkspaceSymbol = "";
|
||||||
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
|
std::string dateTimeStyle = "%a %D - %H:%M:%S %Z"; // A sane default
|
||||||
std::string dateTimeLocale = ""; // use system locale
|
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!
|
// 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
|
// See data/update.sh for a human-readable version
|
||||||
|
|
|
@ -202,10 +202,12 @@ namespace System
|
||||||
DiskInfo GetDiskInfo()
|
DiskInfo GetDiskInfo()
|
||||||
{
|
{
|
||||||
struct statvfs stat;
|
struct statvfs stat;
|
||||||
int err = statvfs("/", &stat);
|
std::string partition = Config::Get().diskPartition;
|
||||||
ASSERT(err == 0, "Cannot stat root!");
|
int err = statvfs(partition.c_str(), &stat);
|
||||||
|
ASSERT(err == 0, "Cannot stat " + partition + "!");
|
||||||
|
|
||||||
DiskInfo out{};
|
DiskInfo out{};
|
||||||
|
out.partition = partition;
|
||||||
out.totalGiB = (double)(stat.f_blocks * stat.f_frsize) / (1024 * 1024 * 1024);
|
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);
|
out.usedGiB = (double)((stat.f_blocks - stat.f_bfree) * stat.f_frsize) / (1024 * 1024 * 1024);
|
||||||
return out;
|
return out;
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace System
|
||||||
|
|
||||||
struct DiskInfo
|
struct DiskInfo
|
||||||
{
|
{
|
||||||
|
std::string partition;
|
||||||
double totalGiB;
|
double totalGiB;
|
||||||
double usedGiB;
|
double usedGiB;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue