1 // Copyright © 2017-2021 Rémi Thebault 2 /// bindings to wayland-client-core.h 3 module wayland.native.client; 4 5 // Wayland client-core copyright: 6 /* 7 * Copyright © 2008 Kristian Høgsberg 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining 10 * a copy of this software and associated documentation files (the 11 * "Software"), to deal in the Software without restriction, including 12 * without limitation the rights to use, copy, modify, merge, publish, 13 * distribute, sublicense, and/or sell copies of the Software, and to 14 * permit persons to whom the Software is furnished to do so, subject to 15 * the following conditions: 16 * 17 * The above copyright notice and this permission notice (including the 18 * next paragraph) shall be included in all copies or substantial 19 * portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 * SOFTWARE. 29 */ 30 31 import wayland.native.util; 32 33 extern (C) nothrow 34 { 35 /** \class wl_proxy 36 * 37 * \brief Represents a protocol object on the client side. 38 * 39 * A wl_proxy acts as a client side proxy to an object existing in the 40 * compositor. The proxy is responsible for converting requests made by the 41 * clients with \ref wl_proxy_marshal() into Wayland's wire format. Events 42 * coming from the compositor are also handled by the proxy, which will in 43 * turn call the handler set with \ref wl_proxy_add_listener(). 44 * 45 * \note With the exception of function \ref wl_proxy_set_queue(), functions 46 * accessing a wl_proxy are not normally used by client code. Clients 47 * should normally use the higher level iface generated by the scanner to 48 * interact with compositor objects. 49 * 50 */ 51 struct wl_proxy; 52 53 /** \class wl_display 54 * 55 * \brief Represents a connection to the compositor and acts as a proxy to 56 * the wl_display singleton object. 57 * 58 * A wl_display object represents a client connection to a Wayland 59 * compositor. It is created with either \ref wl_display_connect() or 60 * \ref wl_display_connect_to_fd(). A connection is terminated using 61 * \ref wl_display_disconnect(). 62 * 63 * A wl_display is also used as the \ref wl_proxy for the wl_display 64 * singleton object on the compositor side. 65 * 66 * A wl_display object handles all the data sent from and to the 67 * compositor. When a \ref wl_proxy marshals a request, it will write its wire 68 * representation to the display's write buffer. The data is sent to the 69 * compositor when the client calls \ref wl_display_flush(). 70 * 71 * Incoming data is handled in two steps: queueing and dispatching. In the 72 * queue step, the data coming from the display fd is interpreted and 73 * added to a queue. On the dispatch step, the handler for the incoming 74 * event set by the client on the corresponding \ref wl_proxy is called. 75 * 76 * A wl_display has at least one event queue, called the <em>default 77 * queue</em>. Clients can create additional event queues with \ref 78 * wl_display_create_queue() and assign \ref wl_proxy's to it. Events 79 * occurring in a particular proxy are always queued in its assigned queue. 80 * A client can ensure that a certain assumption, such as holding a lock 81 * or running from a given thread, is true when a proxy event handler is 82 * called by assigning that proxy to an event queue and making sure that 83 * this queue is only dispatched when the assumption holds. 84 * 85 * The default queue is dispatched by calling \ref wl_display_dispatch(). 86 * This will dispatch any events queued on the default queue and attempt 87 * to read from the display fd if it's empty. Events read are then queued 88 * on the appropriate queues according to the proxy assignment. 89 * 90 * A user created queue is dispatched with \ref wl_display_dispatch_queue(). 91 * This function behaves exactly the same as wl_display_dispatch() 92 * but it dispatches given queue instead of the default queue. 93 * 94 * A real world example of event queue usage is Mesa's implementation of 95 * eglSwapBuffers() for the Wayland platform. This function might need 96 * to block until a frame callback is received, but dispatching the default 97 * queue could cause an event handler on the client to start drawing 98 * again. This problem is solved using another event queue, so that only 99 * the events handled by the EGL code are dispatched during the block. 100 * 101 * This creates a problem where a thread dispatches a non-default 102 * queue, reading all the data from the display fd. If the application 103 * would call \em poll(2) after that it would block, even though there 104 * might be events queued on the default queue. Those events should be 105 * dispatched with \ref wl_display_dispatch_pending() or \ref 106 * wl_display_dispatch_queue_pending() before flushing and blocking. 107 */ 108 struct wl_display; 109 110 /** \class wl_event_queue 111 * 112 * \brief A queue for \ref wl_proxy object events. 113 * 114 * Event queues allows the events on a display to be handled in a thread-safe 115 * manner. See \ref wl_display for details. 116 * 117 */ 118 struct wl_event_queue; 119 120 // used for wl_proxy_add_listener 121 alias void_func_t = void function(); 122 } 123 124 version (WlDynamic) 125 { 126 extern (C) nothrow 127 { 128 alias da_wl_event_queue_destroy = void function(wl_event_queue* queue); 129 130 alias da_wl_proxy_marshal = void function(wl_proxy* p, uint opcode, ...); 131 132 alias da_wl_proxy_marshal_array = void function(wl_proxy* p, uint opcode, wl_argument* args); 133 134 alias da_wl_proxy_create = wl_proxy* function(wl_proxy* factory, const(wl_interface)* iface); 135 136 alias da_wl_proxy_create_wrapper = void* function(void* proxy); 137 138 alias da_wl_proxy_wrapper_destroy = void function(void* proxy_wrapper); 139 140 alias da_wl_proxy_marshal_constructor = wl_proxy* function(wl_proxy* proxy, 141 uint opcode, const(wl_interface)* iface, ...); 142 143 alias da_wl_proxy_marshal_constructor_versioned = wl_proxy* function(wl_proxy* proxy, 144 uint opcode, const(wl_interface)* iface, uint ver, ...); 145 146 alias da_wl_proxy_marshal_array_constructor = wl_proxy* function(wl_proxy* proxy, 147 uint opcode, wl_argument* args, const(wl_interface)* iface); 148 149 alias da_wl_proxy_marshal_array_constructor_versioned = wl_proxy* function(wl_proxy* proxy, 150 uint opcode, wl_argument* args, const(wl_interface)* iface, uint ver); 151 152 alias da_wl_proxy_destroy = void function(wl_proxy* proxy); 153 154 alias da_wl_proxy_add_listener = int function(wl_proxy* proxy, 155 void_func_t* impl, void* data); 156 157 alias da_wl_proxy_get_listener = const(void)* function(wl_proxy* proxy); 158 159 alias da_wl_proxy_add_dispatcher = int function(wl_proxy* proxy, 160 wl_dispatcher_func_t dispatcher_func, const(void)* dispatcher_data, void* data); 161 162 alias da_wl_proxy_set_user_data = void function(wl_proxy* proxy, void* user_data); 163 164 alias da_wl_proxy_get_user_data = void* function(wl_proxy* proxy); 165 166 alias da_wl_proxy_get_version = uint function(wl_proxy* proxy); 167 168 alias da_wl_proxy_get_id = uint function(wl_proxy* proxy); 169 170 alias da_wl_proxy_get_class = const(char)* function(wl_proxy* proxy); 171 172 alias da_wl_proxy_set_queue = void function(wl_proxy* proxy, wl_event_queue* queue); 173 174 alias da_wl_display_connect = wl_display* function(const(char)* name); 175 176 alias da_wl_display_connect_to_fd = wl_display* function(int fd); 177 178 alias da_wl_display_disconnect = void function(wl_display* display); 179 180 alias da_wl_display_get_fd = int function(wl_display* display); 181 182 alias da_wl_display_dispatch = int function(wl_display* display); 183 184 alias da_wl_display_dispatch_queue = int function(wl_display* display, 185 wl_event_queue* queue); 186 187 alias da_wl_display_dispatch_queue_pending = int function(wl_display* display, 188 wl_event_queue* queue); 189 190 alias da_wl_display_dispatch_pending = int function(wl_display* display); 191 192 alias da_wl_display_get_error = int function(wl_display* display); 193 194 alias da_wl_display_get_protocol_error = uint function(wl_display* display, 195 const(wl_interface)** iface, uint* id); 196 197 alias da_wl_display_flush = int function(wl_display* display); 198 199 alias da_wl_display_roundtrip_queue = int function(wl_display* display, 200 wl_event_queue* queue); 201 202 alias da_wl_display_roundtrip = int function(wl_display* display); 203 204 alias da_wl_display_create_queue = wl_event_queue* function(wl_display* display); 205 206 alias da_wl_display_prepare_read_queue = int function(wl_display* display, 207 wl_event_queue* queue); 208 209 alias da_wl_display_prepare_read = int function(wl_display* display); 210 211 alias da_wl_display_cancel_read = void function(wl_display* display); 212 213 alias da_wl_display_read_events = int function(wl_display* display); 214 215 alias da_wl_log_set_handler_client = void function(wl_log_func_t handler); 216 } 217 218 __gshared 219 { 220 da_wl_event_queue_destroy wl_event_queue_destroy; 221 222 da_wl_proxy_marshal wl_proxy_marshal; 223 224 da_wl_proxy_marshal_array wl_proxy_marshal_array; 225 226 da_wl_proxy_create wl_proxy_create; 227 228 da_wl_proxy_create_wrapper wl_proxy_create_wrapper; 229 230 da_wl_proxy_wrapper_destroy wl_proxy_wrapper_destroy; 231 232 da_wl_proxy_marshal_constructor wl_proxy_marshal_constructor; 233 234 da_wl_proxy_marshal_constructor_versioned wl_proxy_marshal_constructor_versioned; 235 236 da_wl_proxy_marshal_array_constructor wl_proxy_marshal_array_constructor; 237 238 da_wl_proxy_marshal_array_constructor_versioned wl_proxy_marshal_array_constructor_versioned; 239 240 da_wl_proxy_destroy wl_proxy_destroy; 241 242 da_wl_proxy_add_listener wl_proxy_add_listener; 243 244 da_wl_proxy_get_listener wl_proxy_get_listener; 245 246 da_wl_proxy_add_dispatcher wl_proxy_add_dispatcher; 247 248 da_wl_proxy_set_user_data wl_proxy_set_user_data; 249 250 da_wl_proxy_get_user_data wl_proxy_get_user_data; 251 252 da_wl_proxy_get_version wl_proxy_get_version; 253 254 da_wl_proxy_get_id wl_proxy_get_id; 255 256 da_wl_proxy_get_class wl_proxy_get_class; 257 258 da_wl_proxy_set_queue wl_proxy_set_queue; 259 260 da_wl_display_connect wl_display_connect; 261 262 da_wl_display_connect_to_fd wl_display_connect_to_fd; 263 264 da_wl_display_disconnect wl_display_disconnect; 265 266 da_wl_display_get_fd wl_display_get_fd; 267 268 da_wl_display_dispatch wl_display_dispatch; 269 270 da_wl_display_dispatch_queue wl_display_dispatch_queue; 271 272 da_wl_display_dispatch_queue_pending wl_display_dispatch_queue_pending; 273 274 da_wl_display_dispatch_pending wl_display_dispatch_pending; 275 276 da_wl_display_get_error wl_display_get_error; 277 278 da_wl_display_get_protocol_error wl_display_get_protocol_error; 279 280 da_wl_display_flush wl_display_flush; 281 282 da_wl_display_roundtrip_queue wl_display_roundtrip_queue; 283 284 da_wl_display_roundtrip wl_display_roundtrip; 285 286 da_wl_display_create_queue wl_display_create_queue; 287 288 da_wl_display_prepare_read_queue wl_display_prepare_read_queue; 289 290 da_wl_display_prepare_read wl_display_prepare_read; 291 292 da_wl_display_cancel_read wl_display_cancel_read; 293 294 da_wl_display_read_events wl_display_read_events; 295 296 da_wl_log_set_handler_client wl_log_set_handler_client; 297 } 298 } 299 300 version (WlStatic) 301 { 302 extern (C) nothrow 303 { 304 void wl_event_queue_destroy(wl_event_queue* queue); 305 306 void wl_proxy_marshal(wl_proxy* p, uint opcode, ...); 307 308 void wl_proxy_marshal_array(wl_proxy* p, uint opcode, wl_argument* args); 309 310 wl_proxy* wl_proxy_create(wl_proxy* factory, const(wl_interface)* iface); 311 312 void* wl_proxy_create_wrapper(void* proxy); 313 314 void wl_proxy_wrapper_destroy(void* proxy_wrapper); 315 316 wl_proxy* wl_proxy_marshal_constructor(wl_proxy* proxy, uint opcode, 317 const(wl_interface)* iface, ...); 318 319 wl_proxy* wl_proxy_marshal_constructor_versioned(wl_proxy* proxy, 320 uint opcode, const(wl_interface)* iface, uint ver, ...); 321 322 wl_proxy* wl_proxy_marshal_array_constructor(wl_proxy* proxy, 323 uint opcode, wl_argument* args, const(wl_interface)* iface); 324 325 wl_proxy* wl_proxy_marshal_array_constructor_versioned(wl_proxy* proxy, 326 uint opcode, wl_argument* args, const(wl_interface)* iface, uint ver); 327 328 void wl_proxy_destroy(wl_proxy* proxy); 329 330 int wl_proxy_add_listener(wl_proxy* proxy, void_func_t* impl, void* data); 331 332 const(void)* wl_proxy_get_listener(wl_proxy* proxy); 333 334 int wl_proxy_add_dispatcher(wl_proxy* proxy, 335 wl_dispatcher_func_t dispatcher_func, const(void)* dispatcher_data, void* data); 336 337 void wl_proxy_set_user_data(wl_proxy* proxy, void* user_data); 338 339 void* wl_proxy_get_user_data(wl_proxy* proxy); 340 341 uint wl_proxy_get_version(wl_proxy* proxy); 342 343 uint wl_proxy_get_id(wl_proxy* proxy); 344 345 const(char)* wl_proxy_get_class(wl_proxy* proxy); 346 347 void wl_proxy_set_queue(wl_proxy* proxy, wl_event_queue* queue); 348 349 wl_display* wl_display_connect(const(char)* name); 350 351 wl_display* wl_display_connect_to_fd(int fd); 352 353 void wl_display_disconnect(wl_display* display); 354 355 int wl_display_get_fd(wl_display* display); 356 357 int wl_display_dispatch(wl_display* display); 358 359 int wl_display_dispatch_queue(wl_display* display, wl_event_queue* queue); 360 361 int wl_display_dispatch_queue_pending(wl_display* display, wl_event_queue* queue); 362 363 int wl_display_dispatch_pending(wl_display* display); 364 365 int wl_display_get_error(wl_display* display); 366 367 uint wl_display_get_protocol_error(wl_display* display, 368 const(wl_interface)** iface, uint* id); 369 370 int wl_display_flush(wl_display* display); 371 372 int wl_display_roundtrip_queue(wl_display* display, wl_event_queue* queue); 373 374 int wl_display_roundtrip(wl_display* display); 375 376 wl_event_queue* wl_display_create_queue(wl_display* display); 377 378 int wl_display_prepare_read_queue(wl_display* display, wl_event_queue* queue); 379 380 int wl_display_prepare_read(wl_display* display); 381 382 void wl_display_cancel_read(wl_display* display); 383 384 int wl_display_read_events(wl_display* display); 385 386 void wl_log_set_handler_client(wl_log_func_t handler); 387 } 388 }