x11 - XPutImage to a DefaultRootWindow() gives nothing -
i'm trying write screensaver compatible "xscreensaver"-package. requires program draw in root-window. program runs fine when create non-root-window myself, e.g.:
window window = xcreatesimplewindow(display, rootwindow(display, 0), 0, 0, width, height, 1, 0, 0); drawing a
window window = defaultrootwindow(display);
instead gives nothing. tried running xscreensaver-demo, xterm, environment without window manager give black. in terminal start it, no x11 errors shown. error-handler not triggered. guess biggest problem can't find (not google) how debug this.
any appreciated!
here's code:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <x11/xlib.h> #include <x11/xutil.h> void draw(char *rgb_out, int w, int h) { for(int i=0; i<w*h*4; i++) *rgb_out++ = rand(); } ximage *create_ximage(display *display, visual *visual, int width, int height) { char *image32 = (char *)malloc(width * height * 4); draw(image32, width, height); return xcreateimage(display, visual, 24, zpixmap, 0, image32, width, height, 32, 0); } int x11_err_handler(display *pd, xerrorevent *pxev) { char msg[4096] = { 0 }; xgeterrortext(pd, pxev -> error_code, msg, sizeof(msg)); printf("%s\n", msg); return 0; } int main(int argc, char **argv) { display *display = xopendisplay(getenv("display")); window window = defaultrootwindow(display); xwindowattributes wa; xgetwindowattributes(display, window, &wa); int width = wa.width, height = wa.height; printf("res: %dx%d\n", width, height); gc gc = xcreategc(display, window, 0, null); visual *visual = defaultvisual(display, 0); xseterrorhandler(x11_err_handler); for(;;) { ximage *ximage = create_ximage(display, visual, width, height); xputimage(display, window, gc, ximage, 0, 0, 0, 0, width, height); xdestroyimage(ximage); xflush(display); usleep(50000); } return 0; } it can compiled using:
g++ -o3 -lx11 -lxpm so.cpp
your code works fine me, tested xephyr. guess (as commented) in setup root window obscured de, example in ubuntu there 'nautilus' running full screen provide desktop / icons / dnd / rubber band selection functionality.
Comments
Post a Comment