From a4a3d93203e9508cf0cea7b6e639c5c3de44caca Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 22 Oct 2020 03:14:14 +0200 Subject: [PATCH] Repair terminal update skipping --- ChangeLog | 3 + doc/Makefile.am | 2 + ...get tree.svg => final-cut-widget-tree.svg} | 0 doc/first-steps.md | 2 +- src/fvterm.cpp | 64 ++++++------------- src/include/final/fvterm.h | 3 +- 6 files changed, 27 insertions(+), 47 deletions(-) rename doc/{final-cut-widget tree.svg => final-cut-widget-tree.svg} (100%) diff --git a/ChangeLog b/ChangeLog index ac4d98a4..9777cb82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2020-10-22 Markus Gans + * Repair terminal update skipping + 2020-10-20 Markus Gans * For fast mouse movements the keyboard interval was increased from 13.3 to 30 Hz diff --git a/doc/Makefile.am b/doc/Makefile.am index d8ec9405..70351616 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -18,6 +18,7 @@ EXTRA_DIST = \ faq.md \ fileopen-dialog.png \ final-cut-application-structure.svg \ + final-cut-widget-tree.svg \ first-steps.md \ first-steps_callback-function.cpp.png \ first-steps_callback-lambda.cpp.png \ @@ -74,6 +75,7 @@ doc_DATA = \ faq.md \ fileopen-dialog.png \ final-cut-application-structure.svg \ + final-cut-widget-tree.svg \ first-steps.md \ first-steps_callback-function.cpp.png \ first-steps_callback-lambda.cpp.png \ diff --git a/doc/final-cut-widget tree.svg b/doc/final-cut-widget-tree.svg similarity index 100% rename from doc/final-cut-widget tree.svg rename to doc/final-cut-widget-tree.svg diff --git a/doc/first-steps.md b/doc/first-steps.md index 7cafbacb..4fb6fd50 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -89,7 +89,7 @@ unique and can not have a parent widget. The class `FApplication` manages all settings and assigns keyboard and mouse input to the different widgets.
- widget tree + widget tree
Figure 2. Widget tree of a FINAL CUT application


diff --git a/src/fvterm.cpp b/src/fvterm.cpp index a9175e97..d82e22d5 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -55,11 +55,9 @@ static FVTerm* init_object{nullptr}; // static class attributes bool FVTerm::draw_completed{false}; -bool FVTerm::terminal_update_pending{false}; -bool FVTerm::force_terminal_update{false}; bool FVTerm::no_terminal_updates{false}; bool FVTerm::cursor_hideable{false}; -int FVTerm::skipped_terminal_update{}; +int FVTerm::skipped_terminal_update{0}; uInt64 FVTerm::term_size_check_timeout{500000}; // 500 ms uInt FVTerm::erase_char_length{}; uInt FVTerm::repeat_char_length{}; @@ -271,24 +269,23 @@ void FVTerm::updateTerminal() const { // Updates pending changes to the terminal - if ( no_terminal_updates || FApplication::isQuit() ) - return; - - if ( ! force_terminal_update ) + // Check if terminal updates were stopped, application is stopping, + // VTerm has changes or the drawing is not completed + if ( no_terminal_updates || FApplication::isQuit() + || ! (hasPendingUpdates(vterm) && draw_completed) ) { - if ( ! draw_completed ) - return; - - if ( keyboard->isInputDataPending() ) - { - terminal_update_pending = true; - return; - } + return; } - // Checks if VTerm has changes - if ( ! hasPendingUpdates(vterm) ) + if ( (keyboard->isInputDataPending() || keyboard->isKeyPressed()) + && skipped_terminal_update <= max_skip ) + { + // Skipping terminal updates if there is unprocessed inputs + skipped_terminal_update++; return; + } + + skipped_terminal_update = 0; for (uInt y{0}; y < uInt(vterm->height); y++) updateTerminalLine (y); @@ -1268,9 +1265,6 @@ void FVTerm::clearArea (FTermArea* area, int fillchar) const //---------------------------------------------------------------------- void FVTerm::processTerminalUpdate() const { - // Retains terminal updates if there are unprocessed inputs - static constexpr int max_skip = 8; - const auto& data = FTerm::getFTermData(); // Checks if the resizing of the terminal is not finished @@ -1287,25 +1281,8 @@ void FVTerm::processTerminalUpdate() const // Update data on VTerm updateVTerm(); - if ( ! terminal_update_pending && ! hasPendingUpdates(vterm) ) - return; - - if ( ! keyboard->isInputDataPending() ) - { - updateTerminal(); - terminal_update_pending = false; - skipped_terminal_update = 0; - } - else if ( skipped_terminal_update > max_skip ) - { - force_terminal_update = true; - updateTerminal(); - force_terminal_update = false; - terminal_update_pending = false; - skipped_terminal_update = 0; - } - else - skipped_terminal_update++; + // Update the visible terminal + updateTerminal(); } //---------------------------------------------------------------------- @@ -1693,7 +1670,7 @@ void FVTerm::callPreprocessingHandler (const FTermArea* area) { // Call preprocessing handler - if ( area->preproc_list.empty() ) + if ( ! area || area->preproc_list.empty() ) return; for (auto&& pcall : area->preproc_list) @@ -1707,7 +1684,7 @@ void FVTerm::callPreprocessingHandler (const FTermArea* area) //---------------------------------------------------------------------- bool FVTerm::hasChildAreaChanges (FTermArea* area) const { - if ( ! area ) + if ( ! area || area->preproc_list.empty() ) return false; return std::any_of ( area->preproc_list.begin() @@ -1724,13 +1701,12 @@ bool FVTerm::hasChildAreaChanges (FTermArea* area) const //---------------------------------------------------------------------- void FVTerm::clearChildAreaChanges (const FTermArea* area) const { - if ( ! area ) + if ( ! area || area->preproc_list.empty() ) return; for (auto&& pcall : area->preproc_list) { - if ( pcall.instance - && pcall.instance->child_print_area ) + if ( pcall.instance && pcall.instance->child_print_area ) pcall.instance->child_print_area->has_changes = false; } } diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 0dbd3330..51338515 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -341,6 +341,7 @@ class FVTerm // Constants // Buffer size for character output on the terminal static constexpr uInt TERMINAL_OUTPUT_BUFFER_SIZE = 131072; + static constexpr int max_skip = 20; // Methods void resetTextAreaToDefault ( const FTermArea* @@ -449,8 +450,6 @@ class FVTerm static FKeyboard* keyboard; static timeval last_term_size_check; static bool draw_completed; - static bool terminal_update_pending; - static bool force_terminal_update; static bool no_terminal_updates; static uInt64 term_size_check_timeout; static int skipped_terminal_update;