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
30 changes: 29 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ xkbcommon-dl = { version = "0.4.2", features = ["x11"] }
x11-dl = { version = "2.21.0" }
calloop = "0.14.4"
percent-encoding = "2.3.2"
bytemuck = "1.25.0"
bytemuck = { version = "1.25.0", features = ["extern_crate_alloc"] }

[target.'cfg(target_os="windows")'.dependencies]
windows = { version = "0.62.2", features = [
Expand Down Expand Up @@ -97,6 +97,34 @@ members = ["examples/open_parented", "examples/open_window", "examples/plugin_cl
[lints.clippy]
missing-safety-doc = "allow"

allow-attributes-without-reason = "warn"
arithmetic-side-effects = "warn"
clone-on-ref-ptr = "warn"
dbg-macro = "warn"
default-union-representation = "deny"
deref-by-slicing = "warn"
doc-paragraphs-missing-punctuation = "warn"
empty-drop = "warn"
empty-enum-variants-with-brackets = "warn"
empty-structs-with-brackets = "warn"
error-impl-error = "warn"
exhaustive-enums = "warn"
exit = "deny"
expect-used = "warn"
float-cmp-const = "warn"
get-unwrap = "warn"
indexing-slicing = "warn"
integer-division = "warn"
lossy-float-literal = "warn"
non-zero-suggestions = "warn"
print-stderr = "warn"
print-stdout = "warn"
todo = "warn"
try-err = "warn"
unnecessary-safety-comment = "warn"
unwrap-used = "warn"


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

Expand Down
4 changes: 2 additions & 2 deletions examples/plugin_clack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
clack-plugin = "0.1.0"
clack-extensions = { version = "0.1.0", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
clack-plugin = "0.1.1"
clack-extensions = { version = "0.1.1", features = ["gui", "state", "clack-plugin", "raw-window-handle_06"] }
baseview = { path = "../..", features = ["opengl"] }
softbuffer = "0.4.8"
raw-window-handle = "0.6.2"
Expand Down
7 changes: 2 additions & 5 deletions examples/plugin_clack/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use clack_extensions::gui::{
};
use clack_plugin::plugin::PluginError;
use clack_plugin::prelude::{HostMainThreadHandle, HostSharedHandle};
#[allow(deprecated)]
use raw_window_handle::HasRawWindowHandle;

pub struct ExamplePluginGui {
pub handle: Window,
Expand Down Expand Up @@ -123,14 +121,13 @@ impl PluginGuiImpl for ExamplePluginMainThread<'_> {
Ok(())
}

#[allow(deprecated)]
fn set_parent(&mut self, window: ClapWindow) -> Result<(), PluginError> {
let Some(gui) = &self.gui else {
return Err(PluginError::Message("set_parent called without a GUI active"));
};

let parent = window.raw_window_handle()?;
let parent = unsafe { raw_window_handle::WindowHandle::borrow_raw(parent) };
// SAFETY: The CLAP spec ensures the parent window handle is valid for at least this call
let parent = unsafe { window.borrow_handle_unchecked()? };

gui.handle.set_parent(&parent)?;
gui.handle.show()?;
Expand Down
4 changes: 2 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ impl HasDisplayHandle for WindowContext {
/// # Platform compatibility notes
///
/// Depending on the platform, the [`PlatformHandle::window_handle`] method may return
/// [`HandleError::Unavailable`] if called from a thread other than the main thread. (Even if the
/// window is still alive and well)
/// [`HandleError::Unavailable`] if called from a thread other than the main thread (Even if the
/// window is still alive and well).
#[derive(Clone)]
pub struct PlatformHandle {
inner: platform::PlatformHandle,
Expand Down
9 changes: 5 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ use std::fmt::{Debug, Display, Formatter};
/// not possible on e.g. Windows or macOS.
///
/// This is the general Baseview error type.
#[expect(clippy::error_impl_error, reason = "This is fine for the global error type")]
pub struct Error {
inner: crate::platform::Error,
inner: crate::platform::PlatformError,
}

impl From<crate::platform::Error> for Error {
fn from(inner: crate::platform::Error) -> Error {
impl From<crate::platform::PlatformError> for Error {
fn from(inner: crate::platform::PlatformError) -> Error {
Error { inner }
}
}
Expand All @@ -40,7 +41,7 @@ impl std::error::Error for Error {

impl From<HandlerError> for Error {
fn from(e: HandlerError) -> Self {
Self { inner: crate::platform::Error::Handler(e) }
Self { inner: crate::platform::PlatformError::Handler(e) }
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@ pub enum MouseButton {

/// A scroll movement.
#[derive(Debug, Clone, Copy, PartialEq)]
#[expect(clippy::exhaustive_enums, reason = "We don't expect new scroll types anytime soon")]
pub enum ScrollDelta {
/// A line-based scroll movement
/// A line-based scroll movement.
Lines {
/// The number of horizontal lines scrolled
/// The number of horizontal lines scrolled.
x: f32,

/// The number of vertical lines scrolled
/// The number of vertical lines scrolled.
y: f32,
},
/// A pixel-based scroll movement
/// A pixel-based scroll movement.
Pixels {
/// The number of horizontal pixels scrolled
/// The number of horizontal pixels scrolled.
x: f32,
/// The number of vertical pixels scrolled
/// The number of vertical pixels scrolled.
y: f32,
},
}

#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum MouseEvent {
/// The mouse cursor was moved
/// The mouse cursor was moved.
CursorMoved {
/// The logical coordinates of the mouse position
/// The logical coordinates of the mouse position.
position: PhysicalPosition<f64>,
/// The modifiers that were held down just before the event.
modifiers: Modifiers,
Expand Down Expand Up @@ -79,31 +80,31 @@ pub enum MouseEvent {
CursorLeft,

DragEntered {
/// The logical coordinates of the mouse position
/// The logical coordinates of the mouse position.
position: PhysicalPosition<f64>,
/// The modifiers that were held down just before the event.
modifiers: Modifiers,
/// Data being dragged
/// Data being dragged.
data: DropData,
},

DragMoved {
/// The logical coordinates of the mouse position
/// The logical coordinates of the mouse position.
position: PhysicalPosition<f64>,
/// The modifiers that were held down just before the event.
modifiers: Modifiers,
/// Data being dragged
/// Data being dragged.
data: DropData,
},

DragLeft,

DragDropped {
/// The logical coordinates of the mouse position
/// The logical coordinates of the mouse position.
position: PhysicalPosition<f64>,
/// The modifiers that were held down just before the event.
modifiers: Modifiers,
/// Data being dragged
/// Data being dragged.
data: DropData,
},
}
Expand Down Expand Up @@ -161,6 +162,6 @@ pub enum EventStatus {
/// plugin window is in focus.
Ignored,
/// We are prepared to handle the data in the drag and dropping will
/// result in [DropEffect]
/// result in [DropEffect].
AcceptDrop(DropEffect),
}
4 changes: 4 additions & 0 deletions src/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ impl Default for GlConfig {
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[expect(
clippy::exhaustive_enums,
reason = "We don't expect to add new profiles until a new major version"
)]
pub enum Profile {
Compatibility,
Core,
Expand Down
3 changes: 1 addition & 2 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub trait WindowHandler: 'static {

type DynBuilderResult = core::result::Result<Box<dyn WindowHandler>, HandlerError>;

#[allow(unused)]
pub struct WindowHandlerBuilder {
inner: Box<dyn FnOnce(WindowContext) -> DynBuilderResult + Send + 'static>,
}
Expand All @@ -40,7 +39,7 @@ impl WindowHandlerBuilder {
pub fn build(self, ctx: WindowContext) -> Result<Box<dyn WindowHandler>> {
match (self.inner)(ctx) {
Ok(handle) => Ok(handle),
Err(e) => Err(platform::Error::Handler(e)),
Err(e) => Err(platform::PlatformError::Handler(e)),
}
}
}
19 changes: 11 additions & 8 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,18 @@ impl Host {
///
/// This is only useful on X11. On Window and macOS, this is a no-op.
#[inline]
#[allow(unused)]
pub fn with_main_thread(mut self, main_thread: impl HostMainThreadCaller) -> Self {
pub fn with_main_thread(self, main_thread: impl HostMainThreadCaller) -> Self {
#[cfg(target_os = "linux")]
{
self.main_thread = Some(Box::new(main_thread));
let mut this = self;
this.main_thread = Some(Box::new(main_thread));
this
}
#[cfg(not(target_os = "linux"))]
{
let _ = main_thread;
self
}

self
}

/// Sets the [`HostCallbacks`] handler to be used.
Expand All @@ -106,16 +110,15 @@ impl Host {
self.callbacks = Some(RefCell::new(Box::new(callbacks)));
self
}
}

#[allow(unused)]
impl Host {
#[cfg(any(target_os = "macos", target_os = "windows"))]
pub(crate) fn notify_destroyed(&self) {
let Some(callbacks) = &self.callbacks else { return };
let Ok(mut callbacks) = callbacks.try_borrow_mut() else { return };
callbacks.destroyed();
}

#[cfg(any(target_os = "macos", target_os = "windows"))]
pub(crate) fn request_resize(&self, new_size: WindowSize) -> Result<(), HandlerError> {
let Some(callbacks) = &self.callbacks else { return Ok(()) };
let Ok(mut callbacks) = callbacks.try_borrow_mut() else { return 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,7 +25,7 @@ pub use mouse_cursor::MouseCursor;
pub use settings::*;
pub use window::*;

#[allow(unused)]
#[allow(unused, reason = "Some platforms may not use all exports from this mod")]
pub(crate) use tracing::*;

mod utils;
Expand Down
1 change: 1 addition & 0 deletions src/mouse_cursor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[expect(clippy::exhaustive_enums, reason = "TODO: next major version")]
#[derive(Debug, Eq, PartialEq, Clone, Copy, PartialOrd, Ord, Hash, Default)]
pub enum MouseCursor {
#[default]
Expand Down
7 changes: 1 addition & 6 deletions src/platform/macos/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum Cursor {
}

impl From<MouseCursor> for Cursor {
#[expect(deprecated, reason = "TODO: resize curosrs are deprecated")]
fn from(cursor: MouseCursor) -> Self {
match cursor {
MouseCursor::Default => Cursor::Native(NSCursor::arrowCursor),
Expand All @@ -25,19 +26,13 @@ impl From<MouseCursor> for Cursor {
Cursor::Native(NSCursor::operationNotAllowedCursor)
}
MouseCursor::Crosshair => Cursor::Native(NSCursor::crosshairCursor),
#[allow(deprecated)]
MouseCursor::EResize => Cursor::Native(NSCursor::resizeRightCursor),
#[allow(deprecated)]
MouseCursor::NResize => Cursor::Native(NSCursor::resizeUpCursor),
#[allow(deprecated)]
MouseCursor::WResize => Cursor::Native(NSCursor::resizeLeftCursor),
#[allow(deprecated)]
MouseCursor::SResize => Cursor::Native(NSCursor::resizeDownCursor),
#[allow(deprecated)]
MouseCursor::EwResize | MouseCursor::ColResize => {
Cursor::Native(NSCursor::resizeLeftRightCursor)
}
#[allow(deprecated)]
MouseCursor::NsResize | MouseCursor::RowResize => {
Cursor::Native(NSCursor::resizeUpDownCursor)
}
Expand Down
16 changes: 8 additions & 8 deletions src/platform/macos/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ use crate::HandlerError;
use std::fmt::Display;

#[derive(Debug)]
pub enum Error {
pub enum PlatformError {
Handler(HandlerError),
#[cfg(feature = "opengl")]
GlError(super::gl::GlError),
}

impl Display for Error {
impl Display for PlatformError {
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
#[cfg(feature = "opengl")]
Error::GlError(e) => e.fmt(fmt),
Error::Handler(e) => e.fmt(fmt),
PlatformError::GlError(e) => e.fmt(fmt),
PlatformError::Handler(e) => e.fmt(fmt),
}
}
}

impl std::error::Error for Error {
impl std::error::Error for PlatformError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Handler(e) => Some(e.source()),
PlatformError::Handler(e) => Some(e.source()),
#[cfg(feature = "opengl")]
_ => None,
}
}
}

impl From<HandlerError> for Error {
impl From<HandlerError> for PlatformError {
fn from(e: HandlerError) -> Self {
Error::Handler(e)
PlatformError::Handler(e)
}
}
13 changes: 10 additions & 3 deletions src/platform/macos/gl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(deprecated)] // OpenGL is deprecated on macOS
#![expect(deprecated, reason = "OpenGL is deprecated on macOS")]

use crate::gl::{GlConfig, Profile};
use crate::platform::*;
Expand Down Expand Up @@ -27,7 +27,7 @@ pub enum GlError {
OpenGlBundleNotFound,
}

impl From<GlError> for Error {
impl From<GlError> for PlatformError {
fn from(value: GlError) -> Self {
Self::GlError(value)
}
Expand Down Expand Up @@ -75,10 +75,17 @@ impl GlContext {
.into());
};

let Some(color_size) = (config.red_bits as u32)
.checked_add(config.blue_bits as u32)
.and_then(|c| c.checked_add(config.green_bits as u32))
else {
panic!("Overflow when computing color size")
};

#[rustfmt::skip]
let mut attrs = vec![
NSOpenGLPFAOpenGLProfile, version,
NSOpenGLPFAColorSize, (config.red_bits + config.blue_bits + config.green_bits) as u32,
NSOpenGLPFAColorSize, color_size,
NSOpenGLPFAAlphaSize, config.alpha_bits as u32,
NSOpenGLPFADepthSize, config.depth_bits as u32,
NSOpenGLPFAStencilSize, config.stencil_bits as u32,
Expand Down
Loading