0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

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.
This commit is contained in:
xlinshan 2023-03-03 09:01:06 +08:00 committed by Matthew Gajownik
parent cedf0ace53
commit 542cb876dc

View File

@ -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<int>(width / scale_factor);
height = static_cast<int>(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<int>(width / scale_factor);
height = static_cast<int>(height / scale_factor);
resize(width, height);
}
}