#+build linux #+vet explicit-allocators package wayland import rt "base:runtime" import "core:bufio" import "core:bytes" import "core:io" import "core:math/fixed" import "core:strings" import "core:sys/linux" Session :: struct { socket_data: struct { fd: linux.Fd, reader_stream: io.Stream, reader: bufio.Reader, writer_stream: io.Stream, writer: bufio.Writer, read_writer: bufio.Read_Writer }, socket_stream: io.Stream, // Read-writer. message_read_buffer: bytes.Buffer, message_write_buffer: bytes.Buffer, debug_log_builder: strings.Builder, objects: map[Object_ID]Object_Info, next_id: Object_ID, // Used for long-lived allocations.. allocator: rt.Allocator, // Used for "per-frame" allocations - will automatically be emptied after pump_events is complete. frame_allocator: rt.Allocator, debug_logging_enabled: bool, } Object_Info :: struct { kind: Object_Kind, handlers: map[Opcode]Handler_Info, } Handler_Info :: struct { dispatcher: #type proc(session: ^Session, stream: io.Stream, object_id: Object_ID, opcode: Opcode, handler_info: Handler_Info) -> Error, handler: rawptr, userdata: rawptr, } Error :: union { io.Error, } Fixed :: fixed.Fixed(u32, 8) Opcode :: u16 Object_ID :: distinct u32 Message_Primitive :: union { u32, i32, Object_ID, Fixed, string, []byte, linux.Fd, } Raw_Message :: struct { header: Message_Header, payload: []byte, // Sliced from Session.message_read_buffer } // The Wayland protocol has a minimum "packet size" of 32 bits, so it encodes two 16-bit values as one 32-bit value, // creating an endianness dependency. when ODIN_ENDIAN == .Little { Message_Header :: struct #packed { object_id: Object_ID, opcode: Opcode, size: u16, } } else { Message_Header :: struct #packed { object_id: Object_ID, size: u16, opcode: Opcode, } }