From 52fee3556e63859f3ba52609e8f025a491767a81 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 7 Apr 2015 12:59:41 +0200 Subject: [PATCH] Fix external middle-mouse pasting with Qt5/X11. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #9216. Patch by Jürgen and me. --- src/frontends/qt4/GuiApplication.cpp | 50 ++++++++++++++++++++++++++-- src/frontends/qt4/GuiApplication.h | 9 ++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 9ddb87c8c5..ee2ecbcb8b 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -115,12 +115,16 @@ #include #include -// FIXME QT5 #ifdef Q_WS_X11 #include #include #undef CursorShape #undef None +#elif defined(QPA_XCB) +#include +#include +#include +#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(message); + + switch (ev->response_type) { + case XCB_SELECTION_REQUEST: { + xcb_selection_request_event_t * srev = + reinterpret_cast(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(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 diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 6bf457e00f..c6258eaeb6 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -18,6 +18,9 @@ #include #include +#ifdef QPA_XCB +#include +#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 //@}