diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c47e126..3535549 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -296,6 +296,11 @@ void MainWindow::updateTemperatures() int totalReadings = 0; bool needsLegendUpdate = false; + // GPU memory variables for status bar + double gpuMemoryUsedGB = 0.0; + double gpuMemoryTotalGB = 0.0; + bool hasGpuData = false; + for (auto &deviceEntry : allTemps) { const std::string &device = deviceEntry.first; const auto &temps = deviceEntry.second; @@ -395,12 +400,12 @@ void MainWindow::updateTemperatures() if (gpuMonitor && gpuMonitor->isEnabled()) { GpuStats gpuStats; if (gpuMonitor->getGpuStats(gpuStats)) { - // Add GPU utilization data - if (chart->addCpuLoadData("GPU - Utilization", gpuStats.utilizationPercent, currentTime)) { + // Add GPU utilization data - using "GPU" as cpuName to create series key "CPU - GPU" + if (chart->addCpuLoadData("GPU", gpuStats.utilizationPercent, currentTime)) { needsLegendUpdate = true; // Apply saved settings for GPU series - std::string seriesId = "GPU - Utilization"; + std::string seriesId = "CPU - GPU"; auto savedNames = config->getSensorNames(); if (savedNames.count(seriesId)) { chart->setSeriesName(seriesId, savedNames[seriesId]); @@ -415,15 +420,16 @@ void MainWindow::updateTemperatures() } } - // Add GPU memory usage data (as percentage, not raw MB) + // Add GPU memory usage data - as percentage double memoryPercent = (gpuStats.memoryTotalMB > 0) ? (gpuStats.memoryUsedMB / gpuStats.memoryTotalMB) * 100.0 : 0.0; - std::string memorySeriesId = "GPU - Memory Usage"; - if (chart->addTemperatureData(memorySeriesId, "Memory Usage", memoryPercent, currentTime)) { + // Using "GPU" as device and "Memory" as sensor to create series key "GPU - Memory" + if (chart->addTemperatureData("GPU", "Memory", memoryPercent, currentTime)) { needsLegendUpdate = true; // Apply saved settings for GPU memory series + std::string memorySeriesId = "GPU - Memory"; auto savedNames = config->getSensorNames(); if (savedNames.count(memorySeriesId)) { chart->setSeriesName(memorySeriesId, savedNames[memorySeriesId]); @@ -437,6 +443,29 @@ void MainWindow::updateTemperatures() } } } + + // Update GPU utilization label in legend + std::string utilizationSeriesId = "CPU - GPU"; + if (tempLabels.count(utilizationSeriesId)) { + char buf[16]; + snprintf(buf, sizeof(buf), "%.0f%%", gpuStats.utilizationPercent); + gtk_label_set_text(GTK_LABEL(tempLabels[utilizationSeriesId]), buf); + } + + // Update GPU memory label in legend + std::string memoryLabelSeriesId = "GPU - Memory"; + if (tempLabels.count(memoryLabelSeriesId)) { + double usedGB = gpuStats.memoryUsedMB / 1024.0; + double totalGB = gpuStats.memoryTotalMB / 1024.0; + char buf[32]; + snprintf(buf, sizeof(buf), "%.1f/%.1f GB", usedGB, totalGB); + gtk_label_set_text(GTK_LABEL(tempLabels[memoryLabelSeriesId]), buf); + } + + // Store GPU memory for status bar (convert to GB) + gpuMemoryUsedGB = gpuStats.memoryUsedMB / 1024.0; + gpuMemoryTotalGB = gpuStats.memoryTotalMB / 1024.0; + hasGpuData = true; } } } @@ -449,6 +478,12 @@ void MainWindow::updateTemperatures() << " | Devices: " << allTemps.size() << " | Total readings: " << totalReadings; + // Add GPU memory to status bar if available + if (hasGpuData) { + oss << " | GPU Memory: " << std::fixed << std::setprecision(1) + << gpuMemoryUsedGB << " / " << gpuMemoryTotalGB << " GB"; + } + gtk_label_set_text(GTK_LABEL(statusLabel), oss.str().c_str()); // Update legend ONLY if new sensors were found or legend is empty @@ -475,9 +510,35 @@ void MainWindow::updateLegend() // Add legend items auto sensorEnabledMap = config->getSensorEnabled(); + // Sort series by type: CPU first, then GPU, then temperatures + std::vector*> sortedSeries; + std::vector*> cpuSeries; + std::vector*> gpuSeries; + std::vector*> tempSeries; + for (const auto &pair : seriesColors) { const std::string &seriesId = pair.first; - const GdkRGBA &color = pair.second; + // Categorize by series ID + if (seriesId.find("CPU -") == 0 && seriesId != "CPU - GPU") { + // CPU items but exclude GPU utilization + cpuSeries.push_back(&pair); + } else if (seriesId.find("GPU -") == 0 || seriesId == "CPU - GPU") { + // GPU items including GPU utilization + gpuSeries.push_back(&pair); + } else { + // Temperature items + tempSeries.push_back(&pair); + } + } + + // Combine in desired order: CPU, GPU, Temperatures + sortedSeries.insert(sortedSeries.end(), cpuSeries.begin(), cpuSeries.end()); + sortedSeries.insert(sortedSeries.end(), gpuSeries.begin(), gpuSeries.end()); + sortedSeries.insert(sortedSeries.end(), tempSeries.begin(), tempSeries.end()); + + for (const auto *pairPtr : sortedSeries) { + const std::string &seriesId = pairPtr->first; + const GdkRGBA &color = pairPtr->second; std::string displayName = chart->getSeriesName(seriesId); bool isVisible = true; diff --git a/src/temperature_chart.cpp b/src/temperature_chart.cpp index 0f1bcf0..b8d0413 100644 --- a/src/temperature_chart.cpp +++ b/src/temperature_chart.cpp @@ -188,7 +188,12 @@ bool TemperatureChart::addTemperatureData(const std::string &device, const std:: SeriesData series; series.color = getColorForSeries(seriesKey); series.id = seriesKey; - series.name = seriesKey; + // Set friendly display name + if (seriesKey == "GPU - Memory") { + series.name = "GPU Mem"; + } else { + series.name = seriesKey; + } series.dataType = DataType::TEMPERATURE; seriesMap[seriesKey] = series; isNew = true; @@ -278,7 +283,14 @@ bool TemperatureChart::addCpuLoadData(const std::string &cpuName, double loadPer SeriesData series; series.color = getColorForSeries(seriesKey); series.id = seriesKey; - series.name = "CPU " + cpuName; + // Set friendly display name + if (cpuName == "Overall") { + series.name = "CPU Util"; + } else if (cpuName == "GPU") { + series.name = "GPU Util"; + } else { + series.name = "CPU " + cpuName; + } series.dataType = DataType::CPU_LOAD; seriesMap[seriesKey] = series; isNew = true;