fix(gamescope): Performance Additions

Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
Collecting
2026-01-05 07:29:03 +00:00
parent d83234d238
commit d14f40230a

View File

@@ -63,11 +63,11 @@ PerformanceOverlay::PerformanceOverlay(QWidget* parent) : QWidget(IsGamescope()
setAttribute(Qt::WA_WState_ExplicitShowHide);
if (IsGamescope()) {
title_font = QFont(QString::fromUtf8("Segoe UI"), 8, QFont::Bold);
value_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Bold);
small_font = QFont(QString::fromUtf8("Segoe UI"), 7, QFont::Normal);
setMinimumSize(150, 110);
resize(170, 140); // Taller for 2-line stats
title_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Bold);
value_font = QFont(QString::fromUtf8("Segoe UI"), 10, QFont::Bold);
small_font = QFont(QString::fromUtf8("Segoe UI"), 8, QFont::Normal);
setMinimumSize(160, 130);
resize(195, 160);
} else {
title_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Medium);
value_font = QFont(QString::fromUtf8("Segoe UI"), 11, QFont::Bold);
@@ -245,69 +245,67 @@ void PerformanceOverlay::UpdatePerformanceStats() {
void PerformanceOverlay::UpdateHardwareTemperatures() {
cpu_temperature = 0.0f;
gpu_temperature = 0.0f;
cpu_sensor_type.clear();
gpu_sensor_type.clear();
battery_percentage = 0;
battery_temperature = 0.0f;
#if defined(Q_OS_LINUX)
// 1. Read Battery Percentage and Temperature (Steam Deck / Linux Laptops)
QStringList bat_nodes = {QStringLiteral("BAT1"), QStringLiteral("BAT0")};
for (const QString& node : bat_nodes) {
QString base_path = QStringLiteral("/sys/class/power_supply/%1/").arg(node);
QFile cap_file(base_path + QStringLiteral("capacity"));
if (cap_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// 1. Read Battery Data
QDir bat_dir(QStringLiteral("/sys/class/power_supply/"));
QStringList bats = bat_dir.entryList({QStringLiteral("BAT*")}, QDir::Dirs);
for (const QString& node : bats) {
QFile cap_file(bat_dir.filePath(node + QStringLiteral("/capacity")));
if (cap_file.open(QIODevice::ReadOnly)) {
battery_percentage = cap_file.readAll().trimmed().toInt();
cap_file.close();
QFile btemp_file(base_path + QStringLiteral("temp"));
if (btemp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
battery_temperature = btemp_file.readAll().trimmed().toFloat() / 10.0f;
QFile btemp_file(bat_dir.filePath(node + QStringLiteral("/temp")));
if (btemp_file.open(QIODevice::ReadOnly)) {
float raw_temp = btemp_file.readAll().trimmed().toFloat();
// SCALE FIX: Detect millidegrees (35000) or tenths (350)
battery_temperature = (raw_temp > 1000) ? raw_temp / 1000.0f : raw_temp / 10.0f;
btemp_file.close();
}
break;
}
}
// 2. Read CPU/GPU Temperature via hwmon (Steam Deck APU)
// 2. Read APU Temperatures
QDir hwmon_dir(QStringLiteral("/sys/class/hwmon/"));
QStringList hwmons = hwmon_dir.entryList({QStringLiteral("hwmon*")}, QDir::Dirs);
for (const QString& h_node : hwmons) {
QFile name_file(hwmon_dir.filePath(h_node + QStringLiteral("/name")));
if (!name_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
if (!name_file.open(QIODevice::ReadOnly)) continue;
QString hw_name = QString::fromUtf8(name_file.readAll().trimmed());
name_file.close();
if (hw_name == QStringLiteral("amdgpu") || hw_name == QStringLiteral("k10temp")) {
if (hw_name == QStringLiteral("amdgpu")) {
QFile temp_file(hwmon_dir.filePath(h_node + QStringLiteral("/temp1_input")));
if (temp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
float temp = temp_file.readAll().trimmed().toFloat() / 1000.0f;
if (temp_file.open(QIODevice::ReadOnly)) {
gpu_temperature = temp_file.readAll().trimmed().toFloat() / 1000.0f;
gpu_sensor_type = QStringLiteral("GPU");
temp_file.close();
}
} else if (hw_name == QStringLiteral("k10temp")) {
QFile temp_file(hwmon_dir.filePath(h_node + QStringLiteral("/temp1_input")));
if (temp_file.open(QIODevice::ReadOnly)) {
cpu_temperature = temp_file.readAll().trimmed().toFloat() / 1000.0f;
cpu_sensor_type = QStringLiteral("CPU");
temp_file.close();
if (temp > cpu_temperature) {
cpu_temperature = temp;
gpu_temperature = temp;
cpu_sensor_type = QStringLiteral("APU");
gpu_sensor_type = QStringLiteral("GPU");
}
}
}
}
// 3. Fallback to generic thermal_zones
// 3. Fallback to generic thermal_zones (ONLY if sensors didn't find anything)
if (cpu_temperature <= 0.0f) {
QDir thermal_dir(QStringLiteral("/sys/class/thermal/"));
QStringList thermal_zones = thermal_dir.entryList({QStringLiteral("thermal_zone*")}, QDir::Dirs);
for (const QString& zone_name : thermal_zones) {
QFile type_file(thermal_dir.filePath(zone_name + QStringLiteral("/type")));
if (!type_file.open(QIODevice::ReadOnly | QIODevice::Text)) continue;
if (!type_file.open(QIODevice::ReadOnly)) continue;
QString type = QString::fromUtf8(type_file.readAll().trimmed());
type_file.close();
if (type.contains(QStringLiteral("x86_pkg_temp")) || type.contains(QStringLiteral("cpu"))) {
QFile temp_file(thermal_dir.filePath(zone_name + QStringLiteral("/temp")));
if (temp_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (temp_file.open(QIODevice::ReadOnly)) {
cpu_temperature = temp_file.readAll().trimmed().toFloat() / 1000.0f;
cpu_sensor_type = QStringLiteral("CPU");
temp_file.close();
@@ -316,6 +314,7 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
}
}
#endif
}
#if defined(Q_OS_ANDROID)
QJniObject battery_status = QJniObject::callStaticObjectMethod(
@@ -384,58 +383,67 @@ void PerformanceOverlay::UpdatePosition() {
void PerformanceOverlay::DrawPerformanceInfo(QPainter& painter) {
painter.setRenderHint(QPainter::TextAntialiasing, true);
int y_offset = padding;
const int line_height = IsGamescope() ? 16 : 20;
// Dynamic spacing based on font size to prevent squishing
const int title_step = painter.fontMetrics().height() + 8;
const int stat_step = painter.fontMetrics().height() + 2;
// Draw title
int y_left = padding + painter.fontMetrics().ascent();
int y_right = padding + painter.fontMetrics().ascent();
// 1. Draw Title (Left)
painter.setFont(title_font);
painter.setPen(text_color);
painter.drawText(padding, y_offset + 12, QString::fromUtf8("CITRON"));
painter.drawText(padding, y_left, QStringLiteral("CITRON"));
int y_offset_right = padding;
const int line_height_right = IsGamescope() ? 14 : 18;
// Draw Temperatures
// 2. Draw Hardware Stats (Right Column)
painter.setFont(small_font);
float core_temp_to_display = std::max(cpu_temperature, gpu_temperature);
if (core_temp_to_display > 0.0f) {
QString core_label = gpu_temperature > cpu_temperature ? gpu_sensor_type : cpu_sensor_type;
QString core_temp_text = QString::fromUtf8("%1:%2°C").arg(core_label).arg(core_temp_to_display, 0, 'f', 0);
painter.setPen(GetTemperatureColor(core_temp_to_display));
int text_width = painter.fontMetrics().horizontalAdvance(core_temp_text);
painter.drawText(width() - padding - text_width, y_offset_right + 12, core_temp_text);
}
y_offset_right += line_height_right;
const int hw_step = IsGamescope() ? 16 : 20;
if (cpu_temperature > 0.0f) {
QString cpu_text = QStringLiteral("CPU:%1°C").arg(cpu_temperature, 0, 'f', 0);
painter.setPen(GetTemperatureColor(cpu_temperature));
int tw = painter.fontMetrics().horizontalAdvance(cpu_text);
painter.drawText(width() - padding - tw, y_right, cpu_text);
y_right += hw_step;
}
if (gpu_temperature > 0.0f) {
QString gpu_text = QStringLiteral("GPU:%1°C").arg(gpu_temperature, 0, 'f', 0);
painter.setPen(GetTemperatureColor(gpu_temperature));
int tw = painter.fontMetrics().horizontalAdvance(gpu_text);
painter.drawText(width() - padding - tw, y_right, gpu_text);
y_right += hw_step;
}
// Draw Battery info
if (battery_percentage > 0) {
QString batt_text = QString::fromUtf8("Batt:%1%").arg(battery_percentage);
if (battery_temperature > 0.0f) batt_text += QString::fromUtf8("(%1°C)").arg(battery_temperature, 0, 'f', 0);
QString batt_text = QStringLiteral("Battery %:%1%").arg(battery_percentage);
if (battery_temperature > 0.0f) {
batt_text += QStringLiteral(" (%1°C)").arg(battery_temperature, 0, 'f', 0);
}
painter.setPen(text_color);
int text_width = painter.fontMetrics().horizontalAdvance(batt_text);
painter.drawText(width() - padding - text_width, y_offset_right + 12, batt_text);
int tw = painter.fontMetrics().horizontalAdvance(batt_text);
painter.drawText(width() - padding - tw, y_right, batt_text);
}
y_offset += line_height + 12;
// Draw FPS
// 3. Draw FPS (Left Column)
y_left += title_step;
painter.setFont(value_font);
painter.setPen(fps_color);
painter.drawText(padding, y_offset, QString::fromUtf8("%1 FPS").arg(FormatFps(current_fps)));
y_offset += line_height;
painter.drawText(padding, y_left, QStringLiteral("%1 FPS").arg(FormatFps(current_fps)));
// Draw frame time and speed
// 4. Draw Small Stats (Left Column)
y_left += title_step;
painter.setFont(small_font);
painter.setPen(text_color);
painter.drawText(padding, y_offset, QString::fromUtf8("Frame:%1 ms").arg(FormatFrameTime(current_frame_time)));
y_offset += line_height - 2;
painter.drawText(padding, y_offset, QString::fromUtf8("Speed:%1%").arg(emulation_speed, 0, 'f', 0));
y_offset += line_height - 2;
painter.drawText(padding, y_left, QStringLiteral("Frame:%1 ms").arg(FormatFrameTime(current_frame_time)));
y_left += stat_step;
painter.drawText(padding, y_left, QStringLiteral("Speed:%1%").arg(emulation_speed, 0, 'f', 0));
// Draw shader building info
if (shaders_building > 0) {
painter.setPen(QColor(255, 152, 0, 255));
painter.drawText(padding, y_offset, QString::fromUtf8("Building:%1").arg(shaders_building));
y_left += stat_step;
painter.setPen(QColor(255, 152, 0));
painter.drawText(padding, y_left, QStringLiteral("Building:%1").arg(shaders_building));
}
}
@@ -515,8 +523,8 @@ QColor PerformanceOverlay::GetFpsColor(double fps) const {
}
QColor PerformanceOverlay::GetTemperatureColor(float temperature) const {
if (temperature > 70.0f) return QColor(244, 67, 54, 255);
if (temperature > 60.0f) return QColor(255, 152, 0, 255);
if (temperature > 85.0f) return QColor(244, 67, 54, 255);
if (temperature > 75.0f) return QColor(255, 152, 0, 255);
return QColor(76, 175, 80, 255);
}