Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbsystemtraytracker.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the plugins of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qxcbsystemtraytracker.h" | - | ||||||||||||
41 | #include "qxcbconnection.h" | - | ||||||||||||
42 | #include "qxcbscreen.h" | - | ||||||||||||
43 | - | |||||||||||||
44 | #include <QtCore/QDebug> | - | ||||||||||||
45 | #include <QtCore/QRect> | - | ||||||||||||
46 | #include <QtGui/QScreen> | - | ||||||||||||
47 | - | |||||||||||||
48 | #include <qpa/qplatformnativeinterface.h> | - | ||||||||||||
49 | - | |||||||||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||||||||
51 | - | |||||||||||||
52 | enum { | - | ||||||||||||
53 | SystemTrayRequestDock = 0, | - | ||||||||||||
54 | SystemTrayBeginMessage = 1, | - | ||||||||||||
55 | SystemTrayCancelMessage = 2 | - | ||||||||||||
56 | }; | - | ||||||||||||
57 | - | |||||||||||||
58 | // QXcbSystemTrayTracker provides API for accessing the tray window and tracks | - | ||||||||||||
59 | // its lifecyle by listening for its destruction and recreation. | - | ||||||||||||
60 | // See http://standards.freedesktop.org/systemtray-spec/systemtray-spec-latest.html | - | ||||||||||||
61 | - | |||||||||||||
62 | QXcbSystemTrayTracker *QXcbSystemTrayTracker::create(QXcbConnection *connection) | - | ||||||||||||
63 | { | - | ||||||||||||
64 | // Selection, tray atoms for GNOME, NET WM Specification | - | ||||||||||||
65 | const xcb_atom_t trayAtom = connection->atom(QXcbAtom::_NET_SYSTEM_TRAY_OPCODE); | - | ||||||||||||
66 | if (!trayAtom)
| 0-1 | ||||||||||||
67 | return 0; never executed: return 0; | 0 | ||||||||||||
68 | const QByteArray netSysTray = QByteArrayLiteral("_NET_SYSTEM_TRAY_S") + QByteArray::number(connection->primaryScreenNumber()); executed 1 time by 1 test: return ba; Executed by:
| 1 | ||||||||||||
69 | const xcb_atom_t selection = connection->internAtom(netSysTray.constData()); | - | ||||||||||||
70 | if (!selection)
| 0-1 | ||||||||||||
71 | return 0; never executed: return 0; | 0 | ||||||||||||
72 | - | |||||||||||||
73 | return new QXcbSystemTrayTracker(connection, trayAtom, selection); executed 1 time by 1 test: return new QXcbSystemTrayTracker(connection, trayAtom, selection); Executed by:
| 1 | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | QXcbSystemTrayTracker::QXcbSystemTrayTracker(QXcbConnection *connection, | - | ||||||||||||
77 | xcb_atom_t trayAtom, | - | ||||||||||||
78 | xcb_atom_t selection) | - | ||||||||||||
79 | : QObject(connection) | - | ||||||||||||
80 | , m_selection(selection) | - | ||||||||||||
81 | , m_trayAtom(trayAtom) | - | ||||||||||||
82 | , m_connection(connection) | - | ||||||||||||
83 | , m_trayWindow(0) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
86 | - | |||||||||||||
87 | xcb_window_t QXcbSystemTrayTracker::locateTrayWindow(const QXcbConnection *connection, xcb_atom_t selection) | - | ||||||||||||
88 | { | - | ||||||||||||
89 | xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(connection->xcb_connection(), selection); | - | ||||||||||||
90 | xcb_get_selection_owner_reply_t *reply = xcb_get_selection_owner_reply(connection->xcb_connection(), cookie, 0); | - | ||||||||||||
91 | if (!reply)
| 0-1 | ||||||||||||
92 | return 0; never executed: return 0; | 0 | ||||||||||||
93 | const xcb_window_t result = reply->owner; | - | ||||||||||||
94 | free(reply); | - | ||||||||||||
95 | return result; executed 1 time by 1 test: return result; Executed by:
| 1 | ||||||||||||
96 | } | - | ||||||||||||
97 | - | |||||||||||||
98 | // API for QPlatformNativeInterface/QPlatformSystemTrayIcon: Request a window | - | ||||||||||||
99 | // to be docked on the tray. | - | ||||||||||||
100 | void QXcbSystemTrayTracker::requestSystemTrayWindowDock(xcb_window_t window) const | - | ||||||||||||
101 | { | - | ||||||||||||
102 | xcb_client_message_event_t trayRequest; | - | ||||||||||||
103 | trayRequest.response_type = XCB_CLIENT_MESSAGE; | - | ||||||||||||
104 | trayRequest.format = 32; | - | ||||||||||||
105 | trayRequest.sequence = 0; | - | ||||||||||||
106 | trayRequest.window = m_trayWindow; | - | ||||||||||||
107 | trayRequest.type = m_trayAtom; | - | ||||||||||||
108 | trayRequest.data.data32[0] = XCB_CURRENT_TIME; | - | ||||||||||||
109 | trayRequest.data.data32[1] = SystemTrayRequestDock; | - | ||||||||||||
110 | trayRequest.data.data32[2] = window; | - | ||||||||||||
111 | xcb_send_event(m_connection->xcb_connection(), 0, m_trayWindow, XCB_EVENT_MASK_NO_EVENT, (const char *)&trayRequest); | - | ||||||||||||
112 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
113 | - | |||||||||||||
114 | // API for QPlatformNativeInterface/QPlatformSystemTrayIcon: Return tray window. | - | ||||||||||||
115 | xcb_window_t QXcbSystemTrayTracker::trayWindow() | - | ||||||||||||
116 | { | - | ||||||||||||
117 | if (!m_trayWindow) {
| 1-5 | ||||||||||||
118 | m_trayWindow = QXcbSystemTrayTracker::locateTrayWindow(m_connection, m_selection); | - | ||||||||||||
119 | if (m_trayWindow) { // Listen for DestroyNotify on tray.
| 0-1 | ||||||||||||
120 | m_connection->addWindowEventListener(m_trayWindow, this); | - | ||||||||||||
121 | const quint32 mask = XCB_CW_EVENT_MASK; | - | ||||||||||||
122 | const quint32 value = XCB_EVENT_MASK_STRUCTURE_NOTIFY; | - | ||||||||||||
123 | Q_XCB_CALL2(xcb_change_window_attributes(m_connection->xcb_connection(), m_trayWindow, mask, &value), m_connection); | - | ||||||||||||
124 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
125 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
126 | return m_trayWindow; executed 6 times by 1 test: return m_trayWindow; Executed by:
| 6 | ||||||||||||
127 | } | - | ||||||||||||
128 | - | |||||||||||||
129 | // API for QPlatformNativeInterface/QPlatformSystemTrayIcon: Return the geometry of a | - | ||||||||||||
130 | // a window parented on the tray. Determines the global geometry via XCB since mapToGlobal | - | ||||||||||||
131 | // does not work for the QWindow parented on the tray. | - | ||||||||||||
132 | QRect QXcbSystemTrayTracker::systemTrayWindowGlobalGeometry(xcb_window_t window) const | - | ||||||||||||
133 | { | - | ||||||||||||
134 | - | |||||||||||||
135 | xcb_connection_t *conn = m_connection->xcb_connection(); | - | ||||||||||||
136 | xcb_get_geometry_reply_t *geomReply = | - | ||||||||||||
137 | xcb_get_geometry_reply(conn, xcb_get_geometry(conn, window), 0); | - | ||||||||||||
138 | if (!geomReply)
| 0-4 | ||||||||||||
139 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
140 | - | |||||||||||||
141 | xcb_translate_coordinates_reply_t *translateReply = | - | ||||||||||||
142 | xcb_translate_coordinates_reply(conn, xcb_translate_coordinates(conn, window, m_connection->rootWindow(), 0, 0), 0); | - | ||||||||||||
143 | if (!translateReply) {
| 0-4 | ||||||||||||
144 | free(geomReply); | - | ||||||||||||
145 | return QRect(); never executed: return QRect(); | 0 | ||||||||||||
146 | } | - | ||||||||||||
147 | - | |||||||||||||
148 | const QRect result(QPoint(translateReply->dst_x, translateReply->dst_y), QSize(geomReply->width, geomReply->height)); | - | ||||||||||||
149 | free(translateReply); | - | ||||||||||||
150 | return result; executed 4 times by 1 test: return result; Executed by:
| 4 | ||||||||||||
151 | } | - | ||||||||||||
152 | - | |||||||||||||
153 | inline void QXcbSystemTrayTracker::emitSystemTrayWindowChanged() | - | ||||||||||||
154 | { | - | ||||||||||||
155 | if (const QPlatformScreen *ps = m_connection->primaryScreen())
| 0 | ||||||||||||
156 | emit systemTrayWindowChanged(ps->screen()); never executed: systemTrayWindowChanged(ps->screen()); | 0 | ||||||||||||
157 | } never executed: end of block | 0 | ||||||||||||
158 | - | |||||||||||||
159 | // Client messages with the "MANAGER" atom on the root window indicate creation of a new tray. | - | ||||||||||||
160 | void QXcbSystemTrayTracker::notifyManagerClientMessageEvent(const xcb_client_message_event_t *t) | - | ||||||||||||
161 | { | - | ||||||||||||
162 | if (t->data.data32[1] == m_selection)
| 0 | ||||||||||||
163 | emitSystemTrayWindowChanged(); never executed: emitSystemTrayWindowChanged(); | 0 | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | - | |||||||||||||
166 | // Listen for destruction of the tray. | - | ||||||||||||
167 | void QXcbSystemTrayTracker::handleDestroyNotifyEvent(const xcb_destroy_notify_event_t *event) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | if (event->window == m_trayWindow) {
| 0 | ||||||||||||
170 | m_connection->removeWindowEventListener(m_trayWindow); | - | ||||||||||||
171 | m_trayWindow = XCB_WINDOW_NONE; | - | ||||||||||||
172 | emitSystemTrayWindowChanged(); | - | ||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||
174 | } never executed: end of block | 0 | ||||||||||||
175 | - | |||||||||||||
176 | bool QXcbSystemTrayTracker::visualHasAlphaChannel() | - | ||||||||||||
177 | { | - | ||||||||||||
178 | if (m_trayWindow == XCB_WINDOW_NONE)
| 0-3 | ||||||||||||
179 | return false; never executed: return false; | 0 | ||||||||||||
180 | - | |||||||||||||
181 | xcb_atom_t tray_atom = m_connection->atom(QXcbAtom::_NET_SYSTEM_TRAY_VISUAL); | - | ||||||||||||
182 | - | |||||||||||||
183 | // Get the xcb property for the _NET_SYSTEM_TRAY_VISUAL atom | - | ||||||||||||
184 | xcb_get_property_cookie_t systray_atom_cookie; | - | ||||||||||||
185 | xcb_get_property_reply_t *systray_atom_reply; | - | ||||||||||||
186 | - | |||||||||||||
187 | systray_atom_cookie = xcb_get_property_unchecked(m_connection->xcb_connection(), false, m_trayWindow, | - | ||||||||||||
188 | tray_atom, XCB_ATOM_VISUALID, 0, 1); | - | ||||||||||||
189 | systray_atom_reply = xcb_get_property_reply(m_connection->xcb_connection(), systray_atom_cookie, 0); | - | ||||||||||||
190 | - | |||||||||||||
191 | if (!systray_atom_reply)
| 0-3 | ||||||||||||
192 | return false; never executed: return false; | 0 | ||||||||||||
193 | - | |||||||||||||
194 | xcb_visualid_t systrayVisualId = XCB_NONE; | - | ||||||||||||
195 | if (systray_atom_reply->value_len > 0 && xcb_get_property_value_length(systray_atom_reply) > 0) {
| 0-3 | ||||||||||||
196 | xcb_visualid_t * vids = (uint32_t *)xcb_get_property_value(systray_atom_reply); | - | ||||||||||||
197 | systrayVisualId = vids[0]; | - | ||||||||||||
198 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
199 | - | |||||||||||||
200 | free(systray_atom_reply); | - | ||||||||||||
201 | - | |||||||||||||
202 | if (systrayVisualId != XCB_NONE) {
| 0-3 | ||||||||||||
203 | quint8 depth = m_connection->primaryScreen()->depthOfVisual(systrayVisualId); | - | ||||||||||||
204 | return depth == 32; executed 3 times by 1 test: return depth == 32; Executed by:
| 3 | ||||||||||||
205 | } | - | ||||||||||||
206 | - | |||||||||||||
207 | return false; never executed: return false; | 0 | ||||||||||||
208 | } | - | ||||||||||||
209 | - | |||||||||||||
210 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |