kwin/tests/pointerconstraintstest.h
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

179 lines
3.8 KiB
C++

/*
SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef POINTERCONSTRAINTSTEST_H
#define POINTERCONSTRAINTSTEST_H
#include <QObject>
#include <QQuickView>
#include <xcb/xcb.h>
namespace KWayland
{
namespace Client
{
class ConnectionThread;
class Registry;
class Compositor;
class Seat;
class Pointer;
class PointerConstraints;
class LockedPointer;
class ConfinedPointer;
}
}
class MainWindow;
class Backend : public QObject
{
Q_OBJECT
public:
Backend(QObject *parent = nullptr)
: QObject(parent)
{
}
Q_PROPERTY(int mode READ mode CONSTANT)
Q_PROPERTY(bool lockHint MEMBER m_lockHint NOTIFY lockHintChanged)
Q_PROPERTY(bool errorsAllowed READ errorsAllowed WRITE setErrorsAllowed NOTIFY errorsAllowedChanged)
virtual void init(QQuickView *view)
{
m_view = view;
}
int mode() const
{
return (int)m_mode;
}
bool lockHint() const
{
return m_lockHint;
}
bool errorsAllowed() const
{
return m_errorsAllowed;
}
void setErrorsAllowed(bool set)
{
if (m_errorsAllowed == set) {
return;
}
m_errorsAllowed = set;
Q_EMIT errorsAllowedChanged();
}
Q_INVOKABLE virtual void lockRequest(bool persistent = true, QRect region = QRect())
{
}
Q_INVOKABLE virtual void unlockRequest()
{
}
Q_INVOKABLE virtual void confineRequest(bool persistent = true, QRect region = QRect())
{
}
Q_INVOKABLE virtual void unconfineRequest()
{
}
Q_INVOKABLE virtual void hideAndConfineRequest(bool confineBeforeHide = false)
{
}
Q_INVOKABLE virtual void undoHideRequest()
{
}
Q_SIGNALS:
void confineChanged(bool confined);
void lockChanged(bool locked);
void lockHintChanged();
void errorsAllowedChanged();
void forceSurfaceCommit();
protected:
enum class Mode {
Wayland = 0,
X = 1
};
QQuickView *view() const
{
return m_view;
}
void setMode(Mode set)
{
m_mode = set;
}
private:
QQuickView *m_view;
Mode m_mode;
bool m_lockHint = true;
bool m_errorsAllowed = false;
};
class WaylandBackend : public Backend
{
Q_OBJECT
public:
WaylandBackend(QObject *parent = nullptr);
void init(QQuickView *view) override;
void lockRequest(bool persistent, QRect region) override;
void unlockRequest() override;
void confineRequest(bool persistent, QRect region) override;
void unconfineRequest() override;
private:
void setupRegistry(KWayland::Client::Registry *registry);
bool isLocked();
bool isConfined();
void cleanupLock();
void cleanupConfine();
KWayland::Client::ConnectionThread *m_connectionThreadObject;
KWayland::Client::Compositor *m_compositor = nullptr;
KWayland::Client::Seat *m_seat = nullptr;
KWayland::Client::Pointer *m_pointer = nullptr;
KWayland::Client::PointerConstraints *m_pointerConstraints = nullptr;
KWayland::Client::LockedPointer *m_lockedPointer = nullptr;
bool m_lockedPointerPersistent = false;
KWayland::Client::ConfinedPointer *m_confinedPointer = nullptr;
bool m_confinedPointerPersistent = false;
};
class XBackend : public Backend
{
Q_OBJECT
public:
XBackend(QObject *parent = nullptr);
void init(QQuickView *view) override;
void lockRequest(bool persistent, QRect region) override;
void unlockRequest() override;
void confineRequest(bool persistent, QRect region) override;
void unconfineRequest() override;
void hideAndConfineRequest(bool confineBeforeHide) override;
void undoHideRequest() override;
private:
bool tryConfine(int &error);
xcb_connection_t *m_xcbConn = nullptr;
};
#endif