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

SDL_GetWindowWMInfo is not exposed #649

Closed
MaikKlein opened this issue Apr 28, 2017 · 6 comments
Closed

SDL_GetWindowWMInfo is not exposed #649

MaikKlein opened this issue Apr 28, 2017 · 6 comments
Milestone

Comments

@MaikKlein
Copy link

MaikKlein commented Apr 28, 2017

See, https://wiki.libsdl.org/SDL_GetWindowWMInfo. At least I could not find it.

@Cobrand
Copy link
Member

Cobrand commented May 14, 2017

Here is the native code that defines SDL_SysWMinfo:

struct SDL_SysWMinfo
{
    SDL_version version;
    SDL_SYSWM_TYPE subsystem;
    union
    {
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
        struct
        {
            HWND window;                /**< The window handle */
            HDC hdc;                    /**< The window device context */
        } win;
#endif
#if defined(SDL_VIDEO_DRIVER_WINRT)
        struct
        {
            IInspectable * window;      /**< The WinRT CoreWindow */
        } winrt;
#endif
#if defined(SDL_VIDEO_DRIVER_X11)
        struct
        {
            Display *display;           /**< The X11 display */
            Window window;              /**< The X11 window */
        } x11;
#endif
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
        struct
        {
            IDirectFB *dfb;             /**< The directfb main interface */
            IDirectFBWindow *window;    /**< The directfb window handle */
            IDirectFBSurface *surface;  /**< The directfb client surface */
        } dfb;
#endif
#if defined(SDL_VIDEO_DRIVER_COCOA)
        struct
        {
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
            NSWindow __unsafe_unretained *window; /* The Cocoa window */
#else
            NSWindow *window;                     /* The Cocoa window */
#endif
        } cocoa;
#endif
#if defined(SDL_VIDEO_DRIVER_UIKIT)
        struct
        {
#if defined(__OBJC__) && defined(__has_feature) && __has_feature(objc_arc)
            UIWindow __unsafe_unretained *window; /* The UIKit window */
#else
            UIWindow *window;                     /* The UIKit window */
#endif
            GLuint framebuffer; /* The GL view's Framebuffer Object. It must be bound when rendering to the screen using GL. */
            GLuint colorbuffer; /* The GL view's color Renderbuffer Object. It must be bound when SDL_GL_SwapWindow is called. */
            GLuint resolveFramebuffer; /* The Framebuffer Object which holds the resolve color Renderbuffer, when MSAA is used. */
        } uikit;
#endif
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
        struct
        {
            struct wl_display *display;            /**< Wayland display */
            struct wl_surface *surface;            /**< Wayland surface */
            struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
        } wl;
#endif
#if defined(SDL_VIDEO_DRIVER_MIR)
        struct
        {
            struct MirConnection *connection;  /**< Mir display server connection */
            struct MirSurface *surface;  /**< Mir surface */
        } mir;
#endif

#if defined(SDL_VIDEO_DRIVER_ANDROID)
        struct
        {
            ANativeWindow *window;
            EGLSurface surface;
        } android;
#endif

#if defined(SDL_VIDEO_DRIVER_VIVANTE)
        struct
        {
            EGLNativeDisplayType display;
            EGLNativeWindowType window;
        } vivante;
#endif

        /* Can't have an empty union */
        int dummy;
    } info;
};

SDL_version and subsystem aside, there is actually a huge union where all its variants are conditional on things that we can hardly predict, unless at compile time. That effectively means that this binding should be part of the compilation process, and thus this method cannot be implemented without integrating bindgen to this crate, unfortunately. This is a pretty special case since this is one of the few functions which are very platform-specific, and thus lots of #ifdef are required in this part of sdl2.

@asgeir
Copy link

asgeir commented Jun 17, 2017

It sounds like version 2.0.6 will guarantee that this union will be exactly 64 bytes http://hg.libsdl.org/SDL/rev/69452f9839d5 which should make this a bit easier

@hodasemi
Copy link

I built something minimalistic to test the topic:

extern crate sdl2;

use std::mem;

pub enum SDL_SYSWM_TYPE {
    SDL_SYSWM_UNKNOWN,
    SDL_SYSWM_WINDOWS,
    SDL_SYSWM_X11,
    SDL_SYSWM_DIRECTFB,
    SDL_SYSWM_COCOA,
    SDL_SYSWM_UIKIT,
    SDL_SYSWM_WAYLAND,
    SDL_SYSWM_MIR,
    SDL_SYSWM_WINRT,
    SDL_SYSWM_ANDROID,
    SDL_SYSWM_VIVANTE
}

struct SdlSysWminfo {
    pub version: sdl2::version::Version,
    pub subsystem: SDL_SYSWM_TYPE,
    pub info: [u64; 32],
}

extern "C" {
    fn SDL_GetWindowWMInfo(window: *mut sdl2::sys::SDL_Window, info: *mut SdlSysWminfo) -> bool;
}

fn main() {
    let sdl_context = sdl2::init().unwrap();
    let video_subsystem = sdl_context.video().unwrap();

    let window = video_subsystem.window("SDL2", 640, 480)
        .position_centered().build().unwrap();

    let mut sys_wm_info: SdlSysWminfo;

    unsafe {
        sys_wm_info = mem::uninitialized();
    }

    sys_wm_info.version = sdl2::version::version();

    println!("sdl version: {}.{}.{}", sys_wm_info.version.major, sys_wm_info.version.minor, sys_wm_info.version.patch);

    unsafe {
        if !SDL_GetWindowWMInfo(window.raw(), &mut sys_wm_info) {
            panic!("syswm_error: {}", sdl2::get_error());
        }
    }
}

The strange thing is, that it will always panic with:
Application not compiled with SDL 2.0

@asgeir
Copy link

asgeir commented Jun 20, 2017

@hodasemi That can be fixed by declaring the SdlSysWminfo struct as #[repr(C)]

@hodasemi
Copy link

@asgeir Yes, thanks. I also changed the type of subsystem to u32 and made SDL_SYSWM_* to const u32 values. It seems to be working now.

@Cobrand Cobrand modified the milestone: 0.31 Jul 5, 2017
@Cobrand Cobrand closed this as completed in 7623bd5 Jul 9, 2017
@Cobrand
Copy link
Member

Cobrand commented Jul 9, 2017

I added this to the master branch in sdl2_sys, please tell me if that works for you as well. By the way, your pub info: [u64; 32] in your example is 256 bytes and not 64 bytes :) Might want to correct that in your code.

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

No branches or pull requests

4 participants