summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-05-09 13:48:48 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-05-09 13:48:48 +0100
commitd3aff03062a344f8ec0387d7c514747ee97fc69b (patch)
treeae23d25579c463378ffe4624ac0233e5ccbae767 /src
parent3338ba5c6c19590794f678dd9c47c49b8391f34f (diff)
Keep a pointer to current client in windows so that window hooks can access it
Diffstat (limited to 'src')
-rw-r--r--src/client.cc5
-rw-r--r--src/window.cc3
-rw-r--r--src/window.hh4
3 files changed, 12 insertions, 0 deletions
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<UserInterface>&& 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<UserInterface>&& ui,
Client::~Client()
{
m_window->options().unregister_watcher(*this);
+ m_window->set_client(nullptr);
}
Optional<Key> 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<UserInterface::Options>());
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<Buffer> m_buffer;
+ SafePtr<Client> m_client;
CharCoord m_position;
CharCoord m_dimensions;