]> git.lyx.org Git - lyx.git/commitdiff
Fix external middle-mouse pasting with Qt5/X11.
authorEnrico Forestieri <forenr@lyx.org>
Tue, 7 Apr 2015 10:59:41 +0000 (12:59 +0200)
committerEnrico Forestieri <forenr@lyx.org>
Tue, 7 Apr 2015 10:59:41 +0000 (12:59 +0200)
Closes #9216. Patch by Jürgen and me.

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiApplication.h

index 9ddb87c8c5bc4aa0dd962e548ccbc5ab7d2bcfde..ee2ecbcb8b62ef1e9f472bafe9ef4164bfa5b305 100644 (file)
 #include <QThreadPool>
 #include <QWidget>
 
-// FIXME QT5
 #ifdef Q_WS_X11
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
 #undef CursorShape
 #undef None
+#elif defined(QPA_XCB)
+#include <xcb/xcb.h>
+#include <X11/Xatom.h>
+#include <X11/Intrinsic.h>
+#undef None
 #endif
 
 #if (QT_VERSION < 0x050000) || (QT_VERSION >= 0x050400)
@@ -998,6 +1002,11 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
        // Install translator for GUI elements.
        installTranslator(&d->qt_trans_);
 
+#ifdef QPA_XCB
+       // Enable reception of XCB events.
+       installNativeEventFilter(this);
+#endif
+
        // FIXME: quitOnLastWindowClosed is true by default. We should have a
        // lyxrc setting for this in order to let the application stay resident.
        // But then we need some kind of dock icon, at least on Windows.
@@ -2986,7 +2995,6 @@ bool GuiApplication::longOperationStarted() {
 //
 // X11 specific stuff goes here...
 
-// FIXME QT5
 #ifdef Q_WS_X11
 bool GuiApplication::x11EventFilter(XEvent * xev)
 {
@@ -3018,6 +3026,44 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
        }
        return false;
 }
+#elif defined(QPA_XCB)
+bool GuiApplication::nativeEventFilter(const QByteArray & eventType,
+                                      void * message, long *) Q_DECL_OVERRIDE
+{
+       if (!current_view_ || eventType != "xcb_generic_event_t")
+               return false;
+
+       xcb_generic_event_t * ev = static_cast<xcb_generic_event_t *>(message);
+
+       switch (ev->response_type) {
+       case XCB_SELECTION_REQUEST: {
+               xcb_selection_request_event_t * srev =
+                       reinterpret_cast<xcb_selection_request_event_t *>(ev);
+               if (srev->selection != XA_PRIMARY)
+                       break;
+               LYXERR(Debug::SELECTION, "X requested selection.");
+               BufferView * bv = current_view_->currentBufferView();
+               if (bv) {
+                       docstring const sel = bv->requestSelection();
+                       if (!sel.empty())
+                               d->selection_.put(sel);
+               }
+               break;
+       }
+       case XCB_SELECTION_CLEAR: {
+               xcb_selection_clear_event_t * scev =
+                       reinterpret_cast<xcb_selection_clear_event_t *>(ev);
+               if (scev->selection != XA_PRIMARY)
+                       break;
+               LYXERR(Debug::SELECTION, "Lost selection.");
+               BufferView * bv = current_view_->currentBufferView();
+               if (bv)
+                       bv->clearSelection();
+               break;
+       }
+       }
+       return false;
+}
 #endif
 
 } // namespace frontend
index 6bf457e00fc18dcceb19ee931e1a6d65f67707f4..c6258eaeb692c60004950061733d9433f133fc4f 100644 (file)
@@ -18,6 +18,9 @@
 
 #include <QApplication>
 #include <QList>
+#ifdef QPA_XCB
+#include <QAbstractNativeEventFilter>
+#endif
 
 class QAbstractItemModel;
 class QIcon;
@@ -47,6 +50,9 @@ There should be only one instance of this class. No Qt object
 initialisation should be done before the instantiation of this class.
 */
 class GuiApplication : public QApplication, public Application
+#ifdef QPA_XCB
+                    , public QAbstractNativeEventFilter
+#endif
 {
        Q_OBJECT
 
@@ -99,9 +105,10 @@ public:
        //@{
        bool notify(QObject * receiver, QEvent * event);
        void commitData(QSessionManager & sm);
-       // FIXME QT5
 #ifdef Q_WS_X11
        bool x11EventFilter(XEvent * ev);
+#elif defined(QPA_XCB)
+       virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
 #endif
        //@}