Skip to content
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

api: add DeviceId::{into,from}_raw #3941

Merged
merged 1 commit into from
Oct 11, 2024
Merged

api: add DeviceId::{into,from}_raw #3941

merged 1 commit into from
Oct 11, 2024

Conversation

kchibisov
Copy link
Member

The same as for WindowId.

This also removes the internal platform ID.

--

I'm not sure what type to pick here, since some use u32, some i32. I think i64 would be the best, but then, negative values for DeviceId are strange?

Also, it's not that clear to what IDs should be limited.

For now I'm just using u64.

@daxpedda
Copy link
Member

daxpedda commented Oct 8, 2024

Whats the reason for introducing the methods? I would prefer keeping it opaque for the same reasons discussed in #3795.

@kchibisov
Copy link
Member Author

@daxpedda we need a way to build those types when backends will be split.

@kchibisov kchibisov force-pushed the kchibisov/device-id branch from 08ebda5 to 293736b Compare October 8, 2024 21:14
@kchibisov
Copy link
Member Author

I can make those functions private for now, but they'll be public eventually...

@daxpedda
Copy link
Member

daxpedda commented Oct 8, 2024

@daxpedda we need a way to build those types when backends will be split.

No, we can have Winit introduce its own DeviceId type that wraps this one to keep it opaque.
This problem was discussed in the last two meetings.

Generally speaking I'm always leaning towards making compromises internally rather then on the public API, which is to me the most important part of the whole project.

I'm in favor of keeping them private as long as the types are still in the winit crate.

@kchibisov
Copy link
Member Author

I mean, if the core types are in winit-core including DeviceId, I'm not sure how you'd create one without e.g. Box or something like that.

Like with a layout like

// winit-core

pub trait DeviceEventHandler: ApplicationHandler {
    fn device_event(&mut self, device_id: Option<DeviceId>, event: Event); 
}

// winit-wayland
{
     // Should be `DeviceId`, but no way to build?
     state.device_event(device_id???, event)
}

It's true that if you re-export everything possible inside the winit and wrap everything, you can probably avoid certain things, but however you can not create traits with types like that, or at least there still should be a type that can be build from e.g. u64.

Unless you just do dyn, but dyn for Id doesn't make any sense.

@kchibisov kchibisov force-pushed the kchibisov/device-id branch from 293736b to ca3162f Compare October 10, 2024 17:40
The same as for `WindowId`.
Copy link
Member

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

It's true that if you re-export everything possible inside the winit and wrap everything, you can probably avoid certain things, but however you can not create traits with types like that, or at least there still should be a type that can be build from e.g. u64.

Unless you just do dyn, but dyn for Id doesn't make any sense.

Yeah, makes sense.

Only reviewed the public API and the Web backend, LGTM!

@kchibisov
Copy link
Member Author

I've removed public API for now, so should be less concerning.

@kchibisov kchibisov merged commit 4e3165f into master Oct 11, 2024
58 checks passed
@kchibisov kchibisov deleted the kchibisov/device-id branch October 11, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants