Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/make -f
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
export QT_SELECT = qt5
export QT_SELECT = qt6
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall
export DEB_CXXFLAGS_MAINT_APPEND = -Wall
Expand Down
42 changes: 25 additions & 17 deletions plugins/application-tray/sniprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,23 @@ SniTrayProtocolHandler::SniTrayProtocolHandler(const QString &sniServicePath, QO
init();

connect(m_sniInter, &StatusNotifierItem::NewIcon, this, [this] {
m_cachedIcon = dbusImageList2QIcon(m_sniInter->iconPixmap());
if (m_sniInter->iconName().isEmpty())
m_cachedIcon = dbusImageList2QIcon(m_sniInter->iconPixmap());
Q_EMIT iconChanged();
});
connect(m_sniInter, &StatusNotifierItem::NewOverlayIcon, this, &SniTrayProtocolHandler::overlayIconChanged);
connect(m_sniInter, &StatusNotifierItem::NewOverlayIcon, this, [this] {
if (m_sniInter->overlayIconName().isEmpty())
m_cachedOverlayIcon = dbusImageList2QIcon(m_sniInter->overlayIconPixmap());
Q_EMIT overlayIconChanged();
});
connect(m_sniInter, &StatusNotifierItem::NewAttentionIcon, this, [this] {
if (m_ignoreFirstAttention) {
m_ignoreFirstAttention = false;
return;
}

if (m_sniInter->attentionIconName().isEmpty())
m_cachedAttentionIcon = dbusImageList2QIcon(m_sniInter->attentionIconPixmap());
Q_EMIT attentionIconChanged();
});

Expand Down Expand Up @@ -193,6 +200,8 @@ void SniTrayProtocolHandler::init()
generateId();
m_menuPath = m_sniInter->menu().path();
m_cachedIcon = dbusImageList2QIcon(m_sniInter->iconPixmap());
m_cachedAttentionIcon = dbusImageList2QIcon(m_sniInter->attentionIconPixmap());
m_cachedOverlayIcon = dbusImageList2QIcon(m_sniInter->overlayIconPixmap());
}

void SniTrayProtocolHandler::generateId()
Expand Down Expand Up @@ -261,8 +270,7 @@ QIcon SniTrayProtocolHandler::overlayIcon() const
return QIcon::fromTheme(iconName);
}

auto icon = dbusImageList2QIcon(m_sniInter->overlayIconPixmap());
return icon;
return m_cachedOverlayIcon;
}

QIcon SniTrayProtocolHandler::attentionIcon() const
Expand All @@ -272,8 +280,7 @@ QIcon SniTrayProtocolHandler::attentionIcon() const
return QIcon::fromTheme(iconName);
}

auto icon = dbusImageList2QIcon(m_sniInter->attentionIconPixmap());
return icon;
return m_cachedAttentionIcon;
}

QIcon SniTrayProtocolHandler::icon() const
Expand Down Expand Up @@ -356,18 +363,19 @@ QPair<QString, QString> SniTrayProtocolHandler::serviceAndPath(const QString &se
QIcon SniTrayProtocolHandler::dbusImageList2QIcon(const DBusImageList &dbusImageList)
{
QIcon res;
if (!dbusImageList.isEmpty() && !dbusImageList.first().pixels.isEmpty()) {
for (auto image = dbusImageList.begin(); image < dbusImageList.end(); image++) {
const char *image_data = image->pixels.data();
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
for (int i = 0; i < image->pixels.size(); i += 4) {
*(qint32 *)(image_data + i) = qFromBigEndian(*(qint32 *)(image_data + i));
}
}

QImage qimage((const uchar *)image->pixels.constData(), image->width, image->height, QImage::Format_ARGB32);
res.addPixmap(QPixmap::fromImage(qimage));
if (dbusImageList.isEmpty() || dbusImageList.first().pixels.isEmpty())
return res;

DBusImageList copy = dbusImageList;
for (auto &image : copy) {
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
quint32 *pixels = reinterpret_cast<quint32 *>(image.pixels.data());
for (int i = 0; i < image.pixels.size() / 4; i++)
pixels[i] = qFromBigEndian(pixels[i]);
}

QImage qimage(reinterpret_cast<const uchar *>(image.pixels.constData()), image.width, image.height, QImage::Format_ARGB32);
res.addPixmap(QPixmap::fromImage(qimage));
}

return res;
Expand Down
2 changes: 2 additions & 0 deletions plugins/application-tray/sniprotocolhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@ class SniTrayProtocolHandler : public AbstractTrayProtocolHandler
QString m_menuPath;
bool m_ignoreFirstAttention;
QIcon m_cachedIcon;
QIcon m_cachedAttentionIcon;
QIcon m_cachedOverlayIcon;
};
}
51 changes: 33 additions & 18 deletions plugins/application-tray/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
QRect Util::getX11WindowGeometry(const xcb_window_t& window) const
{
auto cookie = xcb_get_geometry(m_x11connection, window);
QSharedPointer<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(m_x11connection, cookie, nullptr));
QSharedPointer<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(m_x11connection, cookie, nullptr), [](xcb_get_geometry_reply_t* ptr){ free(ptr); });

