raw-window-handle 0.5.0
This commit is contained in:
parent
c129b12ead
commit
a6e07b7ea7
|
@ -20,7 +20,7 @@ opengl = ["uuid", "x11/glx"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
keyboard-types = { version = "0.6.1", default-features = false }
|
keyboard-types = { version = "0.6.1", default-features = false }
|
||||||
raw-window-handle = "0.4.2"
|
raw-window-handle = "0.5.0"
|
||||||
|
|
||||||
[target.'cfg(target_os="linux")'.dependencies]
|
[target.'cfg(target_os="linux")'.dependencies]
|
||||||
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
|
||||||
|
|
|
@ -17,7 +17,10 @@ use keyboard_types::KeyboardEvent;
|
||||||
|
|
||||||
use objc::{msg_send, runtime::Object, sel, sel_impl};
|
use objc::{msg_send, runtime::Object, sel, sel_impl};
|
||||||
|
|
||||||
use raw_window_handle::{AppKitHandle, HasRawWindowHandle, RawWindowHandle};
|
use raw_window_handle::{
|
||||||
|
AppKitDisplayHandle, AppKitWindowHandle, HasRawDisplayHandle, HasRawWindowHandle,
|
||||||
|
RawDisplayHandle, RawWindowHandle,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Event, EventStatus, Size, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions,
|
Event, EventStatus, Size, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions,
|
||||||
|
@ -62,7 +65,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawWindowHandle::AppKit(AppKitHandle::empty())
|
RawWindowHandle::AppKit(AppKitWindowHandle::empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,6 +374,7 @@ impl WindowState {
|
||||||
/// Don't use this to create two simulataneous references to a single
|
/// Don't use this to create two simulataneous references to a single
|
||||||
/// WindowState. Apparently, macOS blocks for the duration of an event,
|
/// WindowState. Apparently, macOS blocks for the duration of an event,
|
||||||
/// callback, meaning that this shouldn't be a problem in practice.
|
/// callback, meaning that this shouldn't be a problem in practice.
|
||||||
|
#[allow(clippy::mut_from_ref)]
|
||||||
pub(super) unsafe fn from_field(obj: &Object) -> &mut Self {
|
pub(super) unsafe fn from_field(obj: &Object) -> &mut Self {
|
||||||
let state_ptr: *mut c_void = *obj.get_ivar(BASEVIEW_STATE_IVAR);
|
let state_ptr: *mut c_void = *obj.get_ivar(BASEVIEW_STATE_IVAR);
|
||||||
|
|
||||||
|
@ -476,7 +480,7 @@ unsafe impl HasRawWindowHandle for Window {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
let ns_window = self.ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
let ns_window = self.ns_window.unwrap_or(ptr::null_mut()) as *mut c_void;
|
||||||
|
|
||||||
let mut handle = AppKitHandle::empty();
|
let mut handle = AppKitWindowHandle::empty();
|
||||||
handle.ns_window = ns_window;
|
handle.ns_window = ns_window;
|
||||||
handle.ns_view = self.ns_view as *mut c_void;
|
handle.ns_view = self.ns_view as *mut c_void;
|
||||||
|
|
||||||
|
@ -484,6 +488,12 @@ unsafe impl HasRawWindowHandle for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl HasRawDisplayHandle for Window {
|
||||||
|
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
|
||||||
|
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copy_to_clipboard(string: &str) {
|
pub fn copy_to_clipboard(string: &str) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let pb = NSPasteboard::generalPasteboard(nil);
|
let pb = NSPasteboard::generalPasteboard(nil);
|
||||||
|
|
|
@ -24,7 +24,10 @@ use std::os::windows::ffi::OsStrExt;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle};
|
use raw_window_handle::{
|
||||||
|
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, Win32WindowHandle,
|
||||||
|
WindowsDisplayHandle,
|
||||||
|
};
|
||||||
|
|
||||||
const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1;
|
const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1;
|
||||||
|
|
||||||
|
@ -84,12 +87,12 @@ impl WindowHandle {
|
||||||
unsafe impl HasRawWindowHandle for WindowHandle {
|
unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
if let Some(hwnd) = self.hwnd {
|
if let Some(hwnd) = self.hwnd {
|
||||||
let mut handle = Win32Handle::empty();
|
let mut handle = Win32WindowHandle::empty();
|
||||||
handle.hwnd = hwnd as *mut c_void;
|
handle.hwnd = hwnd as *mut c_void;
|
||||||
|
|
||||||
RawWindowHandle::Win32(handle)
|
RawWindowHandle::Win32(handle)
|
||||||
} else {
|
} else {
|
||||||
RawWindowHandle::Win32(Win32Handle::empty())
|
RawWindowHandle::Win32(Win32WindowHandle::empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -757,13 +760,19 @@ impl Window<'_> {
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for Window<'_> {
|
unsafe impl HasRawWindowHandle for Window<'_> {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
let mut handle = Win32Handle::empty();
|
let mut handle = Win32WindowHandle::empty();
|
||||||
handle.hwnd = self.state.hwnd as *mut c_void;
|
handle.hwnd = self.state.hwnd as *mut c_void;
|
||||||
|
|
||||||
RawWindowHandle::Win32(handle)
|
RawWindowHandle::Win32(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl HasRawDisplayHandle for Window<'_> {
|
||||||
|
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
|
RawDisplayHandle::Windows(WindowsDisplayHandle::empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn copy_to_clipboard(data: &str) {
|
pub fn copy_to_clipboard(data: &str) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
use raw_window_handle::{
|
||||||
|
AppKitDisplayHandle, HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::event::{Event, EventStatus};
|
use crate::event::{Event, EventStatus};
|
||||||
use crate::window_open_options::WindowOpenOptions;
|
use crate::window_open_options::WindowOpenOptions;
|
||||||
|
@ -48,6 +50,12 @@ unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl HasRawDisplayHandle for WindowHandle {
|
||||||
|
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
|
||||||
|
RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait WindowHandler {
|
pub trait WindowHandler {
|
||||||
fn on_frame(&mut self, window: &mut Window);
|
fn on_frame(&mut self, window: &mut Window);
|
||||||
fn on_event(&mut self, window: &mut Window, event: Event) -> EventStatus;
|
fn on_event(&mut self, window: &mut Window, event: Event) -> EventStatus;
|
||||||
|
@ -129,6 +137,12 @@ unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<'a> HasRawDisplayHandle for Window<'a> {
|
||||||
|
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
|
self.window.raw_display_handle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for RawWindowHandleWrapper {
|
unsafe impl HasRawWindowHandle for RawWindowHandleWrapper {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
self.handle
|
self.handle
|
||||||
|
|
|
@ -6,7 +6,10 @@ use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::*;
|
use std::time::*;
|
||||||
|
|
||||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, XlibHandle};
|
use raw_window_handle::{
|
||||||
|
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, XlibDisplayHandle,
|
||||||
|
XlibWindowHandle,
|
||||||
|
};
|
||||||
use xcb::ffi::xcb_screen_t;
|
use xcb::ffi::xcb_screen_t;
|
||||||
use xcb::StructPtr;
|
use xcb::StructPtr;
|
||||||
|
|
||||||
|
@ -57,7 +60,7 @@ unsafe impl HasRawWindowHandle for WindowHandle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RawWindowHandle::Xlib(XlibHandle::empty())
|
RawWindowHandle::Xlib(XlibWindowHandle::empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -686,14 +689,22 @@ impl Window {
|
||||||
|
|
||||||
unsafe impl HasRawWindowHandle for Window {
|
unsafe impl HasRawWindowHandle for Window {
|
||||||
fn raw_window_handle(&self) -> RawWindowHandle {
|
fn raw_window_handle(&self) -> RawWindowHandle {
|
||||||
let mut handle = XlibHandle::empty();
|
let mut handle = XlibWindowHandle::empty();
|
||||||
handle.window = self.window_id as c_ulong;
|
handle.window = self.window_id as c_ulong;
|
||||||
handle.display = self.xcb_connection.conn.get_raw_dpy() as *mut c_void;
|
|
||||||
|
|
||||||
RawWindowHandle::Xlib(handle)
|
RawWindowHandle::Xlib(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl HasRawDisplayHandle for Window {
|
||||||
|
fn raw_display_handle(&self) -> RawDisplayHandle {
|
||||||
|
let mut handle = XlibDisplayHandle::empty();
|
||||||
|
handle.display = self.xcb_connection.conn.get_raw_dpy() as *mut c_void;
|
||||||
|
|
||||||
|
RawDisplayHandle::Xlib(handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn mouse_id(id: u8) -> MouseButton {
|
fn mouse_id(id: u8) -> MouseButton {
|
||||||
match id {
|
match id {
|
||||||
1 => MouseButton::Left,
|
1 => MouseButton::Left,
|
||||||
|
|
Loading…
Reference in a new issue