From d3aff03062a344f8ec0387d7c514747ee97fc69b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 May 2016 13:48:48 +0100 Subject: [PATCH] Keep a pointer to current client in windows so that window hooks can access it --- src/client.cc | 5 +++++ src/window.cc | 3 +++ src/window.hh | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/client.cc b/src/client.cc index 3dc3ea07..6d875c39 100644 --- a/src/client.cc +++ b/src/client.cc @@ -28,6 +28,8 @@ Client::Client(std::unique_ptr&& ui, std::move(name)}, m_env_vars(env_vars) { + m_window->set_client(this); + context().set_client(*this); context().set_window(*m_window); @@ -42,6 +44,7 @@ Client::Client(std::unique_ptr&& ui, Client::~Client() { m_window->options().unregister_watcher(*this); + m_window->set_client(nullptr); } Optional Client::get_next_key(EventMode mode) @@ -149,11 +152,13 @@ void Client::change_buffer(Buffer& buffer) auto& client_manager = ClientManager::instance(); m_window->options().unregister_watcher(*this); + m_window->set_client(nullptr); client_manager.add_free_window(std::move(m_window), std::move(context().selections())); WindowAndSelections ws = client_manager.get_free_window(buffer); m_window = std::move(ws.window); + m_window->set_client(this); m_window->options().register_watcher(*this); m_ui->set_ui_options(m_window->options()["ui_options"].get()); diff --git a/src/window.cc b/src/window.cc index 6dea389c..0e7c3b96 100644 --- a/src/window.cc +++ b/src/window.cc @@ -377,6 +377,9 @@ void Window::run_hook_in_own_context(StringView hook_name, StringView param) { InputHandler hook_handler({ *m_buffer, Selection{} }, Context::Flags::Transient); hook_handler.context().set_window(*this); + if (m_client) + hook_handler.context().set_client(*m_client); + hooks().run_hook(hook_name, param, hook_handler.context()); } } diff --git a/src/window.hh b/src/window.hh index 40e0fef8..ef9af667 100644 --- a/src/window.hh +++ b/src/window.hh @@ -1,6 +1,7 @@ #ifndef window_hh_INCLUDED #define window_hh_INCLUDED +#include "client.hh" #include "display_buffer.hh" #include "highlighter_group.hh" #include "option_manager.hh" @@ -46,6 +47,8 @@ public: ByteCoord offset_coord(ByteCoord coord, CharCount offset); ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset); + void set_client(Client* client) { m_client = client; } + void clear_display_buffer(); private: Window(const Window&) = delete; @@ -56,6 +59,7 @@ private: void run_hook_in_own_context(StringView hook_name, StringView param); SafePtr m_buffer; + SafePtr m_client; CharCoord m_position; CharCoord m_dimensions;