-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_display.c
76 lines (63 loc) · 2.42 KB
/
d_display.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
#include "d_display.h"
#include "def.h"
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
#include <xcb/xproto.h>
#include <string.h>
D_XcbWindow d_XcbWindow;
#define WINDOW_CLASS "floating\0floating"
static const int windowClassLen = sizeof(WINDOW_CLASS);
static const char* windowName = "floating";
void d_Init(void)
{
int screenNum = 0;
d_XcbWindow.connection = xcb_connect(NULL, &screenNum);
d_XcbWindow.window = xcb_generate_id(d_XcbWindow.connection);
const xcb_setup_t* setup = xcb_get_setup(d_XcbWindow.connection);
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
for (int i = 0; i < screenNum; i++)
{
xcb_screen_next(&iter);
}
xcb_screen_t* screen = iter.data;
uint32_t values[2];
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
values[0] = screen->black_pixel;
// we need to limit what events we are interested in.
// otherwise the queue will fill up with garbage
values[1] = //XCB_EVENT_MASK_EXPOSURE |
// XCB_EVENT_MASK_POINTER_MOTION |
// XCB_EVENT_MASK_ENTER_WINDOW |
XCB_EVENT_MASK_KEY_PRESS |
XCB_EVENT_MASK_KEY_RELEASE;
// XCB_EVENT_MASK_LEAVE_WINDOW |
// XCB_EVENT_MASK_BUTTON_PRESS |
// XCB_EVENT_MASK_BUTTON_RELEASE;
//
xcb_create_window(d_XcbWindow.connection,
XCB_COPY_FROM_PARENT, // depth
d_XcbWindow.window, // window id
screen->root, // parent
0, 0, // x and y coordinate of new window
WINDOW_WIDTH, WINDOW_HEIGHT,
0, // border wdith
XCB_WINDOW_CLASS_COPY_FROM_PARENT, // class
XCB_COPY_FROM_PARENT, // visual
mask, values); // masks (TODO: set to get inputs)
xcb_change_property(d_XcbWindow.connection,
XCB_PROP_MODE_REPLACE,
d_XcbWindow.window,
XCB_ATOM_WM_NAME,
XCB_ATOM_STRING, 8, strlen(windowName), windowName);
xcb_change_property(d_XcbWindow.connection,
XCB_PROP_MODE_REPLACE,
d_XcbWindow.window,
XCB_ATOM_WM_CLASS,
XCB_ATOM_STRING, 8, windowClassLen, WINDOW_CLASS);
xcb_map_window(d_XcbWindow.connection, d_XcbWindow.window);
//xcb_flush(d_XcbWindow.connection);
}
void d_CleanUp(void)
{
xcb_disconnect(d_XcbWindow.connection);
}