Add an option for different High DPI scaling
Closes #2884 Closes #2876 Closes #2819 Closes #492 Closes #2801 Closes #2876
This commit is contained in:
parent
1656256f58
commit
601e2d1175
|
@ -90,6 +90,7 @@ void SettingsDialog::LoadSettings()
|
|||
settings.guiDisableAutoComplete = false;
|
||||
settings.guiAutoFollowInStack = false;
|
||||
settings.guiHideSeasonalIcons = false;
|
||||
settings.guiEnableQtHighDpiScaling = true;
|
||||
|
||||
//Events tab
|
||||
GetSettingBool("Events", "SystemBreakpoint", &settings.eventSystemBreakpoint);
|
||||
|
@ -305,6 +306,8 @@ void SettingsDialog::LoadSettings()
|
|||
GetSettingBool("Gui", "ShowExitConfirmation", &settings.guiShowExitConfirmation);
|
||||
GetSettingBool("Gui", "DisableAutoComplete", &settings.guiDisableAutoComplete);
|
||||
GetSettingBool("Gui", "AutoFollowInStack", &settings.guiAutoFollowInStack);
|
||||
GetSettingBool("Gui", "NoSeasons", &settings.guiHideSeasonalIcons);
|
||||
GetSettingBool("Gui", "EnableQtHighDpiScaling", &settings.guiEnableQtHighDpiScaling);
|
||||
ui->chkFpuRegistersLittleEndian->setChecked(settings.guiFpuRegistersLittleEndian);
|
||||
ui->chkSaveColumnOrder->setChecked(settings.guiSaveColumnOrder);
|
||||
ui->chkNoCloseDialog->setChecked(settings.guiNoCloseDialog);
|
||||
|
@ -317,6 +320,9 @@ void SettingsDialog::LoadSettings()
|
|||
ui->chkShowExitConfirmation->setChecked(settings.guiShowExitConfirmation);
|
||||
ui->chkDisableAutoComplete->setChecked(settings.guiDisableAutoComplete);
|
||||
ui->chkAutoFollowInStack->setChecked(settings.guiAutoFollowInStack);
|
||||
ui->chkHideSeasonalIcons->setChecked(settings.guiHideSeasonalIcons);
|
||||
ui->chkHideSeasonalIcons->setVisible(isSeasonal());
|
||||
ui->chkQtHighDpiScaling->setChecked(settings.guiEnableQtHighDpiScaling);
|
||||
|
||||
//Misc tab
|
||||
if(DbgFunctions()->GetJit)
|
||||
|
@ -383,14 +389,11 @@ void SettingsDialog::LoadSettings()
|
|||
GetSettingBool("Misc", "QueryProcessCookie", &settings.miscQueryProcessCookie);
|
||||
GetSettingBool("Misc", "QueryWorkingSet", &settings.miscQueryWorkingSet);
|
||||
GetSettingBool("Misc", "TransparentExceptionStepping", &settings.miscTransparentExceptionStepping);
|
||||
GetSettingBool("Misc", "NoSeasons", &settings.guiHideSeasonalIcons);
|
||||
ui->chkUtf16LogRedirect->setChecked(settings.miscUtf16LogRedirect);
|
||||
ui->chkUseLocalHelpFile->setChecked(settings.miscUseLocalHelpFile);
|
||||
ui->chkQueryProcessCookie->setChecked(settings.miscQueryProcessCookie);
|
||||
ui->chkQueryWorkingSet->setChecked(settings.miscQueryWorkingSet);
|
||||
ui->chkTransparentExceptionStepping->setChecked(settings.miscTransparentExceptionStepping);
|
||||
ui->chkHideSeasonalIcons->setChecked(settings.guiHideSeasonalIcons);
|
||||
ui->chkHideSeasonalIcons->setVisible(isSeasonal());
|
||||
}
|
||||
|
||||
void SettingsDialog::SaveSettings()
|
||||
|
@ -478,6 +481,8 @@ void SettingsDialog::SaveSettings()
|
|||
BridgeSettingSetUint("Gui", "ShowExitConfirmation", settings.guiShowExitConfirmation);
|
||||
BridgeSettingSetUint("Gui", "DisableAutoComplete", settings.guiDisableAutoComplete);
|
||||
BridgeSettingSetUint("Gui", "AutoFollowInStack", settings.guiAutoFollowInStack);
|
||||
BridgeSettingSetUint("Gui", "NoSeasons", settings.guiHideSeasonalIcons);
|
||||
BridgeSettingSetUint("Gui", "EnableQtHighDpiScaling", settings.guiEnableQtHighDpiScaling);
|
||||
|
||||
//Misc tab
|
||||
if(DbgFunctions()->GetJit)
|
||||
|
@ -508,7 +513,6 @@ void SettingsDialog::SaveSettings()
|
|||
BridgeSettingSetUint("Misc", "QueryProcessCookie", settings.miscQueryProcessCookie);
|
||||
BridgeSettingSetUint("Misc", "QueryWorkingSet", settings.miscQueryWorkingSet);
|
||||
BridgeSettingSetUint("Misc", "TransparentExceptionStepping", settings.miscTransparentExceptionStepping);
|
||||
BridgeSettingSetUint("Misc", "NoSeasons", settings.guiHideSeasonalIcons);
|
||||
|
||||
BridgeSettingFlush();
|
||||
Config()->load();
|
||||
|
@ -1188,3 +1192,9 @@ void SettingsDialog::on_chkTransparentExceptionStepping_toggled(bool checked)
|
|||
{
|
||||
settings.miscTransparentExceptionStepping = checked;
|
||||
}
|
||||
|
||||
void SettingsDialog::on_chkQtHighDpiScaling_toggled(bool checked)
|
||||
{
|
||||
settings.guiEnableQtHighDpiScaling = checked;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,8 @@ private slots:
|
|||
void on_chkQueryWorkingSet_toggled(bool checked);
|
||||
void on_chkTransparentExceptionStepping_toggled(bool checked);
|
||||
|
||||
void on_chkQtHighDpiScaling_toggled(bool checked);
|
||||
|
||||
private:
|
||||
//enums
|
||||
enum CalcType
|
||||
|
@ -238,6 +240,7 @@ private:
|
|||
bool guiDisableAutoComplete;
|
||||
bool guiAutoFollowInStack;
|
||||
bool guiHideSeasonalIcons;
|
||||
bool guiEnableQtHighDpiScaling;
|
||||
//Misc Tab
|
||||
bool miscSetJIT;
|
||||
bool miscSetJITAuto;
|
||||
|
|
|
@ -898,6 +898,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkQtHighDpiScaling">
|
||||
<property name="toolTip">
|
||||
<string>Disabling this option will tell Windows that x64dbg is DPI unaware. This might result in blurry results in some configurations.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Qt High DPI Scaling</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacerGUI">
|
||||
<property name="orientation">
|
||||
|
|
|
@ -287,6 +287,7 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
|
|||
guiBool.insert("CaseSensitiveAutoComplete", false);
|
||||
guiBool.insert("AutoRepeatOnEnter", false);
|
||||
guiBool.insert("AutoFollowInStack", true);
|
||||
guiBool.insert("EnableQtHighDpiScaling", true);
|
||||
//Named menu settings
|
||||
insertMenuBuilderBools(&guiBool, "CPUDisassembly", 50); //CPUDisassembly
|
||||
insertMenuBuilderBools(&guiBool, "CPUDump", 50); //CPUDump
|
||||
|
|
|
@ -293,7 +293,7 @@ static bool allowSeasons()
|
|||
{
|
||||
srand(GetTickCount());
|
||||
duint setting = 0;
|
||||
return !BridgeSettingGetUint("Misc", "NoSeasons", &setting) || !setting;
|
||||
return !BridgeSettingGetUint("Gui", "NoSeasons", &setting) || !setting;
|
||||
}
|
||||
|
||||
static bool isChristmas()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QTranslator>
|
||||
#include <QTextStream>
|
||||
#include <QLibraryInfo>
|
||||
#include <QDebug>
|
||||
#include "MiscUtil.h"
|
||||
|
||||
MyApplication::MyApplication(int & argc, char** argv)
|
||||
|
@ -73,31 +74,70 @@ static bool isValidLocale(const QString & locale)
|
|||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
enableHighDpiScaling()
|
||||
// This function doesn't appear to have any effect when Qt DPI scaling is enabled.
|
||||
// When scaling is disabled it drastically improves the results though.
|
||||
static void setDpiUnaware()
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiawarenesscontext
|
||||
static HMODULE user32 = LoadLibraryW(L"user32.dll");
|
||||
if(user32)
|
||||
typedef unsigned int(WINAPI * pfnSetProcessDpiAwarenessContext)(size_t value);
|
||||
static pfnSetProcessDpiAwarenessContext pSetProcessDpiAwarenessContext =
|
||||
(pfnSetProcessDpiAwarenessContext)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetProcessDpiAwarenessContext");
|
||||
if(pSetProcessDpiAwarenessContext)
|
||||
{
|
||||
typedef unsigned int(WINAPI * pfnSetProcessDpiAwarenessContext)(size_t value);
|
||||
static pfnSetProcessDpiAwarenessContext pSetProcessDpiAwarenessContext =
|
||||
(pfnSetProcessDpiAwarenessContext)GetProcAddress(user32, "SetProcessDpiAwarenessContext");
|
||||
if(pSetProcessDpiAwarenessContext)
|
||||
// It's unclear if there is any benefit to the GDI scaling, but it should work the best in theory.
|
||||
pSetProcessDpiAwarenessContext(/* DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED */ -5);
|
||||
if(GetLastError() == ERROR_INVALID_PARAMETER)
|
||||
{
|
||||
pSetProcessDpiAwarenessContext(/*DPI_AWARENESS_CONTEXT_SYSTEM_AWARE*/ -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Old windows version
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
// Fall back to unaware if the option doesn't exist.
|
||||
pSetProcessDpiAwarenessContext(/* DPI_AWARENESS_CONTEXT_UNAWARE */ -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Some resources:
|
||||
- https://www.programmersought.com/article/89186999411/
|
||||
- https://github.com/COVESA/dlt-viewer/issues/205
|
||||
- https://vicrucann.github.io/tutorials/osg-qt-high-dpi/
|
||||
- https://forum.freecadweb.org/viewtopic.php?t=52307
|
||||
- https://wiki.freecadweb.org/HiDPI_support
|
||||
- https://doc.qt.io/qt-5/highdpi.html#high-dpi-support-in-qt
|
||||
*/
|
||||
static void handleHighDpiScaling()
|
||||
{
|
||||
// If the user messes with the Qt environment variables, do not set anything
|
||||
if(qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO") // legacy in 5.6, but still functional
|
||||
|| qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR")
|
||||
|| qEnvironmentVariableIsSet("QT_SCALE_FACTOR")
|
||||
|| qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")
|
||||
|| qEnvironmentVariableIsSet("QT_ENABLE_HIGHDPI_SCALING")
|
||||
|| qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY"))
|
||||
{
|
||||
qDebug() << "Detected environment variables related to Qt scaling, skipping High DPI handling";
|
||||
return;
|
||||
}
|
||||
|
||||
duint enableQtHighDpiScaling = true;
|
||||
BridgeSettingGetUint("Gui", "EnableQtHighDpiScaling", &enableQtHighDpiScaling);
|
||||
|
||||
if(enableQtHighDpiScaling)
|
||||
{
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This enables Windows scaling the application automatically
|
||||
setDpiUnaware();
|
||||
|
||||
// These options don't seem to do anything, but the Qt documentation recommends it
|
||||
putenv("QT_AUTO_SCREEN_SCALE_FACTOR=1");
|
||||
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
enableHighDpiScaling();
|
||||
handleHighDpiScaling();
|
||||
MyApplication application(argc, argv);
|
||||
MainWindow::loadSelectedStyle(true);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
|
|
Loading…
Reference in New Issue