diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-03-25 16:34:40 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-03-25 16:34:40 +0000 |
| commit | 832377fc21fb5b44f419c17322ca95abdbf8db4a (patch) | |
| tree | bb4f02fe33e46ff9f0650c41a0fcb59935633704 /src/drivers/Android/Fl_Android_Screen_Driver.cxx | |
| parent | 0e765c6cd8e573476718a266108a498808491782 (diff) | |
Android: Improved event handling to handle all pending events before redrawing the interface.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12799 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Android/Fl_Android_Screen_Driver.cxx')
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.cxx | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index 7be726938..4a3f8484d 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -304,6 +304,7 @@ int Fl_Android_Screen_Driver::handle_mouse_event(AInputQueue *queue, AInputEvent */ int Fl_Android_Screen_Driver::handle_queued_events(double time_to_wait) { + AInputQueue *queue = Fl_Android_Application::input_event_queue(); int ret = 0; // Read all pending events. int ident; @@ -311,8 +312,8 @@ int Fl_Android_Screen_Driver::handle_queued_events(double time_to_wait) int delay_millis = time_to_wait*1000; bool done = false; -// while (!done) { - int delay = Fl::damage() ? 0 : delay_millis; + int delay = Fl::damage() ? 0 : delay_millis; + while (!done) { ident = ALooper_pollOnce(delay, nullptr, &events, nullptr); switch (ident) { case Fl_Android_Application::LOOPER_ID_MAIN: @@ -325,30 +326,37 @@ int Fl_Android_Screen_Driver::handle_queued_events(double time_to_wait) timer_do_callback(Fl_Android_Application::receive_timer_index()); break; case ALOOPER_POLL_WAKE: - Fl_Android_Application::log_e("Someone woke up ALooper_pollAll."); + Fl_Android_Application::log_e("Someone woke up ALooper_pollOnce."); done = true; break; case ALOOPER_POLL_CALLBACK: Fl_Android_Application::log_e( - "Someone added a callback to ALooper_pollAll."); + "Someone added a callback to ALooper_pollOnce."); done = true; break; case ALOOPER_POLL_TIMEOUT: - // timer expired - done = true; + done = true; // timer expired, return to FLTK break; case ALOOPER_POLL_ERROR: Fl_Android_Application::log_e( - "Something caused an ERROR in ALooper_pollAll."); - done = true; + "Something caused an ERROR in ALooper_pollOnce."); + done = true; // return to the app to find the error break; default: Fl_Android_Application::log_e( - "Unknown return value from ALooper_pollAll."); - done = true; + "Unknown return value from ALooper_pollOnce."); + done = true; // return to the app, just in case break; } -// } + // we need to repeat this as long as there are messages in the queue, or any + // change in the graphical interface will trigger a redraw immediately. To + // save time and energy, we want to collect graphics changes and execute + // them as soon as no more events are pending. + // Setting delay to zero on the second round makes sure that all events + // are handled first, and the call returns only when no more + // events are pending. + delay = 0; + } return ret; } |
