Skip to content

Commit

Permalink
Merge pull request obsproject#50 from Vertver/master
Browse files Browse the repository at this point in the history
Fixed plugin resize on Windows
  • Loading branch information
DDRBoxman committed Feb 2, 2019
2 parents f900e5b + 96bd81c commit db9e116
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion headers/EditorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class EditorWidget : public QWidget {
#ifdef __APPLE__
QMacCocoaViewContainer *cocoaViewContainer = NULL;
#elif WIN32

HWND windowHandle = NULL;
#elif __linux__

#endif
Expand Down
61 changes: 51 additions & 10 deletions win/EditorWidget-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

void EditorWidget::buildEffectContainer(AEffect *effect)
{
WNDCLASSEX wcex{sizeof(wcex)};
WNDCLASSEXW wcex{sizeof(wcex)};

wcex.lpfnWndProc = DefWindowProc;
wcex.hInstance = GetModuleHandle(0);
wcex.lpfnWndProc = DefWindowProcW;
wcex.hInstance = GetModuleHandleW(nullptr);
wcex.lpszClassName = L"Minimal VST host - Guest VST Window Frame";
RegisterClassEx(&wcex);
RegisterClassExW(&wcex);

const auto style = WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPEDWINDOW;
HWND hwnd = CreateWindow(wcex.lpszClassName, TEXT(""), style, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr);
windowHandle =
CreateWindowW(wcex.lpszClassName, TEXT(""), style, 0, 0, 0, 0, nullptr, nullptr, nullptr, nullptr);

QWidget *widget = QWidget::createWindowContainer(QWindow::fromWinId((WId)hwnd), this);
// set pointer to vst effect for window long
LONG_PTR wndPtr = (LONG_PTR)effect;
SetWindowLongPtr(windowHandle, -21 /*GWLP_USERDATA*/, wndPtr);

QWidget *widget = QWidget::createWindowContainer(QWindow::fromWinId((WId)windowHandle), this);
widget->move(0, 0);
widget->resize(300, 300);

effect->dispatcher(effect, effEditOpen, 0, 0, hwnd, 0);
effect->dispatcher(effect, effEditOpen, 0, 0, windowHandle, 0);

VstRect *vstRect = nullptr;
effect->dispatcher(effect, effEditGetRect, 0, 0, &vstRect, 0);
Expand All @@ -44,7 +49,43 @@ void EditorWidget::buildEffectContainer(AEffect *effect)

void EditorWidget::handleResizeRequest(int, int)
{
// We don't have to do anything here as far as I can tell.
// The widget will resize the HWIND itself and then this
// widget will automatically size depending on that.
// Some plugins can't resize automatically (like SPAN by Voxengo),
// so we must resize window manually

// get pointer to vst effect from window long
LONG_PTR wndPtr = (LONG_PTR)GetWindowLongPtrW(windowHandle, -21 /*GWLP_USERDATA*/);
AEffect * effect = (AEffect *)(wndPtr);
VstRect * rec = nullptr;
static RECT PluginRc = {0};
RECT winRect = {0};

GetWindowRect(windowHandle, &winRect);
if (effect) {
effect->dispatcher(effect, effEditGetRect, 1, 0, &rec, 0);
}

// compare window rect with VST Rect
if (rec) {
if (PluginRc.bottom != rec->bottom || PluginRc.left != rec->left || PluginRc.right != rec->right ||
PluginRc.top != rec->top) {
PluginRc.bottom = rec->bottom;
PluginRc.left = rec->left;
PluginRc.right = rec->right;
PluginRc.top = rec->top;

// set rect to our window
AdjustWindowRectEx(&PluginRc,
WS_CAPTION | WS_THICKFRAME | WS_OVERLAPPEDWINDOW,
FALSE,
0);

// move window to apply pos
MoveWindow(windowHandle,
winRect.left,
winRect.top,
PluginRc.right - PluginRc.left,
PluginRc.bottom - PluginRc.top,
TRUE);
}
}
}

0 comments on commit db9e116

Please sign in to comment.