From 933e4a599cfd3fc09edd67a024b8af08bbec7c01 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 6 Dec 2022 17:48:42 +1100 Subject: [PATCH] Load buffer in command line order Pass the first buffer on the the command line explicitely to client creation. This ensure the buffer list matches the command line, which makes buffer-next/buffer-previous a bit more useful. Fixes #2705 --- src/client_manager.cc | 6 ++++-- src/client_manager.hh | 2 +- src/main.cc | 10 ++++------ src/remote.cc | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index 25d96c4d..5453f02c 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -47,10 +47,12 @@ String ClientManager::generate_name() const Client* ClientManager::create_client(std::unique_ptr&& ui, int pid, String name, EnvVarMap env_vars, StringView init_cmds, - Optional init_coord, + StringView init_buffer, Optional init_coord, Client::OnExitCallback on_exit) { - Buffer& buffer = BufferManager::instance().get_first_buffer(); + Buffer& buffer = init_buffer.empty() ? BufferManager::instance().get_first_buffer() + : BufferManager::instance().get_buffer(init_buffer); + WindowAndSelections ws = get_free_window(buffer); Client* client = new Client{std::move(ui), std::move(ws.window), std::move(ws.selections), pid, diff --git a/src/client_manager.hh b/src/client_manager.hh index 2323e07b..8edeb790 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -21,7 +21,7 @@ public: Client* create_client(std::unique_ptr&& ui, int pid, String name, EnvVarMap env_vars, StringView init_cmds, - Optional init_coord, + StringView init_buffer, Optional init_coord, Client::OnExitCallback on_exit); bool empty() const { return m_clients.empty(); } diff --git a/src/main.cc b/src/main.cc index 2b09ccd6..844b4574 100644 --- a/src/main.cc +++ b/src/main.cc @@ -754,7 +754,7 @@ enum class ServerFlags constexpr bool with_bit_ops(Meta::Type) { return true; } int run_server(StringView session, StringView server_init, - StringView client_init, Optional init_coord, + StringView client_init, StringView init_buffer, Optional init_coord, ServerFlags flags, UIType ui_type, DebugFlags debug_flags, ConstArrayView files) { @@ -836,9 +836,7 @@ int run_server(StringView session, StringView server_init, if (not files.empty()) try { - // create buffers in reverse order so that the first given buffer - // is the most recently created one. - for (auto& file : files | reverse()) + for (auto& file : files) { try { @@ -867,7 +865,7 @@ int run_server(StringView session, StringView server_init, if (not server.is_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, init_buffer, std::move(init_coord), [](int status) { local_client_exit = status; }); if (startup_error and local_client) @@ -1234,7 +1232,7 @@ int main(int argc, char* argv[]) ((argc == 1 or (ignore_kakrc and argc == 2)) and isatty(0) ? ServerFlags::StartupInfo : ServerFlags::None); auto debug_flags = option_from_string(Meta::Type{}, parser.get_switch("debug").value_or("")); - return run_server(session, server_init, client_init, init_coord, flags, ui_type, debug_flags, files); + return run_server(session, server_init, client_init, files.empty() ? StringView{} : files[0], init_coord, flags, ui_type, debug_flags, files); } catch (convert_to_client_mode& convert) { diff --git a/src/remote.cc b/src/remote.cc index 99fda3e1..50dda1b0 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -793,7 +793,7 @@ private: auto* ui = new RemoteUI{sock, dimensions}; ClientManager::instance().create_client( std::unique_ptr(ui), pid, std::move(name), - std::move(env_vars), init_cmds, init_coord, + std::move(env_vars), init_cmds, {}, init_coord, [ui](int status) { ui->exit(status); }); Server::instance().remove_accepter(this);