kwin/src/wayland/viewporter_interface.cpp
Vlad Zahorodnii 7fffe99328 build: Add -Wno-unused-parameter compiler option
Due to being a compositor, kwin has to conform to some certain
interfaces. It means a lot of virtual functions and function tables to
integrate with C APIs. Naturally, we not always want to use every
argument in such functions.

Since we get -Wunused-parameter from -Wall, we have to plumb those
unused arguments in order to suppress compiler warnings at the moment.

However, I don't think that extra work is worth it. We cannot change or
alter prototypes in any way to fix the warning the desired way. Q_UNUSED
and similar macros are not good indicators of whether an argument is
used too, we tend to overlook putting or removing those macros. I've
also noticed that Q_UNUSED are not used to guide us with the removal no
longer needed parameters.

Therefore, I think it's worth adding -Wno-unused-parameter compiler
option to stop the compiler producing warnings about unused parameters.
It changes nothing except that we don't need to put Q_UNUSED anymore,
which can be really cumbersome sometimes. Note that it doesn't affect
unused variables, you'll still get a -Wunused-variable compiler warning
if a variable is unused.
2022-10-31 15:50:37 +00:00

146 lines
4.9 KiB
C++

/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "viewporter_interface.h"
#include "display.h"
#include "surface_interface_p.h"
#include "viewporter_interface_p.h"
static const int s_version = 1;
namespace KWaylandServer
{
class ViewporterInterfacePrivate : public QtWaylandServer::wp_viewporter
{
protected:
void wp_viewporter_destroy(Resource *resource) override;
void wp_viewporter_get_viewport(Resource *resource, uint32_t id, struct ::wl_resource *surface) override;
};
void ViewporterInterfacePrivate::wp_viewporter_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void ViewporterInterfacePrivate::wp_viewporter_get_viewport(Resource *resource, uint32_t id, struct ::wl_resource *surface_resource)
{
SurfaceInterface *surface = SurfaceInterface::get(surface_resource);
ViewportInterface *viewport = ViewportInterface::get(surface);
if (viewport) {
wl_resource_post_error(resource->handle, error_viewport_exists, "the specified surface already has a viewport");
return;
}
wl_resource *viewportResource = wl_resource_create(resource->client(), &wp_viewport_interface, resource->version(), id);
new ViewportInterface(surface, viewportResource);
}
ViewportInterface::ViewportInterface(SurfaceInterface *surface, wl_resource *resource)
: QtWaylandServer::wp_viewport(resource)
, surface(surface)
{
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->viewportExtension = this;
}
ViewportInterface::~ViewportInterface()
{
if (surface) {
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->viewportExtension = nullptr;
}
}
ViewportInterface *ViewportInterface::get(SurfaceInterface *surface)
{
return SurfaceInterfacePrivate::get(surface)->viewportExtension;
}
void ViewportInterface::wp_viewport_destroy_resource(Resource *resource)
{
delete this;
}
void ViewportInterface::wp_viewport_destroy(Resource *resource)
{
if (surface) {
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->pending.viewport.sourceGeometry = QRectF();
surfacePrivate->pending.viewport.sourceGeometryIsSet = true;
surfacePrivate->pending.viewport.destinationSize = QSize();
surfacePrivate->pending.viewport.destinationSizeIsSet = true;
}
wl_resource_destroy(resource->handle);
}
void 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)
{
if (!surface) {
wl_resource_post_error(resource->handle, error_no_surface, "the wl_surface for this viewport no longer exists");
return;
}
const qreal x = wl_fixed_to_double(x_fixed);
const qreal y = wl_fixed_to_double(y_fixed);
const qreal width = wl_fixed_to_double(width_fixed);
const qreal height = wl_fixed_to_double(height_fixed);
if (x == -1 && y == -1 && width == -1 && height == -1) {
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->pending.viewport.sourceGeometry = QRectF();
surfacePrivate->pending.viewport.sourceGeometryIsSet = true;
return;
}
if (x < 0 || y < 0 || width <= 0 || height <= 0) {
wl_resource_post_error(resource->handle, error_bad_value, "invalid source geometry");
return;
}
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->pending.viewport.sourceGeometry = QRectF(x, y, width, height);
surfacePrivate->pending.viewport.sourceGeometryIsSet = true;
}
void ViewportInterface::wp_viewport_set_destination(Resource *resource, int32_t width, int32_t height)
{
if (!surface) {
wl_resource_post_error(resource->handle, error_no_surface, "the wl_surface for this viewport no longer exists");
return;
}
if (width == -1 && height == -1) {
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->pending.viewport.destinationSize = QSize();
surfacePrivate->pending.viewport.destinationSizeIsSet = true;
return;
}
if (width <= 0 || height <= 0) {
wl_resource_post_error(resource->handle, error_bad_value, "invalid destination size");
return;
}
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(surface);
surfacePrivate->pending.viewport.destinationSize = QSize(width, height);
surfacePrivate->pending.viewport.destinationSizeIsSet = true;
}
ViewporterInterface::ViewporterInterface(Display *display, QObject *parent)
: QObject(parent)
, d(new ViewporterInterfacePrivate)
{
d->init(*display, s_version);
}
ViewporterInterface::~ViewporterInterface()
{
}
} // namespace KWaylandServer