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