diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 5d7159b..944ea2f 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -272,7 +272,7 @@ ChatGui4::~ChatGui4(void) { //} } -float ChatGui4::render(float time_delta, bool window_hidden) { +float ChatGui4::render(float time_delta, bool window_hidden, bool window_focused) { _fss.render(); _sip.render(time_delta); _b_tc.update(); @@ -533,17 +533,17 @@ float ChatGui4::render(float time_delta, bool window_hidden) { Message3Registry& msg_reg = *msg_reg_ptr; // do systems TODO: extract - { // fade system + if (window_focused) { // fade system std::vector to_remove; msg_reg.view().each([&to_remove, time_delta](const Message3 e, Components::UnreadFade& fade) { // TODO: configurable - const float fade_duration = 7.5f; - fade.fade -= 1.f/fade_duration * std::min(time_delta, 1.f/8.f); // fps but not below 8 for smooth-ish fade + const float fade_duration = 5.f; + fade.fade -= 1.f/fade_duration * std::min(time_delta, 1.f/10.f); // fps but not below 10 for smooth-ish fade if (fade.fade <= 0.f) { to_remove.push_back(e); } }); - msg_reg.remove(to_remove.cbegin(), to_remove.cend()); + msg_reg.remove(to_remove.cbegin(), to_remove.cend()); } //auto tmp_view = msg_reg.view(); @@ -611,14 +611,22 @@ float ChatGui4::render(float time_delta, bool window_hidden) { // use username as visibility test if (ImGui::IsItemVisible()) { if (msg_reg.all_of(e)) { - // get time now - const uint64_t ts_now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - msg_reg.emplace_or_replace(e, ts_now); - msg_reg.remove(e); - msg_reg.emplace_or_replace(e, 1.f); - - // we remove the unread tag here - _rmm.throwEventUpdate(msg_reg, e); + if (!msg_reg.all_of(e)) { + if (msg_reg.all_of(e)) { + // skip fade, we might get here by merging + msg_reg.remove(e); + } else { + // get time now + const uint64_t ts_now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + msg_reg.emplace_or_replace(e, ts_now); + msg_reg.emplace_or_replace(e, 1.f); + } + _rmm.throwEventUpdate(msg_reg, e); + } else if (window_focused) { + // remove unread early, when we focus the window + msg_reg.remove(e); + _rmm.throwEventUpdate(msg_reg, e); + } } // track view diff --git a/src/chat_gui4.hpp b/src/chat_gui4.hpp index 126576a..b5f5d18 100644 --- a/src/chat_gui4.hpp +++ b/src/chat_gui4.hpp @@ -72,7 +72,7 @@ class ChatGui4 : public ObjectStoreEventI { ~ChatGui4(void); public: - float render(float time_delta, bool window_hidden); + float render(float time_delta, bool window_hidden, bool window_focused); public: void sendFilePath(std::string_view file_path); diff --git a/src/main.cpp b/src/main.cpp index 0303f23..1a2b02d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -181,15 +181,6 @@ int main(int argc, char** argv) { last_time_render = new_time; } - //// TODO: seperate out render and tick - //const float time_to_next_loop = std::min(screen->nextRender(), screen->nextTick()); - - //std::this_thread::sleep_for( // time left to get to 60fps - //std::chrono::duration(time_to_next_loop) - //- std::chrono::duration(std::chrono::steady_clock::now() - new_time) // time used for rendering - //); - - #if 1 if (render || tick) { // why is windows like this diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 6b183a4..02520bd 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -328,6 +328,14 @@ bool MainScreen::handleEvent(SDL_Event& e) { return true; // forward? } + if (e.type == SDL_EVENT_WINDOW_FOCUS_GAINED) { + _window_focused = true; + } + + if (e.type == SDL_EVENT_WINDOW_FOCUS_LOST) { + _window_focused = false; + } + if ( _fps_perf_mode <= 1 && ( // those are all the events imgui polls @@ -391,7 +399,11 @@ Screen* MainScreen::render(float time_delta, bool&) { si.render(time_delta); - const float cg_interval = cg.render(time_delta, _window_hidden); // render + if (_window_hidden && _window_focused) { + _window_focused = false; + } + + const float cg_interval = cg.render(time_delta, _window_hidden, _window_focused); // render sw.render(); // render osui.render(); tuiu.render(); // render diff --git a/src/main_screen.hpp b/src/main_screen.hpp index b66f648..fedb66a 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -112,6 +112,7 @@ struct MainScreen final : public Screen { bool _show_tool_id_stack {false}; bool _show_tool_demo {false}; + bool _window_focused {true}; bool _window_hidden {false}; uint64_t _window_hidden_ts {0}; float _time_since_event {0.f}; diff --git a/src/tox_netprof_ui.cpp b/src/tox_netprof_ui.cpp index 4107772..fd216ea 100644 --- a/src/tox_netprof_ui.cpp +++ b/src/tox_netprof_ui.cpp @@ -288,8 +288,8 @@ float ToxNetprofUI::render(float time_delta) { if (ImGui::Begin("Tox Netprof histograms", &_show_window_histo)) { if (_enabled) { const float line_height = ImGui::GetTextLineHeight(); - ImGui::PlotHistogram("udp total count sent##histograms", _udp_tctx.data(), _udp_tctx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); - ImGui::PlotHistogram("udp total count received##histograms", _udp_tcrx.data(), _udp_tcrx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); + ImGui::PlotHistogram("udp total packets sent##histograms", _udp_tctx.data(), _udp_tctx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); + ImGui::PlotHistogram("udp total packets received##histograms", _udp_tcrx.data(), _udp_tcrx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); ImGui::PlotHistogram("udp total bytes sent##histograms", _udp_tbtx.data(), _udp_tbtx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); ImGui::PlotHistogram("udp total bytes received##histograms", _udp_tbrx.data(), _udp_tbrx.size(), 0, nullptr, 0.f, FLT_MAX, {0, 3*line_height}); } else {