consistant glib type usage
[dana/openbox.git] / render / 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) 2003        Ben Jansens
5    Copyright (c) 2003        Derek Foreman
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include <stdio.h>
21 #include <X11/Xlib.h>
22 #include <X11/Xutil.h>
23 #include <X11/extensions/shape.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include "render.h"
27 #include <glib.h>
28
29 static gint x_error_handler(Display * disp, XErrorEvent * error)
30 {
31         gchar buf[1024];
32         XGetErrorText(disp, error->error_code, buf, 1024);
33         printf("%s\n", buf);
34         return 0;
35 }
36
37 Display *ob_display;
38 gint ob_screen;
39 Window ob_root;
40
41 gint main()
42 {
43         Window win;
44         RrInstance *inst;
45         RrAppearance *look;
46
47         Window root;
48         XEvent report;
49         gint h = 500, w = 500;
50
51         ob_display = XOpenDisplay(NULL);
52         XSetErrorHandler(x_error_handler);
53         ob_screen = DefaultScreen(ob_display);
54         ob_root = RootWindow(ob_display, ob_screen);
55         win =
56             XCreateWindow(ob_display, RootWindow(ob_display, 0),
57                                           10, 10, w, h, 10, 
58                                           CopyFromParent,       /* depth */
59                                           CopyFromParent,       /* class */
60                                           CopyFromParent,       /* visual */
61                                           0,                    /* valuemask */
62                                           0);                   /* attributes */
63         XMapWindow(ob_display, win);
64         XSelectInput(ob_display, win, ExposureMask | StructureNotifyMask);
65         root = RootWindow (ob_display, DefaultScreen (ob_display));
66         inst = RrInstanceNew(ob_display, ob_screen);
67
68         look = RrAppearanceNew(inst, 0);
69         look->surface.grad = RR_SURFACE_PYRAMID;
70         look->surface.secondary = RrColorParse(inst, "Yellow");
71         look->surface.primary = RrColorParse(inst, "Blue");
72         look->surface.interlaced = FALSE;
73         if (ob_display == NULL) {
74                 fprintf(stderr, "couldn't connect to X server :0\n");
75                 return 0;
76         }
77
78         RrPaint(look, win, w, h);
79         while (1) {
80                 XNextEvent(ob_display, &report);
81                 switch (report.type) {
82                 case Expose:
83                         break;
84                 case ConfigureNotify:
85                         RrPaint(look, win,
86                                         report.xconfigure.width,
87                                         report.xconfigure.height);
88                         break;
89                 }
90
91         }
92
93         RrAppearanceFree (look);
94         RrInstanceFree (inst);
95
96         return 1;
97 }