vx11 / events.v
102 lines · 89 sloc · 2.11 KB · c4bc47d81a04ec4c69336c7c85575735cb003365
Raw
1module vx11
2
3// Event is a value snapshot. Accessors check the active union member for you.
4// raw remains available for uncommon event types and extension cookies.
5pub struct Event {
6pub:
7 kind int
8 raw XEvent
9}
10
11pub struct KeyEvent {
12pub:
13 window Window
14 code u32
15 state u32
16 x int
17 y int
18 root_x int
19 root_y int
20 time Time
21}
22
23pub struct ButtonEvent {
24pub:
25 window Window
26 button u32
27 state u32
28 x int
29 y int
30}
31
32pub struct MotionEvent {
33pub:
34 window Window
35 state u32
36 x int
37 y int
38}
39
40pub struct ConfigureEvent {
41pub:
42 window Window
43 x int
44 y int
45 width int
46 height int
47}
48
49pub struct ExposeEvent {
50pub:
51 window Window
52 x int
53 y int
54 width int
55 height int
56 remaining int
57}
58
59pub struct ClientMessage {
60pub:
61 window Window
62 message_type Atom
63 format int
64 data [5]CLong
65}
66
67pub fn (e Event) key() ?KeyEvent {
68 if e.kind != key_press && e.kind != key_release { return none }
69 k := unsafe { e.raw.xkey }
70 return KeyEvent{k.window, k.keycode, k.state, int(k.x), int(k.y), int(k.x_root), int(k.y_root), k.time}
71}
72
73pub fn (e Event) button() ?ButtonEvent {
74 if e.kind != button_press && e.kind != button_release { return none }
75 b := unsafe { e.raw.xbutton }
76 return ButtonEvent{b.window, b.button, b.state, int(b.x), int(b.y)}
77}
78
79pub fn (e Event) motion() ?MotionEvent {
80 if e.kind != motion_notify { return none }
81 m := unsafe { e.raw.xmotion }
82 return MotionEvent{m.window, m.state, int(m.x), int(m.y)}
83}
84
85pub fn (e Event) configure() ?ConfigureEvent {
86 if e.kind != configure_notify { return none }
87 r := unsafe { e.raw.xconfigure }
88 return ConfigureEvent{r.window, int(r.x), int(r.y), int(r.width), int(r.height)}
89}
90
91pub fn (e Event) expose() ?ExposeEvent {
92 if e.kind != expose { return none }
93 r := unsafe { e.raw.xexpose }
94 return ExposeEvent{r.window, int(r.x), int(r.y), int(r.width), int(r.height), int(r.count)}
95}
96
97pub fn (e Event) client_message() ?ClientMessage {
98 if e.kind != client_message { return none }
99 m := unsafe { e.raw.xclient }
100 if m.format != 32 { return none }
101 return ClientMessage{m.window, m.message_type, int(m.format), unsafe { m.data.l }}
102}
103