File indexing completed on 2025-02-16 05:09:08
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2018 The Qt Company Ltd. 0004 ** Contact: https://www.qt.io/licensing/ 0005 ** 0006 ** This file is part of the test suite of the Qt Toolkit. 0007 ** 0008 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 0009 ** Commercial License Usage 0010 ** Licensees holding valid commercial Qt licenses may use this file in 0011 ** accordance with the commercial license agreement provided with the 0012 ** Software or, alternatively, in accordance with the terms contained in 0013 ** a written agreement between you and The Qt Company. For licensing terms 0014 ** and conditions see https://www.qt.io/terms-conditions. For further 0015 ** information use the contact form at https://www.qt.io/contact-us. 0016 ** 0017 ** GNU General Public License Usage 0018 ** Alternatively, this file may be used under the terms of the GNU 0019 ** General Public License version 3 as published by the Free Software 0020 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 0021 ** included in the packaging of this file. Please review the following 0022 ** information to ensure the GNU General Public License requirements will 0023 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 0024 ** 0025 ** $QT_END_LICENSE$ 0026 ** 0027 ****************************************************************************/ 0028 0029 #include "mockcompositor.h" 0030 0031 namespace MockCompositor 0032 { 0033 DefaultCompositor::DefaultCompositor() 0034 { 0035 { 0036 Lock l(this); 0037 0038 add<WlCompositor>(); 0039 add<XdgOutputManagerV1>(); 0040 auto *output = add<Output>(); 0041 auto *outputOrder = add<OutputOrder>(); 0042 output->m_data.physicalSize = output->m_data.mode.physicalSizeForDpi(96); 0043 add<Seat>(Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch); 0044 add<Shm>(); 0045 add<XdgWmBase>(); 0046 outputOrder->setList({"WL-1"}); 0047 add<LayerShell>(); 0048 0049 QObject::connect(get<WlCompositor>(), &WlCompositor::surfaceCreated, [&](Surface *surface) { 0050 QObject::connect(surface, &Surface::bufferCommitted, [this, surface] { 0051 if (m_config.autoRelease) { 0052 // Pretend we made a copy of the buffer and just release it immediately 0053 surface->m_committed.buffer->send_release(); 0054 } 0055 if (m_config.autoEnter && get<Output>() && surface->m_outputs.empty()) 0056 surface->sendEnter(get<Output>()); 0057 wl_display_flush_clients(m_display); 0058 }); 0059 }); 0060 QObject::connect( 0061 get<XdgWmBase>(), 0062 &XdgWmBase::toplevelCreated, 0063 get<XdgWmBase>(), 0064 [&](XdgToplevel *toplevel) { 0065 if (m_config.autoConfigure) 0066 toplevel->sendCompleteConfigure(); 0067 }, 0068 Qt::DirectConnection); 0069 } 0070 Q_ASSERT(isClean()); 0071 } 0072 0073 uint DefaultCompositor::sendXdgShellPing() 0074 { 0075 warnIfNotLockedByThread(Q_FUNC_INFO); 0076 uint serial = nextSerial(); 0077 auto *base = get<XdgWmBase>(); 0078 const auto resourceMap = base->resourceMap(); 0079 Q_ASSERT(resourceMap.size() == 1); // binding more than once shouldn't be needed 0080 base->send_ping(resourceMap.first()->handle, serial); 0081 return serial; 0082 } 0083 0084 void DefaultCompositor::xdgPingAndWaitForPong() 0085 { 0086 QSignalSpy pongSpy(exec([this] { 0087 return get<XdgWmBase>(); 0088 }), 0089 &XdgWmBase::pong); 0090 uint serial = exec([this] { 0091 return sendXdgShellPing(); 0092 }); 0093 QTRY_COMPARE(pongSpy.count(), 1); 0094 QTRY_COMPARE(pongSpy.first().at(0).toUInt(), serial); 0095 } 0096 0097 } // namespace MockCompositor