mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Linux-specific: don't force X11 focus unnecessarily
Focus is already transferred to GoldenDict in toggleMainWindow() only the first time the main window is shown. At all subsequent requests to show the main window, focus has to be forced with the workaround. Checking focus asynchronously allows to resort to the workaround less often. Under Xfce: the timeout of 0 ms is almost always sufficient in the Qt 5 version, but is never enough in the Qt 4 version. The timeout of 4 ms is always sufficient in both versions. Under KDE Plasma: the timeout of 0 ms is rarely sufficient in the Qt 5 version. Unfortunately, with any timeout other than 0 ms, the Qt 5 version does not always get focus, which would be a serious regression, so no other timeout can be used. The Qt 4 version does not always get focus both with and without the timeout.
This commit is contained in:
parent
a321593ed1
commit
5f96f1f26e
|
@ -3078,10 +3078,19 @@ void MainWindow::toggleMainWindow( bool onlyShow )
|
|||
focusTranslateLine();
|
||||
|
||||
#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS
|
||||
if( !byIconClick )
|
||||
QTimer::singleShot( 0, this, SLOT( forceX11Focus() ) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS
|
||||
void MainWindow::forceX11Focus()
|
||||
{
|
||||
Window wh = 0;
|
||||
int rev = 0;
|
||||
XGetInputFocus( QX11Info::display(), &wh, &rev );
|
||||
if( wh != internalWinId() && !byIconClick )
|
||||
if( wh != internalWinId() )
|
||||
{
|
||||
QPoint const pointRelativeToRoot = mapToGlobal( QPoint( 0, 0 ) );
|
||||
XEvent event;
|
||||
|
@ -3104,9 +3113,8 @@ void MainWindow::toggleMainWindow( bool onlyShow )
|
|||
XSendEvent( QX11Info::display(), internalWinId(), true, 0xfff, &event );
|
||||
XFlush( QX11Info::display() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void MainWindow::installHotKeys()
|
||||
{
|
||||
|
|
|
@ -280,6 +280,10 @@ private:
|
|||
|
||||
private slots:
|
||||
|
||||
#ifdef X11_MAIN_WINDOW_FOCUS_WORKAROUNDS
|
||||
void forceX11Focus();
|
||||
#endif
|
||||
|
||||
void hotKeyActivated( int );
|
||||
|
||||
/// If new release checks are on, santizies the next check time and starts
|
||||
|
|
Loading…
Reference in a new issue