x11: run window in a separate thread
there's a thread.join() to mimic the previous semantics (which are the same as on the other platforms).
This commit is contained in:
parent
030388cf25
commit
5207d961d9
|
@ -2,7 +2,7 @@ use baseview::{Event, Window, WindowHandler};
|
|||
|
||||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview",
|
||||
title: "baseview".into(),
|
||||
width: 512,
|
||||
height: 512,
|
||||
parent: baseview::Parent::None,
|
||||
|
@ -22,7 +22,7 @@ impl WindowHandler for MyProgram {
|
|||
|
||||
fn on_frame(&mut self) {}
|
||||
|
||||
fn on_event(&mut self, window: &mut Window, event: Event) {
|
||||
fn on_event(&mut self, _window: &mut Window, event: Event) {
|
||||
match event {
|
||||
Event::Mouse(e) => println!("Mouse event: {:?}", e),
|
||||
Event::Keyboard(e) => println!("Keyboard event: {:?}", e),
|
||||
|
|
|
@ -28,8 +28,10 @@ pub enum Parent {
|
|||
WithParent(*mut c_void),
|
||||
}
|
||||
|
||||
pub struct WindowOpenOptions<'a> {
|
||||
pub title: &'a str,
|
||||
unsafe impl Send for Parent {}
|
||||
|
||||
pub struct WindowOpenOptions {
|
||||
pub title: String,
|
||||
|
||||
pub width: usize,
|
||||
pub height: usize,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::os::raw::{c_ulong, c_void};
|
||||
use std::time::*;
|
||||
use std::thread;
|
||||
|
||||
use raw_window_handle::{unix::XlibHandle, HasRawWindowHandle, RawWindowHandle};
|
||||
|
||||
|
@ -25,6 +26,16 @@ pub struct WindowHandle;
|
|||
|
||||
impl Window {
|
||||
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
|
||||
let runner = thread::spawn(move || {
|
||||
Self::window_thread::<H>(options);
|
||||
});
|
||||
|
||||
let _ = runner.join();
|
||||
|
||||
WindowHandle
|
||||
}
|
||||
|
||||
fn window_thread<H: WindowHandler>(options: WindowOpenOptions) {
|
||||
// Connect to the X server
|
||||
// FIXME: baseview error type instead of unwrap()
|
||||
let xcb_connection = XcbConnection::new().unwrap();
|
||||
|
@ -119,8 +130,6 @@ impl Window {
|
|||
let mut handler = H::build(&mut window);
|
||||
|
||||
window.run_event_loop(&mut handler);
|
||||
|
||||
WindowHandle
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue