Updating to version 0.20.2
[wmaker-crm.git] / wrlib / view.c
blobae69a7df4dbe2d02852fc49372694a825371ee89
2 #include <X11/Xlib.h>
3 #include "wraster.h"
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "tile.xpm"
7 Display *dpy;
8 Window win;
9 RContext *ctx;
10 RImage *img;
11 Pixmap pix;
13 void main(int argc, char **argv)
15 RContextAttributes attr;
17 dpy = XOpenDisplay("");
18 if (!dpy) {
19 puts("cant open display");
20 exit(1);
23 attr.flags = RC_RenderMode | RC_ColorsPerChannel;
24 attr.render_mode = RM_DITHER;
25 attr.colors_per_channel = 4;
26 ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
28 if (argc<2)
29 img = RGetImageFromXPMData(ctx, image_name);
30 else
31 img = RLoadImage(ctx, argv[1], argc>2 ? atol(argv[2]) : 0);
33 if (!img) {
34 puts(RMessageForError(RErrorCode));
35 exit(1);
37 if (!RConvertImage(ctx, img, &pix)) {
38 puts(RMessageForError(RErrorCode));
39 exit(1);
42 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, img->width,
43 img->height, 0, 0, 0);
44 XSelectInput(dpy, win, ExposureMask);
45 XMapRaised(dpy, win);
46 XSync(dpy, False);
47 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height,
48 0, 0);
50 XSync(dpy, False);
51 while (1) {
52 XEvent ev;
53 XNextEvent(dpy, &ev);
54 if (ev.type==Expose)
55 XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height,
56 0, 0);
58 XFlush(dpy);
60 getchar();