File indexing completed on 2024-04-21 16:17:35

0001 /*
0002  *  SPDX-FileCopyrightText: 2013 Alejandro Fiestas Olivares <afiestas@kde.org>
0003  *  SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #include "testpnp.h"
0009 
0010 #include "../src/configmonitor.h"
0011 #include "../src/edid.h"
0012 #include "../src/getconfigoperation.h"
0013 #include "../src/mode.h"
0014 #include "../src/output.h"
0015 
0016 #include <QGuiApplication>
0017 #include <QRect>
0018 #include <QScreen>
0019 #include <cstdint>
0020 //#include <QX11Info>
0021 
0022 using namespace KScreen;
0023 
0024 QString typetoString(const Output::Type &type)
0025 {
0026     switch (type) {
0027     case Output::Unknown:
0028         return QStringLiteral("Unknown");
0029     case Output::Panel:
0030         return QStringLiteral("Panel (Laptop)");
0031     case Output::VGA:
0032         return QStringLiteral("VGA");
0033     case Output::DVII:
0034         return QStringLiteral("DVI-I");
0035     case Output::DVIA:
0036         return QStringLiteral("DVI-A");
0037     case Output::DVID:
0038         return QStringLiteral("DVI-D");
0039     case Output::HDMI:
0040         return QStringLiteral("HDMI");
0041     case Output::TV:
0042         return QStringLiteral("TV");
0043     case Output::TVComposite:
0044         return QStringLiteral("TV-Composite");
0045     case Output::TVSVideo:
0046         return QStringLiteral("TV-SVideo");
0047     case Output::TVComponent:
0048         return QStringLiteral("TV-Component");
0049     case Output::TVSCART:
0050         return QStringLiteral("TV-SCART");
0051     case Output::TVC4:
0052         return QStringLiteral("TV-C4");
0053     case Output::DisplayPort:
0054         return QStringLiteral("DisplayPort");
0055     default:
0056         return QStringLiteral("Invalid Type");
0057     };
0058 }
0059 
0060 TestPnp::TestPnp(bool monitor, QObject *parent)
0061     : QObject(parent)
0062     , m_monitor(monitor)
0063 {
0064     init();
0065 }
0066 
0067 TestPnp::~TestPnp()
0068 {
0069 }
0070 
0071 void TestPnp::init()
0072 {
0073     connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished, this, &TestPnp::configReady);
0074 }
0075 
0076 void TestPnp::configReady(KScreen::ConfigOperation *op)
0077 {
0078     m_config = qobject_cast<KScreen::GetConfigOperation *>(op)->config();
0079     if (!m_config) {
0080         qDebug() << "Config is invalid, probably backend couldn't load";
0081         qApp->quit();
0082         return;
0083     }
0084     if (!m_config->screen()) {
0085         qDebug() << "No screen in the configuration, broken backend";
0086         qApp->quit();
0087         return;
0088     }
0089 
0090     print();
0091     if (m_monitor) {
0092         ConfigMonitor::instance()->addConfig(m_config);
0093     } else {
0094         qApp->quit();
0095     }
0096 }
0097 
0098 void TestPnp::print()
0099 {
0100     qDebug() << "Screen:";
0101     qDebug() << "\tmaxSize:" << m_config->screen()->maxSize();
0102     qDebug() << "\tminSize:" << m_config->screen()->minSize();
0103     qDebug() << "\tcurrentSize:" << m_config->screen()->currentSize();
0104 
0105     const OutputList outputs = m_config->outputs();
0106     for (const OutputPtr &output : outputs) {
0107         qDebug() << "\n-----------------------------------------------------\n";
0108         qDebug() << "Id: " << output->id();
0109         qDebug() << "Name: " << output->name();
0110         qDebug() << "Type: " << typetoString(output->type());
0111         qDebug() << "Connected: " << output->isConnected();
0112         if (!output->isConnected()) {
0113             continue;
0114         }
0115         qDebug() << "Enabled: " << output->isEnabled();
0116         qDebug() << "Priority: " << output->priority();
0117         qDebug() << "Rotation: " << output->rotation();
0118         qDebug() << "Pos: " << output->pos();
0119         qDebug() << "MMSize: " << output->sizeMm();
0120         if (output->currentMode()) {
0121             qDebug() << "Size: " << output->currentMode()->size();
0122         }
0123         if (output->clones().isEmpty()) {
0124             qDebug() << "Clones: "
0125                      << "None";
0126         } else {
0127             qDebug() << "Clones: " << output->clones().count();
0128         }
0129         qDebug() << "Mode: " << output->currentModeId();
0130         qDebug() << "Preferred Mode: " << output->preferredModeId();
0131         qDebug() << "Preferred modes: " << output->preferredModes();
0132         qDebug() << "Modes: ";
0133 
0134         const ModeList modes = output->modes();
0135         for (const ModePtr &mode : modes) {
0136             qDebug() << "\t" << mode->id() << "  " << mode->name() << " " << mode->size() << " " << mode->refreshRate();
0137         }
0138 
0139         const Edid *const edid = output->edid();
0140         qDebug() << "EDID Info: ";
0141         if (edid && edid->isValid()) {
0142             qDebug() << "\tDevice ID: " << edid->deviceId();
0143             qDebug() << "\tName: " << edid->name();
0144             qDebug() << "\tVendor: " << edid->vendor();
0145             qDebug() << "\tSerial: " << edid->serial();
0146             qDebug() << "\tEISA ID: " << edid->eisaId();
0147             qDebug() << "\tHash: " << edid->hash();
0148             qDebug() << "\tWidth: " << edid->width();
0149             qDebug() << "\tHeight: " << edid->height();
0150             qDebug() << "\tGamma: " << edid->gamma();
0151             qDebug() << "\tRed: " << edid->red();
0152             qDebug() << "\tGreen: " << edid->green();
0153             qDebug() << "\tBlue: " << edid->blue();
0154             qDebug() << "\tWhite: " << edid->white();
0155         } else {
0156             qDebug() << "\tUnavailable";
0157         }
0158     }
0159 }