From 3daac4883ee3788b00c27972f8b678c1523df96d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 5 Nov 2012 19:58:04 +0100 Subject: [PATCH] Move client drawing responsiblity to the ClientManager --- src/client_manager.cc | 25 ++++++++++++++++++++++++- src/client_manager.hh | 1 + src/commands.cc | 4 ++-- src/context.hh | 14 -------------- src/input_handler.cc | 1 - 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index d60f49e8..3fbdcaeb 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -16,6 +16,7 @@ void ClientManager::create_client(std::unique_ptr&& ui, try { input_handler->handle_available_inputs(*context); + context->window().forget_timestamp(); } catch (Kakoune::runtime_error& error) { @@ -26,8 +27,9 @@ void ClientManager::create_client(std::unique_ptr&& ui, EventManager::instance().unwatch(event_fd); close(event_fd); } + ClientManager::instance().redraw_clients(); }); - context->draw_ifn(); + redraw_clients(); } void ClientManager::remove_client_by_context(Context& context) @@ -52,9 +54,30 @@ Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer) const return &client.context->window() == w.get(); }); if (it == m_clients.end()) + { + w->forget_timestamp(); return *w; + } } return buffer.new_window(); } +void ClientManager::redraw_clients() const +{ + for (auto& client : m_clients) + { + Context& context = *client.context; + if (context.window().timestamp() != context.buffer().timestamp()) + { + DisplayCoord dimensions = context.ui().dimensions(); + if (dimensions == DisplayCoord{0,0}) + return; + context.window().set_dimensions(dimensions); + context.window().update_display_buffer();; + context.ui().draw(context.window().display_buffer(), + context.window().status_line()); + } + } +} + } diff --git a/src/client_manager.hh b/src/client_manager.hh index dab3b356..99245348 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -21,6 +21,7 @@ public: Window& get_unused_window_for_buffer(Buffer& buffer) const; + void redraw_clients() const; private: struct Client { diff --git a/src/commands.cc b/src/commands.cc index cbbbbf54..7bd58031 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -238,14 +238,14 @@ Buffer* open_fifo(const String& name , const String& filename, Context& context) { EventManager::instance().unwatch(fd); close(fd); } ); - EventManager::instance().watch(fd, [buffer, &context](int fd) { + EventManager::instance().watch(fd, [buffer](int fd) { char data[4096]; ssize_t count = read(fd, data, 4096); buffer->insert(buffer->end()-1, count > 0 ? String(data, data+count) : "*** kak: fifo closed ***\n"); buffer->reset_undo_data(); - context.draw_ifn(); + ClientManager::instance().redraw_clients(); if (count <= 0) { close(fd); diff --git a/src/context.hh b/src/context.hh index 97c8e1c5..0568c6c4 100644 --- a/src/context.hh +++ b/src/context.hh @@ -91,20 +91,6 @@ struct Context return GlobalOptionManager::instance(); } - void draw_ifn() const - { - if (has_ui() and has_window()) - { - DisplayCoord dimensions = ui().dimensions(); - if (dimensions == DisplayCoord{0,0}) - return; - window().set_dimensions(dimensions); - window().update_display_buffer();; - ui().draw(window().display_buffer(), window().status_line()); - } - - } - void print_status(const String& status) const { if (has_ui()) diff --git a/src/input_handler.cc b/src/input_handler.cc index 4683b30f..6131a5f2 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -635,7 +635,6 @@ void InputHandler::handle_available_inputs(Context& context) if (is_valid(key)) m_mode->on_key(key, context); } - context.draw_ifn(); } }