On Sat, Jul 09, 2016 at 03:27:40AM -0400, Scott Kostyshak wrote:
> 
> I tried a few random variations on your patch to squash the last
> warning. One that worked for me is to add
> 
>   return true;
> 
> after
> 
>   xcb_flush(con);
> 
> I have no idea if that makes any sense but perhaps it provides a clue.
> Does the warning go away if you add that?

Yes, it does. The documentation is not so much clear about this. It says
"if you want to filter the message out, i.e. stop it being handled further,
return true; otherwise return false."
but it is not clear whether it refers to the *same* message or to the
same message type. Anyway, returning true has no ill effect and gets
rid of the warning (even compiling without Qt5X11Extras), so I added it.
Thanks for the tip.

I have also extended the fix to Qt4 in much the same manner and it works
for me. In the attached patch I have also incorporated the changes for
cmake, except for Qt4, as I don't know what is required.
The more I think about it, the more I am convinced that this is a Qt issue.

> Finally, this doesn't seem to solve the flood of messages I get when
> CopyQ is running, but I don't think this is worth investigating.

Clipboard managers are always troublesome. Cannot help here, sorry.

-- 
Enrico
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 76cbdde..7e13427 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -926,9 +926,12 @@ include(${LYX_CMAKE_DIR}/ConfigureChecks.cmake)
 configure_file(${LYX_CMAKE_DIR}/configCompiler.h.cmake 
${TOP_BINARY_DIR}/configCompiler.h)
 
 set(QPA_XCB)
-if(Qt5X11Extras_FOUND AND QT_USES_X11)
+if(LYX_USE_QT MATCHES "QT5" AND QT_USES_X11)
   # QPA_XCB is only valid if QT5+X11
   set(QPA_XCB 1)
+  if(Qt5X11Extras_FOUND)
+    set(HAVE_QT5_X11_EXTRAS 1)
+  endif()
 endif()
 configure_file(${LYX_CMAKE_DIR}/config.h.cmake ${TOP_BINARY_DIR}/config.h)
 
diff --git a/config/qt4.m4 b/config/qt4.m4
index 0e357a4..f39c0ed 100644
--- a/config/qt4.m4
+++ b/config/qt4.m4
@@ -172,18 +172,30 @@ AC_DEFUN([QT_DO_IT_ALL],
        [AC_MSG_ERROR([LyX requires at least version $1 of Qt. Only version 
$QTLIB_VERSION has been found.])
        ])
 
+       save_CPPFLAGS=$CPPFLAGS
+       AC_MSG_CHECKING([whether Qt uses the X Window system])
+       CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES"
        if test x$USE_QT5 = xyes ; then
-         save_CPPFLAGS=$CPPFLAGS
-         AC_MSG_CHECKING([whether Qt uses the X Window system])
-         CPPFLAGS="$save_CPPFLAGS $QT_CORE_INCLUDES"
          AC_EGREP_CPP(xcb,
            [#include <qconfig.h>
            QT_QPA_DEFAULT_PLATFORM_NAME],
            [AC_MSG_RESULT(yes)
             AC_DEFINE(QPA_XCB, 1, [Define if Qt uses the X Window System])],
            [AC_MSG_RESULT(no)])
