Ensure to not call X11 specific calls if we are not on platform X11

This fixes a bunch of possible crashy code when trying to run
applications linking plasma-framework on platform Wayland.

REVIEW: 115641
This commit is contained in:
Martin Gräßlin 2014-02-11 08:49:55 +01:00
parent 68552f81dd
commit 31e301174a
4 changed files with 57 additions and 2 deletions

View File

@ -40,6 +40,7 @@ public:
#if HAVE_X11
,_connection( 0x0 ),
_gc( 0x0 )
, m_isX11(QX11Info::isPlatformX11())
#endif
{
}
@ -79,6 +80,9 @@ public:
//! graphical context
xcb_gcontext_t _gc;
#if HAVE_X11
bool m_isX11;
#endif
QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long> > data;
QHash<const QWindow *, Plasma::FrameSvg::EnabledBorders> m_windows;
@ -172,6 +176,9 @@ Qt::HANDLE DialogShadows::Private::createPixmap(const QPixmap& source)
*/
#if HAVE_X11
if (!m_isX11) {
return 0;
}
// check connection
if( !_connection ) _connection = QX11Info::connection();
@ -224,6 +231,9 @@ void DialogShadows::Private::initPixmap(const QString &element)
QPixmap DialogShadows::Private::initEmptyPixmap(const QSize &size)
{
#ifdef HAVE_X11
if (!m_isX11) {
return QPixmap();
}
QPixmap tempEmptyPix(size);
if (!size.isEmpty()) {
tempEmptyPix.fill(Qt::transparent);
@ -260,6 +270,9 @@ void DialogShadows::Private::setupPixmaps()
void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
//shadow-top
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_shadowPixmaps[0]));
@ -390,6 +403,9 @@ void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledB
void DialogShadows::Private::freeX11Pixmaps()
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
if (!QX11Info::display()) {
return;
@ -443,6 +459,9 @@ void DialogShadows::Private::clearPixmaps()
void DialogShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
if (m_shadowPixmaps.isEmpty()) {
setupPixmaps();
}
@ -463,6 +482,9 @@ void DialogShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSv
void DialogShadows::Private::clearShadow(const QWindow *window)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
Display *dpy = QX11Info::display();
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
XDeleteProperty(dpy, window->winId(), atom);

View File

@ -28,8 +28,17 @@ namespace Plasma
EffectWatcher::EffectWatcher(const QString& property, QObject *parent)
: QObject(parent),
m_property(XCB_ATOM_NONE)
m_property(XCB_ATOM_NONE),
m_isX11(QX11Info::isPlatformX11())
{
init(property);
}
void EffectWatcher::init(const QString &property)
{
if (!m_isX11) {
return;
}
QCoreApplication::instance()->installNativeEventFilter(this);
xcb_connection_t *c = QX11Info::connection();
@ -73,7 +82,7 @@ bool EffectWatcher::nativeEventFilter(const QByteArray& eventType, void *message
bool EffectWatcher::isEffectActive() const
{
if (m_property == XCB_ATOM_NONE) {
if (m_property == XCB_ATOM_NONE || !m_isX11) {
return false;
}
xcb_connection_t *c = QX11Info::connection();

View File

@ -45,8 +45,10 @@ Q_SIGNALS:
void effectChanged(bool on);
private:
void init(const QString &property);
xcb_atom_t m_property;
bool m_effectActive;
bool m_isX11;
};
} // namespace Plasma

View File

@ -39,6 +39,7 @@ public:
#if HAVE_X11
,_connection( 0x0 ),
_gc( 0x0 )
, m_isX11(QX11Info::isPlatformX11())
#endif
{
}
@ -78,6 +79,9 @@ public:
//! graphical context
xcb_gcontext_t _gc;
#if HAVE_X11
bool m_isX11;
#endif
QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long> > data;
QHash<const QWindow *, Plasma::FrameSvg::EnabledBorders> m_windows;
@ -171,6 +175,9 @@ Qt::HANDLE PanelShadows::Private::createPixmap(const QPixmap& source)
*/
#if HAVE_X11
if (!m_isX11) {
return 0;
}
// check connection
if( !_connection ) _connection = QX11Info::connection();
@ -223,6 +230,9 @@ void PanelShadows::Private::initPixmap(const QString &element)
QPixmap PanelShadows::Private::initEmptyPixmap(const QSize &size)
{
#ifdef HAVE_X11
if (!m_isX11) {
return QPixmap();
}
QPixmap tempEmptyPix(size);
if (!size.isEmpty()) {
tempEmptyPix.fill(Qt::transparent);
@ -259,6 +269,9 @@ void PanelShadows::Private::setupPixmaps()
void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
//shadow-top
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << reinterpret_cast<unsigned long>(createPixmap(m_shadowPixmaps[0]));
@ -389,6 +402,9 @@ void PanelShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBo
void PanelShadows::Private::freeX11Pixmaps()
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
if (!QX11Info::display()) {
return;
@ -442,6 +458,9 @@ void PanelShadows::Private::clearPixmaps()
void PanelShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
if (m_shadowPixmaps.isEmpty()) {
setupPixmaps();
}
@ -462,6 +481,9 @@ void PanelShadows::Private::updateShadow(const QWindow *window, Plasma::FrameSvg
void PanelShadows::Private::clearShadow(const QWindow *window)
{
#ifdef HAVE_X11
if (!m_isX11) {
return;
}
Display *dpy = QX11Info::display();
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
XDeleteProperty(dpy, window->winId(), atom);