Skip to content

Commit

Permalink
[rpi] Issue #266 - Fix for keypresses being cached w/ sfml-pi build (…
Browse files Browse the repository at this point in the history
…non-X11)

- Also addresses a related UI responsiveness (menus etc) bug when using
keyboard-based input
  • Loading branch information
mickelson committed Nov 4, 2016
1 parent dbcc5c8 commit 1ef8212
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,16 @@ void FeOverlay::init_event_loop( FeEventLoopCtx &ctx )
//
const sf::Transform &t = m_fePresent.get_transform();

#ifdef USE_GLES
// get_current_state() doesn't work reliably on RPI w/ sfml-pi (non-X11 custom SFML)
// so we reduce the timeout here for better UI performance
int to_sec( 1 );
#else
int to_sec( 6 );
#endif

sf::Clock timer;
while (( timer.getElapsedTime() < sf::seconds( 6 ) )
while (( timer.getElapsedTime() < sf::seconds( to_sec ) )
&& ( m_feSettings.get_current_state( FeInputMap::Back )
|| m_feSettings.get_current_state( FeInputMap::ExitNoMenu )
|| m_feSettings.get_current_state( FeInputMap::Select ) ))
Expand Down
22 changes: 22 additions & 0 deletions src/fe_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,33 @@ bool FeWindow::run()
// Empty the window event queue, so we don't go triggering other
// right away after running an emulator
sf::Event ev;

#if defined(USE_GLES)
// Unruly hack for RPI w/ custom sfml-pi (non-X11 version of SFML):
//
// Keypresses made in the emulator are all cached and replayed in
// the frontend after exiting the emulator. pollEvent() isn't
// behaving correctly when we first return from the emulator.
//
// On my RPI3, repeating the call every 10ms for 60ms after the
// return fixes the problem. We are doing this 180ms just to err
// on the side of caution until a better fix can be found...
for ( int i=0; i<18; i++ )
{
sf::sleep( sf::milliseconds( 10 ) );
while (isOpen() && pollEvent(ev))
{
if ( ev.type == sf::Event::Closed )
return false;
}
}
#else
while (isOpen() && pollEvent(ev))
{
if ( ev.type == sf::Event::Closed )
return false;
}
#endif

return true;
}
Expand Down

0 comments on commit 1ef8212

Please sign in to comment.