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
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

A low-level windowing system geared towards making audio plugin UIs.

`baseview` abstracts the platform-specific windowing APIs (winapi, cocoa, xcb) into a platform-independent API, but otherwise gets out of your way so you can write plugin UIs.
`baseview` abstracts the platform-specific windowing APIs (winapi, cocoa, xcb) into a platform-independent API, but
otherwise gets out of your way so you can write plugin UIs.

Interested in learning more about the project? Join us on [discord](https://discord.gg/b3hjnGw), channel `#baseview`.

## Prerequisites

### Linux

Install dependencies, e.g.:

```sh
sudo apt-get install libx11-dev libxcb1-dev libx11-xcb-dev libgl1-mesa-dev
```

## Contributing

Contributions are very much welcomed! As long as they comply to the policy and licensing requirements
Expand Down
14 changes: 7 additions & 7 deletions examples/open_parented/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use baseview::dpi::LogicalSize;
use baseview::{
Event, EventStatus, HandlerError, WindowContext, WindowHandle, WindowHandler,
WindowOpenOptions, WindowSize,
Event, EventStatus, HandlerError, Window, WindowContext, WindowHandler, WindowSettings,
WindowSize,
};
use std::cell::{Cell, RefCell};
use std::num::NonZeroU32;
Expand All @@ -10,7 +10,7 @@ struct ParentWindowHandler {
surface: RefCell<softbuffer::Surface<WindowContext, WindowContext>>,
damaged: Cell<bool>,

child_window: WindowHandle,
child_window: Window,
}

impl ParentWindowHandler {
Expand All @@ -20,12 +20,12 @@ impl ParentWindowHandler {
let size = window.size().physical;
surface.resize(size.width.try_into()?, size.height.try_into()?)?;

let window_open_options = WindowOpenOptions::new()
let window_open_options = WindowSettings::new()
.with_size(LogicalSize::new(256, 256))
.with_parent(&window)
.with_title("baseview child");

let child_window = baseview::create_window(window_open_options, ChildWindowHandler::new)?;
let child_window = Window::create(window_open_options, ChildWindowHandler::new)?;

Ok(Self { surface: surface.into(), damaged: true.into(), child_window })
}
Expand Down Expand Up @@ -128,9 +128,9 @@ impl WindowHandler for ChildWindowHandler {
}

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

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

Ok(())
}
8 changes: 4 additions & 4 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, WindowContext, WindowHandler, WindowOpenOptions,
WindowSize,
Event, EventStatus, HandlerError, MouseEvent, Window, WindowContext, WindowHandler,
WindowSettings, WindowSize,
};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -140,7 +140,7 @@ impl WindowHandler for OpenWindowExample {
}

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

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

Expand All @@ -152,7 +152,7 @@ fn main() -> Result<(), baseview::Error> {
}
});

