mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-29 14:44:56 +03:00
Restore client name after converting to client
When Kakoune forked the sever to background, the newly converted to client process (the original client/server process) was not preserving its previous client name.
This commit is contained in:
parent
796fbc6c1f
commit
db7b43acd5
@ -39,7 +39,7 @@ String ClientManager::generate_name() const
|
||||
}
|
||||
|
||||
Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pid,
|
||||
EnvVarMap env_vars, StringView init_cmds,
|
||||
String name, EnvVarMap env_vars, StringView init_cmds,
|
||||
Optional<BufferCoord> init_coord,
|
||||
Client::OnExitCallback on_exit)
|
||||
{
|
||||
@ -47,7 +47,8 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi
|
||||
WindowAndSelections ws = get_free_window(buffer);
|
||||
Client* client = new Client{std::move(ui), std::move(ws.window),
|
||||
std::move(ws.selections), pid,
|
||||
std::move(env_vars), generate_name(),
|
||||
std::move(env_vars),
|
||||
name.empty() ? generate_name() : std::move(name),
|
||||
std::move(on_exit)};
|
||||
m_clients.emplace_back(client);
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
~ClientManager();
|
||||
|
||||
Client* create_client(std::unique_ptr<UserInterface>&& ui, int pid,
|
||||
EnvVarMap env_vars, StringView init_cmds,
|
||||
String name, EnvVarMap env_vars, StringView init_cmds,
|
||||
Optional<BufferCoord> init_coord,
|
||||
Client::OnExitCallback on_exit);
|
||||
|
||||
|
18
src/main.cc
18
src/main.cc
@ -511,14 +511,14 @@ std::unique_ptr<UserInterface> create_local_ui(UIType ui_type)
|
||||
return std::make_unique<LocalUI>();
|
||||
}
|
||||
|
||||
int run_client(StringView session, StringView client_init,
|
||||
int run_client(StringView session, StringView name, StringView client_init,
|
||||
Optional<BufferCoord> init_coord, UIType ui_type,
|
||||
bool suspend)
|
||||
{
|
||||
try
|
||||
{
|
||||
EventManager event_manager;
|
||||
RemoteClient client{session, make_ui(ui_type), getpid(), get_env_vars(),
|
||||
RemoteClient client{session, name, make_ui(ui_type), getpid(), get_env_vars(),
|
||||
client_init, std::move(init_coord)};
|
||||
if (suspend)
|
||||
raise(SIGTSTP);
|
||||
@ -536,6 +536,7 @@ int run_client(StringView session, StringView client_init,
|
||||
struct convert_to_client_mode
|
||||
{
|
||||
String session;
|
||||
String client_name;
|
||||
String buffer_name;
|
||||
String selections;
|
||||
};
|
||||
@ -659,7 +660,7 @@ int run_server(StringView session, StringView server_init,
|
||||
if (not (flags & ServerFlags::Daemon))
|
||||
{
|
||||
local_client = client_manager.create_client(
|
||||
create_local_ui(ui_type), getpid(), get_env_vars(), client_init, std::move(init_coord),
|
||||
create_local_ui(ui_type), getpid(), {}, get_env_vars(), client_init, std::move(init_coord),
|
||||
[](int status) { local_client_exit = status; });
|
||||
|
||||
if (startup_error)
|
||||
@ -693,8 +694,9 @@ int run_server(StringView session, StringView server_init,
|
||||
}
|
||||
else if (convert_to_client_pending)
|
||||
{
|
||||
String buffer_name = local_client->context().buffer().name();
|
||||
String selections = selection_list_to_string(local_client->context().selections());
|
||||
const String client_name = local_client->context().name();
|
||||
const String buffer_name = local_client->context().buffer().name();
|
||||
const String selections = selection_list_to_string(local_client->context().selections());
|
||||
|
||||
ClientManager::instance().remove_client(*local_client, true, 0);
|
||||
client_manager.clear_client_trash();
|
||||
@ -704,7 +706,7 @@ int run_server(StringView session, StringView server_init,
|
||||
{
|
||||
String session = server.session();
|
||||
server.close_session(false);
|
||||
throw convert_to_client_mode{ std::move(session), std::move(buffer_name), std::move(selections) };
|
||||
throw convert_to_client_mode{ std::move(session), std::move(client_name), std::move(buffer_name), std::move(selections) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -985,7 +987,7 @@ int main(int argc, char* argv[])
|
||||
for (auto name : files)
|
||||
new_files += format("edit '{}';", escape(real_path(name), "'", '\\'));
|
||||
|
||||
return run_client(*server_session, new_files + client_init, init_coord, ui_type, false);
|
||||
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1000,7 +1002,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
catch (convert_to_client_mode& convert)
|
||||
{
|
||||
return run_client(convert.session,
|
||||
return run_client(convert.session, convert.client_name,
|
||||
format("try %^buffer '{}'; select '{}'^; echo converted to client only mode",
|
||||
escape(convert.buffer_name, "'^", '\\'), convert.selections), {}, ui_type, true);
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ bool check_session(StringView session)
|
||||
return connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) != -1;
|
||||
}
|
||||
|
||||
RemoteClient::RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
|
||||
RemoteClient::RemoteClient(StringView session, StringView name, std::unique_ptr<UserInterface>&& ui,
|
||||
int pid, const EnvVarMap& env_vars, StringView init_command,
|
||||
Optional<BufferCoord> init_coord)
|
||||
: m_ui(std::move(ui))
|
||||
@ -576,6 +576,7 @@ RemoteClient::RemoteClient(StringView session, std::unique_ptr<UserInterface>&&
|
||||
{
|
||||
MsgWriter msg{m_send_buffer, MessageType::Connect};
|
||||
msg.write(pid);
|
||||
msg.write(name);
|
||||
msg.write(init_command);
|
||||
msg.write(init_coord);
|
||||
msg.write(m_ui->dimensions());
|
||||
@ -723,13 +724,14 @@ private:
|
||||
case MessageType::Connect:
|
||||
{
|
||||
auto pid = m_reader.read<int>();
|
||||
auto name = m_reader.read<String>();
|
||||
auto init_cmds = m_reader.read<String>();
|
||||
auto init_coord = m_reader.read_optional<BufferCoord>();
|
||||
auto dimensions = m_reader.read<DisplayCoord>();
|
||||
auto env_vars = m_reader.read_hash_map<String, String, MemoryDomain::EnvVars>();
|
||||
auto* ui = new RemoteUI{sock, dimensions};
|
||||
if (auto* client = ClientManager::instance().create_client(
|
||||
std::unique_ptr<UserInterface>(ui), pid,
|
||||
std::unique_ptr<UserInterface>(ui), pid, std::move(name),
|
||||
std::move(env_vars), init_cmds, init_coord,
|
||||
[ui](int status) { ui->exit(status); }))
|
||||
ui->set_client(client);
|
||||
|
@ -30,7 +30,7 @@ using RemoteBuffer = Vector<char, MemoryDomain::Remote>;
|
||||
class RemoteClient
|
||||
{
|
||||
public:
|
||||
RemoteClient(StringView session, std::unique_ptr<UserInterface>&& ui,
|
||||
RemoteClient(StringView session, StringView name, std::unique_ptr<UserInterface>&& ui,
|
||||
int pid, const EnvVarMap& env_vars, StringView init_command,
|
||||
Optional<BufferCoord> init_coord);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user