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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright © 2013 Keith Packard <keithp@keithp.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
#include <xcb/dri3.h>
#include <xcb/present.h>
#define WIDTH 128
#define HEIGHT 128
int
main (int argc, char **argv)
{
xcb_connection_t *c;
int screen_num;
xcb_screen_t *screen;
xcb_gc_t gc;
xcb_present_event_t present_event;
xcb_window_t window;
xcb_generic_event_t *event;
xcb_generic_error_t *error;
const xcb_query_extension_reply_t *present_extension;
uint32_t window_mask;
uint32_t window_values[5];
xcb_ge_event_t *xge;
c = xcb_connect(NULL, &screen_num);
if (xcb_connection_has_error(c)) {
printf ("connection error\n");
exit(1);
}
screen = xcb_aux_get_screen(c, screen_num);
window_mask = XCB_CW_BACK_PIXEL|XCB_CW_EVENT_MASK;
window_values[0] = 0xffffff;
window_values[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(c,
0, /* depth */
(window = xcb_generate_id(c)), /* window */
screen->root, /* root */
0, /* x */
0, /* y */
WIDTH * 2, /* width */
HEIGHT, /* height */
0, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
screen->root_visual, /* visual */
window_mask, /* mask */
window_values); /* values */
xcb_create_gc(c,
(gc = xcb_generate_id(c)), /* gc */
window, /* drawable */
0, /* mask */
NULL); /* values */
xcb_present_select_input(c,
(present_event = xcb_generate_id(c)),
window,
XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY);
present_extension = xcb_get_extension_data(c, &xcb_present_id);
xcb_register_for_special_event(c,
present_extension->major_opcode,
present_event,
NULL);
xcb_map_window(c, window);
printf ("mapped\n");
for (;;) {
xcb_flush(c);
event = xcb_wait_for_event(c);
if (!event)
break;
printf ("event %d\n", event->response_type);
switch (event->response_type) {
case XCB_EXPOSE:
break;
case 0:
error = (xcb_generic_error_t *) event;
printf ("error %d major %d minor %d\n",
error->error_code,
error->major_code,
error->minor_code);
break;
case XCB_GE:
xge = (xcb_ge_event_t *) event;
if (xge->extension == present_extension->major_opcode) {
switch (xge->evtype) {
case XCB_PRESENT_CONFIGURE_NOTIFY: {
xcb_present_configure_notify_event_t *ce = (void *) event;
printf ("present configure %d %d %d %d\n",
ce->x, ce->y, ce->width, ce->height);
break;
}
}
}
break;
default:
printf ("response %d\n", event->response_type);
break;
}
}
return 0;
}
|