1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "console.h"
#include <KWindowSystem>
#include <QDebug>
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStandardPaths>
#include <QTextStream>
#include <kscreen/config.h>
#include <kscreen/configmonitor.h>
#include <kscreen/edid.h>
#include <kscreen/getconfigoperation.h>
#include <kscreen/mode.h>
#include <kscreen/screen.h>
#include <kscreen/types.h>
static QTextStream cout(stdout);
namespace KScreen
{
namespace ConfigSerializer
{
// Exported private symbol in configserializer_p.h in KScreen
extern QJsonObject serializeConfig(const KScreen::ConfigPtr &config);
}
}
using namespace KScreen;
Console::Console(const ConfigPtr &config)
: QObject()
, m_config(config)
{
}
Console::~Console()
{
}
void Console::printConfig()
{
if (!m_config) {
qDebug() << "Config is invalid, probably backend couldn't load";
return;
}
if (!m_config->screen()) {
qDebug() << "No screen in the configuration, broken backend";
return;
}
connect(m_config.data(), &Config::prioritiesChanged, [&]() {
qDebug() << "Priorities changed:" << m_config.data()->outputs();
});
qDebug() << "Screen:";
qDebug() << "\tmaxSize:" << m_config->screen()->maxSize();
qDebug() << "\tminSize:" << m_config->screen()->minSize();
qDebug() << "\tcurrentSize:" << m_config->screen()->currentSize();
const OutputList outputs = m_config->outputs();
for (const OutputPtr &output : outputs) {
qDebug() << "\n-----------------------------------------------------\n";
qDebug() << "Id: " << output->id();
qDebug() << "Name: " << output->name();
qDebug() << "Type: " << output->typeName();
qDebug() << "Connected: " << output->isConnected();
if (!output->isConnected()) {
continue;
}
qDebug() << "Enabled: " << output->isEnabled();
qDebug() << "Priority: " << output->priority();
qDebug() << "Rotation: " << output->rotation();
qDebug() << "Pos: " << output->pos();
qDebug() << "MMSize: " << output->sizeMm();
qDebug() << "FollowPreferredMode: " << output->followPreferredMode();
if (output->currentMode()) {
qDebug() << "Size: " << output->size();
}
qDebug() << "Scale: " << output->scale();
if (output->clones().isEmpty()) {
qDebug() << "Clones: "
<< "None";
} else {
qDebug() << "Clones: " << output->clones().count();
}
qDebug() << "Mode: " << output->currentModeId();
qDebug() << "Preferred Mode: " << output->preferredModeId();
qDebug() << "Preferred modes: " << output->preferredModes();
qDebug() << "Modes: ";
const ModeList modes = output->modes();
for (const ModePtr &mode : modes) {
qDebug() << "\t" << mode->id() << " " << mode->name() << " " << mode->size() << " " << mode->refreshRate();
}
Edid *edid = output->edid();
qDebug() << "EDID Info: ";
if (edid && edid->isValid()) {
qDebug() << "\tDevice ID: " << edid->deviceId();
qDebug() << "\tName: " << edid->name();
qDebug() << "\tVendor: " << edid->vendor();
qDebug() << "\tSerial: " << edid->serial();
qDebug() << "\tEISA ID: " << edid->eisaId();
qDebug() << "\tHash: " << edid->hash();
qDebug() << "\tWidth: " << edid->width();
qDebug() << "\tHeight: " << edid->height();
qDebug() << "\tGamma: " << edid->gamma();
qDebug() << "\tRed: " << edid->red();
qDebug() << "\tGreen: " << edid->green();
qDebug() << "\tBlue: " << edid->blue();
qDebug() << "\tWhite: " << edid->white();
} else {
qDebug() << "\tUnavailable";
}
}
}
void Console::printJSONConfig()
{
QJsonDocument doc(KScreen::ConfigSerializer::serializeConfig(m_config));
cout << doc.toJson(QJsonDocument::Indented);
}
void Console::printSerializations()
{
if (KWindowSystem::isPlatformWayland()) {
QFile file(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1String("/kwinoutputconfig.json"));
file.open(QFile::ReadOnly);
qDebug().noquote() << file.readAll();
} else {
QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kscreen/");
qDebug() << "Configs in: " << path;
QDir dir(path);
const QStringList files = dir.entryList(QDir::Files);
qDebug() << "Number of files: " << files.count() << Qt::endl;
QJsonDocument parser;
for (const QString &fileName : files) {
QJsonParseError error;
qDebug() << fileName;
QFile file(path + QLatin1Char('/') + fileName);
file.open(QFile::ReadOnly);
QJsonDocument parser = QJsonDocument::fromJson(file.readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug() << " can't parse file:";
qDebug() << " " << error.errorString();
} else {
qDebug().noquote() << parser.toJson(QJsonDocument::Indented);
}
}
}
}
void Console::monitor()
{
ConfigMonitor::instance()->addConfig(m_config);
}
void Console::monitorAndPrint()
{
monitor();
connect(ConfigMonitor::instance(), &ConfigMonitor::configurationChanged, this, &Console::printConfig);
}
#include "moc_console.cpp"
|