Fix M9.8d review findings in binding capture
Arming capture drops the toolkit's held keys/modifiers and queued keyboard input; the chosen key stays owned until release or focus loss so its repeats, text and release reach neither toolkit nor world. Idle toolkit frames run when nothing is drawn and the toolkit queue is bounded. Controls host logic moves to ControlsFlow with an Apply -> save -> restart -> load rehearsal; key test events now carry realistic keycodes and modifiers with positive controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-80
@@ -1,3 +1,4 @@
|
||||
#include "controls_flow.hpp"
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/client/launcher.hpp"
|
||||
#include "evo/client/selection.hpp"
|
||||
@@ -335,31 +336,18 @@ int main(int argc, char** argv) try {
|
||||
std::fprintf(stderr, "client initialization error=%d\n", static_cast<int>(app.error()));
|
||||
return 1;
|
||||
}
|
||||
// A minimized native window may start with no drawable area. Adopt the
|
||||
// native viewport before projecting; until then use the requested size.
|
||||
// Controls (ADR-0085): an invalid file is reported and left untouched; defaults
|
||||
// apply until the user saves new bindings.
|
||||
// Controls (ADR-0085): per-user file unless --controls names one.
|
||||
if (controls_path.empty())
|
||||
if (const auto dir = evo::client::Application::settings_directory())
|
||||
controls_path = *dir / "controls-v1.txt";
|
||||
if (std::error_code missing;
|
||||
!controls_path.empty() && std::filesystem::exists(controls_path, missing)) {
|
||||
// Notices expire on the same monotonic clock the loop uses.
|
||||
static_cast<void>(ui.advance(milliseconds(std::chrono::steady_clock::now())).has_value());
|
||||
if (const auto loaded = evo::client::load_bindings(controls_path))
|
||||
(*app)->set_bindings(*loaded);
|
||||
else
|
||||
static_cast<void>(
|
||||
ui.notify("Saved controls rejected: " + evo::client::describe(loaded.error()) +
|
||||
" Default controls are in use; the file was not changed.",
|
||||
evo::client::NoticeLevel::warning, 15000)
|
||||
.has_value());
|
||||
}
|
||||
std::optional<evo::client::BindingEditor> editor;
|
||||
std::optional<evo::client_app::ControlSlot> capturing;
|
||||
std::optional<evo::client::BindingProblem> controls_problem;
|
||||
// Notices expire on the same monotonic clock the loop uses.
|
||||
static_cast<void>(ui.advance(milliseconds(std::chrono::steady_clock::now())).has_value());
|
||||
evo::client_app::ControlsFlow controls{controls_path};
|
||||
controls.load(**app, ui);
|
||||
if (show_controls)
|
||||
editor.emplace((*app)->bindings());
|
||||
controls.show(**app);
|
||||
// A minimized native window may start with no drawable area. Adopt the
|
||||
// native viewport before projecting; until then use the requested size.
|
||||
auto camera = evo::client::Camera::create(
|
||||
{config.width, config.height, config.width, config.height}, {}, 0.05);
|
||||
if (!camera)
|
||||
@@ -405,9 +393,7 @@ int main(int argc, char** argv) try {
|
||||
}
|
||||
view.visible_organisms = drawn_organisms;
|
||||
view.bindings = &(*app)->bindings();
|
||||
view.controls = editor ? &*editor : nullptr;
|
||||
view.capturing = capturing;
|
||||
view.controls_problem = controls_problem;
|
||||
controls.fill(view);
|
||||
actions = evo::client_app::draw_panels(view, buffers, display);
|
||||
});
|
||||
std::vector<evo::render::Rectangle> boxes;
|
||||
@@ -451,65 +437,11 @@ int main(int argc, char** argv) try {
|
||||
disconnect_dialog.reset();
|
||||
if (actions.dismiss_notice)
|
||||
static_cast<void>(ui.dismiss(*actions.dismiss_notice));
|
||||
if (actions.open_controls && !editor) {
|
||||
editor.emplace((*app)->bindings());
|
||||
controls_problem.reset();
|
||||
}
|
||||
if (editor) {
|
||||
if (actions.capture_key && !capturing) {
|
||||
capturing = actions.capture_key;
|
||||
controls_problem.reset();
|
||||
(*app)->begin_key_capture();
|
||||
}
|
||||
if (actions.cancel_capture && capturing) {
|
||||
(*app)->cancel_key_capture();
|
||||
capturing.reset();
|
||||
}
|
||||
if (actions.clear_secondary)
|
||||
editor->clear_secondary(*actions.clear_secondary);
|
||||
if (actions.reset_controls) {
|
||||
editor->reset_defaults();
|
||||
controls_problem.reset();
|
||||
}
|
||||
if (actions.apply_controls) {
|
||||
if (const auto applied = editor->apply(); !applied) {
|
||||
controls_problem = applied.error();
|
||||
} else {
|
||||
(*app)->set_bindings(*applied); // Releases held actions.
|
||||
const bool saved = !controls_path.empty() &&
|
||||
evo::client::save_bindings(*applied, controls_path);
|
||||
static_cast<void>(
|
||||
ui.notify(saved ? "Controls saved."
|
||||
: "Controls apply to this session but could not be saved.",
|
||||
saved ? evo::client::NoticeLevel::info
|
||||
: evo::client::NoticeLevel::warning)
|
||||
.has_value());
|
||||
editor.reset();
|
||||
}
|
||||
}
|
||||
if (actions.close_controls) {
|
||||
editor.reset();
|
||||
controls_problem.reset();
|
||||
}
|
||||
if (!editor && capturing) {
|
||||
(*app)->cancel_key_capture();
|
||||
capturing.reset();
|
||||
}
|
||||
}
|
||||
// A finished capture (key, Escape or focus loss) updates the draft only.
|
||||
if (capturing && editor && !(*app)->key_capture_active()) {
|
||||
if (const auto key = (*app)->take_captured_key();
|
||||
key && *key != evo::client::escape_key) {
|
||||
if (auto assigned = editor->assign(capturing->action, capturing->secondary, *key);
|
||||
!assigned)
|
||||
controls_problem = assigned.error();
|
||||
}
|
||||
capturing.reset();
|
||||
}
|
||||
controls.step(actions, **app, ui);
|
||||
actions = {};
|
||||
// The launcher and modal dialogs own input: no world movement or selection.
|
||||
(*app)->set_ui_capture(mode() == Mode::launcher || ui.dialog().has_value() ||
|
||||
editor.has_value());
|
||||
controls.open());
|
||||
const auto navigation = (*app)->take_navigation();
|
||||
// Local input counter; in remote mode the session sets the server tick.
|
||||
const auto intention = (*app)->sample_intention(count);
|
||||
|
||||
Reference in New Issue
Block a user