Skip to content

Commit 379f7c0

Browse files
committed
wip
1 parent fd69f5c commit 379f7c0

8 files changed

Lines changed: 12 additions & 18 deletions

File tree

examples/open_parented/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl WindowHandler for ChildWindowHandler {
130130
fn main() -> Result<(), baseview::Error> {
131131
let window_open_options = WindowOpenOptions::new().with_size(LogicalSize::new(512.0, 512.0));
132132

133-
baseview::create_window(window_open_options, ParentWindowHandler::new)?.run_until_closed();
133+
baseview::create_window(window_open_options, ParentWindowHandler::new)?.run_until_closed()?;
134134

135135
Ok(())
136136
}

examples/open_window/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn main() -> Result<(), baseview::Error> {
167167
damaged: true.into(),
168168
})
169169
})?
170-
.run_until_closed();
170+
.run_until_closed()?;
171171

172172
Ok(())
173173
}

examples/render_femtovg/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn main() -> Result<(), baseview::Error> {
123123
.with_size(LogicalSize::new(512, 512))
124124
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });
125125

126-
baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed();
126+
baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed()?;
127127
Ok(())
128128
}
129129

examples/render_wgpu/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn main() -> Result<(), baseview::Error> {
214214
.with_size(LogicalSize::new(512, 512));
215215

216216
baseview::create_window(window_open_options, |c| pollster::block_on(WgpuExample::new(c)))?
217-
.run_until_closed();
217+
.run_until_closed()?;
218218

219219
Ok(())
220220
}

src/platform/x11/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use x11rb::x11_utils::{TryParse, X11Error};
1313
#[derive(Debug)]
1414
pub enum Error {
1515
CreationFailed(String),
16-
RunError(String),
16+
Run(String),
1717
Io(std::io::Error),
1818
DylibOpen(OpenError),
1919
InitThreadsFailed(InitThreadsFailedError),

src/platform/x11/event_loop.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::keyboard::{convert_key_press_event, convert_key_release_event, key_mo
33
use super::*;
44
use std::result::Result;
55

6-
use crate::platform::x11::window_thread::WindowThreadShared;
76
use crate::warn;
87
use crate::wrappers::xkbcommon::XkbcommonState;
98
use crate::{Event, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowHandler, WindowSize};
@@ -29,14 +28,13 @@ pub(crate) struct EventLoop {
2928
xkb_state: Option<XkbcommonState>,
3029

3130
run_error: Option<Error>,
32-
pub(crate) shared: Arc<WindowThreadShared>,
3331
}
3432

3533
const FRAME_INTERVAL: Duration = Duration::from_millis(15);
3634

3735
impl EventLoop {
3836
pub fn new(
39-
window: Rc<WindowInner>, handler: Box<dyn WindowHandler>, shared: Arc<WindowThreadShared>,
37+
window: Rc<WindowInner>, handler: Box<dyn WindowHandler>,
4038
inner: &mut calloop::EventLoop<'static, Self>,
4139
) -> Result<Self, Error> {
4240
let loop_handle = inner.handle();
@@ -59,15 +57,10 @@ impl EventLoop {
5957
drag_n_drop: DragNDropState::NoCurrentSession,
6058
xkb_state: XkbcommonState::new(&window.connection),
6159
run_error: None,
62-
shared,
6360
window,
6461
})
6562
}
6663

67-
pub fn window_id(&self) -> NonZeroU32 {
68-
self.window.xcb_window.id()
69-
}
70-
7164
#[inline]
7265
fn drain_xcb_events(&mut self) -> Result<(), ConnectionError> {
7366
// the X server has a tendency to send spurious/extraneous configure notify events when a

src/platform/x11/window_shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl WindowInner {
4747
WindowVisualConfig::find_best_visual_config_for_gl(&xcb_connection, options.gl_config)?;
4848

4949
#[cfg(not(feature = "opengl"))]
50-
let visual_info = WindowVisualConfig::find_best_visual_config(&connection)?;
50+
let visual_info = WindowVisualConfig::find_best_visual_config(&xcb_connection)?;
5151

5252
let connection = Rc::new(xcb_connection);
5353

src/platform/x11/window_thread.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::platform::x11::window_shared::WindowInner;
55
use crate::{WindowContext, WindowOpenOptions};
66
use calloop::LoopSignal;
77
use std::cell::Cell;
8-
use std::num::NonZeroU32;
98
use std::panic::resume_unwind;
109
use std::rc::Rc;
1110
use std::sync::atomic::{AtomicBool, Ordering};
@@ -63,7 +62,7 @@ impl WindowThreadHandle {
6362
}
6463

6564
if let Some(e) = self.shared.final_error.lock().unwrap().take() {
66-
return Err(Error::RunError(e));
65+
return Err(Error::Run(e));
6766
}
6867

6968
Ok(())
@@ -79,7 +78,9 @@ impl Drop for WindowThreadHandle {
7978
self.loop_signal.stop();
8079
self.loop_signal.wakeup();
8180

82-
self.run_until_closed();
81+
if let Err(e) = self.run_until_closed() {
82+
crate::warn!("Error while closing window: {}", e)
83+
}
8384
}
8485
}
8586

@@ -101,7 +102,7 @@ impl WindowThread {
101102
let mut ev_loop = calloop::EventLoop::try_new()?;
102103
let inner = WindowInner::create(options, &ev_loop)?;
103104
let handler = handler.build(WindowContext::new(Rc::clone(&inner)))?;
104-
let event_loop = EventLoop::new(inner, handler, shared.clone(), &mut ev_loop)?;
105+
let event_loop = EventLoop::new(inner, handler, &mut ev_loop)?;
105106

106107
Ok(Self { event_loop, ev_loop, shared })
107108
}

0 commit comments

Comments
 (0)