Fix WinResize hook getting triggered during urgent event processing

WinResize hooks could be triggered during shell evaluation, leading
to any state potentially getting mutated after a shell evaluation
call.
This commit is contained in:
Maxime Coste 2019-12-16 14:07:22 +11:00
parent f8ab9e0780
commit efabe28173
3 changed files with 15 additions and 2 deletions

View File

@ -80,6 +80,7 @@ bool Client::is_ui_ok() const
bool Client::process_pending_inputs()
{
const bool debug_keys = (bool)(context().options()["debug"].get<DebugFlags>() & DebugFlags::Keys);
m_window->run_resize_hook_ifn();
// steal keys as we might receive new keys while handling them.
Vector<Key, MemoryDomain::Client> keys = std::move(m_pending_keys);
for (auto& key : keys)

View File

@ -193,8 +193,17 @@ void Window::set_dimensions(DisplayCoord dimensions)
if (m_dimensions != dimensions)
{
m_dimensions = dimensions;
run_hook_in_own_context(Hook::WinResize, format("{}.{}", dimensions.line,
dimensions.column));
m_resize_hook_pending = true;
}
}
void Window::run_resize_hook_ifn()
{
if (m_resize_hook_pending)
{
m_resize_hook_pending = false;
run_hook_in_own_context(Hook::WinResize,
format("{}.{}", m_dimensions.line, m_dimensions.column));
}
}

View File

@ -48,6 +48,8 @@ public:
void set_client(Client* client) { m_client = client; }
void clear_display_buffer();
void run_resize_hook_ifn();
private:
Window(const Window&) = delete;
@ -66,6 +68,7 @@ private:
DisplayBuffer m_display_buffer;
Highlighters m_builtin_highlighters;
bool m_resize_hook_pending = false;
struct Setup
{