return clientGeom ? QRect(clientGeom->x, clientGeom->y, clientGeom->width, clientGeom->height) : QRect();
}
Expand Down Expand Up @@ -236,26 +236,36 @@
xcb_flush(m_x11connection);
}

QImage Util::getX11WindowImageNonComposite(const xcb_window_t& window)

Check warning on line 239 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getX11WindowImageNonComposite' is never used.
{
QSize size = getX11WindowGeometry(window).size();
if (size.isEmpty()) {
return QImage();
}

xcb_image_t *image = xcb_image_get(m_x11connection, window, 0, 0, size.width(), size.height(), 0xFFFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);

QImage naiveConversion;
if (image) {
naiveConversion = QImage(image->data, image->width, image->height, QImage::Format_ARGB32);
} else {
if (!image) {
return QImage();
}

QImage naiveConversion(image->data, image->width, image->height, QImage::Format_ARGB32);
if (naiveConversion.isNull()) {
xcb_image_destroy(image);
return QImage();
}

if (isTransparentImage(naiveConversion)) {
QImage elaborateConversion = QImage(convertFromNative(image));
if (isTransparentImage(elaborateConversion)) {
return QImage();
} else
} else {
return elaborateConversion;
}
} else {
return QImage(image->data, image->width, image->height, image->stride, QImage::Format_ARGB32, clean_xcb_image, image);
QImage res = naiveConversion.copy();
xcb_image_destroy(image);
return res;
}
}

Expand Down Expand Up @@ -384,36 +394,41 @@
format = QImage::Format_ARGB32_Premultiplied;
break;
default:
xcb_image_destroy(xcbImage);
return QImage();
}

QImage image(xcbImage->data, xcbImage->width, xcbImage->height, xcbImage->stride, format, clean_xcb_image, xcbImage);
QImage image(xcbImage->data, xcbImage->width, xcbImage->height, xcbImage->stride, format);

if (image.isNull()) {
xcb_image_destroy(xcbImage);
Comment thread
yixinshark marked this conversation as resolved.
return QImage();
}

QImage deepCopy = image.copy();
xcb_image_destroy(xcbImage);

if (format == QImage::Format_RGB32 && xcbImage->bpp == 32) {
QImage m = image.createHeuristicMask();
QPixmap p = QPixmap::fromImage(std::move(image));
if (format == QImage::Format_RGB32 && deepCopy.depth() == 32) {
QImage m = deepCopy.createHeuristicMask();
QPixmap p = QPixmap::fromImage(std::move(deepCopy));
p.setMask(QBitmap::fromImage(std::move(m)));
image = p.toImage();
deepCopy = p.toImage();
}

if (image.format() == QImage::Format_MonoLSB) {
image.setColorCount(2);
image.setColor(0, QColor(Qt::white).rgb());
image.setColor(1, QColor(Qt::black).rgb());
if (deepCopy.format() == QImage::Format_MonoLSB) {
deepCopy.setColorCount(2);
deepCopy.setColor(0, QColor(Qt::white).rgb());
deepCopy.setColor(1, QColor(Qt::black).rgb());
}

return image;
return deepCopy;
}

QPoint Util::getMousePos() const

Check warning on line 427 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getMousePos' is never used.
{
QPoint pos;
xcb_query_pointer_cookie_t cookie = xcb_query_pointer(m_x11connection, m_rootWindow);
QScopedPointer<xcb_query_pointer_reply_t> reply(xcb_query_pointer_reply(m_x11connection, cookie, NULL));
QSharedPointer<xcb_query_pointer_reply_t> reply(xcb_query_pointer_reply(m_x11connection, cookie, NULL), [](xcb_query_pointer_reply_t* ptr){ free(ptr); });
if (reply) {
pos = QPoint(reply->root_x, reply->root_y);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/application-tray/xembedprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void XembedProtocolHandler::initX11resources()
xcb_flush(c);

auto waCookie = xcb_get_window_attributes(c, m_windowId);
QSharedPointer<xcb_get_window_attributes_reply_t> windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr));
QSharedPointer<xcb_get_window_attributes_reply_t> windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr), [](xcb_get_window_attributes_reply_t* ptr){ free(ptr); });
if (windowAttributes && !(windowAttributes->all_event_masks & XCB_EVENT_MASK_BUTTON_PRESS)) {
m_injectMode = XTest;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ void XembedProtocolHandler::sendClick(uint8_t qMouseButton)
auto dis = UTIL->getDisplay();

auto cookieSize = xcb_get_geometry(c, m_windowId);
QSharedPointer<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr));
QSharedPointer<xcb_get_geometry_reply_t> clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr), [](xcb_get_geometry_reply_t* ptr){ free(ptr); });

if (!clientGeom) {
return;
Expand Down
Loading