9#include <QCommandLineParser>
15#include <private/qtx11extras_p.h>
17static QList<uint32_t> readShadow(quint32 windowId)
19 KWin::Xcb::Atom atom(QByteArrayLiteral(
"_KDE_NET_WM_SHADOW"),
false, QX11Info::connection());
21 if (windowId != XCB_WINDOW) {
23 uint32_t *shadow =
property.value<uint32_t *>();
26 for (
int i = 0; i < 12; ++i) {
30 qDebug() <<
"!!!! no shadow";
33 qDebug() <<
"!!!! no window";
38static QList<QPixmap> getPixmaps(
const QList<uint32_t> &data)
41 static const int ShadowElementsCount = 8;
42 QList<KWin::Xcb::WindowGeometry> pixmapGeometries(ShadowElementsCount);
43 QList<xcb_get_image_cookie_t> getImageCookies(ShadowElementsCount);
45 for (
int i = 0; i < ShadowElementsCount; ++i) {
48 auto discardReplies = [&getImageCookies](
int start) {
49 for (
int i = start; i < getImageCookies.size(); ++i) {
53 for (
int i = 0; i < ShadowElementsCount; ++i) {
54 auto &geo = pixmapGeometries[i];
57 return QList<QPixmap>();
59 getImageCookies[i] = xcb_get_image_unchecked(c, XCB_IMAGE_FORMAT_Z_PIXMAP, data[i],
60 0, 0, geo->width, geo->height, ~0);
62 for (
int i = 0; i < ShadowElementsCount; ++i) {
63 auto *reply = xcb_get_image_reply(c, getImageCookies.at(i),
nullptr);
65 discardReplies(i + 1);
66 return QList<QPixmap>();
68 auto &geo = pixmapGeometries[i];
69 QImage image(xcb_get_image_data(reply), geo->width, geo->height, QImage::Format_ARGB32);
70 ret << QPixmap::fromImage(image);
76int main(
int argc,
char **argv)
78 qputenv(
"QT_QPA_PLATFORM",
"xcb");
79 QApplication app(argc, argv);
80 app.setProperty(
"x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
82 QCommandLineParser parser;
83 parser.addPositionalArgument(QStringLiteral(
"windowId"), QStringLiteral(
"The X11 windowId from which to read the shadow"));
84 parser.addHelpOption();
87 if (parser.positionalArguments().count() != 1) {
92 const auto shadow = readShadow(parser.positionalArguments().constFirst().toULongLong(&ok, 16));
94 qDebug() <<
"!!! Failed to read window id";
97 if (shadow.isEmpty()) {
98 qDebug() <<
"!!!! Read shadow failed";
101 const auto pixmaps = getPixmaps(shadow);
102 if (pixmaps.isEmpty()) {
103 qDebug() <<
"!!!! Read pixmap failed";
107 std::unique_ptr<QWidget> widget(
new QWidget());
108 QFormLayout *layout =
new QFormLayout(widget.get());
109 for (
const auto &pix : pixmaps) {
110 QLabel *l =
new QLabel(widget.get());
112 layout->addRow(QStringLiteral(
"%1x%2:").arg(pix.width()).arg(pix.height()), l);
114 widget->setLayout(layout);
KWIN_EXPORT xcb_connection_t * connection()