diff --git a/Cargo.toml b/Cargo.toml index 393e18b8e..62993e591 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ failure = "0.1" failure_derive = "0.1" foreign-types = "0.3" freetype = { path = "deps/freetype" } -glium = { version = "0.24", default-features = false, features = ["glutin", "icon_loading"]} +glium = { optional=true, version = "0.24", default-features = false, features = ["glutin", "icon_loading"]} harfbuzz = { path = "deps/harfbuzz" } lazy_static = "1.3" leb128 = "0.2" @@ -52,7 +52,7 @@ toml = "0.4" unicode-normalization = "0.1" unicode-width = "0.1" varbincode = "0.1" -winit = "0.19" +winit = {version="0.19",optional=true} window = { path = "window", features=["opengl"]} zstd = "0.4" @@ -101,7 +101,9 @@ core-graphics = "0.17" core-text = "13.2" [features] +default = ["enable-winit"] force-fontconfig = ["fontconfig"] +enable-winit = ["winit", "glium"] [workspace] diff --git a/src/frontend/guicommon/host.rs b/src/frontend/guicommon/host.rs index a820dc26d..c383b9568 100644 --- a/src/frontend/guicommon/host.rs +++ b/src/frontend/guicommon/host.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "enable-winit")] use super::window::TerminalWindow; use crate::font::{FontConfiguration, FontSystemSelection}; use crate::frontend::guicommon::clipboard::SystemClipboard; @@ -37,6 +38,7 @@ pub enum KeyAssignment { CloseCurrentTab, } +#[cfg(feature = "enable-winit")] pub trait HostHelper { fn with_window Result<(), Error>>( &self, @@ -45,6 +47,7 @@ pub trait HostHelper { fn toggle_full_screen(&mut self); } +#[cfg(feature = "enable-winit")] pub struct HostImpl { helper: H, clipboard: Arc, @@ -142,6 +145,7 @@ impl KeyMap { } } +#[cfg(feature = "enable-winit")] impl HostImpl { pub fn new(helper: H) -> Self { Self { @@ -280,12 +284,15 @@ impl HostImpl { } } +#[cfg(feature = "enable-winit")] impl Deref for HostImpl { type Target = H; fn deref(&self) -> &H { &self.helper } } + +#[cfg(feature = "enable-winit")] impl DerefMut for HostImpl { fn deref_mut(&mut self) -> &mut H { &mut self.helper @@ -295,17 +302,20 @@ impl DerefMut for HostImpl { /// Implements `TerminalHost` for a Tab. /// `TabHost` instances are short lived and borrow references to /// other state. +#[cfg(feature = "enable-winit")] pub struct TabHost<'a, H: HostHelper> { writer: &'a mut dyn std::io::Write, host: &'a mut HostImpl, } +#[cfg(feature = "enable-winit")] impl<'a, H: HostHelper> TabHost<'a, H> { pub fn new(writer: &'a mut dyn std::io::Write, host: &'a mut HostImpl) -> Self { Self { writer, host } } } +#[cfg(feature = "enable-winit")] impl<'a, H: HostHelper> term::TerminalHost for TabHost<'a, H> { fn writer(&mut self) -> &mut dyn std::io::Write { &mut self.writer diff --git a/src/frontend/guicommon/window.rs b/src/frontend/guicommon/window.rs index de7e4d5e0..9df09fa17 100644 --- a/src/frontend/guicommon/window.rs +++ b/src/frontend/guicommon/window.rs @@ -4,9 +4,12 @@ use crate::mux::domain::DomainId; use crate::mux::tab::{Tab, TabId}; use crate::mux::window::WindowId; use crate::mux::Mux; +#[cfg(feature = "enable-winit")] use crate::opengl::render::Renderer; +#[cfg(feature = "enable-winit")] use crate::opengl::textureatlas::OutOfTextureSpace; use failure::{bail, ensure, format_err, Error}; +#[cfg(feature = "enable-winit")] use glium; use log::{debug, error}; use portable_pty::PtySize; @@ -41,6 +44,7 @@ pub struct Dimensions { /// the different GUI systems. /// A number of methods need to be provided by the window in order to /// unlock the use of the provided methods towards the bottom of the trait. +#[cfg(feature = "enable-winit")] pub trait TerminalWindow { fn set_window_title(&mut self, title: &str) -> Result<(), Error>; fn get_mux_window_id(&self) -> WindowId; diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index 3789c60c4..935f74b45 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -12,6 +12,7 @@ use std::cell::RefCell; use std::rc::Rc; use std::sync::{Arc, Mutex}; +#[cfg(feature = "enable-winit")] pub mod glium; pub mod guicommon; pub mod muxserver; @@ -33,8 +34,10 @@ impl Default for FrontEndSelection { fn default() -> Self { if cfg!(all(unix, not(target_os = "macos"))) { FrontEndSelection::X11 - } else { + } else if cfg!(feature = "enable-winit") { FrontEndSelection::Glutin + } else { + FrontEndSelection::OpenGL } } } @@ -67,7 +70,10 @@ pub fn front_end() -> Option> { impl FrontEndSelection { pub fn try_new(self, mux: &Rc) -> Result, Error> { let front_end = match self { + #[cfg(feature = "enable-winit")] FrontEndSelection::Glutin => glium::glutinloop::GlutinFrontEnd::try_new(mux), + #[cfg(not(feature = "enable-winit"))] + FrontEndSelection::Glutin => failure::bail!("Glutin not compiled in"), #[cfg(all(unix, not(target_os = "macos")))] FrontEndSelection::X11 => xwindows::x11loop::X11FrontEnd::try_new(mux), #[cfg(not(all(unix, not(target_os = "macos"))))] diff --git a/src/main.rs b/src/main.rs index f0d675a5f..9635dfd79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,8 @@ use std::sync::Arc; mod config; mod frontend; mod mux; + +#[cfg(feature = "enable-winit")] mod opengl; mod ratelim; mod server;