Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tracing = { version = "0.1", optional = true }
x11rb = { version = "0.13.2", features = ["cursor", "resource_manager", "allow-unsafe-code", "dl-libxcb"], default-features = false }
xkbcommon-dl = { version = "0.4.2", features = ["x11"] }
x11-dl = { version = "2.21.0" }
polling = "3.11.0"
calloop = "0.14.4"
percent-encoding = "2.3.2"
bytemuck = "1.25.0"

Expand Down Expand Up @@ -99,3 +99,6 @@ missing-safety-doc = "allow"

[package.metadata.docs.rs]
all-features = true

[workspace.dependencies]
tracing-subscriber = "0.3.23"
2 changes: 1 addition & 1 deletion examples/open_parented/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl WindowHandler for ChildWindowHandler {
fn main() -> Result<(), baseview::Error> {
let window_open_options = WindowOpenOptions::new().with_size(LogicalSize::new(512.0, 512.0));

baseview::create_window(window_open_options, ParentWindowHandler::new)?.run_until_closed();
baseview::create_window(window_open_options, ParentWindowHandler::new)?.run_until_closed()?;

Ok(())
}
2 changes: 1 addition & 1 deletion examples/open_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn main() -> Result<(), baseview::Error> {
damaged: true.into(),
})
})?
.run_until_closed();
.run_until_closed()?;

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion examples/render_femtovg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ edition = "2021"
publish = false

[dependencies]
baseview = { path = "../..", features = ["opengl"] }
baseview = { path = "../..", features = ["opengl", "tracing"] }
femtovg = "0.25.1"
tracing-subscriber = { workspace = true }
4 changes: 3 additions & 1 deletion examples/render_femtovg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ impl WindowHandler for FemtovgExample {
}

fn main() -> Result<(), baseview::Error> {
tracing_subscriber::fmt::init();

let window_open_options = WindowOpenOptions::new()
.with_title("Femtovg on Baseview")
.with_size(LogicalSize::new(512, 512))
.with_gl_config(GlConfig { alpha_bits: 8, ..GlConfig::default() });

baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed();
baseview::create_window(window_open_options, FemtovgExample::new)?.run_until_closed()?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion examples/render_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ fn main() -> Result<(), baseview::Error> {
.with_size(LogicalSize::new(512, 512));

baseview::create_window(window_open_options, |c| pollster::block_on(WgpuExample::new(c)))?
.run_until_closed();
.run_until_closed()?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ pub use window::*;
pub use window_open_options::*;

#[allow(unused)]
pub(crate) use tracing::warn;
pub(crate) use tracing::*;

pub(crate) mod wrappers;
3 changes: 2 additions & 1 deletion src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ impl WindowHandle {
Ok(Self { mtm, state, view: Weak::from_retained(&view), _window: Some(window) })
}

pub fn run_until_closed(self) {
pub fn run_until_closed(self) -> Result<()> {
NSApplication::sharedApplication(self.mtm).run();
Ok(())
}

pub fn is_open(&self) -> bool {
Expand Down
5 changes: 3 additions & 2 deletions src/platform/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ pub struct WindowHandle {
}

impl WindowHandle {
pub fn run_until_closed(self) {
run_thread_message_loop_until(|| !self.is_open()).unwrap();
pub fn run_until_closed(self) -> Result<()> {
run_thread_message_loop_until(|| !self.is_open())?;
Ok(())
}

pub fn is_open(&self) -> bool {
Expand Down
16 changes: 5 additions & 11 deletions src/platform/x11/drag_n_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ pub(crate) enum DragNDropState {
// Other errors (protocol errors, transfer errors) should be dealt with as gracefully as possible.
impl DragNDropState {
pub fn handle_enter_event(
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
event: &ClientMessageEvent,
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
) -> Result<(), ConnectionError> {
let data = event.data.as_data32();

Expand Down Expand Up @@ -155,8 +154,7 @@ impl DragNDropState {
}

pub fn handle_position_event(
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
event: &ClientMessageEvent,
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
) -> Result<(), ConnectionError> {
let event_data = event.data.as_data32();

Expand Down Expand Up @@ -262,9 +260,7 @@ impl DragNDropState {
}
}

pub fn handle_leave_event(
&mut self, handler: &mut dyn WindowHandler, event: &ClientMessageEvent,
) {
pub fn handle_leave_event(&mut self, handler: &dyn WindowHandler, event: &ClientMessageEvent) {
let data = event.data.as_data32();
let event_source_window = data[0] as xproto::Window;

Expand Down Expand Up @@ -295,8 +291,7 @@ impl DragNDropState {
}

pub fn handle_drop_event(
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
event: &ClientMessageEvent,
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &ClientMessageEvent,
) -> Result<(), ConnectionError> {
let data = event.data.as_data32();

Expand Down Expand Up @@ -400,8 +395,7 @@ impl DragNDropState {
}

pub fn handle_selection_notify_event(
&mut self, window: &WindowInner, handler: &mut dyn WindowHandler,
event: &SelectionNotifyEvent,
&mut self, window: &WindowInner, handler: &dyn WindowHandler, event: &SelectionNotifyEvent,
) -> Result<(), ConnectionError> {
// Ignore the event if we weren't actually waiting for a selection notify event
let WaitingForData {
Expand Down
14 changes: 14 additions & 0 deletions src/platform/x11/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use x11rb::x11_utils::{TryParse, X11Error};
#[derive(Debug)]
pub enum Error {
CreationFailed(String),
Run(String),
Io(std::io::Error),
DylibOpen(OpenError),
InitThreadsFailed(InitThreadsFailedError),
Expand All @@ -25,6 +26,7 @@ pub enum Error {
DisplayOpenFailed(DisplayOpenFailedError),
Handler(HandlerError),
Channel(RecvError),
Calloop(calloop::Error),
#[cfg(feature = "opengl")]
XLib(crate::wrappers::xlib::XLibError),
#[cfg(feature = "opengl")]
Expand Down Expand Up @@ -98,6 +100,18 @@ impl From<HandlerError> for Error {
}
}

impl From<calloop::Error> for Error {
fn from(value: calloop::Error) -> Self {
Self::Calloop(value)
}
}

impl From<RecvError> for Error {
fn from(value: RecvError) -> Self {
Self::Channel(value)
}
}

#[cfg(feature = "opengl")]
impl From<crate::wrappers::xlib::XLibError> for Error {
fn from(value: crate::wrappers::xlib::XLibError) -> Self {
Expand Down
Loading