146
144
if (proxy == NULL)
149
proxy->base.interface = interface;
147
proxy->object.interface = interface;
148
proxy->object.id = id;
151
149
proxy->display = display;
152
150
wl_list_init(&proxy->listener_list);
153
wl_hash_table_insert(display->objects, proxy->base.id, proxy);
151
wl_hash_table_insert(display->objects, proxy->object.id, proxy);
201
199
va_start(ap, opcode);
202
200
closure = wl_connection_vmarshal(proxy->display->connection,
203
&proxy->base, opcode, ap,
204
&proxy->base.interface->methods[opcode]);
201
&proxy->object, opcode, ap,
202
&proxy->object.interface->methods[opcode]);
207
205
wl_closure_send(closure, proxy->display->connection);
276
274
if (strcmp(interface, "display") == 0)
277
275
wl_hash_table_insert(display->objects,
278
id, &display->proxy.base);
276
id, &display->proxy.object);
279
277
else if (strcmp(interface, "visual") == 0)
280
278
add_visual(display, id);
295
display_handle_sync(void *data, struct wl_display *display, uint32_t key)
297
struct wl_sync_handler *handler;
299
handler = container_of(display->sync_list.next,
300
struct wl_sync_handler, link);
301
if (handler->key != key) {
302
fprintf(stderr, "unsolicited sync event, client gone?\n");
306
wl_list_remove(&handler->link);
307
handler->func(handler->data);
312
display_handle_frame(void *data,
313
struct wl_display *display, uint32_t key, uint32_t time)
315
struct wl_frame_handler *handler;
317
handler = container_of(display->frame_list. next,
318
struct wl_frame_handler, link);
319
if (handler->key != key) {
320
fprintf(stderr, "unsolicited frame event, client gone?\n");
324
wl_list_remove(&handler->link);
325
handler->func(handler->data, time);
293
display_handle_key(void *data,
294
struct wl_display *display, uint32_t key, uint32_t time)
296
struct wl_sync_handler *sync_handler;
297
struct wl_frame_handler *frame_handler;
299
sync_handler = container_of(display->sync_list.next,
300
struct wl_sync_handler, link);
301
if (!wl_list_empty(&display->sync_list) && sync_handler->key == key) {
302
wl_list_remove(&sync_handler->link);
303
sync_handler->func(sync_handler->data);
308
frame_handler = container_of(display->frame_list. next,
309
struct wl_frame_handler, link);
310
if (!wl_list_empty(&display->frame_list) &&
311
frame_handler->key == key) {
312
wl_list_remove(&frame_handler->link);
313
frame_handler->func(frame_handler->data, time);
318
fprintf(stderr, "unsolicited sync event, client gone?\n");
329
321
static const struct wl_display_listener display_listener = {
332
324
display_handle_no_memory,
333
325
display_handle_global,
334
326
display_handle_range,
339
330
WL_EXPORT struct wl_display *
340
wl_display_create(const char *name, size_t name_size)
331
wl_display_connect(const char *name)
342
333
struct wl_display *display;
343
334
struct sockaddr_un addr;
336
const char *runtime_dir;
346
339
display = malloc(sizeof *display);
347
340
if (display == NULL)
350
runtime_dir = getenv("XDG_RUNTIME_DIR");
351
if (runtime_dir == NULL) {
354
"XDG_RUNTIME_DIR not set, falling back to %s\n",
359
name = getenv("WAYLAND_DISPLAY");
363
memset(&addr, 0, sizeof addr);
357
364
addr.sun_family = AF_LOCAL;
358
memcpy(addr.sun_path, name, name_size);
366
snprintf(addr.sun_path, sizeof addr.sun_path,
367
"%s/%s", runtime_dir, name) + 1;
360
369
size = offsetof (struct sockaddr_un, sun_path) + name_size;
368
377
display->objects = wl_hash_table_create();
369
378
wl_list_init(&display->global_listener_list);
371
display->proxy.base.interface = &wl_display_interface;
372
display->proxy.base.id = 1;
380
display->proxy.object.interface = &wl_display_interface;
381
display->proxy.object.id = 1;
373
382
display->proxy.display = display;
374
383
wl_list_init(&display->proxy.listener_list);
470
message = &proxy->base.interface->events[opcode];
479
message = &proxy->object.interface->events[opcode];
471
480
closure = wl_connection_demarshal(display->connection,
472
481
size, display->objects, message);
474
483
wl_list_for_each(listener, &proxy->listener_list, link)
475
wl_closure_invoke(closure, &proxy->base,
484
wl_closure_invoke(closure, &proxy->object,
476
485
listener->implementation[opcode],