Handle all pending events before redrawing

If new events happen while handling events, take care of those
new events as well before redrawing.
This commit is contained in:
Maxime Coste 2018-05-15 21:37:41 +10:00
parent 75eb293f98
commit fcce76ba57
3 changed files with 12 additions and 5 deletions

View File

@ -69,7 +69,7 @@ EventManager::~EventManager()
kak_assert(m_timers.empty()); kak_assert(m_timers.empty());
} }
void EventManager::handle_next_events(EventMode mode, sigset_t* sigmask, bool block) bool EventManager::handle_next_events(EventMode mode, sigset_t* sigmask, bool block)
{ {
int max_fd = 0; int max_fd = 0;
fd_set rfds, wfds, efds; fd_set rfds, wfds, efds;
@ -140,6 +140,8 @@ void EventManager::handle_next_events(EventMode mode, sigset_t* sigmask, bool bl
if (contains(m_timers, timer) and timer->next_date() <= now) if (contains(m_timers, timer) and timer->next_date() <= now)
timer->run(mode); timer->run(mode);
} }
return res > 0;
} }
void EventManager::force_signal(int fd) void EventManager::force_signal(int fd)

View File

@ -86,7 +86,7 @@ public:
EventManager(); EventManager();
~EventManager(); ~EventManager();
void handle_next_events(EventMode mode, sigset_t* sigmask = nullptr, bool block = true); bool handle_next_events(EventMode mode, sigset_t* sigmask = nullptr, bool block = true);
// force the watchers associated with fd to be executed // force the watchers associated with fd to be executed
// on next handle_next_events call. // on next handle_next_events call.

View File

@ -680,9 +680,14 @@ int run_server(StringView session, StringView server_init,
(flags & ServerFlags::Daemon))) (flags & ServerFlags::Daemon)))
{ {
client_manager.redraw_clients(); client_manager.redraw_clients();
event_manager.handle_next_events(EventMode::Normal, nullptr,
not client_manager.has_pending_inputs()); // Loop a
client_manager.process_pending_inputs(); bool allow_blocking = not client_manager.has_pending_inputs();
while (event_manager.handle_next_events(EventMode::Normal, nullptr, allow_blocking))
{
client_manager.process_pending_inputs();
allow_blocking = false;
}
client_manager.clear_client_trash(); client_manager.clear_client_trash();
client_manager.clear_window_trash(); client_manager.clear_window_trash();
buffer_manager.clear_buffer_trash(); buffer_manager.clear_buffer_trash();