mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-11 03:21:32 +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]
|
[dependencies]
|
||||||
cast = "0.2"
|
cast = "0.2"
|
||||||
time = "0.1.34"
|
time = "0.1.34"
|
||||||
|
raw-window-handle = "0.3.3"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.winapi]
|
[target.'cfg(windows)'.dependencies.winapi]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#![cfg(target_os = "macos")]
|
#![cfg(target_os = "macos")]
|
||||||
|
|
||||||
|
extern crate raw_window_handle;
|
||||||
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use key_handler::KeyHandler;
|
use key_handler::KeyHandler;
|
||||||
use Result;
|
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 {
|
impl Window {
|
||||||
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
||||||
let n = match CString::new(name) {
|
let n = match CString::new(name) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
extern crate cast;
|
extern crate cast;
|
||||||
extern crate x11_dl;
|
extern crate x11_dl;
|
||||||
|
extern crate raw_window_handle;
|
||||||
|
|
||||||
use self::x11_dl::keysym::*;
|
use self::x11_dl::keysym::*;
|
||||||
use self::x11_dl::xcursor;
|
use self::x11_dl::xcursor;
|
||||||
|
@ -242,6 +243,17 @@ pub struct Window {
|
||||||
menus: Vec<UnixMenu>,
|
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 {
|
impl Window {
|
||||||
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
|
||||||
let name = match CString::new(name) {
|
let name = match CString::new(name) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![cfg(target_os = "windows")]
|
#![cfg(target_os = "windows")]
|
||||||
|
|
||||||
|
extern crate raw_window_handle;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
extern crate winapi;
|
extern crate winapi;
|
||||||
|
|
||||||
|
@ -337,13 +338,16 @@ pub struct Window {
|
||||||
cursors: [windef::HCURSOR; 8],
|
cursors: [windef::HCURSOR; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
// TranslateAccelerator is currently missing in win-rs
|
unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
||||||
// #[cfg(target_family = "windows")]
|
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||||
// #[link(name = "user32")]
|
let handle = raw_window_handle::windows::WindowsHandle {
|
||||||
// #[allow(non_snake_case)]
|
hwnd: self.window.unwrap() as *mut raw::c_void,
|
||||||
// extern "system" {
|
hinstance: unsafe { libloaderapi::GetModuleHandleA(ptr::null()) } as *mut raw::c_void,
|
||||||
// fn RemoveMenu(menu: HMENU, pos: UINT, flags: UINT) -> BOOL;
|
..raw_window_handle::windows::WindowsHandle::empty()
|
||||||
// }
|
};
|
||||||
|
raw_window_handle::RawWindowHandle::Windows(handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
fn open_window(
|
fn open_window(
|
||||||
|
|
Loading…
Reference in a new issue