diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8230d028c..a0f9a1aaa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,54 +1,47 @@ if (XCB_ICCCM_FOUND) set(normalhintsbasesizetest_SRCS normalhintsbasesizetest.cpp) add_executable(normalhintsbasesizetest ${normalhintsbasesizetest_SRCS}) target_link_libraries(normalhintsbasesizetest XCB::XCB XCB::ICCCM KF5::WindowSystem) endif() # next target set(screenedgeshowtest_SRCS screenedgeshowtest.cpp) add_executable(screenedgeshowtest ${screenedgeshowtest_SRCS}) target_link_libraries(screenedgeshowtest Qt5::Widgets Qt5::X11Extras KF5::ConfigCore KF5::WindowSystem KF5::WaylandClient ${XCB_XCB_LIBRARY}) -if (KF5Wayland_FOUND) - add_definitions(-DSOURCE_DIR="${KWIN_SOURCE_DIR}") - set(waylandclienttest_SRCS waylandclienttest.cpp) - add_executable(waylandclienttest ${waylandclienttest_SRCS}) - target_link_libraries(waylandclienttest Qt5::Core Qt5::Gui KF5::WaylandClient) -endif() - set(libinputtest_SRCS ${KWIN_SOURCE_DIR}/libinput/connection.cpp ${KWIN_SOURCE_DIR}/libinput/context.cpp ${KWIN_SOURCE_DIR}/libinput/device.cpp ${KWIN_SOURCE_DIR}/libinput/events.cpp ${KWIN_SOURCE_DIR}/libinput/libinput_logging.cpp ${KWIN_SOURCE_DIR}/logind.cpp ${KWIN_SOURCE_DIR}/udev.cpp libinputtest.cpp ) add_executable(libinputtest ${libinputtest_SRCS}) add_definitions(-DKWIN_BUILD_TESTING) target_link_libraries(libinputtest Qt5::Core Qt5::DBus Libinput::Libinput ${UDEV_LIBS} KF5::ConfigCore KF5::GlobalAccel KF5::WindowSystem) add_executable(x11shadowreader x11shadowreader.cpp) target_link_libraries(x11shadowreader XCB::XCB Qt5::Widgets Qt5::X11Extras KF5::ConfigCore KF5::WindowSystem) add_executable(pointerconstraints pointerconstraintstest.cpp) add_definitions(-DDIR="${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(pointerconstraints XCB::XCB Qt5::Gui Qt5::Quick KF5::WaylandClient) add_executable(pointergestures pointergesturestest.cpp) add_definitions(-DDIR="${CMAKE_CURRENT_SOURCE_DIR}") target_link_libraries(pointergestures Qt5::Gui Qt5::Quick KF5::WaylandClient) add_executable(cursorhotspottest cursorhotspottest.cpp) target_link_libraries(cursorhotspottest Qt5::Widgets) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(orientationtest_SRCS ../orientation_sensor.cpp orientationtest.cpp ) qt5_add_dbus_adaptor(orientationtest_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../org.kde.kwin.OrientationSensor.xml ${CMAKE_CURRENT_SOURCE_DIR}/../orientation_sensor.h KWin::OrientationSensor) add_executable(orientationtest ${orientationtest_SRCS}) target_link_libraries(orientationtest Qt5::DBus Qt5::Widgets Qt5::Sensors KF5::ConfigCore KF5::Notifications KF5::I18n) diff --git a/tests/waylandclienttest.cpp b/tests/waylandclienttest.cpp deleted file mode 100644 index 6984eb8aa..000000000 --- a/tests/waylandclienttest.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2014 Martin Gräßlin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ -#include "waylandclienttest.h" -// KWin::Wayland -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// Qt -#include -#include -#include -#include -#include -#include - -#include - -using namespace KWayland::Client; - -static Qt::GlobalColor s_colors[] = { - Qt::white, - Qt::red, - Qt::green, - Qt::blue, - Qt::black -}; -static int s_colorIndex = 0; - -WaylandClientTest::WaylandClientTest(QObject *parent) - : QObject(parent) - , m_connectionThread(new QThread(this)) - , m_connectionThreadObject(new ConnectionThread(nullptr)) - , m_eventQueue(nullptr) - , m_compositor(nullptr) - , m_output(nullptr) - , m_surface(nullptr) - , m_shm(nullptr) - , m_shellSurface(nullptr) - , m_timer(new QTimer(this)) -{ - init(); -} - -WaylandClientTest::~WaylandClientTest() -{ - m_connectionThread->quit(); - m_connectionThread->wait(); - m_connectionThreadObject->deleteLater(); -} - -void WaylandClientTest::init() -{ - connect(m_connectionThreadObject, &ConnectionThread::connected, this, - [this]() { - // create the event queue for the main gui thread - m_eventQueue = new EventQueue(this); - m_eventQueue->setup(m_connectionThreadObject); - // setup registry - Registry *registry = new Registry(this); - setupRegistry(registry); - }, - Qt::QueuedConnection); - - m_connectionThreadObject->moveToThread(m_connectionThread); - m_connectionThread->start(); - - m_connectionThreadObject->initConnection(); - - connect(m_timer, &QTimer::timeout, this, - [this]() { - s_colorIndex = (s_colorIndex + 1) % 5; - render(); - } - ); - m_timer->setInterval(1000); - m_timer->start(); -} - -void WaylandClientTest::setupRegistry(Registry *registry) -{ - connect(registry, &Registry::compositorAnnounced, this, - [this, registry](quint32 name) { - m_compositor = registry->createCompositor(name, 1, this); - m_surface = m_compositor->createSurface(this); - m_transient.surface = m_compositor->createSurface(this); - } - ); - connect(registry, &Registry::shellAnnounced, this, - [this, registry](quint32 name) { - Shell *shell = registry->createShell(name, 1, this); - m_shellSurface = shell->createSurface(m_surface, m_surface); - m_transient.shellSurface = shell->createSurface(m_transient.surface, m_transient.surface); - m_transient.shellSurface->setTransient(m_surface, QPoint(100, 100)); - connect(m_shellSurface, &ShellSurface::sizeChanged, this, static_cast(&WaylandClientTest::render)); - render(QSize(200, 200)); - } - ); - connect(registry, &Registry::outputAnnounced, this, - [this, registry](quint32 name) { - if (m_output) { - return; - } - m_output = registry->createOutput(name, 2, this); - } - ); - connect(registry, &Registry::shmAnnounced, this, - [this, registry](quint32 name) { - m_shm = registry->createShmPool(name, 1, this); - } - ); - connect(registry, &Registry::seatAnnounced, this, - [this, registry](quint32 name) { - Seat *s = registry->createSeat(name, 2, this); - connect(s, &Seat::hasKeyboardChanged, this, - [this, s](bool has) { - if (!has) { - return; - } - Keyboard *k = s->createKeyboard(this); - connect(k, &Keyboard::keyChanged, this, - [this](quint32 key, Keyboard::KeyState state) { - if (key == KEY_Q && state == Keyboard::KeyState::Released) { - QCoreApplication::instance()->quit(); - } - if (key == KEY_F && state == Keyboard::KeyState::Released) { - if (m_shellSurface) { - static bool s_fullscreen = false; - s_fullscreen = !s_fullscreen; - if (s_fullscreen) { - m_shellSurface->setFullscreen(); - } else { - m_shellSurface->setToplevel(); - } - } - } - if (key == KEY_T && state == Keyboard::KeyState::Released) { - if (m_transient.visible) { - m_transient.surface->attachBuffer(Buffer::Ptr()); - m_transient.surface->commit(Surface::CommitFlag::None); - m_transient.visible = false; - } else { - const QSize size(200, 200); - auto buffer = m_shm->getBuffer(size, size.width() * 4).toStrongRef(); - buffer->setUsed(true); - QImage image(buffer->address(), size.width(), size.height(), QImage::Format_ARGB32_Premultiplied); - image.fill(s_colors[s_colorIndex]); - - m_transient.surface->attachBuffer(*buffer); - m_transient.surface->damage(QRect(QPoint(0, 0), size)); - m_transient.surface->commit(Surface::CommitFlag::None); - buffer->setUsed(false); - m_transient.visible = true; - } - } - if (key == KEY_K && state == Keyboard::KeyState::Released) { - delete m_shellSurface; - m_shellSurface = nullptr; - delete m_surface; - m_surface = nullptr; - m_connectionThreadObject->flush(); - } - } - ); - } - ); - connect(s, &Seat::hasPointerChanged, this, - [this, s](bool has) { - if (!has) { - return; - } - Pointer *p = s->createPointer(this); - connect(p, &Pointer::buttonStateChanged, this, - [this](quint32 serial, quint32 time, quint32 button, Pointer::ButtonState state) { - Q_UNUSED(serial) - Q_UNUSED(time) - if (state == Pointer::ButtonState::Released) { - if (button == BTN_LEFT) { - if (m_timer->isActive()) { - m_timer->stop(); - } else { - m_timer->start(); - } - } - if (button == BTN_RIGHT) { - QCoreApplication::instance()->quit(); - } - if (button == BTN_MIDDLE) { - if (m_shellSurface) { - static bool s_maximized = false; - s_maximized = !s_maximized; - if (s_maximized) { - m_shellSurface->setMaximized(); - } else { - m_shellSurface->setToplevel(); - } - } - } - } - } - ); - } - ); - } - ); - registry->create(m_connectionThreadObject->display()); - registry->setEventQueue(m_eventQueue); - registry->setup(); -} - -void WaylandClientTest::render(const QSize &size) -{ - m_currentSize = size; - render(); -} - -void WaylandClientTest::render() -{ - if (!m_shm || !m_surface || !m_surface->isValid() || !m_currentSize.isValid()) { - return; - } - auto buffer = m_shm->getBuffer(m_currentSize, m_currentSize.width() * 4).toStrongRef(); - buffer->setUsed(true); - QImage image(buffer->address(), m_currentSize.width(), m_currentSize.height(), QImage::Format_ARGB32_Premultiplied); - image.fill(s_colors[s_colorIndex]); - - QPainter p; - p.begin(&image); - QImage icon(QStringLiteral(SOURCE_DIR) + QStringLiteral("/48-apps-kwin.png")); - p.drawImage(QPoint(0, 0), icon); - p.end(); - - m_surface->attachBuffer(*buffer); - m_surface->damage(QRect(QPoint(0, 0), m_currentSize)); - m_surface->commit(Surface::CommitFlag::None); - buffer->setUsed(false); -} - -int main(int argc, char **argv) -{ - QCoreApplication app(argc, argv); - - new WaylandClientTest(&app); - - return app.exec(); -} diff --git a/tests/waylandclienttest.h b/tests/waylandclienttest.h deleted file mode 100644 index 652556339..000000000 --- a/tests/waylandclienttest.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2014 Martin Gräßlin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . -*/ -#ifndef WAYLANDCLIENTTEST_H -#define WAYLANDCLIENTTEST_H - -#include -#include - -namespace KWayland -{ -namespace Client -{ -class Compositor; -class ConnectionThread; -class EventQueue; -class Output; -class Registry; -class ShellSurface; -class ShmPool; -class Surface; -} -} - -class QThread; -class QTimer; - -class WaylandClientTest : public QObject -{ - Q_OBJECT -public: - explicit WaylandClientTest(QObject *parent = nullptr); - ~WaylandClientTest() override; - -private: - void init(); - void render(const QSize &size); - void render(); - void setupRegistry(KWayland::Client::Registry *registry); - void toggleTimer(); - QThread *m_connectionThread; - KWayland::Client::ConnectionThread *m_connectionThreadObject; - KWayland::Client::EventQueue *m_eventQueue; - KWayland::Client::Compositor *m_compositor; - KWayland::Client::Output *m_output; - KWayland::Client::Surface *m_surface; - KWayland::Client::ShmPool *m_shm; - KWayland::Client::ShellSurface *m_shellSurface; - QSize m_currentSize; - QTimer *m_timer; - struct { - KWayland::Client::Surface *surface = nullptr; - KWayland::Client::ShellSurface *shellSurface = nullptr; - bool visible = false; - } m_transient; -}; - -#endif