Skip to content

Missing SysWMinfo for Windows #1263

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

Open
KivApple opened this issue Oct 8, 2022 · 3 comments
Open

Missing SysWMinfo for Windows #1263

KivApple opened this issue Oct 8, 2022 · 3 comments

Comments

@KivApple
Copy link

KivApple commented Oct 8, 2022

Usually in C/C++ code you are able to retrive WinAPI window handle like this:

// SDL_Window *my_window = ...;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(my_window, &wmInfo);
wmInfo.info.win.window // Do something

But it's impossible in Rust:

// let my_window: sdl2::video::Window = ...;
unsafe {
    let mut wminfo: SDL_SysWMinfo = MaybeUninit::zeroed().assume_init();
    SDL_GetVersion(&mut wminfo.version);
    SDL_GetWindowWMInfo(my_window.raw(), &mut wminfo);
    wminfo.info.win.window // no field `win` on type `SDL_SysWMinfo__bindgen_ty_1`
                           // available fields are: `x11`, `wl`, `dummy`
}

It seems that Rust sdl2-sys bindings missing platform-specific union values and on any platform offer only Linux union variants.

@Cobrand
Copy link
Member

Cobrand commented Oct 8, 2022

You need to compile your own sdl2-sys bindings with the "use-bindgen" feature, by default they are Linux variant (not that we don't want to include all of the platforms, but SDL auto-detects the host platform so we can't have generic sdl2-sys bindings).

@KivApple
Copy link
Author

KivApple commented Oct 8, 2022

I've got an error:

   Compiling sdl2-sys v0.35.2
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
     --> C:\Users\kiv\Projects\my_app\target\debug\build\sdl2-sys-2e0686f7ed6e4fb0\out/sdl_bindings.rs:74524:1
      |
74524 | pub struct _IMAGE_TLS_DIRECTORY64 {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
note: `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1` has a `#[repr(align)]` attribute
     --> C:\Users\kiv\Projects\my_app\target\debug\build\sdl2-sys-2e0686f7ed6e4fb0\out/sdl_bindings.rs:74542:1
      |
74542 | pub struct _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1 {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `_IMAGE_TLS_DIRECTORY64` contains a field of type `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1`
     --> C:\Users\kiv\Projects\my_app\target\debug\build\sdl2-sys-2e0686f7ed6e4fb0\out/sdl_bindings.rs:74530:9
      |
74530 |     pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1,
      |         ^^^^^^^^^^^^^^^^
note: ...which contains a field of type `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1`
     --> C:\Users\kiv\Projects\my_app\target\debug\build\sdl2-sys-2e0686f7ed6e4fb0\out/sdl_bindings.rs:74536:9
      |
74536 |     pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1,
      |         ^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0588`.
The following warnings were emitted during compilation:

warning: couldn't execute `llvm-config --prefix` (error: program not found)
warning: set the LLVM_CONFIG_PATH environment variable to the full path to a valid `llvm-config` executable (including the executable itself)

error: could not compile `sdl2-sys` due to previous error

In the meantime, I think there are not a lot platform-specific structures (I actually see only two - SDL_SysWMmsg and SDL_SysWMinfo) and it might be possible to dispatch them in Rust using cfgs rather than in C.

@bane9
Copy link

bane9 commented Dec 6, 2023

I aplogise for the necro, just posting this in the case anyone else needs to retrieve the HWND:
https://gist.github.com/bane9/4b5839bf3828e5b10136e9ac72c76481

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

No branches or pull requests

3 participants