-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.c
93 lines (73 loc) · 1.86 KB
/
event.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <xcb/xcb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int
main (int argc, char **argv)
{
xcb_connection_t *c;
xcb_screen_t *s;
xcb_window_t w;
xcb_gcontext_t g;
xcb_generic_event_t *e;
uint32_t mask;
uint32_t values[2];
int done;
xcb_rectangle_t r = { 20, 20, 60, 60 };
/* open connection with the server */
c = xcb_connect (NULL, NULL);
if (!c)
{
printf ("Cannot open display\n");
exit (1);
}
s = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
/* create window */
mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = s->white_pixel;
values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
w = xcb_generate_id (c);
xcb_create_window (c, XCB_COPY_FROM_PARENT, w, s->root,
10, 10, 100, 100, 1,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
s->root_visual,
mask, values);
/* create black graphics context */
mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
values[0] = s->black_pixel;
values[1] = 0;
g = xcb_generate_id (c);
xcb_create_gc (c, g, w, mask, values);
/* map (show) the window */
xcb_map_window (c, w);
xcb_flush (c);
/* event loop */
done = 0;
while (!done && (e = xcb_wait_for_event (c)))
{
switch (e->response_type)
{
/* (re)draw
* the
* window
* */
case XCB_EXPOSE:
printf ("EXPOSE\n");
xcb_poly_fill_rectangle (c, w, g, 1, &r);
xcb_flush (c);
break;
/* exit
* on
* keypress
* */
case XCB_KEY_PRESS:
done = 1;
break;
}
free (e);
}
/* close connection
* to server */
xcb_disconnect (c);
return 0;
}