frontend: Improve High DPI support and scaling

This patch enhances High DPI support across the Qt frontend with the following improvements:

**Windows DPI Awareness:**
- Add shellscalingapi.h include for Windows DPI functions
- Implement Per Monitor DPI Awareness (Windows 8.1+) and Per Monitor v2 DPI Awareness (Windows 10+)
- Use SetProcessDPIAware() and SetProcessDpiAwareness() for better multi-monitor scaling
- Dynamically load shcore.dll to access modern DPI awareness APIs

**Configuration Dialog Enhancements:**
- Add comprehensive High DPI responsive CSS media queries for different DPI levels (192dpi, 240dpi)
- Scale UI elements (buttons, comboboxes, line edits, checkboxes, radio buttons) based on screen DPI
- Improve scroll area styling with proper scrollbar theming for high DPI displays
- Set proper window attributes for scaling (WA_TranslucentBackground, WA_NoSystemBackground)
- Calculate logical window size based on device pixel ratio for accurate scaling

**UI Improvements:**
- Enhanced scroll area styling with custom scrollbar appearance
- Better visual feedback with hover effects on scrollbar handles
- Improved spacing and sizing for high DPI displays
- Set proper window modality and title for configuration dialog

These changes provide better visual quality and usability on high DPI displays, particularly on Windows systems with multiple monitors or high-resolution screens. The scaling is now more accurate and consistent across different display configurations.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
Zephyron
2025-07-22 16:30:47 +10:00
parent bd6dd7f0ff
commit f5bea18fd9
3 changed files with 169 additions and 3 deletions

View File

@@ -183,6 +183,7 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
#ifdef _WIN32
#include <windows.h>
#include <shellscalingapi.h>
extern "C" {
// tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
// graphics
@@ -5252,8 +5253,29 @@ static void SetHighDPIAttributes() {
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
// Enable high DPI scaling and pixmaps
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
// Set the DPI awareness for better scaling on Windows
#ifdef _WIN32
// Enable Per Monitor DPI Awareness for Windows 8.1+
SetProcessDPIAware();
// For Windows 10+, use Per Monitor v2 DPI Awareness
// This provides better scaling for multi-monitor setups
HMODULE shcore = LoadLibrary(L"shcore.dll");
if (shcore) {
typedef HRESULT(WINAPI* SetProcessDpiAwarenessFunc)(int);
SetProcessDpiAwarenessFunc setProcessDpiAwareness =
(SetProcessDpiAwarenessFunc)GetProcAddress(shcore, "SetProcessDpiAwareness");
if (setProcessDpiAwareness) {
// PROCESS_PER_MONITOR_DPI_AWARE_V2 = 2
setProcessDpiAwareness(2);
}
FreeLibrary(shcore);
}
#endif
}
int main(int argc, char* argv[]) {