Richard Heck wrote:
Abdelrazak Younes wrote:
Richard Heck wrote:
First, the slowness is coming during the update of the standard toolbar, in particular, during the update of the PASTE button, and more precisely during the getStatus() call, and yet more precisely, during the theClipboard().empty() check. So I did this:
bool GuiClipboard::empty() const
{
   // We need to check both the plaintext and the LyX version of the
   // clipboard. The plaintext version is empty if the LyX version
   // contains only one inset, and the LyX version is empry if the
   // clipboard does not come from LyX.
   QTime t = QTime::currentTime();
   bool b = !qApp->clipboard()->text(QClipboard::Clipboard).isEmpty();
   lyxerr << "Checking emptiness took " << t.restart() << std::endl;
   if (b)
       return false;
   return !hasLyXContents();
}
and I'm getting times on the order of 125ms just for that one call.
Should be easy to solve.
Can you fix this, Abdel?

Here is a quick untested fix (hopefully).

One question, there is still something I don't understand in this issue. In principle the X11 Clipboard should not be triggered if the only thing you did was to select something in some other apps. The only way this could happen is when this other app automatically put the X11 selection in the X11 clipboard (which is bad). I've also read somewhere that KDE do something like this at desktop level... do you use KDE?

Abdel.
Index: GuiClipboard.cpp
===================================================================
--- GuiClipboard.cpp    (revision 20564)
+++ GuiClipboard.cpp    (working copy)
@@ -35,6 +35,15 @@
 namespace lyx {
 namespace frontend {
 
+GuiClipboard::GuiClipboard()
+{
+       connect(qApp->clipboard(), SIGNAL(dataChanged()),
+               this, SLOT(on_dataChanged()));
+       // initialize clipboard status.
+       on_dataChanged()
+}
+
+
 string const GuiClipboard::getAsLyX() const
 {
        LYXERR(Debug::ACTION) << "GuiClipboard::getAsLyX(): `";
@@ -109,16 +118,27 @@
 }
 
 
+void GuiClipboard::on_dataChanged()
+{
+       text_clipboard_empty_ = qApp->clipboard()->
+               text(QClipboard::Clipboard).isEmpty();
+
+       has_lyx_contents_ = hasLyXContents();
+}
+
+
 bool GuiClipboard::empty() const
 {
        // We need to check both the plaintext and the LyX version of the
        // clipboard. The plaintext version is empty if the LyX version
-       // contains only one inset, and the LyX version is empry if the
+       // contains only one inset, and the LyX version is empty if the
        // clipboard does not come from LyX.
-       if (!qApp->clipboard()->text(QClipboard::Clipboard).isEmpty())
+       if (!text_clipboard_empty_)
                return false;
-       return !hasLyXContents();
+       return !has_lyx_contents_;
 }
 
 } // namespace frontend
 } // namespace lyx
+
+#include "GuiClipboard_moc.cpp"
Index: GuiClipboard.h
===================================================================
--- GuiClipboard.h      (revision 20564)
+++ GuiClipboard.h      (working copy)
@@ -16,15 +16,19 @@
 
 #include "frontends/Clipboard.h"
 
+#include <QObject>
+
 namespace lyx {
 namespace frontend {
 
 /**
  * The Qt4 version of the Clipboard.
  */
-class GuiClipboard: public Clipboard
+class GuiClipboard: public QObject, public Clipboard
 {
+       Q_OBJECT
 public:
+       GuiClipboard();
        virtual ~GuiClipboard() {}
 
        /** Clipboard overloaded methods
@@ -37,6 +41,13 @@
        bool isInternal() const;
        bool empty() const;
        //@}
+
+private Q_SLOTS:
+       void on_dataChanged();
+
+private:
+       bool text_clipboard_empty_;
+       bool has_lyx_contents_;
 };
 
 } // namespace frontend

Reply via email to