fix(bridge): anchored fx-gui embed - dance dat window dung panel rect, khong park/restore cursor, resize view qua WM_FXGUI_RESIZE
This commit is contained in:
@@ -689,6 +689,37 @@ public:
|
||||
delete s->plugFrame;
|
||||
s->plugFrame = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// Resize the editor view to w x h (VST3 host resize flow: checkSizeConstraint
|
||||
// lets the plugin clamp to a supported size, host resizes the window, then
|
||||
// onSize tells the plugin -- it moves/resizes its own child window). Runs on
|
||||
// the GUI pump thread (WM_FXGUI_RESIZE) -- plugin calls must not come from
|
||||
// the HTTP worker thread.
|
||||
bool resizeEditor(void* parentWindowHandle, int w, int h) {
|
||||
#ifndef HAVE_VST3SDK
|
||||
(void)parentWindowHandle; (void)w; (void)h;
|
||||
return false;
|
||||
#else
|
||||
auto* s = static_cast<Vst3FxState*>(state_);
|
||||
if (!s || !s->view || w <= 0 || h <= 0) return false;
|
||||
Steinberg::ViewRect vr = {0, 0, w, h};
|
||||
s->view->checkSizeConstraint(&vr); // plugin clamps to a supported size
|
||||
const int cw = vr.right - vr.left;
|
||||
const int ch = vr.bottom - vr.top;
|
||||
if (cw <= 0 || ch <= 0) return false;
|
||||
#ifdef _WIN32
|
||||
RECT r = {0, 0, cw, ch};
|
||||
AdjustWindowRectEx(&r,
|
||||
(DWORD)GetWindowLongPtrA((HWND)parentWindowHandle, GWL_STYLE),
|
||||
FALSE,
|
||||
(DWORD)GetWindowLongPtrA((HWND)parentWindowHandle, GWL_EXSTYLE));
|
||||
SetWindowPos((HWND)parentWindowHandle, nullptr, 0, 0,
|
||||
r.right - r.left, r.bottom - r.top,
|
||||
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
#endif
|
||||
s->view->onSize(&vr);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
bool loaded() const { return state_ != nullptr; }
|
||||
@@ -892,6 +923,10 @@ int run_render_fx_job(const std::string& jobPath, const std::string& inPath,
|
||||
|
||||
// --- --open-fx-gui <job.json>: native editor window for one VST3 FX ----------
|
||||
#ifdef _WIN32
|
||||
// Worker (HTTP) thread -> pump thread editor-resize request. Declared
|
||||
// outside the anonymous namespace: the definition sits after the namespace.
|
||||
static void fxGuiResizeSafe(void* fx, HWND hwnd, int w, int h);
|
||||
|
||||
namespace {
|
||||
|
||||
const char* kFxGuiWndClass = "SonicForge_FX_GUI_Class";
|
||||
@@ -900,6 +935,10 @@ struct FxGuiCtx {
|
||||
bool closing = false;
|
||||
};
|
||||
|
||||
// Worker (HTTP) thread -> pump thread editor-resize request. The plugin's
|
||||
// checkSizeConstraint/onSize must run on the thread that owns the editor.
|
||||
#define WM_FXGUI_RESIZE (WM_APP + 0x51)
|
||||
|
||||
LRESULT CALLBACK FxGuiWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
FxGuiCtx* ctx = (FxGuiCtx*)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
|
||||
switch (msg) {
|
||||
@@ -909,6 +948,9 @@ LRESULT CALLBACK FxGuiWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
|
||||
case WM_DESTROY:
|
||||
if (ctx) ctx->closing = true;
|
||||
return 0;
|
||||
case WM_FXGUI_RESIZE:
|
||||
fxGuiResizeSafe((void*)GetPropA(hwnd, "FXGUI_FX"), hwnd, (int)wp, (int)lp);
|
||||
return 0;
|
||||
default:
|
||||
return DefWindowProcA(hwnd, msg, wp, lp);
|
||||
}
|
||||
@@ -934,6 +976,18 @@ static void fxGuiDetachSafe(void* fx) {
|
||||
(void)fx;
|
||||
#endif
|
||||
}
|
||||
static void fxGuiResizeSafe(void* fx, HWND hwnd, int w, int h) {
|
||||
#ifdef HAVE_VST3SDK
|
||||
__try { static_cast<Vst3Fx*>(fx)->resizeEditor(hwnd, w, h); }
|
||||
__except (EXCEPTION_EXECUTE_HANDLER) {}
|
||||
#else
|
||||
(void)fx; (void)hwnd; (void)w; (void)h;
|
||||
#endif
|
||||
}
|
||||
// Worker (HTTP) thread asks the GUI pump thread to resize the plugin view.
|
||||
void fxGuiRequestResize(HWND hwnd, int w, int h) {
|
||||
PostMessageA(hwnd, WM_FXGUI_RESIZE, (WPARAM)w, (LPARAM)h);
|
||||
}
|
||||
|
||||
// Shared setup for both GUI modes: parse job, load plugin, create host window
|
||||
// (offscreen for embedded capture), attach editor (SEH-guarded). Returns 0 ok,
|
||||
@@ -1034,8 +1088,10 @@ int run_fx_gui_server(const std::string& jobPath) {
|
||||
HWND hwnd = nullptr;
|
||||
const int rc = fxGuiSetup(jobPath, &fx, &hwnd, /*offscreen=*/true, 0);
|
||||
if (rc) return rc;
|
||||
SetPropA(hwnd, "FXGUI_FX", &fx); // for WM_FXGUI_RESIZE on the pump thread
|
||||
|
||||
const int srv = fxGuiServerLoop(hwnd);
|
||||
RemovePropA(hwnd, "FXGUI_FX");
|
||||
fxGuiDetachSafe(&fx);
|
||||
std::cout << "[FxGuiServer] closed" << std::endl;
|
||||
return srv;
|
||||
|
||||
Reference in New Issue
Block a user