summaryrefslogtreecommitdiff
path: root/src/yuzu/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r--src/yuzu/main.cpp254
1 files changed, 202 insertions, 52 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index c55f81c2f..f233b065e 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -219,7 +219,7 @@ static void LogRuntimes() {
#ifdef _MSC_VER
// It is possible that the name of the dll will change.
// vcruntime140.dll is for 2015 and onwards
- constexpr char runtime_dll_name[] = "vcruntime140.dll";
+ static constexpr char runtime_dll_name[] = "vcruntime140.dll";
UINT sz = GetFileVersionInfoSizeA(runtime_dll_name, nullptr);
bool runtime_version_inspection_worked = false;
if (sz > 0) {
@@ -680,8 +680,10 @@ void GMainWindow::SoftwareKeyboardShowNormal() {
const auto y = layout.screen.top;
const auto w = layout.screen.GetWidth();
const auto h = layout.screen.GetHeight();
+ const auto scale_ratio = devicePixelRatioF();
- software_keyboard->ShowNormalKeyboard(render_window->mapToGlobal(QPoint(x, y)), QSize(w, h));
+ software_keyboard->ShowNormalKeyboard(render_window->mapToGlobal(QPoint(x, y) / scale_ratio),
+ QSize(w, h) / scale_ratio);
}
void GMainWindow::SoftwareKeyboardShowTextCheck(
@@ -714,9 +716,11 @@ void GMainWindow::SoftwareKeyboardShowInline(
(1.0f - appear_parameters.key_top_scale_y))));
const auto w = static_cast<int>(layout.screen.GetWidth() * appear_parameters.key_top_scale_x);
const auto h = static_cast<int>(layout.screen.GetHeight() * appear_parameters.key_top_scale_y);
+ const auto scale_ratio = devicePixelRatioF();
software_keyboard->ShowInlineKeyboard(std::move(appear_parameters),
- render_window->mapToGlobal(QPoint(x, y)), QSize(w, h));
+ render_window->mapToGlobal(QPoint(x, y) / scale_ratio),
+ QSize(w, h) / scale_ratio);
}
void GMainWindow::SoftwareKeyboardHideInline() {
@@ -796,9 +800,12 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url,
}
const auto& layout = render_window->GetFramebufferLayout();
- web_browser_view.resize(layout.screen.GetWidth(), layout.screen.GetHeight());
- web_browser_view.move(layout.screen.left, layout.screen.top + menuBar()->height());
- web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth()) /
+ const auto scale_ratio = devicePixelRatioF();
+ web_browser_view.resize(layout.screen.GetWidth() / scale_ratio,
+ layout.screen.GetHeight() / scale_ratio);
+ web_browser_view.move(layout.screen.left / scale_ratio,
+ (layout.screen.top / scale_ratio) + menuBar()->height());
+ web_browser_view.setZoomFactor(static_cast<qreal>(layout.screen.GetWidth() / scale_ratio) /
static_cast<qreal>(Layout::ScreenUndocked::Width));
web_browser_view.setFocus();
@@ -957,6 +964,38 @@ void GMainWindow::InitializeWidgets() {
tas_label->setFocusPolicy(Qt::NoFocus);
statusBar()->insertPermanentWidget(0, tas_label);
+ volume_popup = new QWidget(this);
+ volume_popup->setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup);
+ volume_popup->setLayout(new QVBoxLayout());
+ volume_popup->setMinimumWidth(200);
+
+ volume_slider = new QSlider(Qt::Horizontal);
+ volume_slider->setObjectName(QStringLiteral("volume_slider"));
+ volume_slider->setMaximum(200);
+ volume_slider->setPageStep(5);
+ connect(volume_slider, &QSlider::valueChanged, this, [this](int percentage) {
+ Settings::values.audio_muted = false;
+ const auto volume = static_cast<u8>(percentage);
+ Settings::values.volume.SetValue(volume);
+ UpdateVolumeUI();
+ });
+ volume_popup->layout()->addWidget(volume_slider);
+
+ volume_button = new QPushButton();
+ volume_button->setObjectName(QStringLiteral("TogglableStatusBarButton"));
+ volume_button->setFocusPolicy(Qt::NoFocus);
+ volume_button->setCheckable(true);
+ UpdateVolumeUI();
+ connect(volume_button, &QPushButton::clicked, this, [&] {
+ UpdateVolumeUI();
+ volume_popup->setVisible(!volume_popup->isVisible());
+ QRect rect = volume_button->geometry();
+ QPoint bottomLeft = statusBar()->mapToGlobal(rect.topLeft());
+ bottomLeft.setY(bottomLeft.y() - volume_popup->geometry().height());
+ volume_popup->setGeometry(QRect(bottomLeft, QSize(rect.width(), rect.height())));
+ });
+ statusBar()->insertPermanentWidget(0, volume_button);
+
// setup AA button
aa_status_button = new QPushButton();
aa_status_button->setObjectName(QStringLiteral("TogglableStatusBarButton"));
@@ -983,11 +1022,6 @@ void GMainWindow::InitializeWidgets() {
filter_status_button->setFocusPolicy(Qt::NoFocus);
connect(filter_status_button, &QPushButton::clicked, this,
&GMainWindow::OnToggleAdaptingFilter);
- auto filter = Settings::values.scaling_filter.GetValue();
- if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL &&
- filter == Settings::ScalingFilter::Fsr) {
- Settings::values.scaling_filter.SetValue(Settings::ScalingFilter::NearestNeighbor);
- }
UpdateFilterText();
filter_status_button->setCheckable(true);
filter_status_button->setChecked(true);
@@ -1124,34 +1158,21 @@ void GMainWindow::InitializeHotkeys() {
&GMainWindow::OnToggleAdaptingFilter);
connect_shortcut(QStringLiteral("Change Docked Mode"), &GMainWindow::OnToggleDockedMode);
connect_shortcut(QStringLiteral("Change GPU Accuracy"), &GMainWindow::OnToggleGpuAccuracy);
- connect_shortcut(QStringLiteral("Audio Mute/Unmute"),
- [] { Settings::values.audio_muted = !Settings::values.audio_muted; });
- connect_shortcut(QStringLiteral("Audio Volume Down"), [] {
- const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
- int step = 5;
- if (current_volume <= 30) {
- step = 2;
- }
- if (current_volume <= 6) {
- step = 1;
- }
- Settings::values.volume.SetValue(std::max(current_volume - step, 0));
- });
- connect_shortcut(QStringLiteral("Audio Volume Up"), [] {
- const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
- int step = 5;
- if (current_volume < 30) {
- step = 2;
- }
- if (current_volume < 6) {
- step = 1;
- }
- Settings::values.volume.SetValue(current_volume + step);
- });
+ connect_shortcut(QStringLiteral("Audio Mute/Unmute"), &GMainWindow::OnMute);
+ connect_shortcut(QStringLiteral("Audio Volume Down"), &GMainWindow::OnDecreaseVolume);
+ connect_shortcut(QStringLiteral("Audio Volume Up"), &GMainWindow::OnIncreaseVolume);
connect_shortcut(QStringLiteral("Toggle Framerate Limit"), [] {
Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue());
});
connect_shortcut(QStringLiteral("Toggle Mouse Panning"), [&] {
+ if (Settings::values.mouse_enabled) {
+ Settings::values.mouse_panning = false;
+ QMessageBox::warning(
+ this, tr("Emulated mouse is enabled"),
+ tr("Real mouse input and mouse panning are incompatible. Please disable the "
+ "emulated mouse in input advanced settings to allow mouse panning."));
+ return;
+ }
Settings::values.mouse_panning = !Settings::values.mouse_panning;
if (Settings::values.mouse_panning) {
render_window->installEventFilter(render_window);
@@ -1258,6 +1279,7 @@ void GMainWindow::ConnectWidgetEvents() {
connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList);
connect(game_list, &GameList::PopulatingCompleted,
[this] { multiplayer_state->UpdateGameList(game_list->GetModel()); });
+ connect(game_list, &GameList::SaveConfig, this, &GMainWindow::OnSaveConfig);
connect(game_list, &GameList::OpenPerGameGeneralRequested, this,
&GMainWindow::OnGameListOpenPerGameProperties);
@@ -1766,7 +1788,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
std::filesystem::path{Common::U16StringFromBuffer(filename.utf16(), filename.size())}
.filename());
}
- const bool is_64bit = system->Kernel().CurrentProcess()->Is64BitProcess();
+ const bool is_64bit = system->Kernel().ApplicationProcess()->Is64BitProcess();
const auto instruction_set_suffix = is_64bit ? tr("(64-bit)") : tr("(32-bit)");
title_name = tr("%1 %2", "%1 is the title name. %2 indicates if the title is 64-bit or 32-bit")
.arg(QString::fromStdString(title_name), instruction_set_suffix)
@@ -1839,9 +1861,11 @@ void GMainWindow::OnEmulationStopTimeExpired() {
void GMainWindow::OnEmulationStopped() {
shutdown_timer.stop();
- emu_thread->disconnect();
- emu_thread->wait();
- emu_thread = nullptr;
+ if (emu_thread) {
+ emu_thread->disconnect();
+ emu_thread->wait();
+ emu_thread.reset();
+ }
if (shutdown_dialog) {
shutdown_dialog->deleteLater();
@@ -2639,6 +2663,8 @@ void GMainWindow::OnGameListAddDirectory() {
} else {
LOG_WARNING(Frontend, "Selected directory is already in the game list");
}
+
+ OnSaveConfig();
}
void GMainWindow::OnGameListShowList(bool show) {
@@ -2756,8 +2782,7 @@ void GMainWindow::OnMenuInstallToNAND() {
ui->action_Install_File_NAND->setEnabled(false);
install_progress = new QProgressDialog(QString{}, tr("Cancel"), 0, total_size, this);
- install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint &
- ~Qt::WindowMaximizeButtonHint);
+ install_progress->setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
install_progress->setAttribute(Qt::WA_DeleteOnClose, true);
install_progress->setFixedWidth(installDialog.GetMinimumWidth() + 40);
install_progress->show();
@@ -3001,8 +3026,10 @@ void GMainWindow::OnRestartGame() {
if (!system->IsPoweredOn()) {
return;
}
- // Make a copy since BootGame edits game_path
- BootGame(QString(current_game_path));
+ // Make a copy since ShutdownGame edits game_path
+ const auto current_game = QString(current_game_path);
+ ShutdownGame();
+ BootGame(current_game);
}
void GMainWindow::OnPauseGame() {
@@ -3029,6 +3056,8 @@ void GMainWindow::OnStopGame() {
if (OnShutdownBegin()) {
OnShutdownBeginDialog();
+ } else {
+ OnEmulationStopped();
}
}
@@ -3364,6 +3393,7 @@ void GMainWindow::OnConfigureTas() {
return;
} else if (result == QDialog::Accepted) {
dialog.ApplyConfiguration();
+ OnSaveConfig();
}
}
@@ -3458,6 +3488,39 @@ void GMainWindow::OnToggleGpuAccuracy() {
UpdateGPUAccuracyButton();
}
+void GMainWindow::OnMute() {
+ Settings::values.audio_muted = !Settings::values.audio_muted;
+ UpdateVolumeUI();
+}
+
+void GMainWindow::OnDecreaseVolume() {
+ Settings::values.audio_muted = false;
+ const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
+ int step = 5;
+ if (current_volume <= 30) {
+ step = 2;
+ }
+ if (current_volume <= 6) {
+ step = 1;
+ }
+ Settings::values.volume.SetValue(std::max(current_volume - step, 0));
+ UpdateVolumeUI();
+}
+
+void GMainWindow::OnIncreaseVolume() {
+ Settings::values.audio_muted = false;
+ const auto current_volume = static_cast<s32>(Settings::values.volume.GetValue());
+ int step = 5;
+ if (current_volume < 30) {
+ step = 2;
+ }
+ if (current_volume < 6) {
+ step = 1;
+ }
+ Settings::values.volume.SetValue(current_volume + step);
+ UpdateVolumeUI();
+}
+
void GMainWindow::OnToggleAdaptingFilter() {
auto filter = Settings::values.scaling_filter.GetValue();
if (filter == Settings::ScalingFilter::LastFilter) {
@@ -3465,10 +3528,6 @@ void GMainWindow::OnToggleAdaptingFilter() {
} else {
filter = static_cast<Settings::ScalingFilter>(static_cast<u32>(filter) + 1);
}
- if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL &&
- filter == Settings::ScalingFilter::Fsr) {
- filter = Settings::ScalingFilter::NearestNeighbor;
- }
Settings::values.scaling_filter.SetValue(filter);
filter_status_button->setChecked(true);
UpdateFilterText();
@@ -3487,7 +3546,7 @@ void GMainWindow::OnToggleGraphicsAPI() {
}
void GMainWindow::OnConfigurePerGame() {
- const u64 title_id = system->GetCurrentProcessProgramID();
+ const u64 title_id = system->GetApplicationProcessProgramID();
OpenPerGameConfiguration(title_id, current_game_path.toStdString());
}
@@ -3646,7 +3705,7 @@ void GMainWindow::OnCaptureScreenshot() {
return;
}
- const u64 title_id = system->GetCurrentProcessProgramID();
+ const u64 title_id = system->GetApplicationProcessProgramID();
const auto screenshot_path =
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir));
const auto date =
@@ -3726,15 +3785,36 @@ void GMainWindow::UpdateWindowTitle(std::string_view title_name, std::string_vie
}
}
+std::string GMainWindow::CreateTASFramesString(
+ std::array<size_t, InputCommon::TasInput::PLAYER_NUMBER> frames) const {
+ std::string string = "";
+ size_t maxPlayerIndex = 0;
+ for (size_t i = 0; i < frames.size(); i++) {
+ if (frames[i] != 0) {
+ if (maxPlayerIndex != 0)
+ string += ", ";
+ while (maxPlayerIndex++ != i)
+ string += "0, ";
+ string += std::to_string(frames[i]);
+ }
+ }
+ return string;
+}
+
QString GMainWindow::GetTasStateDescription() const {
auto [tas_status, current_tas_frame, total_tas_frames] = input_subsystem->GetTas()->GetStatus();
+ std::string tas_frames_string = CreateTASFramesString(total_tas_frames);
switch (tas_status) {
case InputCommon::TasInput::TasState::Running:
- return tr("TAS state: Running %1/%2").arg(current_tas_frame).arg(total_tas_frames);
+ return tr("TAS state: Running %1/%2")
+ .arg(current_tas_frame)
+ .arg(QString::fromStdString(tas_frames_string));
case InputCommon::TasInput::TasState::Recording:
- return tr("TAS state: Recording %1").arg(total_tas_frames);
+ return tr("TAS state: Recording %1").arg(total_tas_frames[0]);
case InputCommon::TasInput::TasState::Stopped:
- return tr("TAS state: Idle %1/%2").arg(current_tas_frame).arg(total_tas_frames);
+ return tr("TAS state: Idle %1/%2")
+ .arg(current_tas_frame)
+ .arg(QString::fromStdString(tas_frames_string));
default:
return tr("TAS State: Invalid");
}
@@ -3899,6 +3979,18 @@ void GMainWindow::UpdateAAText() {
}
}
+void GMainWindow::UpdateVolumeUI() {
+ const auto volume_value = static_cast<int>(Settings::values.volume.GetValue());
+ volume_slider->setValue(volume_value);
+ if (Settings::values.audio_muted) {
+ volume_button->setChecked(false);
+ volume_button->setText(tr("VOLUME: MUTE"));
+ } else {
+ volume_button->setChecked(true);
+ volume_button->setText(tr("VOLUME: %1%", "Volume percentage (e.g. 50%)").arg(volume_value));
+ }
+}
+
void GMainWindow::UpdateStatusButtons() {
renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() ==
Settings::RendererBackend::Vulkan);
@@ -3907,6 +3999,7 @@ void GMainWindow::UpdateStatusButtons() {
UpdateDockedButton();
UpdateFilterText();
UpdateAAText();
+ UpdateVolumeUI();
}
void GMainWindow::UpdateUISettings() {
@@ -4376,6 +4469,55 @@ void GMainWindow::changeEvent(QEvent* event) {
#undef main
#endif
+static void SetHighDPIAttributes() {
+#ifdef _WIN32
+ // For Windows, we want to avoid scaling artifacts on fractional scaling ratios.
+ // This is done by setting the optimal scaling policy for the primary screen.
+
+ // Create a temporary QApplication.
+ int temp_argc = 0;
+ char** temp_argv = nullptr;
+ QApplication temp{temp_argc, temp_argv};
+
+ // Get the current screen geometry.
+ const QScreen* primary_screen = QGuiApplication::primaryScreen();
+ if (primary_screen == nullptr) {
+ return;
+ }
+
+ const QRect screen_rect = primary_screen->geometry();
+ const int real_width = screen_rect.width();
+ const int real_height = screen_rect.height();
+ const float real_ratio = primary_screen->logicalDotsPerInch() / 96.0f;
+
+ // Recommended minimum width and height for proper window fit.
+ // Any screen with a lower resolution than this will still have a scale of 1.
+ constexpr float minimum_width = 1350.0f;
+ constexpr float minimum_height = 900.0f;
+
+ const float width_ratio = std::max(1.0f, real_width / minimum_width);
+ const float height_ratio = std::max(1.0f, real_height / minimum_height);
+
+ // Get the lower of the 2 ratios and truncate, this is the maximum integer scale.
+ const float max_ratio = std::trunc(std::min(width_ratio, height_ratio));
+
+ if (max_ratio > real_ratio) {
+ QApplication::setHighDpiScaleFactorRoundingPolicy(
+ Qt::HighDpiScaleFactorRoundingPolicy::Round);
+ } else {
+ QApplication::setHighDpiScaleFactorRoundingPolicy(
+ Qt::HighDpiScaleFactorRoundingPolicy::Floor);
+ }
+#else
+ // Other OSes should be better than Windows at fractional scaling.
+ QApplication::setHighDpiScaleFactorRoundingPolicy(
+ Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
+#endif
+
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+}
+
int main(int argc, char* argv[]) {
std::unique_ptr<Config> config = std::make_unique<Config>();
bool has_broken_vulkan = false;
@@ -4431,8 +4573,16 @@ int main(int argc, char* argv[]) {
}
#endif
+ SetHighDPIAttributes();
+
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ // Disables the "?" button on all dialogs. Disabled by default on Qt6.
+ QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
+#endif
+
// Enables the core to make the qt created contexts current on std::threads
QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
+
QApplication app(argc, argv);
#ifdef _WIN32