annotate src/X_main.c @ 3:164162781a7a

Test cairo with Xlib surface
author Thinker K.F. Li <thinker@branda.to>
date Fri, 25 Jul 2008 10:09:53 +0800
parents
children 9c331ec9e210
rev   line source
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <unistd.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <X11/Xlib.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <cairo.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 void drawing(cairo_surface_t *surface, int w, int h) {
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 cairo_t *cr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 cr = cairo_create(surface);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 cairo_set_source_rgb(cr, 0xff, 0xff, 0x80);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 cairo_move_to(cr, 10, h / 2);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 cairo_set_font_size(cr, 48.0);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 cairo_text_path(cr, "hello \xe4\xb8\xad\xe6\x96\x87");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 cairo_set_line_width(cr, 1);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 cairo_stroke(cr);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 }
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 int
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 main(int argc, char * const argv[]) {
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 Display *display;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 Window root;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 Visual *visual;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 int screen;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 XSetWindowAttributes wattr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 Window win;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 int depth;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 cairo_surface_t *surface;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 int w, h;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 int x, y;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 int r;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 display = XOpenDisplay(":0.0");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 if(display == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 printf("XOpenDisplay\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 screen = DefaultScreen(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 root = DefaultRootWindow(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 visual = DefaultVisual(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 depth = DefaultDepth(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 wattr.override_redirect = False;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 x = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 y = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 w = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 h = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 win = XCreateWindow(display, root,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 x, y,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 w, h,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 1, depth, InputOutput, visual,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 CWOverrideRedirect, &wattr);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 r = XMapWindow(display, win);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 surface = cairo_xlib_surface_create(display, win, visual, w, h);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 if(surface == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 printf("cairo_xlib_surface_create\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 drawing(surface, w, h);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 XFlush(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 sleep(10);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 XCloseDisplay(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 }