mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 19:31:30 +11:00
Raw window handle (#110)
* Added support for raw-window-handle Ref #104 * Fixed some typos * Fixed more typos * windows fix * Another windows fix * Another typo * More typos * More windwos fixes * Yet anonther Windows fix
This commit is contained in:
parent
9c86b47ec5
commit
a2633f78ad
|
@ -22,6 +22,7 @@ cc = "1.0"
|
|||
[dependencies]
|
||||
cast = "0.2"
|
||||
time = "0.1.34"
|
||||
raw-window-handle = "0.3.3"
|
||||
|
||||
[target.'cfg(windows)'.dependencies.winapi]
|
||||
version = "0.3"
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#![cfg(target_os = "macos")]
|
||||
|
||||
extern crate raw_window_handle;
|
||||
|
||||
use error::Error;
|
||||
use key_handler::KeyHandler;
|
||||
use Result;
|
||||
|
@ -243,6 +245,17 @@ unsafe extern "C" fn char_callback(window: *mut c_void, code_point: u32) {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
||||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||
let handle = raw_window_handle::macos::MacOSHandle {
|
||||
ns_window: self.window_handle,
|
||||
ns_view: std::ptr::null_mut(),
|
||||
..raw_window_handle::macos::MacOSHandle::empty()
|
||||
};
|
||||
raw_window_handle::RawWindowHandle::MacOS(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
||||
let n = match CString::new(name) {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
extern crate cast;
|
||||
extern crate x11_dl;
|
||||
extern crate raw_window_handle;
|
||||
|
||||
use self::x11_dl::keysym::*;
|
||||
use self::x11_dl::xcursor;
|
||||
|
@ -242,6 +243,17 @@ pub struct Window {
|
|||
menus: Vec<UnixMenu>,
|
||||
}
|
||||
|
||||
unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
||||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||
let handle = raw_window_handle::unix::XlibHandle {
|
||||
window: self.handle,
|
||||
display: self.d.display as *mut core::ffi::c_void,
|
||||
..raw_window_handle::unix::XlibHandle::empty()
|
||||
};
|
||||
raw_window_handle::RawWindowHandle::Xlib(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
||||
let name = match CString::new(name) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![cfg(target_os = "windows")]
|
||||
|
||||
extern crate raw_window_handle;
|
||||
extern crate time;
|
||||
extern crate winapi;
|
||||
|
||||
|
@ -337,13 +338,16 @@ pub struct Window {
|
|||
cursors: [windef::HCURSOR; 8],
|
||||
}
|
||||
|
||||
// TranslateAccelerator is currently missing in win-rs
|
||||
// #[cfg(target_family = "windows")]
|
||||
// #[link(name = "user32")]
|
||||
// #[allow(non_snake_case)]
|
||||
// extern "system" {
|
||||
// fn RemoveMenu(menu: HMENU, pos: UINT, flags: UINT) -> BOOL;
|
||||
// }
|
||||
unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
||||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||
let handle = raw_window_handle::windows::WindowsHandle {
|
||||
hwnd: self.window.unwrap() as *mut raw::c_void,
|
||||
hinstance: unsafe { libloaderapi::GetModuleHandleA(ptr::null()) } as *mut raw::c_void,
|
||||
..raw_window_handle::windows::WindowsHandle::empty()
|
||||
};
|
||||
raw_window_handle::RawWindowHandle::Windows(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
fn open_window(
|
||||
|
|
Loading…
Reference in a new issue