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

List:       kde-core-devel
Subject:    KDE/kdelibs/kdeui/kernel
From:       Michael Leupold <lemma () confuego ! org>
Date:       2010-08-07 9:44:12
Message-ID: 20100807094412.B4B04AC7CA () svn ! kde ! org
[Download RAW message or body]

SVN commit 1160177 by mleupold:

Revert r1156762. KApplication has to keep its event filtering code. Replacing it with \
the KSystemEventFilter methods unfortunately disrupts how KGlobalAccel works, \
including KWin messup.

CCMAIL: kde-core-devel@kde.org

 M  +47 -3     kapplication.cpp  
 M  +3 -6      kapplication.h  


--- trunk/KDE/kdelibs/kdeui/kernel/kapplication.cpp #1160176:1160177
@@ -52,7 +52,6 @@
 #include "kurl.h"
 #include "kmessage.h"
 #include "kmessageboxmessagehandler.h"
-#include "ksystemeventfilter.h"
 
 #if defined Q_WS_X11
 #include <QtGui/qx11info_x11.h>
@@ -200,6 +199,7 @@
   KConfig *config() { return KGlobal::config().data(); }
 #endif
 
+  void _k_x11FilterDestroyed();
   void _k_checkAppStartedSlot();
   void _k_slot_KToolInvocation_hook(QStringList&, QByteArray&);
 
@@ -230,6 +230,8 @@
 };
 
 
+static QList< QWeakPointer< QWidget > > *x11Filter = 0;
+
 /**
    * Installs a handler for the SIGPIPE signal. It is thrown when you write to
    * a pipe or socket that has been closed.
@@ -250,13 +252,37 @@
 
 void KApplication::installX11EventFilter( QWidget* filter )
 {
-    KSystemEventFilter::installEventFilter(filter);
+    if ( !filter )
+        return;
+    if (!x11Filter)
+        x11Filter = new QList< QWeakPointer< QWidget > >;
+    connect ( filter, SIGNAL( destroyed() ), this, SLOT( _k_x11FilterDestroyed() ) \
); +    x11Filter->append( filter );
 }
 
+void KApplicationPrivate::_k_x11FilterDestroyed()
+{
+    q->removeX11EventFilter( static_cast< const QWidget* >(q->sender()));
+}
+
 void KApplication::removeX11EventFilter( const QWidget* filter )
 {
-    KSystemEventFilter::removeEventFilter(filter);
+    if ( !x11Filter || !filter )
+        return;
+    // removeAll doesn't work, creating QWeakPointer to something that's about to be \
deleted aborts +    // x11Filter->removeAll( const_cast< QWidget* >( filter ));
+    for( QMutableListIterator< QWeakPointer< QWidget > > it( *x11Filter );
+         it.hasNext();
+         ) {
+        QWidget* w = it.next().data();
+        if( w == filter || w == NULL )
+            it.remove();
 }
+    if ( x11Filter->isEmpty() ) {
+        delete x11Filter;
+        x11Filter = 0;
+    }
+}
 
 bool KApplication::notify(QObject *receiver, QEvent *event)
 {
@@ -885,6 +911,16 @@
 
 
 #ifdef Q_WS_X11
+class KAppX11HackWidget: public QWidget
+{
+public:
+    bool publicx11Event( XEvent * e) { return x11Event( e ); }
+};
+#endif
+
+
+
+#ifdef Q_WS_X11
 bool KApplication::x11EventFilter( XEvent *_event )
 {
     switch ( _event->type ) {
@@ -926,6 +962,14 @@
         default: break;
     }
 
+    if (x11Filter) {
+        foreach (const QWeakPointer< QWidget >& wp, *x11Filter) {
+            if( QWidget* w = wp.data())
+                if ( static_cast<KAppX11HackWidget*>( w )->publicx11Event(_event))
+                    return true;
+        }
+    }
+
     return false;
 }
 #endif // Q_WS_X11
--- trunk/KDE/kdelibs/kdeui/kernel/kapplication.h #1160176:1160177
@@ -280,8 +280,6 @@
 #endif
 
   /**
-   * @deprecated Use KSystemEventFilter::installEventFilter() instead.
-   *
    * Installs widget filter as global X11 event filter.
    *
    * The widget
@@ -290,15 +288,13 @@
    *  Warning: Only do this when absolutely necessary. An installed X11 filter
    *  can slow things down.
    **/
-  void KDE_DEPRECATED installX11EventFilter( QWidget* filter );
+  void installX11EventFilter( QWidget* filter );
 
   /**
-   * @deprecated Use KSystemEventFilter::removeEventFilter() instead.
-   *
    * Removes global X11 event filter previously installed by
    * installX11EventFilter().
    */
-  void KDE_DEPRECATED removeX11EventFilter( const QWidget* filter );
+  void removeX11EventFilter( const QWidget* filter );
 
 #ifdef KDE3_SUPPORT
   /**
@@ -479,6 +475,7 @@
   friend class KApplicationPrivate;
   KApplicationPrivate* const d;
 
+  Q_PRIVATE_SLOT(d, void _k_x11FilterDestroyed())
   Q_PRIVATE_SLOT(d, void _k_checkAppStartedSlot())
   Q_PRIVATE_SLOT(d, void _k_slot_KToolInvocation_hook(QStringList&, QByteArray&))
 };


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

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