Skip to content

Commit fa93b49

Browse files
committed
Add FreeBSD support
1 parent eae4033 commit fa93b49

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use std::marker::PhantomData;
55
#[cfg(not(target_os = "linux"))]
66
use raw_window_handle::HasRawWindowHandle;
77

8+
#[cfg(not(target_os = "freebsd"))]
9+
use raw_window_handle::HasRawWindowHandle;
10+
811
#[cfg(target_os = "windows")]
912
mod win;
1013
#[cfg(target_os = "windows")]
@@ -16,6 +19,11 @@ pub(crate) mod x11;
1619
#[cfg(target_os = "linux")]
1720
pub(crate) use self::x11 as platform;
1821

22+
#[cfg(target_os = "freebsd")]
23+
pub(crate) mod x11;
24+
#[cfg(target_os = "freebsd")]
25+
pub(crate) use self::x11 as platform;
26+
1927
#[cfg(target_os = "macos")]
2028
mod macos;
2129
#[cfg(target_os = "macos")]
@@ -75,7 +83,7 @@ pub struct GlContext {
7583
}
7684

7785
impl GlContext {
78-
#[cfg(not(target_os = "linux"))]
86+
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
7987
pub(crate) unsafe fn create(
8088
parent: &impl HasRawWindowHandle, config: GlConfig,
8189
) -> Result<GlContext, GlError> {
@@ -86,7 +94,7 @@ impl GlContext {
8694
/// The X11 version needs to be set up in a different way compared to the Windows and macOS
8795
/// versions. So the platform-specific versions should be used to construct the context within
8896
/// baseview, and then this object can be passed to the user.
89-
#[cfg(target_os = "linux")]
97+
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
9098
pub(crate) fn new(context: platform::GlContext) -> GlContext {
9199
GlContext { context, phantom: PhantomData }
92100
}

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)