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
|
import xlib, xutil, x, keysym
const
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 300
var
width, height: cuint
display: PDisplay
screen: cint
depth: int
win: TWindow
sizeHints: TXSizeHints
proc create_window =
width = WINDOW_WIDTH
height = WINDOW_HEIGHT
display = XOpenDisplay(nil)
if display == nil:
echo("Verbindung zum X-Server fehlgeschlagen")
quit(1)
screen = XDefaultScreen(display)
depth = XDefaultDepth(display, screen)
var rootwin = XRootWindow(display, screen)
win = XCreateSimpleWindow(display, rootwin, 100, 10,
width, height, 5,
XBlackPixel(display, screen),
XWhitePixel(display, screen))
size_hints.flags = PSize or PMinSize or PMaxSize
size_hints.min_width = width.cint
size_hints.max_width = width.cint
size_hints.min_height = height.cint
size_hints.max_height = height.cint
discard XSetStandardProperties(display, win, "Simple Window", "window",
0, nil, 0, addr(size_hints))
discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or
PointerMotionMask)
discard XMapWindow(display, win)
proc close_window =
discard XDestroyWindow(display, win)
discard XCloseDisplay(display)
var
xev: TXEvent
proc process_event =
var key: TKeySym
case int(xev.theType)
of KeyPress:
key = XLookupKeysym(cast[ptr TXKeyEvent](addr(xev)), 0)
if key != 0:
echo("keyboard event")
of ButtonPressMask, PointerMotionMask:
Echo("Mouse event")
else: nil
proc eventloop =
discard XFlush(display)
var num_events = int(XPending(display))
while num_events != 0:
dec(num_events)
discard XNextEvent(display, addr(xev))
process_event()
create_window()
while true:
eventloop()
close_window()
|