From 717e9ef581024d327fd6c21afce20ba216339b72 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 4 Oct 2022 09:46:47 +0200 Subject: [PATCH] ipc: add view content type References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3599 --- include/sway/server.h | 1 + protocols/meson.build | 1 + sway/ipc-json.c | 25 +++++++++++++++++++++++++ sway/server.c | 3 +++ 4 files changed, 30 insertions(+) diff --git a/include/sway/server.h b/include/sway/server.h index 6a5a60c8c..2d796d047 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -110,6 +110,7 @@ struct sway_server { struct wlr_input_method_manager_v2 *input_method; struct wlr_text_input_manager_v3 *text_input; struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager; + struct wlr_content_type_manager_v1 *content_type_manager_v1; struct wlr_xdg_activation_v1 *xdg_activation_v1; struct wl_listener xdg_activation_v1_request_activate; diff --git a/protocols/meson.build b/protocols/meson.build index f18ab6f49..71e700bb0 100644 --- a/protocols/meson.build +++ b/protocols/meson.build @@ -16,6 +16,7 @@ protocols = [ wl_protocol_dir / 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml', wl_protocol_dir / 'unstable/tablet/tablet-unstable-v2.xml', wl_protocol_dir / 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml', + wl_protocol_dir / 'staging/content-type/content-type-v1.xml', 'wlr-layer-shell-unstable-v1.xml', 'idle.xml', 'wlr-input-inhibitor-unstable-v1.xml', diff --git a/sway/ipc-json.c b/sway/ipc-json.c index d757f21f2..73a3d3766 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include "config.h" @@ -201,6 +202,20 @@ static const char *ipc_json_user_idle_inhibitor_description(enum sway_idle_inhib return NULL; } +static const char *ipc_json_content_type_description(enum wp_content_type_v1_type type) { + switch (type) { + case WP_CONTENT_TYPE_V1_TYPE_NONE: + return "none"; + case WP_CONTENT_TYPE_V1_TYPE_PHOTO: + return "photo"; + case WP_CONTENT_TYPE_V1_TYPE_VIDEO: + return "video"; + case WP_CONTENT_TYPE_V1_TYPE_GAME: + return "game"; + } + return NULL; +} + json_object *ipc_json_get_version(void) { int major = 0, minor = 0, patch = 0; json_object *version = json_object_new_object(); @@ -602,6 +617,16 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object json_object_object_add(object, "idle_inhibitors", idle_inhibitors); + enum wp_content_type_v1_type content_type = WP_CONTENT_TYPE_V1_TYPE_NONE; + if (c->view->surface != NULL) { + content_type = wlr_surface_get_content_type_v1(server.content_type_manager_v1, + c->view->surface); + } + if (content_type != WP_CONTENT_TYPE_V1_TYPE_NONE) { + json_object_object_add(object, "content_type", + json_object_new_string(ipc_json_content_type_description(content_type))); + } + #if HAVE_XWAYLAND if (c->view->type == SWAY_VIEW_XWAYLAND) { json_object_object_add(object, "window", diff --git a/sway/server.c b/sway/server.c index fd9504cc4..ef7d4c4b8 100644 --- a/sway/server.c +++ b/sway/server.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -205,6 +206,8 @@ bool server_init(struct sway_server *server) { wlr_primary_selection_v1_device_manager_create(server->wl_display); wlr_viewporter_create(server->wl_display); wlr_single_pixel_buffer_manager_v1_create(server->wl_display); + server->content_type_manager_v1 = + wlr_content_type_manager_v1_create(server->wl_display, 1); struct wlr_xdg_foreign_registry *foreign_registry = wlr_xdg_foreign_registry_create(server->wl_display);