2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-01-29 13:03:05 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2013-01-29 13:03:05 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-01-29 13:03:05 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
// KWin
|
2022-01-13 13:54:03 +00:00
|
|
|
#include "utils/xcbutils.h"
|
2013-01-29 13:03:05 +00:00
|
|
|
// Qt
|
|
|
|
#include <QApplication>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QtTest>
|
2022-03-09 16:25:44 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
#include <private/qtx11extras_p.h>
|
|
|
|
#else
|
2016-11-11 08:59:46 +00:00
|
|
|
#include <QX11Info>
|
2022-03-09 16:25:44 +00:00
|
|
|
#endif
|
2013-01-29 13:03:05 +00:00
|
|
|
// xcb
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
|
|
|
class TestXcbWindow : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-07-22 14:07:39 +00:00
|
|
|
private Q_SLOTS:
|
2015-02-18 07:31:53 +00:00
|
|
|
void initTestCase();
|
2013-01-29 13:03:05 +00:00
|
|
|
void defaultCtor();
|
|
|
|
void ctor();
|
|
|
|
void classCtor();
|
|
|
|
void create();
|
|
|
|
void mapUnmap();
|
|
|
|
void geometry();
|
|
|
|
void destroy();
|
2014-09-24 19:04:15 +00:00
|
|
|
void destroyNotManaged();
|
2013-01-29 13:03:05 +00:00
|
|
|
};
|
|
|
|
|
2015-02-18 07:31:53 +00:00
|
|
|
void TestXcbWindow::initTestCase()
|
|
|
|
{
|
|
|
|
qApp->setProperty("x11RootWindow", QVariant::fromValue<quint32>(QX11Info::appRootWindow()));
|
2022-03-23 10:13:38 +00:00
|
|
|
qApp->setProperty("x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
|
2015-02-18 07:31:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 13:03:05 +00:00
|
|
|
void TestXcbWindow::defaultCtor()
|
|
|
|
{
|
|
|
|
Xcb::Window window;
|
|
|
|
QCOMPARE(window.isValid(), false);
|
|
|
|
xcb_window_t wId = window;
|
|
|
|
QCOMPARE(wId, noneWindow());
|
|
|
|
|
|
|
|
xcb_window_t nativeWindow = createWindow();
|
|
|
|
Xcb::Window window2(nativeWindow);
|
|
|
|
QCOMPARE(window2.isValid(), true);
|
|
|
|
wId = window2;
|
|
|
|
QCOMPARE(wId, nativeWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::ctor()
|
|
|
|
{
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
Xcb::Window window(geometry, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
QCOMPARE(window.isValid(), true);
|
|
|
|
QVERIFY(window != XCB_WINDOW_NONE);
|
|
|
|
Xcb::WindowGeometry windowGeometry(window);
|
|
|
|
QCOMPARE(windowGeometry.isNull(), false);
|
|
|
|
QCOMPARE(windowGeometry.rect(), geometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::classCtor()
|
|
|
|
{
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
Xcb::Window window(geometry, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
QCOMPARE(window.isValid(), true);
|
|
|
|
QVERIFY(window != XCB_WINDOW_NONE);
|
|
|
|
Xcb::WindowGeometry windowGeometry(window);
|
|
|
|
QCOMPARE(windowGeometry.isNull(), false);
|
|
|
|
QCOMPARE(windowGeometry.rect(), geometry);
|
|
|
|
|
|
|
|
Xcb::WindowAttributes attribs(window);
|
|
|
|
QCOMPARE(attribs.isNull(), false);
|
|
|
|
QVERIFY(attribs->_class == XCB_WINDOW_CLASS_INPUT_ONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::create()
|
|
|
|
{
|
|
|
|
Xcb::Window window;
|
|
|
|
QCOMPARE(window.isValid(), false);
|
|
|
|
xcb_window_t wId = window;
|
|
|
|
QCOMPARE(wId, noneWindow());
|
|
|
|
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
window.create(geometry, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
QCOMPARE(window.isValid(), true);
|
|
|
|
QVERIFY(window != XCB_WINDOW_NONE);
|
2014-09-24 19:04:15 +00:00
|
|
|
// and reset again
|
|
|
|
window.reset();
|
|
|
|
QCOMPARE(window.isValid(), false);
|
|
|
|
QVERIFY(window == XCB_WINDOW_NONE);
|
2013-01-29 13:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::mapUnmap()
|
|
|
|
{
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
Xcb::Window window(geometry, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
Xcb::WindowAttributes attribs(window);
|
|
|
|
QCOMPARE(attribs.isNull(), false);
|
|
|
|
QVERIFY(attribs->map_state == XCB_MAP_STATE_UNMAPPED);
|
|
|
|
|
|
|
|
window.map();
|
|
|
|
Xcb::WindowAttributes attribs2(window);
|
|
|
|
QCOMPARE(attribs2.isNull(), false);
|
|
|
|
QVERIFY(attribs2->map_state != XCB_MAP_STATE_UNMAPPED);
|
|
|
|
|
|
|
|
window.unmap();
|
|
|
|
Xcb::WindowAttributes attribs3(window);
|
|
|
|
QCOMPARE(attribs3.isNull(), false);
|
|
|
|
QVERIFY(attribs3->map_state == XCB_MAP_STATE_UNMAPPED);
|
2014-09-24 19:04:15 +00:00
|
|
|
|
|
|
|
// map, unmap shouldn't fail for an invalid window, it's just ignored
|
|
|
|
window.reset();
|
|
|
|
window.map();
|
|
|
|
window.unmap();
|
2013-01-29 13:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::geometry()
|
|
|
|
{
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
Xcb::Window window(geometry, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
Xcb::WindowGeometry windowGeometry(window);
|
|
|
|
QCOMPARE(windowGeometry.isNull(), false);
|
|
|
|
QCOMPARE(windowGeometry.rect(), geometry);
|
|
|
|
|
|
|
|
const QRect geometry2(10, 20, 100, 200);
|
|
|
|
window.setGeometry(geometry2);
|
|
|
|
Xcb::WindowGeometry windowGeometry2(window);
|
|
|
|
QCOMPARE(windowGeometry2.isNull(), false);
|
|
|
|
QCOMPARE(windowGeometry2.rect(), geometry2);
|
2014-09-24 19:04:15 +00:00
|
|
|
|
|
|
|
// setting a geometry on an invalid window should be ignored
|
|
|
|
window.reset();
|
|
|
|
window.setGeometry(geometry2);
|
|
|
|
Xcb::WindowGeometry windowGeometry3(window);
|
|
|
|
QCOMPARE(windowGeometry3.isNull(), true);
|
2013-01-29 13:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestXcbWindow::destroy()
|
|
|
|
{
|
|
|
|
const QRect geometry(0, 0, 10, 10);
|
|
|
|
const uint32_t values[] = {true};
|
|
|
|
Xcb::Window window(geometry, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
QCOMPARE(window.isValid(), true);
|
|
|
|
xcb_window_t wId = window;
|
|
|
|
|
|
|
|
window.create(geometry, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
// wId should now be invalid
|
2014-01-08 10:13:08 +00:00
|
|
|
xcb_generic_error_t *error = nullptr;
|
2013-01-29 13:03:05 +00:00
|
|
|
ScopedCPointer<xcb_get_window_attributes_reply_t> attribs(xcb_get_window_attributes_reply(
|
|
|
|
connection(),
|
|
|
|
xcb_get_window_attributes(connection(), wId),
|
|
|
|
&error));
|
|
|
|
QVERIFY(attribs.isNull());
|
|
|
|
QCOMPARE(error->error_code, uint8_t(3));
|
|
|
|
QCOMPARE(error->resource_id, wId);
|
|
|
|
free(error);
|
|
|
|
|
|
|
|
// test the same for the dtor
|
|
|
|
{
|
|
|
|
Xcb::Window scopedWindow(geometry, XCB_CW_OVERRIDE_REDIRECT, values);
|
|
|
|
QVERIFY(scopedWindow.isValid());
|
|
|
|
wId = scopedWindow;
|
|
|
|
}
|
2014-01-08 10:13:08 +00:00
|
|
|
error = nullptr;
|
2013-01-29 13:03:05 +00:00
|
|
|
ScopedCPointer<xcb_get_window_attributes_reply_t> attribs2(xcb_get_window_attributes_reply(
|
|
|
|
connection(),
|
|
|
|
xcb_get_window_attributes(connection(), wId),
|
|
|
|
&error));
|
|
|
|
QVERIFY(attribs2.isNull());
|
|
|
|
QCOMPARE(error->error_code, uint8_t(3));
|
|
|
|
QCOMPARE(error->resource_id, wId);
|
|
|
|
free(error);
|
|
|
|
}
|
|
|
|
|
2014-09-24 19:04:15 +00:00
|
|
|
void TestXcbWindow::destroyNotManaged()
|
|
|
|
{
|
|
|
|
Xcb::Window window;
|
|
|
|
// just destroy the non-existing window
|
|
|
|
window.reset();
|
|
|
|
|
|
|
|
// now let's add a window
|
|
|
|
window.reset(createWindow(), false);
|
|
|
|
xcb_window_t w = window;
|
|
|
|
window.reset();
|
|
|
|
Xcb::WindowAttributes attribs(w);
|
|
|
|
QVERIFY(attribs);
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:08:45 +00:00
|
|
|
Q_CONSTRUCTOR_FUNCTION(forceXcb)
|
2016-09-08 13:15:41 +00:00
|
|
|
QTEST_MAIN(TestXcbWindow)
|
2013-01-29 13:03:05 +00:00
|
|
|
#include "test_xcb_window.moc"
|