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