kwin/src/wayland/idlenotify_v1_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

92 lines
2.6 KiB
C++

/*
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "idlenotify_v1_interface.h"
#include "display.h"
#include "idledetector.h"
#include "qwayland-server-ext-idle-notify-v1.h"
using namespace KWin;
namespace KWaylandServer
{
static const quint32 s_version = 1;
class IdleNotifyV1InterfacePrivate : public QtWaylandServer::ext_idle_notifier_v1
{
public:
IdleNotifyV1InterfacePrivate(Display *display);
protected:
void ext_idle_notifier_v1_destroy(Resource *resource) override;
void ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat) override;
};
class IdleNotificationV1Interface : public QObject, public QtWaylandServer::ext_idle_notification_v1
{
Q_OBJECT
public:
IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout);
protected:
void ext_idle_notification_v1_destroy_resource(Resource *resource) override;
void ext_idle_notification_v1_destroy(Resource *resource) override;
};
IdleNotifyV1InterfacePrivate::IdleNotifyV1InterfacePrivate(Display *display)
: QtWaylandServer::ext_idle_notifier_v1(*display, s_version)
{
}
void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void IdleNotifyV1InterfacePrivate::ext_idle_notifier_v1_get_idle_notification(Resource *resource, uint32_t id, uint32_t timeout, struct ::wl_resource *seat)
{
new IdleNotificationV1Interface(resource->client(), resource->version(), id, std::chrono::milliseconds(timeout));
}
IdleNotificationV1Interface::IdleNotificationV1Interface(wl_client *client, int version, uint32_t id, std::chrono::milliseconds timeout)
: QtWaylandServer::ext_idle_notification_v1(client, id, version)
{
auto detector = new IdleDetector(timeout, this);
connect(detector, &IdleDetector::idle, this, [this]() {
send_idled();
});
connect(detector, &IdleDetector::resumed, this, [this]() {
send_resumed();
});
}
void IdleNotificationV1Interface::ext_idle_notification_v1_destroy_resource(Resource *resource)
{
delete this;
}
void IdleNotificationV1Interface::ext_idle_notification_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
IdleNotifyV1Interface::IdleNotifyV1Interface(Display *display, QObject *parent)
: QObject(parent)
, d(new IdleNotifyV1InterfacePrivate(display))
{
}
IdleNotifyV1Interface::~IdleNotifyV1Interface()
{
}
}
#include "idlenotify_v1_interface.moc"