Merge branch 'test-fix-gtk2' of https://github.com/AliKet/wxWidgets
Fix setting focus in GUI tests using wxUIActionSimulator with GTK 2.
Fixing the actual problem allows to re-enable activating the TLW in
SetFocus() (done in d06e97e8d9
(Make sure toplevel is active in
SetFocus(), 2020-07-08), see #18783) and remove the now unnecessary
workarounds in the tests too.
See https://github.com/wxWidgets/wxWidgets/pull/1945
This commit is contained in:
@@ -4583,13 +4583,9 @@ void wxWindowGTK::SetFocus()
|
|||||||
if (gs_currentFocus != this)
|
if (gs_currentFocus != this)
|
||||||
gs_pendingFocus = this;
|
gs_pendingFocus = this;
|
||||||
|
|
||||||
// We can't do this under GTK 2 as it breaks the GUI tests suite, but GTK 3
|
|
||||||
// tests are robust enough to pass even if we do this.
|
|
||||||
#ifdef __WXGTK3__
|
|
||||||
wxWindow* tlw = wxGetTopLevelParent(static_cast<wxWindow*>(this));
|
wxWindow* tlw = wxGetTopLevelParent(static_cast<wxWindow*>(this));
|
||||||
if (tlw && tlw->m_widget && !gtk_window_is_active(GTK_WINDOW(tlw->m_widget)))
|
if (tlw && tlw->m_widget && !gtk_window_is_active(GTK_WINDOW(tlw->m_widget)))
|
||||||
tlw->Raise();
|
tlw->Raise();
|
||||||
#endif // __WXGTK3__
|
|
||||||
|
|
||||||
GtkWidget *widget = m_wxwindow ? m_wxwindow : m_focusWidget;
|
GtkWidget *widget = m_wxwindow ? m_wxwindow : m_focusWidget;
|
||||||
|
|
||||||
|
@@ -130,27 +130,19 @@ protected:
|
|||||||
wxYield();
|
wxYield();
|
||||||
wxMilliSleep(50);
|
wxMilliSleep(50);
|
||||||
|
|
||||||
|
#ifndef __WXGTK3__
|
||||||
SetInputFocusToXWindow();
|
SetInputFocusToXWindow();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// This helper function tries to set the input focus to the active (top level)
|
// Workaround a focus problem happening with GTK2 when running under Xvfb,
|
||||||
// window, i.e.: the window to which keyboard events will be reported.
|
// i.e. keyboard and mouse events not delivered to the right window.
|
||||||
//
|
//
|
||||||
// Normally we would expect the input focus to be correctly set by the WM.
|
// This helper function tries to set the input focus to the active (top level)
|
||||||
// But for some reasons, the input focus is set to PointerRoot under Xvfb,
|
// window, i.e.: the window to which keyboard events will be delivered.
|
||||||
// which means: all keyboard events are forewarded to whatever is underneath
|
|
||||||
// mouse pointer. and consequently, our fake events could be simply lost and
|
|
||||||
// do not reach the subject window at all.
|
|
||||||
void SetInputFocusToXWindow()
|
void SetInputFocusToXWindow()
|
||||||
{
|
{
|
||||||
Window focus;
|
Window focus = None;
|
||||||
int revert_to; // dummy
|
|
||||||
|
|
||||||
XGetInputFocus(m_display, &focus, &revert_to);
|
|
||||||
|
|
||||||
if ( focus != PointerRoot && focus != None )
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxWindow* win = wxGetActiveWindow();
|
wxWindow* win = wxGetActiveWindow();
|
||||||
|
|
||||||
#if defined(__WXGTK20__)
|
#if defined(__WXGTK20__)
|
||||||
@@ -178,9 +170,10 @@ protected:
|
|||||||
wxUnusedVar(win);
|
wxUnusedVar(win);
|
||||||
#endif // platform
|
#endif // platform
|
||||||
|
|
||||||
wxLogTrace("focus", "SetInputFocusToXWindow on Window 0x%ul.", focus);
|
wxLogTrace("focus", "SetInputFocusToXWindow on Window 0x%lu.", focus);
|
||||||
|
|
||||||
XSetInputFocus(m_display, focus, RevertToPointerRoot, CurrentTime);
|
if ( focus != None )
|
||||||
|
XSetInputFocus(m_display, focus, RevertToPointerRoot, CurrentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxX11Display m_display;
|
wxX11Display m_display;
|
||||||
|
@@ -584,10 +584,6 @@ void MenuTestCase::Events()
|
|||||||
// Invoke the accelerator.
|
// Invoke the accelerator.
|
||||||
m_frame->Show();
|
m_frame->Show();
|
||||||
m_frame->SetFocus();
|
m_frame->SetFocus();
|
||||||
#ifdef __WXGTK__
|
|
||||||
// Without this, test fails when run with other tests under Xvfb.
|
|
||||||
m_frame->Raise();
|
|
||||||
#endif
|
|
||||||
wxYield();
|
wxYield();
|
||||||
|
|
||||||
wxUIActionSimulator sim;
|
wxUIActionSimulator sim;
|
||||||
|
@@ -211,16 +211,6 @@ void NumValidatorTestCase::Interactive()
|
|||||||
return;
|
return;
|
||||||
#endif // __WXMSW__
|
#endif // __WXMSW__
|
||||||
|
|
||||||
#ifdef __WXGTK20__
|
|
||||||
// Travis CI fails without this!
|
|
||||||
if ( IsAutomaticTest() )
|
|
||||||
{
|
|
||||||
wxFrame* frame = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
|
|
||||||
frame->SetFocus();
|
|
||||||
frame->Raise();
|
|
||||||
}
|
|
||||||
#endif // __WXGTK20__
|
|
||||||
|
|
||||||
// Set a locale using comma as thousands separator character.
|
// Set a locale using comma as thousands separator character.
|
||||||
wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);
|
wxLocale loc(wxLANGUAGE_ENGLISH_UK, wxLOCALE_DONT_LOAD_DEFAULT);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user