KWin
Loading...
Searching...
No Matches
viewporter.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "viewporter.h"
8#include "display.h"
9#include "surface_p.h"
10#include "viewporter_p.h"
11
12static const int s_version = 1;
13
14namespace KWin
15{
16class ViewporterInterfacePrivate : public QtWaylandServer::wp_viewporter
17{
18protected:
19 void wp_viewporter_destroy(Resource *resource) override;
20 void wp_viewporter_get_viewport(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
21};
22
24{
25 wl_resource_destroy(resource->handle);
26}
27
28void ViewporterInterfacePrivate::wp_viewporter_get_viewport(Resource *resource, uint32_t id, struct ::wl_resource *surface_resource)
29{
30 SurfaceInterface *surface = SurfaceInterface::get(surface_resource);
31 ViewportInterface *viewport = ViewportInterface::get(surface);
32
33 if (viewport) {
34 wl_resource_post_error(resource->handle, error_viewport_exists, "the specified surface already has a viewport");
35 return;
36 }
37
38 wl_resource *viewportResource = wl_resource_create(resource->client(), &wp_viewport_interface, resource->version(), id);
39
40 new ViewportInterface(surface, viewportResource);
41}
42
44 : QtWaylandServer::wp_viewport(resource)
45 , surface(surface)
46{
48 surfacePrivate->viewportExtension = this;
49}
50
52{
53 if (surface) {
55 surfacePrivate->viewportExtension = nullptr;
56 }
57}
58
63
65{
66 delete this;
67}
68
70{
71 if (surface) {
73 surfacePrivate->pending->viewport.sourceGeometry = QRectF();
74 surfacePrivate->pending->viewport.sourceGeometryIsSet = true;
75 surfacePrivate->pending->viewport.destinationSize = QSize();
76 surfacePrivate->pending->viewport.destinationSizeIsSet = true;
77 }
78
79 wl_resource_destroy(resource->handle);
80}
81
82void ViewportInterface::wp_viewport_set_source(Resource *resource, wl_fixed_t x_fixed, wl_fixed_t y_fixed, wl_fixed_t width_fixed, wl_fixed_t height_fixed)
83{
84 if (!surface) {
85 wl_resource_post_error(resource->handle, error_no_surface, "the wl_surface for this viewport no longer exists");
86 return;
87 }
88
89 const qreal x = wl_fixed_to_double(x_fixed);
90 const qreal y = wl_fixed_to_double(y_fixed);
91 const qreal width = wl_fixed_to_double(width_fixed);
92 const qreal height = wl_fixed_to_double(height_fixed);
93
94 if (x == -1 && y == -1 && width == -1 && height == -1) {
96 surfacePrivate->pending->viewport.sourceGeometry = QRectF();
97 surfacePrivate->pending->viewport.sourceGeometryIsSet = true;
98 return;
99 }
100
101 if (x < 0 || y < 0 || width <= 0 || height <= 0) {
102 wl_resource_post_error(resource->handle, error_bad_value, "invalid source geometry");
103 return;
104 }
105
107 surfacePrivate->pending->viewport.sourceGeometry = QRectF(x, y, width, height);
108 surfacePrivate->pending->viewport.sourceGeometryIsSet = true;
109}
110
111void ViewportInterface::wp_viewport_set_destination(Resource *resource, int32_t width, int32_t height)
112{
113 if (!surface) {
114 wl_resource_post_error(resource->handle, error_no_surface, "the wl_surface for this viewport no longer exists");
115 return;
116 }
117
118 if (width == -1 && height == -1) {
120 surfacePrivate->pending->viewport.destinationSize = QSize();
121 surfacePrivate->pending->viewport.destinationSizeIsSet = true;
122 return;
123 }
124
125 if (width <= 0 || height <= 0) {
126 wl_resource_post_error(resource->handle, error_bad_value, "invalid destination size");
127 return;
128 }
129
131 surfacePrivate->pending->viewport.destinationSize = QSize(width, height);
132 surfacePrivate->pending->viewport.destinationSizeIsSet = true;
133}
134
136 : QObject(parent)
138{
139 d->init(*display, s_version);
140}
141
145
146} // namespace KWin
147
148#include "moc_viewporter.cpp"
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
std::unique_ptr< SurfaceState > pending
Definition surface_p.h:137
static SurfaceInterfacePrivate * get(SurfaceInterface *surface)
Definition surface_p.h:99
ViewportInterface * viewportExtension
Definition surface_p.h:165
void wp_viewport_set_source(Resource *resource, wl_fixed_t x, wl_fixed_t y, wl_fixed_t width, wl_fixed_t height) override
ViewportInterface(SurfaceInterface *surface, wl_resource *resource)
~ViewportInterface() override
void wp_viewport_destroy(Resource *resource) override
void wp_viewport_set_destination(Resource *resource, int32_t width, int32_t height) override
void wp_viewport_destroy_resource(Resource *resource) override
static ViewportInterface * get(SurfaceInterface *surface)
QPointer< SurfaceInterface > surface
ViewporterInterface(Display *display, QObject *parent=nullptr)
void wp_viewporter_destroy(Resource *resource) override
void wp_viewporter_get_viewport(Resource *resource, uint32_t id, struct ::wl_resource *surface) override