raiguard/odin-wayland

git clone https://git.raiguard.me/raiguard/odin-wayland

Caleb HeuerMove generated -> mockgenfd8ef50

trunk
1.8 KiB90 linesraw
1#+build linux
2#+vet explicit-allocators
3package wayland
4
5import rt "base:runtime"
6import "core:bufio"
7import "core:bytes"
8import "core:io"
9import "core:math/fixed"
10import "core:strings"
11import "core:sys/linux"
12
13Session :: struct {
14	socket_data: struct {
15		fd: linux.Fd,
16
17		reader_stream: io.Stream,
18		reader: bufio.Reader,
19
20		writer_stream: io.Stream,
21		writer: bufio.Writer,
22
23		read_writer: bufio.Read_Writer
24	},
25	socket_stream: io.Stream, // Read-writer.
26
27	message_read_buffer: bytes.Buffer,
28	message_write_buffer: bytes.Buffer,
29	debug_log_builder: strings.Builder,
30
31	objects: map[Object_ID]Object_Info,
32	next_id: Object_ID,
33
34	// Used for long-lived allocations..
35	allocator: rt.Allocator,
36	// Used for "per-frame" allocations - will automatically be emptied after pump_events is complete.
37	frame_allocator: rt.Allocator,
38
39	debug_logging_enabled: bool,
40}
41
42Object_Info :: struct {
43	kind: Object_Kind,
44	handlers: map[Opcode]Handler_Info,
45}
46
47Handler_Info :: struct {
48	dispatcher: #type proc(session: ^Session, stream: io.Stream, object_id: Object_ID, opcode: Opcode, handler_info: Handler_Info) -> Error,
49	handler: rawptr,
50	userdata: rawptr,
51}
52
53Error :: union {
54	io.Error,
55}
56
57Fixed :: fixed.Fixed(u32, 8)
58Opcode :: u16
59Object_ID :: distinct u32
60
61Message_Primitive :: union {
62	u32,
63	i32,
64	Object_ID,
65	Fixed,
66	string,
67	[]byte,
68	linux.Fd,
69}
70
71Raw_Message :: struct {
72	header: Message_Header,
73	payload: []byte, // Sliced from Session.message_read_buffer
74}
75
76// The Wayland protocol has a minimum "packet size" of 32 bits, so it encodes two 16-bit values as one 32-bit value,
77// creating an endianness dependency.
78when ODIN_ENDIAN == .Little {
79	Message_Header :: struct #packed {
80		object_id: Object_ID,
81		opcode: Opcode,
82		size: u16,
83	}
84} else {
85	Message_Header :: struct #packed {
86		object_id: Object_ID,
87		size: u16,
88		opcode: Opcode,
89	}
90}