0

I am trying to embed a native app running in Debian such as LibreOffice into a Java SWT application. I have written the SWT code in Java. I send the handle of SWT Composite through the JNI call and embed the child window into it. But it is not getting embedded. Can anyone please help me with what I have done wrong?

Thanks.

This is the Java code:

import java.util.logging.Logger;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.internal.gtk.OS;

public class DebianWindowEmbedder {
private static final Logger logger = Logger.getLogger(DebianWindowEmbedder.class.getName());

static {
    System.load("path_to_my_library_so_file");
    logger.info("Loaded lib");
}
private static native void embedWindow(String windowTitle, long parentWindowXid)
public static void main(String[] args) {

Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Main Application");
String title = "Mozilla Firefox";
shell.setSize(1366, 768);
Composite debianComposite = new Composite(shell, SWT.EMBEDDED);
debianComposite.setLayout(new FillLayout());

long parentXid = debianComposite.handle;

embedWindow(title,parentXid);


shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

This is the C code:

#include <jni.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include<stdio.h>


JNIEXPORT void JNICALL Java_DebianWindowEmbedder_embedWindow(JNIEnv *env, jclass clazz, jstring      windowTitle, jlong parentWindowXid) {

GtkWidget* pParentWidget = (GtkWidget*)(parentWindowXid);        
GdkWindow* pParentWindow = gtk_widget_get_window(pParentWidget);

//For time being, I have hardcoded the xid.
Window child_xid = 0x02a00009 ;
    
GdkWindow *childWindow = gdk_window_lookup(child_xid);
  
GdkDisplay *gdk_display =  gdk_display_get_default();
        
gdk_window_reparent(childWindow , pParentWindow , 0, 0);
           
}
user123
  • 1
  • 1
  • Only the few people with an intimate knowledge of SWT on Linux internals are going to be able to comment in this, and they probably aren't looking here. Try the discussions or issues on https://github.com/eclipse-platform/eclipse.platform.swt – greg-449 Apr 28 '23 at 06:58

0 Answers0