在java swing中创建X窗口(X11)并获取其id [英] to create X window(X11) in java swing and to get its id

查看:383
本文介绍了在java swing中创建X窗口(X11)并获取其id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人可以帮助我使用eclipse在java swing中创建一个X11窗口?还有用于获取x11 id的函数。在java中创建X11窗口的基本要求是什么。

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.

推荐答案

汤姆回答了你问题的第一部分。答案的第二部分是:要获取X11窗口的id,您将不得不使用本机代码(用C或C ++编写的代码)并通过JNI接口访问它。

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);
}

注意:**遗憾的是,XFetchName函数中存在记录错误的内存泄漏在X11中实现,从未修复过。如果你运行valgrind并且有轻微的内存泄漏问题,这就是造成它们的原因。

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.

这篇关于在java swing中创建X窗口(X11)并获取其id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