baseview::create_window(window_open_options, |window| {
Window::create(window_open_options, |window| {
let ctx = softbuffer::Context::new(window.clone())?;
let mut surface = softbuffer::Surface::new(&ctx, window.clone())?;
let size = window.size().physical;
Expand Down
8 changes: 4 additions & 4 deletions examples/plugin_clack/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ExamplePluginMainThread;
use baseview::dpi::*;
use baseview::gl::GlConfig;
use baseview::host::{Host, HostCallbacks, HostMainThreadCaller};
use baseview::{HandlerError, WindowHandle, WindowOpenOptions, WindowSize};
use baseview::{HandlerError, Window, WindowSettings, WindowSize};
use clack_extensions::gui::{
AspectRatioStrategy, GuiApiType, GuiConfiguration, GuiResizeHints, GuiSize, HostGui,
PluginGuiImpl, Window as ClapWindow,
Expand All @@ -14,7 +14,7 @@ use clack_plugin::prelude::{HostMainThreadHandle, HostSharedHandle};
use raw_window_handle::HasRawWindowHandle;

pub struct ExamplePluginGui {
pub handle: WindowHandle,
pub handle: Window,
}

impl PluginGuiImpl for ExamplePluginMainThread<'_> {
Expand All @@ -31,7 +31,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
}

fn create(&mut self, _configuration: GuiConfiguration) -> Result<(), PluginError> {
let options = WindowOpenOptions::new()
let options = WindowSettings::new()
.with_size(PhysicalSize::new(400, 200))
.with_gl_config(GlConfig::default());

Expand All @@ -45,7 +45,7 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
});
}

let window = baseview::create_window_with_host(options, OpenWindowExample::new, host)?;
let window = Window::create_with_host(options, OpenWindowExample::new, host)?;

self.gui = Some(ExamplePluginGui { handle: window });
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions examples/render_femtovg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use baseview::dpi::{LogicalSize, PhysicalPosition};
use baseview::gl::{GlConfig, GlContext};
use baseview::{
Event, EventStatus, HandlerError, MouseEvent, WindowContext, WindowHandler, WindowOpenOptions,
WindowSize,
Event, EventStatus, HandlerError, MouseEvent, Window, WindowContext, WindowHandler,
WindowSettings, WindowSize,
};
use femtovg::renderer::OpenGl;
use femtovg::{Canvas, Color};
Expand Down Expand Up @@ -118,12 +118,12 @@ impl WindowHandler for FemtovgExample {
fn main() -> Result<(), baseview::Error> {
tracing_subscriber::fmt::init();

let window_open_options = WindowOpenOptions::new()
let window_open_options = WindowSettings::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()?;
Window::create(window_open_options, FemtovgExample::new)?.run_until_closed()?;
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions examples/render_wgpu/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use baseview::dpi::{LogicalSize, PhysicalSize};
use baseview::{
Event, EventStatus, HandlerError, WindowContext, WindowHandler, WindowOpenOptions, WindowSize,
Event, EventStatus, HandlerError, Window, WindowContext, WindowHandler, WindowSettings,
WindowSize,
};

use log::LevelFilter;
Expand Down Expand Up @@ -210,11 +211,10 @@ impl WindowHandler for WgpuExample {

fn main() -> Result<(), baseview::Error> {
env_logger::builder().filter_level(LevelFilter::Debug).init();
let window_open_options = WindowOpenOptions::new()
.with_title("WGPU on Baseview")
.with_size(LogicalSize::new(512, 512));
let window_open_options =
WindowSettings::new().with_title("WGPU on Baseview").with_size(LogicalSize::new(512, 512));

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

Ok(())
Expand Down
18 changes: 10 additions & 8 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cell::RefCell;

/// A special handler for the Window thread to wake up and call methods on the main thread.
///
/// [`WindowHandle::host_main_thread_callback`](crate::WindowHandle::host_main_thread_callback)
/// [`WindowHandle::host_main_thread_callback`](crate::Window::host_main_thread_callback)
/// should be called as a response to this.
///
/// # Platform compatibility notes
Expand All @@ -12,7 +12,7 @@ use std::cell::RefCell;
pub trait HostMainThreadCaller: Send + 'static {
/// Schedules a callback on the main thread.
///
/// [`WindowHandle::host_main_thread_callback`](crate::WindowHandle::host_main_thread_callback)
/// [`WindowHandle::host_main_thread_callback`](crate::Window::host_main_thread_callback)
/// should be called as a response to this.
///
/// # Platform compatibility notes
Expand Down Expand Up @@ -48,10 +48,12 @@ pub trait HostCallbacks: 'static {
///
/// This type and its methods are always safe to use.
///
/// It also brings the additional safety guarantee that all handlers given to this types will be
/// destroyed alongside with the window, guaranteeing callbacks cannot be fired after the
/// [`WindowHandle`](crate::WindowHandle) is dropped. (or after this [`Host`] object is dropped, if
/// it never made it to a [`create_window_with_host`](crate::create_window_with_host) call).
/// It also brings the additional safety guarantee that all handlers given to this type will be
/// destroyed alongside with the window.
///
/// This guarantees callbacks cannot be fired after the [`Window`](crate::Window) is dropped.
/// (or after this [`Host`] object is dropped, if it never made it to a
/// [`Window::create_with_host`](crate::Window::create_with_host) call).
pub struct Host {
#[cfg(target_os = "linux")]
pub(crate) main_thread: Option<Box<dyn HostMainThreadCaller>>,
Expand All @@ -67,8 +69,8 @@ impl Default for Host {
impl Host {
/// Creates a new, empty host with no callbacks.
///
/// Calling [`create_window_with_host`](crate::create_window_with_host) with this is equivalent
/// to just calling [`create_window`](crate::create_window).
/// Calling [`Window::create_with_host`](crate::Window::create_with_host) with this is equivalent
/// to just calling [`Window::create`](crate::Window::create).
#[inline]
pub fn new() -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::wrappers::appkit::*;
use crate::MouseEvent::{ButtonPressed, ButtonReleased};
use crate::{
DropData, DropEffect, Event, EventStatus, MouseButton, MouseEvent, ScrollDelta, WindowEvent,
WindowHandler, WindowOpenOptions, WindowSize,
WindowHandler, WindowSettings, WindowSize,
};
use dpi::{LogicalPosition, LogicalSize, Size};
use objc2::__framework_prelude::Retained;
Expand Down Expand Up @@ -79,7 +79,7 @@ pub(crate) struct BaseviewView {

impl BaseviewView {
pub fn new(
_options: WindowOpenOptions, builder: WindowHandlerBuilder, parenting: ViewParentingType,
_options: WindowSettings, builder: WindowHandlerBuilder, parenting: ViewParentingType,
host: Host, final_size: LogicalSize<f64>, mtm: MainThreadMarker,
) -> Result<(Retained<View<Self>>, Rc<WindowSharedState>)> {
let view_rect =
Expand Down
9 changes: 4 additions & 5 deletions src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Drop for WindowHandle {

impl WindowHandle {
pub fn create_window(
mut options: WindowOpenOptions, handler: WindowHandlerBuilder, host: Host,
mut options: WindowSettings, handler: WindowHandlerBuilder, host: Host,
) -> Result<Self> {
autoreleasepool(|_| {
let Some(mtm) = MainThreadMarker::new() else {
Expand All @@ -57,7 +57,7 @@ impl WindowHandle {
}

pub fn create_window_parented(
builder: WindowOpenOptions, handler: WindowHandlerBuilder, host: Host,
builder: WindowSettings, handler: WindowHandlerBuilder, host: Host,
parent_view: Retained<NSView>, mtm: MainThreadMarker,
) -> Result<Self> {
let parenting =
Expand All @@ -74,8 +74,7 @@ impl WindowHandle {
}

pub fn create_window_standalone(
builder: WindowOpenOptions, handler: WindowHandlerBuilder, host: Host,
mtm: MainThreadMarker,
builder: WindowSettings, handler: WindowHandlerBuilder, host: Host, mtm: MainThreadMarker,
) -> Result<Self> {
let window = create_window_with_options(&builder, mtm);

Expand Down Expand Up @@ -158,7 +157,7 @@ impl WindowHandle {
}

fn create_window_with_options(
options: &WindowOpenOptions, mtm: MainThreadMarker,
options: &WindowSettings, mtm: MainThreadMarker,
) -> Retained<NSWindow> {
let initial_size = options.size.to_logical(1.0);
let window = create_window(initial_size, mtm);
Expand Down
6 changes: 2 additions & 4 deletions src/platform/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ use crate::wrappers::win32::{
ole_initialize, run_thread_message_loop_until, Dpi, DpiAwarenessContext, ExtendedUser32, Rect,
WindowStyle,
};
use crate::{
Event, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowOpenOptions, WindowSize,
};
use crate::{Event, MouseButton, MouseEvent, ScrollDelta, WindowEvent, WindowSettings, WindowSize};

#[allow(non_snake_case)]
fn HIWORD(wparam: WPARAM) -> u16 {
Expand Down Expand Up @@ -560,7 +558,7 @@ unsafe fn wnd_proc_inner(

impl WindowHandle {
pub fn create_window(
options: WindowOpenOptions, build: WindowHandlerBuilder, host: Host,
options: WindowSettings, build: WindowHandlerBuilder, host: Host,
) -> Result<WindowHandle> {
let extended_user_32 = ExtendedUser32::load()?;
let title = HSTRING::from(options.title);
Expand Down
4 changes: 2 additions & 2 deletions src/platform/x11/window_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::platform::x11::visual_info::WindowVisualConfig;
use crate::platform::x11::window_thread::WindowThreadShared;
use crate::platform::x11::xcb_window::XcbWindow;
use crate::platform::*;
use crate::{warn, MouseCursor, WindowHandler, WindowOpenOptions, WindowSize};
use crate::{warn, MouseCursor, WindowHandler, WindowSettings, WindowSize};
use calloop::LoopSignal;
use dpi::{PhysicalSize, Size};
use raw_window_handle::{DisplayHandle, XlibWindowHandle};
Expand Down Expand Up @@ -66,7 +66,7 @@ pub(crate) struct WindowInner {

impl WindowInner {
pub(crate) fn create(
options: WindowOpenOptions, ev_loop: &calloop::EventLoop<'static, EventLoop>,
options: WindowSettings, ev_loop: &calloop::EventLoop<'static, EventLoop>,
shared: Arc<WindowThreadShared>,
) -> Result<Rc<Self>> {
// Connect to the X server
Expand Down
6 changes: 3 additions & 3 deletions src/platform/x11/window_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::host::{Host, HostCallbacks};
use crate::platform::x11::event_loop::{EventLoop, MainThreadCaller};
use crate::platform::x11::window_shared::WindowInner;
use crate::warn;
use crate::{WindowContext, WindowOpenOptions, WindowSize};
use crate::{WindowContext, WindowSettings, WindowSize};
use calloop::LoopSignal;
use dpi::{PhysicalSize, Size};
use std::cell::Cell;
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct WindowThreadHandle {

impl WindowThreadHandle {
pub fn create_window(
options: WindowOpenOptions, handler: WindowHandlerBuilder, host: Host,
options: WindowSettings, handler: WindowHandlerBuilder, host: Host,
) -> Result<Self> {
let (tx, rx) = result_channel();
let shared = Arc::new(WindowThreadShared::new());
Expand Down Expand Up @@ -263,7 +263,7 @@ impl Display for RequestFailed {

impl WindowThread {
pub fn create(
options: WindowOpenOptions, handler: WindowHandlerBuilder, shared: Arc<WindowThreadShared>,
options: WindowSettings, handler: WindowHandlerBuilder, shared: Arc<WindowThreadShared>,
receiver: calloop::channel::Channel<WindowThreadRequest>,
sender: mpsc::Sender<WindowThreadResponseMessage>,
main_thread_caller: Option<MainThreadCaller>,
Expand Down
Loading