summaryrefslogtreecommitdiffstats
path: root/src/yuzu/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu/main.cpp')
-rw-r--r--src/yuzu/main.cpp174
1 files changed, 144 insertions, 30 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 42b7b64c8..f28268e9b 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -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,10 +800,11 @@ 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()) /
- static_cast<qreal>(Layout::ScreenUndocked::Width));
+ 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.setFocus();
web_browser_view.show();
@@ -957,6 +962,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"));
@@ -1119,30 +1156,9 @@ 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());
});
@@ -3456,6 +3472,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) {
@@ -3914,6 +3963,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);
@@ -3922,6 +3983,7 @@ void GMainWindow::UpdateStatusButtons() {
UpdateDockedButton();
UpdateFilterText();
UpdateAAText();
+ UpdateVolumeUI();
}
void GMainWindow::UpdateUISettings() {
@@ -4391,6 +4453,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;
@@ -4446,6 +4557,8 @@ 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);
@@ -4453,6 +4566,7 @@ int main(int argc, char* argv[]) {
// Enables the core to make the qt created contexts current on std::threads
QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
+
QApplication app(argc, argv);
#ifdef _WIN32