From 196883b3909b1e6e40e36a64e88527a412418422 Mon Sep 17 00:00:00 2001 From: William Light Date: Fri, 11 Sep 2020 18:25:50 +0200 Subject: [PATCH] x11: WindowHandle.app_run_blocking() --- examples/open_window.rs | 23 ++++++++++++----------- src/x11/window.rs | 22 ++++++++++++++-------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/examples/open_window.rs b/examples/open_window.rs index 87b82a4..9459c5c 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -1,16 +1,5 @@ use baseview::{Event, Window, WindowHandler}; -fn main() { - let window_open_options = baseview::WindowOpenOptions { - title: "baseview".into(), - width: 512, - height: 512, - parent: baseview::Parent::None, - }; - - let _handle = Window::open::(window_open_options); -} - struct MyProgram {} impl WindowHandler for MyProgram { @@ -33,3 +22,15 @@ impl WindowHandler for MyProgram { fn on_message(&mut self, _window: &mut Window, _message: Self::Message) {} } + +fn main() { + let window_open_options = baseview::WindowOpenOptions { + title: "baseview".into(), + width: 512, + height: 512, + parent: baseview::Parent::None, + }; + + let handle = Window::open::(window_open_options); + handle.app_run_blocking(); +} diff --git a/src/x11/window.rs b/src/x11/window.rs index a0ad71d..25c6a4d 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -21,18 +21,24 @@ pub struct Window { } // FIXME: move to outer crate context -pub struct WindowHandle; +pub struct WindowHandle { + thread: std::thread::JoinHandle<()> +} + +impl WindowHandle { + pub fn app_run_blocking(self) { + let _ = self.thread.join(); + } +} impl Window { pub fn open(options: WindowOpenOptions) -> WindowHandle { - let runner = thread::spawn(move || { - Self::window_thread::(options); - }); - - let _ = runner.join(); - - WindowHandle + WindowHandle { + thread: thread::spawn(move || { + Self::window_thread::(options); + }) + } } fn window_thread(options: WindowOpenOptions) {