| 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 | - | |||||||||||||
| 115 | - | |||||||||||||
| 116 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 117 | q->messageClicked(); | - | ||||||||||||
| 118 | QBalloonTip::hideBalloon(); | - | ||||||||||||
| 119 | } never executed: end of block | 0 | ||||||||||||
| 120 | - | |||||||||||||
| 121 | if (ev->button() == Qt::LeftButton
| 0 | ||||||||||||
| 122 | q->activated(QSystemTrayIcon::Trigger); never executed: q->activated(QSystemTrayIcon::Trigger); | 0 | ||||||||||||
| 123 | else if (ev->button() == Qt::RightButton
| 0 | ||||||||||||
| 124 | q->activated(QSystemTrayIcon::Context); never executed: q->activated(QSystemTrayIcon::Context); | 0 | ||||||||||||
| 125 | else if (ev->button() == Qt::MidButton
| 0 | ||||||||||||
| 126 | q->activated(QSystemTrayIcon::MiddleClick); never executed: q->activated(QSystemTrayIcon::MiddleClick); | 0 | ||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | void QSystemTrayIconSys::mouseDoubleClickEvent(QMouseEvent *ev) | - | ||||||||||||
| 130 | { | - | ||||||||||||
| 131 | if (ev->button() == Qt::LeftButton
| 0 | ||||||||||||
| 132 | q->activated(QSystemTrayIcon::DoubleClick); never executed: q->activated(QSystemTrayIcon::DoubleClick); | 0 | ||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||
| 134 | - | |||||||||||||
| 135 | bool QSystemTrayIconSys::event(QEvent *e) | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | switch (e->type()) { | - | ||||||||||||
| 138 | case never executed: QEvent::ToolTip:case QEvent::ToolTip:never executed: case QEvent::ToolTip: | 0 | ||||||||||||
| 139 | QApplication::sendEvent(q, e); | - | ||||||||||||
| 140 | break; never executed: break; | 0 | ||||||||||||
| 141 | - | |||||||||||||
| 142 | case never executed: QEvent::Wheel:case QEvent::Wheel:never executed: case QEvent::Wheel: | 0 | ||||||||||||
| 143 | return never executed: QApplication::sendEvent(q, e);return QApplication::sendEvent(q, e);never executed: return QApplication::sendEvent(q, e); | 0 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | default never executed: :default:never executed: default: | 0 | ||||||||||||
| 146 | break; never executed: break; | 0 | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | return never executed: QWidget::event(e);return QWidget::event(e);never executed: return QWidget::event(e); | 0 | ||||||||||||
| 149 | } | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | void QSystemTrayIconSys::paintEvent(QPaintEvent *) | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | const QRect rect(QPoint(0, 0), geometry().size()); | - | ||||||||||||
| 154 | QPainter painter(this); | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| 157 | - | |||||||||||||
| 158 | if (testAttribute(Qt::WA_TranslucentBackground)
| 0 | ||||||||||||
| 159 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
| 160 | painter.fillRect(rect, Qt::transparent); | - | ||||||||||||
| 161 | } never executed: else {end of block | 0 | ||||||||||||
| 162 | - | |||||||||||||
| 163 | - | |||||||||||||
| 164 | if (background.isNull()
| 0 | ||||||||||||
| 165 | background = QGuiApplication::primaryScreen()->grabWindow(winId(), | - | ||||||||||||
| 166 | 0, 0, rect.size().width(), rect.size().height()); | - | ||||||||||||
| 167 | } never executed: end of block | 0 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | painter.drawPixmap(QPoint(0, 0), background); | - | ||||||||||||
| 170 | } never executed: end of block | 0 | ||||||||||||
| 171 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | - | ||||||||||||
| 172 | q->icon().paint(&painter, rect); | - | ||||||||||||
| 173 | } never executed: end of block | 0 | ||||||||||||
| 174 | - | |||||||||||||
| 175 | void QSystemTrayIconSys::moveEvent(QMoveEvent *event) | - | ||||||||||||
| 176 | { | - | ||||||||||||
| 177 | QWidget::moveEvent(event); | - | ||||||||||||
| 178 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 179 | QBalloonTip::updateBalloonPosition(globalGeometry().center()); never executed: QBalloonTip::updateBalloonPosition(globalGeometry().center()); | 0 | ||||||||||||
| 180 | } never executed: end of block | 0 | ||||||||||||
| 181 | - | |||||||||||||
| 182 | void QSystemTrayIconSys::resizeEvent(QResizeEvent *event) | - | ||||||||||||
| 183 | { | - | ||||||||||||
| 184 | update(); | - | ||||||||||||
| 185 | QWidget::resizeEvent(event); | - | ||||||||||||
| 186 | if (QBalloonTip::isBalloonVisible()
| 0 | ||||||||||||
| 187 | QBalloonTip::updateBalloonPosition(globalGeometry().center()); never executed: QBalloonTip::updateBalloonPosition(globalGeometry().center()); | 0 | ||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | - | |||||||||||||
| 191 | QSystemTrayIconPrivate::QSystemTrayIconPrivate() | - | ||||||||||||
| 192 | : sys(0), | - | ||||||||||||
| 193 | qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()), | - | ||||||||||||
| 194 | visible(false) | - | ||||||||||||
| 195 | { | - | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | - | |||||||||||||
| 198 | QSystemTrayIconPrivate::~QSystemTrayIconPrivate() | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | delete qpa_sys; | - | ||||||||||||
| 201 | } never executed: end of block | 0 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | void QSystemTrayIconPrivate::install_sys() | - | ||||||||||||
| 204 | { | - | ||||||||||||
| 205 | if (qpa_sys
| 0 | ||||||||||||
| 206 | install_sys_qpa(); | - | ||||||||||||
| 207 | return; never executed: return; | 0 | ||||||||||||
| 208 | } | - | ||||||||||||
| 209 | QSystemTrayIcon * const q = q_func(); | - | ||||||||||||
| 210 | if (!sys
| 0 | ||||||||||||
| 211 | sys = new QSystemTrayIconSys(q); | - | ||||||||||||
| 212 | QObject::connect(QGuiApplication::platformNativeInterface(), qFlagLocation("2""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "279"), | - | ||||||||||||
| 213 | sys, qFlagLocation("1""systemTrayWindowChanged(QScreen*)" "\0" __FILE__ ":" "280")); | - | ||||||||||||
| 214 | } never executed: end of block | 0 | ||||||||||||
| 215 | } never executed: end of block | 0 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | QRect QSystemTrayIconPrivate::geometry_sys() const | - | ||||||||||||
| 218 | { | - | ||||||||||||
| 219 | if (qpa_sys
| 0 | ||||||||||||
| 220 | return never executed: geometry_sys_qpa();return geometry_sys_qpa();never executed: return geometry_sys_qpa(); | 0 | ||||||||||||
| 221 | if (!sys
| 0 | ||||||||||||
| 222 | return never executed: QRect();return QRect();never executed: return QRect(); | 0 | ||||||||||||
| 223 | return never executed: sys->globalGeometry();return sys->globalGeometry();never executed: return sys->globalGeometry(); | 0 | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | void QSystemTrayIconPrivate::remove_sys() | - | ||||||||||||
| 227 | { | - | ||||||||||||
| 228 | if (qpa_sys
| 0 | ||||||||||||
| 229 | remove_sys_qpa(); | - | ||||||||||||
| 230 | return; never executed: return; | 0 | ||||||||||||
| 231 | } | - | ||||||||||||
| 232 | if (!sys
| 0 | ||||||||||||
| 233 | return; never executed: return; | 0 | ||||||||||||
| 234 | QBalloonTip::hideBalloon(); | - | ||||||||||||
| 235 | sys->hide(); | - | ||||||||||||
| 236 | delete sys; | - | ||||||||||||
| 237 | sys = 0; | - | ||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||
| 239 | - | |||||||||||||
| 240 | void QSystemTrayIconPrivate::updateIcon_sys() | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 | if (qpa_sys
| 0 | ||||||||||||
| 243 | updateIcon_sys_qpa(); | - | ||||||||||||
| 244 | return; never executed: return; | 0 | ||||||||||||
| 245 | } | - | ||||||||||||
| 246 | if (sys
| 0 | ||||||||||||
| 247 | sys->updateIcon(); never executed: sys->updateIcon(); | 0 | ||||||||||||
| 248 | } never executed: end of block | 0 | ||||||||||||
| 249 | - | |||||||||||||
| 250 | void QSystemTrayIconPrivate::updateMenu_sys() | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | if (qpa_sys
| 0 | ||||||||||||
| 253 | updateMenu_sys_qpa(); never executed: updateMenu_sys_qpa(); | 0 | ||||||||||||
| 254 | } never executed: end of block | 0 | ||||||||||||
| 255 | - | |||||||||||||
| 256 | void QSystemTrayIconPrivate::updateToolTip_sys() | - | ||||||||||||
| 257 | { | - | ||||||||||||
| 258 | if (qpa_sys
| 0 | ||||||||||||
| 259 | updateToolTip_sys_qpa(); | - | ||||||||||||
| 260 | return; never executed: return; | 0 | ||||||||||||
| 261 | } | - | ||||||||||||
| 262 | if (!sys
| 0 | ||||||||||||
| 263 | return; never executed: return; | 0 | ||||||||||||
| 264 | - | |||||||||||||
| 265 | sys->setToolTip(toolTip); | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | } never executed: end of block | 0 | ||||||||||||
| 268 | - | |||||||||||||
| 269 | bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() | - | ||||||||||||
| 270 | { | - | ||||||||||||
| 271 | QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()); | - | ||||||||||||
| 272 | if (sys
| 0 | ||||||||||||
| 273 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 274 | - | |||||||||||||
| 275 | - | |||||||||||||
| 276 | const QString platform = QGuiApplication::platformName(); | - | ||||||||||||
| 277 | if (platform.compare(QLatin1String("xcb"), Qt::CaseInsensitive) == 0
| 0 | ||||||||||||
| 278 | return never executed: locateSystemTray();return locateSystemTray();never executed: return locateSystemTray(); | 0 | ||||||||||||
| 279 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 280 | } | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | bool QSystemTrayIconPrivate::supportsMessages_sys() | - | ||||||||||||
| 283 | { | - | ||||||||||||
| 284 | QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()); | - | ||||||||||||
| 285 | if (sys
| 0 | ||||||||||||
| 286 | return never executed: sys->supportsMessages();return sys->supportsMessages();never executed: return sys->supportsMessages(); | 0 | ||||||||||||
| 287 | - | |||||||||||||
| 288 | - | |||||||||||||
| 289 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 290 | } | - | ||||||||||||
| 291 | - | |||||||||||||
| 292 | void QSystemTrayIconPrivate::showMessage_sys(const QString &title, const QString &message, | - | ||||||||||||
| 293 | QSystemTrayIcon::MessageIcon icon, int msecs) | - | ||||||||||||
| 294 | { | - | ||||||||||||
| 295 | if (qpa_sys
| 0 | ||||||||||||
| 296 | showMessage_sys_qpa(title, message, icon, msecs); | - | ||||||||||||
| 297 | return; never executed: return; | 0 | ||||||||||||
| 298 | } | - | ||||||||||||
| 299 | if (!sys
| 0 | ||||||||||||
| 300 | return; never executed: return; | 0 | ||||||||||||
| 301 | QBalloonTip::showBalloon(icon, title, message, sys->systemTrayIcon(), | - | ||||||||||||
| 302 | sys->globalGeometry().center(), | - | ||||||||||||
| 303 | msecs); | - | ||||||||||||
| 304 | } never executed: end of block | 0 | ||||||||||||
| 305 | - | |||||||||||||
| 306 | - | |||||||||||||
| 307 | - | |||||||||||||
| Switch to Source code | Preprocessed file |