File indexing completed on 2024-05-26 05:39:41
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2020 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 #pragma once 0030 0031 #include "coreprotocol.h" 0032 0033 #include <qwayland-server-xdg-output-unstable-v1.h> 0034 0035 namespace MockCompositor 0036 { 0037 class XdgOutputV1 : public QObject, public QtWaylandServer::zxdg_output_v1 0038 { 0039 Q_OBJECT 0040 public: 0041 explicit XdgOutputV1(Output *output) 0042 : m_output(output) 0043 , m_logicalGeometry(m_output->m_data.position, QSize(m_output->m_data.mode.resolution / m_output->m_data.scale)) 0044 , m_name(m_output->m_data.connector.isEmpty() ? QString("WL-%1").arg(s_nextId++) : m_output->m_data.connector) 0045 { 0046 } 0047 0048 void send_logical_size(int32_t width, int32_t height) = delete; 0049 void sendLogicalSize(const QSize &size); 0050 0051 void send_done() = delete; // zxdg_output_v1.done has been deprecated (in protocol version 3) 0052 0053 void addResource(wl_client *client, int id, int version); 0054 Output *m_output = nullptr; 0055 QRect m_logicalGeometry; 0056 QString m_name; 0057 QString m_description = "This is an Xdg Output description"; 0058 static int s_nextId; 0059 }; 0060 0061 class XdgOutputManagerV1 : public Global, public QtWaylandServer::zxdg_output_manager_v1 0062 { 0063 Q_OBJECT 0064 public: 0065 explicit XdgOutputManagerV1(CoreCompositor *compositor) 0066 : QtWaylandServer::zxdg_output_manager_v1(compositor->m_display, 3) 0067 { 0068 } 0069 QMap<Output *, XdgOutputV1 *> m_xdgOutputs; 0070 XdgOutputV1 *getXdgOutput(Output *output) 0071 { 0072 if (auto *xdgOutput = m_xdgOutputs.value(output)) { 0073 return xdgOutput; 0074 } 0075 m_xdgOutputs[output] = new XdgOutputV1(output); 0076 connect(output, &Output::destroyed, this, [this, output]() { 0077 delete m_xdgOutputs[output]; 0078 m_xdgOutputs.remove(output); 0079 }); 0080 return m_xdgOutputs[output]; 0081 } 0082 0083 protected: 0084 void zxdg_output_manager_v1_get_xdg_output(Resource *resource, uint32_t id, wl_resource *outputResource) override 0085 { 0086 auto *output = fromResource<Output>(outputResource); 0087 auto *xdgOutput = getXdgOutput(output); 0088 xdgOutput->addResource(resource->client(), id, resource->version()); 0089 } 0090 }; 0091 0092 } // namespace MockCompositor