Skip to content

Commit

Permalink
Various improvements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Jun 18, 2014
1 parent 9c84f03 commit bbb06b4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
28 changes: 15 additions & 13 deletions host/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,30 +235,31 @@ bool serve_request2(struct vst_bridge_request *rq)
return true;

case effEditOpen: {
assert(!g_host.hwnd);
if (!g_host.hwnd) {
ERect * rect = NULL;
g_host.e->dispatcher(g_host.e, effEditGetRect, 0, 0, &rect, 0);

g_host.hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
APPLICATION_CLASS_NAME, "Plugin",
WS_POPUP,
0, 0, rect->right - rect->left,
rect->bottom - rect->top,
0, 0, GetModuleHandle(0), 0);
}

ERect * rect = NULL;
g_host.e->dispatcher(g_host.e, effEditGetRect, 0, 0, &rect, 0);

g_host.hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
APPLICATION_CLASS_NAME, "Plugin",
WS_POPUP,
0, 0, rect->right - rect->left,
rect->bottom - rect->top,
0, 0, GetModuleHandle(0), 0);
if (!g_host.hwnd)
CRIT("failed to create window\n");

rq->erq.value = g_host.e->dispatcher(g_host.e, effEditOpen, 0, 0, g_host.hwnd, 0);
rq->erq.value = 0;
rq->erq.index = (ptrdiff_t)GetPropA(g_host.hwnd, "__wine_x11_whole_window");

write(g_host.socket, rq, VST_BRIDGE_ERQ_LEN(0));
return true;
}

case effEditClose:
CloseWindow(g_host.hwnd);
g_host.hwnd = 0;
DestroyWindow(g_host.hwnd);
g_host.hwnd = NULL;
rq->erq.value = g_host.e->dispatcher(g_host.e, rq->erq.opcode, rq->erq.index,
rq->erq.value, rq->erq.data, rq->erq.opt);
write(g_host.socket, rq, VST_BRIDGE_ERQ_LEN(0));
Expand Down Expand Up @@ -404,6 +405,7 @@ bool serve_request2(struct vst_bridge_request *rq)
}

case VST_BRIDGE_CMD_SHOW_WINDOW:
g_host.e->dispatcher(g_host.e, effEditOpen, 0, 0, g_host.hwnd, 0);
ShowWindow(g_host.hwnd, SW_SHOWNORMAL);
UpdateWindow(g_host.hwnd);
write(g_host.socket, rq, VST_BRIDGE_RQ_LEN);
Expand Down
2 changes: 1 addition & 1 deletion plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TARGET = vst-bridge-plugin-tpl.so
SRC = plugin.cc

$(TARGET): $(SRC) ../common/common.h ../config.h
$(CXX) $(CXXFLAGS) -shared -fPIC $(SRC) -o $@
$(CXX) $(CXXFLAGS) -shared -fPIC $(SRC) -o $@ -lX11 -lXcomposite

install: $(TARGET)
install -m 755 -d $(DESTDIR)$(PREFIX)/lib/vst-bridge
Expand Down
63 changes: 43 additions & 20 deletions plugin/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct vst_bridge_effect {
pthread_mutex_destroy(&lock);
int st;
waitpid(child, &st, 0);
//XCloseDisplay(display);
}

struct AEffect e;
Expand All @@ -77,8 +78,17 @@ struct vst_bridge_effect {
ERect rect;
bool close_flag;
std::list<vst_bridge_request> pending;
Display *display;
};

void xevent_handler(XEvent *event)
{
if (event)
LOG("XEVENT: type: %d\n", event->type);
else
LOG("XEVENT: NULL");
}

void copy_plugin_data(struct vst_bridge_effect *vbe,
struct vst_bridge_request *rq)
{
Expand Down Expand Up @@ -423,47 +433,56 @@ VstIntPtr vst_bridge_call_effect_dispatcher2(AEffect* effect,
write(vbe->socket, &rq, VST_BRIDGE_ERQ_LEN(0));
vst_bridge_wait_response(vbe, &rq, rq.tag);

if (getenv("VST_BRIDGE_XEMBED")) {
Display *display = (Display *)value;
Window parent = (Window)ptr;
Window child = (Window)rq.erq.index;
bool close_display = false;
Display *display = (Display *)value;
Window parent = (Window)ptr;
Window child = (Window)rq.erq.index;

if (1 /*getenv("VST_BRIDGE_XEMBED")*/) {

if (!vbe->display)
vbe->display = XOpenDisplay(NULL);

if (!display) {
display = XOpenDisplay(NULL);
close_display = !!display;
// set xevent_handler
{
size_t data = (size_t)xevent_handler;
long temp[2];

// Split the 64 bit pointer into a little-endian long array
temp[0] = (long)(data & 0xffffffffUL);
temp[1] = (long)(data >> 32L);

Atom atom = XInternAtom(display, "_XEventProc", false);
XChangeProperty(vbe->display, child, atom, atom, 32,
PropModeReplace, (unsigned char*)temp, 2);
}

XReparentWindow(display, child, parent, 0, 0);
XMapWindow(display, child);
XReparentWindow(vbe->display, child, parent, 0, 0);
//XMapWindow(vbe->display, child);

XEvent ev;

memset(&ev, 0, sizeof (ev));
ev.xclient.type = ClientMessage;
ev.xclient.window = child;
ev.xclient.message_type = XInternAtom(display, "_XEMBED", false);
ev.xclient.message_type = XInternAtom(vbe->display, "_XEMBED", false);
ev.xclient.format = 32;
ev.xclient.data.l[0] = CurrentTime;
ev.xclient.data.l[1] = XEMBED_EMBEDDED_NOTIFY;
ev.xclient.data.l[3] = parent;
XSendEvent(display, child, false, NoEventMask, &ev);
XSync(display, false);
XSendEvent(vbe->display, child, false, NoEventMask, &ev);
XSync(vbe->display, false);

// memset(&ev, 0, sizeof (ev));
// ev.xclient.type = ClientMessage;
// ev.xclient.window = child;
// ev.xclient.message_type = XInternAtom(display, "_XEMBED", false);
// ev.xclient.message_type = XInternAtom(vbe->display, "_XEMBED", false);
// ev.xclient.format = 32;
// ev.xclient.data.l[0] = CurrentTime;
// ev.xclient.data.l[1] = XEMBED_FOCUS_OUT;
// XSendEvent(display, child, false, NoEventMask, &ev);
// XSync(display, false);
// XSendEvent(vbe->display, child, false, NoEventMask, &ev);
// XSync(vbe->display, false);

XFlush(display);

// if (close_display)
// XCloseDisplay(display);
XFlush(vbe->display);
}

rq.tag = vbe->next_tag;
Expand All @@ -473,6 +492,9 @@ VstIntPtr vst_bridge_call_effect_dispatcher2(AEffect* effect,
write(vbe->socket, &rq, VST_BRIDGE_RQ_LEN);
vst_bridge_wait_response(vbe, &rq, rq.tag);

XMapWindow(vbe->display, child);
XMapSubwindows(vbe->display, child);

return rq.erq.value;
}

Expand Down Expand Up @@ -786,6 +808,7 @@ AEffect* VSTPluginMain(audioMasterCallback audio_master)
vbe->e.processReplacing = vst_bridge_call_process;
vbe->e.processDoubleReplacing = vst_bridge_call_process_double;
vbe->close_flag = false;
vbe->display = NULL;

// initialize sockets
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds))
Expand Down

0 comments on commit bbb06b4

Please sign in to comment.