raiguard/odin-wayland
git clone https://git.raiguard.me/raiguard/odin-wayland
fd8ef50
trunk
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 { 14socket_data : struct { 15fd : linux . Fd , 16 17reader_stream : io . Stream , 18reader : bufio . Reader , 19 20writer_stream : io . Stream , 21writer : bufio . Writer , 22 23read_writer : bufio . Read_Writer 24}, 25socket_stream : io . Stream , // Read-writer. 26 27message_read_buffer : bytes . Buffer , 28message_write_buffer : bytes . Buffer , 29debug_log_builder : strings . Builder , 30 31objects : map [ Object_ID ] Object_Info , 32next_id : Object_ID , 33 34// Used for long-lived allocations.. 35allocator : rt . Allocator , 36// Used for "per-frame" allocations - will automatically be emptied after pump_events is complete. 37frame_allocator : rt . Allocator , 38 39debug_logging_enabled : bool , 40} 41 42Object_Info :: struct { 43kind : Object_Kind , 44handlers : map [ Opcode ] Handler_Info , 45} 46 47Handler_Info :: struct { 48dispatcher : #type proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error , 49handler : rawptr , 50userdata : rawptr , 51} 52 53Error :: union { 54io . Error , 55} 56 57Fixed :: fixed . Fixed ( u32 , 8 ) 58Opcode :: u16 59Object_ID :: distinct u32 60 61Message_Primitive :: union { 62u32 , 63i32 , 64Object_ID , 65Fixed , 66string , 67[] byte , 68linux . Fd , 69} 70 71Raw_Message :: struct { 72header : Message_Header , 73payload : [] 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 { 79Message_Header :: struct #packed { 80object_id : Object_ID , 81opcode : Opcode , 82size : u16 , 83} 84} else { 85Message_Header :: struct #packed { 86object_id : Object_ID , 87size : u16 , 88opcode : Opcode , 89} 90}