plugViewGetSize impl for apple and windows

This commit is contained in:
Paolo Marrone 2025-01-21 15:48:53 +01:00
parent c6de99898d
commit 83f333ef6b

View File

@ -1572,26 +1572,43 @@ static Steinberg_tresult plugViewGetSize(void* thisInterface, struct Steinberg_V
plugView *v = (plugView *)((char *)thisInterface - offsetof(plugView, vtblIPlugView));
size->left = 0;
size->top = 0;
if (!v->ui) {
uint32_t width, height;
plugin_ui_get_default_size(&width, &height);
size->right = width;
size->bottom = height;
} else {
size->right = 0;
size->bottom = 0;
if (v->ui) {
# ifdef __linux__
XWindowAttributes attr;
TRACE(" window %u\n", (Window)(*((char **)v->ui)));
XGetWindowAttributes(v->display, (Window)(*((char **)v->ui)), &attr);
size->right = attr.width;
size->bottom = attr.height;
# elif defined(__APPLE__)
SEL boundsSelector = sel_registerName("bounds");
CGRect (*boundsMsgSend)(id, SEL) = (CGRect (*)(id, SEL))objc_msgSend;
CGRect bounds = boundsMsgSend((id)(*((char **)v->ui)), boundsSelector);
CGFloat width = bounds.size.width;
CGFloat height = bounds.size.height;
size->right = width;
size->bottom = height;
# elif defined(_WIN32) || defined(__CYGWIN__)
RECT rect;
if (GetWindowRect((HWND)*((char **)v->ui), &rect)) {
size->right = rect.right - rect.left;
size->bottom = rect.bottom - rect.top;
}
# endif
}
if (!v->ui || size->right < 1 || size->bottom < 1) {
uint32_t width, height;
plugin_ui_get_default_size(&width, &height);
size->right = width;
size->bottom = height;
}
TRACE(" %u x %u\n", size->right, size->bottom);
return Steinberg_kResultTrue;
}
static Steinberg_tresult plugViewOnSize(void* thisInterface, struct Steinberg_ViewRect* newSize) {
TRACE("plugView onSize %p\n", thisInterface);
TRACE("plugView onSize %p %d %d\n", thisInterface, newSize->right - newSize->left, newSize->bottom - newSize->top);
plugView *v = (plugView *)((char *)thisInterface - offsetof(plugView, vtblIPlugView));
// TODO: if not resizable by both user and plugin just return false
if (!v->ui)