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

raw-window-handle 0.5 (tested only on linux) #329

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ png = "0.17"
cc = "1.0"

[dependencies]
raw-window-handle = "0.4"
raw-window-handle = "0.5"

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
self.0.raw_display_handle()
}
}

pub fn clamp<T: PartialOrd>(low: T, value: T, high: T) -> T {
if value < low {
low
Expand Down
9 changes: 8 additions & 1 deletion src/os/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,20 @@ 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 mut handle = raw_window_handle::AppKitHandle::empty();
let mut handle = raw_window_handle::AppKitWindowHandle::empty();
handle.ns_window = self.window_handle as *mut _;
handle.ns_view = self.view_handle as *mut _;
raw_window_handle::RawWindowHandle::AppKit(handle)
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let handle = raw_window_handle::AppKitDisplayHandle::empty();
raw_window_handle::RawDisplayHandle::AppKit(handle)
}
}

impl Window {
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
let n = match CString::new(name) {
Expand Down
11 changes: 11 additions & 0 deletions src/os/posix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,14 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
}
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
match *self {
#[cfg(feature = "x11")]
Window::X11(ref w) => w.raw_display_handle(),
#[cfg(feature = "wayland")]
Window::Wayland(ref w) => w.raw_display_handle(),
}
}
}
12 changes: 10 additions & 2 deletions src/os/posix/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,16 @@ impl Window {

unsafe impl raw_window_handle::HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
let mut handle = raw_window_handle::WaylandHandle::empty();
let mut handle = raw_window_handle::WaylandWindowHandle::empty();
handle.surface = self.display.surface.as_ref().c_ptr() as *mut _ as *mut c_void;

raw_window_handle::RawWindowHandle::Wayland(handle)
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let mut handle = raw_window_handle::WaylandDisplayHandle::empty();
handle.display = self
.display
.attached_display
Expand All @@ -1275,7 +1283,7 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
.as_ref()
.c_ptr() as *mut _ as *mut c_void;

raw_window_handle::RawWindowHandle::Wayland(handle)
raw_window_handle::RawDisplayHandle::Wayland(handle)
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/os/posix/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,20 @@ pub struct Window {

unsafe impl raw_window_handle::HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
let mut handle = raw_window_handle::XlibHandle::empty();
let mut handle = raw_window_handle::XlibWindowHandle::empty();
handle.window = self.handle;
handle.display = self.d.display as *mut core::ffi::c_void;
raw_window_handle::RawWindowHandle::Xlib(handle)
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let mut handle = raw_window_handle::XlibDisplayHandle::empty();
handle.display = self.d.display as *mut core::ffi::c_void;
raw_window_handle::RawDisplayHandle::Xlib(handle)
}
}

impl Window {
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
let name = match CString::new(name) {
Expand Down
9 changes: 8 additions & 1 deletion src/os/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,14 @@ impl Menu {
unsafe impl raw_window_handle::HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
//TODO: assign a different ID to each window
let handle = raw_window_handle::WebHandle::empty();
let handle = raw_window_handle::WebWindowHandle::empty();
raw_window_handle::RawWindowHandle::Web(handle)
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let handle = raw_window_handle::WebDisplayHandle::empty();
raw_window_handle::RawDisplayHandle::Web(handle)
}
}
9 changes: 8 additions & 1 deletion src/os/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
return winuser::DefWindowProcW(window, msg, wparam, lparam);
}

let mut wnd: &mut Window = mem::transmute(user_data);

Check warning on line 207 in src/os/windows/mod.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

variable does not need to be mutable

Check warning on line 207 in src/os/windows/mod.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

variable does not need to be mutable

match msg {
winuser::WM_SYSCOMMAND => {
Expand Down Expand Up @@ -509,14 +509,21 @@

unsafe impl raw_window_handle::HasRawWindowHandle for Window {
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
let mut handle = raw_window_handle::Win32Handle::empty();
let mut handle = raw_window_handle::Win32WindowHandle::empty();
handle.hwnd = self.window.unwrap() as *mut raw::c_void;
handle.hinstance =
unsafe { libloaderapi::GetModuleHandleA(ptr::null()) } as *mut raw::c_void;
raw_window_handle::RawWindowHandle::Win32(handle)
}
}

unsafe impl raw_window_handle::HasRawDisplayHandle for Window {
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let handle = raw_window_handle::WindowsDisplayHandle::empty();
raw_window_handle::RawDisplayHandle::Windows(handle)
}
}

impl Window {
fn open_window(
name: &str,
Expand Down
Loading