game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
performance_profile_dialog.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// performance_profile_dialog.cpp
4// ==============================================================================
5// Dialog for managing per-game performance profiles
6// ==============================================================================
7
10#include "models/game.h"
12#include "theme_manager.h"
13
14#include <QDialogButtonBox>
15#include <QFormLayout>
16#include <QHBoxLayout>
17#include <QHeaderView>
18#include <QMessageBox>
19#include <QScrollArea>
20#include <QSplitter>
21#include <QUuid>
22#include <QVBoxLayout>
23
24// ==============================================================================
25// Constructor (Game-specific mode)
26// ==============================================================================
27
29 PerformanceProfileService* profileService,
30 QWidget* parent, ThemeManager* themeManager)
31 : QDialog(parent), game_(game), gameId_(game ? game->id : ""), profileService_(profileService),
32 isGlobalMode_(false), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
33{
34 setWindowTitle(
35 game ? QString("Performance Profiles - %1").arg(QString::fromStdString(game->name))
36 : "Performance Profiles");
37 setupUI();
38 refreshProfileList();
39 applyTheme();
40
41 connect(themeManager_, &ThemeManager::themeChanged, this,
42 &PerformanceProfileDialog::applyTheme);
43}
44
45// ==============================================================================
46// Constructor (Global mode)
47// ==============================================================================
48
50 core::GameLibraryController* libraryController,
51 QWidget* parent, ThemeManager* themeManager)
52 : QDialog(parent), profileService_(profileService), libraryController_(libraryController),
53 isGlobalMode_(true), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
54{
55 setWindowTitle("Performance Profile Manager");
56 setupUI();
57 refreshProfileList();
58 applyTheme();
59
60 connect(themeManager_, &ThemeManager::themeChanged, this,
61 &PerformanceProfileDialog::applyTheme);
62}
63
65
66// ==============================================================================
67// UI Setup
68// ==============================================================================
69
70void PerformanceProfileDialog::setupUI()
71{
72 resize(800, 600);
73
74 auto* mainLayout = new QVBoxLayout(this);
75 mainLayout->setSpacing(12);
76 mainLayout->setContentsMargins(16, 16, 16, 16);
77
78 // Game selector for global mode
79 if (isGlobalMode_ && libraryController_)
80 {
81 auto* gameLayout = new QHBoxLayout();
82 auto* gameLabel = new QLabel("Game:", this);
83 gameCombo_ = new QComboBox(this);
84 gameCombo_->addItem("-- Global Profiles --", QString());
85
86 auto games = libraryController_->getAllGames();
87 for (const auto* g : games)
88 {
89 gameCombo_->addItem(QString::fromStdString(g->name), QString::fromStdString(g->id));
90 }
91
92 connect(gameCombo_, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
93 &PerformanceProfileDialog::onGameSelected);
94
95 gameLayout->addWidget(gameLabel);
96 gameLayout->addWidget(gameCombo_, 1);
97 mainLayout->addLayout(gameLayout);
98 }
99
100 // Main splitter
101 auto* splitter = new QSplitter(Qt::Horizontal, this);
102 splitter->setChildrenCollapsible(false);
103
104 // Left panel: Profile list
105 auto* leftPanel = new QWidget(this);
106 auto* leftLayout = new QVBoxLayout(leftPanel);
107 leftLayout->setContentsMargins(0, 0, 0, 0);
108 leftLayout->setSpacing(8);
109
110 auto* listLabel = new QLabel("Profiles", this);
111 listLabel->setStyleSheet("font-weight: bold; font-size: 13px;");
112 leftLayout->addWidget(listLabel);
113
114 setupProfileList();
115 leftLayout->addWidget(profileList_, 1);
116
117 // List buttons
118 auto* listBtnLayout = new QHBoxLayout();
119 createBtn_ = new QPushButton("+ New", this);
120 createBtn_->setCursor(Qt::PointingHandCursor);
121 deleteBtn_ = new QPushButton("Delete", this);
122 deleteBtn_->setCursor(Qt::PointingHandCursor);
123 deleteBtn_->setEnabled(false);
124
125 connect(createBtn_, &QPushButton::clicked, this, &PerformanceProfileDialog::onCreateProfile);
126 connect(deleteBtn_, &QPushButton::clicked, this, &PerformanceProfileDialog::onDeleteProfile);
127
128 listBtnLayout->addWidget(createBtn_);
129 listBtnLayout->addWidget(deleteBtn_);
130 listBtnLayout->addStretch();
131 leftLayout->addLayout(listBtnLayout);
132
133 splitter->addWidget(leftPanel);
134
135 // Right panel: Profile editor
136 setupProfileEditor();
137 splitter->addWidget(editorPanel_);
138
139 splitter->setSizes({250, 550});
140 mainLayout->addWidget(splitter, 1);
141
142 // Bottom buttons
143 auto* buttonLayout = new QHBoxLayout();
144 buttonLayout->addStretch();
145
146 applyBtn_ = new QPushButton("Apply to Game", this);
147 applyBtn_->setCursor(Qt::PointingHandCursor);
148 applyBtn_->setEnabled(false);
149 connect(applyBtn_, &QPushButton::clicked, this, &PerformanceProfileDialog::onApplyProfile);
150
151 closeBtn_ = new QPushButton("Close", this);
152 closeBtn_->setCursor(Qt::PointingHandCursor);
153 connect(closeBtn_, &QPushButton::clicked, this, &QDialog::accept);
154
155 buttonLayout->addWidget(applyBtn_);
156 buttonLayout->addWidget(closeBtn_);
157 mainLayout->addLayout(buttonLayout);
158}
159
160void PerformanceProfileDialog::setupProfileList()
161{
162 profileList_ = new QListWidget(this);
163 profileList_->setMinimumWidth(200);
164 profileList_->setSelectionMode(QAbstractItemView::SingleSelection);
165
166 connect(profileList_, &QListWidget::currentItemChanged, this,
167 &PerformanceProfileDialog::onProfileSelected);
168}
169
170void PerformanceProfileDialog::setupProfileEditor()
171{
172 editorPanel_ = new QWidget(this);
173 auto* editorLayout = new QVBoxLayout(editorPanel_);
174 editorLayout->setContentsMargins(8, 0, 0, 0);
175 editorLayout->setSpacing(12);
176
177 // Scroll area for editor content
178 auto* scrollArea = new QScrollArea(this);
179 scrollArea->setWidgetResizable(true);
180 scrollArea->setFrameShape(QFrame::NoFrame);
181
182 auto* scrollContent = new QWidget();
183 auto* contentLayout = new QVBoxLayout(scrollContent);
184 contentLayout->setSpacing(16);
185
186 // Basic info section
187 auto* basicGroup = new QGroupBox("Profile Settings", this);
188 auto* basicLayout = new QFormLayout(basicGroup);
189 basicLayout->setSpacing(8);
190
191 nameEdit_ = new QLineEdit(this);
192 nameEdit_->setPlaceholderText("Profile name");
193 connect(nameEdit_, &QLineEdit::textChanged, this, &PerformanceProfileDialog::onSettingsChanged);
194 basicLayout->addRow("Name:", nameEdit_);
195
196 descEdit_ = new QTextEdit(this);
197 descEdit_->setMaximumHeight(60);
198 descEdit_->setPlaceholderText("Optional description");
199 connect(descEdit_, &QTextEdit::textChanged, this, &PerformanceProfileDialog::onSettingsChanged);
200 basicLayout->addRow("Description:", descEdit_);
201
202 presetCombo_ = new QComboBox(this);
203 presetCombo_->addItem("Custom", -1);
204 presetCombo_->addItem("Default (Balanced)", 0);
205 presetCombo_->addItem("High Performance", 1);
206 presetCombo_->addItem("Battery Saver", 2);
207 presetCombo_->addItem("Streaming/Recording", 3);
208 connect(presetCombo_, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
209 &PerformanceProfileDialog::onPresetSelected);
210 basicLayout->addRow("Preset:", presetCombo_);
211
212 contentLayout->addWidget(basicGroup);
213
214 // Display settings
215 displayGroup_ = new QGroupBox("Display & Overlays", this);
216 auto* displayLayout = new QVBoxLayout(displayGroup_);
217
218 mangoHudCheck_ = new QCheckBox("Enable MangoHud (FPS overlay)", this);
219 connect(mangoHudCheck_, &QCheckBox::toggled, this,
220 &PerformanceProfileDialog::onSettingsChanged);
221 displayLayout->addWidget(mangoHudCheck_);
222
223 gameModCheck_ = new QCheckBox("Enable GameMode (performance optimizations)", this);
224 connect(gameModCheck_, &QCheckBox::toggled, this, &PerformanceProfileDialog::onSettingsChanged);
225 displayLayout->addWidget(gameModCheck_);
226
227 gamescopeCheck_ = new QCheckBox("Enable Gamescope (compositor)", this);
228 connect(gamescopeCheck_, &QCheckBox::toggled, this,
229 [this](bool checked)
230 {
231 gamescopeGroup_->setEnabled(checked);
232 onSettingsChanged();
233 });
234 displayLayout->addWidget(gamescopeCheck_);
235
236 vkbasaltCheck_ = new QCheckBox("Enable vkBasalt (post-processing)", this);
237 connect(vkbasaltCheck_, &QCheckBox::toggled, this,
238 &PerformanceProfileDialog::onSettingsChanged);
239 displayLayout->addWidget(vkbasaltCheck_);
240
241 contentLayout->addWidget(displayGroup_);
242
243 // Gamescope settings
244 gamescopeGroup_ = new QGroupBox("Gamescope Settings", this);
245 gamescopeGroup_->setEnabled(false);
246 auto* gsLayout = new QFormLayout(gamescopeGroup_);
247
248 gamescopeWidthSpin_ = new QSpinBox(this);
249 gamescopeWidthSpin_->setRange(640, 7680);
250 gamescopeWidthSpin_->setValue(1920);
251 gamescopeWidthSpin_->setSuffix(" px");
252 connect(gamescopeWidthSpin_, QOverload<int>::of(&QSpinBox::valueChanged), this,
253 &PerformanceProfileDialog::onSettingsChanged);
254 gsLayout->addRow("Width:", gamescopeWidthSpin_);
255
256 gamescopeHeightSpin_ = new QSpinBox(this);
257 gamescopeHeightSpin_->setRange(480, 4320);
258 gamescopeHeightSpin_->setValue(1080);
259 gamescopeHeightSpin_->setSuffix(" px");
260 connect(gamescopeHeightSpin_, QOverload<int>::of(&QSpinBox::valueChanged), this,
261 &PerformanceProfileDialog::onSettingsChanged);
262 gsLayout->addRow("Height:", gamescopeHeightSpin_);
263
264 gamescopeFullscreenCheck_ = new QCheckBox(this);
265 connect(gamescopeFullscreenCheck_, &QCheckBox::toggled, this,
266 &PerformanceProfileDialog::onSettingsChanged);
267 gsLayout->addRow("Fullscreen:", gamescopeFullscreenCheck_);
268
269 gamescopeBorderlessCheck_ = new QCheckBox(this);
270 connect(gamescopeBorderlessCheck_, &QCheckBox::toggled, this,
271 &PerformanceProfileDialog::onSettingsChanged);
272 gsLayout->addRow("Borderless:", gamescopeBorderlessCheck_);
273
274 gamescopeScalerCombo_ = new QComboBox(this);
275 gamescopeScalerCombo_->addItem("Auto", "auto");
276 gamescopeScalerCombo_->addItem("Integer", "integer");
277 gamescopeScalerCombo_->addItem("Fit", "fit");
278 gamescopeScalerCombo_->addItem("Fill", "fill");
279 gamescopeScalerCombo_->addItem("Stretch", "stretch");
280 connect(gamescopeScalerCombo_, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
281 &PerformanceProfileDialog::onSettingsChanged);
282 gsLayout->addRow("Scaler:", gamescopeScalerCombo_);
283
284 gamescopeFpsLimitSpin_ = new QSpinBox(this);
285 gamescopeFpsLimitSpin_->setRange(0, 360);
286 gamescopeFpsLimitSpin_->setValue(0);
287 gamescopeFpsLimitSpin_->setSpecialValueText("Unlimited");
288 gamescopeFpsLimitSpin_->setSuffix(" FPS");
289 connect(gamescopeFpsLimitSpin_, QOverload<int>::of(&QSpinBox::valueChanged), this,
290 &PerformanceProfileDialog::onSettingsChanged);
291 gsLayout->addRow("FPS Limit:", gamescopeFpsLimitSpin_);
292
293 contentLayout->addWidget(gamescopeGroup_);
294
295 // Wine/Proton settings
296 wineGroup_ = new QGroupBox("Wine/Proton Settings", this);
297 auto* wineLayout = new QVBoxLayout(wineGroup_);
298
299 fsyncCheck_ = new QCheckBox("Enable Fsync (fast synchronization)", this);
300 connect(fsyncCheck_, &QCheckBox::toggled, this, &PerformanceProfileDialog::onSettingsChanged);
301 wineLayout->addWidget(fsyncCheck_);
302
303 esyncCheck_ = new QCheckBox("Enable Esync (eventfd synchronization)", this);
304 connect(esyncCheck_, &QCheckBox::toggled, this, &PerformanceProfileDialog::onSettingsChanged);
305 wineLayout->addWidget(esyncCheck_);
306
307 ntsyncCheck_ = new QCheckBox("Enable NTSync (kernel 6.14+, experimental)", this);
308 connect(ntsyncCheck_, &QCheckBox::toggled, this, &PerformanceProfileDialog::onSettingsChanged);
309 wineLayout->addWidget(ntsyncCheck_);
310
311 dxvkAsyncCheck_ = new QCheckBox("DXVK Async shader compilation", this);
312 connect(dxvkAsyncCheck_, &QCheckBox::toggled, this,
313 &PerformanceProfileDialog::onSettingsChanged);
314 wineLayout->addWidget(dxvkAsyncCheck_);
315
316 dxvkHudCheck_ = new QCheckBox("DXVK HUD (show Vulkan stats)", this);
317 connect(dxvkHudCheck_, &QCheckBox::toggled, this, &PerformanceProfileDialog::onSettingsChanged);
318 wineLayout->addWidget(dxvkHudCheck_);
319
320 contentLayout->addWidget(wineGroup_);
321
322 // Environment variables
323 envGroup_ = new QGroupBox("Custom Environment Variables", this);
324 auto* envLayout = new QVBoxLayout(envGroup_);
325
326 auto* envHint = new QLabel("One variable per line: VAR_NAME=value", this);
327 envHint->setStyleSheet("color: gray; font-size: 11px;");
328 envLayout->addWidget(envHint);
329
330 envVarsEdit_ = new QTextEdit(this);
331 envVarsEdit_->setMaximumHeight(80);
332 envVarsEdit_->setPlaceholderText("MESA_GL_VERSION_OVERRIDE=4.6\nDXVK_ASYNC=1");
333 connect(envVarsEdit_, &QTextEdit::textChanged, this,
334 &PerformanceProfileDialog::onSettingsChanged);
335 envLayout->addWidget(envVarsEdit_);
336
337 contentLayout->addWidget(envGroup_);
338
339 contentLayout->addStretch();
340
341 scrollArea->setWidget(scrollContent);
342 editorLayout->addWidget(scrollArea);
343}
344
345// ==============================================================================
346// Profile List Management
347// ==============================================================================
348
349void PerformanceProfileDialog::refreshProfileList()
350{
351 profileList_->clear();
352
353 if (!profileService_)
354 return;
355
356 std::vector<PerformanceProfile> profiles;
357
358 if (isGlobalMode_)
359 {
360 if (gameId_.empty())
361 {
362 // Show global profiles
363 profiles = profileService_->getGlobalProfiles();
364 }
365 else
366 {
367 profiles = profileService_->getProfiles(gameId_);
368 }
369 }
370 else if (!gameId_.empty())
371 {
372 profiles = profileService_->getProfiles(gameId_);
373 }
374
375 // Get active profile ID
376 std::string activeId;
377 if (!gameId_.empty())
378 {
379 auto active = profileService_->getActiveProfile(gameId_);
380 if (active)
381 {
382 activeId = active->id;
383 }
384 }
385
386 for (const auto& profile : profiles)
387 {
388 auto* item = new QListWidgetItem(QString::fromStdString(profile.name));
389 item->setData(Qt::UserRole, QString::fromStdString(profile.id));
390
391 if (profile.id == activeId)
392 {
393 item->setText(QString::fromStdString(profile.name) + " ★");
394 auto font = item->font();
395 font.setBold(true);
396 item->setFont(font);
397 }
398
399 profileList_->addItem(item);
400 }
401
402 updateButtonStates();
403}
404
405void PerformanceProfileDialog::loadProfileSettings(const std::string& profileId)
406{
407 if (!profileService_ || profileId.empty())
408 return;
409
410 std::optional<PerformanceProfile> profile;
411
412 if (isGlobalMode_ && gameId_.empty())
413 {
414 // Look in global profiles
415 auto globals = profileService_->getGlobalProfiles();
416 for (const auto& p : globals)
417 {
418 if (p.id == profileId)
419 {
420 profile = p;
421 break;
422 }
423 }
424 }
425 else
426 {
427 profile = profileService_->getProfile(gameId_.empty() ? "__global__" : gameId_, profileId);
428 }
429
430 if (!profile)
431 return;
432
433 // Block signals while loading
434 nameEdit_->blockSignals(true);
435 descEdit_->blockSignals(true);
436
437 nameEdit_->setText(QString::fromStdString(profile->name));
438 descEdit_->setText(QString::fromStdString(profile->description));
439
440 // Wrapper settings (MangoHud, GameMode, etc.)
441 mangoHudCheck_->setChecked(profile->wrappers.enableMangoHud);
442 gameModCheck_->setChecked(profile->wrappers.enableGameMode);
443 gamescopeCheck_->setChecked(profile->framerate.useGamescope);
444 vkbasaltCheck_->setChecked(profile->wrappers.enableVkBasalt);
445
446 // Gamescope settings
447 gamescopeGroup_->setEnabled(profile->framerate.useGamescope);
448 gamescopeWidthSpin_->setValue(
449 profile->scaling.internalWidth > 0 ? profile->scaling.internalWidth : 1920);
450 gamescopeHeightSpin_->setValue(
451 profile->scaling.internalHeight > 0 ? profile->scaling.internalHeight : 1080);
452 gamescopeFullscreenCheck_->setChecked(true); // Default to fullscreen
453 gamescopeBorderlessCheck_->setChecked(false);
454 gamescopeFpsLimitSpin_->setValue(profile->framerate.fpsLimit);
455
456 // Sync settings (Wine/Proton)
457 fsyncCheck_->setChecked(profile->sync.enableFsync);
458 esyncCheck_->setChecked(profile->sync.enableEsync);
459 ntsyncCheck_->setChecked(profile->sync.enableNTSync);
460 // DXVK settings are in environment variables - check for them
461 dxvkAsyncCheck_->setChecked(profile->environmentVariables.count("DXVK_ASYNC") > 0);
462 dxvkHudCheck_->setChecked(profile->environmentVariables.count("DXVK_HUD") > 0);
463
464 // Environment variables
465 QString envText;
466 for (const auto& [key, value] : profile->environmentVariables)
467 {
468 // Skip DXVK settings that have dedicated checkboxes
469 if (key == "DXVK_ASYNC" || key == "DXVK_HUD")
470 continue;
471 envText += QString::fromStdString(key) + "=" + QString::fromStdString(value) + "\n";
472 }
473 envVarsEdit_->setText(envText.trimmed());
474
475 nameEdit_->blockSignals(false);
476 descEdit_->blockSignals(false);
477
478 isDirty_ = false;
479 presetCombo_->setCurrentIndex(0); // Custom
480}
481
482void PerformanceProfileDialog::saveCurrentProfile()
483{
484 if (!profileService_ || currentProfileId_.empty())
485 return;
486
487 auto profile = buildProfileFromUI();
488 profile.id = currentProfileId_;
489
490 // Update profile (global profiles use special game ID "__global__")
491 profileService_->updateProfile(isGlobalMode_ && gameId_.empty() ? "__global__" : gameId_,
492 profile);
493
494 isDirty_ = false;
495 refreshProfileList();
496
497 // Re-select the same profile
498 for (int i = 0; i < profileList_->count(); ++i)
499 {
500 if (profileList_->item(i)->data(Qt::UserRole).toString().toStdString() == currentProfileId_)
501 {
502 profileList_->setCurrentRow(i);
503 break;
504 }
505 }
506}
507
508PerformanceProfile PerformanceProfileDialog::buildProfileFromUI() const
509{
510 PerformanceProfile profile;
511
512 profile.name = nameEdit_->text().toStdString();
513 profile.description = descEdit_->toPlainText().toStdString();
514
515 // Wrapper settings (MangoHud, GameMode, VkBasalt)
516 profile.wrappers.enableMangoHud = mangoHudCheck_->isChecked();
517 profile.wrappers.enableGameMode = gameModCheck_->isChecked();
518 profile.wrappers.enableVkBasalt = vkbasaltCheck_->isChecked();
519
520 // Framerate and Gamescope settings
521 profile.framerate.useGamescope = gamescopeCheck_->isChecked();
522 profile.framerate.fpsLimit = gamescopeFpsLimitSpin_->value();
523
524 // Scaling settings (used by Gamescope)
525 profile.scaling.internalWidth = gamescopeWidthSpin_->value();
526 profile.scaling.internalHeight = gamescopeHeightSpin_->value();
527
528 // Sync settings (Wine/Proton)
529 profile.sync.enableFsync = fsyncCheck_->isChecked();
530 profile.sync.enableEsync = esyncCheck_->isChecked();
531 profile.sync.enableNTSync = ntsyncCheck_->isChecked();
532
533 // Environment variables
534 QString envText = envVarsEdit_->toPlainText();
535 for (const QString& line : envText.split('\n', Qt::SkipEmptyParts))
536 {
537 qsizetype eqPos = line.indexOf('=');
538 if (eqPos > 0)
539 {
540 QString key = line.left(static_cast<int>(eqPos)).trimmed();
541 QString value = line.mid(static_cast<int>(eqPos) + 1).trimmed();
542 profile.environmentVariables[key.toStdString()] = value.toStdString();
543 }
544 }
545
546 // Add DXVK settings as environment variables
547 if (dxvkAsyncCheck_->isChecked())
548 {
549 profile.environmentVariables["DXVK_ASYNC"] = "1";
550 }
551 if (dxvkHudCheck_->isChecked())
552 {
553 profile.environmentVariables["DXVK_HUD"] = "1";
554 }
555
556 return profile;
557}
558
559// ==============================================================================
560// Slots
561// ==============================================================================
562
563void PerformanceProfileDialog::onProfileSelected(QListWidgetItem* current,
564 QListWidgetItem* previous)
565{
566 Q_UNUSED(previous)
567
568 // Save previous if dirty
569 if (isDirty_ && !currentProfileId_.empty())
570 {
571 auto reply =
572 QMessageBox::question(this, "Save Changes", "Save changes to the current profile?",
573 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
574
575 if (reply == QMessageBox::Yes)
576 {
577 saveCurrentProfile();
578 }
579 else if (reply == QMessageBox::Cancel)
580 {
581 // Re-select previous item
582 for (int i = 0; i < profileList_->count(); ++i)
583 {
584 if (profileList_->item(i)->data(Qt::UserRole).toString().toStdString() ==
585 currentProfileId_)
586 {
587 profileList_->blockSignals(true);
588 profileList_->setCurrentRow(i);
589 profileList_->blockSignals(false);
590 return;
591 }
592 }
593 }
594 }
595
596 if (!current)
597 {
598 currentProfileId_.clear();
599 editorPanel_->setEnabled(false);
600 updateButtonStates();
601 return;
602 }
603
604 currentProfileId_ = current->data(Qt::UserRole).toString().toStdString();
605 editorPanel_->setEnabled(true);
606 loadProfileSettings(currentProfileId_);
607 updateButtonStates();
608}
609
610void PerformanceProfileDialog::onCreateProfile()
611{
612 if (!profileService_)
613 return;
614
615 // Generate unique name
616 QString baseName = "New Profile";
617 int counter = 1;
618 QString name = baseName;
619
620 auto existingProfiles = isGlobalMode_ && gameId_.empty()
621 ? profileService_->getGlobalProfiles()
622 : profileService_->getProfiles(gameId_);
623
624 while (true)
625 {
626 bool exists = false;
627 for (const auto& p : existingProfiles)
628 {
629 if (p.name == name.toStdString())
630 {
631 exists = true;
632 break;
633 }
634 }
635 if (!exists)
636 break;
637 name = QString("%1 %2").arg(baseName).arg(++counter);
638 }
639
640 // Create default profile
641 auto profile = profileService_->getDefaultProfile();
642 profile.id = QUuid::createUuid().toString(QUuid::WithoutBraces).toStdString();
643 profile.name = name.toStdString();
644
645 bool success = false;
646 if (isGlobalMode_ && gameId_.empty())
647 {
648 success = profileService_->createGlobalProfile(profile);
649 }
650 else
651 {
652 success = profileService_->createProfile(gameId_, profile);
653 }
654
655 if (success)
656 {
657 refreshProfileList();
658
659 // Select the new profile
660 for (int i = 0; i < profileList_->count(); ++i)
661 {
662 if (profileList_->item(i)->data(Qt::UserRole).toString().toStdString() == profile.id)
663 {
664 profileList_->setCurrentRow(i);
665 nameEdit_->selectAll();
666 nameEdit_->setFocus();
667 break;
668 }
669 }
670 }
671}
672
673void PerformanceProfileDialog::onDeleteProfile()
674{
675 if (!profileService_ || currentProfileId_.empty())
676 return;
677
678 auto reply = QMessageBox::question(this, "Delete Profile",
679 QString("Delete profile '%1'?").arg(nameEdit_->text()),
680 QMessageBox::Yes | QMessageBox::No);
681
682 if (reply != QMessageBox::Yes)
683 return;
684
685 // Delete the profile (global profiles use the same API with special game ID)
686 bool success = profileService_->deleteProfile(
687 isGlobalMode_ && gameId_.empty() ? "__global__" : gameId_, currentProfileId_);
688
689 if (success)
690 {
691 currentProfileId_.clear();
692 isDirty_ = false;
693 refreshProfileList();
694 }
695}
696
697void PerformanceProfileDialog::onApplyProfile()
698{
699 if (!profileService_ || currentProfileId_.empty() || gameId_.empty())
700 return;
701
702 // Save any pending changes
703 if (isDirty_)
704 {
705 saveCurrentProfile();
706 }
707
708 // Set as active profile
709 profileService_->setActiveProfile(gameId_, currentProfileId_);
710
711 emit profileApplied(gameId_, currentProfileId_);
712
713 refreshProfileList();
714
715 QMessageBox::information(
716 this, "Profile Applied",
717 QString("Profile '%1' is now active for this game.").arg(nameEdit_->text()));
718}
719
720void PerformanceProfileDialog::onPresetSelected(int index)
721{
722 if (!profileService_ || index <= 0)
723 return; // 0 = Custom
724
725 int presetType = presetCombo_->itemData(index).toInt();
726 if (presetType < 0)
727 return;
728
729 auto preset = profileService_->createFromPreset(static_cast<PerformancePreset>(presetType));
730
731 // Apply preset values to UI (keeping name/description)
732 mangoHudCheck_->setChecked(preset.wrappers.enableMangoHud);
733 gameModCheck_->setChecked(preset.wrappers.enableGameMode);
734 gamescopeCheck_->setChecked(preset.framerate.useGamescope);
735 vkbasaltCheck_->setChecked(preset.wrappers.enableVkBasalt);
736
737 fsyncCheck_->setChecked(preset.sync.enableFsync);
738 esyncCheck_->setChecked(preset.sync.enableEsync);
739 ntsyncCheck_->setChecked(preset.sync.enableNTSync);
740
741 // DXVK settings from environment variables
742 dxvkAsyncCheck_->setChecked(preset.environmentVariables.count("DXVK_ASYNC") > 0);
743 dxvkHudCheck_->setChecked(preset.environmentVariables.count("DXVK_HUD") > 0);
744
745 onSettingsChanged();
746}
747
748void PerformanceProfileDialog::onSettingsChanged()
749{
750 isDirty_ = true;
751 presetCombo_->setCurrentIndex(0); // Mark as custom
752 updateButtonStates();
753}
754
755void PerformanceProfileDialog::onGameSelected(int index)
756{
757 if (!gameCombo_)
758 return;
759
760 QString id = gameCombo_->itemData(index).toString();
761 gameId_ = id.toStdString();
762 refreshProfileList();
763}
764
765void PerformanceProfileDialog::updateButtonStates()
766{
767 bool hasSelection = !currentProfileId_.empty();
768 bool hasGame = !gameId_.empty();
769
770 deleteBtn_->setEnabled(hasSelection);
771 applyBtn_->setEnabled(hasSelection && hasGame);
772 editorPanel_->setEnabled(hasSelection);
773}
774
776{
777 return currentProfileId_;
778}
779
780// ==============================================================================
781// Theming
782// ==============================================================================
783
784void PerformanceProfileDialog::applyTheme()
785{
786 const ThemeColors& c = themeManager_->colors();
787
788 setStyleSheet(
789 QString("QDialog { background-color: %1; }"
790 "QGroupBox { font-weight: bold; border: 1px solid %2; border-radius: 4px; "
791 " margin-top: 8px; padding-top: 8px; }"
792 "QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 3px; }"
793 "QLineEdit, QTextEdit, QSpinBox, QComboBox { "
794 " background-color: %3; border: 1px solid %2; border-radius: 4px; padding: 4px; }"
795 "QLineEdit:focus, QTextEdit:focus, QSpinBox:focus, QComboBox:focus { "
796 " border-color: %4; }"
797 "QPushButton { background-color: %5; border: 1px solid %2; border-radius: 4px; "
798 " padding: 6px 16px; }"
799 "QPushButton:hover { background-color: %6; border-color: %4; }"
800 "QPushButton:pressed { background-color: %4; }"
801 "QListWidget { background-color: %3; border: 1px solid %2; border-radius: 4px; }"
802 "QListWidget::item { padding: 6px; }"
803 "QListWidget::item:selected { background-color: %4; color: %7; }"
804 "QCheckBox { spacing: 6px; }"
805 "QScrollArea { border: none; }")
806 .arg(c.windowBackground.name()) // %1
807 .arg(c.border.name()) // %2
808 .arg(c.inputBackground.name()) // %3
809 .arg(c.accent.name()) // %4
810 .arg(c.cardBackground.name()) // %5
811 .arg(c.hoverBackground.name()) // %6
812 .arg(c.textOnAccent.name()) // %7
813 );
814
815 // Style the apply button with accent
816 applyBtn_->setStyleSheet(
817 QString("QPushButton { background-color: %1; color: %2; font-weight: bold; }"
818 "QPushButton:hover { background-color: %3; }"
819 "QPushButton:disabled { background-color: %4; color: %5; }")
820 .arg(c.accent.name())
821 .arg(c.textOnAccent.name())
822 .arg(c.accentHover.name())
823 .arg(c.inputBackground.name())
824 .arg(c.textMuted.name()));
825}
Complete representation of a game in the library.
Definition game.h:767
std::string name
Display name shown in UI.
Definition game.h:774
~PerformanceProfileDialog() override
void profileApplied(const std::string &gameId, const std::string &profileId)
Emitted when a profile is applied to a game.
PerformanceProfileDialog(const Game *game, PerformanceProfileService *profileService, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
Construct a profile dialog for a specific game.
std::string getSelectedProfileId() const
Get the currently selected profile ID.
Service for managing per-game performance profiles.
void themeChanged()
Emitted when theme or accent color changes.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
std::vector< Game * > getAllGames()
Get all games (non-const for process tracking).
PerformancePreset
Built-in performance presets.
int fpsLimit
FPS limit (0 = unlimited).
bool useGamescope
Use Gamescope compositor.
Complete performance profile for a game.
std::string description
Optional description.
std::string id
Unique profile ID.
std::map< std::string, std::string > environmentVariables
std::string name
Display name (e.g., "High Performance").
int internalWidth
Internal render width (0 = native).
int internalHeight
Internal render height (0 = native).
bool enableNTSync
Use NTSync (experimental, kernel 6.14+).
bool enableEsync
Use Esync if Fsync unavailable.
bool enableFsync
Use Fsync if available.
QColor inputBackground
QColor cardBackground
QColor accentHover
QColor windowBackground
QColor textMuted
QColor hoverBackground
QColor textOnAccent
bool enableGameMode
Feral GameMode.
bool enableVkBasalt
VkBasalt post-processing.
bool enableMangoHud
MangoHud overlay.