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

First Last begre1929 at yahoo.com
Sat May 18 20:27:33 PDT 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130518/d3a6c5bd/attachment.html>


More information about the cairo mailing list