Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the user disable main window stealing focus when searching. #387

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ Preferences::Preferences():
, limitInputPhraseLength( false )
, inputPhraseLengthLimit( 1000 )
, maxDictionaryRefsInContextMenu ( 20 )
, synonymSearchEnabled( true )
, stripClipboard( false )
, synonymSearchEnabled( true ),
stripClipboard( false ),
raiseWindowOnSearch(true)
{
}

Expand Down Expand Up @@ -1041,6 +1042,9 @@ Class load()
if ( !preferences.namedItem( "stripClipboard" ).isNull() )
c.preferences.stripClipboard = ( preferences.namedItem( "stripClipboard" ).toElement().text() == "1" );

if( !preferences.namedItem( "raiseWindowOnSearch" ).isNull() )
c.preferences.raiseWindowOnSearch = ( preferences.namedItem( "raiseWindowOnSearch" ).toElement().text() == "1" );

QDomNode fts = preferences.namedItem( "fullTextSearch" );

if ( !fts.isNull() )
Expand Down Expand Up @@ -2032,6 +2036,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.stripClipboard ? "1" : "0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "raiseWindowOnSearch" );
opt.appendChild( dd.createTextNode( c.preferences.raiseWindowOnSearch ? "1" : "0" ) );
preferences.appendChild( opt );

{
QDomNode hd = dd.createElement( "fullTextSearch" );
preferences.appendChild( hd );
Expand Down
1 change: 1 addition & 0 deletions config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ struct Preferences

bool synonymSearchEnabled;
bool stripClipboard;
bool raiseWindowOnSearch;

QString addonStyle;

Expand Down
10 changes: 5 additions & 5 deletions mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2934,12 +2934,12 @@ void MainWindow::toggleMainWindow( bool onlyShow )
raise();
shown = true;
}
else
if ( !isActiveWindow() )
{
else if( !isActiveWindow() ) {
qApp->setActiveWindow( this );
raise();
activateWindow();
if( cfg.preferences.raiseWindowOnSearch ) {
raise();
activateWindow();
}
shown = true;
}
else
Expand Down
3 changes: 3 additions & 0 deletions preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):

ui.stripClipboard->setChecked( p.stripClipboard );

ui.raiseWindowOnSearch->setChecked( p.raiseWindowOnSearch );

ui.maxDictsInContextMenu->setValue( p.maxDictionaryRefsInContextMenu );

// Different platforms have different keys available
Expand Down Expand Up @@ -443,6 +445,7 @@ Config::Preferences Preferences::getPreferences()
p.ignoreDiacritics = ui.ignoreDiacritics->isChecked();
p.ignorePunctuation = ui.ignorePunctuation->isChecked();
p.stripClipboard = ui.stripClipboard->isChecked();
p.raiseWindowOnSearch = ui.raiseWindowOnSearch->isChecked();

p.synonymSearchEnabled = ui.synonymSearchEnabled->isChecked();

Expand Down
7 changes: 7 additions & 0 deletions preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,13 @@ from Stardict, Babylon and GLS dictionaries</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="raiseWindowOnSearch">
<property name="text">
<string>On a new search, focus the main or popup window even if it's visible</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_17">
<property name="orientation">
Expand Down
14 changes: 6 additions & 8 deletions scanpopup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,16 @@ 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 if( ui.pinButton->isChecked() ) {
// Pinned-down window isn't always on top, so we need to raise it
show();
Copy link
Owner

@xiaoyifang xiaoyifang Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show() should this method be called at all conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show() should this method be called at all conditions?

I think so. I will change that.

activateWindow();
raise();
if( cfg.preferences.raiseWindowOnSearch ) {
activateWindow();
raise();
}
}
#if defined( HAVE_X11 )
else
if ( ( windowFlags() & Qt::Tool ) == Qt::Tool )
{
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();
Expand Down