Skip to content

Commit

Permalink
opt: popup focus (#1635)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
xiaoyifang and autofix-ci[bot] authored Jul 5, 2024
1 parent 7252e7b commit 922b7c3
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/ui/scanpopup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -485,8 +479,6 @@ void ScanPopup::engagePopup( bool forcePopup, bool giveFocus )
return;
}

definition->setSelectionBySingleClick( cfg.preferences.selectWordBySingleClick );

if ( !isVisible() ) {
// Need to show the window

Expand Down Expand Up @@ -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();
Expand All @@ -558,24 +542,17 @@ 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 ) {
activateWindow();
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
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 922b7c3

Please sign in to comment.