From 922b7c39c6e7fdb42bbfc0bf98900b9bac7c1456 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 5 Jul 2024 08:44:36 +0800 Subject: [PATCH] opt: popup focus (#1635) * opt: windows title * opt: popup focus * opt: windows title * [autofix.ci] apply automated fixes * opt: popup articleview setting --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/ui/scanpopup.cc | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/ui/scanpopup.cc b/src/ui/scanpopup.cc index ce097e24d..b649f8724 100644 --- a/src/ui/scanpopup.cc +++ b/src/ui/scanpopup.cc @@ -136,6 +136,7 @@ ScanPopup::ScanPopup( QWidget * parent, ui.groupList->setCurrentGroup( cfg.lastPopupGroupId ); definition->setCurrentGroupId( ui.groupList->getCurrentGroup() ); + definition->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick ); dictionaryBar.setFloatable( false ); Instances::Group const * igrp = groups.findGroup( cfg.lastPopupGroupId ); @@ -438,14 +439,7 @@ void ScanPopup::translateWord( QString const & word ) emit hideScanFlag(); #endif - engagePopup( false, -#ifdef Q_OS_WIN - true // We only focus popup under Windows when activated via Ctrl+C+C - // -- on Linux it already has an implicit focus -#else - false -#endif - ); + engagePopup( false, true ); } #ifdef HAVE_X11 @@ -485,8 +479,6 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) return; } - definition->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick ); - if ( !isVisible() ) { // Need to show the window @@ -536,14 +528,6 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) show(); -#if defined( HAVE_X11 ) - // Ensure that the window always has focus on X11 with Qt::Tool flag. - // This also often prevents the window from disappearing prematurely with Qt::Popup flag, - // especially when combined with Qt::X11BypassWindowManagerHint flag. - if ( !ui.pinButton->isChecked() ) - giveFocus = true; -#endif - if ( giveFocus ) { activateWindow(); raise(); @@ -558,7 +542,7 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) // This produced some funky mouse grip-related bugs so we commented it out //QApplication::processEvents(); // Make window appear immediately no matter what } - else if ( ui.pinButton->isChecked() ) { + else { // Pinned-down window isn't always on top, so we need to raise it show(); if ( cfg.preferences.raiseWindowOnSearch ) { @@ -566,16 +550,9 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) raise(); } } -#if defined( HAVE_X11 ) - else if ( ( windowFlags() & Qt::Tool ) == Qt::Tool && cfg.preferences.raiseWindowOnSearch ) { - // Ensure that the window with Qt::Tool flag always has focus on X11. - activateWindow(); - raise(); - } -#endif if ( ui.pinButton->isChecked() ) - setWindowTitle( tr( "%1 - %2" ).arg( elideInputWord(), "GoldenDict" ) ); + setWindowTitle( tr( "%1 - GoldenDict-ng" ).arg( elideInputWord() ) ); /// Too large strings make window expand which is probably not what user /// wants @@ -937,7 +914,7 @@ void ScanPopup::pinButtonClicked( bool checked ) setAttribute( Qt::WA_MacAlwaysShowToolWindow ); #endif - setWindowTitle( tr( "%1 - %2" ).arg( elideInputWord(), "GoldenDict" ) ); + setWindowTitle( tr( "%1 - GoldenDict-ng" ).arg( elideInputWord() ) ); dictionaryBar.setMovable( true ); hideTimer.stop(); }