Don't track globals in the client lib, just send out events

Users of the client library must install an global handler to get access
to globals.
This commit is contained in:
Kristian Høgsberg 2010-08-10 14:02:48 -04:00
parent ccb75867ac
commit 4fe1a3ed3a
6 changed files with 112 additions and 238 deletions

View file

@ -36,45 +36,36 @@
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", 1);
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)
struct screenshooter;
static const struct wl_message screenshooter_requests[] = {
{ "shoot", "" },
};
static const struct wl_interface screenshooter_interface = {
"screenshooter", 1,
ARRAY_LENGTH(screenshooter_requests), screenshooter_requests,
0, NULL
};
static inline void
screenshooter_shoot(struct screenshooter *shooter)
{
uint32_t request[2];
wl_proxy_marshal((struct wl_proxy *) shooter, SCREENSHOOTER_SHOOT);
}
request[0] = screenshooter->id;
request[1] = SCREENSHOOTER_SHOOT | ((sizeof request) << 16);
static void
handle_global(struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data)
{
struct screenshooter **screenshooter = data;
wl_display_write(screenshooter->display,
request, sizeof request);
if (strcmp(interface, "screenshooter") == 0)
*screenshooter = (struct screenshooter *)
wl_proxy_create_for_id(display,
&screenshooter_interface, id);
}
int main(int argc, char *argv[])
@ -82,7 +73,7 @@ int main(int argc, char *argv[])
struct wl_display *display;
GMainLoop *loop;
GSource *source;
struct screenshooter *s;
struct screenshooter *screenshooter;
display = wl_display_create(socket_name, sizeof socket_name);
if (display == NULL) {
@ -90,16 +81,20 @@ int main(int argc, char *argv[])
return -1;
}
screenshooter = NULL;
wl_display_add_global_listener(display, handle_global, &screenshooter);
wl_display_iterate(display, WL_DISPLAY_READABLE);
if (screenshooter == NULL) {
fprintf(stderr, "display doesn't support screenshooter\n");
return -1;
}
loop = g_main_loop_new(NULL, FALSE);
source = wl_glib_source_new(display);
g_source_attach(source, NULL);
s = screenshooter_create(display);
if (s == NULL)
exit(-1);
screenshooter_shoot(screenshooter);
screenshooter_shoot(s);
g_idle_add((GSourceFunc) g_main_loop_quit, loop);
g_main_loop_run(loop);

View file

@ -766,7 +766,7 @@ static const struct wl_output_listener output_listener = {
};
static void
display_add_input(struct display *d, struct wl_object *object)
display_add_input(struct display *d, uint32_t id)
{
struct input *input;
@ -776,7 +776,7 @@ display_add_input(struct display *d, struct wl_object *object)
memset(input, 0, sizeof *input);
input->display = d;
input->input_device = (struct wl_input_device *) object;
input->input_device = wl_input_device_create(d->display, id);
input->pointer_focus = NULL;
input->keyboard_focus = NULL;
wl_list_insert(d->input_list.prev, &input->link);
@ -786,24 +786,25 @@ display_add_input(struct display *d, struct wl_object *object)
}
static void
display_handle_global(struct wl_display *display,
struct wl_object *object, void *data)
display_handle_global(struct wl_display *display, uint32_t id,
const char *interface, uint32_t version, void *data)
{
struct display *d = data;
if (wl_object_implements(object, "compositor", 1)) {
d->compositor = (struct wl_compositor *) object;
wl_compositor_add_listener(d->compositor, &compositor_listener, d);
} else if (wl_object_implements(object, "output", 1)) {
d->output = (struct wl_output *) object;
if (strcmp(interface, "compositor") == 0) {
d->compositor = wl_compositor_create(display, id);
wl_compositor_add_listener(d->compositor,
&compositor_listener, d);
} else if (strcmp(interface, "output") == 0) {
d->output = wl_output_create(display, id);
wl_output_add_listener(d->output, &output_listener, d);
} else if (wl_object_implements(object, "input_device", 1)) {
display_add_input(d, object);
} else if (wl_object_implements(object, "shell", 1)) {
d->shell = (struct wl_shell *) object;
} else if (strcmp(interface, "input_device") == 0) {
display_add_input(d, id);
} else if (strcmp(interface, "shell") == 0) {
d->shell = wl_shell_create(display, id);
wl_shell_add_listener(d->shell, &shell_listener, d);
} else if (wl_object_implements(object, "drm", 1)) {
d->drm = (struct wl_drm *) object;
} else if (strcmp(interface, "drm") == 0) {
d->drm = wl_drm_create(display, id);
wl_drm_add_listener(d->drm, &drm_listener, d);
}
}