Skip to content

Commit c0c01e7

Browse files
committed
Add FreeBSD support
1 parent eae4033 commit c0c01e7

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ x11 = { version = "2.18", features = ["xlib", "xcursor"] }
2828
xcb-util = { version = "0.3", features = ["icccm"] }
2929
nix = "0.22.0"
3030

31+
[target.'cfg(target_os="freebsd")'.dependencies]
32+
xcb = { version = "0.9", features = ["thread", "xlib_xcb", "dri2"] }
33+
x11 = { version = "2.18", features = ["xlib", "xcursor"] }
34+
xcb-util = { version = "0.3", features = ["icccm"] }
35+
nix = "0.22.0"
36+
3137
[target.'cfg(target_os="windows")'.dependencies]
3238
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi", "wingdi", "errhandlingapi"] }
3339
uuid = { version = "0.8", features = ["v4"], optional = true }

src/gl/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ffi::c_void;
22
use std::marker::PhantomData;
33

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

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

19+
#[cfg(target_os = "freebsd")]
20+
pub(crate) mod x11;
21+
#[cfg(target_os = "freebsd")]
22+
pub(crate) use self::x11 as platform;
23+
1924
#[cfg(target_os = "macos")]
2025
mod macos;
2126
#[cfg(target_os = "macos")]
@@ -75,7 +80,7 @@ pub struct GlContext {
7580
}
7681

7782
impl GlContext {
78-
#[cfg(not(target_os = "linux"))]
83+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
7984
pub(crate) unsafe fn create(
8085
parent: &impl HasRawWindowHandle, config: GlConfig,
8186
) -> Result<GlContext, GlError> {
@@ -86,7 +91,7 @@ impl GlContext {
8691
/// The X11 version needs to be set up in a different way compared to the Windows and macOS
8792
/// versions. So the platform-specific versions should be used to construct the context within
8893
/// baseview, and then this object can be passed to the user.
89-
#[cfg(target_os = "linux")]
94+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
9095
pub(crate) fn new(context: platform::GlContext) -> GlContext {
9196
GlContext { context, phantom: PhantomData }
9297
}

src/keyboard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
//! Keyboard types.
1919
20-
#[cfg(any(target_os = "linux", target_os = "macos"))]
20+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
2121
use keyboard_types::{Code, Location};
2222

23-
#[cfg(any(target_os = "linux", target_os = "macos"))]
23+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
2424
/// Map key code to location.
2525
///
2626
/// The logic for this is adapted from InitKeyEvent in TextInputHandler (in the Mozilla

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod macos;
44
mod win;
55
#[cfg(target_os = "linux")]
66
mod x11;
7+
#[cfg(target_os = "freebsd")]
8+
mod x11;
79

810
mod event;
911
mod keyboard;

src/window.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use crate::macos as platform;
1111
use crate::win as platform;
1212
#[cfg(target_os = "linux")]
1313
use crate::x11 as platform;
14+
#[cfg(target_os = "freebsd")]
15+
use crate::x11 as platform;
1416

1517
pub struct WindowHandle {
1618
window_handle: platform::WindowHandle,

src/x11/keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fn code_to_key(code: Code, m: Modifiers) -> Key {
201201
}
202202
}
203203

204-
#[cfg(target_os = "linux")]
204+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
205205
/// Map hardware keycode to code.
206206
///
207207
/// In theory, the hardware keycode is device dependent, but in

0 commit comments

Comments
 (0)