aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2017-10-24 23:22:27 +0200
committeremersion <contact@emersion.fr>2017-10-24 23:22:27 +0200
commite84d573b9127a431671e1f74773aee53830f8d09 (patch)
tree6b88900447a6a7f763b005371e01bcb9b45db70d
parente521b0404bb1a50326404a47bdb510f8fc46898e (diff)
Complete server-decoration implementation
-rw-r--r--include/wlr/types/wlr_server_decoration.h20
-rw-r--r--types/wlr_server_decoration.c144
2 files changed, 153 insertions, 11 deletions
diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h
index 11c2511c..059aa77f 100644
--- a/include/wlr/types/wlr_server_decoration.h
+++ b/include/wlr/types/wlr_server_decoration.h
@@ -5,25 +5,45 @@
struct wlr_server_decoration_manager {
struct wl_global *wl_global;
+ struct wl_list wl_resources;
struct wl_list decorations; // wlr_server_decoration::link
+ uint32_t default_mode; // enum org_kde_kwin_server_decoration_manager_mode
+
+ struct {
+ struct wl_signal new_decoration;
+ } events;
+
void *data;
};
struct wlr_server_decoration {
struct wl_resource *resource;
+ struct wlr_surface *surface;
struct wl_list link;
+ // enum org_kde_kwin_server_decoration_manager_mode
+ uint32_t requested_mode;
+ uint32_t sent_mode;
+
struct {
struct wl_signal destroy;
+ struct wl_signal request_mode;
} events;
+ struct wl_listener surface_destroy_listener;
+
void *data;
};
struct wlr_server_decoration_manager *wlr_server_decoration_manager_create(
struct wl_display *display);
+void wlr_server_decoration_manager_set_default_mode(
+ struct wlr_server_decoration_manager *manager, uint32_t default_mode);
void wlr_server_decoration_manager_destroy(
struct wlr_server_decoration_manager *manager);
+void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration,
+ uint32_t mode);
+
#endif
diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c
index 9c34304b..0d276445 100644
--- a/types/wlr_server_decoration.c
+++ b/types/wlr_server_decoration.c
@@ -1,13 +1,131 @@
#include <assert.h>
#include <stdlib.h>
#include <server-decoration-protocol.h>
+#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_server_decoration.h>
+#include <wlr/util/log.h>
+
+static void server_decoration_handle_release(struct wl_client *client,
+ struct wl_resource *resource) {
+ wl_resource_destroy(resource);
+}
+
+static void server_decoration_handle_request_mode(struct wl_client *client,
+ struct wl_resource *resource, uint32_t mode) {
+ struct wlr_server_decoration *decoration =
+ wl_resource_get_user_data(resource);
+ decoration->requested_mode = mode;
+ wl_signal_emit(&decoration->events.request_mode, decoration);
+}
+
+void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration,
+ uint32_t mode) {
+ if (decoration->sent_mode == mode) {
+ return;
+ }
+ org_kde_kwin_server_decoration_send_mode(decoration->resource, mode);
+ decoration->sent_mode = mode;
+}
+
+static void server_decoration_destroy(
+ struct wlr_server_decoration *decoration) {
+ wl_signal_emit(&decoration->events.destroy, decoration);
+ wl_list_remove(&decoration->surface_destroy_listener.link);
+ wl_resource_set_user_data(decoration->resource, NULL);
+ wl_list_remove(&decoration->link);
+ free(decoration);
+}
+
+static void server_decoration_destroy_resource(struct wl_resource *resource) {
+ struct wlr_server_decoration *decoration =
+ wl_resource_get_user_data(resource);
+ if (decoration != NULL) {
+ server_decoration_destroy(decoration);
+ }
+}
+
+static void server_decoration_handle_surface_destroy(
+ struct wl_listener *listener, void *data) {
+ struct wlr_server_decoration *decoration =
+ wl_container_of(listener, decoration, surface_destroy_listener);
+ server_decoration_destroy(decoration);
+}
+
+static const struct org_kde_kwin_server_decoration_interface
+server_decoration_impl = {
+ .release = server_decoration_handle_release,
+ .request_mode = server_decoration_handle_request_mode,
+};
+
+static void server_decoration_manager_handle_create(struct wl_client *client,
+ struct wl_resource *manager_resource, uint32_t id,
+ struct wl_resource *surface_resource) {
+ struct wlr_server_decoration_manager *manager =
+ wl_resource_get_user_data(manager_resource);
+ struct wlr_surface *surface = wl_resource_get_user_data(surface_resource);
+
+ struct wlr_server_decoration *decoration =
+ calloc(1, sizeof(struct wlr_server_decoration));
+ if (decoration == NULL) {
+ wl_client_post_no_memory(client);
+ return;
+ }
+ decoration->surface = surface;
+ decoration->requested_mode =
+ ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
+
+ int version = wl_resource_get_version(manager_resource);
+ decoration->resource = wl_resource_create(client,
+ &org_kde_kwin_server_decoration_interface, version, id);
+ if (decoration->resource == NULL) {
+ wl_client_post_no_memory(client);
+ free(decoration);
+ return;
+ }
+ wl_resource_set_implementation(decoration->resource,
+ &server_decoration_impl, decoration,
+ server_decoration_destroy_resource);
+
+ wlr_log(L_DEBUG, "new server_decoration %p (res %p)", decoration,
+ decoration->resource);
+
+ wl_signal_init(&decoration->events.destroy);
+ wl_signal_init(&decoration->events.request_mode);
+
+ wl_signal_add(&surface->events.destroy,
+ &decoration->surface_destroy_listener);
+ decoration->surface_destroy_listener.notify =
+ server_decoration_handle_surface_destroy;
+
+ wl_list_insert(&manager->decorations, &decoration->link);
+
+ org_kde_kwin_server_decoration_send_mode(decoration->resource,
+ manager->default_mode);
+ decoration->sent_mode = manager->default_mode;
+
+ wl_signal_emit(&manager->events.new_decoration, decoration);
+}
static const struct org_kde_kwin_server_decoration_manager_interface
server_decoration_manager_impl = {
- // TODO
+ .create = server_decoration_manager_handle_create,
};
+void wlr_server_decoration_manager_set_default_mode(
+ struct wlr_server_decoration_manager *manager, uint32_t default_mode) {
+ manager->default_mode = default_mode;
+
+ struct wl_resource *resource;
+ wl_resource_for_each(resource, &manager->wl_resources) {
+ org_kde_kwin_server_decoration_manager_send_default_mode(resource,
+ manager->default_mode);
+ }
+}
+
+void server_decoration_manager_destroy_resource(struct wl_resource *resource) {
+ wl_list_remove(wl_resource_get_link(resource));
+}
+
static void server_decoration_manager_bind(struct wl_client *client,
void *_manager, uint32_t version, uint32_t id) {
struct wlr_server_decoration_manager *manager = _manager;
@@ -20,15 +138,12 @@ static void server_decoration_manager_bind(struct wl_client *client,
return;
}
wl_resource_set_implementation(resource, &server_decoration_manager_impl,
- manager, NULL);
-}
+ manager, server_decoration_manager_destroy_resource);
-static void server_decoration_destroy(
- struct wlr_server_decoration *decoration) {
- wl_signal_emit(&decoration->events.destroy, decoration);
- wl_resource_set_user_data(decoration->resource, NULL);
- wl_list_remove(&decoration->link);
- free(decoration);
+ wl_list_insert(&manager->wl_resources, wl_resource_get_link(resource));
+
+ org_kde_kwin_server_decoration_manager_send_default_mode(resource,
+ manager->default_mode);
}
struct wlr_server_decoration_manager *wlr_server_decoration_manager_create(
@@ -45,7 +160,10 @@ struct wlr_server_decoration_manager *wlr_server_decoration_manager_create(
free(manager);
return NULL;
}
+ manager->default_mode = ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE;
+ wl_list_init(&manager->wl_resources);
wl_list_init(&manager->decorations);
+ wl_signal_init(&manager->events.new_decoration);
return manager;
}
@@ -54,11 +172,15 @@ void wlr_server_decoration_manager_destroy(
if (manager == NULL) {
return;
}
- struct wlr_server_decoration *decoration, *tmp;
- wl_list_for_each_safe(decoration, tmp, &manager->decorations,
+ struct wlr_server_decoration *decoration, *tmp_decoration;
+ wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations,
link) {
server_decoration_destroy(decoration);
}
+ struct wl_resource *resource, *tmp_resource;
+ wl_resource_for_each_safe(resource, tmp_resource, &manager->wl_resources) {
+ server_decoration_manager_destroy_resource(resource);
+ }
wl_global_destroy(manager->wl_global);
free(manager);
}