LCOV - code coverage report
Current view: top level - window-lib - waylandqtamserverextension.cpp (source / functions) Coverage Total Hit
Test: QtApplicationManager Lines: 88.7 % 53 47
Test Date: 2024-05-11 10:19:06 Functions: 100.0 % 5 5
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35.7 % 126 45

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2021 The Qt Company Ltd.
       2                 :             : // Copyright (C) 2019 Luxoft Sweden AB
       3                 :             : // Copyright (C) 2018 Pelagicore AG
       4                 :             : // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
       5                 :             : 
       6                 :             : #include "waylandqtamserverextension_p.h"
       7                 :             : 
       8                 :             : #include <QDataStream>
       9                 :             : #include <QCborValue>
      10                 :             : #include <QtWaylandCompositor/QWaylandCompositor>
      11                 :             : #include <QtWaylandCompositor/QWaylandResource>
      12                 :             : #include <QtWaylandCompositor/QWaylandSurface>
      13                 :             : 
      14                 :             : #include <QtAppManCommon/logging.h>
      15                 :             : 
      16                 :             : QT_BEGIN_NAMESPACE_AM
      17                 :             : 
      18                 :          25 : WaylandQtAMServerExtension::WaylandQtAMServerExtension(QWaylandCompositor *compositor)
      19                 :             :     : QWaylandCompositorExtensionTemplate(compositor)
      20   [ +  -  +  - ]:          25 :     , QtWaylandServer::qtam_extension(compositor->display(), 2)
      21                 :          25 : { }
      22                 :             : 
      23                 :          79 : QVariantMap WaylandQtAMServerExtension::windowProperties(const QWaylandSurface *surface) const
      24                 :             : {
      25                 :          79 :     return m_windowProperties.value(surface);
      26                 :             : }
      27                 :             : 
      28                 :          58 : void WaylandQtAMServerExtension::setWindowProperty(QWaylandSurface *surface, const QString &name, const QVariant &value)
      29                 :             : {
      30         [ +  - ]:          58 :     if (setWindowPropertyHelper(surface, name, value)) {
      31   [ +  -  +  -  :         116 :         if (Resource *target = resourceMap().value(surface->waylandClient())) {
                   +  - ]
      32                 :          58 :             QByteArray data;
      33                 :             : 
      34   [ +  -  +  +  :          58 :             switch (target->version()) {
                      - ]
      35                 :          52 :             case 1: {
      36         [ +  - ]:          52 :                 QDataStream ds(&data, QDataStream::WriteOnly);
      37         [ +  - ]:          52 :                 ds << value;
      38                 :          52 :                 break;
      39                 :          52 :             }
      40                 :           6 :             case 2:
      41   [ +  -  +  -  :           6 :                 data = QCborValue::fromVariant(value).toCbor();
             +  +  -  - ]
      42                 :           6 :                 break;
      43                 :           0 :             default:
      44   [ #  #  #  #  :           0 :                 qCWarning(LogWaylandDebug) << "Unsupported qtam_extension version:" << target->version();
          #  #  #  #  #  
                #  #  # ]
      45                 :           0 :                 return;
      46                 :             :             }
      47                 :             : 
      48   [ +  -  -  -  :         116 :             qCDebug(LogWaylandDebug) << "window property: server send" << surface << name << value;
          -  -  -  -  -  
             -  -  -  -  
                      + ]
      49   [ +  -  +  - ]:          58 :             send_window_property_changed(target->handle, surface->resource(), name, data);
      50                 :          58 :         }
      51                 :             :     }
      52                 :             : }
      53                 :             : 
      54                 :         109 : bool WaylandQtAMServerExtension::setWindowPropertyHelper(QWaylandSurface *surface, const QString &name, const QVariant &value)
      55                 :             : {
      56                 :         109 :     auto it = m_windowProperties.find(surface);
      57   [ +  -  +  +  :         181 :     if ((it == m_windowProperties.end()) || (it.value().value(name) != value)) {
          +  -  +  -  +  
          -  +  +  +  +  
             +  -  -  - ]
      58         [ +  + ]:         109 :         if (it == m_windowProperties.end()) {
      59                 :          37 :             m_windowProperties[surface].insert(name, value);
      60                 :          37 :             connect(surface, &QWaylandSurface::surfaceDestroyed, this, [this, surface]() {
      61                 :          37 :                 m_windowProperties.remove(surface);
      62                 :             :             });
      63                 :             :         } else {
      64                 :          72 :             it.value().insert(name, value);
      65                 :             :         }
      66                 :         109 :         emit windowPropertyChanged(surface, name, value);
      67                 :         109 :         return true;
      68                 :             :     }
      69                 :             :     return false;
      70                 :             : }
      71                 :             : 
      72                 :          51 : void WaylandQtAMServerExtension::qtam_extension_set_window_property(QtWaylandServer::qtam_extension::Resource *resource, wl_resource *surface_resource, const QString &name, wl_array *value)
      73                 :             : {
      74                 :          51 :     QWaylandSurface *surface = QWaylandSurface::fromResource(surface_resource);
      75                 :          51 :     const auto data = QByteArray::fromRawData(static_cast<const char *>(value->data), qsizetype(value->size));
      76         [ +  - ]:          51 :     QVariant variantValue;
      77                 :             : 
      78   [ +  -  +  +  :          51 :     switch (resource->version()) {
                      - ]
      79                 :          50 :     case 1: {
      80         [ +  - ]:          50 :         QDataStream ds(data);
      81         [ +  - ]:          50 :         ds >> variantValue;
      82                 :          50 :         break;
      83                 :          50 :     }
      84                 :           1 :     case 2:
      85   [ +  -  +  -  :           1 :         variantValue = QCborValue::fromCbor(data).toVariant();
                   +  - ]
      86                 :           1 :         break;
      87                 :           0 :     default:
      88   [ #  #  #  #  :           0 :         qCWarning(LogWaylandDebug) << "Unsupported qtam_extension version:" << resource->version();
          #  #  #  #  #  
                #  #  # ]
      89                 :           0 :         return;
      90                 :             :     }
      91   [ +  -  -  -  :         153 :     qCDebug(LogWaylandDebug) << "window property: server receive" << surface << name << variantValue;
          -  -  -  -  -  
          -  -  -  -  +  
                   -  + ]
      92         [ +  - ]:          51 :     setWindowPropertyHelper(surface, name, variantValue);
      93                 :          51 : }
      94                 :             : 
      95                 :             : QT_END_NAMESPACE_AM
      96                 :             : 
      97                 :             : #include "moc_waylandqtamserverextension_p.cpp"
        

Generated by: LCOV version 2.0-1