-         CPPFLAGS=$save_CPPFLAGS
+       else
+         AC_PREPROC_IFELSE([AC_LANG_SOURCE([
+           [#include <qglobal.h>],
+           [#ifndef Q_WS_X11],
+           [#error Fail],
+           [#endif]])],
+           qt_use_x11=yes,
+           qt_use_x11=no)
+         AC_MSG_RESULT($qt_use_x11)
+         if test "x$qt_use_x11" = "xyes"; then
+           QT_LIB="$QT_LIB -lX11"
+         fi
        fi
+       CPPFLAGS=$save_CPPFLAGS
 
        QT_FIND_TOOL([QT_MOC], [moc])
        QT_FIND_TOOL([QT_UIC], [uic])
@@ -209,6 +221,13 @@ AC_DEFUN([QT_DO_PKG_CONFIG],
        if test "x$USE_QT5" != "xno" ; then
                qt_corelibs="Qt5Core"
                qt_guilibs="Qt5Core Qt5Concurrent Qt5Gui Qt5Svg Qt5Widgets"
+               lyx_use_x11extras=false
+               PKG_CHECK_EXISTS(Qt5X11Extras, [lyx_use_x11extras=true], [])
+               if $lyx_use_x11extras; then
+                       qt_guilibs="$qt_guilibs Qt5X11Extras xcb"
+                       AC_DEFINE(HAVE_QT5_X11_EXTRAS, 1,
+                               [Define if you have the Qt5X11Extras module])
+               fi
                lyx_use_winextras=false
                PKG_CHECK_EXISTS(Qt5WinExtras, [lyx_use_winextras=true], [])
                if $lyx_use_winextras; then
diff --git a/development/cmake/config.h.cmake b/development/cmake/config.h.cmake
index 253d39f..95148b6 100644
--- a/development/cmake/config.h.cmake
+++ b/development/cmake/config.h.cmake
@@ -73,6 +73,9 @@
 // Defined if QT=QT5 uses X11
 #cmakedefine QPA_XCB 1
 
+// Define if you have the Qt5X11Extras module
+#cmakedefine HAVE_QT5_X11_EXTRAS 1
+
 ${Include_used_spellchecker}
 
 #cmakedefine AIKSAURUSLIB_FOUND 1
diff --git a/src/frontends/qt4/GuiApplication.cpp 
b/src/frontends/qt4/GuiApplication.cpp
index 6586207..6f48ed0 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -121,10 +121,14 @@
 #ifdef Q_WS_X11
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
+#include <QX11Info>
 #undef CursorShape
 #undef None
 #elif defined(QPA_XCB)
 #include <xcb/xcb.h>
+#ifdef HAVE_QT5_X11_EXTRAS
+#include <QtX11Extras/QX11Info>
+#endif
 #endif
 
 #if (QT_VERSION < 0x050000) || (QT_VERSION >= 0x050400)
@@ -3130,8 +3134,21 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
                BufferView * bv = current_view_->currentBufferView();
                if (bv) {
                        docstring const sel = bv->requestSelection();
-                       if (!sel.empty())
+                       if (!sel.empty()) {
                                d->selection_.put(sel);
+                               XSelectionEvent nev;
+                               nev.type = SelectionNotify;
+                               nev.display = xev->xselectionrequest.display;
+                               nev.requestor = 
xev->xselectionrequest.requestor;
+                               nev.selection = 
xev->xselectionrequest.selection;
+                               nev.target = xev->xselectionrequest.target;
+                               nev.property = 0L; // None
+                               nev.time = CurrentTime;
+                               XSendEvent(QX11Info::display(),
+                                       nev.requestor, False, 0,
+                                       reinterpret_cast<XEvent *>(&nev));
+                               return true;
+                       }
                }
                break;
        }
@@ -3166,8 +3183,24 @@ bool GuiApplication::nativeEventFilter(const QByteArray 
& eventType,
                BufferView * bv = current_view_->currentBufferView();
                if (bv) {
                        docstring const sel = bv->requestSelection();
-                       if (!sel.empty())
+                       if (!sel.empty()) {
                                d->selection_.put(sel);
+#ifdef HAVE_QT5_X11_EXTRAS
+                               xcb_selection_notify_event_t nev;
+                               nev.response_type = XCB_SELECTION_NOTIFY;
+                               nev.requestor = srev->requestor;
+                               nev.selection = srev->selection;
+                               nev.target = srev->target;
+                               nev.property = XCB_NONE;
+                               nev.time = XCB_CURRENT_TIME;
+                               xcb_connection_t * con = QX11Info::connection();
+                               xcb_send_event(con, 0, srev->requestor,
+                                       XCB_EVENT_MASK_NO_EVENT,
+                                       reinterpret_cast<char const *>(&nev));
+                               xcb_flush(con);
+#endif
+                               return true;
+                       }
                }
                break;
        }

Reply via email to