Move the systemTrayVisualHasAlphaChannel to the QXcbSystemTrayTracker

also expose it through the QXcbScreenFunctions platform header and use
it in the qsystemtrayicon_x11.cpp. This gives us static typechecking.

Change-Id: Ia9e2e2563ed5994be0b19d7bcf5a6aca92b1b760
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Jørgen Lind 2015-02-17 16:00:00 +01:00 committed by Shawn Rutledge
parent 2cac171dde
commit 8f9a72c39d
10 changed files with 133 additions and 54 deletions

View File

@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QXCBINTEGRATIONFUNCTIONS_H
#define QXCBINTEGRATIONFUNCTIONS_H
#include "qxcbfunctionshelper.h"
QT_BEGIN_NAMESPACE
class QXcbIntegrationFunctions
{
public:
typedef bool (*XEmbedSystemTrayVisualHasAlphaChannel)();
static const QByteArray xEmbedSystemTrayVisualHasAlphaChannelIdentifier() { return QByteArrayLiteral("XcbXEmbedSystemTrayVisualHasAlphaChannel"); }
static bool xEmbedSystemTrayVisualHasAlphaChannel()
{
return QXcbFunctionsHelper::callPlatformFunction<bool, XEmbedSystemTrayVisualHasAlphaChannel>(xEmbedSystemTrayVisualHasAlphaChannelIdentifier());
}
};
QT_END_NAMESPACE
#endif /*QXCBINTEGRATIONFUNCTIONS_H*/

View File

@ -1 +1,3 @@
HEADERS += $$PWD/qxcbwindowfunctions.h HEADERS += \
$$PWD/qxcbwindowfunctions.h \
$$PWD/qxcbintegrationfunctions.h

View File

