KWin
Loading...
Searching...
No Matches
contenttype_v1.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Xaver Hugl <xaver.hugl@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "contenttype_v1.h"
7
8#include "display.h"
9#include "surface_p.h"
10
11namespace KWin
12{
13
14static constexpr uint32_t s_version = 1;
15
16static ContentType waylandToKwinContentType(uint32_t type)
17{
18 using Type = QtWaylandServer::wp_content_type_v1::type;
19 switch (type) {
20 case Type::type_photo:
21 return ContentType::Photo;
22 case Type::type_video:
23 return ContentType::Video;
24 case Type::type_game:
25 return ContentType::Game;
26 default:
27 return ContentType::None;
28 }
29}
30
32 : QObject(parent)
33 , QtWaylandServer::wp_content_type_manager_v1(*display, s_version)
34{
35}
36
37void ContentTypeManagerV1Interface::wp_content_type_manager_v1_destroy(Resource *resource)
38{
39 wl_resource_destroy(resource->handle);
40}
41
42void ContentTypeManagerV1Interface::wp_content_type_manager_v1_get_surface_content_type(Resource *resource, uint32_t id, struct ::wl_resource *wlSurface)
43{
44 SurfaceInterface *surface = SurfaceInterface::get(wlSurface);
45 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
46 if (surfacePrivate->contentTypeInterface) {
47 wl_resource_post_error(resource->handle, error_already_constructed, "Surface already has a wp_content_type_v1");
48 return;
49 }
50 surfacePrivate->contentTypeInterface = new ContentTypeV1Interface(surface, resource->client(), id);
51}
52
54 : QtWaylandServer::wp_content_type_v1(client, id, s_version)
55 , m_surface(surface)
56{
57}
58
59void ContentTypeV1Interface::wp_content_type_v1_set_content_type(Resource *, uint32_t content_type)
60{
61 if (!m_surface) {
62 return;
63 }
64 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
65 surfacePrivate->pending->contentType = waylandToKwinContentType(content_type);
66 surfacePrivate->pending->contentTypeIsSet = true;
67}
68
69void ContentTypeV1Interface::wp_content_type_v1_destroy(Resource *resource)
70{
71 if (m_surface) {
72 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(m_surface);
73 surfacePrivate->pending->contentType = ContentType::None;
74 surfacePrivate->pending->contentTypeIsSet = true;
75 }
76 wl_resource_destroy(resource->handle);
77}
78
79void ContentTypeV1Interface::wp_content_type_v1_destroy_resource(Resource *)
80{
81 delete this;
82}
83
84}
85
86#include "moc_contenttype_v1.cpp"
ContentTypeManagerV1Interface(Display *display, QObject *parent=nullptr)
ContentTypeV1Interface(SurfaceInterface *surface, wl_client *client, uint32_t id)
Class holding the Wayland server display loop.
Definition display.h:34
Resource representing a wl_surface.
Definition surface.h:80
static SurfaceInterface * get(wl_resource *native)
Definition surface.cpp:819
static SurfaceInterfacePrivate * get(SurfaceInterface *surface)
Definition surface_p.h:99
Session::Type type
Definition session.cpp:17
ContentType
Definition globals.h:284