~cosme/ubuntu/oneiric/wayland/wayland

« back to all changes in this revision

Viewing changes to wayland/wayland-client.c

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-02-23 18:13:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110223181323-xm62w5zi2adkscxq
Tags: 0.1~git20110214.e4762a6a-0ubuntu1
* Update to new git snapshot from 2011-02-14 up to commit e4762a6a. (This
  is the most recent upstream commit that doesn't require moving to a
  newer version of mesa.)
  (LP: #700986)
* copyright: Update to match current codebase, and reformat to follow
  dep5 style.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include "wayland-util.h"
39
39
#include "wayland-client.h"
40
40
 
41
 
static const char socket_name[] = "\0wayland";
42
 
 
43
41
struct wl_global_listener {
44
42
        wl_display_global_func_t handler;
45
43
        void *data;
53
51
};
54
52
 
55
53
struct wl_proxy {
56
 
        struct wl_object base;
 
54
        struct wl_object object;
57
55
        struct wl_display *display;
58
56
        struct wl_list listener_list;
59
57
        void *user_data;
146
144
        if (proxy == NULL)
147
145
                return NULL;
148
146
 
149
 
        proxy->base.interface = interface;
150
 
        proxy->base.id = id;
 
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);
154
152
 
155
153
        return proxy;
156
154
}
171
169
        wl_list_for_each_safe(listener, next, &proxy->listener_list, link)
172
170
                free(listener);
173
171
 
174
 
        wl_hash_table_remove(proxy->display->objects, proxy->base.id);
 
172
        wl_hash_table_remove(proxy->display->objects, proxy->object.id);
175
173
        free(proxy);
176
174
}
177
175
 
200
198
 
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]);
205
203
        va_end(ap);
206
204
 
207
205
        wl_closure_send(closure, proxy->display->connection);
275
273
 
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);
281
279
 
292
290
}
293
291
 
294
292
static void
295
 
display_handle_sync(void *data, struct wl_display *display, uint32_t key)
296
 
{
297
 
        struct wl_sync_handler *handler;
298
 
 
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");
303
 
                return;
304
 
        }
305
 
 
306
 
        wl_list_remove(&handler->link);
307
 
        handler->func(handler->data);
308
 
        free(handler);
309
 
}
310
 
 
311
 
static void
312
 
display_handle_frame(void *data,
313
 
                     struct wl_display *display, uint32_t key, uint32_t time)
314
 
{
315
 
        struct wl_frame_handler *handler;
316
 
 
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");
321
 
                return;
322
 
        }
323
 
 
324
 
        wl_list_remove(&handler->link);
325
 
        handler->func(handler->data, time);
326
 
        free(handler);
 
293
display_handle_key(void *data,
 
294
                   struct wl_display *display, uint32_t key, uint32_t time)
 
295
{
 
296
        struct wl_sync_handler *sync_handler;
 
297
        struct wl_frame_handler *frame_handler;
 
298
 
 
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);
 
304
                free(sync_handler);
 
305
                return;
 
306
        }
 
307
 
 
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);
 
314
                free(frame_handler);
 
315
                return;
 
316
        }
 
317
 
 
318
        fprintf(stderr, "unsolicited sync event, client gone?\n");
327
319
}
328
320
 
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,
335
 
        display_handle_sync,
336
 
        display_handle_frame
 
327
        display_handle_key
337
328
};
338
329
 
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)
341
332
{
342
333
        struct wl_display *display;
343
334
        struct sockaddr_un addr;
344
335
        socklen_t size;
 
336
        const char *runtime_dir;
 
337
        size_t name_size;
345
338
 
346
339
        display = malloc(sizeof *display);
347
340
        if (display == NULL)
354
347
                return NULL;
355
348
        }
356
349
 
 
350
        runtime_dir = getenv("XDG_RUNTIME_DIR");
 
351
        if (runtime_dir == NULL) {
 
352
                runtime_dir = ".";
 
353
                fprintf(stderr,
 
354
                        "XDG_RUNTIME_DIR not set, falling back to %s\n",
 
355
                        runtime_dir);
 
356
        }
 
357
 
 
358
        if (name == NULL)
 
359
                name = getenv("WAYLAND_DISPLAY");
 
360
        if (name == NULL)
 
361
                name = "wayland-0";
 
362
 
 
363
        memset(&addr, 0, sizeof addr);
357
364
        addr.sun_family = AF_LOCAL;
358
 
        memcpy(addr.sun_path, name, name_size);
 
365
        name_size =
 
366
                snprintf(addr.sun_path, sizeof addr.sun_path,
 
367
                         "%s/%s", runtime_dir, name) + 1;
359
368
 
360
369
        size = offsetof (struct sockaddr_un, sun_path) + name_size;
361
370
 
368
377
        display->objects = wl_hash_table_create();
369
378
        wl_list_init(&display->global_listener_list);
370
379
 
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);
375
384
 
467
476
                return;
468
477
        }
469
478
 
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);
473
482
 
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],
477
486
                                  listener->data);
478
487