mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-03-30 11:37:10 -07:00
tests and docs
This commit is contained in:
@@ -543,6 +543,22 @@ fn main() {
|
||||
|
||||
```
|
||||
|
||||
# Support for raw-window-handle
|
||||
|
||||
`raw-window-handle` can be enabled using the feature name:
|
||||
|
||||
```toml
|
||||
[dependencies.sdl2]
|
||||
version = "0.32"
|
||||
features = ["raw-window-handle"]
|
||||
```
|
||||
|
||||
### sdl2 with raw-window-handle on macOS:
|
||||
|
||||
On macOS the `RawWindowHandle.ns_view` field is returned null. Libraries consuming the `RawWindowHandle` (such as
|
||||
`wgpu-rs`) should determine a sane default for `ns_view`. If they do not, please file an issue with the associated
|
||||
project.
|
||||
|
||||
# When things go wrong
|
||||
Rust, and Rust-SDL2, are both still heavily in development, and you may run
|
||||
into teething issues when using this. Before panicking, check that you're using
|
||||
|
||||
@@ -27,6 +27,9 @@ Ignore unknown bits in `SDL_Keysym`'s `mod` field (key modifiers) when construct
|
||||
[PR #898](https://github.com/Rust-SDL2/rust-sdl2/pull/898):
|
||||
Implements `TryFrom<PixelFormatEnum>` for `PixelFormat`
|
||||
|
||||
[PR #962](https://github.com/Rust-SDL2/rust-sdl2/pull/962):
|
||||
Added `raw-window-handle` support for Windows, Linux (X11 and Wayland) and macOS.
|
||||
|
||||
### v0.32.2
|
||||
|
||||
[PR #868](https://github.com/Rust-SDL2/rust-sdl2/pull/868):
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
extern crate raw_window_handle;
|
||||
|
||||
use self::raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||
use crate::{sys::SDL_Window, video::Window as VideoWindow};
|
||||
use crate::{sys::SDL_Window, video::Window};
|
||||
|
||||
unsafe impl HasRawWindowHandle for VideoWindow {
|
||||
unsafe impl HasRawWindowHandle for Window {
|
||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||
use self::SDL_SYSWM_TYPE::*;
|
||||
let mut wm_info = SDL_SysWMinfo::default();
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#[cfg(feature = "raw-window-handle")]
|
||||
mod raw_window_handle_test {
|
||||
extern crate raw_window_handle;
|
||||
extern crate sdl2;
|
||||
|
||||
use self::raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||
use self::sdl2::video::Window;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn get_windows_handle() {
|
||||
let window = new_hidden_window();
|
||||
match window.raw_window_handle() {
|
||||
RawWindowHandle::Windows(windows_handle) => {
|
||||
assert_ne!(windows_handle.hwnd, 0 as *mut libc::c_void);
|
||||
println!("Successfully received Windows RawWindowHandle!");
|
||||
},
|
||||
x => assert!(false, "Received wrong RawWindowHandle type for Windows: {:?}", x),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd",
|
||||
))]
|
||||
#[test]
|
||||
fn get_linux_handle() {
|
||||
let window = new_hidden_window();
|
||||
match window.raw_window_handle() {
|
||||
RawWindowHandle::Xlib(x11_handle) => {
|
||||
assert_ne!(x11_handle.window, 0, "Window for X11 should not be 0");
|
||||
assert_ne!(x11_handle.display, 0 as *mut libc::c_void, "Display for X11 should not be null");
|
||||
println!("Successfully received linux X11 RawWindowHandle!");
|
||||
},
|
||||
RawWindowHandle::Wayland(wayland_handle) => {
|
||||
assert_ne!(wayland_handle.surface, 0 as *mut libc::c_void, "Surface for Wayland should not be null");
|
||||
assert_ne!(wayland_handle.display, 0 as *mut libc::c_void, "Display for Wayland should not be null");
|
||||
println!("Successfully received linux Wayland RawWindowHandle!");
|
||||
},
|
||||
x => assert!(false, "Received wrong RawWindowHandle type for linux: {:?}", x),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn get_macos_handle() {
|
||||
let window = new_hidden_window();
|
||||
match window.raw_window_handle() {
|
||||
RawWindowHandle::MacOS(macos_handle) => {
|
||||
assert_ne!(macos_handle.ns_window, 0 as *mut libc::c_void, "ns_window should not be null");
|
||||
assert_eq!(macos_handle.ns_view, 0 as *mut libc::c_void, "nw_view should be null");
|
||||
println!("Successfully received macOS RawWindowHandle!");
|
||||
},
|
||||
x => assert!(false, "Received wrong RawWindowHandle type for macOS: {:?}", x),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn new_hidden_window() -> Window {
|
||||
let context = sdl2::init().unwrap();
|
||||
let video_subsystem = context.video().unwrap();
|
||||
video_subsystem
|
||||
.window("Hello, World!", 800, 600)
|
||||
.hidden()
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user