Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | enum { | - |
7 | SYSTEM_TRAY_REQUEST_DOCK = 0, | - |
8 | SYSTEM_TRAY_BEGIN_MESSAGE = 1, | - |
9 | SYSTEM_TRAY_CANCEL_MESSAGE =2 | - |
10 | }; | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | class QX11SystemTrayContext | - |
19 | { | - |
20 | public: | - |
21 | QX11SystemTrayContext(); | - |
22 | ~QX11SystemTrayContext(); | - |
23 | | - |
24 | bool isValid() const { return m_systemTraySelection != 0; } executed: return m_systemTraySelection != 0; Execution Count:6 | 6 |
25 | | - |
26 | inline Display *display() const { return m_display; } executed: return m_display; Execution Count:15 | 15 |
27 | inline int screenNumber() const { return m_screenNumber; } executed: return m_screenNumber; Execution Count:4 | 4 |
28 | Window locateSystemTray() const; | - |
29 | | - |
30 | private: | - |
31 | Display *m_display; | - |
32 | int m_screenNumber; | - |
33 | Atom m_systemTraySelection; | - |
34 | }; | - |
35 | | - |
36 | QX11SystemTrayContext::QX11SystemTrayContext() : m_display(0), m_screenNumber(0), m_systemTraySelection(0) | - |
37 | { | - |
38 | QScreen *screen = QGuiApplication::primaryScreen(); | - |
39 | if (!screen) { partially evaluated: !screen no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
40 | QMessageLogger("util/qsystemtrayicon_x11.cpp", 102, __PRETTY_FUNCTION__).warning("%s: No screen.", __PRETTY_FUNCTION__); | - |
41 | return; | 0 |
42 | } | - |
43 | void *displayV = QGuiApplication::platformNativeInterface()->nativeResourceForScreen(QByteArray("display", sizeof("display") - 1), screen); | - |
44 | if (!displayV) { partially evaluated: !displayV no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
45 | QMessageLogger("util/qsystemtrayicon_x11.cpp", 107, __PRETTY_FUNCTION__).warning("%s: Unable to obtain X11 display of primary screen.", __PRETTY_FUNCTION__); | - |
46 | return; | 0 |
47 | } | - |
48 | | - |
49 | m_display = static_cast<Display *>(displayV); | - |
50 | | - |
51 | const QByteArray netSysTray = "_NET_SYSTEM_TRAY_S" + QByteArray::number(m_screenNumber); | - |
52 | m_systemTraySelection = XInternAtom(m_display, netSysTray.constData(), 0); | - |
53 | if (!m_systemTraySelection) { partially evaluated: !m_systemTraySelection no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
54 | QMessageLogger("util/qsystemtrayicon_x11.cpp", 116, __PRETTY_FUNCTION__).warning("%s: Unable to retrieve atom '%s'.", __PRETTY_FUNCTION__, netSysTray.constData()); | - |
55 | return; | 0 |
56 | } | - |
57 | } executed: } Execution Count:1 | 1 |
58 | | - |
59 | Window QX11SystemTrayContext::locateSystemTray() const | - |
60 | { | - |
61 | if (isValid()) partially evaluated: isValid() yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
62 | return XGetSelectionOwner(m_display, m_systemTraySelection); executed: return XGetSelectionOwner(m_display, m_systemTraySelection); Execution Count:3 | 3 |
63 | return 0; never executed: return 0; | 0 |
64 | } | - |
65 | | - |
66 | QX11SystemTrayContext::~QX11SystemTrayContext() | - |
67 | { | - |
68 | } | - |
69 | | - |
70 | static QX11SystemTrayContext *qX11SystemTrayContext() { static QGlobalStatic<QX11SystemTrayContext > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QX11SystemTrayContext *x = new QX11SystemTrayContext; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QX11SystemTrayContext > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); } executed: return thisGlobalStatic.pointer.load(); Execution Count:10 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:1 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:1 | yes Evaluation Count:9 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:1 | no Evaluation Count:0 |
never executed: delete x; | 0-10 |
71 | | - |
72 | | - |
73 | | - |
74 | class QSystemTrayIconSys : public QWidget | - |
75 | { | - |
76 | public: | - |
77 | explicit QSystemTrayIconSys(QSystemTrayIcon *q); | - |
78 | | - |
79 | inline void updateIcon() { update(); } executed: } Execution Count:1 | 1 |
80 | inline QSystemTrayIcon *systemTrayIcon() const { return q; } executed: return q; Execution Count:4 | 4 |
81 | | - |
82 | QRect globalGeometry() const; | - |
83 | | - |
84 | protected: | - |
85 | virtual void mousePressEvent(QMouseEvent *ev); | - |
86 | virtual void mouseDoubleClickEvent(QMouseEvent *ev); | - |
87 | virtual bool event(QEvent *); | - |
88 | virtual void paintEvent(QPaintEvent *); | - |
89 | | - |
90 | private: | - |
91 | QSystemTrayIcon *q; | - |
92 | }; | - |
93 | | - |
94 | QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn) : | - |
95 | q(qIn) | - |
96 | { | - |
97 | setToolTip(q->toolTip()); | - |
98 | QX11SystemTrayContext *context = qX11SystemTrayContext(); | - |
99 | qt_noop(); | - |
100 | setAttribute(Qt::WA_AlwaysShowToolTips, true); | - |
101 | setAttribute(Qt::WA_TranslucentBackground, true); | - |
102 | setAttribute(Qt::WA_QuitOnClose, false); | - |
103 | setWindowFlags(Qt::Window | Qt::FramelessWindowHint); | - |
104 | const QSize size(22, 22); | - |
105 | setGeometry(QRect(QPoint(0, 0), size)); | - |
106 | setMinimumSize(size); | - |
107 | createWinId(); | - |
108 | setMouseTracking(true); | - |
109 | | - |
110 | Display *display = context->display(); | - |
111 | | - |
112 | | - |
113 | static Atom netwm_tray_atom = XInternAtom(display, "_NET_SYSTEM_TRAY_OPCODE", 0); | - |
114 | long l[5] = { 0L, SYSTEM_TRAY_REQUEST_DOCK, static_cast<long>(winId()), 0, 0 }; | - |
115 | XEvent ev; | - |
116 | memset(&ev, 0, sizeof(ev)); | - |
117 | ev.xclient.type = 33; | - |
118 | ev.xclient.window = context->locateSystemTray(); | - |
119 | ev.xclient.message_type = netwm_tray_atom; | - |
120 | ev.xclient.format = 32; | - |
121 | memcpy((char *)&ev.xclient.data, (const char *) l, sizeof(l)); | - |
122 | XSendEvent(display, ev.xclient.window, 0, 0, &ev); | - |
123 | XSync(display, 0); | - |
124 | show(); | - |
125 | } executed: } Execution Count:3 | 3 |
126 | | - |
127 | QRect QSystemTrayIconSys::globalGeometry() const | - |
128 | { | - |
129 | QX11SystemTrayContext *context = qX11SystemTrayContext(); | - |
130 | ::Window dummy; | - |
131 | int x, y, rootX, rootY; | - |
132 | unsigned int width, height, border, depth; | - |
133 | | - |
134 | XGetGeometry(context->display(), winId(), &dummy, &x, &y, &width, &height, &border, &depth); | - |
135 | XTranslateCoordinates(context->display(), winId(), | - |
136 | XRootWindow(context->display(), context->screenNumber()), | - |
137 | x, y, &rootX, &rootY, &dummy); | - |
138 | return QRect(QPoint(rootX, rootY), QSize(width, height)); executed: return QRect(QPoint(rootX, rootY), QSize(width, height)); Execution Count:4 | 4 |
139 | } | - |
140 | | - |
141 | | - |
142 | void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev) | - |
143 | { | - |
144 | QPoint globalPos = ev->globalPos(); | - |
145 | | - |
146 | if (ev->button() == Qt::RightButton && q->contextMenu()) never evaluated: ev->button() == Qt::RightButton never evaluated: q->contextMenu() | 0 |
147 | q->contextMenu()->popup(globalPos); never executed: q->contextMenu()->popup(globalPos); | 0 |
148 | | - |
149 | | - |
150 | if (QBalloonTip::isBalloonVisible()) { never evaluated: QBalloonTip::isBalloonVisible() | 0 |
151 | q->messageClicked(); | - |
152 | QBalloonTip::hideBalloon(); | - |
153 | } | 0 |
154 | | - |
155 | if (ev->button() == Qt::LeftButton) never evaluated: ev->button() == Qt::LeftButton | 0 |
156 | q->activated(QSystemTrayIcon::Trigger); never executed: q->activated(QSystemTrayIcon::Trigger); | 0 |
157 | else if (ev->button() == Qt::RightButton) never evaluated: ev->button() == Qt::RightButton | 0 |
158 | q->activated(QSystemTrayIcon::Context); never executed: q->activated(QSystemTrayIcon::Context); | 0 |
159 | else if (ev->button() == Qt::MidButton) never evaluated: ev->button() == Qt::MidButton | 0 |
160 | q->activated(QSystemTrayIcon::MiddleClick); never executed: q->activated(QSystemTrayIcon::MiddleClick); | 0 |
161 | } | - |
162 | | - |
163 | void QSystemTrayIconSys::mouseDoubleClickEvent(QMouseEvent *ev) | - |
164 | { | - |
165 | if (ev->button() == Qt::LeftButton) never evaluated: ev->button() == Qt::LeftButton | 0 |
166 | q->activated(QSystemTrayIcon::DoubleClick); never executed: q->activated(QSystemTrayIcon::DoubleClick); | 0 |
167 | } | 0 |
168 | | - |
169 | bool QSystemTrayIconSys::event(QEvent *e) | - |
170 | { | - |
171 | switch (e->type()) { | - |
172 | | - |
173 | case QEvent::Wheel: | - |
174 | return QApplication::sendEvent(q, e); never executed: return QApplication::sendEvent(q, e); | 0 |
175 | | - |
176 | default: | - |
177 | break; executed: break; Execution Count:52 | 52 |
178 | } | - |
179 | return QWidget::event(e); executed: return QWidget::event(e); Execution Count:52 | 52 |
180 | } | - |
181 | | - |
182 | void QSystemTrayIconSys::paintEvent(QPaintEvent *) | - |
183 | { | - |
184 | | - |
185 | | - |
186 | const QRect rect(QPoint(0, 0), geometry().size()); | - |
187 | QPainter painter(this); | - |
188 | painter.setCompositionMode(QPainter::CompositionMode_Source); | - |
189 | painter.fillRect(rect, Qt::transparent); | - |
190 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | - |
191 | q->icon().paint(&painter, rect); | - |
192 | } executed: } Execution Count:1 | 1 |
193 | | - |
194 | | - |
195 | | - |
196 | QSystemTrayIconPrivate::QSystemTrayIconPrivate() | - |
197 | : sys(0), | - |
198 | visible(false) | - |
199 | { | - |
200 | } executed: } Execution Count:4 | 4 |
201 | | - |
202 | QSystemTrayIconPrivate::~QSystemTrayIconPrivate() | - |
203 | { | - |
204 | } | - |
205 | | - |
206 | void QSystemTrayIconPrivate::install_sys() | - |
207 | { | - |
208 | QSystemTrayIcon * const q = q_func(); | - |
209 | if (!sys && qX11SystemTrayContext()->isValid()) partially evaluated: !sys yes Evaluation Count:3 | no Evaluation Count:0 |
partially evaluated: qX11SystemTrayContext()->isValid() yes Evaluation Count:3 | no Evaluation Count:0 |
| 0-3 |
210 | sys = new QSystemTrayIconSys(q); executed: sys = new QSystemTrayIconSys(q); Execution Count:3 | 3 |
211 | } executed: } Execution Count:3 | 3 |
212 | | - |
213 | QRect QSystemTrayIconPrivate::geometry_sys() const | - |
214 | { | - |
215 | if (!sys) | 0 |
216 | return QRect(); never executed: return QRect(); | 0 |
217 | return sys->globalGeometry(); never executed: return sys->globalGeometry(); | 0 |
218 | } | - |
219 | | - |
220 | void QSystemTrayIconPrivate::remove_sys() | - |
221 | { | - |
222 | if (!sys) evaluated: !sys yes Evaluation Count:2 | yes Evaluation Count:3 |
| 2-3 |
223 | return; executed: return; Execution Count:2 | 2 |
224 | QBalloonTip::hideBalloon(); | - |
225 | sys->hide(); | - |
226 | delete sys; | - |
227 | sys = 0; | - |
228 | } executed: } Execution Count:3 | 3 |
229 | | - |
230 | void QSystemTrayIconPrivate::updateIcon_sys() | - |
231 | { | - |
232 | if (sys) evaluated: sys yes Evaluation Count:1 | yes Evaluation Count:4 |
| 1-4 |
233 | sys->updateIcon(); executed: sys->updateIcon(); Execution Count:1 | 1 |
234 | } executed: } Execution Count:5 | 5 |
235 | | - |
236 | void QSystemTrayIconPrivate::updateMenu_sys() | - |
237 | { | - |
238 | | - |
239 | } | - |
240 | | - |
241 | void QSystemTrayIconPrivate::updateToolTip_sys() | - |
242 | { | - |
243 | if (!sys) partially evaluated: !sys yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
244 | return; executed: return; Execution Count:1 | 1 |
245 | | - |
246 | sys->setToolTip(toolTip); | - |
247 | | - |
248 | } | 0 |
249 | | - |
250 | bool QSystemTrayIconPrivate::isSystemTrayAvailable_sys() | - |
251 | { | - |
252 | const QString platform = QGuiApplication::platformName(); | - |
253 | if (platform.compare(QString::fromUtf8("" "xcb" "", sizeof("xcb") - 1), Qt::CaseInsensitive) == 0) never evaluated: platform.compare(QString::fromUtf8("" "xcb" "", sizeof("xcb") - 1), Qt::CaseInsensitive) == 0 | 0 |
254 | return qX11SystemTrayContext()->locateSystemTray() != 0L; never executed: return qX11SystemTrayContext()->locateSystemTray() != 0L; | 0 |
255 | return false; never executed: return false; | 0 |
256 | } | - |
257 | | - |
258 | bool QSystemTrayIconPrivate::supportsMessages_sys() | - |
259 | { | - |
260 | return true; executed: return true; Execution Count:1 | 1 |
261 | } | - |
262 | | - |
263 | void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QString &title, | - |
264 | QSystemTrayIcon::MessageIcon icon, int msecs) | - |
265 | { | - |
266 | if (!sys) partially evaluated: !sys no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
267 | return; | 0 |
268 | const QPoint g = sys->globalGeometry().topLeft(); | - |
269 | QBalloonTip::showBalloon(icon, message, title, sys->systemTrayIcon(), | - |
270 | QPoint(g.x() + sys->width()/2, g.y() + sys->height()/2), | - |
271 | msecs); | - |
272 | } executed: } Execution Count:4 | 4 |
273 | | - |
274 | | - |
275 | | - |
| | |