aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-06-23 15:10:52 -0400
committerDrew DeVault <sir@cmpwn.com>2017-06-26 10:26:55 -0400
commitf5b7bc033eced5c1ba3ba63b52985fb9b0e9f618 (patch)
treedf732b8b07009590cc6d2cfa2f23cceb794f3f3a
parent8a18cf456aac6fee666ccb4e7df0a9eb6c059756 (diff)
Add wlr_wl_compositor and remove wlr_wl_shm
-rw-r--r--CMakeLists.txt2
-rw-r--r--example/CMakeLists.txt2
-rw-r--r--example/compositor.c5
-rw-r--r--include/wlr/types/wlr_output.h3
-rw-r--r--include/wlr/wayland/wlr_compositor.h25
-rw-r--r--include/wlr/wlcore/wl_shm.h13
-rw-r--r--types/wlr_output.c6
-rw-r--r--wayland/CMakeLists.txt3
-rw-r--r--wayland/wlr_compositor.c60
-rw-r--r--wlcore/CMakeLists.txt3
-rw-r--r--wlcore/wl_shm.c78
11 files changed, 98 insertions, 102 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 571b7b61..bd3d4219 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,7 +61,7 @@ add_subdirectory(backend)
add_subdirectory(types)
add_subdirectory(session)
add_subdirectory(render)
-add_subdirectory(wlcore)
+add_subdirectory(wayland)
add_subdirectory(util)
add_subdirectory(example)
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index 6c53e923..100e110a 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -75,6 +75,6 @@ target_link_libraries(compositor
wlr-backend
wlr-session
wlr-render
- wlr-wlcore
+ wlr-wayland
${XKBCOMMON_LIBRARIES}
)
diff --git a/example/compositor.c b/example/compositor.c
index 5106ec96..a52fe460 100644
--- a/example/compositor.c
+++ b/example/compositor.c
@@ -10,7 +10,7 @@
#include <wlr/render.h>
#include <wlr/render/gles2.h>
#include <wlr/types/wlr_output.h>
-#include <wlr/wlcore/wl_shm.h>
+#include <wlr/wayland/wlr_compositor.h>
#include <xkbcommon/xkbcommon.h>
#include "shared.h"
@@ -37,7 +37,8 @@ int main() {
compositor_init(&compositor);
state.renderer = wlr_gles2_renderer_init();
- wlr_wl_shm_init(compositor.display);
+ wl_display_init_shm(compositor.display);
+ wlr_compositor_init(compositor.display);
compositor_run(&compositor);
}
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h
index 71e1d0fe..6c7c320d 100644
--- a/include/wlr/types/wlr_output.h
+++ b/include/wlr/types/wlr_output.h
@@ -19,8 +19,9 @@ struct wlr_output_state;
struct wlr_output {
const struct wlr_output_impl *impl;
struct wlr_output_state *state;
+ void *user_data;
struct wl_global *wl_global;
- struct wl_list resource_list;
+ struct wl_list wl_resources;
uint32_t flags;
char name[16];
diff --git a/include/wlr/wayland/wlr_compositor.h b/include/wlr/wayland/wlr_compositor.h
new file mode 100644
index 00000000..2c2ade62
--- /dev/null
+++ b/include/wlr/wayland/wlr_compositor.h
@@ -0,0 +1,25 @@
+#ifndef _WLR_COMPOSITOR_H
+#define _WLR_COMPOSITOR_H
+#include <wayland-server.h>
+
+struct wlr_compositor_state;
+
+struct wlr_compositor {
+ struct wlr_compositor_state *state;
+ void *user_data;
+ struct wl_global *wl_global;
+ struct wl_list wl_resources;
+
+ struct {
+ /** Emits a reference to the wl_resource just created */
+ struct wl_signal bound;
+ /** Emits a reference to the wl_surface just created */
+ struct wl_signal create_surface;
+ /** Emits a reference to the wl_region just created */
+ struct wl_signal create_region;
+ } events;
+};
+
+struct wlr_compositor *wlr_compositor_init(struct wl_display *display);
+
+#endif
diff --git a/include/wlr/wlcore/wl_shm.h b/include/wlr/wlcore/wl_shm.h
deleted file mode 100644
index 12c2ef78..00000000
--- a/include/wlr/wlcore/wl_shm.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef _WLR_WLCORE_WL_SHM_H
-#define _WLR_WLCORE_WL_SHM_H
-#include <wayland-server-core.h>
-#include <wlr/render.h>
-
-struct wlr_wl_shm;
-
-struct wlr_wl_shm *wlr_wl_shm_init(struct wl_display *display);
-void wlr_wl_shm_add_format(struct wlr_wl_shm *shm, enum wl_shm_format format);
-void wlr_wl_shm_add_renderer_formats(
- struct wlr_wl_shm *shm, struct wlr_renderer *renderer);
-
-#endif
diff --git a/types/wlr_output.c b/types/wlr_output.c
index 4d2e7778..b6ca7e79 100644
--- a/types/wlr_output.c
+++ b/types/wlr_output.c
@@ -41,7 +41,7 @@ static void wl_output_send_to_resource(struct wl_resource *resource) {
static void wl_output_destroy(struct wl_resource *resource) {
struct wlr_output *output = wl_resource_get_user_data(resource);
struct wl_resource *_resource = NULL;
- wl_resource_for_each(_resource, &output->resource_list) {
+ wl_resource_for_each(_resource, &output->wl_resources) {
if (_resource == resource) {
struct wl_list *link = wl_resource_get_link(_resource);
wl_list_remove(link);
@@ -71,7 +71,7 @@ static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output,
wl_client, &wl_output_interface, version, id);
wl_resource_set_implementation(wl_resource, &wl_output_impl,
wlr_output, wl_output_destroy);
- wl_list_insert(&wlr_output->resource_list, wl_resource_get_link(wl_resource));
+ wl_list_insert(&wlr_output->wl_resources, wl_resource_get_link(wl_resource));
wl_output_send_to_resource(wl_resource);
}
@@ -80,7 +80,7 @@ struct wl_global *wlr_output_create_global(
struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global;
- wl_list_init(&wlr_output->resource_list);
+ wl_list_init(&wlr_output->wl_resources);
return wl_global;
}
diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt
new file mode 100644
index 00000000..b629a95c
--- /dev/null
+++ b/wayland/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library(wlr-wayland STATIC
+ wlr_compositor.c
+)
diff --git a/wayland/wlr_compositor.c b/wayland/wlr_compositor.c
new file mode 100644
index 00000000..631c22b6
--- /dev/null
+++ b/wayland/wlr_compositor.c
@@ -0,0 +1,60 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <wayland-server.h>
+#include <wlr/wayland/wlr_compositor.h>
+#include <wlr/util/log.h>
+
+static void wl_compositor_create_surface(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id) {
+ wlr_log(L_DEBUG, "Creating surface for client");
+}
+
+static void wl_compositor_create_region(struct wl_client *client,
+ struct wl_resource *resource, uint32_t id) {
+ wlr_log(L_DEBUG, "Creating region for client");
+}
+
+static struct wl_compositor_interface wl_compositor_impl = {
+ .create_surface = wl_compositor_create_surface,
+ .create_region = wl_compositor_create_region,
+};
+
+static void wl_compositor_destroy(struct wl_resource *wl_resource) {
+ struct wlr_compositor *wlr_c = wl_resource_get_user_data(wl_resource);
+ struct wl_resource *_wl_resource = NULL;
+ wl_resource_for_each(_wl_resource, &wlr_c->wl_resources) {
+ if (_wl_resource == wl_resource) {
+ struct wl_list *link = wl_resource_get_link(_wl_resource);
+ wl_list_remove(link);
+ break;
+ }
+ }
+}
+
+static void wl_compositor_bind(struct wl_client *wl_client,
+ void *_wlr_compositor, uint32_t version, uint32_t id) {
+ struct wlr_compositor *wlr_c = _wlr_compositor;
+ assert(wl_client && wlr_c);
+ if (version > 3) {
+ wlr_log(L_ERROR, "Client requested unsupported wl_compositor version, disconnecting");
+ wl_client_destroy(wl_client);
+ return;
+ }
+ struct wl_resource *wl_resource = wl_resource_create(
+ wl_client, &wl_compositor_interface, version, id);
+ wl_resource_set_implementation(wl_resource, &wl_compositor_impl,
+ wlr_c, wl_compositor_destroy);
+ wl_list_insert(&wlr_c->wl_resources, wl_resource_get_link(wl_resource));
+}
+
+struct wlr_compositor *wlr_compositor_init(struct wl_display *display) {
+ struct wlr_compositor *wlr_c = calloc(1, sizeof(struct wlr_compositor));
+ struct wl_global *wl_global = wl_global_create(display,
+ &wl_compositor_interface, 1, wlr_c, wl_compositor_bind);
+ wlr_c->wl_global = wl_global;
+ wl_list_init(&wlr_c->wl_resources);
+ wl_signal_init(&wlr_c->events.bound);
+ wl_signal_init(&wlr_c->events.create_surface);
+ wl_signal_init(&wlr_c->events.create_region);
+ return wlr_c;
+}
diff --git a/wlcore/CMakeLists.txt b/wlcore/CMakeLists.txt
deleted file mode 100644
index cf6233c1..00000000
--- a/wlcore/CMakeLists.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-add_library(wlr-wlcore STATIC
- wl_shm.c
-)
diff --git a/wlcore/wl_shm.c b/wlcore/wl_shm.c
deleted file mode 100644
index 824b3620..00000000
--- a/wlcore/wl_shm.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#include <assert.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <wayland-server.h>
-#include <wlr/wlcore/wl_shm.h>
-#include <wlr/util/list.h>
-#include <wlr/util/log.h>
-#include <wlr/render.h>
-
-struct wlr_wl_shm {
- struct wl_global *wl_global;
- struct wl_list resources;
- struct wl_list pools;
- list_t *formats;
-};
-
-static void wl_shm_destroy(struct wl_resource *resource) {
- struct wlr_wl_shm *shm = wl_resource_get_user_data(resource);
- struct wl_resource *_resource = NULL;
- wl_resource_for_each(_resource, &shm->resources) {
- if (_resource == resource) {
- struct wl_list *link = wl_resource_get_link(_resource);
- wl_list_remove(link);
- break;
- }
- }
-}
-
-struct wl_shm_interface wl_shm_impl = {
- //.create_pool = wl_shm_create_pool
-};
-
-static void wl_shm_bind(struct wl_client *wl_client, void *_wlr_wl_shm,
- uint32_t version, uint32_t id) {
- struct wlr_wl_shm *wlr_shm = _wlr_wl_shm;
- assert(wl_client && wlr_shm);
- if (version > 1) {
- wlr_log(L_ERROR, "Client requested unsupported wl_shm version, disconnecting");
- wl_client_destroy(wl_client);
- return;
- }
- struct wl_resource *wl_resource = wl_resource_create(
- wl_client, &wl_shm_interface, version, id);
- wl_resource_set_implementation(wl_resource, &wl_shm_impl,
- wlr_shm, wl_shm_destroy);
- wl_list_insert(&wlr_shm->resources, wl_resource_get_link(wl_resource));
- for (size_t i = 0; i < wlr_shm->formats->length; ++i) {
- uint32_t *f = wlr_shm->formats->items[i];
- wl_shm_send_format(wl_resource, *f);
- }
-}
-
-struct wlr_wl_shm *wlr_wl_shm_init(struct wl_display *display) {
- struct wlr_wl_shm *shm = calloc(1, sizeof(struct wlr_wl_shm));
- wl_list_init(&shm->resources);
- wl_list_init(&shm->pools);
- shm->formats = list_create();
- shm->wl_global = wl_global_create(display, &wl_shm_interface, 1,
- shm, wl_shm_bind);
- return shm;
-}
-
-void wlr_wl_shm_add_format(struct wlr_wl_shm *shm, enum wl_shm_format format) {
- assert(shm);
- uint32_t *f = calloc(1, sizeof(uint32_t));
- *f = format;
- list_add(shm->formats, f);
-}
-
-void wlr_wl_shm_add_renderer_formats(struct wlr_wl_shm *shm,
- struct wlr_renderer *renderer) {
- assert(shm && renderer);
- size_t len;
- const enum wl_shm_format *formats = wlr_renderer_get_formats(renderer, &len);
- for (size_t i = 0; i < len; ++i) {
- wlr_wl_shm_add_format(shm, formats[i]);
- }
-}