如何为GPGPU创建不可见的X11窗口?

发布于 2024-12-18 09:22:00 字数 431 浏览 2 评论 0原文

是否可以创建一个不可见的 X 窗口?为了初始化 OpenGL ES 2.0 上下文,必须手动创建一个 X 窗口,但我找不到一种方法让它不可见。因为我只做 GPGPU,所以不需要输出窗口。事实上,就我而言,这很烦人。

我知道早期问题中的解决方案,其中已指出在 XCreateWindow() 中使用 InputOnly。然而,这会导致 X 错误 GLXBadDrawable。可能是因为EGL需要窗口响应图形请求。还有别的办法吗?也许将其最小化?但我也找不到任何相关内容。另外,将窗口尺寸设置得非常小也没有帮助,因为它总是占据我的设备(诺基亚 N9)上的整个屏幕。

Is it possible to create an invisible X window? For initialization of an OpenGL ES 2.0 context, one has to create a X window manually, but I can't find a way to make it invisible. Since I'm only doing GPGPU I don't need an output window. In fact, it is rather annoying in my case.

I'm aware of a solution from an earlier question, where it has been pointed out to use InputOnly in XCreateWindow(). This, however, leads to the X error GLXBadDrawable. Probably because EGL requires the window to respond to graphics request. Is there another way? Maybe create it minimized? But I can't find anything on that either. Also setting the window's size really small doesn't help, since it always occupies the whole screen on my device (Nokia N9).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你与清晨阳光 2024-12-25 09:22:00

当您创建 X 窗口时,它是在未映射的情况下创建的,那么创建一个 InputOutput 窗口并使其保持未映射状态又如何呢?另一种选择是将其移出屏幕(如果窗口必须保持映射状态)。

When you create an X window, it is created unmapped, so what about creating an InputOutput window and leaving it unmapped? Another option would be (if the window must stay mapped), to move it out of the screen.

川水往事 2024-12-25 09:22:00
  1. 创建一个具有属性_NET_WM_STATE_SKIP_TASKBAR的窗口。
  2. 将其图标化。

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>


Window createWindow(Display* display, int screen) {
    Window window = XCreateSimpleWindow(
        display,
        RootWindow(display, screen),
        0, 0, 100, 100, 4,
        BlackPixel(display, screen),
        WhitePixel(display, screen)
    );

    return window;
}


Display* openDisplay() {
    Display *display = XOpenDisplay(NULL);

    if (!display) {
        fprintf(stderr, "No display\n");
        exit(EXIT_FAILURE);
    }

    return display;
}


int setWindowProperties(Display* display, Window window) {
    Atom skipTaskbar = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR", False);

    XChangeProperty(
        display,
        window,
        XInternAtom(display, "_NET_WM_STATE", False),
        XA_ATOM, 32,
        PropModeReplace,
        (unsigned char *) &skipTaskbar, 1
    );
}


int waitWindowClose(Display* display, Window window) {
    XEvent event;
    Atom delete = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &delete, 1);

    while (event.type != ClientMessage && event.xclient.data.l[0] != delete) {
        XNextEvent(display, &event);
    }
}


int main() {
    Display* display = openDisplay();
    int screen = DefaultScreen(display);

    Window window = createWindow(display, screen);
    setWindowProperties(display, window);

    XMapWindow(display, window);
    XIconifyWindow(display, window, screen);
    XFlush(display);

    waitWindowClose(display, window);
}

  1. Create a window with the property _NET_WM_STATE_SKIP_TASKBAR.
  2. Iconify it.

#include <stdio.h>
#include <stdlib.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>


Window createWindow(Display* display, int screen) {
    Window window = XCreateSimpleWindow(
        display,
        RootWindow(display, screen),
        0, 0, 100, 100, 4,
        BlackPixel(display, screen),
        WhitePixel(display, screen)
    );

    return window;
}


Display* openDisplay() {
    Display *display = XOpenDisplay(NULL);

    if (!display) {
        fprintf(stderr, "No display\n");
        exit(EXIT_FAILURE);
    }

    return display;
}


int setWindowProperties(Display* display, Window window) {
    Atom skipTaskbar = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR", False);

    XChangeProperty(
        display,
        window,
        XInternAtom(display, "_NET_WM_STATE", False),
        XA_ATOM, 32,
        PropModeReplace,
        (unsigned char *) &skipTaskbar, 1
    );
}


int waitWindowClose(Display* display, Window window) {
    XEvent event;
    Atom delete = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, window, &delete, 1);

    while (event.type != ClientMessage && event.xclient.data.l[0] != delete) {
        XNextEvent(display, &event);
    }
}


int main() {
    Display* display = openDisplay();
    int screen = DefaultScreen(display);

    Window window = createWindow(display, screen);
    setWindowProperties(display, window);

    XMapWindow(display, window);
    XIconifyWindow(display, window, screen);
    XFlush(display);

    waitWindowClose(display, window);
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文