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

List:       kde-commits
Subject:    kdebase/klipper
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2004-11-10 17:26:26
Message-ID: 20041110172626.82F8C16C4F () office ! kde ! org
[Download RAW message or body]

CVS commit by lunakl: 

Protection against too many clipboard data changes. Lyx responds to clipboard data
requests with setting new clipboard data, so if Lyx takes over clipboard,
Klipper notices, requests this data, this triggers "new" clipboard contents
from Lyx, so Klipper notices again, requests this data, ... you get the idea.
Not that this doesn't really fix Lyx, almost no app is capable of retrieving clipboard
data from it, but the bug is in Lyx after all.
BUG: 84595


  M +24 -1     toplevel.cpp   1.158
  M +5 -1      toplevel.h   1.53


--- kdebase/klipper/toplevel.cpp  #1.157:1.158
@@ -61,9 +61,15 @@
 #define EMPTY (m_popup->count() - MENU_ITEMS)
 
+// Protection against too many clipboard data changes. Lyx responds to clipboard data
+// requests with setting new clipboard data, so if Lyx takes over clipboard,
+// Klipper notices, requests this data, this triggers "new" clipboard contents
+// from Lyx, so Klipper notices again, requests this data, ... you get the idea.
+const int MAX_CLIPBOARD_CHANGES = 10; // max changes per second
+
 extern bool qt_qclipboard_bailout_hack;
 
 // config == kapp->config for process, otherwise applet
 KlipperWidget::KlipperWidget( QWidget *parent, KConfig* config )
-    : QWidget( parent ), DCOPObject( "klipper" ), m_config( config )
+    : QWidget( parent ), DCOPObject( "klipper" ), mOverflowCounter( 0 ), m_config( config )
 {
     qt_qclipboard_bailout_hack = true;
@@ -73,4 +79,7 @@ KlipperWidget::KlipperWidget( QWidget *p
     m_selectedItem = -1;
 
+    connect( &mOverflowClearTimer, SIGNAL( timeout()), SLOT( slotClearOverflow()));
+    mOverflowClearTimer.start( 1000 );
+
     QSempty = i18n("<empty clipboard>");
 
@@ -637,4 +646,6 @@ void KlipperWidget::slotMoveSelectedToTo
 void KlipperWidget::newClipData()
 {
+    if( ++mOverflowCounter > MAX_CLIPBOARD_CHANGES )
+        return;
     bool selectionMode;
     QString clipContents = clipboardContents( &selectionMode );
@@ -645,4 +656,6 @@ void KlipperWidget::newClipData()
 void KlipperWidget::clipboardSignalArrived( bool selectionMode )
 {
+    if( ++mOverflowCounter > MAX_CLIPBOARD_CHANGES )
+        return;
     // Don't react on Klipper's own actions. This signal comes either
     // from this process when it sets the clipboard (in which case ignoring
@@ -753,4 +766,14 @@ void KlipperWidget::setClipboard( const 
 }
 
+void KlipperWidget::slotClearOverflow()
+{
+    if( mOverflowCounter > MAX_CLIPBOARD_CHANGES ) {
+        kdDebug() << "App owning the clipboard/selection is lame" << endl;
+        // update to the latest data - this unfortunately may trigger the problem again
+        newClipData();
+    }
+    mOverflowCounter = 0;
+}
+
 QStringList KlipperWidget::getClipboardHistoryMenu()
 {

--- kdebase/klipper/toplevel.h  #1.52:1.53
@@ -21,4 +21,5 @@
 #include <qpixmap.h>
 #include <dcopobject.h>
+#include <qtimer.h>
 
 class QClipboard;
@@ -110,4 +111,5 @@ private slots:
     void slotAboutToHideMenu();
 
+    void slotClearOverflow();
 
 private:
@@ -120,4 +122,5 @@ private:
     QString m_lastString;
     QString m_lastClipboard, m_lastSelection;
+    int mOverflowCounter;
     KPopupMenu *m_popup;
     KToggleAction *toggleURLGrabAction;
@@ -139,4 +142,5 @@ private:
     int URLGrabItem;
     KConfig* m_config;
+    QTimer mOverflowClearTimer;
     ClipboardPoll* poll;
     static KAboutData* about_data;


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

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