Make the wayland server a library used by the compositors.

Kristian Høgsberg 16 years ago
parent 87e0a384da
commit 122912c69b
  1. 60
      Makefile.in
  2. 32
      egl-compositor.c
  3. 32
      glx-compositor.c
  4. 68
      wayland.c
  5. 10
      wayland.h

@ -1,65 +1,51 @@
CFLAGS = @GCC_CFLAGS@
libs = libwayland-server.so libwayland.so
clients = flower window screenshot
compositors = egl-compositor.so glx-compositor.so
compositors = egl-compositor glx-compositor
all : wayland libwayland.so $(compositors) $(clients)
all : $(libs) $(compositors) $(clients)
wayland_objs = \
libwayland-server.so : \
wayland.o \
event-loop.o \
connection.o \
wayland-util.o
wayland : CFLAGS += @FFI_CFLAGS@
wayland : LDLIBS += @FFI_LIBS@ -ldl -rdynamic
libwayland-server.so : CFLAGS += @FFI_CFLAGS@
libwayland-server.so : LDLIBS += @FFI_LIBS@ -ldl -rdynamic
wayland : $(wayland_objs)
gcc -o $@ $(LDLIBS) $(wayland_objs)
libwayland_objs = \
libwayland.so : \
wayland-client.o \
connection.o \
wayland-util.o
libwayland.so : $(libwayland_objs)
$(libs) :
gcc -shared $^ $(LDLIBS) -o $@
$(compositors) $(clients) : CFLAGS += @LIBDRM_CFLAGS@
egl_compositor_objs = egl-compositor.o evdev.o cairo-util.o
egl-compositor.so : CFLAGS += @EGL_COMPOSITOR_CFLAGS@
egl-compositor.so : LDLIBS += @EGL_COMPOSITOR_LIBS@ -rdynamic -lrt
egl-compositor.so : $(egl_compositor_objs)
glx_compositor_objs = glx-compositor.o
glx-compositor.so : CFLAGS += @GL_COMPOSITOR_CFLAGS@
glx-compositor.so : LDLIBS += @GL_COMPOSITOR_LIBS@
glx-compositor.so : $(glx_compositor_objs)
egl-compositor : \
egl-compositor.o \
evdev.o \
cairo-util.o
egl-compositor : CFLAGS += @EGL_COMPOSITOR_CFLAGS@
egl-compositor : LDLIBS += @EGL_COMPOSITOR_LIBS@ -L. -lwayland-server -rdynamic -lrt
libwayland.so $(compositors) :
gcc -o $@ $^ $(LDLIBS) -shared
glx-compositor : glx-compositor.o
glx-compositor : CFLAGS += @GL_COMPOSITOR_CFLAGS@
glx-compositor : LDLIBS += @GL_COMPOSITOR_LIBS@ -L. -lwayland-server
flower_objs = flower.o wayland-glib.o cairo-util.o
window_objs = window.o gears.o wayland-glib.o cairo-util.o
screenshot_objs = screenshot.o wayland-glib.o
flower : flower.o wayland-glib.o cairo-util.o
window : window.o gears.o wayland-glib.o cairo-util.o
screenshot : screenshot.o wayland-glib.o
$(clients) : CFLAGS += @CLIENT_CFLAGS@
$(clients) : LDLIBS += @CLIENT_LIBS@ -lrt
define client_template
$(1): $$($(1)_objs) libwayland.so
endef
$(foreach c,$(clients),$(eval $(call client_template,$(c))))
$(clients) :
gcc -o $@ -L. -lwayland $(LDLIBS) $^
$(clients) : LDLIBS += @CLIENT_LIBS@ -L. -lwayland -lrt
clean :
rm -f $(clients) wayland *.o *.so
rm -f $(clients) $(compositors) *.o *.so
Makefile : Makefile.in
./config.status

@ -931,8 +931,8 @@ pick_config(struct egl_compositor *ec)
static const char gem_device[] = "/dev/dri/card0";
WL_EXPORT struct wl_compositor *
wl_compositor_create(struct wl_display *display)
static struct egl_compositor *
egl_compositor_create(struct wl_display *display)
{
EGLint major, minor;
struct egl_compositor *ec;
@ -1019,5 +1019,31 @@ wl_compositor_create(struct wl_display *display)
schedule_repaint(ec);
return &ec->base;
return ec;
}
/* The plan here is to generate a random anonymous socket name and
* advertise that through a service on the session dbus.
*/
static const char socket_name[] = "\0wayland";
int main(int argc, char *argv[])
{
struct wl_display *display;
struct egl_compositor *ec;
display = wl_display_create();
ec = egl_compositor_create(display);
wl_display_set_compositor(display, &ec->base);
if (wl_display_add_socket(display, socket_name)) {
fprintf(stderr, "failed to add socket: %m\n");
exit(EXIT_FAILURE);
}
wl_display_run(display);
return 0;
}

