add doc/obxprop.1 to gitignore
[dana/openbox.git] / obrender / test.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    test.c for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6    Copyright (c) 2003        Derek Foreman
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    See the COPYING file for a copy of the GNU General Public License.
19 */
20
21 #include <stdio.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/extensions/shape.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include "render.h"
28 #include <glib.h>
29
30 static gint x_error_handler(Display * disp, XErrorEvent * error)
31 {
32     gchar buf[1024];
33     XGetErrorText(disp, error->error_code, buf, 1024);
34     printf("%s\n", buf);
35     return 0;
36 }
37
38 Display *ob_display;
39 gint ob_screen;
40 Window ob_root;
41
42 gint main()
43 {
44     Window win;
45     RrInstance *inst;
46     RrAppearance *look;
47     int done;
48
49     Window root;
50     XEvent report;
51     gint h = 500, w = 500;
52
53     ob_display = XOpenDisplay(NULL);
54     XSetErrorHandler(x_error_handler);
55     ob_screen = DefaultScreen(ob_display);
56     ob_root = RootWindow(ob_display, ob_screen);
57     win =
58         XCreateWindow(ob_display, RootWindow(ob_display, 0),
59                       10, 10, w, h, 10,
60                       CopyFromParent,    /* depth */
61                       CopyFromParent,    /* class */
62                       CopyFromParent,    /* visual */
63                       0,                    /* valuemask */
64                       0);                    /* attributes */
65     XMapWindow(ob_display, win);
66     XSelectInput(ob_display, win, ExposureMask | StructureNotifyMask);
67     root = RootWindow (ob_display, DefaultScreen (ob_display));
68     inst = RrInstanceNew(ob_display, ob_screen);
69
70     look = RrAppearanceNew(inst, 0);
71     look->surface.grad = RR_SURFACE_MIRROR_HORIZONTAL;
72     look->surface.secondary = RrColorParse(inst, "Yellow");
73     look->surface.split_secondary = RrColorParse(inst, "Red");
74     look->surface.split_primary = RrColorParse(inst, "Green");
75     look->surface.primary = RrColorParse(inst, "Blue");
76     look->surface.interlaced = FALSE;
77     if (ob_display == NULL) {
78         fprintf(stderr, "couldn't connect to X server :0\n");
79         return 0;
80     }
81
82 #if BIGTEST
83     int i;
84     look->surface.pixel_data = g_new(RrPixel32, w*h);
85     for (i = 0; i < 10000; ++i) {
86         printf("\r%d", i);
87         fflush(stdout);
88         RrRender(look, w, h);
89     }
90     exit (0);
91 #endif
92
93     RrPaint(look, win, w, h);
94     done = 0;
95     while (!done) {
96         XNextEvent(ob_display, &report);
97         switch (report.type) {
98         case Expose:
99             break;
100         case ConfigureNotify:
101             RrPaint(look, win,
102                     report.xconfigure.width,
103                     report.xconfigure.height);
104             break;
105         case UnmapNotify:
106             done = 1;
107             break;
108         }
109     }
110
111     RrAppearanceFree (look);
112     RrInstanceFree (inst);
113
114     return 1;
115 }