2016-07-06 11:32:38 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2016-07-06 11:32:38 +00:00
|
|
|
*/
|
2022-01-13 13:54:03 +00:00
|
|
|
#include "utils/xcbutils.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
|
2016-07-06 11:32:38 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QCommandLineParser>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QDebug>
|
2016-07-06 11:32:38 +00:00
|
|
|
#include <QFormLayout>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QLabel>
|
2016-07-06 11:32:38 +00:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QWidget>
|
2022-03-09 16:25:44 +00:00
|
|
|
#include <private/qtx11extras_p.h>
|
2016-07-06 11:32:38 +00:00
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
static QList<uint32_t> readShadow(quint32 windowId)
|
2016-07-06 11:32:38 +00:00
|
|
|
{
|
|
|
|
KWin::Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SHADOW"), false, QX11Info::connection());
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<uint32_t> ret;
|
2016-07-06 11:32:38 +00:00
|
|
|
if (windowId != XCB_WINDOW) {
|
|
|
|
KWin::Xcb::Property property(false, windowId, atom, XCB_ATOM_CARDINAL, 0, 12);
|
2022-03-23 10:13:38 +00:00
|
|
|
uint32_t *shadow = property.value<uint32_t *>();
|
2016-07-06 11:32:38 +00:00
|
|
|
if (shadow) {
|
|
|
|
ret.reserve(12);
|
2022-03-23 10:13:38 +00:00
|
|
|
for (int i = 0; i < 12; ++i) {
|
2016-07-06 11:32:38 +00:00
|
|
|
ret << shadow[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qDebug() << "!!!! no shadow";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qDebug() << "!!!! no window";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-10-19 06:50:15 +00:00
|
|
|
static QList<QPixmap> getPixmaps(const QList<uint32_t> &data)
|
2016-07-06 11:32:38 +00:00
|
|
|
{
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<QPixmap> ret;
|
2016-07-06 11:32:38 +00:00
|
|
|
static const int ShadowElementsCount = 8;
|
2023-10-19 06:50:15 +00:00
|
|
|
QList<KWin::Xcb::WindowGeometry> pixmapGeometries(ShadowElementsCount);
|
|
|
|
QList<xcb_get_image_cookie_t> getImageCookies(ShadowElementsCount);
|
2016-07-06 11:32:38 +00:00
|
|
|
auto *c = KWin::connection();
|
|
|
|
for (int i = 0; i < ShadowElementsCount; ++i) {
|
|
|
|
pixmapGeometries[i] = KWin::Xcb::WindowGeometry(data[i]);
|
|
|
|
}
|
|
|
|
auto discardReplies = [&getImageCookies](int start) {
|
|
|
|
for (int i = start; i < getImageCookies.size(); ++i) {
|
|
|
|
xcb_discard_reply(KWin::connection(), getImageCookies.at(i).sequence);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (int i = 0; i < ShadowElementsCount; ++i) {
|
|
|
|
auto &geo = pixmapGeometries[i];
|
|
|
|
if (geo.isNull()) {
|
|
|
|
discardReplies(0);
|
2023-10-19 06:50:15 +00:00
|
|
|
return QList<QPixmap>();
|
2016-07-06 11:32:38 +00:00
|
|
|
}
|
|
|
|
getImageCookies[i] = xcb_get_image_unchecked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, data[i],
|
|
|
|
0, 0, geo->width, geo->height, ~0);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < ShadowElementsCount; ++i) {
|
|
|
|
auto *reply = xcb_get_image_reply(c, getImageCookies.at(i), nullptr);
|
|
|
|
if (!reply) {
|
2022-03-23 10:13:38 +00:00
|
|
|
discardReplies(i + 1);
|
2023-10-19 06:50:15 +00:00
|
|
|
return QList<QPixmap>();
|
2016-07-06 11:32:38 +00:00
|
|
|
}
|
|
|
|
auto &geo = pixmapGeometries[i];
|
|
|
|
QImage image(xcb_get_image_data(reply), geo->width, geo->height, QImage::Format_ARGB32);
|
|
|
|
ret << QPixmap::fromImage(image);
|
|
|
|
free(reply);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
qputenv("QT_QPA_PLATFORM", "xcb");
|
|
|
|
QApplication app(argc, argv);
|
2022-03-23 10:13:38 +00:00
|
|
|
app.setProperty("x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
|
2016-07-06 11:32:38 +00:00
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addPositionalArgument(QStringLiteral("windowId"), QStringLiteral("The X11 windowId from which to read the shadow"));
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
if (parser.positionalArguments().count() != 1) {
|
|
|
|
parser.showHelp(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ok = false;
|
2021-05-13 16:38:42 +00:00
|
|
|
const auto shadow = readShadow(parser.positionalArguments().constFirst().toULongLong(&ok, 16));
|
2016-07-06 11:32:38 +00:00
|
|
|
if (!ok) {
|
|
|
|
qDebug() << "!!! Failed to read window id";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (shadow.isEmpty()) {
|
|
|
|
qDebug() << "!!!! Read shadow failed";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const auto pixmaps = getPixmaps(shadow);
|
|
|
|
if (pixmaps.isEmpty()) {
|
|
|
|
qDebug() << "!!!! Read pixmap failed";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<QWidget> widget(new QWidget());
|
|
|
|
QFormLayout *layout = new QFormLayout(widget.get());
|
2016-07-06 11:32:38 +00:00
|
|
|
for (const auto &pix : pixmaps) {
|
2022-08-01 21:29:02 +00:00
|
|
|
QLabel *l = new QLabel(widget.get());
|
2016-07-06 11:32:38 +00:00
|
|
|
l->setPixmap(pix);
|
|
|
|
layout->addRow(QStringLiteral("%1x%2:").arg(pix.width()).arg(pix.height()), l);
|
|
|
|
}
|
|
|
|
widget->setLayout(layout);
|
|
|
|
widget->show();
|
|
|
|
return app.exec();
|
|
|
|
}
|