Skip to content

Conversation

@Lunderberg
Copy link

Prior to this commit, message types defined by reference were exposed to Rust as type aliases, such as type KeyReleaseEvent = KeyPressEvent;. As a result, they shared a single implementation of BaseEvent, erroneously sharing the same BaseEvent::NUMBER.

This commit updates the code generation to instead expose these types as a wrapper struct, such as struct KeyReleaseEvent(KeyPressEvent);. These wrapper structs expose the same methods, but have an independent implementation of BaseEvent. This allows these events to be constructed, such as for use in SendEvent.

Fixes #214

@Lunderberg
Copy link
Author

Unfortunately, this change has the potential to break user code that relied on the type def representing these types. For example, in x::Event::KeyRelease(release), release now has the type x::KeyReleaseEvent rather than x::KeyPressEvent. I've added implementations of From and AsRef to make migration be as easy as possible, but the distinct types are required in order to have the correct value for both <KeyPressEvent as BaseEvent>::NUMBER and <KeyReleaseEvent as BaseEvent>::NUMBER.

Prior to this commit, message types defined by reference were exposed
to Rust as type aliases, such as `type KeyReleaseEvent =
KeyPressEvent;`.  As a result, they shared a single implementation of
`BaseEvent`, erroneously sharing the same `BaseEvent::NUMBER`.

This commit updates the code generation to instead expose these types
as a wrapper struct, such as `struct KeyReleaseEvent(KeyPressEvent);`.
These wrapper structs expose the same methods, but have an independent
implementation of `BaseEvent`.  This allows these events to be
constructed, such as for use in `SendEvent`.

Fixes rust-x-bindings#214
@Lunderberg Lunderberg force-pushed the distinct-types-when-defined-by-reference branch from d95a206 to 1ddeeb1 Compare November 29, 2024 19:54
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.

Unable to handle "copied" events correctly

1 participant