File indexing completed on 2024-11-10 04:57:25

0001 /*
0002     SPDX-FileCopyrightText: 2022 Xaver Hugl <xaver.hugl@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #include "contenttype_v1.h"
0007 
0008 #include "display.h"
0009 #include "surface_p.h"
0010 
0011 namespace KWin
0012 {
0013 
0014 static constexpr uint32_t s_version = 1;
0015 
0016 static ContentType waylandToKwinContentType(uint32_t type)
0017 {
0018     using Type = QtWaylandServer::wp_content_type_v1::type;
0019     switch (type) {
0020     case Type::type_photo:
0021         return ContentType::Photo;
0022     case Type::type_video:
0023         return ContentType::Video;
0024     case Type::type_game:
0025         return ContentType::Game;
0026     default:
0027         return ContentType::None;
0028     }
0029 }
0030 
0031 ContentTypeManagerV1Interface::ContentTypeManagerV1Interface(Display *display, QObject *parent)
0032     : QObject(parent)
0033     , QtWaylandServer::wp_content_type_manager_v1(*display, s_version)
0034 {
0035 }
0036 
0037 void ContentTypeManagerV1Interface::wp_content_type_manager_v1_destroy(Resource *resource)
0038 {
0039     wl_resource_destroy(resource->handle);
0040 }
0041 
0042 void ContentTypeManagerV1Interface::wp_content_type_manager_v1_get_surface_content_type(Resource *resource, uint32_t id, struct ::wl_resource *wlSurface)
0043 {
0044     SurfaceInterface *surface = SurfaceInterface::get(wlSurface);
0045     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
0046     if (surfacePrivate->contentTypeInterface) {
0047         wl_resource_post_error(resource->handle, error_already_constructed, "Surface already has a wp_content_type_v1");
0048         return;
0049     }
0050     surfacePrivate->contentTypeInterface = new ContentTypeV1Interface(surface, resource->client(), id);
0051 }
0052 
0053 ContentTypeV1Interface::ContentTypeV1Interface(SurfaceInterface *surface, wl_client *client, uint32_t id)
0054     : QtWaylandServer::wp_content_type_v1(client, id, s_version)
0055     , m_surface(surface)
0056 {
0057 }
0058 
0059 void ContentTypeV1Interface::wp_content_type_v1_set_content_type(Resource *, uint32_t content_type)
0060 {
0061     if (!m_surface) {
0062         return;
0063     }
0064     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
0065     surfacePrivate->pending->contentType = waylandToKwinContentType(content_type);
0066     surfacePrivate->pending->contentTypeIsSet = true;
0067 }
0068 
0069 void ContentTypeV1Interface::wp_content_type_v1_destroy(Resource *resource)
0070 {
0071     if (m_surface) {
0072         SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
0073         surfacePrivate->pending->contentType = ContentType::None;
0074         surfacePrivate->pending->contentTypeIsSet = true;
0075     }
0076     wl_resource_destroy(resource->handle);
0077 }
0078 
0079 void ContentTypeV1Interface::wp_content_type_v1_destroy_resource(Resource *)
0080 {
0081     delete this;
0082 }
0083 
0084 }
0085 
0086 #include "moc_contenttype_v1.cpp"