| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qsystemtrayicon_x11.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | static inline unsigned long locateSystemTray() | - | ||||||||||||
| 6 | { | - | ||||||||||||
| 7 | return never executed: (unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(([]() -> QByteArray { enum { Size = sizeof("traywindow") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "traywindow" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); returnreturn (unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(([]() -> QByteArray { enum { Size = sizeof("traywindow") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "traywindow" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()), QGuiApplication::primaryScreen());never executed: ba;return ba;never executed: }()), QGuiApplication::primaryScreen());return ba;never executed: return (unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(([]() -> QByteArray { enum { Size = sizeof("traywindow") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "traywindow" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()), QGuiApplication::primaryScreen()); | 0 | ||||||||||||
| 8 | } | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | - | |||||||||||||
| 11 | - | |||||||||||||
| 12 | class QSystemTrayIconSys : public QWidget | - | ||||||||||||
| 13 | { | - | ||||||||||||
| 14 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
| 15 | #pragma GCC diagnostic push | - | ||||||||||||
| 16 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
| 17 | #pragma GCC diagnostic pop | - | ||||||||||||
| 18 | struct QPrivateSignal {}; | - | ||||||||||||
| 19 | public: | - | ||||||||||||
| 20 | explicit QSystemTrayIconSys(QSystemTrayIcon *q); | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | inline void updateIcon() { update(); } never executed: end of block | 0 | ||||||||||||
| 23 | inline QSystemTrayIcon *systemTrayIcon() const { return never executed: q;return q;never executed: }return q; | 0 | ||||||||||||
| 24 | - | |||||||||||||
| 25 | QRect globalGeometry() const; | - | ||||||||||||
| 26 | - | |||||||||||||
| 27 | protected: | - | ||||||||||||
| 28 | virtual void mousePressEvent(QMouseEvent *ev) override; | - | ||||||||||||
| 29 | virtual void mouseDoubleClickEvent(QMouseEvent *ev) override; | - | ||||||||||||
| 30 | virtual bool event(QEvent *) override; | - | ||||||||||||
| 31 | virtual void paintEvent(QPaintEvent *) override; | - | ||||||||||||
| 32 | virtual void resizeEvent(QResizeEvent *) override; | - | ||||||||||||
| 33 | virtual void moveEvent(QMoveEvent *) override; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | private : | - | ||||||||||||
| 36 | void systemTrayWindowChanged(QScreen *screen); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | private: | - | ||||||||||||
| 39 | bool addToTray(); | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | QSystemTrayIcon *q; | - | ||||||||||||
| 42 | QPixmap background; | - | ||||||||||||
| 43 | }; | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn) | - | ||||||||||||
| 46 | : QWidget(0, Qt::Window | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint) | - | ||||||||||||
| 47 | , q(qIn) | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | setObjectName(([]() -> QString { enum { Size = sizeof(u"" "QSystemTrayIconSys")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "QSystemTrayIconSys" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }()));return qstring_literal_temp; | 0 | ||||||||||||
| 50 | setToolTip(q->toolTip()); | - | ||||||||||||
| 51 | setAttribute(Qt::WA_AlwaysShowToolTips, true); | - | ||||||||||||
| 52 | setAttribute(Qt::WA_QuitOnClose, false); | - | ||||||||||||
| 53 | const QSize size(22, 22); | - | ||||||||||||
| 54 | setGeometry(QRect(QPoint(0, 0), size)); | - | ||||||||||||
| 55 | setMinimumSize(size); | - | ||||||||||||
| 56 | bool hasAlphaChannel = QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannel(); | - | ||||||||||||
| 57 | setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel); | - | ||||||||||||
| 58 | if (!hasAlphaChannel
| 0 | ||||||||||||
| 59 | createWinId(); | - | ||||||||||||
| 60 | QXcbWindowFunctions::setParentRelativeBackPixmap(windowHandle()); | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | - | |||||||||||||
| 63 | - | |||||||||||||
| 64 | - | |||||||||||||
| 65 | - | |||||||||||||
| 66 | - | |||||||||||||
| 67 | - | |||||||||||||
| 68 | } never executed: end of block | 0 | ||||||||||||
| 69 | - | |||||||||||||
| 70 | addToTray(); | - | ||||||||||||
| 71 | } never executed: end of block | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | bool QSystemTrayIconSys::addToTray() | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | if (!locateSystemTray()
| 0 | ||||||||||||
| 76 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | createWinId(); | - | ||||||||||||
| 79 | setMouseTracking(true); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | if (!QXcbWindowFunctions::requestSystemTrayWindowDock(windowHandle())
| 0 | ||||||||||||
| 82 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 83 | - | |||||||||||||
| 84 | if (!background.isNull()
| 0 | ||||||||||||
| 85 | background = QPixmap(); never executed: background = QPixmap(); | 0 | ||||||||||||
| 86 | show(); | - | ||||||||||||
| 87 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 88 | } | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | void QSystemTrayIconSys::systemTrayWindowChanged(QScreen *) | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | if (locateSystemTray()
| 0 | ||||||||||||
| 93 | addToTray(); | - | ||||||||||||
| 94 | } never executed: else {end of block | 0 | ||||||||||||
| 95 | QBalloonTip::hideBalloon(); | - | ||||||||||||
| 96 | hide(); | - | ||||||||||||
| 97 | destroy(); | - | ||||||||||||
| 98 | } never executed: end of block | 0 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | QRect QSystemTrayIconSys::globalGeometry() const | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | return never executed: QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle());return QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle());never executed: return QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle()); | 0 | ||||||||||||
| 104 | } | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev) | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | QPoint globalPos = ev->globalPos(); | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | if (ev->button() == Qt::RightButton
| 0 | ||||||||||||
| 111 | q->contextMenu()->popup(globalPos); never executed: q->contextMenu()->popup(globalPos); | 0 | ||||||||||||
| 112 | - | |||||||||||||
| 113 | - | |||||||||||||
| 114 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 115 | q->messageClicked(); | - | ||||||||||||
| 116 | QBalloonTip::hideBalloon(); | - | ||||||||||||
| 117 | } never executed: end of block | 0 | ||||||||||||
| 118 | - | |||||||||||||
| 119 | if (ev->button() == Qt::LeftButton
| 0 | ||||||||||||
| 120 | q->activated(QSystemTrayIcon::Trigger); never executed: q->activated(QSystemTrayIcon::Trigger); | 0 | ||||||||||||
| 121 | else if (ev->button() == Qt::RightButton
| 0 | ||||||||||||
| 122 | q->activated(QSystemTrayIcon::Context); never executed: q->activated(QSystemTrayIcon::Context); | 0 | ||||||||||||
| 123 | else if (ev->button() == Qt::MidButton
| 0 | ||||||||||||
| 124 | q->activated(QSystemTrayIcon::MiddleClick); never executed: q->activated(QSystemTrayIcon::MiddleClick); | 0 | ||||||||||||
| 125 | } never executed: end of block | 0 | ||||||||||||
| 126 | - | |||||||||||||
| 127 | void QSystemTrayIconSys::mouseDoubleClickEvent(QMouseEvent *ev) | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | if (ev->button() == Qt::LeftButton
| 0 | ||||||||||||
| 130 | q->activated(QSystemTrayIcon::DoubleClick); never executed: q->activated(QSystemTrayIcon::DoubleClick); | 0 | ||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||
| 132 | - | |||||||||||||
| 133 | bool QSystemTrayIconSys::event(QEvent *e) | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | switch (e->type()) { | - | ||||||||||||
| 136 | case never executed: QEvent::ToolTip:case QEvent::ToolTip:never executed: case QEvent::ToolTip: | 0 | ||||||||||||
| 137 | QApplication::sendEvent(q, e); | - | ||||||||||||
| 138 | break; never executed: break; | 0 | ||||||||||||
| 139 | - | |||||||||||||
| 140 | case never executed: QEvent::Wheel:case QEvent::Wheel:never executed: case QEvent::Wheel: | 0 | ||||||||||||
| 141 | return never executed: QApplication::sendEvent(q, e);return QApplication::sendEvent(q, e);never executed: return QApplication::sendEvent(q, e); | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 144 | break; never executed: break; | 0 | ||||||||||||
| 145 | } | - | ||||||||||||
| 146 | return never executed: QWidget::event(e);return QWidget::event(e);never executed: return QWidget::event(e); | 0 | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | void QSystemTrayIconSys::paintEvent(QPaintEvent *) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | const QRect rect(QPoint(0, 0), geometry().size()); | - | ||||||||||||
| 152 | QPainter painter(this); | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | - | |||||||||||||
| 155 | - | |||||||||||||
| 156 | if (testAttribute(Qt::WA_TranslucentBackground)
| 0 | ||||||||||||
| 157 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
| 158 | painter.fillRect(rect, Qt::transparent); | - | ||||||||||||
| 159 | } never executed: else {end of block | 0 | ||||||||||||
| 160 | - | |||||||||||||
| 161 | - | |||||||||||||
| 162 | if (background.isNull()
| 0 | ||||||||||||
| 163 | background = QGuiApplication::primaryScreen()->grabWindow(winId(), | - | ||||||||||||
| 164 | 0, 0, rect.size().width(), rect.size().height()); | - | ||||||||||||
| 165 | } never executed: end of block | 0 | ||||||||||||
| 166 | - | |||||||||||||
| 167 | painter.drawPixmap(QPoint(0, 0), background); | - | ||||||||||||
| 168 | } never executed: end of block | 0 | ||||||||||||
| 169 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | - | ||||||||||||
| 170 | q->icon().paint(&painter, rect); | - | ||||||||||||
| 171 | } never executed: end of block | 0 | ||||||||||||
| 172 | - | |||||||||||||
| 173 | void QSystemTrayIconSys::moveEvent(QMoveEvent *event) | - | ||||||||||||
| 174 | { | - | ||||||||||||
| 175 | QWidget::moveEvent(event); | - | ||||||||||||
| 176 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 177 | QBalloonTip::updateBalloonPosition(globalGeometry().center()); never executed: QBalloonTip::updateBalloonPosition(globalGeometry().center()); | 0 | ||||||||||||
| 178 | } never executed: end of block | 0 | ||||||||||||
| 179 | - | |||||||||||||
| 180 | void QSystemTrayIconSys::resizeEvent(QResizeEvent *event) | - | ||||||||||||
| 181 | { | - | ||||||||||||
| 182 | update(); | - | ||||||||||||
| 183 | QWidget::resizeEvent(event); | - | ||||||||||||
| 184 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 185 | QBalloonTip::updateBalloonPosition(globalGeometry().center()); never executed: QBalloonTip::updateBalloonPosition(globalGeometry().center()); | 0 | ||||||||||||
| 186 | } never executed: end of block | 0 | ||||||||||||
| 187 | - | |||||||||||||
| 188 | - | |||||||||||||
| 189 | QSystemTrayIconPrivate::QSystemTrayIconPrivate() | - | ||||||||||||
| 190 | : sys(0), | - | ||||||||||||
| 191 | qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()), | - | ||||||||||||
| 192 | visible(false) | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||
| 195 | - | |||||||||||||
| 196 | QSystemTrayIconPrivate::~QSystemTrayIconPrivate() | - | ||||||||||||
| 197 | { | - | ||||||||||||
| 198 | delete qpa_sys; | - | ||||||||||||
| 199 | } never executed: end of block | 0 | ||||||||||||
| 200 | - | |||||||||||||
| 201 | void QSystemTrayIconPrivate::install_sys() | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 | if (qpa_sys
| 0 | ||||||||||||
| 204 | install_sys_qpa(); | - | ||||||||||||
| 205 | return; never executed: return; | 0 | ||||||||||||
| 206 | } | - | ||||||||||||
| 207 | QSystemTrayIcon * const q = q_func(); | - | ||||||||||||
| 208 | if (!sys
| 0 | ||||||||||||
| 209 | sys = new QSystemTrayIconSys(q); | - | ||||||||||||
| 210 | QObject::connect(QGuiApplication::platformNativeInterface(), qFlagLocation("2""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "271"), | - | ||||||||||||
| 211 | sys, qFlagLocation("1""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "272")); | - | ||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | QRect QSystemTrayIconPrivate::geometry_sys() const | - | ||||||||||||
| 216 | { | - | ||||||||||||
| 217 | if (qpa_sys
| 0 | ||||||||||||
| 218 | return never executed: geometry_sys_qpa();return geometry_sys_qpa();never executed: return geometry_sys_qpa(); | 0 | ||||||||||||
| 219 | if (!sys
| 0 | ||||||||||||
| 220 | return never executed: QRect();return QRect();never executed: return QRect(); | 0 | ||||||||||||
| 221 | return never executed: sys->globalGeometry();return sys->globalGeometry();never executed: return sys->globalGeometry(); | 0 | ||||||||||||
| 222 | } | - | ||||||||||||
| 223 | - | |||||||||||||
| 224 | void QSystemTrayIconPrivate::remove_sys() | - | ||||||||||||
| 225 | { | - | ||||||||||||
| 226 | if (qpa_sys
| 0 | ||||||||||||
| 227 | remove_sys_qpa(); | - | ||||||||||||
| 228 | return; never executed: return; | 0 | ||||||||||||
| 229 | } | - | ||||||||||||
| 230 | if (!sys
| 0 | ||||||||||||
| 231 | return; never executed: return; | 0 | ||||||||||||
| 232 | QBalloonTip::hideBalloon(); | - | ||||||||||||
| 233 | sys->hide(); | - | ||||||||||||
| 234 | delete sys; | - | ||||||||||||
| 235 | sys = 0; | - | ||||||||||||
| 236 | } never executed: end of block | 0 | ||||||||||||
| 237 | - | |||||||||||||
| 238 | void QSystemTrayIconPrivate::updateIcon_sys() | - | ||||||||||||
| 239 | { | - | ||||||||||||
| 240 | if (qpa_sys
| 0 | ||||||||||||
| 241 | updateIcon_sys_qpa(); | - | ||||||||||||
| 242 | return; never executed: return; | 0 | ||||||||||||
| 243 | } | - | ||||||||||||
| 244 | if (sys
| 0 | ||||||||||||
| 245 | sys->updateIcon(); never executed: sys->updateIcon(); | 0 | ||||||||||||
| 246 | } never executed: end of block | 0 | ||||||||||||
| 247 | - | |||||||||||||
| 248 | void QSystemTrayIconPrivate::updateMenu_sys() | - | ||||||||||||
| 249 | { | - | ||||||||||||
| 250 | if (qpa_sys
| 0 | ||||||||||||
| 251 | updateMenu_sys_qpa(); never executed: updateMenu_sys_qpa(); | 0 | ||||||||||||
| 252 | } never executed: end of block | 0 | ||||||||||||
| 253 | - | |||||||||||||
| 254 | void QSystemTrayIconPrivate::updateToolTip_sys() | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | if (qpa_sys
| 0 | ||||||||||||
| 257 | updateToolTip_sys_qpa(); | - | ||||||||||||
| 258 | return; never executed: return; | 0 | ||||||||||||
| 259 | } | - | ||||||||||||
| 260 | if (!sys
| 0 | ||||||||||||
| 261 | return; never executed: return; | 0 | ||||||||||||
| 262 | - | |||||||||||||
| 263 | sys->setToolTip(toolTip); | - | ||||||||||||
| 264 | - | |||||||||||||
| 265 | } never executed: end of block | 0 | ||||||||||||
| 266 | - | |||||||||||||
| 267 | bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() | - | ||||||||||||
| 268 | { | - | ||||||||||||
| 269 | QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()); | - | ||||||||||||
| 270 | if (sys
| 0 | ||||||||||||
| 271 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 272 | - | |||||||||||||
| 273 | - | |||||||||||||
| 274 | const QString platform = QGuiApplication::platformName(); | - | ||||||||||||
| 275 | if (platform.compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0
| 0 | ||||||||||||
| 276 | return never executed: locateSystemTray();return locateSystemTray();never executed: return locateSystemTray(); | 0 | ||||||||||||
| 277 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 278 | } | - | ||||||||||||
| 279 | - | |||||||||||||
| 280 | bool QSystemTrayIconPrivate::supportsMessages_sys() | - | ||||||||||||
| 281 | { | - | ||||||||||||
| 282 | QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()); | - | ||||||||||||
| 283 | if (sys
| 0 | ||||||||||||
| 284 | return never executed: sys->supportsMessages();return sys->supportsMessages();never executed: return sys->supportsMessages(); | 0 | ||||||||||||
| 285 | - | |||||||||||||
| 286 | - | |||||||||||||
| 287 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 288 | } | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, | - | ||||||||||||
| 291 | QSystemTrayIcon::MessageIcon icon, int msecs) | - | ||||||||||||
| 292 | { | - | ||||||||||||
| 293 | if (qpa_sys
| 0 | ||||||||||||
| 294 | showMessage_sys_qpa(title, message, icon, msecs); | - | ||||||||||||
| 295 | return; never executed: return; | 0 | ||||||||||||
| 296 | } | - | ||||||||||||
| 297 | if (!sys
| 0 | ||||||||||||
| 298 | return; never executed: return; | 0 | ||||||||||||
| 299 | QBalloonTip::showBalloon(icon, title, message, sys->systemTrayIcon(), | - | ||||||||||||
| 300 | sys->globalGeometry().center(), | - | ||||||||||||
| 301 | msecs); | - | ||||||||||||
| 302 | } never executed: end of block | 0 | ||||||||||||
| 303 | - | |||||||||||||
| 304 | - | |||||||||||||
| 305 | - | |||||||||||||
| Switch to Source code | Preprocessed file |