From 06e4555269acdbb9eb3089c5682cc760203bd160 Mon Sep 17 00:00:00 2001 From: "Tobias J. Endres" Date: Thu, 14 Aug 2025 00:59:25 +0200 Subject: [PATCH] feat: Add debug logging to hgx11grab.cpp Added qDebug() statements to trace the execution flow and print out important values in the screen grabbing process. This will help to identify the root cause of the screen grabbing issue. --- hgx11grab.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hgx11grab.cpp b/hgx11grab.cpp index 1ff7174..dbf4b16 100644 --- a/hgx11grab.cpp +++ b/hgx11grab.cpp @@ -1,9 +1,11 @@ #include "hgx11grab.h" +#include // public hgx11grab::hgx11grab(Display *display, unsigned short scaleDivisor, const char *filter) { + qDebug() << "hgx11grab constructor"; _filter_p = filter; _display_p = display; @@ -11,6 +13,7 @@ hgx11grab::hgx11grab(Display *display, unsigned short scaleDivisor, const char * qCritical() << "Xshm is: not available."; return; } + qDebug() << "XShm extension is available."; int dummy, pixmaps_supported; @@ -18,19 +21,23 @@ hgx11grab::hgx11grab(Display *display, unsigned short scaleDivisor, const char * qCritical() << "XRender is not available."; return; } + qDebug() << "XRender extension is available."; if (!XShmQueryVersion(_display_p, &dummy, &dummy, &pixmaps_supported)) { qCritical("Could not get x shared memory version."); return; } + qDebug() << "XShm version query successful."; bool _XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_display_p) == ZPixmap; if (!_XShmPixmapAvailable) { qCritical() << "XshmPixMap is: not available."; return; } + qDebug() << "XShm pixmap is available."; _window_m = DefaultRootWindow(_display_p); + qDebug() << "Root window:" << _window_m; if (!_getWinAttr()) { return; @@ -38,6 +45,7 @@ hgx11grab::hgx11grab(Display *display, unsigned short scaleDivisor, const char * _destWidth_m = int(_srcWidth_m / scaleDivisor); _destHeight_m = int(_srcHeight_m / scaleDivisor); + qDebug() << "Destination size:" << _destWidth_m << "x" << _destHeight_m; _imgSize_m = _destHeight_m * _destWidth_m * 4; @@ -55,6 +63,7 @@ hgx11grab::hgx11grab(Display *display, unsigned short scaleDivisor, const char * _setScale(); connect(this, SIGNAL(scaleChanged()), this, SLOT(_changeScale())); + qDebug() << "hgx11grab constructor finished."; } hgx11grab::~hgx11grab() @@ -76,11 +85,14 @@ int hgx11grab::getDest_width() const bool hgx11grab::_getWinAttr() { + qDebug() << "Getting window attributes."; if (XGetWindowAttributes(_display_p, _window_m, &_windowAttr_m) == 0) { qWarning() << "Failed to obtain X11 window attributes."; return false; } + qDebug() << "Window size:" << _windowAttr_m.width << "x" << _windowAttr_m.height; if (_srcWidth_m != _windowAttr_m.width || _srcHeight_m != _windowAttr_m.height) { + qDebug() << "Screen size changed."; if (0 != _srcWidth_m) { _freeResources(); } @@ -96,6 +108,7 @@ void hgx11grab::_freeResources() if (_freed_m) { return; } + qDebug() << "Freeing resources."; XDestroyImage(_xImage_p); XShmDetach(_display_p, &_shminfo_m); shmdt(_shminfo_m.shmaddr); @@ -116,6 +129,7 @@ void hgx11grab::_setScale() void hgx11grab::grabFrame() { + qDebug() << "Grabbing frame."; if (!_getWinAttr()) { return; } @@ -126,20 +140,24 @@ void hgx11grab::grabFrame() uint(_windowAttr_m.depth), ZPixmap, nullptr, &_shminfo_m, uint(_destWidth_m), uint(_destHeight_m) ); + qDebug() << "XShmCreateImage successful."; _shminfo_m.shmid = shmget(IPC_PRIVATE, ulong(_xImage_p->bytes_per_line * _xImage_p->height), IPC_CREAT|0777); _xImage_p->data = reinterpret_cast(shmat(_shminfo_m.shmid, nullptr, 0)); _shminfo_m.shmaddr = _xImage_p->data; _shminfo_m.readOnly = false; + qDebug() << "Shared memory segment created."; XShmAttach(_display_p, &_shminfo_m); _pixmap_m = XShmCreatePixmap(_display_p, _window_m, _xImage_p->data, &_shminfo_m, uint(_destWidth_m), uint(_destHeight_m), uint(_windowAttr_m.depth)); + qDebug() << "XShm pixmap created."; _dstFormat_p = XRenderFindVisualFormat(_display_p, _windowAttr_m.visual); _srcFormat_p = XRenderFindVisualFormat(_display_p, _windowAttr_m.visual); _srcPicture_m = XRenderCreatePicture(_display_p, _window_m, _srcFormat_p, CPRepeat, &_pictAttr_m); _dstPicture_m = XRenderCreatePicture(_display_p, _pixmap_m, _dstFormat_p, CPRepeat, &_pictAttr_m); + qDebug() << "XRender pictures created."; XRenderSetPictureFilter(_display_p, _srcPicture_m, _filter_p, nullptr, 0); XRenderSetPictureTransform(_display_p, _srcPicture_m, &_mTransform_m); @@ -159,10 +177,12 @@ void hgx11grab::grabFrame() uint(_destWidth_m), // width uint(_destHeight_m) // height ); + qDebug() << "XRenderComposite successful."; XSync(_display_p, false); XShmGetImage(_display_p, _pixmap_m, _xImage_p, 0, 0, 0xFFFFFFFF); + qDebug() << "XShmGetImage successful."; if (_xImage_p == nullptr) { qWarning() << "Failed to get image from X11 server."; @@ -172,6 +192,7 @@ void hgx11grab::grabFrame() QImage qimg(reinterpret_cast(_xImage_p->data), _destWidth_m, _destHeight_m, _xImage_p->bytes_per_line, QImage::Format_ARGB32); qimg = qimg.convertToFormat(QImage::Format_RGB888); imgdata_m = QByteArray::fromRawData(reinterpret_cast(qimg.bits()), qimg.sizeInBytes()).toBase64().data(); + qDebug() << "Image converted and encoded."; _freeResources();