@ -271,8 +271,8 @@ display_data(int fd, uint32_t mask, void *data)
}
}
WL_EXPORT struct wl_compositor *
wl_compositor_create(struct wl_display *display)
static struct glx_compositor *
glx_compositor_create(struct wl_display *display)
{
static int attribs[] = {
GLX_RGBA,
@ -346,5 +346,31 @@ wl_compositor_create(struct wl_display *display)
schedule_repaint(gc);
return &gc->base;
return gc;
}
/* The plan here is to generate a random anonymous socket name and
* advertise that through a service on the session dbus.
*/
static const char socket_name[] = "\0wayland";
int main(int argc, char *argv[])
{
struct wl_display *display;
struct glx_compositor *gc;
display = wl_display_create();
gc = glx_compositor_create(display);
wl_display_set_compositor(display, &gc->base);
if (wl_display_add_socket(display, socket_name)) {
fprintf(stderr, "failed to add socket: %m\n");
exit(EXIT_FAILURE);
}
wl_display_run(display);
return 0;
}

@ -552,7 +552,7 @@ static const struct wl_interface display_interface = {
ARRAY_LENGTH(display_events), display_events,
};
static struct wl_display *
WL_EXPORT struct wl_display *
wl_display_create(void)
{
struct wl_display *display;
@ -725,7 +725,7 @@ wl_display_post_frame(struct wl_display *display,
}
}
void
WL_EXPORT void
wl_display_set_compositor(struct wl_display *display,
struct wl_compositor *compositor)
{
@ -738,18 +738,13 @@ wl_display_get_event_loop(struct wl_display *display)
return display->loop;
}
static void
WL_EXPORT void
wl_display_run(struct wl_display *display)
{
while (1)
wl_event_loop_wait(display->loop);
}
/* The plan here is to generate a random anonymous socket name and
* advertise that through a service on the session dbus.
*/
static const char socket_name[] = "\0wayland";
static void
socket_data(int fd, uint32_t mask, void *data)
{
@ -766,8 +761,8 @@ socket_data(int fd, uint32_t mask, void *data)
wl_client_create(display, client_fd);
}
static int
wl_display_add_socket(struct wl_display *display)
WL_EXPORT int
wl_display_add_socket(struct wl_display *display, const char *socket_name)
{
struct sockaddr_un name;
int sock;
@ -837,56 +832,3 @@ wl_surface_iterator_destroy(struct wl_surface_iterator *iterator)
{
free(iterator);
}
static int
load_compositor(struct wl_display *display, const char *path)
{
struct wl_compositor *(*create)(struct wl_display *display);
struct wl_compositor *compositor;
void *p;
p = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
if (p == NULL) {
fprintf(stderr, "failed to open compositor %s: %s\n",
path, dlerror());
return -1;
}
create = dlsym(p, "wl_compositor_create");
if (create == NULL) {
fprintf(stderr, "failed to look up compositor constructor\n");
return -1;
}
compositor = create(display);
if (compositor == NULL) {
fprintf(stderr, "couldn't create compositor\n");
return -1;
}
wl_display_set_compositor(display, compositor);
return 0;
}
int main(int argc, char *argv[])
{
struct wl_display *display;
const char *compositor = "./egl-compositor.so";
display = wl_display_create();
if (wl_display_add_socket(display)) {
fprintf(stderr, "failed to add socket: %m\n");
exit(EXIT_FAILURE);
}
if (argc == 2)
compositor = argv[1];
if (load_compositor(display, compositor))
return -1;
wl_display_run(display);
return 0;
}

@ -104,8 +104,6 @@ struct wl_map {
int32_t x, y, width, height;
};
struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
void wl_surface_set_data(struct wl_surface *surface, void *data);
void *wl_surface_get_data(struct wl_surface *surface);
@ -119,6 +117,11 @@ void wl_surface_iterator_destroy(struct wl_surface_iterator *iterator);
struct wl_object *
wl_input_device_create(struct wl_display *display, const char *path);
struct wl_display *wl_display_create(void);
struct wl_event_loop *wl_display_get_event_loop(struct wl_display *display);
int wl_display_add_socket(struct wl_display *display, const char *socket_name);
void wl_display_run(struct wl_display *display);
void
wl_display_add_object(struct wl_display *display, struct wl_object *object);
int
@ -179,7 +182,4 @@ struct wl_compositor_interface {
void wl_display_set_compositor(struct wl_display *display,
struct wl_compositor *compositor);
struct wl_compositor *
wl_compositor_create(struct wl_display *display);
#endif

Loading…
Cancel
Save