Skip to content

10/15 keyboard input, from host events through to window messages - #11

Merged
evmar merged 2 commits into
evmar:mainfrom
avanturist888:slice/10
Aug 20, 2026
Merged

10/15 keyboard input, from host events through to window messages#11
evmar merged 2 commits into
evmar:mainfrom
avanturist888:slice/10

Conversation

@avanturist888

Copy link
Copy Markdown
Contributor

Part 10 of 15, splitting up #1. Needs 2, 5 and 9 merged first; on its own it does not compile.

Comment thread win32/winapi/src/user32/input.rs Outdated
}

/// Byte offset of a mouse object within the standard c_dfDIMouse data format:
/// lX@0, lY@4, lZ@8, then one byte per button from 12.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't follow this, why not use a regular struct?

};
// Games poll for messages every frame; keep the audio mixer fed from here
// too, in case the app renders without flipping.
crate::dsound::pump(ctx);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I like this solution, but I wonder what the more principled thing is, like what does Windows itself do? Are we missing a thread that causes dsound to pump or something? (I don't think we need to add one, I am just trying to understand.)

@avanturist888

Copy link
Copy Markdown
Contributor Author

The mouse offsets are a DIMOUSESTATE struct now, with the offsets coming from offset_of! rather than being written out. Sorry, that one was just laziness on my part.

On pumping from the message loop: I do not think we are missing a thread, and I think Windows genuinely has no equivalent of one. On real hardware the sound card DMAs straight out of the DirectSound buffer, so mixing happens below the app entirely and nothing in its process has to run for playback to advance. There is no thread to reproduce, so the choice is between a mixer thread of our own and advancing the mixer from somewhere the app passes through anyway.

I went with the second because a thread would have to read guest memory while the guest writes it, and the only place the two are ordered against each other is the message pump. It is a stand-in rather than the principled thing, and if the mixer ever moves into the host (see #10) the question goes away.

@evmar
evmar merged commit fb3c980 into evmar:main Aug 20, 2026
@avanturist888
avanturist888 deleted the slice/10 branch August 20, 2026 19:15
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.

2 participants