From f503fe586b063197eae09a083b3c7001c69ddeda Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Fri, 28 Oct 2022 10:49:27 +0800 Subject: [PATCH 01/12] add new clang format style --- .clang-format | 54 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/.clang-format b/.clang-format index a845f039..f6756c96 100644 --- a/.clang-format +++ b/.clang-format @@ -1,29 +1,65 @@ # Format Style Options - Created with Clang Power Tools --- -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: AcrossComments +AccessModifierOffset: -1 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveAssignments: Consecutive AlignEscapedNewlines: Left -AlignOperands: Align +AlignOperands: DontAlign +AlignTrailingComments: false AllowAllArgumentsOnNextLine: false -AllowShortBlocksOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: Never +AllowShortBlocksOnASingleLine: Empty +AllowShortLambdasOnASingleLine: None +AllowShortEnumsOnASingleLine: false +AlwaysBreakBeforeMultilineStrings: true BasedOnStyle: LLVM BinPackArguments: false BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: true + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: false + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: false + SplitEmptyNamespace: false + BeforeLambdaBody: false + BeforeWhile: false BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Allman +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: false BreakConstructorInitializers: AfterColon +BreakStringLiterals: false ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth : 2 ContinuationIndentWidth: 2 -MaxEmptyLinesToKeep: 1 +DeriveLineEnding: false +EmptyLineBeforeAccessModifier: Leave +ExperimentalAutoDetectBinPacking: true +FixNamespaceComments: false +IncludeBlocks: Regroup +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: Inner PointerAlignment: Middle +ReflowComments: false SortIncludes: false SortUsingDeclarations: false +SpaceAfterCStyleCast: true +SpaceBeforeCtorInitializerColon: false +SpaceBeforeInheritanceColon: false SpaceBeforeParens: Never SpacesInAngles: true +SpacesInConditionalStatement: true SpacesInParentheses: true SpacesInSquareBrackets: true UseTab: Never From e66380763f454dec4ab9e576d95a3db10116b6b1 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Tue, 1 Nov 2022 17:40:20 +0800 Subject: [PATCH 02/12] Revert "fix possible crash in archlinux" This reverts commit 971909177662ac78fad6fce5cf206f3a32e8c997. Revert "fix crash on archlinux" This reverts commit 0dc2b4d416a7b62f189c8cf1c85ca19b839f4087. --- articleview.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/articleview.cc b/articleview.cc index 8d141f00..4766d413 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2078,7 +2078,7 @@ void ArticleView::resourceDownloadFinished() { if ( (*i)->isFinished() ) { - if ( (*i)->dataSize() > 0 ) + if ( (*i)->dataSize() >= 0 ) { // Ok, got one finished, all others are irrelevant now @@ -2759,7 +2759,7 @@ void ResourceToSaveHandler::downloadFinished() { if ( (*i)->isFinished() ) { - if ( (*i)->dataSize() > 0 && !alreadyDone ) + if ( (*i)->dataSize() >= 0 && !alreadyDone ) { QByteArray resourceData; vector< char > const & data = (*i)->getFullData(); From 10972abcf4140977a79616472f220568162e8897 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Tue, 1 Nov 2022 20:21:16 +0800 Subject: [PATCH 03/12] [clean] remove code in dictionarybar eventfilter --- dictionarybar.cc | 44 +------------------------------------------- dictionarybar.hh | 4 ---- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/dictionarybar.cc b/dictionarybar.cc index 63738df7..a909cc7e 100644 --- a/dictionarybar.cc +++ b/dictionarybar.cc @@ -16,8 +16,7 @@ DictionaryBar::DictionaryBar( QWidget * parent, mutedDictionaries( 0 ), configEvents( events ), editDictionaryCommand( _editDictionaryCommand ), - maxDictionaryRefsInContextMenu(maxDictionaryRefsInContextMenu_), - timerId( 0 ) + maxDictionaryRefsInContextMenu(maxDictionaryRefsInContextMenu_) { setObjectName( "dictionaryBar" ); @@ -28,8 +27,6 @@ DictionaryBar::DictionaryBar( QWidget * parent, connect( this, SIGNAL(actionTriggered(QAction*)), this, SLOT(actionWasTriggered(QAction*)) ); - - installEventFilter( this ); } static QString elideDictName( QString const & name ) @@ -352,42 +349,3 @@ void DictionaryBar::dictsPaneClicked( const QString & id ) } } } - -bool DictionaryBar::eventFilter( QObject * obj, QEvent * ev ) -{ - if(obj == this && !isFloating() ) - { - QPoint pt = parentWidget()->mapFromGlobal( QCursor::pos() ); - switch( ev->type() ) - { - case QEvent::Leave : if( geometry().contains( pt ) ) - { - if( timerId ) - killTimer( timerId ); - timerId = startTimer( 500 ); - return true; - } - break; - case QEvent::Enter : if( timerId != 0) - { - killTimer( timerId ); - timerId = 0; - } - break; - case QEvent::Timer: if( static_cast< QTimerEvent * >( ev )->timerId() == timerId ) - { - if( !geometry().contains( pt ) ) - { - killTimer( timerId ); - timerId = 0; - QEvent event( QEvent::Leave ); - QApplication::sendEvent( this, &event ); - } - return true; - } - break; - default: break; - } - } - return false; -} diff --git a/dictionarybar.hh b/dictionarybar.hh index d108e381..2f886d24 100644 --- a/dictionarybar.hh +++ b/dictionarybar.hh @@ -61,10 +61,6 @@ private: QList< QAction * > dictActions; QAction * maxDictionaryRefsAction; - int timerId; - - virtual bool eventFilter( QObject *, QEvent * ); - protected: void contextMenuEvent( QContextMenuEvent * event ); From 59ec8c4a48f451e1b1e1ebe64652c53773dc926b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Wed, 2 Nov 2022 20:42:39 +0800 Subject: [PATCH 04/12] [clean code]: remove macos lionsupport check this macos version is too old . --- goldendict.pro | 3 +-- lionsupport.h | 23 ----------------------- lionsupport.mm | 34 ---------------------------------- mainwindow.cc | 5 ----- 4 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 lionsupport.h delete mode 100644 lionsupport.mm diff --git a/goldendict.pro b/goldendict.pro index 381d6a21..29e8914a 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -226,8 +226,7 @@ mac { LIBS += -L/opt/homebrew/lib -L/usr/local/lib -framework AppKit -framework Carbon } - OBJECTIVE_SOURCES += lionsupport.mm \ - machotkeywrapper.mm \ + OBJECTIVE_SOURCES += machotkeywrapper.mm \ macmouseover.mm \ speechclient_mac.mm ICON = icons/macicon.icns diff --git a/lionsupport.h b/lionsupport.h deleted file mode 100644 index 2fd1d897..00000000 --- a/lionsupport.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef LIONSUPPORT_H -#define LIONSUPPORT_H - -#include "mainwindow.hh" - -class LionSupport -{ -public: - /** - * Returns whether the current system is Lion. - */ - static bool isLion(); - - /** - * Adds fullscreen button to window for Lion. - */ - static void addFullscreen(MainWindow *window); - - //Check for retina display - static bool isRetinaDisplay(); -}; - -#endif // LIONSUPPORT_H diff --git a/lionsupport.mm b/lionsupport.mm deleted file mode 100644 index 1917b8f9..00000000 --- a/lionsupport.mm +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include "lionsupport.h" - -bool LionSupport::isLion() -{ - NSString *string = [NSString string]; - // this selector was added only in Lion. so we can check if it's responding, we are on Lion - return [string respondsToSelector:@selector(linguisticTagsInRange:scheme:options:orthography:tokenRanges:)]; -} - -void LionSupport::addFullscreen(MainWindow *window) -{ -#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (isLion()) // checks if lion is running - { - NSView *nsview = (NSView *) window->winId(); - NSWindow *nswindow = [nsview window]; - [nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; - } -#else -#warning No fullscreen support will be included in this build -#endif -} - -bool LionSupport::isRetinaDisplay() -{ -#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - return( [ [ NSScreen mainScreen ] respondsToSelector:@selector( backingScaleFactor ) ] - && [ [ NSScreen mainScreen ] backingScaleFactor ] > 1.5 ); -#else - return false; -#endif -} diff --git a/mainwindow.cc b/mainwindow.cc index a7e7de0b..af6bbe5b 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -50,7 +50,6 @@ #include "resourceschemehandler.h" #ifdef Q_OS_MAC -#include "lionsupport.h" #include "macmouseover.hh" #endif @@ -907,10 +906,6 @@ MainWindow::MainWindow( Config::Class & cfg_ ): history.setSaveInterval( cfg.preferences.historyStoreInterval ); - #ifdef Q_OS_MAC - LionSupport::addFullscreen(this); - #endif - ui.centralWidget->grabGesture( Gestures::GDPinchGestureType ); ui.centralWidget->grabGesture( Gestures::GDSwipeGestureType ); From c7c8b6f632b1b3abff10fa6d5dec7ffdc031ef91 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 2 Nov 2022 16:27:03 +0200 Subject: [PATCH 05/12] git clone URL in README: git:// => https:// scheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An attempt to clone the git:// URL fails on my Manjaro GNU/Linux system and produces the following output: $ git clone git://github.com/goldendict/goldendict.git Cloning into 'goldendict'... fatal: unable to connect to github.com: github.com[0: 140.82.121.4]: errno=Connection timed out 128✗ The GitHub UI offers the replacement https:// URL when the green Code button in the GoldenDict repository is clicked. Fixes #1561. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c7712fc..5b8f01af 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This code has been run and tested on Windows XP/Vista/7, Ubuntu Linux, Mac OS X. First, clone this repository, e.g.: - git clone git://github.com/goldendict/goldendict.git + git clone https://github.com/goldendict/goldendict.git And then invoke `qmake-qt4` and `make`: From 9330c89e4b0f39328e4b5fc2c0ee63fcfeeb249b Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 29 Oct 2022 10:05:26 +0300 Subject: [PATCH 06/12] Don't attempt to translate empty or whitespace-only text Silently ignore empty or whitespace-only translation requests. It should be clear to most users why GoldenDict ignores them. The translated word ends up as the "word" URL query item value, which is trimmed in ArticleNetworkAccessManager::getResource(). So the added trimming in MainWindow::translateInputFinished() should be fine. When a trimmed translated word was empty, InputPhrase::isValid() returned false, ArticleNetworkAccessManager::getResource() returned a null pointer and ArticleNetworkAccessManager::createRequest() fell back to QNetworkAccessManager::createRequest(), which: * failed silently in the Qt 4 version; * displayed the Protocol "gdlookup" is unknown Failed to load URL gdlookup://localhost?word= &group=4. QtNetwork Error 301 error page in the Qt 5 version. Fixes #1179. --- mainwindow.cc | 5 ++++- scanpopup.cc | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index fdea2925..680a6466 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2343,7 +2343,10 @@ void MainWindow::updateSuggestionList( QString const & newValue ) void MainWindow::translateInputFinished( bool checkModifiers ) { - QString word = Folding::unescapeWildcardSymbols( translateLine->text() ); + QString word = translateLine->text().trimmed(); + if( word.isEmpty() ) + return; + word = Folding::unescapeWildcardSymbols( word ); respondToTranslationRequest( Config::InputPhrase( word, translateBoxSuffix ), checkModifiers ); } diff --git a/scanpopup.cc b/scanpopup.cc index 4de1ca95..764c5eb3 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -805,7 +805,10 @@ void ScanPopup::updateSuggestionList( QString const & text ) void ScanPopup::translateInputFinished() { - inputPhrase.phrase = Folding::unescapeWildcardSymbols( ui.translateBox->translateLine()->text().trimmed() ); + QString const word = ui.translateBox->translateLine()->text().trimmed(); + if( word.isEmpty() ) + return; + inputPhrase.phrase = Folding::unescapeWildcardSymbols( word ); inputPhrase.punctuationSuffix = translateBoxSuffix; showTranslationFor( inputPhrase ); } From cf84f57632cd314fd4e1600ec0297ad054a598c0 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 29 Oct 2022 13:32:17 +0300 Subject: [PATCH 07/12] Don't append duplicates to openedInspectors There is no benefit in storing the same pointer multiple times in openedInspectors. This occurred when an article inspector window was closed then shown again. When the tab corresponding to the duplicated article inspector pointer was closed, ArticleInspector::beforeClosed() erased only one pointer from openedInspectors. This left dangling duplicate pointer(s) in the list and eventually caused a crash when another inspector's showEvent() accessed a dangling pointer at openedInspectors.front(). --- articleinspector.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/articleinspector.cc b/articleinspector.cc index 7ab091a7..2d1c2006 100644 --- a/articleinspector.cc +++ b/articleinspector.cc @@ -47,7 +47,8 @@ void ArticleInspector::showEvent( QShowEvent * event ) setGeometry( p->geometry() ); } - openedInspectors.push_back( this ); + if( std::find( openedInspectors.begin(), openedInspectors.end(), this ) == openedInspectors.end() ) + openedInspectors.push_back( this ); QWebInspector::showEvent( event ); } From 307fe2ba16e7ae052ec338206236f3e0cdcdada2 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Wed, 2 Nov 2022 20:12:42 +0200 Subject: [PATCH 08/12] Download and open an image double-clicked in scan popup Now double-clicking an image has the same effect in the main window and in the scan popup. This consistency in no way prevents or hinders using the popup window as designed (for fast lookup in a small group of dictionaries), because a user is unlikely to double-click an image accidentally. Without this commit, when "Double-click translates the word clicked" option is on, double-clicking an image in the scan popup translates currently selected text if the selection is not empty. Fixes #1279. --- articleview.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/articleview.cc b/articleview.cc index 5d48d196..58f51abb 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2320,7 +2320,7 @@ void ArticleView::doubleClicked( QPoint pos ) QWebHitTestResult r = ui.definition->page()->mainFrame()->hitTestContent( pos ); QWebElement el = r.element(); QUrl imageUrl; - if( !popupView && el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 ) + if( el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 ) { // Double click on image; download it and transfer to external program From 6dc74a7c7b1fc082ac1df4ff355ec1d8927c90a3 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Thu, 3 Nov 2022 16:58:44 +0200 Subject: [PATCH 09/12] Assign correct values to XButtonEvent::[xy]_root The signature is: QPoint QWidget::mapToGlobal(const QPoint &) const; --- mainwindow.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index 680a6466..53b14ffd 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -3050,15 +3050,14 @@ void MainWindow::toggleMainWindow( bool onlyShow ) XGetInputFocus( QX11Info::display(), &wh, &rev ); if( wh != translateLine->internalWinId() && !byIconClick ) { - QPoint p( 1, 1 ); - mapToGlobal( p ); + QPoint const pointRelativeToRoot = mapToGlobal( QPoint( 1, 1 ) ); XEvent event; memset( &event, 0, sizeof( event) ); event.type = ButtonPress; event.xbutton.x = 1; event.xbutton.y = 1; - event.xbutton.x_root = p.x(); - event.xbutton.y_root = p.y(); + event.xbutton.x_root = pointRelativeToRoot.x(); + event.xbutton.y_root = pointRelativeToRoot.y(); event.xbutton.window = internalWinId(); event.xbutton.root = QX11Info::appRootWindow( QX11Info::appScreen() ); event.xbutton.state = Button1Mask; From a27a29aca31c8a294a89f7229b2a5811ff119bc8 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Thu, 3 Nov 2022 15:09:44 +0200 Subject: [PATCH 10/12] Linux-specific: don't open File menu after showing main window Unfortunately the X11 focus workaround that opens the File menu cannot be simply removed. Without this workaround, when KDE Plasma's Focus stealing prevention level is set to Low (which is the default) or higher, launching a second GoldenDict instance doesn't give focus to the already running instance unless that instance's main window is currently hidden into system tray or minimized. A workaround of hiding then showing the main window makes the window flicker. Suggesting GoldenDict users to set the focus stealing prevention level to None is not right, because this setting is global and affects all applications. Emulate a left mouse button click at position (0, 0) instead of (1, 1) in order to waste 1 rather than 2 pixels to the left of the menu bar. Introduce a new macro X11_MAIN_WINDOW_FOCUS_WORKAROUNDS to link the X11 focus workaround to the File menu workaround introduced in this commit. This simplifies disabling all related workarounds at once. When the focus workaround is replaced with a proper solution, the developer won't forget to remove all obsolete workarounds if they are linked together. Fixes #781. --- mainwindow.cc | 50 +++++++++++++++++++++++++++++++++++++++++++------- mainwindow.hh | 8 +++++++- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index 53b14ffd..b41d6f57 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -63,7 +63,7 @@ #endif -#ifdef HAVE_X11 +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS #include #include #include @@ -76,6 +76,26 @@ using std::wstring; using std::map; using std::pair; +namespace { + +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS +class MinimumSizeWidget: public QWidget +{ + Q_OBJECT +public: + explicit MinimumSizeWidget( QWidget * parent ): + QWidget( parent ) + { + setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); + } + + virtual QSize sizeHint() const + { return QSize( 1, 1 ); } +}; +#endif + +} // unnamed namespace + #ifndef QT_NO_OPENSSL class InitSSLRunnable : public QRunnable @@ -853,6 +873,18 @@ MainWindow::MainWindow( Config::Class & cfg_ ): connect( &newReleaseCheckTimer, SIGNAL( timeout() ), this, SLOT( checkForNewRelease() ) ); +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS + // The X11 focus workaround in toggleMainWindow() emulates a left mouse button + // click on the top-left pixel of the main GoldenDict window. This hack steals + // focus from other applications reliably, but it also performs this click at + // the position that belongs to the File menu in the default KDE Plasma style, + // because the menu bar has no left margin there. + // Insert a minimum-size widget, which ignores mouse clicks, to the left of the + // menu bar to work around opening of the File menu each time the main window + // is shown (e.g. via a hotkey or when another GoldenDict instance is launched). + menuBar()->setCornerWidget( new MinimumSizeWidget( this ), Qt::TopLeftCorner ); +#endif + if ( cfg.preferences.hideMenubar ) { toggleMenuBarTriggered( false ); @@ -2945,7 +2977,7 @@ void MainWindow::showTranslationFor( QString const & inWord, ignoreDiacritics ); } -#ifdef HAVE_X11 +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS void MainWindow::toggleMainWindow( bool onlyShow, bool byIconClick ) #else void MainWindow::toggleMainWindow( bool onlyShow ) @@ -3044,18 +3076,18 @@ void MainWindow::toggleMainWindow( bool onlyShow ) ftsDlg->show(); focusTranslateLine(); -#ifdef HAVE_X11 +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS Window wh = 0; int rev = 0; XGetInputFocus( QX11Info::display(), &wh, &rev ); if( wh != translateLine->internalWinId() && !byIconClick ) { - QPoint const pointRelativeToRoot = mapToGlobal( QPoint( 1, 1 ) ); + QPoint const pointRelativeToRoot = mapToGlobal( QPoint( 0, 0 ) ); XEvent event; memset( &event, 0, sizeof( event) ); event.type = ButtonPress; - event.xbutton.x = 1; - event.xbutton.y = 1; + event.xbutton.x = 0; + event.xbutton.y = 0; event.xbutton.x_root = pointRelativeToRoot.x(); event.xbutton.y_root = pointRelativeToRoot.y(); event.xbutton.window = internalWinId(); @@ -3275,7 +3307,7 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r ) switch(r) { case QSystemTrayIcon::Trigger: // Left click toggles the visibility of main window -#ifdef HAVE_X11 +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS toggleMainWindow( false, true ); #else toggleMainWindow(); @@ -4933,3 +4965,7 @@ bool MainWindow::isGoldenDictWindow( HWND hwnd ) } #endif + +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS +#include "mainwindow.moc" +#endif diff --git a/mainwindow.hh b/mainwindow.hh index 87cd959d..b98cc85b 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -36,6 +36,12 @@ #include #endif +#ifdef HAVE_X11 + // TODO: implement startup notification support and remove these workarounds + // (see investigation comments on #781). + #define X11_MAIN_WINDOW_FOCUS_WORKAROUNDS +#endif + using std::string; using std::vector; @@ -230,7 +236,7 @@ private: /// Brings the main window to front if it's not currently, or hides it /// otherwise. The hiding part is omitted if onlyShow is true. -#ifdef HAVE_X11 +#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS void toggleMainWindow( bool onlyShow = false, bool byIconClick = false ); #else void toggleMainWindow( bool onlyShow = false ); From 208cd509797692b9dab22b2562b649d3b3878b6e Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Fri, 4 Nov 2022 21:23:42 +0800 Subject: [PATCH 11/12] fix: when history forward/back ,the founded dictionary does not change fixed #184 --- article_maker.cc | 3 ++- articleview.cc | 12 +++++++----- articleview.hh | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/article_maker.cc b/article_maker.cc index b27c53fd..d93273f6 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -429,9 +429,10 @@ ArticleRequest::ArticleRequest( data.resize( header.size() ); memcpy( &data.front(), header.data(), header.size() ); - // Accumulate main forms + //clear founded dicts. emit GlobalBroadcaster::instance()->dictionaryClear( ActiveDictIds{word} ); + // Accumulate main forms for( unsigned x = 0; x < activeDicts.size(); ++x ) { sptr< Dictionary::WordSearchRequest > s = activeDicts[ x ]->findHeadwordsForSynonym( gd::toWString( word ) ); diff --git a/articleview.cc b/articleview.cc index 4766d413..b1f4cd53 100644 --- a/articleview.cc +++ b/articleview.cc @@ -401,6 +401,7 @@ void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned g Contexts const & contexts_ ) { currentWord = phrase.phrase.trimmed(); + historyMode = false; currentActiveDictIds.clear(); // first, let's stop the player audioPlayer->stop(); @@ -484,6 +485,7 @@ void ArticleView::showDefinition( QString const & word, QStringList const & dict if( dictIDs.isEmpty() ) return; currentWord = word.trimmed(); + historyMode = false; // first, let's stop the player audioPlayer->stop(); @@ -1623,6 +1625,8 @@ void ArticleView::back() if ( canGoBack() ) { saveHistoryUserData(); + currentActiveDictIds.clear(); + historyMode = true; ui.definition->back(); } } @@ -1630,6 +1634,8 @@ void ArticleView::back() void ArticleView::forward() { saveHistoryUserData(); + currentActiveDictIds.clear(); + historyMode = true; ui.definition->forward(); } @@ -2619,7 +2625,7 @@ void ArticleView::highlightAllFtsOccurences( QWebEnginePage::FindFlags flags ) } void ArticleView::setActiveDictIds(ActiveDictIds ad) { - if (ad.word == currentWord) { + if (ad.word == currentWord || historyMode) { // ignore all other signals. qDebug() << "receive dicts, current word:" << currentWord << ad.word << ":" << ad.dictIds; currentActiveDictIds << ad.dictIds; @@ -2712,10 +2718,6 @@ void ArticleView::performFtsFindOperation( bool backwards ) #endif ui.ftsSearchStatusLabel->setText( searchStatusMessage( ftsPosition + 1, allMatches.size() ) ); - // Store new highlighted selection - // ui.definition->page()-> - // runJavaScript( QString( "%1=window.getSelection().getRangeAt(0);_=0;" ) - // .arg( rangeVarName ) ); } void ArticleView::on_ftsSearchPrevious_clicked() diff --git a/articleview.hh b/articleview.hh index c4131053..32f5b9b3 100644 --- a/articleview.hh +++ b/articleview.hh @@ -70,6 +70,8 @@ class ArticleView: public QFrame /// current active dict id list; QStringList currentActiveDictIds; + bool historyMode=false; + //current active dictionary id; QString activeDictId; From 6d9a6c3d6bd613e3f53f7e1a46ef2fc2fbdf9e20 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Fri, 4 Nov 2022 21:25:55 +0800 Subject: [PATCH 12/12] fix:return directly when the searched word is empty --- articleview.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/articleview.cc b/articleview.cc index b1f4cd53..9263e01e 100644 --- a/articleview.cc +++ b/articleview.cc @@ -401,6 +401,8 @@ void ArticleView::showDefinition( Config::InputPhrase const & phrase, unsigned g Contexts const & contexts_ ) { currentWord = phrase.phrase.trimmed(); + if( currentWord.isEmpty() ) + return; historyMode = false; currentActiveDictIds.clear(); // first, let's stop the player @@ -485,6 +487,8 @@ void ArticleView::showDefinition( QString const & word, QStringList const & dict if( dictIDs.isEmpty() ) return; currentWord = word.trimmed(); + if( currentWord.isEmpty() ) + return; historyMode = false; // first, let's stop the player audioPlayer->stop();