mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Add DrmAmdCard config option
Some AMD cards are under card1, so make the hardcoded path at least a bit configurable.
This commit is contained in:
parent
48c0f4814d
commit
9b551fe848
4 changed files with 17 additions and 10 deletions
|
@ -124,6 +124,10 @@ NetworkAdapter: eno1
|
|||
# Disables the network widget when set to false
|
||||
NetworkWidget: true
|
||||
|
||||
# The card to poll when using AMDGPU. If you don't have an AMD card, you can skip this config.
|
||||
# Possible values can be found by querying /sys/class/drm
|
||||
DrmAmdCard: card0
|
||||
|
||||
# Use tooltips instead of sliders for the sensors
|
||||
SensorTooltips: false
|
||||
|
||||
|
|
17
src/AMDGPU.h
17
src/AMDGPU.h
|
@ -6,16 +6,17 @@
|
|||
#ifdef WITH_AMD
|
||||
namespace AMDGPU
|
||||
{
|
||||
static const char* utilizationFile = "/sys/class/drm/card0/device/gpu_busy_percent";
|
||||
static const char* vramTotalFile = "/sys/class/drm/card0/device/mem_info_vram_total";
|
||||
static const char* vramUsedFile = "/sys/class/drm/card0/device/mem_info_vram_used";
|
||||
static const char* drmCardPrefix = "/sys/class/drm/";
|
||||
static const char* utilizationFile = "/device/gpu_busy_percent";
|
||||
static const char* vramTotalFile = "/device/mem_info_vram_total";
|
||||
static const char* vramUsedFile = "/device/mem_info_vram_used";
|
||||
// TODO: Make this configurable
|
||||
static const char* tempFile = "/sys/class/drm/card0/device/hwmon/hwmon1/temp1_input";
|
||||
|
||||
inline void Init()
|
||||
{
|
||||
// Test for drm device files
|
||||
std::ifstream test(utilizationFile);
|
||||
std::ifstream test(drmCardPrefix + Config::Get().drmAmdCard + utilizationFile);
|
||||
if (!test.is_open())
|
||||
{
|
||||
LOG("AMD GPU not found, disabling AMD GPU");
|
||||
|
@ -31,7 +32,7 @@ namespace AMDGPU
|
|||
return {};
|
||||
}
|
||||
|
||||
std::ifstream file(utilizationFile);
|
||||
std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + utilizationFile);
|
||||
std::string line;
|
||||
std::getline(file, line);
|
||||
return atoi(line.c_str());
|
||||
|
@ -45,7 +46,7 @@ namespace AMDGPU
|
|||
return {};
|
||||
}
|
||||
|
||||
std::ifstream file(tempFile);
|
||||
std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + tempFile);
|
||||
std::string line;
|
||||
std::getline(file, line);
|
||||
return atoi(line.c_str()) / 1000;
|
||||
|
@ -66,12 +67,12 @@ namespace AMDGPU
|
|||
}
|
||||
VRAM mem{};
|
||||
|
||||
std::ifstream file(vramTotalFile);
|
||||
std::ifstream file(drmCardPrefix + Config::Get().drmAmdCard + vramTotalFile);
|
||||
std::string line;
|
||||
std::getline(file, line);
|
||||
mem.totalB = atoi(line.c_str());
|
||||
|
||||
file = std::ifstream(vramUsedFile);
|
||||
file = std::ifstream(drmCardPrefix + Config::Get().drmAmdCard + vramUsedFile);
|
||||
std::getline(file, line);
|
||||
mem.usedB = atoi(line.c_str());
|
||||
|
||||
|
|
|
@ -232,6 +232,7 @@ void Config::Load()
|
|||
|
||||
AddConfigVar("CPUThermalZone", config.cpuThermalZone, lineView, foundProperty);
|
||||
AddConfigVar("NetworkAdapter", config.networkAdapter, lineView, foundProperty);
|
||||
AddConfigVar("DrmAmdCard", config.drmAmdCard, lineView, foundProperty);
|
||||
AddConfigVar("SuspendCommand", config.suspendCommand, lineView, foundProperty);
|
||||
AddConfigVar("LockCommand", config.lockCommand, lineView, foundProperty);
|
||||
AddConfigVar("ExitCommand", config.exitCommand, lineView, foundProperty);
|
||||
|
|
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
std::string cpuThermalZone = ""; // idk, no standard way of doing this.
|
||||
std::string networkAdapter = "eno1"; // Is this standard?
|
||||
std::string drmAmdCard = "card0"; // The card to poll in AMDGPU.
|
||||
std::string suspendCommand = "systemctl suspend";
|
||||
std::string lockCommand = ""; // idk, no standard way of doing this.
|
||||
std::string exitCommand = ""; // idk, no standard way of doing this.
|
||||
|
|
Loading…
Reference in a new issue