Fix M9.8c review findings in the engineering client
Resolve pointer ownership per SDL event so same-batch panel clicks, wheel and click-to-focus typing never reach the world; keep the Tab toggle independent of idempotent external capture release; own launcher phase and remote session together so Local fixture ends any remote attempt; wrap notices beside a reserved close column within a bounded stack. Adds client-panels test and host/session, same-batch and host-order Tab regressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_sdlrenderer3.h>
|
||||
#include <imgui_internal.h> // Pinned 1.92.9b: last-frame window rectangles (ADR-0084).
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
@@ -70,6 +71,19 @@ struct Toolkit {
|
||||
}
|
||||
};
|
||||
constexpr float click_slop = 4; // Logical units between press and release.
|
||||
// True when `at` lies on a toolkit window drawn in the last frame or any popup is open.
|
||||
// Resolved per event from the toolkit's retained window rectangles, so a move onto a
|
||||
// panel followed by a press in the same batch belongs to the panel, not the world.
|
||||
bool toolkit_window_at(float x, float y) {
|
||||
const ImGuiContext& g = *ImGui::GetCurrentContext();
|
||||
if (g.OpenPopupStack.Size > 0)
|
||||
return true;
|
||||
for (const ImGuiWindow* w : g.Windows)
|
||||
if (w->Active && !w->Hidden && (w->Flags & ImGuiWindowFlags_NoMouseInputs) == 0 &&
|
||||
w->OuterRectClipped.Contains(ImVec2{x, y}))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
struct Runtime {
|
||||
bool acquired{false};
|
||||
~Runtime() {
|
||||
@@ -96,6 +110,7 @@ struct Application::Impl {
|
||||
bool external_capture{false}, tab_capture{false}, toolkit_capture{false};
|
||||
bool toolkit_pointer{false};
|
||||
std::optional<SDL_FPoint> press; // Primary press not taken by the toolkit.
|
||||
bool ui_press{false}; // Primary press owned by the toolkit, until release.
|
||||
std::string screenshot;
|
||||
|
||||
// `drain`: input may have queued while an external UI or toolkit widget held it, so
|
||||
@@ -136,9 +151,9 @@ WindowState Application::state() const noexcept {
|
||||
return result;
|
||||
}
|
||||
void Application::set_ui_capture(bool captured) noexcept {
|
||||
// Independent of the legacy Tab toggle: an idempotent release (every host frame
|
||||
// outside a modal) must not cancel it; Tab is ignored while external capture holds.
|
||||
impl_->external_capture = captured;
|
||||
if (!captured)
|
||||
impl_->tab_capture = false; // An external release also ends the legacy toggle.
|
||||
impl_->update_capture();
|
||||
}
|
||||
void Application::set_overlay(Overlay overlay) {
|
||||
@@ -208,13 +223,16 @@ std::expected<void, Error> Application::poll_events() {
|
||||
return {};
|
||||
p.input.admit(p.state.accepts_input() && !p.backlogged);
|
||||
const auto id = SDL_GetWindowID(p.window.get());
|
||||
// The toolkit's wishes from its last frame decide this batch: keyboard focus in a
|
||||
// widget captures world keys; a pointer over UI cannot click, pan or zoom the world.
|
||||
// Keyboard focus in a widget (reported by the toolkit's last frame) captures world
|
||||
// keys. Pointer ownership is resolved per event below from the panel rectangles.
|
||||
const auto& io = ImGui::GetIO();
|
||||
p.toolkit_capture = io.WantCaptureKeyboard;
|
||||
p.toolkit_pointer = io.WantCaptureMouse;
|
||||
p.update_capture();
|
||||
bool reset = false;
|
||||
// A press on a panel in this batch may focus a text field before the toolkit's next
|
||||
// frame can report it: world key-downs after it wait for that frame (releases pass).
|
||||
bool ui_pressed = false;
|
||||
SDL_Event event{};
|
||||
int count = 0;
|
||||
for (; count < 256 && SDL_PollEvent(&event); ++count) {
|
||||
@@ -253,16 +271,20 @@ std::expected<void, Error> Application::poll_events() {
|
||||
}
|
||||
// Admission changes clear held inputs immediately, even if focus returns in this batch.
|
||||
p.input.admit(p.state.accepts_input() && !p.backlogged);
|
||||
if (!p.state.accepts_input()) {
|
||||
p.press.reset(); // A release may never arrive for this window.
|
||||
p.ui_press = false;
|
||||
}
|
||||
if ((event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) &&
|
||||
event.key.windowID == id) {
|
||||
const bool down = event.type == SDL_EVENT_KEY_DOWN;
|
||||
if (event.key.scancode == SDL_SCANCODE_TAB && down && !event.key.repeat &&
|
||||
p.state.accepts_input() && !p.backlogged && !p.external_capture &&
|
||||
!p.toolkit_capture) {
|
||||
!p.toolkit_capture && !ui_pressed) {
|
||||
p.tab_capture = !p.tab_capture;
|
||||
p.update_capture(false);
|
||||
}
|
||||
if (const auto key = input_key(event.key.scancode)) {
|
||||
if (const auto key = input_key(event.key.scancode); key && (!down || !ui_pressed)) {
|
||||
if (auto result = p.input.key(*key, down, event.key.repeat); !result)
|
||||
p.input.admit(false);
|
||||
}
|
||||
@@ -272,21 +294,27 @@ std::expected<void, Error> Application::poll_events() {
|
||||
p.input.admit(false);
|
||||
}
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.windowID == id &&
|
||||
event.button.button == SDL_BUTTON_LEFT)
|
||||
p.press = p.toolkit_pointer || p.input.captured()
|
||||
event.button.button == SDL_BUTTON_LEFT) {
|
||||
p.ui_press = toolkit_window_at(event.button.x, event.button.y);
|
||||
ui_pressed = ui_pressed || p.ui_press;
|
||||
p.press = p.ui_press || p.input.captured()
|
||||
? std::nullopt
|
||||
: std::optional<SDL_FPoint>{{event.button.x, event.button.y}};
|
||||
}
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP && event.button.windowID == id &&
|
||||
event.button.button == SDL_BUTTON_LEFT) {
|
||||
// A click that operated a widget (pressed over UI) never selects through it.
|
||||
// A click that operated a widget (pressed over UI) never selects through it,
|
||||
// nor does a release over UI that appeared while the button was held.
|
||||
if (p.press && std::abs(event.button.x - p.press->x) <= click_slop &&
|
||||
std::abs(event.button.y - p.press->y) <= click_slop && !p.toolkit_pointer &&
|
||||
std::abs(event.button.y - p.press->y) <= click_slop &&
|
||||
!toolkit_window_at(event.button.x, event.button.y) &&
|
||||
!p.input.click({event.button.x, event.button.y}))
|
||||
p.input.admit(false);
|
||||
p.press.reset();
|
||||
p.ui_press = false;
|
||||
}
|
||||
if (event.type == SDL_EVENT_MOUSE_WHEEL && event.wheel.windowID == id &&
|
||||
!p.toolkit_pointer) {
|
||||
if (event.type == SDL_EVENT_MOUSE_WHEEL && event.wheel.windowID == id && !p.ui_press &&
|
||||
!toolkit_window_at(event.wheel.mouse_x, event.wheel.mouse_y)) {
|
||||
const double direction = event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1;
|
||||
if (!p.input.pointer({event.wheel.mouse_x, event.wheel.mouse_y}) ||
|
||||
!p.input.wheel(event.wheel.y * direction))
|
||||
|
||||
Reference in New Issue
Block a user