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
|
#define TB_IMPLEMENTATION
#include "core.h"
#include "../base/base_include.h"
#include "../platform/platform_include.h"
int main()
{
b32 running = 1;
Display *MainDisplay = XOpenDisplay(0);
mem_arena *arena = arena_create(MiB(8));
Window root = XDefaultRootWindow(MainDisplay);
int screen = DefaultScreen(MainDisplay);
Visual *v = DefaultVisual(MainDisplay, screen);
XSetWindowAttributes wa = {
.background_pixmap = None,
.background_pixel = BlackPixel(MainDisplay, DefaultScreen(MainDisplay)),
.border_pixmap = CopyFromParent,
.border_pixel = 0,
.bit_gravity = ForgetGravity,
.win_gravity = NorthWestGravity,
.backing_store = NotUseful,
.backing_planes = 1,
.backing_pixel = 0,
.save_under = False,
.event_mask = 0,
.do_not_propagate_mask = 0,
.override_redirect = False,
.colormap = CopyFromParent,
.cursor = None
};
i32 dp_heigth = DisplayHeight(MainDisplay, screen);
i32 dp_width = DisplayWidth(MainDisplay, screen);
WindowProperties p = {
.x = dp_width / 2,
.y = dp_heigth / 2,
.height = (u32)800,
.width = (u32)1200,
.border_width = 0,
.window_depth = CopyFromParent,
.window_class = CopyFromParent,
.value_mask = CWBackPixel,
};
Window window =
XCreateWindow(
MainDisplay,
root,
p.x,
p.y,
p.width,
p.height,
p.border_width,
p.window_depth,
p.window_class,
v,
p.value_mask,
&wa);
XSetWindowBorder(MainDisplay, window, 60);
XSelectInput(MainDisplay, window, ExposureMask | StructureNotifyMask | KeyReleaseMask | KeyPressMask);
XMapWindow(MainDisplay, window);
XEvent event;
u32 rect_width = 50;
u32 rect_height = 50;
i32 rect_x_position = p.width / 2;
i32 rect_y_position = p.height / 2;
u64 color = 0x0000ff00;
GC gc = XCreateGC(MainDisplay, window, 0, NIL);
XSetForeground(MainDisplay, gc, color);
for (;running;)
{
XNextEvent(MainDisplay, &event);
KeySym keysym = XLookupKeysym(&event.xkey, 0);
switch (event.type)
{
case (KeyPress):
{
if(keysym == XK_h) rect_x_position -= 20;
else if(keysym == XK_l) rect_x_position += 20;
else if(keysym == XK_k)
{
rect_y_position -= 20;
}
else if(keysym == XK_j)
{
rect_y_position += 20;
}
else if(keysym == XK_s)
{
}
else if(keysym == XK_Escape || keysym == XK_q) goto exit;
XClearWindow(MainDisplay, window);
XDrawRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50);
XFillRectangle(MainDisplay, window, gc, rect_x_position, rect_y_position, 50, 50);
break;
}
default:
{
}
}
}
exit:
arena_clear(arena);
return 0;
}
|