@ -1791,10 +1791,11 @@ bool QXcbConnection::xi2PrepareXIGenericDeviceEvent(xcb_ge_event_t *ev, int opCo
} }
#endif // defined(XCB_USE_XINPUT2) #endif // defined(XCB_USE_XINPUT2)
QXcbSystemTrayTracker *QXcbConnection::systemTrayTracker() QXcbSystemTrayTracker *QXcbConnection::systemTrayTracker() const
{ {
if (!m_systemTrayTracker) { if (!m_systemTrayTracker) {
if ( (m_systemTrayTracker = QXcbSystemTrayTracker::create(this)) ) { QXcbConnection *self = const_cast<QXcbConnection *>(this);
if ((self->m_systemTrayTracker = QXcbSystemTrayTracker::create(self))) {
connect(m_systemTrayTracker, SIGNAL(systemTrayWindowChanged(QScreen*)), connect(m_systemTrayTracker, SIGNAL(systemTrayWindowChanged(QScreen*)),
QGuiApplication::platformNativeInterface(), SIGNAL(systemTrayWindowChanged(QScreen*))); QGuiApplication::platformNativeInterface(), SIGNAL(systemTrayWindowChanged(QScreen*)));
} }
@ -1802,6 +1803,22 @@ QXcbSystemTrayTracker *QXcbConnection::systemTrayTracker()
return m_systemTrayTracker; return m_systemTrayTracker;
} }
bool QXcbConnection::xEmbedSystemTrayAvailable()
{
if (!QGuiApplicationPrivate::platformIntegration())
return false;
QXcbConnection *connection = static_cast<QXcbIntegration *>(QGuiApplicationPrivate::platformIntegration())->defaultConnection();
return connection->systemTrayTracker();
}
bool QXcbConnection::xEmbedSystemTrayVisualHasAlphaChannel()
{
if (!QGuiApplicationPrivate::platformIntegration())
return false;
QXcbConnection *connection = static_cast<QXcbIntegration *>(QGuiApplicationPrivate::platformIntegration())->defaultConnection();
return connection->systemTrayTracker() && connection->systemTrayTracker()->visualHasAlphaChannel();
}
bool QXcbConnection::event(QEvent *e) bool QXcbConnection::event(QEvent *e)
{ {
if (e->type() == QEvent::User + 1) { if (e->type() == QEvent::User + 1) {

View File

@ -463,7 +463,9 @@ public:
QXcbNativeInterface *nativeInterface() const { return m_nativeInterface; } QXcbNativeInterface *nativeInterface() const { return m_nativeInterface; }
QXcbSystemTrayTracker *systemTrayTracker(); QXcbSystemTrayTracker *systemTrayTracker() const;
static bool xEmbedSystemTrayAvailable();
static bool xEmbedSystemTrayVisualHasAlphaChannel();
#ifdef XCB_USE_XINPUT2 #ifdef XCB_USE_XINPUT2
void handleEnterEvent(const xcb_enter_notify_event_t *); void handleEnterEvent(const xcb_enter_notify_event_t *);
@ -474,6 +476,7 @@ public:
bool canGrab() const { return m_canGrabServer; } bool canGrab() const { return m_canGrabServer; }
QXcbGlIntegration *glIntegration() const { return m_glIntegration; } QXcbGlIntegration *glIntegration() const { return m_glIntegration; }
protected: protected:
bool event(QEvent *e) Q_DECL_OVERRIDE; bool event(QEvent *e) Q_DECL_OVERRIDE;

View File

@ -47,6 +47,7 @@
#include <QtGui/qscreen.h> #include <QtGui/qscreen.h>
#include <QtPlatformHeaders/qxcbwindowfunctions.h> #include <QtPlatformHeaders/qxcbwindowfunctions.h>
#include <QtPlatformHeaders/qxcbintegrationfunctions.h>
#ifndef QT_NO_DBUS #ifndef QT_NO_DBUS
#include "QtPlatformSupport/private/qdbusmenuconnection_p.h" #include "QtPlatformSupport/private/qdbusmenuconnection_p.h"
@ -85,8 +86,7 @@ static int resourceType(const QByteArray &key)
QXcbNativeInterface::QXcbNativeInterface() : QXcbNativeInterface::QXcbNativeInterface() :
m_genericEventFilterType(QByteArrayLiteral("xcb_generic_event_t")), m_genericEventFilterType(QByteArrayLiteral("xcb_generic_event_t")),
m_sysTraySelectionAtom(XCB_ATOM_NONE), m_sysTraySelectionAtom(XCB_ATOM_NONE)
m_systrayVisualId(XCB_NONE)
{ {
} }
@ -145,42 +145,9 @@ xcb_window_t QXcbNativeInterface::locateSystemTray(xcb_connection_t *conn, const
return selection_window; return selection_window;
} }
bool QXcbNativeInterface::systrayVisualHasAlphaChannel() { bool QXcbNativeInterface::systrayVisualHasAlphaChannel()
const QXcbScreen *screen = static_cast<QXcbScreen *>(QGuiApplication::primaryScreen()->handle()); {
return QXcbConnection::xEmbedSystemTrayVisualHasAlphaChannel();
if (m_systrayVisualId == XCB_NONE) {
xcb_connection_t *xcb_conn = screen->xcb_connection();
xcb_atom_t tray_atom = screen->atom(QXcbAtom::_NET_SYSTEM_TRAY_VISUAL);
xcb_window_t systray_window = locateSystemTray(xcb_conn, screen);
if (systray_window == XCB_WINDOW_NONE)
return false;
// Get the xcb property for the _NET_SYSTEM_TRAY_VISUAL atom
xcb_get_property_cookie_t systray_atom_cookie;
xcb_get_property_reply_t *systray_atom_reply;
systray_atom_cookie = xcb_get_property_unchecked(xcb_conn, false, systray_window,
tray_atom, XCB_ATOM_VISUALID, 0, 1);
systray_atom_reply = xcb_get_property_reply(xcb_conn, systray_atom_cookie, 0);
if (!systray_atom_reply)
return false;
if (systray_atom_reply->value_len > 0 && xcb_get_property_value_length(systray_atom_reply) > 0) {
xcb_visualid_t * vids = (uint32_t *)xcb_get_property_value(systray_atom_reply);
m_systrayVisualId = vids[0];
}
free(systray_atom_reply);
}
if (m_systrayVisualId != XCB_NONE) {
quint8 depth = screen->depthOfVisual(m_systrayVisualId);
return depth == 32;
} else {
return false;
}
} }
void QXcbNativeInterface::setParentRelativeBackPixmap(QWindow *window) void QXcbNativeInterface::setParentRelativeBackPixmap(QWindow *window)
@ -373,6 +340,9 @@ QFunctionPointer QXcbNativeInterface::platformFunction(const QByteArray &functio
if (function == QXcbWindowFunctions::systemTrayWindowGlobalGeometryIdentifier()) if (function == QXcbWindowFunctions::systemTrayWindowGlobalGeometryIdentifier())
return QFunctionPointer(QXcbWindowFunctions::SystemTrayWindowGlobalGeometry(QXcbWindow::systemTrayWindowGlobalGeometryStatic)); return QFunctionPointer(QXcbWindowFunctions::SystemTrayWindowGlobalGeometry(QXcbWindow::systemTrayWindowGlobalGeometryStatic));
if (function == QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannelIdentifier())
return QFunctionPointer(QXcbIntegrationFunctions::XEmbedSystemTrayVisualHasAlphaChannel(QXcbConnection::xEmbedSystemTrayVisualHasAlphaChannel));
return Q_NULLPTR; return Q_NULLPTR;
} }

View File

@ -120,7 +120,6 @@ private:
const QByteArray m_genericEventFilterType; const QByteArray m_genericEventFilterType;
xcb_atom_t m_sysTraySelectionAtom; xcb_atom_t m_sysTraySelectionAtom;
xcb_visualid_t m_systrayVisualId;
static QXcbScreen *qPlatformScreenForWindow(QWindow *window); static QXcbScreen *qPlatformScreenForWindow(QWindow *window);

View File

@ -709,4 +709,5 @@ QXcbXSettings *QXcbScreen::xSettings() const
} }
return m_xSettings; return m_xSettings;
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -63,14 +63,14 @@ QXcbSystemTrayTracker *QXcbSystemTrayTracker::create(QXcbConnection *connection)
const xcb_atom_t selection = connection->internAtom(netSysTray.constData()); const xcb_atom_t selection = connection->internAtom(netSysTray.constData());
if (!selection) if (!selection)
return 0; return 0;
return new QXcbSystemTrayTracker(connection, trayAtom, selection, connection);
return new QXcbSystemTrayTracker(connection, trayAtom, selection);
} }
QXcbSystemTrayTracker::QXcbSystemTrayTracker(QXcbConnection *connection, QXcbSystemTrayTracker::QXcbSystemTrayTracker(QXcbConnection *connection,
xcb_atom_t trayAtom, xcb_atom_t trayAtom,
xcb_atom_t selection, xcb_atom_t selection)
QObject *parent) : QObject(connection)
: QObject(parent)
, m_selection(selection) , m_selection(selection)
, m_trayAtom(trayAtom) , m_trayAtom(trayAtom)
, m_connection(connection) , m_connection(connection)
@ -125,6 +125,7 @@ xcb_window_t QXcbSystemTrayTracker::trayWindow()
// does not work for the QWindow parented on the tray. // does not work for the QWindow parented on the tray.
QRect QXcbSystemTrayTracker::systemTrayWindowGlobalGeometry(xcb_window_t window) const QRect QXcbSystemTrayTracker::systemTrayWindowGlobalGeometry(xcb_window_t window) const
{ {
xcb_connection_t *conn = m_connection->xcb_connection(); xcb_connection_t *conn = m_connection->xcb_connection();
xcb_get_geometry_reply_t *geomReply = xcb_get_geometry_reply_t *geomReply =
xcb_get_geometry_reply(conn, xcb_get_geometry(conn, window), 0); xcb_get_geometry_reply(conn, xcb_get_geometry(conn, window), 0);
@ -161,9 +162,43 @@ void QXcbSystemTrayTracker::handleDestroyNotifyEvent(const xcb_destroy_notify_ev
{ {
if (event->window == m_trayWindow) { if (event->window == m_trayWindow) {
m_connection->removeWindowEventListener(m_trayWindow); m_connection->removeWindowEventListener(m_trayWindow);
m_trayWindow = 0; m_trayWindow = XCB_WINDOW_NONE;
emitSystemTrayWindowChanged(); emitSystemTrayWindowChanged();
} }
} }
bool QXcbSystemTrayTracker::visualHasAlphaChannel()
{
if (m_trayWindow == XCB_WINDOW_NONE)
return false;
xcb_atom_t tray_atom = m_connection->atom(QXcbAtom::_NET_SYSTEM_TRAY_VISUAL);
// Get the xcb property for the _NET_SYSTEM_TRAY_VISUAL atom
xcb_get_property_cookie_t systray_atom_cookie;
xcb_get_property_reply_t *systray_atom_reply;
systray_atom_cookie = xcb_get_property_unchecked(m_connection->xcb_connection(), false, m_trayWindow,
tray_atom, XCB_ATOM_VISUALID, 0, 1);
systray_atom_reply = xcb_get_property_reply(m_connection->xcb_connection(), systray_atom_cookie, 0);
if (!systray_atom_reply)
return false;
xcb_visualid_t systrayVisualId;
if (systray_atom_reply->value_len > 0 && xcb_get_property_value_length(systray_atom_reply) > 0) {
xcb_visualid_t * vids = (uint32_t *)xcb_get_property_value(systray_atom_reply);
systrayVisualId = vids[0];
}
free(systray_atom_reply);
if (systrayVisualId != XCB_NONE) {
quint8 depth = m_connection->primaryScreen()->depthOfVisual(systrayVisualId);
return depth == 32;
}
return false;
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -57,14 +57,14 @@ public:
void handleDestroyNotifyEvent(const xcb_destroy_notify_event_t *) Q_DECL_OVERRIDE; void handleDestroyNotifyEvent(const xcb_destroy_notify_event_t *) Q_DECL_OVERRIDE;
bool visualHasAlphaChannel();
signals: signals:
void systemTrayWindowChanged(QScreen *screen); void systemTrayWindowChanged(QScreen *screen);
private: private:
explicit QXcbSystemTrayTracker(QXcbConnection *connection, explicit QXcbSystemTrayTracker(QXcbConnection *connection,
xcb_atom_t trayAtom, xcb_atom_t trayAtom,
xcb_atom_t selection, xcb_atom_t selection);
QObject *parent = 0);
static xcb_window_t locateTrayWindow(const QXcbConnection *connection, xcb_atom_t selection); static xcb_window_t locateTrayWindow(const QXcbConnection *connection, xcb_atom_t selection);
void emitSystemTrayWindowChanged(); void emitSystemTrayWindowChanged();

View File

@ -53,6 +53,7 @@
#include <qdebug.h> #include <qdebug.h>
#include <QtPlatformHeaders/qxcbwindowfunctions.h> #include <QtPlatformHeaders/qxcbwindowfunctions.h>
#include <QtPlatformHeaders/qxcbintegrationfunctions.h>
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -113,10 +114,7 @@ QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn)
// window to ParentRelative (so that it inherits the background of its X11 parent window), call // window to ParentRelative (so that it inherits the background of its X11 parent window), call
// xcb_clear_region before painting (so that the inherited background is visible) and then grab // xcb_clear_region before painting (so that the inherited background is visible) and then grab
// the just-drawn background from the X11 server. // the just-drawn background from the X11 server.
bool hasAlphaChannel = false; bool hasAlphaChannel = QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannel();
QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(),
"systrayVisualHasAlphaChannel", Qt::DirectConnection,
Q_RETURN_ARG(bool, hasAlphaChannel));
setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel); setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel);
if (!hasAlphaChannel) { if (!hasAlphaChannel) {
createWinId(); createWinId();