begginer needs help, using cairo to make a background program working for X

First Last <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hi, I try to make a program who renders a background when I launch X, for now I'm able to render a rectangle filled with a color, but I didn't find how to put a picture in this rectangle, I add my code :

#include<cairo.h>
#include<cairo-xlib.h>
#include<X11/Xlib.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define DPYW DisplayWidth(dpy,scr)
#define DPYH DisplayHeight(dpy,scr)


int main(int argc, char *argv[]){
        Display *dpy;
        int scr;
        Window rootwin;
        Window wbg;
        XEvent e;
        cairo_surface_t *bg;


        scr=DefaultScreen(dpy);
        rootwin=RootWindow(dpy, scr);
        wbg=XCreateSimpleWindow(dpy,rootwin,0,0,
                                DPYW,DPYH,0,
                                BlackPixel(dpy, scr),
                                BlackPixel(dpy, scr) );


        XStoreName(dpy, wbg, "background");
        XSelectInput(dpy, wbg, ExposureMask);
        XMapWindow(dpy, wbg);

//      bg=cairo_xlib_surface_create(dpy, wbg, DefaultVisual(dpy, 0), DPYW, DPYH);
        bg=cairo_image_surface_create_from_png("/usr/share/backgrounds/wallpaper.png");

        while(1) {
                XNextEvent(dpy, &e);
                if(e.type==Expose && e.xexpose.count<1) {
                cairo_t *c;

                c=cairo_create(bg);
        //      cairo_rectangle(c,0,0,DPYW,DPYH);
        //      cairo_set_source_rgb(c,0.5,0,0);
        //      cairo_fill(c);
        //      cairo_show_page(c);
        //      cairo_destroy(c);

                cairo_set_source_surface (c, bg, 100, 100);
                cairo_paint(c);
        //      cairo_show_page(c);
        //      cairo_surface_destroy(bg);
                cairo_destroy(c);
                }
        }

        cairo_surface_destroy(bg);
        XCloseDisplay(dpy);

        return 0;
}

I don't understand what it's missing, or what I'm doing wrong.

nicoo

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.