mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-08 04:08:49 -04:00
fix(overhaul): UI and resolution bugs for Steam Deck (Gamescope)
Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QSizeGrip>
|
||||||
|
#include <QGridLayout>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <comdef.h>
|
#include <comdef.h>
|
||||||
#include <WbemIdl.h>
|
#include <WbemIdl.h>
|
||||||
#pragma comment(lib, "wbemuuid.lib") // For MSVC, helps the linker find the library
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
@@ -37,53 +39,71 @@
|
|||||||
#include "video_core/gpu.h"
|
#include "video_core/gpu.h"
|
||||||
#include "video_core/renderer_base.h"
|
#include "video_core/renderer_base.h"
|
||||||
|
|
||||||
PerformanceOverlay::PerformanceOverlay(GMainWindow* parent)
|
namespace {
|
||||||
: QWidget(parent), main_window(parent) {
|
bool IsGamescope() {
|
||||||
|
static bool gamescope = qgetenv("XDG_CURRENT_DESKTOP") == "gamescope" ||
|
||||||
|
!qgetenv("GAMESCOPE_WIDTH").isEmpty();
|
||||||
|
return gamescope;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PerformanceOverlay::PerformanceOverlay(QWidget* parent) : QWidget(parent) {
|
||||||
|
// Cast the parent (which is now 'this' from main.cpp) to get our data source
|
||||||
|
main_window = qobject_cast<GMainWindow*>(parent);
|
||||||
|
|
||||||
|
if (IsGamescope()) {
|
||||||
|
setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||||
|
setAttribute(Qt::WA_ShowWithoutActivating);
|
||||||
|
} else {
|
||||||
|
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the widget properties
|
|
||||||
setAttribute(Qt::WA_TranslucentBackground, true);
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
setWindowFlags(Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
|
||||||
// Initialize fonts with better typography
|
if (IsGamescope()) {
|
||||||
title_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Medium);
|
title_font = QFont(QString::fromUtf8("Segoe UI"), 8, QFont::Bold);
|
||||||
value_font = QFont(QString::fromUtf8("Segoe UI"), 11, QFont::Bold);
|
value_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Bold);
|
||||||
small_font = QFont(QString::fromUtf8("Segoe UI"), 8, QFont::Normal);
|
small_font = QFont(QString::fromUtf8("Segoe UI"), 7, QFont::Normal);
|
||||||
|
setMinimumSize(150, 110);
|
||||||
|
resize(170, 130);
|
||||||
|
} else {
|
||||||
|
title_font = QFont(QString::fromUtf8("Segoe UI"), 9, QFont::Medium);
|
||||||
|
value_font = QFont(QString::fromUtf8("Segoe UI"), 11, QFont::Bold);
|
||||||
|
small_font = QFont(QString::fromUtf8("Segoe UI"), 8, QFont::Normal);
|
||||||
|
setMinimumSize(220, 180);
|
||||||
|
resize(220, 180);
|
||||||
|
}
|
||||||
|
|
||||||
temperature_color = QColor(76, 175, 80, 255); // Default to green
|
auto* layout = new QGridLayout(this);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
size_grip = new QSizeGrip(this);
|
||||||
|
layout->addWidget(size_grip, 0, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||||
|
|
||||||
// Graph colors
|
temperature_color = QColor(76, 175, 80, 255);
|
||||||
graph_background_color = QColor(40, 40, 40, 100);
|
graph_background_color = QColor(40, 40, 40, 100);
|
||||||
graph_line_color = QColor(76, 175, 80, 200);
|
graph_line_color = QColor(76, 175, 80, 200);
|
||||||
graph_fill_color = QColor(76, 175, 80, 60);
|
graph_fill_color = QColor(76, 175, 80, 60);
|
||||||
|
|
||||||
// Set up timer for updates
|
|
||||||
update_timer.setSingleShot(false);
|
update_timer.setSingleShot(false);
|
||||||
connect(&update_timer, &QTimer::timeout, this, &PerformanceOverlay::UpdatePerformanceStats);
|
connect(&update_timer, &QTimer::timeout, this, &PerformanceOverlay::UpdatePerformanceStats);
|
||||||
|
|
||||||
// Connect to the main window's theme change signal
|
if (main_window) {
|
||||||
connect(parent, &GMainWindow::themeChanged, this, &PerformanceOverlay::UpdateTheme);
|
connect(main_window, &GMainWindow::themeChanged, this, &PerformanceOverlay::UpdateTheme);
|
||||||
// Set the initial theme colors
|
}
|
||||||
|
|
||||||
UpdateTheme();
|
UpdateTheme();
|
||||||
|
|
||||||
// Set initial size - larger to accommodate the graph
|
|
||||||
resize(220, 180);
|
|
||||||
|
|
||||||
// Position in top-left corner
|
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
PerformanceOverlay::~PerformanceOverlay() = default;
|
PerformanceOverlay::~PerformanceOverlay() = default;
|
||||||
|
|
||||||
void PerformanceOverlay::SetVisible(bool visible) {
|
void PerformanceOverlay::SetVisible(bool visible) {
|
||||||
if (is_visible == visible) {
|
if (is_visible == visible) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
is_visible = visible;
|
is_visible = visible;
|
||||||
|
|
||||||
if (visible) {
|
if (visible) {
|
||||||
show();
|
show();
|
||||||
update_timer.start(500); // Update every 500ms for more accurate data
|
update_timer.start(500);
|
||||||
} else {
|
} else {
|
||||||
hide();
|
hide();
|
||||||
update_timer.stop();
|
update_timer.stop();
|
||||||
@@ -92,30 +112,23 @@ void PerformanceOverlay::SetVisible(bool visible) {
|
|||||||
|
|
||||||
void PerformanceOverlay::paintEvent(QPaintEvent* event) {
|
void PerformanceOverlay::paintEvent(QPaintEvent* event) {
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
|
|
||||||
// Draw background with rounded corners and subtle shadow effect
|
|
||||||
QPainterPath background_path;
|
QPainterPath background_path;
|
||||||
background_path.addRoundedRect(rect(), corner_radius, corner_radius);
|
background_path.addRoundedRect(rect(), corner_radius, corner_radius);
|
||||||
|
|
||||||
// Draw subtle shadow
|
if (!IsGamescope()) {
|
||||||
QPainterPath shadow_path = background_path.translated(1, 1);
|
QPainterPath shadow_path = background_path.translated(1, 1);
|
||||||
painter.fillPath(shadow_path, QColor(0, 0, 0, 40));
|
painter.fillPath(shadow_path, QColor(0, 0, 0, 40));
|
||||||
|
}
|
||||||
|
|
||||||
// Draw main background
|
|
||||||
painter.fillPath(background_path, background_color);
|
painter.fillPath(background_path, background_color);
|
||||||
|
|
||||||
// Draw subtle border
|
|
||||||
painter.setPen(QPen(border_color, border_width));
|
painter.setPen(QPen(border_color, border_width));
|
||||||
painter.drawPath(background_path);
|
painter.drawPath(background_path);
|
||||||
|
|
||||||
// Draw performance information
|
|
||||||
DrawPerformanceInfo(painter);
|
DrawPerformanceInfo(painter);
|
||||||
|
|
||||||
// Draw frame graph
|
|
||||||
DrawFrameGraph(painter);
|
DrawFrameGraph(painter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,128 +137,99 @@ void PerformanceOverlay::resizeEvent(QResizeEvent* event) {
|
|||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PerformanceOverlay::mousePressEvent(QMouseEvent* event) {
|
||||||
|
if (event->button() == Qt::LeftButton && !size_grip->geometry().contains(event->pos())) {
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
// LINUX-SPECIFIC IMPLEMENTATION (Wayland Fix)
|
if (!IsGamescope() && windowHandle()) {
|
||||||
void PerformanceOverlay::mousePressEvent(QMouseEvent* event) {
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
|
||||||
// Hand off window moving responsibility to the OS compositor.
|
|
||||||
if (windowHandle()) {
|
|
||||||
windowHandle()->startSystemMove();
|
windowHandle()->startSystemMove();
|
||||||
|
} else {
|
||||||
|
is_dragging = true;
|
||||||
|
drag_start_pos = event->globalPosition().toPoint() - this->pos();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
QWidget::mousePressEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PerformanceOverlay::mouseMoveEvent(QMouseEvent* event) {
|
|
||||||
// This function is intentionally left blank for dragging, as the
|
|
||||||
// system compositor now handles the entire move operation.
|
|
||||||
QWidget::mouseMoveEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// ORIGINAL IMPLEMENTATION
|
|
||||||
void PerformanceOverlay::mousePressEvent(QMouseEvent* event) {
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
|
||||||
is_dragging = true;
|
is_dragging = true;
|
||||||
drag_start_pos = event->globalPosition().toPoint();
|
drag_start_pos = event->globalPosition().toPoint() - this->pos();
|
||||||
widget_start_pos = this->pos();
|
#endif
|
||||||
setCursor(Qt::ClosedHandCursor);
|
event->accept();
|
||||||
}
|
}
|
||||||
QWidget::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceOverlay::mouseMoveEvent(QMouseEvent* event) {
|
void PerformanceOverlay::mouseMoveEvent(QMouseEvent* event) {
|
||||||
if (is_dragging) {
|
if (is_dragging) {
|
||||||
QPoint delta = event->globalPosition().toPoint() - drag_start_pos;
|
move(event->globalPosition().toPoint() - drag_start_pos);
|
||||||
move(widget_start_pos + delta);
|
event->accept();
|
||||||
}
|
}
|
||||||
QWidget::mouseMoveEvent(event);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void PerformanceOverlay::mouseReleaseEvent(QMouseEvent* event) {
|
void PerformanceOverlay::mouseReleaseEvent(QMouseEvent* event) {
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
is_dragging = false;
|
is_dragging = false;
|
||||||
has_been_moved = true;
|
has_been_moved = true;
|
||||||
setCursor(Qt::ArrowCursor);
|
setCursor(Qt::ArrowCursor);
|
||||||
|
event->accept();
|
||||||
}
|
}
|
||||||
QWidget::mouseReleaseEvent(event);
|
QWidget::mouseReleaseEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PerformanceOverlay::UpdatePerformanceStats() {
|
void PerformanceOverlay::UpdatePerformanceStats() {
|
||||||
if (!main_window) {
|
if (!main_window) return;
|
||||||
return;
|
|
||||||
|
// Gamescope Catch-all: Hide if ANY other Citron window (Updater, Lobby, etc.) is visible.
|
||||||
|
if (IsGamescope()) {
|
||||||
|
bool sub_window_visible = false;
|
||||||
|
for (QWidget* w : QApplication::topLevelWidgets()) {
|
||||||
|
if (w->isWindow() && w->isVisible() && w != main_window && w != this &&
|
||||||
|
!w->inherits("GRenderWindow") && !w->inherits("VramOverlay") && !w->inherits("ControllerOverlay")) {
|
||||||
|
sub_window_visible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sub_window_visible) {
|
||||||
|
if (!this->isHidden()) this->hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_visible && this->isHidden()) {
|
||||||
|
this->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get shader building info (this is safe to call)
|
|
||||||
shaders_building = main_window->GetShadersBuilding();
|
shaders_building = main_window->GetShadersBuilding();
|
||||||
|
|
||||||
// Use a static counter to only call the performance methods occasionally
|
|
||||||
// This reduces the chance of conflicts with the status bar updates
|
|
||||||
static int update_counter = 0;
|
static int update_counter = 0;
|
||||||
update_counter++;
|
update_counter++;
|
||||||
|
|
||||||
// Try to get performance data every 2nd update (every 1 second)
|
|
||||||
if (update_counter % 2 == 0) {
|
if (update_counter % 2 == 0) {
|
||||||
try {
|
try {
|
||||||
current_fps = main_window->GetCurrentFPS();
|
current_fps = main_window->GetCurrentFPS();
|
||||||
current_frame_time = main_window->GetCurrentFrameTime();
|
current_frame_time = main_window->GetCurrentFrameTime();
|
||||||
emulation_speed = main_window->GetEmulationSpeed();
|
emulation_speed = main_window->GetEmulationSpeed();
|
||||||
|
|
||||||
// Validate the values
|
if (std::isnan(current_fps) || current_fps < 0.0 || current_fps > 1000.0) current_fps = 60.0;
|
||||||
if (std::isnan(current_fps) || current_fps < 0.0 || current_fps > 1000.0) {
|
if (std::isnan(current_frame_time) || current_frame_time < 0.0 || current_frame_time > 100.0) current_frame_time = 16.67;
|
||||||
current_fps = 60.0;
|
if (std::isnan(emulation_speed) || emulation_speed < 0.0 || emulation_speed > 1000.0) emulation_speed = 100.0;
|
||||||
}
|
|
||||||
if (std::isnan(current_frame_time) || current_frame_time < 0.0 || current_frame_time > 100.0) {
|
|
||||||
current_frame_time = 16.67;
|
|
||||||
}
|
|
||||||
if (std::isnan(emulation_speed) || emulation_speed < 0.0 || emulation_speed > 1000.0) {
|
|
||||||
emulation_speed = 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure FPS and frame time are consistent
|
if (current_fps > 0.0) current_frame_time = 1000.0 / current_fps;
|
||||||
if (current_fps > 0.0 && current_frame_time > 0.0) {
|
} catch (...) {}
|
||||||
// Recalculate frame time from FPS to ensure consistency
|
|
||||||
current_frame_time = 1000.0 / current_fps;
|
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
// If we get an exception, use the last known good values
|
|
||||||
// Don't reset to defaults immediately
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update hardware temperatures every 4th update (every 2 seconds)
|
|
||||||
if (update_counter % 4 == 0) {
|
if (update_counter % 4 == 0) {
|
||||||
UpdateHardwareTemperatures();
|
UpdateHardwareTemperatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't have valid data yet, use defaults
|
if (std::isnan(current_fps) || current_fps <= 0.0) current_fps = 60.0;
|
||||||
if (std::isnan(current_fps) || current_fps <= 0.0) {
|
if (std::isnan(current_frame_time) || current_frame_time <= 0.0) current_frame_time = 16.67;
|
||||||
current_fps = 60.0;
|
if (std::isnan(emulation_speed) || emulation_speed <= 0.0) emulation_speed = 100.0;
|
||||||
}
|
|
||||||
if (std::isnan(current_frame_time) || current_frame_time <= 0.0) {
|
|
||||||
current_frame_time = 16.67; // 60 FPS
|
|
||||||
}
|
|
||||||
if (std::isnan(emulation_speed) || emulation_speed <= 0.0) {
|
|
||||||
emulation_speed = 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add frame time to graph history (only if it's valid)
|
if (current_frame_time > 0.0) AddFrameTime(current_frame_time);
|
||||||
if (current_frame_time > 0.0) {
|
|
||||||
AddFrameTime(current_frame_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update FPS and Temperature colors based on performance
|
|
||||||
fps_color = GetFpsColor(current_fps);
|
fps_color = GetFpsColor(current_fps);
|
||||||
temperature_color = GetTemperatureColor(std::max({cpu_temperature, gpu_temperature, battery_temperature}));
|
temperature_color = GetTemperatureColor(std::max({cpu_temperature, gpu_temperature, battery_temperature}));
|
||||||
|
|
||||||
// Trigger a repaint
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceOverlay::UpdateHardwareTemperatures() {
|
void PerformanceOverlay::UpdateHardwareTemperatures() {
|
||||||
// Reset data
|
|
||||||
cpu_temperature = 0.0f;
|
cpu_temperature = 0.0f;
|
||||||
gpu_temperature = 0.0f;
|
gpu_temperature = 0.0f;
|
||||||
cpu_sensor_type.clear();
|
cpu_sensor_type.clear();
|
||||||
@@ -254,7 +238,6 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
battery_temperature = 0.0f;
|
battery_temperature = 0.0f;
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
// --- Standard Linux Thermal Zone Reading ---
|
|
||||||
QDir thermal_dir(QString::fromUtf8("/sys/class/thermal/"));
|
QDir thermal_dir(QString::fromUtf8("/sys/class/thermal/"));
|
||||||
QStringList filters{QString::fromUtf8("thermal_zone*")};
|
QStringList filters{QString::fromUtf8("thermal_zone*")};
|
||||||
QStringList thermal_zones = thermal_dir.entryList(filters, QDir::Dirs);
|
QStringList thermal_zones = thermal_dir.entryList(filters, QDir::Dirs);
|
||||||
@@ -285,8 +268,6 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
// This uses QtAndroid Extras to get battery info from the Android system.
|
|
||||||
// NOTE: This requires the QtAndroidExtras module to be linked in the build.
|
|
||||||
QJniObject battery_status = QJniObject::callStaticObjectMethod(
|
QJniObject battery_status = QJniObject::callStaticObjectMethod(
|
||||||
"android/content/CONTEXT", "registerReceiver",
|
"android/content/CONTEXT", "registerReceiver",
|
||||||
"(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;",
|
"(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;",
|
||||||
@@ -300,12 +281,8 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
int temp_tenths = battery_status.callMethod<jint>("getIntExtra", "(Ljava/lang/String;I)I",
|
int temp_tenths = battery_status.callMethod<jint>("getIntExtra", "(Ljava/lang/String;I)I",
|
||||||
QJniObject::fromString("temperature").object<jstring>(), -1);
|
QJniObject::fromString("temperature").object<jstring>(), -1);
|
||||||
|
|
||||||
if (scale > 0) {
|
if (scale > 0) battery_percentage = (level * 100) / scale;
|
||||||
battery_percentage = (level * 100) / scale;
|
if (temp_tenths > 0) battery_temperature = static_cast<float>(temp_tenths) / 10.0f;
|
||||||
}
|
|
||||||
if (temp_tenths > 0) {
|
|
||||||
battery_temperature = static_cast<float>(temp_tenths) / 10.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -313,9 +290,7 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
IWbemLocator* pLoc = nullptr;
|
IWbemLocator* pLoc = nullptr;
|
||||||
IWbemServices* pSvc = nullptr;
|
IWbemServices* pSvc = nullptr;
|
||||||
|
|
||||||
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc);
|
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLoc);
|
||||||
|
|
||||||
if (SUCCEEDED(hres)) {
|
if (SUCCEEDED(hres)) {
|
||||||
hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\WMI"), NULL, NULL, 0, NULL, 0, 0, &pSvc);
|
hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\WMI"), NULL, NULL, 0, NULL, 0, 0, &pSvc);
|
||||||
if (SUCCEEDED(hres)) {
|
if (SUCCEEDED(hres)) {
|
||||||
@@ -331,7 +306,6 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
while (pEnumerator) {
|
while (pEnumerator) {
|
||||||
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
||||||
if (uReturn == 0) break;
|
if (uReturn == 0) break;
|
||||||
|
|
||||||
VARIANT vtProp;
|
VARIANT vtProp;
|
||||||
pclsObj->Get(L"CurrentTemperature", 0, &vtProp, 0, 0);
|
pclsObj->Get(L"CurrentTemperature", 0, &vtProp, 0, 0);
|
||||||
float temp_kelvin = vtProp.uintVal / 10.0f;
|
float temp_kelvin = vtProp.uintVal / 10.0f;
|
||||||
@@ -351,12 +325,7 @@ void PerformanceOverlay::UpdateHardwareTemperatures() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceOverlay::UpdatePosition() {
|
void PerformanceOverlay::UpdatePosition() {
|
||||||
if (!main_window) {
|
if (main_window && !has_been_moved) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only position in top-left corner if we haven't been moved by the user
|
|
||||||
if (!has_been_moved) {
|
|
||||||
QPoint main_window_pos = main_window->mapToGlobal(QPoint(0, 0));
|
QPoint main_window_pos = main_window->mapToGlobal(QPoint(0, 0));
|
||||||
move(main_window_pos.x() + 10, main_window_pos.y() + 10);
|
move(main_window_pos.x() + 10, main_window_pos.y() + 10);
|
||||||
}
|
}
|
||||||
@@ -366,7 +335,7 @@ void PerformanceOverlay::DrawPerformanceInfo(QPainter& painter) {
|
|||||||
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
painter.setRenderHint(QPainter::TextAntialiasing, true);
|
||||||
|
|
||||||
int y_offset = padding;
|
int y_offset = padding;
|
||||||
const int line_height = 20;
|
const int line_height = IsGamescope() ? 16 : 20;
|
||||||
|
|
||||||
// Draw title
|
// Draw title
|
||||||
painter.setFont(title_font);
|
painter.setFont(title_font);
|
||||||
@@ -374,15 +343,14 @@ void PerformanceOverlay::DrawPerformanceInfo(QPainter& painter) {
|
|||||||
painter.drawText(padding, y_offset + 12, QString::fromUtf8("CITRON"));
|
painter.drawText(padding, y_offset + 12, QString::fromUtf8("CITRON"));
|
||||||
|
|
||||||
int y_offset_right = padding;
|
int y_offset_right = padding;
|
||||||
const int line_height_right = 18;
|
const int line_height_right = IsGamescope() ? 14 : 18;
|
||||||
|
|
||||||
// Draw Temperatures
|
// Draw Temperatures
|
||||||
painter.setFont(small_font);
|
painter.setFont(small_font);
|
||||||
|
|
||||||
float core_temp_to_display = std::max(cpu_temperature, gpu_temperature);
|
float core_temp_to_display = std::max(cpu_temperature, gpu_temperature);
|
||||||
if (core_temp_to_display > 0.0f) {
|
if (core_temp_to_display > 0.0f) {
|
||||||
QString core_label = gpu_temperature > cpu_temperature ? gpu_sensor_type : cpu_sensor_type;
|
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);
|
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));
|
painter.setPen(GetTemperatureColor(core_temp_to_display));
|
||||||
int text_width = painter.fontMetrics().horizontalAdvance(core_temp_text);
|
int text_width = painter.fontMetrics().horizontalAdvance(core_temp_text);
|
||||||
painter.drawText(width() - padding - text_width, y_offset_right + 12, core_temp_text);
|
painter.drawText(width() - padding - text_width, y_offset_right + 12, core_temp_text);
|
||||||
@@ -391,66 +359,51 @@ void PerformanceOverlay::DrawPerformanceInfo(QPainter& painter) {
|
|||||||
|
|
||||||
// Draw Battery info
|
// Draw Battery info
|
||||||
if (battery_percentage > 0) {
|
if (battery_percentage > 0) {
|
||||||
QString batt_text = QString::fromUtf8("Batt: %1%").arg(battery_percentage);
|
QString batt_text = QString::fromUtf8("Batt:%1%").arg(battery_percentage);
|
||||||
if (battery_temperature > 0.0f) {
|
if (battery_temperature > 0.0f) batt_text += QString::fromUtf8("(%1°C)").arg(battery_temperature, 0, 'f', 0);
|
||||||
batt_text += QString::fromUtf8(" (%1°C)").arg(battery_temperature, 0, 'f', 0);
|
|
||||||
}
|
|
||||||
painter.setPen(text_color);
|
painter.setPen(text_color);
|
||||||
int text_width = painter.fontMetrics().horizontalAdvance(batt_text);
|
int text_width = painter.fontMetrics().horizontalAdvance(batt_text);
|
||||||
painter.drawText(width() - padding - text_width, y_offset_right + 12, batt_text);
|
painter.drawText(width() - padding - text_width, y_offset_right + 12, batt_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
y_offset += line_height + 4;
|
y_offset += line_height + 12;
|
||||||
|
|
||||||
// Draw FPS
|
// Draw FPS
|
||||||
painter.setFont(value_font);
|
painter.setFont(value_font);
|
||||||
painter.setPen(fps_color);
|
painter.setPen(fps_color);
|
||||||
QString fps_text = QString::fromUtf8("%1 FPS").arg(FormatFps(current_fps));
|
painter.drawText(padding, y_offset, QString::fromUtf8("%1 FPS").arg(FormatFps(current_fps)));
|
||||||
painter.drawText(padding, y_offset, fps_text);
|
|
||||||
y_offset += line_height;
|
y_offset += line_height;
|
||||||
|
|
||||||
// Draw frame time
|
// Draw frame time and speed
|
||||||
painter.setFont(small_font);
|
painter.setFont(small_font);
|
||||||
painter.setPen(text_color);
|
painter.setPen(text_color);
|
||||||
QString frame_time_text = QString::fromUtf8("Frame: %1 ms").arg(FormatFrameTime(current_frame_time));
|
painter.drawText(padding, y_offset, QString::fromUtf8("Frame:%1 ms").arg(FormatFrameTime(current_frame_time)));
|
||||||
painter.drawText(padding, y_offset, frame_time_text);
|
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;
|
y_offset += line_height - 2;
|
||||||
|
|
||||||
// Draw emulation speed
|
// Draw shader building info
|
||||||
QString speed_text = QString::fromUtf8("Speed: %1%").arg(emulation_speed, 0, 'f', 0);
|
|
||||||
painter.drawText(padding, y_offset, speed_text);
|
|
||||||
y_offset += line_height - 2;
|
|
||||||
|
|
||||||
// Draw shader building info with accent color
|
|
||||||
if (shaders_building > 0) {
|
if (shaders_building > 0) {
|
||||||
painter.setPen(QColor(255, 152, 0, 255)); // Material Design orange
|
painter.setPen(QColor(255, 152, 0, 255));
|
||||||
QString shader_text = QString::fromUtf8("Building: %1 shader(s)").arg(shaders_building);
|
painter.drawText(padding, y_offset, QString::fromUtf8("Building:%1").arg(shaders_building));
|
||||||
painter.drawText(padding, y_offset, shader_text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
||||||
if (frame_times.empty()) {
|
if (frame_times.empty()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int graph_y = height() - graph_height - padding;
|
const int graph_y = height() - graph_height - padding;
|
||||||
const int graph_width = width() - (padding * 2);
|
const int graph_width = width() - (padding * 2);
|
||||||
const QRect graph_rect(padding, graph_y, graph_width, graph_height);
|
const QRect graph_rect(padding, graph_y, graph_width, graph_height);
|
||||||
|
|
||||||
// Draw graph background
|
|
||||||
painter.fillRect(graph_rect, graph_background_color);
|
painter.fillRect(graph_rect, graph_background_color);
|
||||||
|
|
||||||
// Calculate graph bounds
|
|
||||||
const double min_val = std::max(0.0, min_frame_time - 1.0);
|
const double min_val = std::max(0.0, min_frame_time - 1.0);
|
||||||
const double max_val = std::max(16.67, max_frame_time + 1.0); // 16.67ms = 60 FPS
|
const double max_val = std::max(16.67, max_frame_time + 1.0);
|
||||||
const double range = max_val - min_val;
|
const double range = max_val - min_val;
|
||||||
|
if (range <= 0.0) return;
|
||||||
|
|
||||||
if (range <= 0.0) {
|
// Grid lines
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw grid lines
|
|
||||||
painter.setPen(QPen(QColor(80, 80, 80, 100), 1));
|
painter.setPen(QPen(QColor(80, 80, 80, 100), 1));
|
||||||
const int grid_lines = 4;
|
const int grid_lines = 4;
|
||||||
for (int i = 1; i < grid_lines; ++i) {
|
for (int i = 1; i < grid_lines; ++i) {
|
||||||
@@ -458,12 +411,11 @@ void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
|||||||
painter.drawLine(graph_rect.left(), y, graph_rect.right(), y);
|
painter.drawLine(graph_rect.left(), y, graph_rect.right(), y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw 60 FPS line (16.67ms)
|
// 60 FPS Target line
|
||||||
const int fps60_y = graph_y + graph_height - static_cast<int>((16.67 - min_val) / range * graph_height);
|
const int fps60_y = graph_y + graph_height - static_cast<int>((16.67 - min_val) / range * graph_height);
|
||||||
painter.setPen(QPen(QColor(255, 255, 255, 80), 1, Qt::DashLine));
|
painter.setPen(QPen(QColor(255, 255, 255, 80), 1, Qt::DashLine));
|
||||||
painter.drawLine(graph_rect.left(), fps60_y, graph_rect.right(), fps60_y);
|
painter.drawLine(graph_rect.left(), fps60_y, graph_rect.right(), fps60_y);
|
||||||
|
|
||||||
// Draw frame time line
|
|
||||||
painter.setPen(QPen(graph_line_color, 2));
|
painter.setPen(QPen(graph_line_color, 2));
|
||||||
painter.setBrush(graph_fill_color);
|
painter.setBrush(graph_fill_color);
|
||||||
|
|
||||||
@@ -476,22 +428,14 @@ void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
|||||||
const double normalized_y = (frame_time - min_val) / range;
|
const double normalized_y = (frame_time - min_val) / range;
|
||||||
const int x = graph_rect.left() + static_cast<int>(i * x_step);
|
const int x = graph_rect.left() + static_cast<int>(i * x_step);
|
||||||
const int y = graph_y + graph_height - static_cast<int>(normalized_y * graph_height);
|
const int y = graph_y + graph_height - static_cast<int>(normalized_y * graph_height);
|
||||||
|
if (i == 0) graph_path.moveTo(x, y); else graph_path.lineTo(x, y);
|
||||||
if (i == 0) {
|
|
||||||
graph_path.moveTo(x, y);
|
|
||||||
} else {
|
|
||||||
graph_path.lineTo(x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the path for filling
|
|
||||||
graph_path.lineTo(graph_rect.right(), graph_rect.bottom());
|
graph_path.lineTo(graph_rect.right(), graph_rect.bottom());
|
||||||
graph_path.lineTo(graph_rect.left(), graph_rect.bottom());
|
graph_path.lineTo(graph_rect.left(), graph_rect.bottom());
|
||||||
graph_path.closeSubpath();
|
graph_path.closeSubpath();
|
||||||
|
|
||||||
painter.drawPath(graph_path);
|
painter.drawPath(graph_path);
|
||||||
|
|
||||||
// Draw statistics text
|
|
||||||
painter.setFont(small_font);
|
painter.setFont(small_font);
|
||||||
painter.setPen(text_color);
|
painter.setPen(text_color);
|
||||||
|
|
||||||
@@ -500,7 +444,7 @@ void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
|||||||
const QString max_text = QString::fromUtf8("Max: %1ms").arg(FormatFrameTime(max_frame_time));
|
const QString max_text = QString::fromUtf8("Max: %1ms").arg(FormatFrameTime(max_frame_time));
|
||||||
|
|
||||||
painter.drawText(graph_rect.left(), graph_y - 5, min_text);
|
painter.drawText(graph_rect.left(), graph_y - 5, min_text);
|
||||||
painter.drawText(graph_rect.center().x() - painter.fontMetrics().horizontalAdvance(avg_text) / 2,
|
painter.drawText(graph_rect.center().x() - (painter.fontMetrics().horizontalAdvance(avg_text) / 2),
|
||||||
graph_y - 5, avg_text);
|
graph_y - 5, avg_text);
|
||||||
painter.drawText(graph_rect.right() - painter.fontMetrics().horizontalAdvance(max_text),
|
painter.drawText(graph_rect.right() - painter.fontMetrics().horizontalAdvance(max_text),
|
||||||
graph_y - 5, max_text);
|
graph_y - 5, max_text);
|
||||||
@@ -508,13 +452,7 @@ void PerformanceOverlay::DrawFrameGraph(QPainter& painter) {
|
|||||||
|
|
||||||
void PerformanceOverlay::AddFrameTime(double frame_time_ms) {
|
void PerformanceOverlay::AddFrameTime(double frame_time_ms) {
|
||||||
frame_times.push_back(frame_time_ms);
|
frame_times.push_back(frame_time_ms);
|
||||||
|
if (frame_times.size() > MAX_FRAME_HISTORY) frame_times.pop_front();
|
||||||
// Keep only the last MAX_FRAME_HISTORY frames
|
|
||||||
if (frame_times.size() > MAX_FRAME_HISTORY) {
|
|
||||||
frame_times.pop_front();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update statistics
|
|
||||||
if (!frame_times.empty()) {
|
if (!frame_times.empty()) {
|
||||||
min_frame_time = *std::min_element(frame_times.begin(), frame_times.end());
|
min_frame_time = *std::min_element(frame_times.begin(), frame_times.end());
|
||||||
max_frame_time = *std::max_element(frame_times.begin(), frame_times.end());
|
max_frame_time = *std::max_element(frame_times.begin(), frame_times.end());
|
||||||
@@ -523,54 +461,39 @@ void PerformanceOverlay::AddFrameTime(double frame_time_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QColor PerformanceOverlay::GetFpsColor(double fps) const {
|
QColor PerformanceOverlay::GetFpsColor(double fps) const {
|
||||||
if (fps >= 55.0) {
|
if (fps >= 55.0) return QColor(76, 175, 80, 255);
|
||||||
return QColor(76, 175, 80, 255); // Material Design green - Good performance
|
if (fps >= 45.0) return QColor(255, 152, 0, 255);
|
||||||
} else if (fps >= 45.0) {
|
if (fps >= 30.0) return QColor(255, 87, 34, 255);
|
||||||
return QColor(255, 152, 0, 255); // Material Design orange - Moderate performance
|
return QColor(244, 67, 54, 255);
|
||||||
} else if (fps >= 30.0) {
|
|
||||||
return QColor(255, 87, 34, 255); // Material Design deep orange - Poor performance
|
|
||||||
} else {
|
|
||||||
return QColor(244, 67, 54, 255); // Material Design red - Very poor performance
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor PerformanceOverlay::GetTemperatureColor(float temperature) const {
|
QColor PerformanceOverlay::GetTemperatureColor(float temperature) const {
|
||||||
if (temperature > 70.0f) {
|
if (temperature > 70.0f) return QColor(244, 67, 54, 255);
|
||||||
return QColor(244, 67, 54, 255); // Material Design red
|
if (temperature > 60.0f) return QColor(255, 152, 0, 255);
|
||||||
} else if (temperature > 60.0f) {
|
return QColor(76, 175, 80, 255);
|
||||||
return QColor(255, 152, 0, 255); // Material Design orange
|
|
||||||
} else {
|
|
||||||
return QColor(76, 175, 80, 255); // Material Design green
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PerformanceOverlay::FormatFps(double fps) const {
|
QString PerformanceOverlay::FormatFps(double fps) const {
|
||||||
if (std::isnan(fps) || fps < 0.0) {
|
if (std::isnan(fps) || fps < 0.0) return QString::fromUtf8("0.0");
|
||||||
return QString::fromUtf8("0.0");
|
|
||||||
}
|
|
||||||
return QString::number(fps, 'f', 1);
|
return QString::number(fps, 'f', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PerformanceOverlay::FormatFrameTime(double frame_time_ms) const {
|
QString PerformanceOverlay::FormatFrameTime(double frame_time_ms) const {
|
||||||
if (std::isnan(frame_time_ms) || frame_time_ms < 0.0) {
|
if (std::isnan(frame_time_ms) || frame_time_ms < 0.0) return QString::fromUtf8("0.00");
|
||||||
return QString::fromUtf8("0.00");
|
|
||||||
}
|
|
||||||
return QString::number(frame_time_ms, 'f', 2);
|
return QString::number(frame_time_ms, 'f', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerformanceOverlay::UpdateTheme() {
|
void PerformanceOverlay::UpdateTheme() {
|
||||||
if (UISettings::IsDarkTheme()) {
|
if (UISettings::IsDarkTheme()) {
|
||||||
// Dark Theme Colors (your original values)
|
background_color = QColor(20, 20, 20, 200);
|
||||||
background_color = QColor(20, 20, 20, 200); // Slightly more opaque
|
|
||||||
border_color = QColor(60, 60, 60, 120);
|
border_color = QColor(60, 60, 60, 120);
|
||||||
text_color = QColor(220, 220, 220, 255);
|
text_color = QColor(220, 220, 220, 255);
|
||||||
graph_background_color = QColor(40, 40, 40, 100);
|
graph_background_color = QColor(40, 40, 40, 100);
|
||||||
} else {
|
} else {
|
||||||
// Light Theme Colors
|
|
||||||
background_color = QColor(245, 245, 245, 220);
|
background_color = QColor(245, 245, 245, 220);
|
||||||
border_color = QColor(200, 200, 200, 120);
|
border_color = QColor(200, 200, 200, 120);
|
||||||
text_color = QColor(20, 20, 20, 255);
|
text_color = QColor(20, 20, 20, 255);
|
||||||
graph_background_color = QColor(220, 220, 220, 100);
|
graph_background_color = QColor(220, 220, 220, 100);
|
||||||
}
|
}
|
||||||
update(); // Force a repaint with the new colors
|
update();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user