[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwindowsystem] src: Add runtime detection to KXMessages
From:       Martin_Gräßlin <mgraesslin () kde ! org>
Date:       2014-02-01 7:42:57
Message-ID: E1W9VE9-0003Eq-3E () scm ! kde ! org
[Download RAW message or body]

Git commit 6f0d8141132e675eb3c5cf32beb04a61524435ec by Martin Gräßlin.
Committed on 23/01/2014 at 08:59.
Pushed by graesslin into branch 'master'.

Add runtime detection to KXMessages

KXMessages should only be used if we are on platformX11. A compile time
check is not enough.

REVIEW: 115248

M  +11   -1    src/kxmessages.cpp

http://commits.kde.org/kwindowsystem/6f0d8141132e675eb3c5cf32beb04a61524435ec

diff --git a/src/kxmessages.cpp b/src/kxmessages.cpp
index a723d42..c76de22 100644
--- a/src/kxmessages.cpp
+++ b/src/kxmessages.cpp
@@ -45,6 +45,7 @@ public:
     Atom accept_atom1;
     QMap< WId, QByteArray > incoming_messages;
     KXMessages *q;
+    bool valid;
 
     bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
     {
@@ -101,7 +102,8 @@ KXMessages::KXMessages(const char *accept_broadcast_P, QObject \
*parent_P)  , d(new KXMessagesPrivate)
 {
     d->q = this;
-    if (accept_broadcast_P != NULL) {
+    d->valid = QX11Info::isPlatformX11();
+    if (d->valid && accept_broadcast_P != NULL) {
         QCoreApplication::instance()->installNativeEventFilter(d);
         d->accept_atom1 = XInternAtom(QX11Info::display(), \
                QByteArray(QByteArray(accept_broadcast_P) + "_BEGIN").constData(), \
                false);
         d->accept_atom2 = XInternAtom(QX11Info::display(), accept_broadcast_P, \
false); @@ -119,6 +121,10 @@ KXMessages::~KXMessages()
 
 void KXMessages::broadcastMessage(const char *msg_type_P, const QString &message_P, \
int screen_P)  {
+    if (!d->valid) {
+        qWarning() << "KXMessages used on non-X11 platform! This is an application \
bug."; +        return;
+    }
     Atom a2 = XInternAtom(QX11Info::display(), msg_type_P, false);
     Atom a1 = XInternAtom(QX11Info::display(), QByteArray(QByteArray(msg_type_P) + \
                "_BEGIN").constData(), false);
     Window root = screen_P == -1 ? QX11Info::appRootWindow() : \
QX11Info::appRootWindow(screen_P); @@ -132,6 +138,10 @@ bool \
KXMessages::broadcastMessageX(Display *disp, const char *msg_type_P,  if (disp == \
NULL) {  return false;
     }
+    if (!QX11Info::isPlatformX11()) {
+        qWarning() << "KXMessages used on non-X11 platform! This is an application \
bug."; +        return false;
+    }
     Atom a2 = XInternAtom(disp, msg_type_P, false);
     Atom a1 = XInternAtom(disp, QByteArray(QByteArray(msg_type_P) + \
                "_BEGIN").constData(), false);
     Window root = screen_P == -1 ? DefaultRootWindow(disp) : RootWindow(disp, \
screen_P);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic