From 06a296c99f7245a86afe69757dd0b46f31d6d2af Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Sat, 19 Nov 2022 13:48:26 -0500 Subject: [PATCH] Put conditions on the ClipboardChange for X11 --- keyboardstate.hh | 2 +- mainwindow.cc | 22 +++++++++++++++++----- mainwindow.hh | 2 +- scanpopup.cc | 10 +++++++--- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/keyboardstate.hh b/keyboardstate.hh index a48e60c0..9272cf42 100644 --- a/keyboardstate.hh +++ b/keyboardstate.hh @@ -27,7 +27,7 @@ public: /// Returns true if all Modifiers present within the given mask are pressed /// right now. - bool checkModifiersPressed( int mask ); + bool static checkModifiersPressed( int mask ); }; #endif diff --git a/mainwindow.cc b/mainwindow.cc index 7554266e..01dec078 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -49,6 +49,8 @@ #include "ui_authentication.h" #include "resourceschemehandler.h" +#include "keyboardstate.hh" + #ifdef Q_OS_MAC #include "macmouseover.hh" #endif @@ -908,15 +910,25 @@ MainWindow::MainWindow( Config::Class & cfg_ ): inspector.reset( new ArticleInspector( this )); - connect( QApplication::clipboard(), &QClipboard::dataChanged, this, &MainWindow::clipboardChange ); + connect( QApplication::clipboard(), &QClipboard::changed, this, &MainWindow::clipboardChange ); } -void MainWindow::clipboardChange( ) +void MainWindow::clipboardChange( QClipboard::Mode m) { - qDebug() << "clipboard change ," << scanPopup.get(); - if( scanPopup && enableScanningAction->isChecked() ) + if( scanPopup && enableScanningAction->isChecked() ) { - scanPopup->translateWordFromClipboard(); + if ( cfg.preferences.enableScanPopupModifiers && KeyboardState::checkModifiersPressed(cfg.preferences.scanPopupModifiers)) + { + if(m == QClipboard::Clipboard){ + if(!cfg.preferences.trackClipboardScan) return; + scanPopup->translateWordFromClipboard(); + } + + if(m == QClipboard::Selection){ + if(!cfg.preferences.trackSelectionScan) return; + scanPopup->translateWordFromSelection(); + } + } } } diff --git a/mainwindow.hh b/mainwindow.hh index 72ba0995..b57c1ba1 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -484,7 +484,7 @@ private slots: void showGDHelp(); void hideGDHelp(); - void clipboardChange( ); + void clipboardChange(QClipboard::Mode m); void inspectElement( QWebEnginePage * ); diff --git a/scanpopup.cc b/scanpopup.cc index 25b73664..57ce7ee9 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -522,11 +522,15 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m ) #ifdef HAVE_X11 if( cfg.preferences.ignoreOwnClipboardChanges && ownsClipboardMode( m ) ) return; -#endif - GD_DPRINTF( "clipboard changed\n" ); + if(m == QClipboard::Clipboard && !cfg.preferences.trackClipboardScan){ + return; + } + + if(m == QClipboard::Selection && !cfg.preferences.trackSelectionScan){ + return; + } -#ifdef HAVE_X11 if( m == QClipboard::Selection ) { // Use delay show to prevent multiple popups while selection in progress