diff --git a/Cargo.toml b/Cargo.toml index 1e9b14e5e..32a4442a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ unicode-width = "~0.1" directories = "~1.0" font-loader = "0.8" rusttype = "0.7" -clipboard = "0.2" +clipboard = "0.5" [target.'cfg(unix)'.dependencies] harfbuzz-sys = "~0.2" @@ -49,7 +49,7 @@ servo-fontconfig = "~0.4" egli = "~0.4" x11 = {version ="~2.17", features = ["xlib_xcb"]} -[target.'cfg(any(target_os = "android", windows, all(unix, not(target_os = "macos"))))'.dependencies.glium] +[dependencies.glium] version = "~0.20" default-features = false features = ["glutin"] diff --git a/src/font/rtype.rs b/src/font/rtype.rs index eb94647bb..752cf8e75 100644 --- a/src/font/rtype.rs +++ b/src/font/rtype.rs @@ -28,13 +28,17 @@ impl RustTypeFonts { impl FontSystem for RustTypeFonts { fn load_font(&self, config: &Config, style: &TextStyle) -> Result, Error> { + #[cfg(not(target_os = "macos"))] + let family = "monospace"; + #[cfg(target_os = "macos")] + let family = "Menlo"; let font_props = system_fonts::FontPropertyBuilder::new() //.family(&style.fontconfig_pattern) - .family("monospace") + .family(family) .monospace() .build(); let (data, idx) = system_fonts::get(&font_props) - .ok_or_else(|| format_err!("no font matching {:?}", style))?; + .ok_or_else(|| format_err!("no font matching {:?}", family))?; eprintln!("want idx {} in bytes of len {}", idx, data.len()); let collection = FontCollection::from_bytes(data)?; let font = collection.font_at(idx as usize)?; diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index de967ab40..53e25cc65 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -2,7 +2,7 @@ use super::MasterPty; use super::{Child, Command}; -use clipboard::ClipboardContext; +use clipboard::{ClipboardContext, ClipboardProvider}; use config::Config; use failure::Error; use font::FontConfiguration; @@ -22,13 +22,45 @@ use termwiz::hyperlink::Hyperlink; struct Host { display: glium::Display, pty: MasterPty, - clipboard: ClipboardContext, + clipboard: Clipboard, window_position: Option<(i32, i32)>, /// is is_some, holds position to be restored after exiting /// fullscreen mode. is_fullscreen: Option<(i32, i32)>, } +/// macOS gets unhappy if we set up the clipboard too early, +/// so we use this to defer it until we use it +#[derive(Default)] +struct Clipboard { + clipboard: Option, +} + +impl Clipboard { + fn clipboard(&mut self) -> Result<&mut ClipboardContext, Error> { + if self.clipboard.is_none() { + self.clipboard = Some(ClipboardContext::new().map_err(|e| format_err!("{}", e))?); + } + Ok(self.clipboard.as_mut().unwrap()) + } + + pub fn get_clipboard(&mut self) -> Result { + self.clipboard()? + .get_contents() + .map_err(|e| format_err!("{}", e)) + } + + pub fn set_clipboard(&mut self, clip: Option) -> Result<(), Error> { + self.clipboard()? + .set_contents(clip.unwrap_or_else(|| "".into())) + .map_err(|e| format_err!("{}", e))?; + // Request the clipboard contents we just set; on some systems + // if we copy and paste in wezterm, the clipboard isn't visible + // to us again until the second call to get_clipboard. + self.get_clipboard().map(|_| ()) + } +} + impl term::TerminalHost for Host { fn writer(&mut self) -> &mut Write { &mut self.pty @@ -44,19 +76,11 @@ impl term::TerminalHost for Host { } fn get_clipboard(&mut self) -> Result { - self.clipboard - .get_contents() - .map_err(|e| format_err!("{}", e)) + self.clipboard.get_clipboard() } fn set_clipboard(&mut self, clip: Option) -> Result<(), Error> { - self.clipboard - .set_contents(clip.unwrap_or_else(|| "".into())) - .map_err(|e| format_err!("{}", e)) - // Request the clipboard contents we just set; on some systems - // if we copy and paste in wezterm, the clipboard isn't visible - // to us again until the second call to get_clipboard. - .and_then(|_| self.get_clipboard().map(|_| ())) + self.clipboard.set_clipboard(clip) } fn set_title(&mut self, title: &str) { @@ -156,7 +180,7 @@ impl TerminalWindow { let host = Host { display, pty, - clipboard: ClipboardContext::new().map_err(|e| format_err!("{}", e))?, + clipboard: Clipboard::default(), window_position, is_fullscreen: None, };