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
|
// std
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// local
#include "scapx.h"
#include "defs.h"
// TODO: move this all to x.c
static Server_context_t *init_XCB_server();
static xcb_window_t create_win(Server_context_t *info);
static Server_context_t *init_XCB_server()
{
Server_context_t *info;
if (!(info = malloc(sizeof(Server_context_t)))) {
fprintf(stderr, "memory allocation failed.\n");
return NULL;
}
info->con = xcb_connect(NULL, &info->scr_nbr);
if (xcb_connection_has_error(info->con) > 0) {
fprintf(stderr, "Error opening display.\n");
free(info);
return NULL;
}
info->iter = xcb_setup_roots_iterator(xcb_get_setup(info->con));
for (; info->iter.rem; --info->scr_nbr, xcb_screen_next(&info->iter))
if (info->scr_nbr == 0) {
info->scr = info->iter.data;
break;
}
return info;
}
static xcb_window_t create_win(Server_context_t *info)
{
xcb_gcontext_t gc;
xcb_window_t win;
u32 vmask, vlist[2];
// create gc
win = info->scr->root;
gc = xcb_generate_id(info->con);
vmask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
vlist[0] = info->scr->black_pixel;
vlist[1] = 0;
xcb_create_gc (info->con, gc, win, vmask, vlist);
// create window
win = xcb_generate_id(info->con);
vmask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
vlist[0] = info->scr->white_pixel;
vlist[1] = XCB_EVENT_MASK_EXPOSURE;
xcb_create_window(info->con,
XCB_COPY_FROM_PARENT,
win,
info->scr->root,
0, 0,
150, 150,
10,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
info->scr->root_visual,
vmask, vlist
);
xcb_map_window(info->con, win);
xcb_flush(info->con);
return win;
}
int main(int argc, char **argv)
{
// TODO: Parse flags
Server_context_t *serv_context = init_XCB_server();
xcb_drawable_t win = create_win(serv_context);
pause();
xcb_disconnect(serv_context->con);
free(serv_context);
return 0;
}
|