2020-08-02 22:22:19 +00:00
|
|
|
|
/*
|
|
|
|
|
KWin - the KDE window manager
|
|
|
|
|
This file is part of the KDE project.
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
2016-10-31 14:50:14 +00:00
|
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
|
2018-01-06 09:45:44 +00:00
|
|
|
|
#include "atoms.h"
|
2016-10-31 14:50:14 +00:00
|
|
|
|
#include "composite.h"
|
|
|
|
|
#include "cursor.h"
|
2018-11-18 19:13:55 +00:00
|
|
|
|
#include "deleted.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
#include "effectloader.h"
|
|
|
|
|
#include "effects.h"
|
2016-10-31 14:50:14 +00:00
|
|
|
|
#include "platform.h"
|
|
|
|
|
#include "wayland_server.h"
|
|
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
|
#include "x11window.h"
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2017-07-23 09:50:58 +00:00
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
|
2016-10-31 14:50:14 +00:00
|
|
|
|
#include <netwm.h>
|
|
|
|
|
#include <xcb/xcb_icccm.h>
|
|
|
|
|
|
|
|
|
|
using namespace KWin;
|
2017-07-23 09:50:58 +00:00
|
|
|
|
using namespace KWayland::Client;
|
2022-04-22 17:54:31 +00:00
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_x11_window-0");
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
class X11WindowTest : public QObject
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
|
Q_OBJECT
|
2016-10-31 14:50:14 +00:00
|
|
|
|
private Q_SLOTS:
|
2022-05-16 20:13:39 +00:00
|
|
|
|
void initTestCase_data();
|
2016-10-31 14:50:14 +00:00
|
|
|
|
void initTestCase();
|
|
|
|
|
void init();
|
|
|
|
|
void cleanup();
|
|
|
|
|
|
2020-02-14 11:59:58 +00:00
|
|
|
|
void testMinimumSize();
|
|
|
|
|
void testMaximumSize();
|
|
|
|
|
void testResizeIncrements();
|
|
|
|
|
void testResizeIncrementsNoBaseSize();
|
Fix captions with non-BMP characters
KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.
This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.
Unit tests adapted by Vlad Zagorodniy.
Test Plan:
kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
BUG: 376813
FIXED-IN: 5.15.5
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, grasslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19052
2019-04-26 08:52:57 +00:00
|
|
|
|
void testTrimCaption_data();
|
|
|
|
|
void testTrimCaption();
|
2017-07-23 09:50:58 +00:00
|
|
|
|
void testFullscreenLayerWithActiveWaylandWindow();
|
2017-07-23 14:18:09 +00:00
|
|
|
|
void testFocusInWithWaylandLastActiveWindow();
|
2017-07-26 05:08:27 +00:00
|
|
|
|
void testX11WindowId();
|
2017-08-13 14:52:14 +00:00
|
|
|
|
void testCaptionChanges();
|
2017-08-01 19:28:36 +00:00
|
|
|
|
void testCaptionWmName();
|
2017-09-18 16:37:45 +00:00
|
|
|
|
void testCaptionMultipleWindows();
|
2018-01-06 09:45:44 +00:00
|
|
|
|
void testFullscreenWindowGroups();
|
2020-06-16 08:03:25 +00:00
|
|
|
|
void testActivateFocusedWindow();
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
|
void testReentrantMoveResize();
|
2016-10-31 14:50:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
|
void X11WindowTest::initTestCase_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<qreal>("scale");
|
|
|
|
|
QTest::newRow("normal") << 1.0;
|
|
|
|
|
QTest::newRow("scaled2x") << 2.0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::initTestCase()
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
2022-03-23 10:13:38 +00:00
|
|
|
|
qRegisterMetaType<KWin::Deleted *>();
|
2022-04-22 17:39:12 +00:00
|
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-10-31 14:50:14 +00:00
|
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2017-07-23 14:18:09 +00:00
|
|
|
|
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2017-07-23 09:50:58 +00:00
|
|
|
|
QVERIFY(KWin::Compositor::self());
|
2016-10-31 14:50:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::init()
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
2017-07-23 09:50:58 +00:00
|
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2016-10-31 14:50:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::cleanup()
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
2017-07-23 09:50:58 +00:00
|
|
|
|
Test::destroyWaylandConnection();
|
2016-10-31 14:50:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct XcbConnectionDeleter
|
|
|
|
|
{
|
2022-08-01 21:29:02 +00:00
|
|
|
|
void operator()(xcb_connection_t *pointer)
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testMinimumSize()
|
2020-02-14 11:59:58 +00:00
|
|
|
|
{
|
|
|
|
|
// This test verifies that the minimum size constraint is correctly applied.
|
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2020-02-14 11:59:58 +00:00
|
|
|
|
// Create an xcb window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-02-14 11:59:58 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_min_size(&hints, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized);
|
|
|
|
|
QSignalSpy clientStepUserMovedResizedSpy(window, &Window::clientStepUserMovedResized);
|
|
|
|
|
QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized);
|
|
|
|
|
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Begin resize.
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
workspace()->slotWindowResize();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), window);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStartMoveResizedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
|
const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos();
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Left);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 0);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Right);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 0);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Right);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
// whilst X11 window size goes through scale, the increment is a logical value kwin side
|
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale + 8);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Up);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, -8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Down);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Down);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 2);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale + 8);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Finish the resize operation.
|
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 0);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Enter);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 1);
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the window.
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testMaximumSize()
|
2020-02-14 11:59:58 +00:00
|
|
|
|
{
|
|
|
|
|
// This test verifies that the maximum size constraint is correctly applied.
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Create an xcb window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-02-14 11:59:58 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_max_size(&hints, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized);
|
|
|
|
|
QSignalSpy clientStepUserMovedResizedSpy(window, &Window::clientStepUserMovedResized);
|
|
|
|
|
QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized);
|
|
|
|
|
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Begin resize.
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
workspace()->slotWindowResize();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), window);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStartMoveResizedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
|
const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos();
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Right);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 0);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Left);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(!clientStepUserMovedResizedSpy.wait(1000));
|
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 0);
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Left);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().width(), 100 / scale - 8);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Down);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Up);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(!frameGeometryChangedSpy.wait(1000));
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Up);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, -8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 2);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize().height(), 200 / scale - 8);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Finish the resize operation.
|
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 0);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Enter);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 1);
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the window.
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testResizeIncrements()
|
2020-02-14 11:59:58 +00:00
|
|
|
|
{
|
|
|
|
|
// This test verifies that the resize increments constraint is correctly applied.
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Create an xcb window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-02-14 11:59:58 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_base_size(&hints, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_resize_inc(&hints, 3, 5);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized);
|
|
|
|
|
QSignalSpy clientStepUserMovedResizedSpy(window, &Window::clientStepUserMovedResized);
|
|
|
|
|
QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized);
|
|
|
|
|
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Begin resize.
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
workspace()->slotWindowResize();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), window);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStartMoveResizedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
|
const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos();
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Right);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
|
|
|
|
|
// 100 + 8 logical pixels, rounded to resize increments. This will differ on scale
|
|
|
|
|
const qreal horizontalResizeInc = 3 / scale;
|
|
|
|
|
const qreal verticalResizeInc = 5 / scale;
|
|
|
|
|
const qreal expectedHorizontalResizeInc = std::floor(8. / horizontalResizeInc) * horizontalResizeInc;
|
|
|
|
|
const qreal expectedVerticalResizeInc = std::floor(8. / verticalResizeInc) * verticalResizeInc;
|
|
|
|
|
|
|
|
|
|
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Down);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 2);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize(), QSize(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, expectedVerticalResizeInc));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Finish the resize operation.
|
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 0);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Enter);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 1);
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the window.
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testResizeIncrementsNoBaseSize()
|
2020-02-14 11:59:58 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2020-02-14 11:59:58 +00:00
|
|
|
|
// Create an xcb window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-02-14 11:59:58 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_min_size(&hints, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
xcb_icccm_size_hints_set_resize_inc(&hints, 3, 5);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QVERIFY(window->isDecorated());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized);
|
|
|
|
|
QSignalSpy clientStepUserMovedResizedSpy(window, &Window::clientStepUserMovedResized);
|
|
|
|
|
QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized);
|
|
|
|
|
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Begin resize.
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
workspace()->slotWindowResize();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), window);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStartMoveResizedSpy.count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2020-04-02 16:18:01 +00:00
|
|
|
|
const QPoint cursorPos = KWin::Cursors::self()->mouse()->pos();
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Right);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 1);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
|
|
|
|
|
// 100 + 8 pixels, rounded to resize increments. This will differ on scale
|
|
|
|
|
const qreal horizontalResizeInc = 3 / scale;
|
|
|
|
|
const qreal verticalResizeInc = 5 / scale;
|
|
|
|
|
const qreal expectedHorizontalResizeInc = std::floor(8. / horizontalResizeInc) * horizontalResizeInc;
|
|
|
|
|
const qreal expectedVerticalResizeInc = std::floor(8. / verticalResizeInc) * verticalResizeInc;
|
|
|
|
|
|
|
|
|
|
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, 0));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Down);
|
|
|
|
|
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
|
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientStepUserMovedResizedSpy.count(), 2);
|
2021-12-24 09:20:00 +00:00
|
|
|
|
QVERIFY(frameGeometryChangedSpy.wait());
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, expectedVerticalResizeInc));
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Finish the resize operation.
|
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 0);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->keyPressEvent(Qt::Key_Enter);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QCOMPARE(clientFinishUserMovedResizedSpy.count(), 1);
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isInteractiveResize());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the window.
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-02-14 11:59:58 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testTrimCaption_data()
|
Fix captions with non-BMP characters
KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.
This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.
Unit tests adapted by Vlad Zagorodniy.
Test Plan:
kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
BUG: 376813
FIXED-IN: 5.15.5
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, grasslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19052
2019-04-26 08:52:57 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
Fix captions with non-BMP characters
KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.
This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.
Unit tests adapted by Vlad Zagorodniy.
Test Plan:
kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
BUG: 376813
FIXED-IN: 5.15.5
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, grasslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19052
2019-04-26 08:52:57 +00:00
|
|
|
|
QTest::addColumn<QByteArray>("originalTitle");
|
|
|
|
|
QTest::addColumn<QByteArray>("expectedTitle");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("simplified")
|
|
|
|
|
<< QByteArrayLiteral("Was tun, wenn Schüler Autismus haben?\342\200\250\342\200\250\342\200\250 – Marlies Hübner - Mozilla Firefox")
|
|
|
|
|
<< QByteArrayLiteral("Was tun, wenn Schüler Autismus haben? – Marlies Hübner - Mozilla Firefox");
|
|
|
|
|
|
|
|
|
|
QTest::newRow("with emojis")
|
|
|
|
|
<< QByteArrayLiteral("\bTesting non\302\255printable:\177, emoij:\360\237\230\203, non-characters:\357\277\276")
|
|
|
|
|
<< QByteArrayLiteral("Testing nonprintable:, emoij:\360\237\230\203, non-characters:");
|
|
|
|
|
}
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testTrimCaption()
|
2016-10-31 14:50:14 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2016-10-31 14:50:14 +00:00
|
|
|
|
// this test verifies that caption is properly trimmed
|
|
|
|
|
|
|
|
|
|
// create an xcb window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2016-10-31 14:50:14 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2016-10-31 14:50:14 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
NETWinInfo winInfo(c.get(), windowId, rootWindow(), NET::Properties(), NET::Properties2());
|
Fix captions with non-BMP characters
KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.
This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.
Unit tests adapted by Vlad Zagorodniy.
Test Plan:
kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
BUG: 376813
FIXED-IN: 5.15.5
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, grasslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19052
2019-04-26 08:52:57 +00:00
|
|
|
|
QFETCH(QByteArray, originalTitle);
|
|
|
|
|
winInfo.setName(originalTitle);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2016-10-31 14:50:14 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
Fix captions with non-BMP characters
KWin replaces any non-printable character with a space. This check does not
handle surrogate pairs correctly. Additionally, translators sometimes insert
non-printable soft-hyphens into titles, which also cause KWin to display a
space instead.
This code adds the missing surrogate handling, and (to fix both issues), also
removes non-printable characters instead of replacing them with a space.
Also moved the changed test after these changes, so that changes in non-
printable characters do not cause unneeded redraws.
Unit tests adapted by Vlad Zagorodniy.
Test Plan:
kwrite /tmp/Test😣.txt shows correct title. I also tested actual non-printable
characters, such as 0x1A, and these are correctly omitted.
BUG: 376813
FIXED-IN: 5.15.5
Reviewers: #kwin, zzag
Reviewed By: #kwin, zzag
Subscribers: zzag, grasslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19052
2019-04-26 08:52:57 +00:00
|
|
|
|
QFETCH(QByteArray, expectedTitle);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(window->caption(), QString::fromUtf8(expectedTitle));
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2016-10-31 14:50:14 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2016-10-31 14:50:14 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
2016-10-31 14:50:14 +00:00
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testFullscreenLayerWithActiveWaylandWindow()
|
2017-07-23 09:50:58 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2017-07-23 09:50:58 +00:00
|
|
|
|
// this test verifies that an X11 fullscreen window does not stay in the active layer
|
|
|
|
|
// when a Wayland window is active, see BUG: 375759
|
2022-07-11 10:41:15 +00:00
|
|
|
|
QCOMPARE(workspace()->outputs().count(), 1);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
// first create an X11 window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-07-23 09:50:58 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-07-23 09:50:58 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QVERIFY(!window->isFullScreen());
|
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
|
QCOMPARE(window->layer(), NormalLayer);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
workspace()->slotWindowFullScreen();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isFullScreen());
|
|
|
|
|
QCOMPARE(window->layer(), ActiveLayer);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
// now let's open a Wayland window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
|
auto waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(waylandWindow);
|
|
|
|
|
QVERIFY(waylandWindow->isActive());
|
|
|
|
|
QCOMPARE(waylandWindow->layer(), NormalLayer);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(window->layer(), NormalLayer);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
// now activate fullscreen again
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(window);
|
|
|
|
|
QTRY_VERIFY(window->isActive());
|
|
|
|
|
QCOMPARE(window->layer(), ActiveLayer);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
// activate wayland window again
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(waylandWindow);
|
|
|
|
|
QTRY_VERIFY(waylandWindow->isActive());
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
2017-07-23 18:02:57 +00:00
|
|
|
|
// back to x window
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(window);
|
|
|
|
|
QTRY_VERIFY(window->isActive());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
// remove fullscreen
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isFullScreen());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
workspace()->slotWindowFullScreen();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isFullScreen());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
// and fullscreen again
|
|
|
|
|
workspace()->slotWindowFullScreen();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isFullScreen());
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
2017-07-23 18:02:57 +00:00
|
|
|
|
|
|
|
|
|
// activate wayland window again
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(waylandWindow);
|
|
|
|
|
QTRY_VERIFY(waylandWindow->isActive());
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
2017-07-23 18:02:57 +00:00
|
|
|
|
|
|
|
|
|
// back to X11 window
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(window);
|
|
|
|
|
QTRY_VERIFY(window->isActive());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
// remove fullscreen
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(window->isFullScreen());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
workspace()->slotWindowFullScreen();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!window->isFullScreen());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
// and fullscreen through X API
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETWinInfo info(c.get(), windowId, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
|
2017-07-23 18:02:57 +00:00
|
|
|
|
info.setState(NET::FullScreen, NET::FullScreen);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETRootInfo rootInfo(c.get(), NET::Properties());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
rootInfo.setActiveWindow(windowId, NET::FromApplication, XCB_CURRENT_TIME, XCB_WINDOW_NONE);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_flush(c.get());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QTRY_VERIFY(window->isFullScreen());
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), window);
|
2017-07-23 18:02:57 +00:00
|
|
|
|
|
|
|
|
|
// activate wayland window again
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(waylandWindow);
|
|
|
|
|
QTRY_VERIFY(waylandWindow->isActive());
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
|
|
|
|
|
QCOMPARE(window->layer(), NormalLayer);
|
2017-07-23 18:02:57 +00:00
|
|
|
|
|
2017-07-23 09:50:58 +00:00
|
|
|
|
// close the window
|
|
|
|
|
shellSurface.reset();
|
|
|
|
|
surface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(waylandWindow));
|
|
|
|
|
QTRY_VERIFY(window->isActive());
|
|
|
|
|
QCOMPARE(window->layer(), ActiveLayer);
|
2017-07-23 09:50:58 +00:00
|
|
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-07-23 09:50:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testFocusInWithWaylandLastActiveWindow()
|
2017-07-23 14:18:09 +00:00
|
|
|
|
{
|
2022-04-23 08:33:23 +00:00
|
|
|
|
// this test verifies that Workspace::allowWindowActivation does not crash if last client was a Wayland client
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
2017-07-23 14:18:09 +00:00
|
|
|
|
|
|
|
|
|
// create an X11 window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-07-23 14:18:09 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-07-23 14:18:09 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-07-23 14:18:09 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QVERIFY(window->isActive());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
|
|
|
|
|
// create Wayland window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
|
auto waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(waylandWindow);
|
|
|
|
|
QVERIFY(waylandWindow->isActive());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
// activate no window
|
2022-04-23 08:33:23 +00:00
|
|
|
|
workspace()->setActiveWindow(nullptr);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(!waylandWindow->isActive());
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QVERIFY(!workspace()->activeWindow());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
// and close Wayland window again
|
|
|
|
|
shellSurface.reset();
|
|
|
|
|
surface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(waylandWindow));
|
2017-07-23 14:18:09 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// and try to activate the x11 window through X11 api
|
2022-08-01 21:29:02 +00:00
|
|
|
|
const auto cookie = xcb_set_input_focus_checked(c.get(), XCB_INPUT_FOCUS_NONE, windowId, XCB_CURRENT_TIME);
|
|
|
|
|
auto error = xcb_request_check(c.get(), cookie);
|
2017-07-23 14:18:09 +00:00
|
|
|
|
QVERIFY(!error);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// this accesses m_lastActiveWindow on trying to activate
|
|
|
|
|
QTRY_VERIFY(window->isActive());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-07-23 14:18:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testX11WindowId()
|
2017-07-26 05:08:27 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2017-07-26 05:08:27 +00:00
|
|
|
|
// create an X11 window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-07-26 05:08:27 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-07-26 05:08:27 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-07-26 05:08:27 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-07-26 05:08:27 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QVERIFY(window->isActive());
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QCOMPARE(window->internalId().isNull(), false);
|
|
|
|
|
const auto uuid = window->internalId();
|
2018-11-18 19:13:55 +00:00
|
|
|
|
QUuid deletedUuid;
|
|
|
|
|
QCOMPARE(deletedUuid.isNull(), true);
|
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
connect(window, &X11Window::windowClosed, this, [&deletedUuid](Window *, Deleted *d) {
|
2022-03-23 10:13:38 +00:00
|
|
|
|
deletedUuid = d->internalId();
|
|
|
|
|
});
|
2017-07-26 05:08:27 +00:00
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETRootInfo rootInfo(c.get(), NET::WMAllProperties);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(rootInfo.activeWindow(), window->window());
|
2017-07-26 05:08:27 +00:00
|
|
|
|
|
|
|
|
|
// activate a wayland window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
|
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
|
|
|
|
|
auto waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(waylandWindow);
|
|
|
|
|
QVERIFY(waylandWindow->isActive());
|
2017-07-26 05:08:27 +00:00
|
|
|
|
xcb_flush(kwinApp()->x11Connection());
|
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETRootInfo rootInfo2(c.get(), NET::WMAllProperties);
|
2017-07-26 05:08:27 +00:00
|
|
|
|
QCOMPARE(rootInfo2.activeWindow(), 0u);
|
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// back to X11 window
|
2017-07-26 05:08:27 +00:00
|
|
|
|
shellSurface.reset();
|
|
|
|
|
surface.reset();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(waylandWindow));
|
2017-07-26 05:08:27 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QTRY_VERIFY(window->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETRootInfo rootInfo3(c.get(), NET::WMAllProperties);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(rootInfo3.activeWindow(), window->window());
|
2017-07-26 05:08:27 +00:00
|
|
|
|
|
|
|
|
|
// and destroy the window again
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2018-11-18 19:13:55 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
|
|
|
|
|
|
QCOMPARE(deletedUuid.isNull(), false);
|
|
|
|
|
QCOMPARE(deletedUuid, uuid);
|
2017-07-26 05:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testCaptionChanges()
|
2017-08-13 14:52:14 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2017-08-13 14:52:14 +00:00
|
|
|
|
// verifies that caption is updated correctly when the X11 window updates it
|
|
|
|
|
// BUG: 383444
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-08-13 14:52:14 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-08-13 14:52:14 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
NETWinInfo info(c.get(), windowId, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
|
2017-08-13 14:52:14 +00:00
|
|
|
|
info.setName("foo");
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-08-13 14:52:14 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// we should get a window for it
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-08-13 14:52:14 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QCOMPARE(window->caption(), QStringLiteral("foo"));
|
2017-08-13 14:52:14 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy captionChangedSpy(window, &X11Window::captionChanged);
|
2017-08-13 14:52:14 +00:00
|
|
|
|
QVERIFY(captionChangedSpy.isValid());
|
|
|
|
|
info.setName("bar");
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_flush(c.get());
|
2017-08-13 14:52:14 +00:00
|
|
|
|
QVERIFY(captionChangedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(window->caption(), QStringLiteral("bar"));
|
2017-08-13 14:52:14 +00:00
|
|
|
|
|
|
|
|
|
// and destroy the window again
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy windowClosedSpy(window, &X11Window::windowClosed);
|
2017-08-13 14:52:14 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_unmap_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-08-13 14:52:14 +00:00
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
2017-08-13 14:52:14 +00:00
|
|
|
|
c.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testCaptionWmName()
|
2017-08-01 19:28:36 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2017-08-01 19:28:36 +00:00
|
|
|
|
// this test verifies that a caption set through WM_NAME is read correctly
|
|
|
|
|
|
|
|
|
|
// open glxgears as that one only uses WM_NAME
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
|
|
|
|
|
QVERIFY(windowAddedSpy.isValid());
|
2017-08-01 19:28:36 +00:00
|
|
|
|
|
|
|
|
|
QProcess glxgears;
|
2020-09-10 07:15:31 +00:00
|
|
|
|
glxgears.setProgram(QStringLiteral("glxgears"));
|
|
|
|
|
glxgears.start();
|
2017-08-01 19:28:36 +00:00
|
|
|
|
QVERIFY(glxgears.waitForStarted());
|
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QVERIFY(windowAddedSpy.wait());
|
|
|
|
|
QCOMPARE(windowAddedSpy.count(), 1);
|
2017-08-01 19:28:36 +00:00
|
|
|
|
QCOMPARE(workspace()->clientList().count(), 1);
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *glxgearsWindow = workspace()->clientList().first();
|
|
|
|
|
QCOMPARE(glxgearsWindow->caption(), QStringLiteral("glxgears"));
|
2017-08-01 19:28:36 +00:00
|
|
|
|
|
|
|
|
|
glxgears.terminate();
|
|
|
|
|
QVERIFY(glxgears.waitForFinished());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testCaptionMultipleWindows()
|
2017-09-18 16:37:45 +00:00
|
|
|
|
{
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2017-09-18 16:37:45 +00:00
|
|
|
|
// BUG 384760
|
|
|
|
|
// create first window
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2017-09-18 16:37:45 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2017-09-18 16:37:45 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
NETWinInfo info(c.get(), windowId, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
info.setName("foo");
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2017-09-18 16:37:45 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QCOMPARE(window->caption(), QStringLiteral("foo"));
|
2017-09-18 16:37:45 +00:00
|
|
|
|
|
|
|
|
|
// create second window with same caption
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t w2 = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, w2, rootWindow(),
|
2017-09-18 16:37:45 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), w2, &hints);
|
|
|
|
|
NETWinInfo info2(c.get(), w2, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
info2.setName("foo");
|
|
|
|
|
info2.setIconName("foo");
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(c.get(), w2);
|
|
|
|
|
xcb_flush(c.get());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
|
|
|
|
|
windowCreatedSpy.clear();
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window2 = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window2);
|
|
|
|
|
QCOMPARE(window2->window(), w2);
|
|
|
|
|
QCOMPARE(window2->caption(), QStringLiteral("foo <2>\u200E"));
|
2017-09-18 16:37:45 +00:00
|
|
|
|
NETWinInfo info3(kwinApp()->x11Connection(), w2, kwinApp()->x11RootWindow(), NET::WMVisibleName | NET::WMVisibleIconName, NET::Properties2());
|
|
|
|
|
QCOMPARE(QByteArray(info3.visibleName()), QByteArrayLiteral("foo <2>\u200E"));
|
|
|
|
|
QCOMPARE(QByteArray(info3.visibleIconName()), QByteArrayLiteral("foo <2>\u200E"));
|
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QSignalSpy captionChangedSpy(window2, &X11Window::captionChanged);
|
2017-09-18 16:37:45 +00:00
|
|
|
|
QVERIFY(captionChangedSpy.isValid());
|
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
|
NETWinInfo info4(c.get(), w2, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
info4.setName("foobar");
|
|
|
|
|
info4.setIconName("foobar");
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(c.get(), w2);
|
|
|
|
|
xcb_flush(c.get());
|
2017-09-18 16:37:45 +00:00
|
|
|
|
|
|
|
|
|
QVERIFY(captionChangedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(window2->caption(), QStringLiteral("foobar"));
|
2017-09-18 16:37:45 +00:00
|
|
|
|
NETWinInfo info5(kwinApp()->x11Connection(), w2, kwinApp()->x11RootWindow(), NET::WMVisibleName | NET::WMVisibleIconName, NET::Properties2());
|
|
|
|
|
QCOMPARE(QByteArray(info5.visibleName()), QByteArray());
|
|
|
|
|
QTRY_COMPARE(QByteArray(info5.visibleIconName()), QByteArray());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testFullscreenWindowGroups()
|
2018-01-06 09:45:44 +00:00
|
|
|
|
{
|
|
|
|
|
// this test creates an X11 window and puts it to full screen
|
|
|
|
|
// then a second window is created which is in the same window group
|
|
|
|
|
// BUG: 388310
|
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2018-01-06 09:45:44 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2018-01-06 09:45:44 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2018-01-06 09:45:44 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2018-01-06 09:45:44 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->window(), windowId);
|
|
|
|
|
QCOMPARE(window->isActive(), true);
|
2018-01-06 09:45:44 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(window->isFullScreen(), false);
|
|
|
|
|
QCOMPARE(window->layer(), NormalLayer);
|
2018-01-06 09:45:44 +00:00
|
|
|
|
workspace()->slotWindowFullScreen();
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QCOMPARE(window->isFullScreen(), true);
|
|
|
|
|
QCOMPARE(window->layer(), ActiveLayer);
|
2018-01-06 09:45:44 +00:00
|
|
|
|
|
|
|
|
|
// now let's create a second window
|
|
|
|
|
windowCreatedSpy.clear();
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t w2 = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, w2, rootWindow(),
|
2018-01-06 09:45:44 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints2;
|
|
|
|
|
memset(&hints2, 0, sizeof(hints2));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints2, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints2, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), w2, &hints2);
|
|
|
|
|
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, w2, atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId);
|
|
|
|
|
xcb_map_window(c.get(), w2);
|
|
|
|
|
xcb_flush(c.get());
|
2018-01-06 09:45:44 +00:00
|
|
|
|
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window2 = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window2);
|
|
|
|
|
QVERIFY(window != window2);
|
|
|
|
|
QCOMPARE(window2->window(), w2);
|
|
|
|
|
QCOMPARE(window2->isActive(), true);
|
|
|
|
|
QCOMPARE(window2->group(), window->group());
|
|
|
|
|
// first window should be moved back to normal layer
|
|
|
|
|
QCOMPARE(window->isActive(), false);
|
|
|
|
|
QCOMPARE(window->isFullScreen(), true);
|
|
|
|
|
QCOMPARE(window->layer(), NormalLayer);
|
2018-01-06 10:24:31 +00:00
|
|
|
|
|
|
|
|
|
// activating the fullscreen window again, should move it to active layer
|
2022-04-23 19:51:16 +00:00
|
|
|
|
workspace()->activateWindow(window);
|
|
|
|
|
QTRY_COMPARE(window->layer(), ActiveLayer);
|
2018-01-06 09:45:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testActivateFocusedWindow()
|
2020-06-16 08:03:25 +00:00
|
|
|
|
{
|
|
|
|
|
// The window manager may call XSetInputFocus() on a window that already has focus, in which
|
|
|
|
|
// case no FocusIn event will be generated and the window won't be marked as active. This test
|
|
|
|
|
// verifies that we handle that subtle case properly.
|
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> connection(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(connection.get()));
|
2020-06-16 08:03:25 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-06-16 08:03:25 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
|
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
|
|
|
|
|
|
|
|
|
// Create the first test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
const xcb_window_t windowId1 = xcb_generate_id(connection.get());
|
|
|
|
|
xcb_create_window(connection.get(), XCB_COPY_FROM_PARENT, windowId1, rootWindow(),
|
2020-06-16 08:03:25 +00:00
|
|
|
|
windowGeometry.x(), windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(), windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(connection.get(), windowId1, &hints);
|
|
|
|
|
xcb_change_property(connection.get(), XCB_PROP_MODE_REPLACE, windowId1,
|
2022-04-23 19:51:16 +00:00
|
|
|
|
atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId1);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(connection.get(), windowId1);
|
|
|
|
|
xcb_flush(connection.get());
|
2020-06-16 08:03:25 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window1 = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window1);
|
|
|
|
|
QCOMPARE(window1->window(), windowId1);
|
|
|
|
|
QCOMPARE(window1->isActive(), true);
|
2020-06-16 08:03:25 +00:00
|
|
|
|
|
|
|
|
|
// Create the second test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
const xcb_window_t windowId2 = xcb_generate_id(connection.get());
|
|
|
|
|
xcb_create_window(connection.get(), XCB_COPY_FROM_PARENT, windowId2, rootWindow(),
|
2020-06-16 08:03:25 +00:00
|
|
|
|
windowGeometry.x(), windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(), windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(connection.get(), windowId2, &hints);
|
|
|
|
|
xcb_change_property(connection.get(), XCB_PROP_MODE_REPLACE, windowId2,
|
2022-04-23 19:51:16 +00:00
|
|
|
|
atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId2);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_map_window(connection.get(), windowId2);
|
|
|
|
|
xcb_flush(connection.get());
|
2020-06-16 08:03:25 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window2 = windowCreatedSpy.last().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window2);
|
|
|
|
|
QCOMPARE(window2->window(), windowId2);
|
|
|
|
|
QCOMPARE(window2->isActive(), true);
|
2020-06-16 08:03:25 +00:00
|
|
|
|
|
|
|
|
|
// When the second test window is destroyed, the window manager will attempt to activate the
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// next window in the focus chain, which is the first window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_set_input_focus(connection.get(), XCB_INPUT_FOCUS_POINTER_ROOT, windowId1, XCB_CURRENT_TIME);
|
|
|
|
|
xcb_destroy_window(connection.get(), windowId2);
|
|
|
|
|
xcb_flush(connection.get());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window2));
|
|
|
|
|
QVERIFY(window1->isActive());
|
2020-06-16 08:03:25 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the first test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_destroy_window(connection.get(), windowId1);
|
|
|
|
|
xcb_flush(connection.get());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window1));
|
2020-06-16 08:03:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
void X11WindowTest::testReentrantMoveResize()
|
2020-07-20 19:33:19 +00:00
|
|
|
|
{
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
|
// This test verifies that calling moveResize() from a slot connected directly
|
2020-07-20 19:33:19 +00:00
|
|
|
|
// to the frameGeometryChanged() signal won't cause an infinite recursion.
|
|
|
|
|
|
2022-05-16 20:13:39 +00:00
|
|
|
|
QFETCH_GLOBAL(qreal, scale);
|
|
|
|
|
kwinApp()->setXwaylandScale(scale);
|
|
|
|
|
|
2020-07-20 19:33:19 +00:00
|
|
|
|
// Create a test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
std::unique_ptr<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
|
|
|
|
|
QVERIFY(!xcb_connection_has_error(c.get()));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
const QRect windowGeometry(0, 0, 100, 200);
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_window_t windowId = xcb_generate_id(c.get());
|
|
|
|
|
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
|
2020-07-20 19:33:19 +00:00
|
|
|
|
windowGeometry.x(),
|
|
|
|
|
windowGeometry.y(),
|
|
|
|
|
windowGeometry.width(),
|
|
|
|
|
windowGeometry.height(),
|
|
|
|
|
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
|
|
|
|
|
xcb_size_hints_t hints;
|
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
|
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
|
|
|
|
|
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
|
|
|
|
|
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId);
|
|
|
|
|
xcb_map_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2020-07-20 19:33:19 +00:00
|
|
|
|
|
2022-04-23 08:33:23 +00:00
|
|
|
|
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
|
2020-07-20 19:33:19 +00:00
|
|
|
|
QVERIFY(windowCreatedSpy.isValid());
|
|
|
|
|
QVERIFY(windowCreatedSpy.wait());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
|
|
|
|
|
QVERIFY(window);
|
|
|
|
|
QCOMPARE(window->pos(), QPoint(0, 0));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// Let's pretend that there is a script that really wants the window to be at (100, 100).
|
|
|
|
|
connect(window, &Window::frameGeometryChanged, this, [window]() {
|
2022-05-16 20:13:39 +00:00
|
|
|
|
window->moveResize(QRectF(QPointF(100, 100), window->size()));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Trigger the lambda above.
|
2022-04-23 19:51:16 +00:00
|
|
|
|
window->move(QPoint(40, 50));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
|
2022-04-23 19:51:16 +00:00
|
|
|
|
// Eventually, the window will end up at (100, 100).
|
|
|
|
|
QCOMPARE(window->pos(), QPoint(100, 100));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
|
|
|
|
|
// Destroy the test window.
|
2022-08-01 21:29:02 +00:00
|
|
|
|
xcb_destroy_window(c.get(), windowId);
|
|
|
|
|
xcb_flush(c.get());
|
2022-04-23 19:51:16 +00:00
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(window));
|
2020-07-20 19:33:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 17:54:31 +00:00
|
|
|
|
WAYLANDTEST_MAIN(X11WindowTest)
|
|
|
|
|
#include "x11_window_test.moc"
|