test(uconsole): support deterministic GTK page captures

This commit is contained in:
liu weikai
2026-07-24 16:38:12 +08:00
parent a2a4f6dcb4
commit 09e30a87fe
3 changed files with 34 additions and 1 deletions
@@ -21,6 +21,8 @@ struct GtkCanvasPresenter::Impl
GtkDrawingArea* drawing_area = nullptr;
GtkEventController* key_controller = nullptr;
bool running = true;
bool startup_inputs_queued = false;
bool startup_shortcut_queued = false;
PointerState pointer{};
int frame_width = 0;
int frame_height = 0;
@@ -198,6 +200,27 @@ GtkCanvasPresenter::~GtkCanvasPresenter()
bool GtkCanvasPresenter::pump()
{
if (!impl_->startup_inputs_queued)
{
for (int step = 0; step < impl_->options.initial_nav_steps; ++step)
{
queueSpecial(impl_->input, InputKey::Tab, "TAB");
}
if (impl_->options.initial_nav_steps > 0)
{
queueSpecial(impl_->input, InputKey::Enter, "OK");
}
impl_->startup_inputs_queued = true;
}
else if (!impl_->startup_shortcut_queued &&
impl_->presented_frames >= 5 &&
impl_->options.initial_shortcut != '\0')
{
impl_->input.push_back(::trailmate::cardputer_zero::app::
makeCharacterInput(
impl_->options.initial_shortcut));
impl_->startup_shortcut_queued = true;
}
while (g_main_context_pending(nullptr))
{
g_main_context_iteration(nullptr, FALSE);
@@ -16,6 +16,8 @@ struct GtkCanvasPresenterOptions
std::string title = "Trail Mate uConsole";
std::string screenshot_path{};
int screenshot_after_frames = 45;
int initial_nav_steps = 0;
char initial_shortcut = '\0';
};
class GtkCanvasPresenter final
@@ -89,7 +89,15 @@ int main(int argc, char** argv)
.screenshot_path =
envString("TRAIL_MATE_UCONSOLE_SCREENSHOT", ""),
.screenshot_after_frames =
envInt("TRAIL_MATE_UCONSOLE_SCREENSHOT_AFTER_FRAMES", 45)}};
envInt("TRAIL_MATE_UCONSOLE_SCREENSHOT_AFTER_FRAMES", 45),
.initial_nav_steps =
envInt("TRAIL_MATE_UCONSOLE_INITIAL_NAV_STEPS", 0),
.initial_shortcut =
envString("TRAIL_MATE_UCONSOLE_INITIAL_SHORTCUT", "")
.empty()
? '\0'
: envString("TRAIL_MATE_UCONSOLE_INITIAL_SHORTCUT", "")
.front()}};
trailmate::uconsole::UConsoleShellOptions shell{};
shell.width = options.width;
shell.height = options.height;