start testing suil/winit

This commit is contained in:
🪞👃🪞 2024-07-24 13:43:38 +03:00
parent dacce119c4
commit 278b213f12
8 changed files with 1071 additions and 6 deletions

View file

@ -1,6 +1,7 @@
use std::ffi::CString;
use std::ffi::{CString, c_void};
pub mod bound;
#[cfg(test)] mod test;
pub struct Host(*mut self::bound::SuilHost);
@ -9,16 +10,33 @@ pub struct Instance(*mut self::bound::SuilInstance);
pub struct Controller(*mut self::bound::SuilController);
impl Host {
fn new () -> Self {
pub fn new () -> Self {
//let write = std::ptr::null();
//let index = std::ptr::null();
//let subscribe = std::ptr::null();
//let unsubscribe = std::ptr::null();
Self(unsafe {
bound::suil_init(&mut 0, std::ptr::null_mut(), 0);
bound::suil_host_new(None, None, None, None)
bound::suil_host_new(
Some(Self::write),
Some(Self::index),
Some(Self::subscribe),
Some(Self::unsubscribe),
)
})
}
unsafe extern "C" fn write (
_: *mut c_void, _: u32, _: u32, _: u32, _: *const c_void
) {}
unsafe extern "C" fn index (
_: *mut c_void, _: *const i8
) -> u32 {0}
unsafe extern "C" fn subscribe (
_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
) -> u32 {0}
unsafe extern "C" fn unsubscribe (
_: *mut c_void, _: u32, _: u32, _: *const *const bound::LV2_Feature
) -> u32 {0}
fn set_touch_func (&self) {
unimplemented!();
}

47
crates/suil/src/test.rs Normal file
View file

@ -0,0 +1,47 @@
use crate::*;
#[test]
fn panics () {
self::ui::UI::run().join();
panic!();
}
mod ui {
use std::thread::{spawn, JoinHandle};
use ::winit::{
application::ApplicationHandler,
event::WindowEvent,
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
window::{Window, WindowId},
platform::x11::EventLoopBuilderExtX11
};
pub struct UI(Option<Window>);
impl UI {
pub fn new () -> Self { Self(None) }
pub fn run () -> JoinHandle<()> {
let mut ui = Self::new();
spawn(move||{
let event_loop = EventLoop::builder().with_x11().with_any_thread(true).build().unwrap();
event_loop.set_control_flow(ControlFlow::Wait);
event_loop.run_app(&mut ui).unwrap()
})
}
}
impl ApplicationHandler for UI {
fn resumed (&mut self, event_loop: &ActiveEventLoop) {
self.0 = Some(event_loop.create_window(Window::default_attributes()).unwrap());
}
fn window_event (&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
self.0.as_ref().unwrap().set_visible(false);
event_loop.exit();
},
WindowEvent::RedrawRequested => {
self.0.as_ref().unwrap().request_redraw();
}
_ => (),
}
}
}
}