Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelfmz <fenix1905@tut.by>2022-09-17 18:29:29 +0300
committerelfmz <fenix1905@tut.by>2022-09-17 18:29:29 +0300
commitb2c68d2f87e96d5bd42517cacccb3002db0cdfd3 (patch)
tree963a7087727c9bbad88a1c4b043f7e8ba294882c
parent9b15d1da51ca8b701d464ef32caaa6c52b8a2b0e (diff)
GUI: stop cursor blink and some other timer-related things after 30 seconds of no IO activity to save CPU time
-rw-r--r--WinPort/src/Backend/WX/Paint.h2
-rw-r--r--WinPort/src/Backend/WX/wxMain.cpp36
-rw-r--r--far2l/src/console/keyboard.cpp3
3 files changed, 37 insertions, 4 deletions
diff --git a/WinPort/src/Backend/WX/Paint.h b/WinPort/src/Backend/WX/Paint.h
index 92e98149..c9e6c86f 100644
--- a/WinPort/src/Backend/WX/Paint.h
+++ b/WinPort/src/Backend/WX/Paint.h
@@ -64,6 +64,8 @@ public:
inline unsigned int FontWidth() const { return _font_width; }
inline unsigned int FontHeight() const { return _font_height; }
inline unsigned int FontThickness() const { return _font_thickness; }
+
+ inline bool CursorBlinkState() const { return _cursor_props.blink_state; }
};
///////////////////////////////
diff --git a/WinPort/src/Backend/WX/wxMain.cpp b/WinPort/src/Backend/WX/wxMain.cpp
index 2a268a18..6913bb65 100644
--- a/WinPort/src/Backend/WX/wxMain.cpp
+++ b/WinPort/src/Backend/WX/wxMain.cpp
@@ -33,6 +33,13 @@
#define AREAS_REDUCTION
+// interval of timer that used to blink cursor and do some other things
+#define TIMER_PERIOD 500 // 0.5 second
+
+// how many timer ticks may pass since last input activity
+// before timer will be stopped until restarted by some activity
+#define TIMER_IDLING_CYCLES 60 // 0.5 second * 60 = 30 seconds
+
// If time between adhoc text copy and mouse button release less then this value then text will not be copied. Used to protect against unwanted copy-paste-s
#define QEDIT_COPY_MINIMAL_DELAY 150
@@ -317,6 +324,7 @@ private:
COORD TranslateMousePosition( wxMouseEvent &event );
void DamageAreaBetween(COORD c1, COORD c2);
int GetDisplayIndex();
+ void ResetTimerIdling();
wxDECLARE_EVENT_TABLE();
KeyTracker _key_tracker;
@@ -350,6 +358,7 @@ private:
struct RefreshRects : std::vector<SMALL_RECT>, std::mutex {} _refresh_rects;
bool _repaint_on_next_timer;
+ unsigned int _timer_idling_counter;
};
///////////////////////////////////////////
@@ -576,11 +585,11 @@ WinPortPanel::WinPortPanel(WinPortFrame *frame, const wxPoint& pos, const wxSize
_paint_context(this), _has_focus(true), _prev_mouse_event_ts(0), _frame(frame), _periodic_timer(NULL),
_last_keydown_enqueued(false), _initialized(false), _adhoc_quickedit(false),
_resize_pending(RP_NONE), _mouse_state(0), _mouse_qedit_start_ticks(0), _mouse_qedit_moved(false), _last_valid_display(0),
- _refresh_rects_throttle(0), _pending_refreshes(0), _repaint_on_next_timer(false)
+ _refresh_rects_throttle(0), _pending_refreshes(0), _repaint_on_next_timer(false), _timer_idling_counter(0)
{
g_winport_con_out->SetBackend(this);
_periodic_timer = new wxTimer(this, TIMER_ID_PERIODIC);
- _periodic_timer->Start(500);
+ _periodic_timer->Start(TIMER_PERIOD);
OnConsoleOutputTitleChanged();
}
@@ -748,6 +757,19 @@ void WinPortPanel::OnTimerPeriodic(wxTimerEvent& event)
Refresh(false);
Update();
}
+ ++_timer_idling_counter;
+ // stop timer if counter reached limit and cursor is visible and no other timer-dependent things remained
+ if (_timer_idling_counter >= TIMER_IDLING_CYCLES && _paint_context.CursorBlinkState() && _text2clip.empty()) {
+ _periodic_timer->Stop();
+ }
+}
+
+void WinPortPanel::ResetTimerIdling()
+{
+ if (_timer_idling_counter >= TIMER_IDLING_CYCLES && !_periodic_timer->IsRunning()) {
+ _periodic_timer->Start(TIMER_PERIOD);
+ }
+ _timer_idling_counter = 0;
}
static int ProcessAllEvents()
@@ -996,6 +1018,7 @@ void WinPortPanel::OnTitleChangedSync( wxCommandEvent& event )
_frame->SetTitle(title.c_str());
if (g_remote) { // under xrdp/forwarded x11 (repro?) - force full repaint after some time to workaround #1303
_repaint_on_next_timer = true;
+ ResetTimerIdling();
}
}
@@ -1011,7 +1034,8 @@ static bool IsForcedCharTranslation(int code)
}
void WinPortPanel::OnKeyDown( wxKeyEvent& event )
-{
+{
+ ResetTimerIdling();
DWORD now = WINPORT(GetTickCount)();
const auto uni = event.GetUnicodeKey();
fprintf(stderr, "OnKeyDown: raw=%x code=%x uni=%x (%lc) ts=%lu [now=%u]",
@@ -1102,6 +1126,7 @@ void WinPortPanel::OnKeyDown( wxKeyEvent& event )
void WinPortPanel::OnKeyUp( wxKeyEvent& event )
{
+ ResetTimerIdling();
const auto uni = event.GetUnicodeKey();
fprintf(stderr, "OnKeyUp: raw=%x code=%x uni=%x (%lc) ts=%lu",
event.GetRawKeyCode(), event.GetKeyCode(),
@@ -1159,6 +1184,7 @@ void WinPortPanel::OnKeyUp( wxKeyEvent& event )
void WinPortPanel::OnChar( wxKeyEvent& event )
{
+ ResetTimerIdling();
const auto uni = event.GetUnicodeKey();
fprintf(stderr, "OnChar: raw=%x code=%x uni=%x (%lc) ts=%lu lke=%u",
event.GetRawKeyCode(), event.GetKeyCode(),
@@ -1226,6 +1252,7 @@ void WinPortPanel::OnSize(wxSizeEvent &event)
CheckForResizePending();
} else {
_resize_pending = RP_DEFER;
+ ResetTimerIdling();
//fprintf(stderr, "RP_DEFER\n");
}
}
@@ -1251,6 +1278,8 @@ COORD WinPortPanel::TranslateMousePosition( wxMouseEvent &event )
void WinPortPanel::OnMouse( wxMouseEvent &event )
{
+ ResetTimerIdling();
+
COORD pos_char = TranslateMousePosition( event );
DWORD mode = 0;
@@ -1573,6 +1602,7 @@ void WinPortPanel::CheckPutText2CLip()
void WinPortPanel::OnSetFocus( wxFocusEvent &event )
{
_has_focus = true;
+ ResetTimerIdling();
}
void WinPortPanel::OnKillFocus( wxFocusEvent &event )
diff --git a/far2l/src/console/keyboard.cpp b/far2l/src/console/keyboard.cpp
index 9acb1109..3b398280 100644
--- a/far2l/src/console/keyboard.cpp
+++ b/far2l/src/console/keyboard.cpp
@@ -60,7 +60,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "console.hpp"
#include "palette.hpp"
#include "xlat.hpp"
-#include "InterThreadCall.hpp"
/* start Глобальные переменные */
@@ -474,6 +473,8 @@ DWORD IsMouseButtonPressed()
{
GetInputRecord(&rec);
}
+ // IsMouseButtonPressed used within loops, so lets sleep to avoid CPU hogging in that loops
+ // it would be nicer to sleep inside of that loops instead, but keep to original code for now
WINPORT(WaitConsoleInput)(10);
return MouseButtonState;
}