This pulls in a bit of extra infrastructure for discovering adertised objects on the client side.dev
parent
14fcff7726
commit
1e4b86af1a
@ -0,0 +1,84 @@ |
|||||||
|
#include <stdint.h> |
||||||
|
#include <stdlib.h> |
||||||
|
#include <stdio.h> |
||||||
|
#include <string.h> |
||||||
|
#include <fcntl.h> |
||||||
|
#include <glib.h> |
||||||
|
|
||||||
|
#include "wayland-client.h" |
||||||
|
#include "wayland-glib.h" |
||||||
|
|
||||||
|
/* The screenshooter is a good example of a custom object exposed by
|
||||||
|
* the compositor and serves as a test bed for implementing client |
||||||
|
* side marshalling outside libwayland.so */ |
||||||
|
|
||||||
|
static const char socket_name[] = "\0wayland"; |
||||||
|
|
||||||
|
struct screenshooter { |
||||||
|
uint32_t id; |
||||||
|
struct wl_display *display; |
||||||
|
}; |
||||||
|
|
||||||
|
static struct screenshooter * |
||||||
|
screenshooter_create(struct wl_display *display) |
||||||
|
{ |
||||||
|
struct screenshooter *screenshooter; |
||||||
|
uint32_t id; |
||||||
|
|
||||||
|
id = wl_display_get_object_id(display, "screenshooter"); |
||||||
|
if (id == 0) { |
||||||
|
fprintf(stderr, "server doesn't support screenshooter interface\n"); |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
screenshooter = malloc(sizeof screenshooter); |
||||||
|
if (screenshooter == NULL) |
||||||
|
return NULL; |
||||||
|
|
||||||
|
screenshooter->id = id; |
||||||
|
screenshooter->display = display; |
||||||
|
|
||||||
|
return screenshooter; |
||||||
|
} |
||||||
|
|
||||||
|
#define SCREENSHOOTER_SHOOT 0 |
||||||
|
|
||||||
|
static void |
||||||
|
screenshooter_shoot(struct screenshooter *screenshooter) |
||||||
|
{ |
||||||
|
uint32_t request[2]; |
||||||
|
|
||||||
|
request[0] = screenshooter->id; |
||||||
|
request[1] = SCREENSHOOTER_SHOOT | ((sizeof request) << 16); |
||||||
|
|
||||||
|
wl_display_write(screenshooter->display, |
||||||
|
request, sizeof request); |
||||||
|
} |
||||||
|
|
||||||
|
int main(int argc, char *argv[]) |
||||||
|
{ |
||||||
|
struct wl_display *display; |
||||||
|
GMainLoop *loop; |
||||||
|
GSource *source; |
||||||
|
struct screenshooter *s; |
||||||
|
|
||||||
|
display = wl_display_create(socket_name); |
||||||
|
if (display == NULL) { |
||||||
|
fprintf(stderr, "failed to create display: %m\n"); |
||||||
|
return -1; |
||||||
|
} |
||||||
|
|
||||||
|
loop = g_main_loop_new(NULL, FALSE); |
||||||
|
source = wayland_source_new(display); |
||||||
|
g_source_attach(source, NULL); |
||||||
|
|
||||||
|
s = screenshooter_create(display); |
||||||
|
if (s == NULL) |
||||||
|
exit(-1); |
||||||
|
|
||||||
|
screenshooter_shoot(s); |
||||||
|
|
||||||
|
g_main_loop_run(loop); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
#ifndef WAYLAND_UTIL_H |
||||||
|
#define WAYLAND_UTIL_H |
||||||
|
|
||||||
|
/* GCC visibility */ |
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 4 |
||||||
|
#define WL_EXPORT __attribute__ ((visibility("default"))) |
||||||
|
#else |
||||||
|
#define WL_EXPORT |
||||||
|
#endif |
||||||
|
|
||||||
|
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
||||||
|
|
||||||
|
#define container_of(ptr, type, member) ({ \ |
||||||
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
|
(type *)( (char *)__mptr - offsetof(type,member) );}) |
||||||
|
|
||||||
|
struct wl_hash { |
||||||
|
struct wl_object **objects; |
||||||
|
uint32_t count, alloc, id; |
||||||
|
}; |
||||||
|
|
||||||
|
int wl_hash_insert(struct wl_hash *hash, struct wl_object *object); |
||||||
|
struct wl_object *wl_hash_lookup(struct wl_hash *hash, uint32_t id); |
||||||
|
void wl_hash_delete(struct wl_hash *hash, struct wl_object *object); |
||||||
|
|
||||||
|
struct wl_list { |
||||||
|
struct wl_list *prev; |
||||||
|
struct wl_list *next; |
||||||
|
}; |
||||||
|
|
||||||
|
void wl_list_init(struct wl_list *list); |
||||||
|
void wl_list_insert(struct wl_list *list, struct wl_list *elm); |
||||||
|
void wl_list_remove(struct wl_list *elm); |
||||||
|
int wl_list_length(struct wl_list *list); |
||||||
|
|
||||||
|
|
||||||
|
#endif |
Loading…
Reference in new issue