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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
export type event_type = enum u32 {
FIRSTEVENT = 0,
QUIT = 0x100,
APP_TERMINATING,
APP_LOWMEMORY,
APP_WILLENTERBACKGROUND,
APP_DIDENTERBACKGROUND,
APP_WILLENTERFOREGROUND,
APP_DIDENTERFOREGROUND,
DISPLAYEVENT = 0x150,
WINDOWEVENT = 0x200,
SYSWMEVENT,
KEYDOWN = 0x300,
KEYUP,
TEXTEDITING,
TEXTINPUT,
KEYMAPCHANGED,
MOUSEMOTION = 0x400,
MOUSEBUTTONDOWN,
MOUSEBUTTONUP,
MOUSEWHEEL,
JOYAXISMOTION = 0x600,
JOYBALLMOTION,
JOYHATMOTION,
JOYBUTTONDOWN,
JOYBUTTONUP,
JOYDEVICEADDED,
JOYDEVICEREMOVED,
CONTROLLERAXISMOTION = 0x650,
CONTROLLERBUTTONDOWN,
CONTROLLERBUTTONUP,
CONTROLLERDEVICEADDED,
CONTROLLERDEVICEREMOVED,
CONTROLLERDEVICEREMAPPED,
FINGERDOWN = 0x700,
FINGERUP,
FINGERMOTION,
DOLLARGESTURE = 0x800,
DOLLARRECORD,
MULTIGESTURE,
CLIPBOARDUPDATE = 0x900,
DROPFILE = 0x1000,
DROPTEXT,
DROPBEGIN,
DROPCOMPLETE,
AUDIODEVICEADDED = 0x1100,
AUDIODEVICEREMOVED,
SENSORUPDATE = 0x1200,
RENDER_TARGETS_RESET = 0x2000,
RENDER_DEVICE_RESET,
USEREVENT = 0x8000,
LASTEVENT = 0xFFFF
};
// Fields shared by every event
export type common_event = struct {
event_type: event_type,
timestamp: u32,
};
// Display state change event data (event.display.*)
export type display_event = struct {
common_event,
display: u32,
event: u8,
padding1: u8,
padding2: u8,
padding3: u8,
data1: i32,
};
// Window state change event data (event.window.*)
export type window_event = struct {
common_event,
window_id: u32,
event: u8,
padding1: u8,
padding2: u8,
padding3: u8,
data1: i32,
data2: i32,
};
// Keyboard button event structure (event.key.*)
export type keyboard_event = struct {
common_event,
window_id: u32,
state: u8,
repeat: u8,
padding2: u8,
padding3: u8,
keysym: uint, // TODO: Rig me up with the keysym type
};
// Size of the [[text_editing_event]] 'text' field.
export def TEXTEDITINGEVENT_TEXT_SIZE: size = 32;
// Keyboard text editing event structure (event.edit.*)
export type text_editing_event = struct {
common_event,
window_id: u32,
text: [TEXTEDITINGEVENT_TEXT_SIZE]char,
start: i32,
length: i32,
};
// Size of the [[text_input_event]] 'text' field.
export def TEXTINPUTEVENT_TEXT_SIZE: size = 32;
// Keyboard text input event structure (event.text.*)
export type text_input_event = struct {
common_event,
window_id: u32,
text: [TEXTINPUTEVENT_TEXT_SIZE]char,
};
// Mouse motion event structure (event.motion.*)
export type mouse_motion_event = struct {
common_event,
window_id: u32,
which: u32,
state: u32,
x: i32,
y: i32,
xrel: i32,
yrel: i32,
};
// Mouse button event structure (event.button.*)
export type mouse_button_event = struct {
common_event,
window_id: u32,
which: u32,
button: u8,
state: u8,
clicks: u8,
padding1: u8,
x: i32,
y: i32,
};
// Mouse wheel event structure (event.wheel.*)
export type mouse_wheel_event = struct {
common_event,
window_id: u32,
which: u32,
x: i32,
y: i32,
direction: u32,
};
// Joystick axis motion event structure (event.jaxis.*)
export type joy_axis_event = struct {
common_event,
which: i32, // TODO: Rig me up with the JoystickID type
axis: u8,
padding1: u8,
padding2: u8,
padding3: u8,
value: i16,
padding4: u16,
};
// Joystick trackball motion event structure (event.jball.*)
export type joy_ball_event = struct {
common_event,
which: i32, // TODO: Rig me up with the JoystickID type
ball: u8,
padding1: u8,
padding2: u8,
padding3: u8,
xrel: i16,
yrel: i16,
};
// Joystick hat position change event structure (event.jhat.*)
export type joy_hat_event = struct {
common_event,
which: i32, // TODO: Rig me up with the JoystickID type
hat: u8,
value: u8, // TODO: Rig me up with HAT_UP et al
padding1: u8,
padding2: u8,
};
// Joystick button event structure (event.jbutton.*)
export type joy_button_event = struct {
common_event,
which: i32, // TODO: Rig me up with the JoystickID type
button: u8,
state: u8,
padding1: u8,
padding2: u8,
};
// Joystick device event structure (event.jdevice.*)
export type joy_device_event = struct {
common_event,
which: i32,
};
// Game controller axis motion event structure (event.caxis.*)
export type controller_axis_event = struct {
common_event,
which: i32, // TODO
axis: u8,
padding1: u8,
padding2: u8,
padding3: u8,
value: i16,
padding4: u16,
};
// Game controller button event structure (event.cbutton.*)
export type controller_button_event = struct {
common_event,
which: i32,
button: u8,
state: u8,
padding1: u8,
padding2: u8,
};
// Controller device event structure (event.cdevice.*)
export type controller_device_event = struct {
common_event,
which: i32,
};
// Audio device event structure (event.adevice.*)
export type audio_device_event = struct {
common_event,
which: u32,
iscapture: u8,
padding1: u8,
padding2: u8,
padding3: u8,
};
// Touch finger event structure (event.tfinger.*)
export type touch_finger_event = struct {
common_event,
touch_id: i64, // TODO
finger_id: i64, // TODO
x: f32,
y: f32,
dx: f32,
dy: f32,
pressure: f32,
};
// Multiple Finger Gesture Event (event.mgesture.*)
export type multi_gesture_event = struct {
common_event,
touch_id: i64, // TODO
dtheta: f32,
ddist: f32,
x: f32,
y: f32,
num_fingers: u16,
padding: u16,
};
// Dollar Gesture Event (event.dgesture.*)
export type dollar_gesture_event = struct {
common_event,
touch_id: i64, // TODO
gesture_id: i64, // TODO
num_fingers: u32,
error: f32,
x: f32,
y: f32,
};
// An event used to request a file open by the system (event.drop.*)
// This event is enabled by default, you can disable it with [[eventstate]].
// If this event is enabled, you must free the filename in the event.
export type drop_event = struct {
common_event,
file: *char,
window_id: u32,
};
// Sensor event structure (event.sensor.*)
export type sensor_event = struct {
common_event,
which: i32,
data: [6]f32,
};
// The "quit requested" event
export type quit_event = struct {
common_event,
};
// OS Specific event
export type os_event = struct {
common_event,
};
// A user-defined event type (event.user.*)
export type user_event = struct {
common_event,
window_id: u32,
code: i32,
data1: *void,
data2: *void,
};
// A video driver dependent system event (event.syswm.*)
// This event is disabled by default, you can enable it with [[eventstate]].
export type syswm_event = struct {
common_event,
msg: *void, // TODO
};
// General event structure
export type event = union {
event_type: event_type,
common: common_event,
display: display_event,
window: window_event,
key: keyboard_event,
edit: text_editing_event,
text: text_input_event,
motion: mouse_motion_event,
button: mouse_button_event,
wheel: mouse_wheel_event,
jaxis: joy_axis_event,
jball: joy_ball_event,
jhat: joy_hat_event,
jbutton: joy_button_event,
jdevice: joy_device_event,
caxis: controller_axis_event,
cbutton: controller_button_event,
cdevice: controller_device_event,
adevice: audio_device_event,
sensor: sensor_event,
quit: quit_event,
user: user_event,
syswm: syswm_event,
tfinger: touch_finger_event,
mgesture: multi_gesture_event,
dgestures: dollar_gesture_event,
drop: drop_event,
padding: [56]u8,
};
// Pumps the event loop, gathering events from the input devices.
//
// This function updates the event queue and internal input device state.
//
// This should only be run in the thread that sets the video mode.
export @symbol("SDL_PumpEvents") fn pump_events() void;
export type eventaction = enum {
ADDEVENT,
PEEKEVENT,
GETEVENT,
};
// Checks the event queue for messages and optionally returns them.
//
// If 'action' is ADDEVENT, up to 'numevents' events will be added to the back
// of the event queue.
//
// If 'action' is PEEKEVENT, up to 'numevents' events at the front of the event
// queue, within the specified minimum and maximum type, will be returned and
// will not be removed from the queue.
//
// If 'action' is GETEVENT, up to 'numevents' events at the front of the event
// queue, within the specified minimum and maximum type, will be returned and
// will be removed from the queue.
//
// Returns the number of events actually stored, or -1 if there was an error.
//
// This function is thread-safe.
export @symbol("SDL_PeepEvents") fn peep_events(events: *event, numevents: int,
action: eventaction, mintype: event_type, maxtype: event_type) int;
// Checks to see if certain event types are in the event queue.
export @symbol("SDL_HasEvent") fn has_event(event_type: event_type) bool;
// Checks to see if certain event types are in the event queue.
export @symbol("SDL_HasEvents") fn has_events(mintype: event_type, maxtype: event_type) bool;
// This function clears events from the event queue
// This function only affects currently queued events. If you want to make
// sure that all pending OS events are flushed, you can call SDL_PumpEvents()
// on the main thread immediately before the flush call.
export @symbol("SDL_FlushEvent") fn flush_event(event_type: event_type) void;
// This function clears events from the event queue
// This function only affects currently queued events. If you want to make
// sure that all pending OS events are flushed, you can call SDL_PumpEvents()
// on the main thread immediately before the flush call.
export @symbol("SDL_FlushEvents") fn flush_events(mintype: event_type, maxtype: event_type) void;
// Polls for currently pending events.
//
// Returns 1 if there are any pending events, or 0 if there are none available.
//
// If 'event' is not null, the next event is removed from the queue and stored
// in that area.
export @symbol("SDL_PollEvent") fn poll_event(event: nullable *event) int;
// Waits indefinitely for the next available event.
//
// Returns 1, or 0 if there was an error while waiting for events.
//
// If 'event' is not null, the next event is removed from the queue and stored
// in that area.
export @symbol("SDL_WaitEvent") fn wait_event(event: nullable *event) int;
// Waits until the specified timeout (in milliseconds) for the next available event.
//
// Returns 1, or 0 if there was an error while waiting for events.
//
// If 'event' is not null, the next event is removed from the queue and stored
// in that area. The 'timeout' is the time (in milliseconds) to wait for next
// event.
export @symbol("SDL_WaitEventTimeout") fn wait_event_timeout(event: nullable *event, timeout: int) int;
// Add an event to the event queue.
//
// Returns 1 on success, 0 if the event was filtered, or -1 if the event queue
// was full or there was some other error.
export @symbol("SDL_PushEvent") fn push_event(event: *event) int;
// TODO: Finish rigging up other SDL_events.h bits
|