Skip to content

Timestamps on the events? #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
waywardmonkeys opened this issue Mar 23, 2025 · 8 comments
Closed

Timestamps on the events? #72

waywardmonkeys opened this issue Mar 23, 2025 · 8 comments

Comments

@waywardmonkeys
Copy link
Contributor

In the browser, KeyEvent and CompositionEvent inherit from Event which has a timestamp. In doing some PointerEvent stuff, I have a timestamp available (since this is useful for doing predicted events from sequences of events).

Would there be interest in adding a timestamp: u64 to KeyEvent and CompositionEvent?

@madsmtm
Copy link
Member

madsmtm commented Mar 27, 2025

Hmm, if we're to have a time stamp, I'd somewhat prefer using std::time::Instant (or web_time::Instant in WASM). But that also kinda conflicts with #17.

@waywardmonkeys
Copy link
Contributor Author

The problem with std::time::Instant is that you can't access or set the value if you're doing things like bridging events, so you can't use the value that the platform gives you to populate it, and if you're converting from another event structure into this one, you can't set it either to a value corresponding to the other.

@waywardmonkeys
Copy link
Contributor Author

You could use core::time::Duration with a flexible interpretation of what the epoch is though.

@madsmtm
Copy link
Member

madsmtm commented Mar 28, 2025

Hmm, yeah. I guess std::time::SystemTime is more meant for transferring over the wire, but you don't actually want the strong guarantees that those provide.

@madsmtm
Copy link
Member

madsmtm commented Mar 28, 2025

Another thing to note is that there's many other fields on the inheritance chain of KeyboardEvent (Event.srcElement, Event.target, UIEvent.view), and it's immediately clear to me where we draw the line?

That of course still shouldn't be an argument against adding this if it's useful, just interesting to discuss.

@madsmtm
Copy link
Member

madsmtm commented Mar 28, 2025

I don't have a strong opinion here either way, will let @pyfisch decide.

@pyfisch
Copy link
Contributor

pyfisch commented Apr 21, 2025

I don't want to add timestamps (or other metadata) to the event type. Keyboard-types was designed with browser uses (in particular servo) in mind.

While in JS you have an event class with attributes such as timeStamp and target from which specific events classes inherit, Servo uses composition instead: There is an Event struct that contains shared attributes with one attribute containing an enum for all the different types: keyboard, mouse, message events, etc. Each variant in turn contains the attributes specific to that event type.

Let me know if that explanation was clear, you can also look up the event types in servo.

@pyfisch pyfisch closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2025
@waywardmonkeys
Copy link
Contributor Author

Sounds good to me! Thanks!

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

No branches or pull requests

3 participants