Skip to content

Add FreeBSD support #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ x11 = { version = "2.18", features = ["xlib", "xcursor"] }
xcb-util = { version = "0.3", features = ["icccm"] }
nix = "0.22.0"

[target.'cfg(target_os="freebsd")'.dependencies]
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
x11 = { version = "2.18", features = ["xlib", "xcursor"] }
xcb-util = { version = "0.3", features = ["icccm"] }
nix = "0.22.0"

[target.'cfg(target_os="windows")'.dependencies]
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi", "wingdi", "errhandlingapi"] }
uuid = { version = "0.8", features = ["v4"], optional = true }
Expand Down
11 changes: 8 additions & 3 deletions src/gl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::c_void;
use std::marker::PhantomData;

// On X11 creating the context is a two step process
#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
use raw_window_handle::HasRawWindowHandle;

#[cfg(target_os = "windows")]
Expand All @@ -16,6 +16,11 @@ pub(crate) mod x11;
#[cfg(target_os = "linux")]
pub(crate) use self::x11 as platform;

#[cfg(target_os = "freebsd")]
pub(crate) mod x11;
#[cfg(target_os = "freebsd")]
pub(crate) use self::x11 as platform;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -75,7 +80,7 @@ pub struct GlContext {
}

impl GlContext {
#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
pub(crate) unsafe fn create(
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
Expand All @@ -86,7 +91,7 @@ impl GlContext {
/// The X11 version needs to be set up in a different way compared to the Windows and macOS
/// versions. So the platform-specific versions should be used to construct the context within
/// baseview, and then this object can be passed to the user.
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub(crate) fn new(context: platform::GlContext) -> GlContext {
GlContext { context, phantom: PhantomData }
}
Expand Down
4 changes: 2 additions & 2 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

//! Keyboard types.

#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
use keyboard_types::{Code, Location};

#[cfg(any(target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
/// Map key code to location.
///
/// The logic for this is adapted from InitKeyEvent in TextInputHandler (in the Mozilla
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod macos;
mod win;
#[cfg(target_os = "linux")]
mod x11;
#[cfg(target_os = "freebsd")]
mod x11;

mod event;
mod keyboard;
Expand Down
2 changes: 2 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::macos as platform;
use crate::win as platform;
#[cfg(target_os = "linux")]
use crate::x11 as platform;
#[cfg(target_os = "freebsd")]
use crate::x11 as platform;

pub struct WindowHandle {
window_handle: platform::WindowHandle,
Expand Down
2 changes: 1 addition & 1 deletion src/x11/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn code_to_key(code: Code, m: Modifiers) -> Key {
}
}

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
/// Map hardware keycode to code.
///
/// In theory, the hardware keycode is device dependent, but in
Expand Down