Initial revision
[wmaker-crm.git] / wrlib / view.c
bloba05b2dbdd89c69320fc8103328d8f8e4358065a5
2 #include "wraster.h"
4 #include <X11/Xlib.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include "tile.xpm"
8 Display *dpy;
9 Window win;
10 RContext *ctx;
11 RImage *img;
12 Pixmap pix;
14 void main(int argc, char **argv)
16 RContextAttributes attr;
18 dpy = XOpenDisplay("");
19 if (!dpy) {
20 puts("cant open display");
21 exit(1);
24 attr.flags = RC_RenderMode | RC_ColorsPerChannel;
25 attr.render_mode = RM_DITHER;
26 attr.colors_per_channel = 4;
27 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
29 if (argc<2)
30 img = RGetImageFromXPMData(ctx, image_name);
31 else
32 img = RLoadImage(ctx, argv[1], argc>2 ? atol(argv[2]) : 0);
34 if (!img) {
35 puts(RErrorString);
36 exit(1);
38 if (!RConvertImage(ctx, img, &pix)) {
39 puts(RErrorString);
40 exit(1);
43 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, img->width,
44 img->height, 0, 0, 0);
45 XSelectInput(dpy, win, ExposureMask);
46 XMapRaised(dpy, win);
47 XSync(dpy, False);
48 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height,
49 0, 0);
51 XSync(dpy, False);
52 while (1) {
53 XEvent ev;
54 XNextEvent(dpy, &ev);
55 if (ev.type==Expose)
56 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height,
57 0, 0);
59 XFlush(dpy);
61 getchar();