Tom answered the first part of your question. The second part of the answer: to get the X11 window identifier, you have to use your own code (code written in C or C ++) and access it through the JNI interface.You may need to run a name search through all existing windows to get the one you need.
Here is a recursive function that will search (starting from the root window) for the window with the desired name
Window windowWithName(Display *dpy, Window top, char *name)
{
Window *children, dummy;
unsigned int nchildren;
unsigned int i;
Window w = 0;
char *window_name;
if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name))
return (top);
if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren))
return (0);
for (i = 0; i < nchildren; i++)
{
w = windowWithName(dpy, children[i], name);
if (w)
break;
}
if (children)
XFree((char *) children);
return (w);
}
Note: ** unfortunately, there is a well-documented memory leak in the XFetchName function implemented in X11 that has never been fixed. If you run valgrind and have problems with a memory leak, this causes them.
source
share