Skip to content
Draft
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dpi = "0.1.2"
tracing = { version = "0.1", optional = true }

[target.'cfg(target_os="linux")'.dependencies]
x11rb = { version = "0.13.2", features = ["cursor", "resource_manager", "allow-unsafe-code", "dl-libxcb"], default-features = false }
x11rb = { version = "0.13.2", features = ["cursor", "dri3", "present", "resource_manager", "allow-unsafe-code", "dl-libxcb"], default-features = false }
xkbcommon-dl = { version = "0.4.2", features = ["x11"] }
x11-dl = { version = "2.21.0" }
calloop = "0.14.4"
Expand Down Expand Up @@ -92,7 +92,7 @@ objc2-app-kit = { version = "0.3.2", default-features = false, features = [
] }

[workspace]
members = ["examples/open_parented", "examples/open_window", "examples/plugin_clack", "examples/render_femtovg", "examples/render_wgpu"]
members = ["examples/open_parented", "examples/open_window", "examples/plugin_clack", "examples/render_femtovg", "examples/render_wgpu", "examples/test-frame-pacing"]

[lints.clippy]
missing-safety-doc = "allow"
Expand Down
4 changes: 2 additions & 2 deletions examples/open_parented/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ParentWindowHandler {
}

impl WindowHandler for ParentWindowHandler {
fn on_frame(&self) -> Result<(), HandlerError> {
fn draw(&self) -> Result<(), HandlerError> {
let mut surface = self.surface.borrow_mut();
let mut buf = surface.buffer_mut()?;
if self.damaged.get() {
Expand Down Expand Up @@ -86,7 +86,7 @@ impl ChildWindowHandler {
}

impl WindowHandler for ChildWindowHandler {
fn on_frame(&self) -> Result<(), HandlerError> {
fn draw(&self) -> Result<(), HandlerError> {
let mut surface = self.surface.borrow_mut();
let mut buf = surface.buffer_mut()?;
if self.damaged.get() {
Expand Down
24 changes: 9 additions & 15 deletions examples/open_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use rtrb::{Consumer, RingBuffer};
use baseview::copy_to_clipboard;
use baseview::dpi::{LogicalSize, PhysicalPosition};
use baseview::{
Event, EventStatus, HandlerError, MouseEvent, Window, WindowContext, WindowHandler,
WindowSettings, WindowSize,
Event, EventStatus, HandlerError, MouseEvent, RedrawStrategy, Window, WindowContext,
WindowHandler, WindowSettings, WindowSize,
};

#[derive(Debug, Clone)]
Expand All @@ -24,7 +24,6 @@ struct OpenWindowExample {
surface: RefCell<softbuffer::Surface<WindowContext, WindowContext>>,
mouse_pos: Cell<PhysicalPosition<f64>>,
is_cursor_inside: Cell<bool>,
damaged: Cell<bool>,
}

impl WindowHandler for OpenWindowExample {
Expand All @@ -35,17 +34,12 @@ impl WindowHandler for OpenWindowExample {
(NonZeroU32::new(new_size.physical.width), NonZeroU32::new(new_size.physical.height))
{
self.surface.borrow_mut().resize(width, height)?;
self.damaged.set(true);
}

Ok(())
}

fn on_frame(&self) -> Result<(), HandlerError> {
if !self.damaged.get() {
return Ok(());
}

fn draw(&self) -> Result<(), HandlerError> {
let mut surface = self.surface.borrow_mut();
let mut pixels = surface.buffer_mut()?;
let size = self.window_context.size();
Expand Down Expand Up @@ -105,7 +99,6 @@ impl WindowHandler for OpenWindowExample {
}

pixels.present()?;
self.damaged.set(false);

while let Ok(message) = self.rx.borrow_mut().pop() {
println!("Message: {:?}", message);
Expand All @@ -120,15 +113,15 @@ impl WindowHandler for OpenWindowExample {
Event::Mouse(MouseEvent::ButtonPressed { .. }) => copy_to_clipboard("This is a test!"),
Event::Mouse(MouseEvent::CursorMoved { position, .. }) => {
self.mouse_pos.set(position);
self.damaged.set(true);
self.window_context.request_redraw();
}
Event::Mouse(MouseEvent::CursorEntered) => {
self.is_cursor_inside.set(true);
self.damaged.set(true);
self.window_context.request_redraw();
}
Event::Mouse(MouseEvent::CursorLeft) => {
self.is_cursor_inside.set(false);
self.damaged.set(true);
self.window_context.request_redraw();
}
_ => {}
}
Expand All @@ -140,7 +133,9 @@ impl WindowHandler for OpenWindowExample {
}

fn main() -> Result<(), baseview::Error> {
let window_open_options = WindowSettings::new().with_size(LogicalSize::new(512.0, 512.0));
let window_open_options = WindowSettings::new()
.with_redraw_strategy(RedrawStrategy::OnDemand)
.with_size(LogicalSize::new(512.0, 512.0));

let (mut tx, rx) = RingBuffer::new(128);

Expand All @@ -164,7 +159,6 @@ fn main() -> Result<(), baseview::Error> {
rx: rx.into(),
mouse_pos: PhysicalPosition::new(0., 0.).into(),
is_cursor_inside: false.into(),
damaged: true.into(),
})
})?
.run_until_closed()?;
Expand Down
2 changes: 1 addition & 1 deletion examples/plugin_clack/src/window_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl WindowHandler for OpenWindowExample {
Ok(())
}

fn on_frame(&self) -> Result<(), HandlerError> {
fn draw(&self) -> Result<(), HandlerError> {
if !self.damaged.get() {
return Ok(());
}
Expand Down
11 changes: 1 addition & 10 deletions examples/render_femtovg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct FemtovgExample {
gl_context: GlContext,
canvas: RefCell<Canvas<OpenGl>>,
current_mouse_position: Cell<PhysicalPosition<f64>>,
damaged: Cell<bool>,
}

impl FemtovgExample {
Expand All @@ -34,18 +33,13 @@ impl FemtovgExample {
gl_context,
window_context,
canvas: canvas.into(),
damaged: true.into(),
current_mouse_position: Cell::new(PhysicalPosition::default()),
})
}
}

impl WindowHandler for FemtovgExample {
fn on_frame(&self) -> Result<(), HandlerError> {
if !self.damaged.get() {
return Ok(());
}

fn draw(&self) -> Result<(), HandlerError> {
let context = &self.gl_context;
unsafe { context.make_current()? };

Expand Down Expand Up @@ -81,15 +75,13 @@ impl WindowHandler for FemtovgExample {
canvas.flush();
context.swap_buffers()?;
unsafe { context.make_not_current()? };
self.damaged.set(false);

Ok(())
}

fn resized(&self, new_size: WindowSize) -> Result<(), HandlerError> {
let size = new_size.physical;
self.canvas.borrow_mut().set_size(size.width, size.height, new_size.scale_factor as f32);
self.damaged.set(true);

Ok(())
}
Expand All @@ -106,7 +98,6 @@ impl WindowHandler for FemtovgExample {
if position.y > 400. && !self.window_context.has_focus() {
let _ = self.window_context.focus();
}
self.damaged.set(true);
}
event => log_event(&event),
};
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 @@ -131,7 +131,7 @@ impl WgpuExample {
}

impl WindowHandler for WgpuExample {
fn on_frame(&self) -> Result<(), HandlerError> {
fn draw(&self) -> Result<(), HandlerError> {
let mut surface = self.surface.borrow_mut();

let surface_texture = match surface.get_current_texture() {
Expand Down
10 changes: 10 additions & 0 deletions examples/test-frame-pacing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "test-frame-pacing"
version = "0.1.0"
edition = "2024"

[dependencies]
baseview = { path = "../..", features = ["opengl", "tracing"] }
femtovg = "0.26.0"
tracing-subscriber = { workspace = true }
keyboard-types = "0.8.3"
Loading
Loading