Skip to content

Commit 07abebb

Browse files
committed
Wayland support
1 parent 43b7fb1 commit 07abebb

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ffi/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ pub extern "C" fn processing_init() {
2828
#[unsafe(no_mangle)]
2929
pub extern "C" fn processing_create_surface(
3030
window_handle: u64,
31+
display_handle: u64,
3132
width: u32,
3233
height: u32,
3334
scale_factor: f32,
3435
) -> u64 {
3536
error::clear_error();
36-
error::check(|| renderer::create_surface(window_handle, width, height, scale_factor))
37-
.unwrap_or(0)
37+
error::check(|| {
38+
renderer::create_surface(window_handle, display_handle, width, height, scale_factor)
39+
})
40+
.unwrap_or(0)
3841
}
3942

4043
/// Destroy the surface associated with the given window ID.

renderer/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub mod error;
22
pub mod render;
33

4-
use std::{cell::RefCell, num::NonZero, sync::OnceLock};
4+
use std::{cell::RefCell, ffi::c_void, num::NonZero, ptr::NonNull, sync::OnceLock};
55

66
use bevy::{
77
app::{App, AppExit},
@@ -95,6 +95,7 @@ impl HasDisplayHandle for GlfwWindow {
9595
/// actually create the surface.
9696
pub fn create_surface(
9797
window_handle: u64,
98+
display_handle: u64,
9899
width: u32,
99100
height: u32,
100101
scale_factor: f32,
@@ -132,7 +133,7 @@ pub fn create_surface(
132133
}
133134
};
134135

135-
let window = AppKitWindowHandle::new(std::ptr::NonNull::new(ns_view_ptr).unwrap());
136+
let window = AppKitWindowHandle::new(NonNull::new(ns_view_ptr).unwrap());
136137
let display = AppKitDisplayHandle::new();
137138
(
138139
RawWindowHandle::AppKit(window),
@@ -178,8 +179,20 @@ pub fn create_surface(
178179
};
179180

180181
#[cfg(target_os = "linux")]
181-
let (raw_window_handle, raw_display_handle) =
182-
{ todo!("implement linux raw window handle conversion") };
182+
let (raw_window_handle, raw_display_handle) = {
183+
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
184+
185+
let window_handle_ptr = unsafe { NonNull::new_unchecked(window_handle as *mut c_void) };
186+
let window = WaylandWindowHandle::new(window_handle_ptr);
187+
188+
let display_handle_ptr = unsafe { NonNull::new_unchecked(display_handle as *mut c_void) };
189+
let display = WaylandDisplayHandle::new(display_handle_ptr);
190+
191+
(
192+
RawWindowHandle::Wayland(window),
193+
RawDisplayHandle::Wayland(display),
194+
)
195+
};
183196

184197
let glfw_window = GlfwWindow {
185198
window_handle: raw_window_handle,

0 commit comments

Comments
 (0)