Files
RedBear-OS/local/recipes/kde/kwin/source/tests/x11shadowreader.cpp
T
vasilito 7aeb3bb475 build: capture build script auto-stash changes from 0.2.5 kernel/relibc/base build
The build-redbear.sh script auto-stashes working tree changes
in nested relibc and base source trees before running the
build. These changes were captured by the failed kernel
build attempt that hit the json-target-spec / kernel rust
toolchain mismatch (fixed in 0.2.5 by creating the local
0.2.5 branch).

Captured changes:
- local/recipes/kde/* : KDE Frameworks 6 source CMakeLists
  whitespace changes from the autostash (preserved)
- local/recipes/qt/qtbase/* : qtypes.h whitespace from the
  autostash (preserved)
- local/sources/kernel/Cargo.lock : dependency lock from
  the kernel relibc rebuild attempt
- local/sources/kernel/src/lib.rs : touched (mtime) by the
  build script's touch + make prefix command

This is a bookkeeping commit — the actual code changes
for the threading plan are on the 4 submodule branches
(kernel, relibc, base, libredox) and will be pushed
separately.

0.2.5 branch was created from 0.2.4 (HEAD cd3950072e) to
continue Phase 0 of the multi-threading plan work in a
clean branch.
2026-07-02 13:41:03 +03:00

118 lines
3.8 KiB
C++

/*
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
*/
#include "utils/xcbutils.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QFormLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
#include <private/qtx11extras_p.h>
static QList<uint32_t> readShadow(quint32 windowId)
{
KWin::Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SHADOW"), false, QX11Info::connection());
QList<uint32_t> ret;
if (windowId != XCB_WINDOW) {
KWin::Xcb::Property property(false, windowId, atom, XCB_ATOM_CARDINAL, 0, 12);
const auto shadow = property.array<uint32_t>();
if (shadow.has_value() && shadow->size() == 12) {
ret.reserve(12);
for (int i = 0; i < 12; ++i) {
ret << (*shadow)[i];
}
} else {
qDebug() << "!!!! no shadow";
}
} else {
qDebug() << "!!!! no window";
}
return ret;
}
static QList<QPixmap> getPixmaps(const QList<uint32_t> &data)
{
QList<QPixmap> ret;
static const int ShadowElementsCount = 8;
QList<KWin::Xcb::WindowGeometry> pixmapGeometries(ShadowElementsCount);
QList<xcb_get_image_cookie_t> getImageCookies(ShadowElementsCount);
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);
return QList<QPixmap>();
}
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) {
discardReplies(i + 1);
return QList<QPixmap>();
}
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);
app.setProperty("x11Connection", QVariant::fromValue<void *>(QX11Info::connection()));
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;
const auto shadow = readShadow(parser.positionalArguments().constFirst().toULongLong(&ok, 16));
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;
}
std::unique_ptr<QWidget> widget(new QWidget());
QFormLayout *layout = new QFormLayout(widget.get());
for (const auto &pix : pixmaps) {
QLabel *l = new QLabel(widget.get());
l->setPixmap(pix);
layout->addRow(QStringLiteral("%1x%2:").arg(pix.width()).arg(pix.height()), l);
}
widget->setLayout(layout);
widget->show();
return app.exec();
}