Why I set xlib window background transparent failed?

拈花ヽ惹草 提交于 2019-12-03 17:16:56

Your code works fine for me:

kde:

openbox + xcompmgr:

Most likely you are not running composite manager. Try to start xcompmgr command

Also check _NET_WM_CM_S0 selection owner - it should point to a window created by composite manager.

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    Display* display = XOpenDisplay(NULL);

    Atom cmAtom = XInternAtom(display, "_NET_WM_CM_S0", 0);
    Window cmOwner = XGetSelectionOwner(display, cmAtom);

    printf("Composite manager window: %i\n", cmOwner);

    XCloseDisplay(display);
    return 0;
}

Update:

Try to set override-redirect to prevent WM decorations from obscuring your window.

attr.border_pixel = 0;
attr.background_pixel = 0;
attr.override_redirect = 1; /* this line added */

Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, 
vinfo.depth, InputOutput, vinfo.visual, 
CWColormap | CWBorderPixel | CWBackPixel | CWOverrideRedirect /* and this one*/, &attr);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!