raiguard/odin-wayland
git clone https://git.raiguard.me/raiguard/odin-wayland
fd8ef50
trunk
1/* 2======================================================================================================================== 3GENERATED CODE 4This code was generated with wayland/codegen from the 'wayland.xml' protocol file. 5Do not edit this code! 6======================================================================================================================== 7 8wayland.xml 9 10Copyright © 2008-2011 Kristian Høgsberg 11Copyright © 2010-2011 Intel Corporation 12Copyright © 2012-2013 Collabora, Ltd. 13 14Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 15documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 16rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 17permit persons to whom the Software is furnished to do so, subject to the following conditions: 18 19The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies 20or substantial portions of the Software. 21 22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 23WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 24OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 27======================================================================================================================== 28*/ 29 30#+build linux 31#+vet explicit-allocators 32package wayland 33 34import "base:intrinsics" 35import "core:fmt" 36import "core:log" 37import "core:io" 38 39// ===================================================================================================================== 40// DISPLAY 41 42// The core global object. This is a special singleton object. It is used for internal Wayland protocol features. 43Display_ID :: distinct Object_ID 44DISPLAY_INTERFACE_NAME :: "wl_display" 45DISPLAY_INTERFACE_VERSION :: 1 46 47// --------------------------------------------------------- 48// REQUESTS 49 50Display_Request :: enum Opcode { 51Sync = 0 , // asynchronous roundtrip 52Get_Registry = 1 , // get global registry object 53} 54 55/* 56The sync request asks the server to emit the 'done' event on the returned wl_callback object. Since requests are 57handled in-order and events are delivered in-order, this can be used as a barrier to ensure all previous requests and 58the resulting events have been handled. 59 60The object returned by this request will be destroyed by the compositor after the callback is fired and as such the 61client must not attempt to use it after that point. 62 63The callback_data passed in the callback is undefined and should be ignored. 64 65Returns: Callback object for the sync request. 66*/ 67@( require_results ) 68display_sync :: proc ( session : ^ Session ) -> ( callback_id : Callback_ID , error : Error ) { 69callback_id = Callback_ID ( _allocate_object ( session , . Callback )) 70_msg_write ( session , DISPLAY , Display_Request . Sync , Object_ID ( callback_id )) or_return 71return 72} 73 74/* 75This request creates a registry object that allows the client to list and bind the global objects available from the 76compositor. 77 78It should be noted that the server side resources consumed in response to a get_registry request can only be released 79when the client disconnects, not when the client side proxy is destroyed. Therefore, clients should invoke 80get_registry as infrequently as possible to avoid wasting memory. 81 82Returns: Global registry object. 83*/ 84@( require_results ) 85display_get_registry :: proc ( session : ^ Session ) -> ( registry_id : Registry_ID , error : Error ) { 86registry_id = Registry_ID ( _allocate_object ( session , . Registry )) 87_msg_write ( session , DISPLAY , Display_Request . Get_Registry , Object_ID ( registry_id )) or_return 88return 89} 90 91// --------------------------------------------------------- 92// EVENTS 93 94Display_Event :: enum Opcode { 95Error = 0 , // Fatal error event. 96Delete_ID = 1 , // Acknowledge object ID deletion. 97} 98 99// Fatal error event. 100// 101// The error event is sent out when a fatal (non-recoverable) error has occurred. The object_id argument is the object 102// where the error occurred, most often in response to a request to that object. The code identifies the error and is 103// defined by the object interface. As such, each interface defines its own set of error codes. The message is a brief 104// description of the error, for (debugging) convenience. 105Display_Error :: struct { 106session : ^ Session , 107// Object where the error occurred. 108object : Object_ID , 109// Error code. 110code : u32 , 111// Error description. 112message : string , 113} 114 115on_display_error :: proc ( session : ^ Session , handler : $ Handler_Type / proc ( e : Display_Error , userdata : $ Userdata_Type ), userdata : Userdata_Type ) 116where size_of ( userdata ) <= size_of ( rawptr ) 117{ 118dispatch :: proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error { 119assert ( session . objects [ object_id ]. kind == . Display ) 120event : Display_Error 121event . session = session 122_unmarshal_to ( & event . object , stream , session . frame_allocator ) or_return 123_unmarshal_to ( & event . code , stream , session . frame_allocator ) or_return 124_unmarshal_to ( & event . message , stream , session . frame_allocator ) or_return 125_message_log ( session , . Event , object_id , Display_Event ( opcode ), event . object , event . code , event . message ) 126( transmute ( Handler_Type ) handler_info . handler )( event , transmute ( Userdata_Type ) handler_info . userdata ) 127return nil 128} 129handler_info := Handler_Info { 130dispatcher = dispatch , 131handler = transmute ( rawptr ) handler , 132userdata = transmute ( rawptr ) userdata , 133} 134_on_event_internal ( session , Object_ID ( DISPLAY ), Opcode ( Display_Event . Error ), handler_info ) 135} 136 137// Acknowledge object ID deletion. 138// 139// This event is used internally by the object ID management logic. When a client deletes an object that it had created, 140// the server will send this event to acknowledge that it has seen the delete request. When the client receives this 141// event, it will know that it can safely reuse the object ID. 142Display_Delete_ID :: struct { 143session : ^ Session , 144// Deleted object ID. 145object : Object_ID , 146} 147 148on_display_delete_id :: proc ( session : ^ Session , handler : $ H / proc ( e : Display_Delete_ID , userdata : $ U ), userdata : U ) 149where size_of ( userdata ) <= size_of ( rawptr ) 150{ 151dispatch :: proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error { 152assert ( session . objects [ object_id ]. kind == . Display ) 153e : Display_Delete_ID 154e . session = session 155_unmarshal_to ( & e . object , stream , session . frame_allocator ) or_return 156_message_log ( session , . Event , object_id , Display_Event ( opcode ), e . object ) 157( transmute ( H ) handler_info . handler )( e , transmute ( U ) handler_info . userdata ) 158// TODO: We need to actually delete the ID here. 159return nil 160} 161handler_info := Handler_Info { 162dispatcher = dispatch , 163handler = transmute ( rawptr ) handler , 164userdata = transmute ( rawptr ) userdata , 165} 166_on_event_internal ( session , Object_ID ( DISPLAY ), Opcode ( Display_Event . Delete_ID ), handler_info ) 167} 168 169// ENUMS 170 171// Global error values. 172// 173// These errors are global and can be emitted in response to any server request. 174Display_Error_Enum :: enum u32 { 175// Server couldn't find object. 176Invalid_Object = 0 , 177// Method doesn't exist on the specified interface or malformed request. 178Invalid_Method = 1 , 179// Server is out of memory. 180No_Memory = 2 , 181// Implementation error in compositor. 182Implementation = 3 , 183} 184 185// ===================================================================================================================== 186// REGISTRY 187 188// Global registry object. 189// 190// The singleton global registry object. The server has a number of global objects that are available to all clients. 191// These objects typically represent an actual object in the server (for example, an input device) or they are singleton 192// objects that provide extension functionality. 193// 194// When a client creates a registry object, the registry object will emit a global event for each global currently in 195// the registry. Globals come and go as a result of device or monitor hotplugs, reconfiguration or other events, and the 196// registry will send out global and global_remove events to keep the client up to date with the changes. To mark the 197// end of the initial burst of events, the client can use the wl_display.sync request immediately after calling 198// wl_display.get_registry. 199// 200// A client can bind to a global object by using the bind request. This creates a client-side handle that lets the 201// object emit events to the client and lets the client invoke requests on the object. 202Registry_ID :: distinct Object_ID 203REGISTRY_INTERFACE_NAME :: "wl_registry" 204REGISTRY_INTERFACE_VERSION :: 1 205 206// --------------------------------------------------------- 207// REQUESTS 208 209Registry_Request :: enum Opcode { 210// Bind an object to the display. 211Bind = 0 , 212} 213 214// Binds a new, client-created object to the server using the specified name as the identifier. 215registry_bind :: proc ( session : ^ Session , registry_id : Registry_ID , name : u32 , interface : string , version : u32 , object_id : ^ $ ID_Type / Object_ID ) -> Error { 216object_id ^ = ID_Type ( _allocate_object ( session , _object_id_type_to_kind ( ID_Type ))) 217_msg_write ( session , registry_id , Registry_Request . Bind , name , interface , version , Object_ID ( object_id ^ )) or_return 218return nil 219} 220 221// --------------------------------------------------------- 222// EVENTS 223 224Registry_Event :: enum Opcode { 225// Announce global object. 226Global = 0 , 227// Announce removal of global object. 228Global_Remove , 229} 230 231// Notify the client of global objects. 232// 233// The event notifies the client that a global object with the given name is now available, and it implements the given 234// version of the given interface. 235Registry_Global :: struct { 236session : ^ Session , 237registry : Registry_ID , 238// Numeric name of the global object. 239name : u32 , 240// Interface implemented by the object. 241interface : string , 242// Interface version. 243version : u32 , 244} 245 246on_registry_global :: proc ( session : ^ Session , registry : Registry_ID , handler : $ H / proc ( e : Registry_Global , userdata : $ U ), userdata : U ) 247where size_of ( userdata ) <= size_of ( rawptr ) 248{ 249dispatch :: proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error { 250assert ( session . objects [ object_id ]. kind == . Registry ) 251e : Registry_Global 252e . session = session 253e . registry = Registry_ID ( object_id ) 254_unmarshal_to ( & e . name , stream , session . frame_allocator ) or_return 255_unmarshal_to ( & e . interface , stream , session . frame_allocator ) or_return 256_unmarshal_to ( & e . version , stream , session . frame_allocator ) or_return 257_message_log ( session , . Event , object_id , Registry_Event ( opcode ), e . name , e . interface , e . version ) 258( transmute ( H ) handler_info . handler )( e , transmute ( U ) handler_info . userdata ) 259return nil 260} 261handler_info := Handler_Info { 262dispatcher = dispatch , 263handler = transmute ( rawptr ) handler , 264userdata = transmute ( rawptr ) userdata , 265} 266_on_event_internal ( session , Object_ID ( registry ), Opcode ( Registry_Event . Global ), handler_info ) 267} 268 269// Notify the client of removed global objects. 270// 271// This event notifies the client that the global identified by name is no longer available. If the client bound to 272// the global using the bind request, the client should now destroy that object. 273// 274// The object remains valid and requests to the object will be ignored until the client destroys it, to avoid races 275// between the global going away and a client sending a request to it. 276Registry_Global_Remove :: struct { 277session : ^ Session , 278registry : Registry_ID , 279// Numeric name of the global object. 280name : u32 , 281} 282 283on_registry_global_remove :: proc ( session : ^ Session , registry : Registry_ID , handler : $ H / proc ( e : Registry_Global_Remove , userdata : $ U ), userdata : U ) { 284dispatch :: proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error { 285assert ( session . objects [ object_id ]. kind == . Registry ) 286e : Registry_Global_Remove 287e . session = session 288e . registry = Registry_ID ( object_id ) 289_unmarshal_to ( & e . name , stream , session . frame_allocator ) or_return 290_message_log ( session , . Event , object_id , opcode , e . name ) 291( transmute ( H ) handler_info . handler )( e , transmute ( U ) handler_info . userdata ) 292return nil 293} 294handler_info := Handler_Info { 295dispatcher = dispatch , 296handler = transmute ( rawptr ) handler , 297userdata = transmute ( rawptr ) userdata , 298} 299_on_event_internal ( session , Object_ID ( registry ), Opcode ( Registry_Event . Global_Remove ), handler_info ) 300} 301 302// ===================================================================================================================== 303// CALLBACK 304 305// Clients can handle the 'done' event to get notified when the related request is done. 306// 307// Note, because wl_callback objects are created from multiple independent factory interfaces, the wl_callback interface 308// is frozen at version 1. 309Callback_ID :: distinct Object_ID 310CALLBACK_INTERFACE_NAME :: "wl_callback" 311CALLBACK_INTERFACE_VERSION :: 1 312// TODO gen: frozen 313 314// EVENTS 315 316Callback_Event :: enum Opcode { 317Done = 0 , // done event 318} 319 320// Notify the client when the related request is done. 321Callback_Done :: struct { 322session : ^ Session , 323callback : Callback_ID , 324// request-specific data for the callback 325callback_data : u32 , 326} 327 328on_callback_done :: proc ( session : ^ Session , callback : Callback_ID , handler : $ H / proc ( e : Callback_Done , userdata : $ U ), userdata : U ) { 329dispatch :: proc ( session : ^ Session , stream : io . Stream , object_id : Object_ID , opcode : Opcode , handler_info : Handler_Info ) -> Error { 330assert ( session . objects [ object_id ]. kind == . Callback ) 331e : Callback_Done 332e . session = session 333e . callback = Callback_ID ( object_id ) 334_unmarshal_to ( & e . callback_data , stream , session . frame_allocator ) or_return 335_message_log ( session , . Event , object_id , Callback_Event ( opcode ), e . callback_data ) 336( transmute ( H ) handler_info . handler )( e , transmute ( U ) handler_info . userdata ) 337return nil 338} 339handler_info := Handler_Info { 340dispatcher = dispatch , 341handler = transmute ( rawptr ) handler , 342userdata = transmute ( rawptr ) userdata , 343} 344_on_event_internal ( session , Object_ID ( callback ), Opcode ( Callback_Event . Done ), handler_info ) 345} 346 347 348// ===================================================================================================================== 349// CALLBACK 350 351Compositor_ID :: distinct Object_ID 352COMPOSITOR_INTERFACE_NAME :: "wl_compositor" 353COMPOSITOR_VERSION :: 7