diff options
Diffstat (limited to 'src/widgets/util/qsystemtrayicon_x11.cpp')
-rw-r--r-- | src/widgets/util/qsystemtrayicon_x11.cpp | 70 |
1 files changed, 4 insertions, 66 deletions
diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index df93e15f80..86532456c7 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -63,8 +63,6 @@ #include <private/qguiapplication_p.h> #include <qdebug.h> -#include <QtPlatformHeaders/qxcbwindowfunctions.h> -#include <QtPlatformHeaders/qxcbintegrationfunctions.h> #ifndef QT_NO_SYSTEMTRAYICON QT_BEGIN_NAMESPACE @@ -98,10 +96,7 @@ private slots: void systemTrayWindowChanged(QScreen *screen); private: - bool addToTray(); - QSystemTrayIcon *q; - QPixmap background; }; QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn) @@ -117,55 +112,13 @@ QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn) const QSize size(22, 22); // Gnome, standard size setGeometry(QRect(QPoint(0, 0), size)); setMinimumSize(size); - - // We need two different behaviors depending on whether the X11 visual for the system tray - // (a) exists and (b) supports an alpha channel, i.e. is 32 bits. - // If we have a visual that has an alpha channel, we can paint this widget with a transparent - // background and it will work. - // However, if there's no alpha channel visual, in order for transparent tray icons to work, - // we do not have a transparent background on the widget, but set the BackPixmap property of our - // window to ParentRelative (so that it inherits the background of its X11 parent window), call - // xcb_clear_region before painting (so that the inherited background is visible) and then grab - // the just-drawn background from the X11 server. - bool hasAlphaChannel = QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannel(); - setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel); - if (!hasAlphaChannel) { - createWinId(); - QXcbWindowFunctions::setParentRelativeBackPixmap(windowHandle()); - - // XXX: This is actually required, but breaks things ("QWidget::paintEngine: Should no - // longer be called"). Why is this needed? When the widget is drawn, we use tricks to grab - // the tray icon's background from the server. If the tray icon isn't visible (because - // another window is on top of it), the trick fails and instead uses the content of that - // other window as the background. - // setAttribute(Qt::WA_PaintOnScreen); - } - - addToTray(); -} - -bool QSystemTrayIconSys::addToTray() -{ - if (!locateSystemTray()) - return false; - - createWinId(); + setAttribute(Qt::WA_TranslucentBackground); setMouseTracking(true); - - if (!QXcbWindowFunctions::requestSystemTrayWindowDock(windowHandle())) - return false; - - if (!background.isNull()) - background = QPixmap(); - show(); - return true; } void QSystemTrayIconSys::systemTrayWindowChanged(QScreen *) { - if (locateSystemTray()) { - addToTray(); - } else { + if (!locateSystemTray()) { QBalloonTip::hideBalloon(); hide(); // still no luck destroy(); @@ -174,7 +127,7 @@ void QSystemTrayIconSys::systemTrayWindowChanged(QScreen *) QRect QSystemTrayIconSys::globalGeometry() const { - return QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle()); + return QRect(mapToGlobal(QPoint(0, 0)), size()); } void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev) @@ -227,22 +180,6 @@ void QSystemTrayIconSys::paintEvent(QPaintEvent *) const QRect rect(QPoint(0, 0), geometry().size()); QPainter painter(this); - // If we have Qt::WA_TranslucentBackground set, during widget creation - // we detected the systray visual supported an alpha channel - if (testAttribute(Qt::WA_TranslucentBackground)) { - painter.setCompositionMode(QPainter::CompositionMode_Source); - painter.fillRect(rect, Qt::transparent); - } else { - // clearRegion() was called on XEMBED_EMBEDDED_NOTIFY, so we hope that got done by now. - // Grab the tray background pixmap, before rendering the icon for the first time. - if (background.isNull()) { - background = QGuiApplication::primaryScreen()->grabWindow(winId(), - 0, 0, rect.size().width(), rect.size().height()); - } - // Then paint over the icon area with the background before compositing the icon on top. - painter.drawPixmap(QPoint(0, 0), background); - } - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); q->icon().paint(&painter, rect); } @@ -285,6 +222,7 @@ void QSystemTrayIconPrivate::install_sys() sys = new QSystemTrayIconSys(q); QObject::connect(QGuiApplication::platformNativeInterface(), SIGNAL(systemTrayWindowChanged(QScreen*)), sys, SLOT(systemTrayWindowChanged(QScreen*))); + sys->show(); } } |