Getting X11 window id

R

Robert Holt

Is there any way to get the X11 window id of a window opened through
Swing? I need this to display the contents of another unix application
within my Java application.

Thanks
Robert Holt
 
R

Ross Bamford

Is there any way to get the X11 window id of a window opened through
Swing? I need this to display the contents of another unix application
within my Java application.

Thanks
Robert Holt

If you're not interested in cross platform (which I assume to be the case
anyway!) you could try running 'xwininfo' (e.g. via Runtime.exec) and
parsing the output (a bit). I'm not sure how portable it'd be - you'd need
to check it out - but here running the command:

xwininfo -name 'jEdit - Untitled-1'

returns the window information, the second line of which (after a blank
line) is:

xwininfo: Window id: 0x1a0001d "jEdit - Untitled-1"

IIRC xprop is able to do a similar thing, and may also be specifically
able to return the ID for a named window. Both have man pages.
 
J

John Perks and Sarah Mount

Robert Holt said:
Is there any way to get the X11 window id of a window opened through
Swing?

If you're prepared to to go native, you can use JAWT:

MyX11Utils.java:

class MyX11Utils {
public static native long windowID(Component comp);
}


MyX11Utils.c

#include <jawt.h>
#include <jawt_md.h>

Java_MyX11Utils_windowID(JNIEnv* env, jclass cls, jobject comp) {
JAWT awt;
JAWT_DrawingSurface* ds = NULL;
int dsLocked = false;
JAWT_DrawingSurfaceInfo* dsi = NULL;
JAWT_X11DrawingSurfaceInfo* x = NULL;
jlong windowID = -1; /* or some appropriate error value */

awt.version = JAWT_VERSION_1_4;
if (!JAWT_GetAWT(env, &awt)) { goto done; }
ds = awt.GetDrawingSurface(env, comp);
if (!ds) { goto done; }
dsLocked = !(ds->Lock(ds) & JAWT_LOCK_ERROR);
if (!dsLocked) { goto done; }
dsi = ds->GetDrawingSurfaceInfo(ds);
if (!dsi) { goto done; }
x = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;

/* get the window id. Don't know x11, but is it something like
windowID = (jlong)x->visualID;
or using it Drawable or Display properties? */


done:
/* resource cleanup */
if (dsi) { ds->FreeDrawingSurfaceInfo(dsi); }
if (dsLocked) { ds->Unlock(ds); }
if (ds) { awt.FreeDrawingSurface(ds); }

return windowID;
}


HTH

John
 
R

Roedy Green

Is there any way to get the X11 window id of a window opened through
Swing? I need this to display the contents of another unix application
within my Java application.

anything platform specific of that sort is going to require JNI. The
big problem is a Window object passed to you on the C side won't have
a field called x11WindowId.

You are going to have to somehow find the matching peer window on the
C side, e.g. from its location.

You might get somewhere chasing the peer object. Consider though that
many Swing components are lightweight, painted on a large native GUI
object. I presume that is true even with X11.
 
R

Robert Holt

Thanks for the help. This is what I wanted. The xwininfo was always my
backup
plan for if I could not use any other method (or to write a similar
application
myself which returned the window I wanted).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top