Move client drawing responsiblity to the ClientManager

This commit is contained in:
Maxime Coste 2012-11-05 19:58:04 +01:00
parent a41bb34b21
commit 3daac4883e
5 changed files with 27 additions and 18 deletions

View File

@ -16,6 +16,7 @@ void ClientManager::create_client(std::unique_ptr<UserInterface>&& 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<UserInterface>&& 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());
}
}
}
}

View File

@ -21,6 +21,7 @@ public:
Window& get_unused_window_for_buffer(Buffer& buffer) const;
void redraw_clients() const;
private:
struct Client
{

View File

@ -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);

View File

@ -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())

View File

@ -635,7 +635,6 @@ void InputHandler::handle_available_inputs(Context& context)
if (is_valid(key))
m_mode->on_key(key, context);
}
context.draw_ifn();
}
}