Skip to content

Commit 6e7dec0

Browse files
authored
X11: Switch to calloop (#294)
1 parent 3773bef commit 6e7dec0

21 files changed

Lines changed: 354 additions & 382 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tracing = { version = "0.1", optional = true }
4343
x11rb = { version = "0.13.2", features = ["cursor", "resource_manager", "allow-unsafe-code", "dl-libxcb"], default-features = false }
4444
xkbcommon-dl = { version = "0.4.2", features = ["x11"] }
4545
x11-dl = { version = "2.21.0" }
46-
polling = "3.11.0"
46+
calloop = "0.14.4"
4747
percent-encoding = "2.3.2"
4848
bytemuck = "1.25.0"
4949

@@ -99,3 +99,6 @@ missing-safety-doc = "allow"
9999

100100
[package.metadata.docs.rs]
101101
all-features = true
102+
103+
[workspace.dependencies]
104+
tracing-subscriber = "0.3.23"

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/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
baseview = { path = "../..", features = ["opengl"] }
8+
baseview = { path = "../..", features = ["opengl", "tracing"] }
99
femtovg = "0.25.1"
10+
tracing-subscriber = { workspace = true }

examples/render_femtovg/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ impl WindowHandler for FemtovgExample {
116116
}
117117

118118
fn main() -> Result<(), baseview::Error> {
119+
tracing_subscriber::fmt::init();
120+
119121
let window_open_options = WindowOpenOptions::new()
120122
.with_title("Femtovg on Baseview")
121123
.with_size(LogicalSize::new(512, 512))
122124
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });
123125

124-
baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed();
126+
baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed()?;
125127
Ok(())
126128
}
127129

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/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ pub use window::*;
2525
pub use window_open_options::*;
2626

2727
#[allow(unused)]
28-
pub(crate) use tracing::warn;
28+
pub(crate) use tracing::*;
2929

3030
pub(crate) mod wrappers;

src/platform/macos/window.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ impl WindowHandle {
8383
Ok(Self { mtm, state, view: Weak::from_retained(&view), _window: Some(window) })
8484
}
8585

86-
pub fn run_until_closed(self) {
86+
pub fn run_until_closed(self) -> Result<()> {
8787
NSApplication::sharedApplication(self.mtm).run();
88+
Ok(())
8889
}
8990

9091
pub fn is_open(&self) -> bool {

src/platform/win/window.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ pub struct WindowHandle {
5757
}
5858

5959
impl WindowHandle {
60-
pub fn run_until_closed(self) {
61-
run_thread_message_loop_until(|| !self.is_open()).unwrap();
60+
pub fn run_until_closed(self) -> Result<()> {
61+
run_thread_message_loop_until(|| !self.is_open())?;
62+
Ok(())
6263
}
6364

6465
pub fn is_open(&self) -> bool {

src/platform/x11/drag_n_drop.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ pub(crate) enum DragNDropState {
9595
// Other errors (protocol errors, transfer errors) should be dealt with as gracefully as possible.
9696
impl DragNDropState {
9797
pub fn handle_enter_event(
98-
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
99-
event: &ClientMessageEvent,
98+
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
10099
) -> Result<(), ConnectionError> {
101100
let data = event.data.as_data32();
102101

@@ -155,8 +154,7 @@ impl DragNDropState {
155154
}
156155

157156
pub fn handle_position_event(
158-
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
159-
event: &ClientMessageEvent,
157+
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
160158
) -> Result<(), ConnectionError> {
161159
let event_data = event.data.as_data32();
162160

@@ -262,9 +260,7 @@ impl DragNDropState {
262260
}
263261
}
264262

265-
pub fn handle_leave_event(
266-
&mut self, handler: &mut dyn WindowHandler, event: &ClientMessageEvent,
267-
) {
263+
pub fn handle_leave_event(&mut self, handler: &dyn WindowHandler, event: &ClientMessageEvent) {
268264
let data = event.data.as_data32();
269265
let event_source_window = data[0] as xproto::Window;
270266

@@ -295,8 +291,7 @@ impl DragNDropState {
295291
}
296292

297293
pub fn handle_drop_event(
298-
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
299-
event: &ClientMessageEvent,
294+
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
300295
) -> Result<(), ConnectionError> {
301296
let data = event.data.as_data32();
302297

@@ -400,8 +395,7 @@ impl DragNDropState {
400395
}
401396

402397
pub fn handle_selection_notify_event(
403-
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
404-
event: &SelectionNotifyEvent,
398+
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &SelectionNotifyEvent,
405399
) -> Result<(), ConnectionError> {
406400
// Ignore the event if we weren't actually waiting for a selection notify event
407401
let WaitingForData {

0 commit comments

Comments
 (0)