A test (untested) that could work would be to run your program under Xnest .
something like this pseudo-call might work:
RWINID=$(xwininfo -root |sed -n -e 's/.*Window.*id: \(0x[a-f0-9]\+\).*/\1/p')
Xnest -parent $RWINID :5
DISPLAY=":5" myapp
source
share