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
9 changes: 1 addition & 8 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#[cfg(target_os = "macos")]
use crate::macos as platform;
#[cfg(target_os = "windows")]
use crate::win as platform;
#[cfg(target_os = "linux")]
use crate::x11 as platform;

pub fn copy_to_clipboard(data: &str) {
platform::copy_to_clipboard(data)
crate::platform::copy_to_clipboard(data)
}
81 changes: 81 additions & 0 deletions src/gl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use crate::platform::gl::*;
use std::ffi::c_void;
use std::marker::PhantomData;
use std::panic::AssertUnwindSafe;

#[derive(Clone, Debug, PartialEq)]
pub struct GlConfig {
pub version: (u8, u8),
pub profile: Profile,
pub red_bits: u8,
pub blue_bits: u8,
pub green_bits: u8,
pub alpha_bits: u8,
pub depth_bits: u8,
pub stencil_bits: u8,
pub samples: Option<u8>,
pub srgb: bool,
pub double_buffer: bool,
pub vsync: bool,
}

impl Default for GlConfig {
fn default() -> Self {
GlConfig {
version: (3, 2),
profile: Profile::Core,
red_bits: 8,
blue_bits: 8,
green_bits: 8,
alpha_bits: 8,
depth_bits: 24,
stencil_bits: 8,
samples: None,
srgb: true,
double_buffer: true,
vsync: false,
}
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Profile {
Compatibility,
Core,
}

#[derive(Debug)]
pub enum GlError {
InvalidWindowHandle,
VersionNotSupported,
CreationFailed(CreationFailedError),
}

pub struct GlContext {
// AssertUnwindSafe should *not* be here, but this is needed for now to keep semver compatibility
// Remove this in 0.2
pub(crate) inner: AssertUnwindSafe<crate::platform::gl::GlContext>,
phantom: PhantomData<*mut ()>,
}

impl GlContext {
pub(crate) fn new(context: crate::platform::gl::GlContext) -> GlContext {
GlContext { inner: AssertUnwindSafe(context), phantom: PhantomData }
}

pub unsafe fn make_current(&self) {
self.inner.make_current();
}

pub unsafe fn make_not_current(&self) {
self.inner.make_not_current();
}

pub fn get_proc_address(&self, symbol: &str) -> *const c_void {
self.inner.get_proc_address(symbol)
}

pub fn swap_buffers(&self) {
self.inner.swap_buffers();
}
}
131 changes: 0 additions & 131 deletions src/gl/mod.rs

This file was deleted.

9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod win;
#[cfg(target_os = "linux")]
pub(crate) mod x11;

mod clipboard;
mod event;
mod keyboard;
Expand All @@ -13,6 +6,8 @@ mod window;
mod window_info;
mod window_open_options;

pub(crate) mod platform;

#[cfg(feature = "opengl")]
pub mod gl;

Expand Down
13 changes: 13 additions & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::*;

#[cfg(target_os = "linux")]
mod x11;
#[cfg(target_os = "linux")]
pub use x11::*;
#[cfg(target_os = "windows")]
mod win;
#[cfg(target_os = "windows")]
pub use win::*;
File renamed without changes.
12 changes: 2 additions & 10 deletions src/gl/macos.rs → src/platform/macos/gl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(deprecated)] // OpenGL is deprecated on macOS

use super::{GlConfig, GlError, Profile};
use crate::gl::{GlConfig, GlError, Profile};
use objc2::rc::Retained;
use objc2::AllocAnyThread;
use objc2::{MainThreadMarker, MainThreadOnly};
Expand All @@ -18,7 +18,7 @@ use std::ptr::NonNull;

pub type CreationFailedError = ();
pub struct GlContext {
view: Retained<NSOpenGLView>,
pub(crate) view: Retained<NSOpenGLView>,
context: Retained<NSOpenGLContext>,
}

Expand Down Expand Up @@ -120,12 +120,4 @@ impl GlContext {
self.view.setFrameSize(size);
self.view.setNeedsDisplay(true);
}

/// Pointer to the `NSOpenGLView` this context renders into. Used by
/// the parent `NSView`'s `hitTest:` override to collapse hits on the
/// render subview to the parent, so AppKit routes `mouseDown:` on
/// first click in non-key windows.
pub(crate) fn ns_view(&self) -> &NSOpenGLView {
&self.view
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions src/macos/mod.rs → src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ mod view;
mod window;

pub use window::*;

#[cfg(feature = "opengl")]
pub mod gl;
9 changes: 5 additions & 4 deletions src/macos/view.rs → src/platform/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ impl BaseviewView {

#[cfg(feature = "opengl")]
if let Some(gl_config) = options.gl_config {
let gl_context = crate::gl::GlContext::create(view.view, gl_config).unwrap();
let gl_context = super::gl::GlContext::create(view.view, gl_config).unwrap();
let gl_context = crate::gl::GlContext::new(gl_context);
let Ok(()) = view.gl_context.set(gl_context) else { unreachable!() };
}

Expand Down Expand Up @@ -151,7 +152,7 @@ impl BaseviewView {
// macOS.
#[cfg(feature = "opengl")]
if let Some(gl_context) = this.gl_context.get() {
gl_context.resize(size);
gl_context.inner.resize(size);
}

// If this is a standalone window then we'll also need to resize the window itself
Expand Down Expand Up @@ -275,7 +276,7 @@ impl ViewImpl for BaseviewView {
/// `hitTest:` override that collapses hits on baseview's internal
/// OpenGL render subview to this NSView.
///
/// `src/gl/macos.rs` attaches an `NSOpenGLView` as a subview of this
/// `src/gl/gl` attaches an `NSOpenGLView` as a subview of this
/// view so the GL context is isolated from event handling. The side
/// effect is that `[NSView hitTest:]` returns the GL subview for
/// every click inside our frame — `NSOpenGLView` inherits the
Expand Down Expand Up @@ -306,7 +307,7 @@ impl ViewImpl for BaseviewView {
#[cfg(feature = "opengl")]
{
if let Some(gl_context) = this.gl_context.get() {
if super_result == gl_context.ns_view() {
if *super_result == **gl_context.inner.0.view {
return Some(this.view);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/macos/window.rs → src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{MouseCursor, Size, WindowHandler, WindowInfo, WindowOpenOptions};

#[cfg(feature = "opengl")]
use crate::gl::GlContext;
use crate::macos::view::{BaseviewView, ViewParentingType};
use crate::platform::macos::view::{BaseviewView, ViewParentingType};
use crate::wrappers::appkit::{create_window, extract_raw_window_handle, View, ViewRef};

pub struct WindowHandle {
Expand Down
4 changes: 2 additions & 2 deletions src/win/drop_target.rs → src/platform/win/drop_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{DropData, DropEffect, Event, EventStatus, MouseEvent, PhyPoint, Poin
use super::WindowState;

#[implement(IDropTarget)]
pub(super) struct DropTarget {
pub(crate) struct DropTarget {
window_state: Weak<WindowState>,

// These are cached since DragOver and DragLeave callbacks don't provide them,
Expand All @@ -28,7 +28,7 @@ pub(super) struct DropTarget {
}

impl DropTarget {
pub(super) fn new(window_state: Weak<WindowState>) -> Self {
pub(crate) fn new(window_state: Weak<WindowState>) -> Self {
Self {
window_state,
drag_position: Cell::new(Point::new(0.0, 0.0)),
Expand Down
2 changes: 1 addition & 1 deletion src/gl/win.rs → src/platform/win/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use windows_sys::{

use raw_window_handle::RawWindowHandle;

use super::{GlConfig, GlError, Profile};
use crate::gl::*;
use crate::wrappers::win32::uuid::Uuid;

// See https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_create_context.txt
Expand Down
2 changes: 1 addition & 1 deletion src/win/hook.rs → src/platform/win/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use windows_sys::Win32::{
},
};

use crate::win::BaseviewWindow;
use super::*;
use crate::wrappers::win32::window::wnd_proc;

// track all windows opened by this instance of baseview
Expand Down
2 changes: 1 addition & 1 deletion src/win/keyboard.rs → src/platform/win/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SHIFT_STATE_ALTGR: ShiftState = 2;
const N_SHIFT_STATE: ShiftState = 4;

/// Per-window keyboard state.
pub(super) struct KeyboardState {
pub(crate) struct KeyboardState {
hkl: HKL,
// A map from (vk, is_shifted) to string val
key_vals: HashMap<(VkCode, ShiftState), String>,
Expand Down
3 changes: 3 additions & 0 deletions src/win/mod.rs → src/platform/win/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ mod keyboard;
mod window;

pub use window::*;

#[cfg(feature = "opengl")]
pub mod gl;
Loading