File indexing completed on 2024-11-10 04:55:58

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2022 David Edmundson <davidedmundson@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #include "kwin_wayland_test.h"
0010 
0011 #include "core/output.h"
0012 #include "pointer_input.h"
0013 #include "wayland/clientconnection.h"
0014 #include "wayland/display.h"
0015 #include "wayland_server.h"
0016 #include "window.h"
0017 #include "workspace.h"
0018 
0019 #include <KWayland/Client/compositor.h>
0020 #include <KWayland/Client/connection_thread.h>
0021 #include <KWayland/Client/output.h>
0022 #include <KWayland/Client/surface.h>
0023 
0024 #include <QDBusConnection>
0025 
0026 // system
0027 #include <sys/socket.h>
0028 #include <sys/types.h>
0029 #include <unistd.h>
0030 
0031 #include <csignal>
0032 
0033 using namespace KWin;
0034 
0035 static const QString s_socketName = QStringLiteral("wayland_test_kwin_fractionalScale-0");
0036 
0037 class TestFractionalScale : public QObject
0038 {
0039     Q_OBJECT
0040 private Q_SLOTS:
0041     void initTestCase();
0042     void init();
0043     void cleanup();
0044 
0045     void testShow();
0046 };
0047 
0048 void TestFractionalScale::initTestCase()
0049 {
0050     qRegisterMetaType<KWin::Window *>();
0051     qRegisterMetaType<KWayland::Client::Output *>();
0052 
0053     QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
0054     QVERIFY(waylandServer()->init(s_socketName));
0055     Test::setOutputConfig({
0056         Test::OutputInfo{
0057             .geometry = QRect(0, 0, 1280 / 1.25, 1024 / 1.25),
0058             .scale = 1.25,
0059         },
0060         Test::OutputInfo{
0061             .geometry = QRect(1280, 0, 1280 / 2, 1024 / 2),
0062             .scale = 2.0,
0063         },
0064     });
0065 
0066     kwinApp()->start();
0067     QVERIFY(applicationStartedSpy.wait());
0068     const auto outputs = workspace()->outputs();
0069     QCOMPARE(outputs.count(), 2);
0070     QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1024, 819));
0071     QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 640, 512));
0072     QCOMPARE(outputs[0]->scale(), 1.25);
0073     QCOMPARE(outputs[1]->scale(), 2.0);
0074 }
0075 
0076 void TestFractionalScale::init()
0077 {
0078     QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::FractionalScaleManagerV1));
0079 
0080     workspace()->setActiveOutput(QPoint(640, 512));
0081     // put mouse in the middle of screen one
0082     KWin::input()->pointer()->warp(QPoint(640, 512));
0083 }
0084 
0085 void TestFractionalScale::cleanup()
0086 {
0087     Test::destroyWaylandConnection();
0088 }
0089 
0090 void TestFractionalScale::testShow()
0091 {
0092     std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
0093     std::unique_ptr<Test::FractionalScaleV1> fractionalScale(Test::createFractionalScaleV1(surface.get()));
0094     std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
0095 
0096     // above call commits the surface and blocks for the configure event. We should have received the scale already
0097     // We are sent the value in 120ths
0098     QCOMPARE(fractionalScale->preferredScale(), 1.25 * 120);
0099 
0100     auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
0101     QVERIFY(window);
0102 
0103     QCOMPARE(fractionalScale->preferredScale(), 1.25 * 120);
0104 }
0105 
0106 WAYLANDTEST_MAIN(TestFractionalScale)
0107 #include "fractional_scaling_test.moc"