Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

to create X window(X11) in java swing and to get its id

Can anyone help me in creating an X11 window in java swing using eclipse?And also the function to get the x11 id also.What are the basic requirement for creating an X11 window in java.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Tom answered the first part of your question. The second part of the answer is: to get the id of an X11 window you are going to have to use native code (code written in C or C++) and access it through the JNI interface.

You may have to run a search by title through all existing windows to get the one you desire.

Here is a recursive function that will search (starting from the root window) for a 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 was never fixed. If you run valgrind and have minor memory leak issues this is whats causing them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...