mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-25 00:00:36 +01:00
main: Enable High DPI fixes for Qt >= 5.14 (#6262)
Fixes https://github.com/citra-emu/citra/issues/4175 Fixes https://github.com/citra-emu/citra/issues/4977
This commit is contained in:
parent
6bef34852c
commit
5eb72e9489
@ -2663,6 +2663,55 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
|
|||||||
#undef main
|
#undef main
|
||||||
#endif
|
#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[]) {
|
int main(int argc, char* argv[]) {
|
||||||
Common::DetachedTasks detached_tasks;
|
Common::DetachedTasks detached_tasks;
|
||||||
MicroProfileOnThreadCreate("Frontend");
|
MicroProfileOnThreadCreate("Frontend");
|
||||||
@ -2680,6 +2729,8 @@ int main(int argc, char* argv[]) {
|
|||||||
format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
|
format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
|
||||||
QSurfaceFormat::setDefaultFormat(format);
|
QSurfaceFormat::setDefaultFormat(format);
|
||||||
|
|
||||||
|
SetHighDPIAttributes();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
|
std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
|
||||||
chdir(bin_path.c_str());
|
chdir(bin_path.c_str());
|
||||||
|
Loading…
Reference in New Issue
Block a user