From c0c01e77c3c8ae36bede98374893f46ab8595007 Mon Sep 17 00:00:00 2001 From: Yuri Victorovich Date: Mon, 31 Oct 2022 00:18:37 -0700 Subject: [PATCH] Add FreeBSD support --- Cargo.toml | 6 ++++++ src/gl/mod.rs | 11 ++++++++--- src/keyboard.rs | 4 ++-- src/lib.rs | 2 ++ src/window.rs | 2 ++ src/x11/keyboard.rs | 2 +- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eb23f4e5..1c425767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/gl/mod.rs b/src/gl/mod.rs index a7922b7c..e1d8fd85 100644 --- a/src/gl/mod.rs +++ b/src/gl/mod.rs @@ -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")] @@ -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")] @@ -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 { @@ -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 } } diff --git a/src/keyboard.rs b/src/keyboard.rs index c56abd3d..27e3c062 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 46a3695e..9340a3bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ mod macos; mod win; #[cfg(target_os = "linux")] mod x11; +#[cfg(target_os = "freebsd")] +mod x11; mod event; mod keyboard; diff --git a/src/window.rs b/src/window.rs index a0d91f64..8c2ef3fd 100644 --- a/src/window.rs +++ b/src/window.rs @@ -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, diff --git a/src/x11/keyboard.rs b/src/x11/keyboard.rs index 32201282..bc46244f 100644 --- a/src/x11/keyboard.rs +++ b/src/x11/keyboard.rs @@ -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