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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/*
Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "info_wayland.h"
#include <KLocalizedString>
#include <QTreeWidgetItem>
#include <QThread>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/event_queue.h>
#include <KWayland/Client/keyboard.h>
#include <KWayland/Client/output.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/registry.h>
WaylandModule::WaylandModule(QTreeWidget *parent)
: QObject(parent)
, m_tree(parent)
, m_thread(new QThread(this))
, m_connection(new KWayland::Client::ConnectionThread)
{
init();
}
WaylandModule::~WaylandModule()
{
delete m_registry;
m_connection->deleteLater();
m_thread->quit();
m_thread->wait();
}
void WaylandModule::init()
{
using namespace KWayland::Client;
m_connection->moveToThread(m_thread);
m_thread->start();
m_tree->setHeaderLabels(QStringList() << i18n("Information") << i18n("Value"));
m_tree->setSortingEnabled(false);
auto compositorItem = new QTreeWidgetItem(m_tree, QStringList() << i18n("Compositor Information"));
compositorItem->setIcon(0, QIcon::fromTheme(QStringLiteral("wayland")));
compositorItem->setExpanded(true);
new QTreeWidgetItem(compositorItem, QStringList() << i18n("Name of the Display") << QString::fromLatin1(qgetenv("WAYLAND_DISPLAY")));
auto interfacesItem = new QTreeWidgetItem(compositorItem, QStringList() << i18n("Interfaces") << i18n("Interface Version"));
interfacesItem->setExpanded(true);
connect(m_connection, &ConnectionThread::connected, this,
[this, compositorItem, interfacesItem] {
Registry *registry = new Registry(this);
EventQueue *queue = new EventQueue(registry);
queue->setup(m_connection);
registry->setEventQueue(queue);
connect(registry, &Registry::interfaceAnnounced, this,
[this, interfacesItem] (const QByteArray &interface, quint32 name, quint32 version) {
Q_UNUSED(name)
new QTreeWidgetItem(interfacesItem, QStringList() << QString::fromLatin1(interface) << QString::number(version));
}
);
connect(registry, &Registry::seatAnnounced, this,
[this, registry, compositorItem] (quint32 name, quint32 version) {
QTreeWidgetItem *seatItem = new QTreeWidgetItem(compositorItem, QStringList() << i18n("Seat") << QString());
seatItem->setExpanded(true);
Seat *seat = registry->createSeat(name, version, registry);
connect(seat, &Seat::nameChanged, this,
[this, seat, seatItem] {
new QTreeWidgetItem(seatItem, QStringList() << i18n("Name") << seat->name());
}
);
connect(seat, &Seat::hasPointerChanged, this,
[this, seat, seatItem] {
if (seat->hasPointer()) {
new QTreeWidgetItem(seatItem, QStringList() << i18n("Pointer"));
}
}
);
connect(seat, &Seat::hasKeyboardChanged, this,
[this, seat, seatItem] {
if (seat->hasKeyboard()) {
auto i = new QTreeWidgetItem(seatItem, QStringList{i18n("Keyboard")});
i->setExpanded(true);
auto e = new QTreeWidgetItem(i, QStringList{i18n("Repeat enabled")});
auto r = new QTreeWidgetItem(i, QStringList{i18n("Repeat rate (characters per second)")});
auto d = new QTreeWidgetItem(i, QStringList{i18n("Repeat delay (msec)")});
auto k = seat->createKeyboard(seat);
connect(k, &Keyboard::keyRepeatChanged, this,
[this, k, e, r, d] {
e->setText(1, k->isKeyRepeatEnabled() ? i18n("Yes") : i18n("No"));
r->setText(1, QString::number(k->keyRepeatRate()));
d->setText(1, QString::number(k->keyRepeatDelay()));
}
);
}
}
);
connect(seat, &Seat::hasTouchChanged, this,
[this, seat, seatItem] {
if (seat->hasTouch()) {
new QTreeWidgetItem(seatItem, QStringList() << i18n("Touch"));
}
}
);
}
);
QTreeWidgetItem *outputItem = new QTreeWidgetItem(compositorItem, QStringList() << i18n("Outputs"));
outputItem->setExpanded(true);
connect(registry, &Registry::outputAnnounced, this,
[this, registry, outputItem] (quint32 name, quint32 version) {
Output *output = registry->createOutput(name, version, registry);
connect(output, &Output::changed, this,
[this, output, outputItem] {
output->deleteLater();
const QSize s = output->physicalSize();
const QPoint p = output->globalPosition();
auto o = new QTreeWidgetItem(outputItem, QStringList() << QString::number(outputItem->childCount()));
o->setExpanded(true);
new QTreeWidgetItem(o, QStringList() << i18n("Manufacturer") << output->manufacturer());
new QTreeWidgetItem(o, QStringList() << i18n("Model") << output->model());
new QTreeWidgetItem(o, QStringList() << i18n("Physical Size") << QStringLiteral("%1x%2").arg(s.width()).arg(s.height()));
new QTreeWidgetItem(o, QStringList() << i18n("Global Position") << QStringLiteral("%1/%2").arg(p.x()).arg(p.y()));
QString subPixel;
switch (output->subPixel()) {
case Output::SubPixel::None:
subPixel = i18n("None");
break;
case Output::SubPixel::HorizontalRGB:
subPixel = i18n("Horizontal RGB");
break;
case Output::SubPixel::HorizontalBGR:
subPixel = i18n("Horizontal BGR");
break;
case Output::SubPixel::VerticalRGB:
subPixel = i18n("Vertical RGB");
break;
case Output::SubPixel::VerticalBGR:
subPixel = i18n("Vertical BGR");
break;
case Output::SubPixel::Unknown:
default:
subPixel = i18n("Unknown");
break;
}
new QTreeWidgetItem(o, QStringList() << i18n("Subpixel") << subPixel);
QString transform;
switch (output->transform()) {
case Output::Transform::Rotated90:
transform = QStringLiteral("90");
break;
case Output::Transform::Rotated180:
transform = QStringLiteral("180");
break;
case Output::Transform::Rotated270:
transform = QStringLiteral("270");
break;
case Output::Transform::Flipped:
transform = i18n("Flipped");
break;
case Output::Transform::Flipped90:
transform = i18n("Flipped 90");
break;
case Output::Transform::Flipped180:
transform = i18n("Flipped 180");
break;
case Output::Transform::Flipped270:
transform = i18n("Flipped 270");
break;
case Output::Transform::Normal:
default:
transform = i18n("Normal");
break;
}
new QTreeWidgetItem(o, QStringList() << i18n("Transform") << transform);
new QTreeWidgetItem(o, QStringList() << i18nc("The scale factor of the output", "Scale") << QString::number(output->scale()));
// add Modes
auto modesItem = new QTreeWidgetItem(o, QStringList() << i18n("Modes"));
int i = 0;
for (const auto &mode : output->modes()) {
auto modeItem = new QTreeWidgetItem(modesItem, QStringList() << QString::number(i++));
modeItem->setExpanded(true);
new QTreeWidgetItem(modeItem, QStringList() << i18n("Size")
<< QStringLiteral("%1x%2").arg(mode.size.width()).arg(mode.size.height()));
new QTreeWidgetItem(modeItem, QStringList() << i18n("Refresh Rate")
<< QString::number(mode.refreshRate));
new QTreeWidgetItem(modeItem, QStringList() << i18n("Preferred")
<< (mode.flags.testFlag(Output::Mode::Flag::Preferred) ? i18n("yes") : i18n("no")));
new QTreeWidgetItem(modeItem, QStringList() << i18n("Current")
<< (mode.flags.testFlag(Output::Mode::Flag::Current) ? i18n("yes") : i18n("no")));
}
}
);
}
);
m_registry = registry;
registry->create(m_connection);
registry->setup();
},
Qt::QueuedConnection
);
m_connection->initConnection();
}
|