From 542cb876dce6077bb24fa5ee0439e7d21ac53f59 Mon Sep 17 00:00:00 2001 From: xlinshan Date: Fri, 3 Mar 2023 09:01:06 +0800 Subject: [PATCH] obs-vst: Fix incorrect VST window size on HiDPI display On Windows, the VST plugins' window sizes are rendered larger than the actual content on displays that have UI scale factor. The sizes are larger by the scale factor, for example, 100x100 content will have a 200x200 window on a 200% scaled screen, and 150x150 on a 150% scaled screen. This change adjust the window size to fit the content size. --- plugins/obs-vst/win/EditorWidget-win.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/plugins/obs-vst/win/EditorWidget-win.cpp b/plugins/obs-vst/win/EditorWidget-win.cpp index d32b72f5c..a645de585 100644 --- a/plugins/obs-vst/win/EditorWidget-win.cpp +++ b/plugins/obs-vst/win/EditorWidget-win.cpp @@ -49,10 +49,16 @@ void EditorWidget::buildEffectContainer(AEffect *effect) VstRect *vstRect = nullptr; effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0); if (vstRect) { - widget->resize(vstRect->right - vstRect->left, - vstRect->bottom - vstRect->top); - resize(vstRect->right - vstRect->left, - vstRect->bottom - vstRect->top); + // on Windows, the size reported by 'effect' is larger than + // its actuall size by a factor of the monitor's ui scale, + // so the window size should be divided by the factor + qreal scale_factor = devicePixelRatioF(); + int width = vstRect->right - vstRect->left; + int height = vstRect->bottom - vstRect->top; + width = static_cast(width / scale_factor); + height = static_cast(height / scale_factor); + widget->resize(width, height); + resize(width, height); } else { widget->resize(300, 300); } @@ -72,6 +78,14 @@ void EditorWidget::handleResizeRequest(int, int) effect->dispatcher(effect, effEditGetRect, 0, 0, &rec, 0); if (rec) { - resize(rec->right - rec->left, rec->bottom - rec->top); + // on Windows, the size reported by 'effect' is larger than + // its actuall size by a factor of the monitor's ui scale, + // so the window size should be divided by the factor + qreal scale_factor = devicePixelRatioF(); + int width = rec->right - rec->left; + int height = rec->bottom - rec->top; + width = static_cast(width / scale_factor); + height = static_cast(height / scale_factor); + resize(width, height); } }