Skip to content

Add own start/stop scripts, exact NTSC refresh rate and pointer parking - #173

Closed
JarJarShinks wants to merge 1 commit into
lippdev:mainfrom
JarJarShinks:custom-hooks-ntsc-pointer
Closed

JarJarShinks wants to merge 1 commit into
lippdev:mainfrom
JarJarShinks:custom-hooks-ntsc-pointer

Conversation

@JarJarShinks

Copy link
Copy Markdown

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

This PR has behavior gaps in timeout cleanup, custom-app pointer parking, and preserving display mode data during the exact-rate request.

Reviewed changes

Reviewed the initial commit adding session hooks, exact NTSC refresh selection, and pointer parking.

  • Session scripts: Adds configurable start and stop commands with hidden execution and a 60-second wait limit.
  • Exact refresh rate: Requests the 1000/1001 refresh-rate twin for the focused display through CCD.
  • Pointer parking: Adds an option to move the pointer after the launcher is ready, with settings, localization, docs, and tests.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6-luna | 𝕏

AppLog.Write($"Script ({label}): não foi possível iniciar");
return;
}
if (!process.WaitForExit((int)UserCommand.Timeout.TotalMilliseconds))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this wait times out, disposing the Process only closes the handle; cmd.exe and the script keep running. A timed-out start script can therefore overlap with session teardown and the stop script, leaving user state modified after restoration; stop or track the timed-out command before returning.

Technical details
# Timed-out session commands remain active

## Affected sites
- `src/ConsoleMode/Services/UserHooks.cs:34-37` — returns after timeout without stopping or retaining the child process.
- `src/ConsoleMode/Services/ConsoleEngine.cs:105` — start command runs before session setup continues.
- `src/ConsoleMode/Services/ConsoleEngine.cs:385` — stop command runs during teardown and may race a still-running start command.

## Required outcome
- Ensure a command reported as timed out cannot continue mutating state unnoticed while the session or its matching stop command proceeds.

var now = DateTime.Now;
var ready = State.FullscreenMode == "xboxMode"
? State.LaunchTime is { } launched && now - launched >= PointerParking.XboxDelay
: State.HasAppeared;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom-app mode takes an earlier return in Tick and never sets State.HasAppeared; only the fullscreen-window path below sets it. Consequently ready stays false and the pointer is never parked for custom apps, despite the documented behavior; use a readiness signal that custom-app sessions can reach.

}
if (!found) return -100;

var flags = SDC_USE_SUPPLIED_DISPLAY_CONFIG | SDC_ALLOW_CHANGES;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDC_ALLOW_CHANGES permits Windows to modify supplied source and target mode information, and the same flag is used for the subsequent apply. That means this request can alter the source mode's resolution or desktop position, contrary to the method's preservation guarantee; avoid allowing source-mode changes or verify and preserve those values.

Technical details
# Exact refresh request may change source mode data

## Affected sites
- `src/ConsoleMode/Native/CcdHelper.cs:368-371` — validation and application both include `SDC_ALLOW_CHANGES` while passing the queried `modes` array.
- `src/ConsoleMode/Native/CcdHelper.cs:361-363` — source mode data is retained but its values are not checked after application.

## Required outcome
- Apply the target refresh-rate request without silently changing the display's source resolution or desktop position.

## Suggested approach
- Reject configurations that require source-mode changes, or confirm the applied source mode still has the original dimensions and position.

@lippdev

lippdev commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks a lot for this, and for the effort you're putting into making Console Mode better! The code is careful and follows the project's conventions well: strings in all six languages, both changelogs, the guides and the TESTING.md checklist. The 553 tests pass and the app builds locally.

I'm already working on implementing these ideas, starting with the pointer from #172. Before going further, could you split this into one PR per feature? The project keeps one topic per PR (see AGENTS.md), and these three carry very different risk:

  1. Pointer parking: the smallest and safest. Two requests: make it on by default, and put the pointer back where it was when the session ends.
  2. Start/stop scripts: the stop command only lives in memory. If the app dies mid-session, the restore on the next start doesn't run it. Persisting it, like the audio backup, would close that gap.
  3. Exact NTSC refresh rate: it touches CCD timing, so it needs testing on real hardware. Also, NtscBase treats 59/23/29 as 60/24/30, which would move a screen that really runs at 59 Hz to 59.94.

A few small things for each PR:

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants